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