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