OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [chips/] [compiler/] [library.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 jondawson
#!/usr/bin/env python
2
"""Support Library for builtin Functionality"""
3
 
4
__author__ = "Jon Dawson"
5
__copyright__ = "Copyright (C) 2013, Jonathan P Dawson"
6
__version__ = "0.1"
7
 
8
libs={"print.h":"""
9
 
10
//Print a string *string* to stdout
11
void print_string(unsigned string[]){
12
        unsigned i=0;
13
        while(string[i]){
14
                       stdout_put_char(string[i]);
15
                i++;
16
        }
17
}
18
 
19
//Print an unsigned int to stdout in hex format
20
void print_uhex(unsigned uhex){
21
        unsigned digit_3 = (uhex >> 12) & 0xf;
22
        unsigned digit_2 = (uhex >> 8) & 0xf;
23
        unsigned digit_1 = (uhex >> 4) & 0xf;
24
        unsigned digit_0 = uhex & 0xf;
25
        if(digit_3 < 9) stdout_put_char(digit_3 | 0x30);
26
        else stdout_put_char(digit_3 + 87);
27
        if(digit_2 < 9) stdout_put_char(digit_2 | 0x30);
28
        else stdout_put_char(digit_2 + 87);
29
        if(digit_1 < 9) stdout_put_char(digit_1 | 0x30);
30
        else stdout_put_char(digit_1 + 87);
31
        if(digit_0 < 9) stdout_put_char(digit_0 | 0x30);
32
        else stdout_put_char(digit_0 + 87);
33
}
34
 
35
//Print an unsigned int to stdout in decimal format
36
//leading 0s will be suppressed
37
void print_udecimal(unsigned udecimal){
38
        unsigned digit;
39
        unsigned significant = 0;
40
        digit = 0;
41
        while(udecimal >= 10000){
42
                udecimal -= 10000;
43
                digit += 1;
44
        }
45
        if(digit | significant){
46
              stdout_put_char(digit | 0x30);
47
              significant = 1;
48
        }
49
        digit = 0;
50
        while(udecimal >= 1000){
51
                udecimal -= 1000;
52
                digit += 1;
53
        }
54
        if(digit | significant){
55
              stdout_put_char(digit | 0x30);
56
              significant = 1;
57
        }
58
        digit = 0;
59
        while(udecimal >= 100){
60
                udecimal -= 100;
61
                digit += 1;
62
        }
63
        if(digit | significant){
64
              stdout_put_char(digit | 0x30);
65
              significant = 1;
66
        }
67
        digit = 0;
68
        while(udecimal >= 10){
69
                udecimal -= 10;
70
                digit += 1;
71
        }
72
        if(digit | significant){
73
              stdout_put_char(digit | 0x30);
74
              significant = 1;
75
        }
76
        stdout_put_char(udecimal | 0x30);
77
}
78
 
79
//Print a signed int to stdout in hex format
80
void print_hex(int hex){
81
        if(hex >= 0){
82
                print_uhex(hex);
83
        } else {
84
                stdout_put_char('-');
85
                print_uhex(-hex);
86
        }
87
}
88
 
89
//Print a signed int to stdout in decimal format
90
//leading 0s will be suppressed
91
void print_decimal(int decimal){
92
        if(decimal >= 0){
93
                print_udecimal(decimal);
94
        } else {
95
                stdout_put_char('-');
96
                print_udecimal(-decimal);
97
        }
98
}
99
 
100
 
101
"""}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.