1 /* $Id: em.c,v 1.12 1994/06/24 12:26:49 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
11 /* This file is used to shield code.c as much as possible from em dependant
12 * details. It introduces some call overhead but not enough for a coffee
14 * Note that functions with a leading upper case letter normally decide between
15 * word or double word arith.
18 int wz = 4, pz = 4, vz = 4;
25 C_init((arith) wz, (arith) pz);
28 void openfile(file) char *file;
30 if (C_open(file) < 0) {
31 fatal("Could not open output file");
37 C_ms_emx((arith) wz, (arith) pz);
42 long max = (1L << (8*wz-1)) - 1;
44 rom(wz, 0L); rom(wz, max); rom(wz, (long) (wz+vz));
46 rom(wz, 0L); rom(wz, max); rom(wz, (long) vz);
48 rom(wz, 0L); rom(wz, max); rom(wz, 1L);
51 int new_label(L) register *L;
57 void Label(L) register L;
59 if (L!=0) C_df_ilb((label) L);
64 int new_dot_label(L) int *L;
66 return *L= ++Dot_label;
69 void dot_label(L) int L;
74 void branch(L) int *L;
76 C_bra((label) new_label(L));
79 char *proc_label(L, name) register L; register char *name;
84 if (lab!=nil) free(lab);
86 lab=Malloc(strlen(name)+(1+sizeof(int)*3+1));
87 /* That is: P<L><name>\0 */
89 sprint(lab, "P%d", L);
94 *n++ = *name=='.' ? '_' : *name;
101 void magic() /* magic? should be called invisible */
124 void Loc(cst) long cst;
126 if (vz>wz) C_ldc((arith) cst); else C_loc((arith) cst);
129 void Lol(offset) int offset;
131 if (vz>wz) C_ldl((arith) offset); else C_lol((arith) offset);
134 void Lolp(offset) int offset;
136 if (pz>wz) C_ldl((arith) offset); else C_lol((arith) offset);
139 void Lil(offset) register offset;
145 C_lil((arith) offset);
148 void Lof(offset) int offset;
150 if (vz>wz) C_ldf((arith) offset); else C_lof((arith) offset);
153 void Lofp(offset) int offset;
155 if (pz>wz) C_ldf((arith) offset); else C_lof((arith) offset);
158 void Lif(offset) register offset;
164 void Stl(offset) int offset;
166 if (vz>wz) C_sdl((arith) offset); else C_stl((arith) offset);
169 void Inl(offset) register offset;
172 C_ldl((arith) offset);
175 C_sdl((arith) offset);
177 C_inl((arith) offset);
180 void Del(offset) register offset;
183 C_ldl((arith) offset);
186 C_sdl((arith) offset);
188 C_del((arith) offset);
191 void Loe(name, offset) char *name; int offset;
194 C_lde_dnam(name, (arith) offset);
196 C_loe_dnam(name, (arith) offset);
199 static int operators[]= { '<', '>', '=', GE, LE, NE };
201 void bxx(pos, op, L) register pos, op, L;
211 if (pos) C_zle((label) L); else C_zgt((label) L);
213 for (i=0; operators[i]!=op; i++) ;
214 if (pos && (i+=3)>=6) i-=6;
262 void Txx(op) register int op;
288 void xxi(op) register op;
309 void aar() { C_aar((arith) wz); }
310 void adp(offset) int offset; { C_adp((arith) offset); }
311 void and() { C_and((arith) vz); }
312 void asp(size) int size; { C_asp((arith) size); }
313 void blm(size) int size; { C_blm((arith) size); }
314 void blt(lab) int lab; { C_blt((label) lab); }
315 void cal(lab) char *lab; { C_cal(lab); }
316 void cmi() { C_cmi((arith) vz); }
317 void com() { C_com((arith) vz); }
318 void del(offset) int offset; { C_del((arith) offset); }
319 void x_end(size) int size; { C_end((arith) size); }
320 void exp(lab) char *lab; { C_exp(lab); }
321 void ior() { C_ior((arith) vz); }
322 void lae(lab, offset) char *lab; int offset;
323 { C_lae_dnam(lab, (arith) offset); }
324 void laedot(lab) int lab; { C_lae_dlb((label) lab, (arith) 0); }
325 void lal(offset) int offset; { C_lal((arith) offset); }
326 void lar() { C_lar((arith) wz); }
327 void ldc0() { C_ldc((arith) 0); }
328 void ldl(offset) int offset; { C_ldl((arith) offset); }
329 void lfr(size) int size; { C_lfr((arith) size); }
330 void loc(cst) int cst; { C_loc((arith) cst); }
331 void loi(size) int size; { C_loi((arith) size); }
332 void lol(offset) int offset; { C_lol((arith) offset); }
333 void lor0() { C_lor((arith) 0); }
334 void lxa(offset) int offset; { C_lxa((arith) offset); }
335 void lxl(offset) int offset; { C_lxl((arith) offset); }
336 void meserr() { C_ms_err(); }
337 void ngi() { C_ngi((arith) vz); }
338 void pro(lab) char *lab; { C_pro_narg(lab); }
339 void ret(size) int size; { C_ret((arith) size); }
340 void init_rt() { C_cal("init"); }
341 void sli() { C_sli((arith) vz); }
342 void sri() { C_sri((arith) vz); }
343 void ste(lab, offset) char *lab; int offset;
344 { C_ste_dnam(lab, (arith) offset); }
345 void sti(size) int size; { C_sti((arith) size); }
346 void stl(offset) int offset; { C_stl((arith) offset); }
347 void trp() { C_trp(); }
348 void tst() { /* No flags in EM */ }
349 void xor() { C_xor((arith) vz); }
350 void zeq(lab) int lab; { C_zeq((label) lab); }
351 void zgt(lab) int lab; { C_zgt((label) lab); }
352 void zlt(lab) int lab; { C_zlt((label) lab); }
353 void zne(lab) int lab; { C_zne((label) lab); }
355 char *itoa(i) long i;
357 static char a[sizeof(long)*3];
362 void rom(size, c) int size; long c;
364 C_rom_icon(itoa(c), (arith) size);
374 C_lin((arith) (oldline=lineno));
377 static struct ftree {
380 struct ftree *left, *right;
381 } std_f = { "stdin", 0, nil, nil }, *curr_f= &std_f, *main_f=nil;
383 char *curr_file="stdin";
385 static void do_fil(f) struct ftree *f;
389 dot_label(new_dot_label(&f->lab));
390 C_rom_scon(f->file, (arith) (strlen(f->file)+1));
392 C_fil_dlb((label) f->lab, (arith) 0);
402 do_fil(main_f==nil ? &std_f : main_f);
405 int set_file(f) char *f;
408 static struct ftree *ftop=nil;
409 register struct ftree *pf, **apf= &ftop;
412 while ((pf= *apf)!=nil && (cmp=strcmp(f, pf->file))!=0)
413 apf= cmp<0 ? &pf->left : &pf->right;
416 *apf= pf= (struct ftree *) Malloc(sizeof *pf);
417 pf->file=strcpy(Malloc(strlen(f)+1), f);
419 pf->left=pf->right=nil;
427 return curr_f!=main_f;
433 C_lal((arith) curr_offset);
435 C_asp((arith) (2*pz));
438 void par_fork(NONZERO) int *NONZERO;
444 C_zne((label) new_label(NONZERO));
454 C_zre_dnam("deadlock", (arith) 0);