full blown version of convtest works again
[libfirm] / ir / be / test / Switcher.c
1 /*
2  * File name:   test/Switcher.c
3  * Purpose:     test the switch statement
4  * Author:      Boris Boesler
5  * Modified by: Michael Beck
6  * Created:     XX.02.2003
7  * CVS-ID:      $Id$
8  * Copyright:   (c) 2003 Universitaet Karlsruhe
9  * Licence:
10  */
11
12 #include <stdio.h>
13
14 static void print_int(int i) {
15     printf(" %d\n", i);
16 }
17
18 static int id(int i) {
19   return(i);
20 }
21
22 // standard switch with 1 case
23 static void switch1(int i) {
24   switch(i) {
25   case 0:
26     print_int(0);
27     break;
28   default:
29     print_int(-1);
30     //break;
31   }
32 }
33
34 // standard switch with more than 1 case
35 static void switch2(int i) {
36   switch(i) {
37   case 0:
38     print_int(0);
39     break;
40   case 2:
41     print_int(2);
42     break;
43   default:
44     print_int(-1);
45     break;
46   }
47 }
48
49 // standard switch with fall through
50 static void switch3(int i) {
51   switch(i) {
52   case 0:
53     print_int(0);
54     // fall through
55   case 3:
56     print_int(3);
57     break;
58   default:
59     print_int(-1);
60     break;
61   }
62 }
63
64 // standard switch without default
65 static void switch4(int i) {
66   switch(i) {
67   case 0:
68     print_int(0);
69     break;
70   case 4:
71     print_int(4);
72     break;
73   }
74 }
75
76 // standard switch without case
77 static void switch5(int i) {
78   switch(i) {
79   default:
80     print_int(-1);
81     break;
82   }
83 }
84
85 // standard switch with more than 1 case and controlflow change
86 static void switch6(int i) {
87   switch(i) {
88   case 0:
89     print_int(0);
90     break;
91   case 2:
92     if(i < 6)
93       print_int(2);
94     else
95       print_int(-2);
96     break;
97   default:
98     print_int(-1);
99     break;
100   }
101 }
102
103 // standard switch with more than 1 case label
104 static void switch7(int i) {
105   switch(i) {
106   case 0:
107     print_int(0);
108     break;
109   case 2:
110   case 3:
111       print_int(5);
112     break;
113   default:
114     print_int(-1);
115     break;
116   }
117 }
118
119
120 static void double_switch(int i) {
121
122     switch(i) {
123     case 16:
124         printf(" is 16\n");
125         switch(i % 4) {
126         case 0:
127             printf(" multiple of 4\n");
128             break;
129         default:
130             printf(" not multiple of 4\n");
131             break;
132         }
133         break;
134
135     default:
136         printf(" != 10 und != 16\n");
137         break;
138     }
139
140 }
141
142 int main (int argc, char *argv[]) {
143   printf("Switcher.c\n");
144   printf(" must print:\n 0\n 2\n 0\n 3\n -1\n 2\n is 16\n multiple of 4\n\n");
145   switch1(0);
146   switch2(2);
147   switch3(0);
148   switch4(5);
149   switch5(0);
150   switch6(2);
151
152   double_switch(16);
153   return 0;
154 }