rename set_using_visited to set_using_irn_visited, some cosmetics, remove obsolete...
[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 // standard switch with 1 case
19 static void switch1(int i) {
20   switch(i) {
21   case 0:
22     print_int(0);
23     break;
24   default:
25     print_int(-1);
26     //break;
27   }
28 }
29
30 // standard switch with more than 1 case
31 static void switch2(int i) {
32   switch(i) {
33   case 0:
34     print_int(0);
35     break;
36   case 2:
37     print_int(2);
38     break;
39   default:
40     print_int(-1);
41     break;
42   }
43 }
44
45 // standard switch with fall through
46 static void switch3(int i) {
47   switch(i) {
48   case 0:
49     print_int(0);
50     // fall through
51   case 3:
52     print_int(3);
53     break;
54   default:
55     print_int(-1);
56     break;
57   }
58 }
59
60 // standard switch without default
61 static void switch4(int i) {
62   switch(i) {
63   case 0:
64     print_int(0);
65     break;
66   case 4:
67     print_int(4);
68     break;
69   }
70 }
71
72 // standard switch without case
73 static void switch5(int i) {
74   switch(i) {
75   default:
76     print_int(-1);
77     break;
78   }
79 }
80
81 // standard switch with more than 1 case and controlflow change
82 static void switch6(int i) {
83   switch(i) {
84   case 0:
85     print_int(0);
86     break;
87   case 2:
88     if(i < 6)
89       print_int(2);
90     else
91       print_int(-2);
92     break;
93   default:
94     print_int(-1);
95     break;
96   }
97 }
98
99 // standard switch with more than 1 case label
100 static void switch7(int i) {
101   switch(i) {
102   case 0:
103     print_int(0);
104     break;
105   case 2:
106   case 3:
107       print_int(5);
108     break;
109   default:
110     print_int(-1);
111     break;
112   }
113 }
114
115
116 static void double_switch(int i) {
117
118     switch(i) {
119     case 16:
120         printf(" is 16\n");
121         switch(i % 4) {
122         case 0:
123             printf(" multiple of 4\n");
124             break;
125         default:
126             printf(" not multiple of 4\n");
127             break;
128         }
129         break;
130
131     default:
132         printf(" != 10 und != 16\n");
133         break;
134     }
135
136 }
137
138 int main (int argc, char *argv[]) {
139   printf("Switcher.c\n");
140   printf(" must print:\n 0\n 2\n 0\n 3\n -1\n 2\n 5\n is 16\n multiple of 4\n\n");
141   switch1(0);
142   switch2(2);
143   switch3(0);
144   switch4(5);
145   switch5(0);
146   switch6(2);
147   switch7(3);
148
149   double_switch(16);
150   return 0;
151 }