2 static char rcsid[] = "$Id: getline.c,v 2.7 1994/06/24 10:40:03 ceriel Exp $";
20 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
21 * See the copyright notice in the ACK home directory, in the file "Copyright".
23 * Author: Hans van Staveren
27 static short tabval; /* temp store for shorts */
28 static offset tabval2; /* temp store for offsets */
29 static char string[IDL+1]; /* temp store for names */
32 * The next constants are close to sp_cend for fast switches
34 #define INST 256 /* instruction: number in tabval */
35 #define PSEU 257 /* pseudo: number in tabval */
36 #define ILBX 258 /* label: number in tabval */
37 #define DLBX 259 /* symbol: name in string[] */
38 #define CSTX1 260 /* short constant: stored in tabval */
39 #define CSTX2 261 /* offset: value in tabval2 */
40 #define VALX1 262 /* symbol+short: in string[] and tabval */
41 #define VALX2 263 /* symbol+offset: in string[] and tabval2 */
42 #define ATEOF 264 /* bumped into end of file */
44 #define readbyte getchar
47 register int l_byte, h_byte;
51 if ( h_byte>=128 ) h_byte -= 256 ;
52 return l_byte | (h_byte*256) ;
61 l |= ((unsigned) readbyte())*256 ;
62 l |= readbyte()*256L*256L ;
64 if ( h_byte>=128 ) h_byte -= 256 ;
65 return l | (h_byte*256L*256*256L) ;
72 * called when MES ERR is encountered.
73 * Drain input in case it is a pipe.
76 while (getchar() != EOF)
83 default: error("int expected");
89 sym_p getsym(status) int status; {
93 error("symbol expected");
95 return(symlookup(string,status,0));
97 return(symlookup(string,status,SYMPRO));
104 default: error("offset expected");
106 return((offset) tabval);
114 make_string(n) int n; {
116 sprintf(string,".%u",n);
121 register char *p = string;
133 int table3(n) int n; {
136 case sp_ilb1: tabval = readbyte(); return(ILBX);
137 case sp_ilb2: tabval = readshort(); return(ILBX);
138 case sp_dlb1: make_string(readbyte()); return(DLBX);
139 case sp_dlb2: make_string(readshort()); return(DLBX);
140 case sp_dnam: inident(); return(DLBX);
141 case sp_pnam: inident(); return(n);
142 case sp_cst2: tabval = readshort(); return(CSTX1);
144 case sp_cst4: tabval2 = readoffset(); return(CSTX2);
146 case sp_doff: if (table2()!=DLBX) error("symbol expected");
148 default: error("offset expected");
149 case CSTX1: return(VALX1);
151 case CSTX2: return(VALX2);
164 if ((n <= sp_lmnem) && (n >= sp_fmnem)) {
168 if ((n <= sp_lpseu) && (n >= sp_fpseu)) {
172 if ((n < sp_filb0 + sp_nilb0) && (n >= sp_filb0)) {
173 tabval = n - sp_filb0;
183 if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) {
184 tabval = n - sp_zcst0;
198 error("unknown instruction byte");
203 error("procedure unterminated at eof");
211 lnp = newline(OPSYMBOL);
212 lnp->l_instr = ps_sym;
213 lnp->l_a.la_sp= symlookup(string,DEFINING,0);
214 lnp->l_next = curpro.lastline;
215 curpro.lastline = lnp;
219 lnp = newline(OPNUMLAB);
220 lnp->l_instr = op_lab;
221 lnp->l_a.la_np = numlookup((unsigned) tabval);
222 if (lnp->l_a.la_np->n_line != (line_p) 0)
223 error("label %u multiple defined",(unsigned) tabval);
224 lnp->l_a.la_np->n_line = lnp;
225 lnp->l_next = curpro.lastline;
226 curpro.lastline = lnp;
235 * Now we have an instruction number in instr
236 * There might be an operand, look for it
239 if ((em_flag[instr-sp_fmnem]&EM_PAR)==PAR_NO) {
241 } else switch(table2()) {
243 error("unknown offset byte");
248 if ((em_flag[instr-sp_fmnem]&EM_PAR)!= PAR_B) {
250 lnp = newline(tabval+Z_OPMINI);
252 lnp = newline(OPSHORT);
253 lnp->l_a.la_short = tabval;
256 lnp = newline(OPNUMLAB);
257 lnp->l_a.la_np = numlookup((unsigned) tabval);
262 lnp = newline(OPOFFSET);
263 lnp->l_a.la_offset = tabval2;
268 lnp = newline(OPNUMLAB);
269 lnp->l_a.la_np = numlookup((unsigned) tabval);
272 lnp = newline(OPSYMBOL);
273 lnp->l_a.la_sp = symlookup(string,OCCURRING,0);
276 lnp = newline(OPSYMBOL);
277 lnp->l_a.la_sp = symlookup(string,OCCURRING,SYMPRO);
280 lnp = newline(OPSVAL);
281 lnp->l_a.la_sval.lasv_sp = symlookup(string,OCCURRING,0);
282 lnp->l_a.la_sval.lasv_short = tabval;
286 lnp = newline(OPLVAL);
287 lnp->l_a.la_lval.lalv_sp = symlookup(string,OCCURRING,0);
288 lnp->l_a.la_lval.lalv_offset = tabval2;
292 lnp->l_instr = instr;
293 lnp->l_next = curpro.lastline;
294 curpro.lastline = lnp;
298 argstring(length,abp) offset length; register argb_p abp; {
301 if (abp->ab_index == NARGBYTES)
302 abp = abp->ab_next = newargb();
303 abp->ab_contents[abp->ab_index++] = readbyte();
307 line_p arglist(n) int n; {
309 register arg_p ap,*app;
315 * creates an arglist with n elements
316 * if n == 0 the arglist is variable and terminated by sp_cend
319 lnp = newline(OPLIST);
320 app = &lnp->l_a.la_arg;
325 error("unknown byte in arglist");
327 tabval2 = (offset) tabval;
329 *app = ap = newarg(ARGOFF);
330 ap->a_a.a_offset = tabval2;
335 *app = ap = newarg(ARGNUM);
336 ap->a_a.a_np = numlookup((unsigned) tabval);
337 ap->a_a.a_np->n_flags |= NUMDATA;
341 *app = ap = newarg(ARGSYM);
342 ap->a_a.a_sp = symlookup(string,OCCURRING,0);
346 *app = ap = newarg(ARGSYM);
347 ap->a_a.a_sp = symlookup(string,OCCURRING,SYMPRO);
351 tabval2 = (offset) tabval;
353 *app = ap = newarg(ARGVAL);
354 ap->a_a.a_val.av_sp = symlookup(string,OCCURRING,0);
355 ap->a_a.a_val.av_offset = tabval2;
359 *app = ap = newarg(ARGSTR);
361 argstring(length,&ap->a_a.a_string);
365 *app = ap = newarg(ARGICN);
368 *app = ap = newarg(ARGUCN);
371 *app = ap = newarg(ARGFCN);
374 ap->a_a.a_con.ac_length = (short) length;
375 argstring(getoff(),&ap->a_a.a_con.ac_con);
383 } while (moretocome);
387 offset aoff(ap,n) register arg_p ap; {
395 error("too few parameters");
396 if (ap->a_typ != ARGOFF)
397 error("offset expected");
398 return(ap->a_a.a_offset);
401 int inpseudo(n) short n; {
402 register line_p lnp,head,tail;
408 if (pcount++ >= PSEUBETWEEN && prodepth==0) {
416 error("unknown pseudo");
429 lnp = newline(OPSYMBOL);
430 lnp->l_a.la_sp = getsym(NOTHING);
433 n1 = getint(); n2 = getint();
434 if (n1 != 0 && n2 != 0) {
435 tail = curpro.lastline;
436 while (--n2) tail = tail->l_next;
438 while (n1--) head = head->l_next;
440 tail->l_next = head->l_next;
441 head->l_next = curpro.lastline;
442 curpro.lastline = lnp;
448 switch((int) aoff(lnp->l_a.la_arg,0)) {
450 draininput(); exit(-1);
454 wordsize = aoff(lnp->l_a.la_arg,1);
455 pointersize = aoff(lnp->l_a.la_arg,2);
458 error("This optimizer cannot handle wordsize>2");
463 /* Treat as empty mes ms_reg */
466 regvar(lnp->l_a.la_arg->a_next);
469 n=ps_exc; /* kludge to force out this line */
475 n=ps_exc; /* kludge to force out this line */
484 curpro.symbol = getsym(DEFINING);
487 curpro.localbytes = (offset) -1;
490 tabval2 = (offset) tabval;
492 curpro.localbytes = tabval2;
495 error("bad second arg of PRO");
502 curpro.lastline = (line_p) 0;
503 curpro.freg = (reg_p) 0;
504 for(i=0;i<NNUMHASH;i++)
505 curpro.numhash[i] = (num_p) 0;
513 error("END misplaced");
516 if (curpro.localbytes == (offset) -1)
517 error("bytes for locals still unknown");
520 tabval2 = (offset) tabval;
522 if (curpro.localbytes != (offset) -1 && curpro.localbytes != tabval2)
523 error("inconsistency in number of bytes for locals");
524 curpro.localbytes = tabval2;
528 curpro.symbol = (sym_p) 0;
539 lnp->l_next = curpro.lastline;
540 curpro.lastline = lnp;
547 error("This is not allowed outside a procedure");