Commit | Line | Data |
---|---|---|
27ea8e45 | 1 | Original BTL Ratfor System for 4.2 |
476fcd16 SL |
2 | #ifndef lint |
3 | static char sccsid[] = "@(#)r0.c 1.2 (Berkeley) %G%"; | |
4 | #endif | |
5 | ||
27ea8e45 CC |
6 | #include "r.h" |
7 | ||
8 | int swlevel = -1; | |
9 | int swexit[5]; | |
10 | int nextcase[5]; | |
11 | ||
12 | swcode() { | |
13 | transfer = 0; | |
14 | putcom("switch"); | |
15 | swlevel++; | |
16 | if (swlevel >= 5) | |
17 | error("Switches nested > 5"); | |
18 | swexit[swlevel] = yyval = genlab(1); | |
19 | outcode("\tI"); | |
20 | outnum(yyval); | |
21 | outcode(" = "); | |
22 | balpar(); | |
23 | outdon(); | |
24 | nextcase[swlevel] = 0; | |
25 | indent++; | |
26 | } | |
27 | ||
28 | getcase() { | |
29 | int t, lpar; | |
30 | char token[100]; | |
31 | ||
32 | if (nextcase[swlevel] != 0) { | |
33 | outgoto(swexit[swlevel]); | |
34 | outcont(nextcase[swlevel]); | |
35 | } | |
36 | indent--; | |
37 | outcode("\tif(.not.("); | |
38 | do { | |
39 | outcode("I"); | |
40 | outnum(swexit[swlevel]); | |
41 | outcode(".eq.("); | |
42 | lpar = 0; | |
43 | do { | |
44 | if ((t=gtok(token)) == ':') | |
45 | break; | |
46 | if (t == '(') | |
47 | lpar++; | |
48 | else if (t == ')') | |
49 | lpar--; | |
50 | else if (t == ',') { | |
51 | if (lpar == 0) | |
52 | break; | |
53 | } | |
54 | outcode(token); | |
55 | } while (lpar >= 0); | |
56 | if (lpar < 0) | |
57 | error("Missing left parenthesis in case"); | |
58 | if (t == ',') | |
59 | outcode(").or."); | |
60 | } while (t != ':'); | |
61 | if (lpar != 0) | |
62 | error("Missing parenthesis in case"); | |
63 | outcode(")))"); | |
64 | nextcase[swlevel] = genlab(1); | |
65 | outgoto(nextcase[swlevel]); | |
66 | indent++; | |
67 | } | |
68 | ||
69 | getdefault() { | |
70 | char token[20]; | |
71 | if (gnbtok(token) != ':') | |
72 | error("Missing colon after default"); | |
73 | outgoto(swexit[swlevel]); | |
74 | outcont(nextcase[swlevel]); | |
75 | indent--; | |
76 | putcom("default"); | |
77 | indent++; | |
78 | } | |
79 | ||
80 | endsw(n, def) { | |
81 | if (def == 0) | |
82 | outcont(nextcase[swlevel]); | |
83 | swlevel--; | |
84 | if (swlevel < -1) | |
85 | error("Switches unwound too far"); | |
86 | indent--; | |
87 | outcont(n); | |
88 | } |