Fixed several pointer related bugs in the PIC port
[fw/sdcc] / src / regression / add2.c
1
2 // Addition tests - mostly int's
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 1
7
8
9 unsigned char success=0;
10 unsigned char failures=0;
11 unsigned char dummy=0;
12
13
14 unsigned int aint0 = 0;
15 unsigned int aint1 = 0;
16 unsigned int aint2 = 0;
17 unsigned int aint3 = 0;
18 unsigned char achar0 = 0;
19 unsigned char achar1 = 0;
20 unsigned char achar2 = 0;
21 unsigned char achar3 = 0;
22 unsigned char *acharP = 0;
23
24 #if SUPPORT_BIT_TYPES
25
26 bit bit0 = 0;
27 bit bit1 = 0;
28 bit bit2 = 0;
29 bit bit3 = 0;
30 bit bit4 = 0;
31 bit bit5 = 0;
32 bit bit6 = 0;
33 bit bit7 = 0;
34 bit bit8 = 0;
35 bit bit9 = 0;
36 bit bit10 = 0;
37 bit bit11 = 0;
38
39 #endif
40
41
42 void done()
43 {
44
45   dummy++;
46
47 }
48
49 void add_lit2uint(void)
50 {
51
52   aint0 = aint0 + 5;
53
54   if(aint0 != 5)
55     failures++;
56
57   aint0 += 10;
58
59   if(aint0 != 15)
60     failures++;
61
62   aint0 = aint0 +1;  // Should be an increment
63   if(aint0 != 16)
64     failures++;
65
66   for(aint1 = 0; aint1 < 100; aint1++)
67     aint0 += 2;
68
69   if(aint0 != 216)
70     failures++;
71
72 }
73
74 void add_uint2uint (void)
75 {
76
77   aint1 = aint1 + aint0;
78
79   if(aint1 != 16)
80     failures++;
81
82   for(aint2 = 0; aint2<7; aint2++)
83     aint1 += aint0;
84
85   if(aint1 != 128)
86     failures++;
87
88 }
89
90 // assumes
91 //  aint0 = 0
92 //  aint1 = 32
93 //  aint2, aint3 can be anything.
94
95 void add_uint2uint2(void)
96 {
97
98
99   aint0++;
100   aint0 = aint0 + 1;
101   aint0 = aint0 + 2;
102   aint0 = aint0 + 3;
103   if(aint0 != 7)
104     failures++;
105
106   aint1 += aint0;
107   if(aint1 != 0x27)
108     failures++;
109
110   aint2 = aint1 + aint0;
111   if(aint2 != 0x2e)
112     failures++;
113
114   aint3 = aint2 + aint1 + aint0;
115   if(aint3 != 0x5c)
116     failures++;
117
118   aint3 += 0xa0;
119   if(aint3 != 0xfc)
120     failures++;
121
122   aint3 += aint0;
123   if(aint3 != 0x103)
124     failures++;
125
126   aint1 += 0xffc0;
127   if(aint1 != 0xffe7)
128     failures++;
129
130   aint3 = aint2 + aint1 + aint0;
131   if(aint3 != 0x1c)
132     failures++;
133
134
135 }
136
137 #if SUPPORT_BIT_TYPES
138 void add_bits(void)
139 {
140
141   bit1 = bit0;
142
143   bit0 = 1;
144
145   if(bit1 != 0)
146     failures++;
147
148   bit1 = bit1+bit0;
149   if(bit1 != 1)
150     failures++;
151
152   bit2 = bit1+bit3;
153   if(!bit2)
154     failures++;
155
156   bit3 = bit4+bit5+bit6+bit7+bit0;
157   if(!bit3)
158     failures++;
159 }
160 #endif
161
162 /* add_bit2uchar(void) - assumes bit0 = 1, aint0 = 7  */
163
164 void add_bit2uchar(void)
165 {
166
167   achar0 += bit0;
168
169   if(achar0 != 8)
170     failures++;
171
172   if(achar0 == bit0)
173     failures++;
174
175 }
176
177 void add_bit2uint(void)
178 {
179
180   if(aint0 != bit11)
181     failures++;
182
183   aint0 += bit0;
184   if(aint0!=1)
185     failures++;
186
187 }
188
189 /***********************************/
190
191 void addlits(void)
192 {
193   aint0 += 0x0001;
194
195   if(aint0 != 1)
196     failures++;
197
198   aint0 += 0x00;
199
200   if(aint0 != 1)
201     failures++;
202
203   aint0 += 0x00fe;
204   if(aint0 != 0x00ff)
205     failures++;
206
207   aint0 += 0x0001;
208
209   if(aint0 != 0x0100)
210     failures++;
211
212   aint0++;
213   if(aint0 != 0x0101)
214     failures++;
215
216   aint0 += 0x00ff;
217   if(aint0 != 0x0200)
218     failures++;
219
220   aint0 += 0x00a0;
221   if(aint0 != 0x02a0)
222     failures++;
223
224   aint0 += 0x0061;
225   if(aint0 != 0x0301)
226     failures++;
227
228   aint0 += 0x0100;
229   if(aint0 != 0x0401)
230     failures++;
231
232   aint0 += 0x0101;
233   if(aint0 != 0x0502)
234     failures++;
235
236   aint0 += 0x00fd;
237   if(aint0 != 0x05ff)
238     failures++;
239
240   aint0 += 0x0101;
241   if(aint0 != 0x0700)
242     failures++;
243
244   aint0 += 0x01ff;
245   if(aint0 != 0x08ff)
246     failures++;
247
248   aint0 += 0x01ff;
249   if(aint0 != 0x0afe)
250     failures++;
251
252   aint0 += 0xff02;
253   if(aint0 != 0x0a00)
254     failures++;
255
256   aint0 += 0xffff;
257   if(aint0 != 0x09ff)
258     failures++;
259
260   aint0 += 0xff01;
261   if(aint0 != 0x0900)
262     failures++;
263
264   aint0 += 0xff00;
265   if(aint0 != 0x0800)
266     failures++;
267
268   aint0 += 0xff01;
269   if(aint0 != 0x0701)
270     failures++;
271
272   aint0 += 0x0300;
273   if(aint0 != 0x0a01)
274     failures++;
275
276   aint0 += 0x03ff;
277   if(aint0 != 0x0e00)
278     failures++;
279
280   aint0 += 0x0301;
281   if(aint0 != 0x1101)
282     failures++;
283
284   aint0 += 0x03fe;
285   if(aint0 != 0x14ff)
286     failures++;
287
288   aint0 += 0x0301;
289   if(aint0 != 0x1800)
290     failures++;
291  
292 }
293
294
295 void main(void)
296 {
297
298   add_lit2uint();
299
300   aint0=16;
301   aint1=0;
302   add_uint2uint();
303
304
305   aint0 = 0;
306   aint1 = 32;
307   aint2 = 0;
308   add_uint2uint2();
309
310 #if SUPPORT_BIT_TYPES
311   add_bits();
312
313   achar0 = 7;
314   add_bit2uchar();
315
316   aint0 = 0;
317   bit0 = 1;
318   add_bit2uint();
319 #endif
320
321   aint0 = 0;
322   addlits();
323
324   success = failures;
325   done();
326 }