1987-03-10 11:49:39 +00:00
|
|
|
/* $Header$ */
|
1987-03-09 16:02:32 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1987-02-24 17:05:53 +00:00
|
|
|
#include "sizes.h"
|
|
|
|
#include "Lpars.h"
|
1987-02-25 16:56:31 +00:00
|
|
|
#include <em.h>
|
1987-02-24 17:05:53 +00:00
|
|
|
#include "em.h"
|
|
|
|
|
|
|
|
/* This file is used to shield code.c as much as possible from em dependant
|
|
|
|
* details. It introduces some call overhead but not enough for a coffee
|
|
|
|
* break. (Sorry)
|
|
|
|
* Note that functions with a leading upper case letter normally decide between
|
|
|
|
* word or double word arith.
|
|
|
|
*/
|
|
|
|
|
1987-02-25 16:56:31 +00:00
|
|
|
int wz = 4, pz = 4, vz = 4;
|
|
|
|
int Lflag;
|
1987-02-24 17:05:53 +00:00
|
|
|
static Lab=0;
|
1988-07-18 16:41:04 +00:00
|
|
|
char *Malloc();
|
1987-02-24 17:05:53 +00:00
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
C_init((arith) wz, (arith) pz);
|
|
|
|
}
|
|
|
|
|
|
|
|
void openfile(file) char *file;
|
|
|
|
{
|
1987-02-25 16:56:31 +00:00
|
|
|
if (C_open(file) < 0) {
|
|
|
|
fatal("Could not open output file");
|
|
|
|
}
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void meswp()
|
|
|
|
{
|
1987-02-25 16:56:31 +00:00
|
|
|
C_ms_emx((arith) wz, (arith) pz);
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void maxdes()
|
|
|
|
{
|
1991-09-25 15:04:02 +00:00
|
|
|
long max = (1L << (8*wz-1)) - 1;
|
1987-02-24 17:05:53 +00:00
|
|
|
C_df_dnam("maxcdes");
|
1991-09-25 15:04:02 +00:00
|
|
|
rom(wz, 0L); rom(wz, max); rom(wz, (long) (wz+vz));
|
1987-02-24 17:05:53 +00:00
|
|
|
C_df_dnam("maxwdes");
|
1991-09-25 15:04:02 +00:00
|
|
|
rom(wz, 0L); rom(wz, max); rom(wz, (long) vz);
|
1987-02-24 17:05:53 +00:00
|
|
|
C_df_dnam("maxbdes");
|
1991-09-25 15:04:02 +00:00
|
|
|
rom(wz, 0L); rom(wz, max); rom(wz, 1L);
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int new_label(L) register *L;
|
|
|
|
{
|
|
|
|
if (*L==0) *L= ++Lab;
|
|
|
|
return *L;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Label(L) register L;
|
|
|
|
{
|
|
|
|
if (L!=0) C_df_ilb((label) L);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Dot_label=0;
|
|
|
|
|
|
|
|
int new_dot_label(L) int *L;
|
|
|
|
{
|
|
|
|
return *L= ++Dot_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dot_label(L) int L;
|
|
|
|
{
|
|
|
|
C_df_dlb((label) L);
|
|
|
|
}
|
|
|
|
|
|
|
|
void branch(L) int *L;
|
|
|
|
{
|
|
|
|
C_bra((label) new_label(L));
|
|
|
|
}
|
|
|
|
|
|
|
|
char *proc_label(L, name) register L; register char *name;
|
|
|
|
{
|
|
|
|
static char *lab=nil;
|
|
|
|
register char *n;
|
|
|
|
|
|
|
|
if (lab!=nil) free(lab);
|
|
|
|
|
1988-07-18 16:41:04 +00:00
|
|
|
lab=Malloc(strlen(name)+(1+sizeof(int)*3+1));
|
1987-02-24 17:05:53 +00:00
|
|
|
/* That is: P<L><name>\0 */
|
|
|
|
|
1987-02-25 16:56:31 +00:00
|
|
|
sprint(lab, "P%d", L);
|
1987-02-24 17:05:53 +00:00
|
|
|
|
|
|
|
n=lab+strlen(lab);
|
|
|
|
|
|
|
|
while (*name!=0) {
|
|
|
|
*n++ = *name=='.' ? '_' : *name;
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
*n=0;
|
|
|
|
return lab;
|
|
|
|
}
|
|
|
|
|
|
|
|
void magic() /* magic? should be called invisible */
|
|
|
|
{
|
|
|
|
C_magic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cwv()
|
|
|
|
{
|
|
|
|
if (vz>wz) {
|
|
|
|
C_loc((arith) wz);
|
|
|
|
C_loc((arith) vz);
|
|
|
|
C_cii();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cvw()
|
|
|
|
{
|
|
|
|
if (vz>wz) {
|
|
|
|
C_loc((arith) vz);
|
|
|
|
C_loc((arith) wz);
|
|
|
|
C_cii();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Loc(const) long const;
|
|
|
|
{
|
|
|
|
if (vz>wz) C_ldc((arith) const); else C_loc((arith) const);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lol(offset) int offset;
|
|
|
|
{
|
|
|
|
if (vz>wz) C_ldl((arith) offset); else C_lol((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lolp(offset) int offset;
|
|
|
|
{
|
|
|
|
if (pz>wz) C_ldl((arith) offset); else C_lol((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lil(offset) register offset;
|
|
|
|
{
|
|
|
|
if (vz>wz) {
|
|
|
|
Lolp(offset);
|
|
|
|
C_loi((arith) vz);
|
|
|
|
} else
|
|
|
|
C_lil((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lof(offset) int offset;
|
|
|
|
{
|
|
|
|
if (vz>wz) C_ldf((arith) offset); else C_lof((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lofp(offset) int offset;
|
|
|
|
{
|
|
|
|
if (pz>wz) C_ldf((arith) offset); else C_lof((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lif(offset) register offset;
|
|
|
|
{
|
|
|
|
Lofp(offset);
|
|
|
|
C_loi((arith) vz);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stl(offset) int offset;
|
|
|
|
{
|
|
|
|
if (vz>wz) C_sdl((arith) offset); else C_stl((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Inl(offset) register offset;
|
|
|
|
{
|
|
|
|
if (vz>wz) {
|
|
|
|
C_ldl((arith) offset);
|
|
|
|
C_ldc((arith) 1);
|
|
|
|
C_adi((arith) vz);
|
|
|
|
C_sdl((arith) offset);
|
|
|
|
} else
|
|
|
|
C_inl((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Del(offset) register offset;
|
|
|
|
{
|
|
|
|
if (vz>wz) {
|
|
|
|
C_ldl((arith) offset);
|
|
|
|
C_ldc((arith) 1);
|
|
|
|
C_sbi((arith) vz);
|
|
|
|
C_sdl((arith) offset);
|
|
|
|
} else
|
|
|
|
C_del((arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Loe(name, offset) char *name; int offset;
|
|
|
|
{
|
|
|
|
if (vz>wz)
|
|
|
|
C_lde_dnam(name, (arith) offset);
|
|
|
|
else
|
|
|
|
C_loe_dnam(name, (arith) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int operators[]= { '<', '>', '=', GE, LE, NE };
|
|
|
|
|
|
|
|
void bxx(pos, op, L) register pos, op, L;
|
|
|
|
{
|
|
|
|
register i;
|
|
|
|
|
|
|
|
if (op==AFTER) {
|
|
|
|
C_sbi((arith) vz);
|
|
|
|
if (vz>wz) {
|
|
|
|
C_ldc((arith) 0);
|
|
|
|
C_cmi((arith) vz);
|
|
|
|
}
|
|
|
|
if (pos) C_zle((label) L); else C_zgt((label) L);
|
|
|
|
} else {
|
|
|
|
for (i=0; operators[i]!=op; i++) ;
|
|
|
|
if (pos && (i+=3)>=6) i-=6;
|
|
|
|
if (vz>wz) {
|
|
|
|
C_cmi((arith) vz);
|
1988-02-15 18:04:27 +00:00
|
|
|
switch(i) {
|
|
|
|
case 0:
|
|
|
|
C_zlt((label) L);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
C_zgt((label) L);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
C_zeq((label) L);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
C_zge((label) L);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
C_zle((label) L);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
C_zne((label) L);
|
|
|
|
break;
|
|
|
|
}
|
1987-02-24 17:05:53 +00:00
|
|
|
} else {
|
1988-02-15 18:04:27 +00:00
|
|
|
switch(i) {
|
|
|
|
case 0:
|
|
|
|
C_blt((label) L);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
C_bgt((label) L);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
C_beq((label) L);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
C_bge((label) L);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
C_ble((label) L);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
C_bne((label) L);
|
|
|
|
break;
|
|
|
|
}
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Txx(op) register int op;
|
|
|
|
{
|
1988-02-15 18:04:27 +00:00
|
|
|
switch(op) {
|
|
|
|
case '<':
|
|
|
|
C_tlt();
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
C_tgt();
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
C_teq();
|
|
|
|
break;
|
|
|
|
case GE:
|
|
|
|
C_tge();
|
|
|
|
break;
|
|
|
|
case LE:
|
|
|
|
C_tle();
|
|
|
|
break;
|
|
|
|
case NE:
|
|
|
|
C_tne();
|
|
|
|
break;
|
|
|
|
}
|
1987-02-24 17:05:53 +00:00
|
|
|
cwv();
|
|
|
|
C_ngi((arith) vz);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xxi(op) register op;
|
|
|
|
{
|
1988-02-15 18:04:27 +00:00
|
|
|
switch(op) {
|
|
|
|
case '+':
|
|
|
|
C_adi((arith) vz);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
C_sbi((arith) vz);
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
C_mli((arith) vz);
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
C_dvi((arith) vz);
|
|
|
|
break;
|
|
|
|
case BS:
|
|
|
|
C_rmi((arith) vz);
|
|
|
|
break;
|
|
|
|
}
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void aar() { C_aar((arith) wz); }
|
|
|
|
void adp(offset) int offset; { C_adp((arith) offset); }
|
|
|
|
void and() { C_and((arith) vz); }
|
|
|
|
void asp(size) int size; { C_asp((arith) size); }
|
|
|
|
void blm(size) int size; { C_blm((arith) size); }
|
|
|
|
void blt(lab) int lab; { C_blt((label) lab); }
|
|
|
|
void cal(lab) char *lab; { C_cal(lab); }
|
|
|
|
void cmi() { C_cmi((arith) vz); }
|
|
|
|
void com() { C_com((arith) vz); }
|
|
|
|
void del(offset) int offset; { C_del((arith) offset); }
|
|
|
|
void _end(size) int size; { C_end((arith) size); }
|
|
|
|
void exp(lab) char *lab; { C_exp(lab); }
|
|
|
|
void ior() { C_ior((arith) vz); }
|
|
|
|
void lae(lab, offset) char *lab; int offset;
|
|
|
|
{ C_lae_dnam(lab, (arith) offset); }
|
|
|
|
void laedot(lab) int lab; { C_lae_dlb((label) lab, (arith) 0); }
|
|
|
|
void lal(offset) int offset; { C_lal((arith) offset); }
|
|
|
|
void lar() { C_lar((arith) wz); }
|
|
|
|
void ldc0() { C_ldc((arith) 0); }
|
|
|
|
void ldl(offset) int offset; { C_ldl((arith) offset); }
|
|
|
|
void lfr(size) int size; { C_lfr((arith) size); }
|
|
|
|
void loc(cst) int cst; { C_loc((arith) cst); }
|
|
|
|
void loi(size) int size; { C_loi((arith) size); }
|
|
|
|
void lol(offset) int offset; { C_lol((arith) offset); }
|
|
|
|
void lor0() { C_lor((arith) 0); }
|
|
|
|
void lxa(offset) int offset; { C_lxa((arith) offset); }
|
|
|
|
void lxl(offset) int offset; { C_lxl((arith) offset); }
|
1987-02-25 16:56:31 +00:00
|
|
|
void meserr() { C_ms_err(); }
|
1987-02-24 17:05:53 +00:00
|
|
|
void ngi() { C_ngi((arith) vz); }
|
|
|
|
void pro(lab) char *lab; { C_pro_narg(lab); }
|
|
|
|
void ret(size) int size; { C_ret((arith) size); }
|
|
|
|
void init_rt() { C_cal("init"); }
|
|
|
|
void sli() { C_sli((arith) vz); }
|
|
|
|
void sri() { C_sri((arith) vz); }
|
|
|
|
void ste(lab, offset) char *lab; int offset;
|
|
|
|
{ C_ste_dnam(lab, (arith) offset); }
|
|
|
|
void sti(size) int size; { C_sti((arith) size); }
|
|
|
|
void stl(offset) int offset; { C_stl((arith) offset); }
|
|
|
|
void trp() { C_trp(); }
|
|
|
|
void tst() { /* No flags in EM */ }
|
|
|
|
void xor() { C_xor((arith) vz); }
|
|
|
|
void zeq(lab) int lab; { C_zeq((label) lab); }
|
|
|
|
void zgt(lab) int lab; { C_zgt((label) lab); }
|
|
|
|
void zlt(lab) int lab; { C_zlt((label) lab); }
|
|
|
|
void zne(lab) int lab; { C_zne((label) lab); }
|
|
|
|
|
|
|
|
char *itoa(i) long i;
|
|
|
|
{
|
|
|
|
static char a[sizeof(long)*3];
|
1987-02-25 16:56:31 +00:00
|
|
|
sprint(a, "%ld", i);
|
1987-02-24 17:05:53 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rom(size, c) int size; long c;
|
|
|
|
{
|
|
|
|
C_rom_icon(itoa(c), (arith) size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lin()
|
|
|
|
{
|
|
|
|
static oldline=0;
|
1991-01-11 14:32:43 +00:00
|
|
|
extern lineno;
|
1987-02-24 17:05:53 +00:00
|
|
|
|
1987-02-25 16:56:31 +00:00
|
|
|
if (Lflag) return;
|
1991-01-11 14:32:43 +00:00
|
|
|
if (lineno!=oldline)
|
|
|
|
C_lin((arith) (oldline=lineno));
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ftree {
|
|
|
|
char *file;
|
|
|
|
int lab;
|
|
|
|
struct ftree *left, *right;
|
|
|
|
} std_f = { "stdin", 0, nil, nil }, *curr_f= &std_f, *main_f=nil;
|
|
|
|
|
|
|
|
char *curr_file="stdin";
|
|
|
|
|
|
|
|
static void do_fil(f) struct ftree *f;
|
|
|
|
{
|
1987-02-25 16:56:31 +00:00
|
|
|
if (Lflag) return;
|
1987-02-24 17:05:53 +00:00
|
|
|
if (f->lab==0) {
|
|
|
|
dot_label(new_dot_label(&f->lab));
|
1987-02-25 16:56:31 +00:00
|
|
|
C_rom_scon(f->file, (arith) (strlen(f->file)+1));
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
1988-02-15 18:04:27 +00:00
|
|
|
C_fil_dlb((label) f->lab, (arith) 0);
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fil()
|
|
|
|
{
|
|
|
|
do_fil(curr_f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main_fil()
|
|
|
|
{
|
|
|
|
do_fil(main_f==nil ? &std_f : main_f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_file(f) char *f;
|
|
|
|
{
|
|
|
|
char *strcpy();
|
|
|
|
static struct ftree *ftop=nil;
|
|
|
|
register struct ftree *pf, **apf= &ftop;
|
|
|
|
register cmp;
|
|
|
|
|
|
|
|
while ((pf= *apf)!=nil && (cmp=strcmp(f, pf->file))!=0)
|
|
|
|
apf= cmp<0 ? &pf->left : &pf->right;
|
|
|
|
|
|
|
|
if (pf==nil) {
|
1988-07-18 16:41:04 +00:00
|
|
|
*apf= pf= (struct ftree *) Malloc(sizeof *pf);
|
|
|
|
pf->file=strcpy(Malloc(strlen(f)+1), f);
|
1987-02-24 17:05:53 +00:00
|
|
|
pf->lab=0;
|
|
|
|
pf->left=pf->right=nil;
|
|
|
|
}
|
|
|
|
curr_f=pf;
|
|
|
|
curr_file=pf->file;
|
|
|
|
if (main_f==nil) {
|
|
|
|
main_f=curr_f;
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return curr_f!=main_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void par_begin()
|
|
|
|
{
|
1988-02-15 18:04:27 +00:00
|
|
|
C_zer((arith) pz);
|
1987-02-24 17:05:53 +00:00
|
|
|
C_lal((arith) curr_offset);
|
|
|
|
C_cal("pc_begin");
|
1988-02-15 18:04:27 +00:00
|
|
|
C_asp((arith) (2*pz));
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void par_fork(NONZERO) int *NONZERO;
|
|
|
|
{
|
1988-02-15 18:04:27 +00:00
|
|
|
C_zer((arith) pz);
|
1987-02-24 17:05:53 +00:00
|
|
|
C_cal("pc_fork");
|
1988-07-18 16:41:04 +00:00
|
|
|
C_asp((arith) pz);
|
1987-02-24 17:05:53 +00:00
|
|
|
C_lfr((arith) wz);
|
|
|
|
C_zne((label) new_label(NONZERO));
|
|
|
|
}
|
|
|
|
|
|
|
|
void resumenext()
|
|
|
|
{
|
1988-02-15 18:04:27 +00:00
|
|
|
C_cal("resumenext");
|
1987-02-24 17:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void no_deadlock()
|
|
|
|
{
|
|
|
|
C_zre_dnam("deadlock", (arith) 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void par_end()
|
|
|
|
{
|
|
|
|
C_cal("parend");
|
|
|
|
}
|
|
|
|
|
|
|
|
void closefile()
|
|
|
|
{
|
|
|
|
C_close();
|
|
|
|
}
|