Imported Upstream version 2.9.0
[debian/cc1111] / src / regression / sub2.c
1 #include "gpsim_assert.h"
2 // Addition tests
3
4 /* bit types are not ANSI - so provide a way of disabling bit types
5  * if this file is used to test other compilers besides SDCC */
6 #define SUPPORT_BIT_TYPES 0
7
8 /* Some compilers that support bit types do not support bit arithmetic 
9  * (like bitx = bity + bitz;) */
10 #define SUPPORT_BIT_ARITHMETIC 1
11
12 unsigned char failures=0;
13
14 #if SUPPORT_BIT_TYPES
15
16 bit bit0 = 0;
17 bit bit1 = 0;
18 bit bit2 = 0;
19 bit bit3 = 0;
20 bit bit4 = 0;
21 bit bit5 = 0;
22 bit bit6 = 0;
23 bit bit7 = 0;
24 bit bit8 = 0;
25 bit bit9 = 0;
26 bit bit10 = 0;
27 bit bit11 = 0;
28
29 #endif
30
31 int int0 = 0;
32 int int1 = 0;
33 char char0 = 0;
34 char char1 = 0;
35 char char2 = 0;
36
37
38 void
39 done()
40 {
41   ASSERT(MANGLE(failures) == 0);
42   PASSED();
43 }
44
45 void sub_int1(void)
46 {
47   if(int0 != 5)
48     failures++;
49
50   if(int1 != 4)
51     failures++;
52
53   int0 = int0 - int1;
54
55   if(int0 != 1)
56     failures++;
57
58   int0 = 4 - int0;
59   if(int0 != 3)
60     failures++;
61
62   int0 = int0 - int1;
63
64   if(int0 != -1)
65     failures++;
66
67   int0 = int0 - 0xff;
68
69   if(int0 != -0x100)
70     failures++;
71
72   int0 = 0xff - int0;
73
74   if(int0 != 0x1ff)
75     failures++;
76
77
78 }
79
80 void sub_char_int(void)
81 {
82
83   int0 = int0 - char0;
84
85   if(int0 != 3)
86     failures++;
87
88   if(int0 < char0)
89     failures++;
90
91   int0 = int0 - char0;
92
93   if(int0 != 1)
94     failures++;
95
96   if(int0 > char0)
97     failures++;
98
99
100   int0 = int0 - char0;
101   if(int0 != -1)
102     failures++;
103
104   if(int0>0)
105     failures++;
106
107 }
108
109 void assign_char2int(void)
110 {
111
112   int0 = char0;
113   if(int0 != 0x7f)
114     failures++;
115
116   int1 = char1;
117   if(int1 != -5)
118     failures++;
119
120 }
121
122
123 void sub_compound_char(void)
124 {
125
126   char0 = char1 - 5;
127   if(char0 != 4)
128     failures++;
129
130   if((char1 - char0 - 5) != 0)
131     failures++;
132
133 }
134
135 void sub_compound_int(void)
136 {
137
138   int0 = int1 - 5;
139   if(int0 != 4)
140     failures++;
141
142   if((int1 - int0 - 5) != 0)
143     failures++;
144
145 }
146
147 void main(void)
148 {
149
150   int0 = 5;
151   int1 = 4;
152
153   sub_int1();
154
155   int0 = 5;
156   int1 = 4;
157   char0 = 2;
158
159   sub_char_int();
160
161   char0 = 0x7f;
162   char1 = -5;
163   assign_char2int();
164
165   char1 = 9;
166   sub_compound_char();
167   
168   int1 = 9;
169   sub_compound_int();
170
171   done();
172 }