2 static char rcsid2[] = "$Id: fillem.c,v 2.14 1994/06/24 13:23:38 ceriel Exp $";
16 #include <cg_pattern.h>
26 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
27 * See the copyright notice in the ACK home directory, in the file "Copyright".
29 * Author: Hans van Staveren
32 #ifndef newplb /* retrofit for older mach.h */
38 It is an error to define both fmt_id and id_first.
39 Read the documentation.
45 It is an error to define both fmt_ilb and ilb_fmt.
46 Read the documentation.
50 /* segment types for switchseg() */
58 #define get8() getc(emfile)
63 extern FILE *codefile;
64 extern FILE *freopen();
66 int nextispseu,savetab1;
71 char str[MAXSTR],argstr[128],labstr[128];
83 extern char em_flag[];
84 extern short em_ptyp[];
87 /* Own version of atol that continues computing on overflow.
88 We don't know that about the ANSI C one.
93 register long total = 0;
94 register unsigned digit;
97 while (*s == ' ' || *s == '\t') s++;
103 while ((digit = *s++ - '0') < 10) {
107 return(minus ? -total : total);
110 #define sp_cstx sp_cst2
118 in_init(filename) char *filename; {
120 if ((emfile=freopen(filename,"r",stdin))==NULL)
121 error("Can't open %s",filename);
122 if (get16()!=sp_magic)
123 error("Bad format %s",filename);
128 fprintf(codefile,"%s",modhead) ;
137 register struct emline *lp;
139 while ((emlines+nemlines)-emp<MAXEMLINES-5) {
140 assert(nemlines<MAXEMLINES);
142 emlines[nemlines].em_instr=0;
145 lp = &emlines[nemlines++];
149 error("unknown instruction byte");
156 nextispseu=1; savetab1=t;
161 nextispseu=1; savetab1=t;
167 lp->em_instr = opcode;
170 i=em_flag[lp->em_instr-sp_fmnem] & EM_PAR;
180 assert(t == sp_cstx);
183 lp->em_optyp = OPINT;
184 lp->em_u.em_ioper = argval;
185 lp->em_soper = tostring((word) argval);
190 lp->em_optyp = OPSYMBOL;
191 lp->em_soper = holstr((word) argval);
197 assert(t == sp_cstx);
198 lp->em_optyp = OPSYMBOL;
199 lp->em_soper = strarg(t);
200 lp->em_u.em_loper = argval;
203 lp->em_soper = strarg(t);
206 else if (t==sp_cstx) {
207 lp->em_optyp = OPINT;
208 lp->em_u.em_ioper = argval;
210 lp->em_optyp = OPSYMBOL;
218 word romcont[MAXROM+1];
221 unsigned dummy,stackupto();
223 if (nextispseu==0 || nemlines>0)
224 error("No table entry for %d",emlines[0].em_instr);
230 dummy = stackupto(&fakestack[stackheight-1],maxply,TRUE);
249 error("Unknown opcode %d",savetab1);
253 sprintf(labstr,hol_fmt,++holno);
257 t = getarg(val_ptyp);
267 con(getarg(val_ptyp));
268 while ((t = getarg(any_ptyp)) != sp_cend)
280 if (t==sp_cstx && nromwords<MAXROM) {
281 romcont[nromwords] = (word) argval;
292 if (c == ps_rom) continue;
293 if (c !=EOF) ungetc(c, emfile);
298 romcont[MAXROM]=rommask;
299 enterglo(labstr,romcont);
304 getarg(ptyp(sp_cst2));
305 if (argval == ms_emx) {
306 getarg(ptyp(sp_cst2));
307 if (argval != TEM_WSIZE)
308 fatal("bad word size");
309 getarg(ptyp(sp_cst2));
310 if (argval != TEM_PSIZE)
311 fatal("bad pointer size");
312 if ( getarg(any_ptyp)!=sp_cend )
313 fatal("too many parameters");
315 } else if (argval == ms_gto) {
316 getarg(ptyp(sp_cend));
318 error("mes 3 not allowed here");
321 } else if (argval == ms_reg) {
323 int r_size,r_type,r_score;
324 struct regvar *linkreg();
327 error("mes 3 not allowed here");
328 if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend) {
335 getarg(ptyp(sp_cst2));
337 getarg(ptyp(sp_cst2));
339 if (r_type<reg_any || r_type>reg_float)
340 fatal("Bad type in register message");
341 if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend)
345 if ( getarg(any_ptyp)!=sp_cend )
346 fatal("too many parameters");
348 tryreg(linkreg(r_off,r_size,r_type,r_score),r_type);
355 strarg(getarg(sym_ptyp));
359 strarg(getarg(sym_ptyp));
363 strarg(getarg(ptyp(sp_pnam)));
367 strarg(getarg(ptyp(sp_pnam)));
373 strarg(getarg(ptyp(sp_pnam)));
376 prolog((full)argval);
382 getarg(cst_ptyp | ptyp(sp_cend));
390 error("No table entry for %d",savetab1);
394 /* ----- input ----- */
399 argtyp = t = table2();
401 fatal("unexpected EOF");
404 if ((typset & t) == 0)
405 error("bad argument type %d",argtyp);
413 if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
417 if (i < sp_fpseu+sp_npseu && i >= sp_fpseu) {
421 if (i < sp_filb0+sp_nilb0 && i >= sp_filb0) {
422 argval = i - sp_filb0;
432 if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
433 argval = i - sp_zcst0;
467 offtyp = getarg(sym_ptyp);
474 consiz = (word) argval;
483 register int l_byte, h_byte;
487 if ( h_byte>=128 ) h_byte -= 256 ;
488 return l_byte | (h_byte*256) ;
496 l |= ((unsigned) get8())*256 ;
497 l |= get8()*256L*256L ;
499 if ( h_byte>=128 ) h_byte -= 256 ;
500 return l | (h_byte*256L*256*256L) ;
508 if (argval < 0 || argval > MAXSTR-1)
509 fatal("string/identifier too long");
510 strsiz = n = (int) argval;
524 fmt_ilb(procno,((int) argval),argstr);
526 sprintf(argstr,ilb_fmt,procno,(int)argval);
531 sprintf(argstr,dlb_fmt,dlbval);
534 sprintf(argstr,cst_fmt,(full)argval);
542 if (strsiz < 8 || str[0] == id_first)
544 sprintf(p,"%.*s",strsiz,str);
549 for (p = argstr; *p; p++)
551 if ((full) argval >= 0)
555 argval = - (full) argval;
557 sprintf(p,off_fmt,(full)argval);
562 return(mystrcpy(argstr));
569 fatal("bad BSS size");
572 || (t==sp_cstx && argval==BSS_INIT)
573 #endif /* BSS_INIT */
585 fatal("bad BSS initializer");
598 return((long)TEM_PSIZE);
605 return((long)TEM_PSIZE);
607 con_part(TEM_WSIZE,(word)argval);
608 return((long)TEM_WSIZE);
610 for (i = 0; i < strsiz; i++)
611 con_part(1,(word) str[i]);
612 return((long)strsiz);
615 if (argval > TEM_WSIZE) {
617 con_mult((word)argval);
619 con_part((int)argval,(word)atol(str));
631 extern char *segname[];
642 if ((curseg = s) >= 0)
643 fprintf(codefile,"%s\n",segname[s]);
651 dlbdlb(argstr,labstr);
664 assert(part_size == 0);
673 assert(part_size == 0);
680 * Each new data fragment and each data label starts at
681 * a new target machine word
690 string holstr(n) word n; {
692 sprintf(str,hol_off,n,holno);
693 return(mystrcpy(str));
697 /* ----- machine dependent routines ----- */