2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
9 static char rcs_id[] = "$Id: graph.c,v 1.2 1994/06/24 11:30:49 ceriel Exp $" ;
15 Linerecord *firstline,
25 /* NOSTRICT */ l = (List *) salloc(sizeof(List));
30 /* Line management is handled here */
32 Linerecord *srchline(nr)
37 for(l=firstline;l && l->linenr<=nr;l= l->nextline)
38 if ( l->linenr== nr) return(l);
49 for(l=forwardlabel;l ;l=l->nextlist)
50 if ( l->linenr== nr) return(l);
64 if ( !srchline(l->linenr))
66 fprint(STDERR, "ERROR: line %d not defined\n",l->linenr);
81 if ( debug) print("newblock at %d\n",nr);
82 if ( nr>0 && currline && currline->linenr>= nr)
84 if ( debug) print("old line:%d\n",currline->linenr);
85 error("Lines out of sequence");
88 frwrd=srchforward(nr);
89 if ( frwrd && debug) print("forward found %d\n",frwrd->emlabel);
93 error("Line redefined");
97 /* make new EM block structure */
98 /* NOSTRICT */ l= (Linerecord *) salloc(sizeof(*l));
99 l->emlabel= frwrd ? frwrd->emlabel : genlabel();
102 /* insert this record */
105 currline->nextline=l;
106 l->prevline= currline;
107 lastline= currline=l;
109 firstline = lastline =currline=l;
117 /* simulate a goto statement in the line record table */
121 if (debug) print("goto label %d\n",nr);
122 /* update currline */
125 ll-> nextlist= currline->gotos;
128 /* try to generate code */
130 if ( (ll=srchforward(nr))!=0)
135 /* declare forward label */
136 if (debug) print("declare forward %d\n",nr);
138 ll->emlabel= genlabel();
140 ll->nextlist= forwardlabel;
143 } else nr= l1->emlabel;
152 C_bra((label) gotolabel(nr));
155 /* GOSUB-return, assume that proper entries are made to subroutines
156 only. The return statement is triggered by a fake constant label */
158 List *gosubhead, *gotail;
169 l->emlabel=genlabel();
173 } else gotail= gosubhead=l;
191 /* administer legal return */
193 C_asp((arith) BEMINTSIZE);
195 C_df_ilb((label)l->emlabel);
205 C_df_dnam("returns");
206 C_rom_ilb((label) nr);
208 C_rom_cst((arith) (gosubcnt-1));
212 C_rom_ilb((label) gosubhead->emlabel);
213 gosubhead= gosubhead->nextlist;
215 C_df_ilb((label) nr);
226 C_lfr((arith) BEMINTSIZE);
227 C_lae_dnam("returns",(arith)0);
228 C_csa((arith) BEMINTSIZE);
233 /* compound goto-gosub statements */
234 List *jumphead,*jumptail;
244 l->emlabel= gotolabel(nr);
246 if ( jumphead==0) jumphead = jumptail = l;
248 jumptail->nextlist=l;
259 /* generate the code itself, index in on top of the stack */
260 /* blurh, store the number of entries in the descriptor */
265 /* create descriptor first */
267 firstlabel=genlabel();
268 C_df_dlb((label)descr);
269 C_rom_ilb((label)firstlabel);
270 C_rom_cst((arith) 1);
271 C_rom_cst((arith)(jumpcnt-1));
275 C_rom_ilb((label)l->emlabel);
278 jumphead= jumptail=0; jumpcnt=0;
279 if (debug) print("ongotst:%d labels\n", jumpcnt);
280 conversion(type,INTTYPE);
281 C_dup((arith) BEMINTSIZE);
282 C_zlt(err_goto_label);
283 C_lae_dlb((label) descr,(arith) 0);
284 C_csa((arith) BEMINTSIZE);
285 C_df_ilb((label)firstlabel);
297 /* create descriptor first */
299 firstlabel=genlabel();
300 C_df_dlb((label)descr);
301 C_rom_ilb((label)firstlabel);
303 C_rom_cst((arith)(jumpcnt-1));
308 C_rom_ilb((label)l->emlabel);
312 jumphead= jumptail=0;
316 l->emlabel=firstlabel;
320 } else gotail=gosubhead=l;
321 /* save the return point of the gosub */
322 C_loc((arith) gosubcnt);
324 C_asp((arith) BEMINTSIZE);
327 conversion(type,INTTYPE);
328 C_dup((arith) BEMINTSIZE);
329 C_zlt(err_goto_label);
330 C_lae_dlb((label) descr,(arith) 0);
331 C_csa((arith) BEMINTSIZE);
332 C_df_ilb((label)firstlabel);
338 /* REGION ANALYSIS and FINAL VERSION GENERATION */