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