Imported Upstream version 2.9.0
[debian/cc1111] / src / regression / add3.c
1 #include "gpsim_assert.h"
2
3 // Addition tests - mostly int's
4
5 /* bit types are not ANSI - so provide a way of disabling bit types
6  * if this file is used to test other compilers besides SDCC */
7 #define SUPPORT_BIT_TYPES 0
8
9
10 unsigned char failures=0;
11
12
13 char char0 = 0;
14 char char1 = 0;
15 char char2 = 0;
16 int int0 = 0;
17 int int1 = 0;
18 long long0 = 0;
19 long long1 = 0;
20 unsigned long ulong0 = 0;
21 unsigned long ulong1 = 0;
22
23 #if SUPPORT_BIT_TYPES
24
25 bit bit0 = 0;
26 bit bit1 = 0;
27 bit bit2 = 0;
28 bit bit3 = 0;
29 bit bit4 = 0;
30 bit bit5 = 0;
31 bit bit6 = 0;
32 bit bit7 = 0;
33 bit bit8 = 0;
34 bit bit9 = 0;
35 bit bit10 = 0;
36 bit bit11 = 0;
37
38 #endif
39
40
41 void
42 done()
43 {
44   ASSERT(MANGLE(failures) == 0);
45   PASSED();
46 }
47
48 void add_char2char(void)
49 {
50   if(char0 != 4)
51     failures++;
52   if(char1 != 5)
53     failures++;
54
55   char0 = char0 + char1;
56
57   if(char0 != 9)
58     failures++;
59
60   char0 += 127;
61   if(char0 > 0)
62     failures++;
63
64   if(char0 != -0x78)
65     failures++;
66
67
68 }
69
70 void add_compound_char(void)
71 {
72   char0 = char1+5;
73
74   if(char0 != 9)
75     failures++;
76
77   if((char0+char1) != 13)
78     failures++;
79 }
80
81 void add_int2int(void)
82 {
83   if(int0 != 4)
84     failures++;
85   if(int1 != 5)
86     failures++;
87
88   int0 += int1;
89   if(int0 != 9)
90     failures++;
91
92   int0 += 0x7fff;
93   if(int0 != -0x7ff8)
94     failures++;
95
96 }
97
98 void add_compound_int(void)
99 {
100   int0 = int1+5;
101
102   if(int0 != 9)
103     failures++;
104
105   if((int0+int1) != 13)
106     failures++;
107 }
108
109
110 void add_lit2long(void)
111 {
112
113   if(long0 != 0)
114     failures++;
115
116   long0++;
117
118   if(long0 != 1)
119     failures++;
120
121   long0 = long0 + 0xff;
122
123   if(long0 != 0x100)
124     failures++;
125
126   long0 = long0 + 0x100;
127   if(long0 != 0x200)
128     failures++;
129
130
131   long0 = long0 + 0xfe00;
132   if(long0 != 0x10000)
133     failures++;
134
135   long0 = long0 + 0xff0000;
136   if(long0 != 0x1000000)
137     failures++;
138
139   long0 = long0 + 0x7e000000;
140   if(long0 != 0x7f000000)
141     failures++;
142
143   /* wrap around zero */
144   long0 = long0 + 0x2000000;
145   if(long0 != -0x7f000000)
146     failures++;
147
148   long0 = long0 + 0x7f000000;
149   if(long0 != 0)
150     failures++;
151
152 }
153
154 void add_lit2ulong(void)
155 {
156
157   if(ulong0 != 0)
158     failures++;
159
160   ulong0++;
161
162   if(ulong0 != 1)
163     failures++;
164
165   ulong0 = ulong0 + 0xff;
166
167   if(ulong0 != 0x100)
168     failures++;
169
170   ulong0 = ulong0 + 0x100;
171   if(ulong0 != 0x200)
172     failures++;
173
174
175   ulong0 = ulong0 + 0xfe00;
176   if(ulong0 != 0x10000)
177     failures++;
178
179   ulong0 = ulong0 + 0xff0000;
180   if(ulong0 != 0x1000000)
181     failures++;
182
183   ulong0 = ulong0 + 0x7e000000;
184   if(ulong0 != 0x7f000000)
185     failures++;
186
187   ulong0 = ulong0 + 0x2000000;
188   if(ulong0 != 0x81000000)
189     failures++;
190
191   /* wrap around zero */
192   ulong0 = ulong0 + 0x7f000000;
193   if(ulong0)
194     failures++;
195
196 }
197
198 void main(void)
199 {
200   char0=4;
201   char1 = char0 + 1;
202   add_char2char();
203
204   char1=4;
205   add_compound_char();
206
207   int0 = 4;
208   int1 = int0 + 1;
209   add_int2int();
210
211   int1=4;
212   add_compound_int();
213
214   add_lit2long();
215   add_lit2ulong();
216
217   done();
218 }