Added mechanism to generate C_out

This commit is contained in:
ceriel 1988-09-12 14:30:22 +00:00
parent 115e92a7dc
commit 2f479b6078
6 changed files with 587 additions and 2 deletions

View file

@ -0,0 +1,441 @@
/* $Header$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* makecalls: expand a datastructure as delivered by "EM_getline"
into calls to the procedural interface.
Exported routine:
C_out
*/
#include <em_spec.h>
#include <em_mnem.h>
#include <em_pseu.h>
#include <em_flag.h>
#include "em_ptyp.h"
#include <em.h>
#include <em_comp.h>
#include <assert.h>
extern char em_flag[]; /* One per EM instruction: indicates parameter kind */
extern short em_ptyp[]; /* One per parameter kind: indicates parameter type */
static char *C_error;
static int listtype = 0; /* indicates pseudo when generating code for
variable length argument lists
(only for MES)
*/
#ifdef CHECKING
/* c_getarg: Check the argument indicated by "args".
The argument must be of a type allowed by "typset".
Return a pointer to the next argument.
*/
PRIVATE
checkarg(arg, typset)
register struct e_arg *arg;
{
if (((!typset) && arg->ema_argtype) ||
((!arg->ema_argtype) && typset)) {
/* End of arguments expected, but there are more, or
an argument expected, but there is none
*/
C_error = "Illegal number of parameters";
return 0;
}
if (!(arg->ema_argtype & typset)) {
/* Type error */
C_error = "Illegal parameter type";
return 0;
}
return 1;
}
#else not CHECKING
#define checkarg(arg, x) 1
#endif CHECKING
/* EM_doinstr: An EM instruction
*/
PRIVATE
EM_doinstr(p)
register struct e_instr *p;
{
register int parametertype; /* parametertype of the instruction */
parametertype = em_flag[p->em_opcode-sp_fmnem] & EM_PAR;
#ifdef CHECKING
if (parametertype != PAR_NO && parametertype != PAR_W) {
if (p->em_argtype == 0) {
C_error = "Illegal number of parameters";
return;
}
}
#endif CHECKING
switch(parametertype) {
case PAR_NO:
break;
default:
if (! checkarg(&(p->em_arg), em_ptyp[parametertype])) {
return;
}
break;
case PAR_W:
if (p->em_argtype != 0) {
if (! checkarg(&(p->em_arg), cst_ptyp)) return;
}
else {
#include "C_mnem_narg"
return;
}
break;
}
#include "C_mnem"
}
PRIVATE
EM_dopseudo(p)
register struct e_instr *p;
{
switch(p->em_opcode) {
case ps_exc: {
C_exc(p->em_exc1, p->em_exc2);
break;
}
case ps_hol: {
if (! checkarg(&(p->em_arg), par_ptyp)) break;
switch(p->em_argtype) {
case cst_ptyp:
C_hol_cst(EM_holsize,
p->em_cst,
EM_holinit);
break;
case ico_ptyp:
C_hol_icon(EM_holsize,
p->em_string,
p->em_size,
EM_holinit);
break;
case uco_ptyp:
C_hol_ucon(EM_holsize,
p->em_string,
p->em_size,
EM_holinit);
break;
case fco_ptyp:
C_hol_fcon(EM_holsize,
p->em_string,
p->em_size,
EM_holinit);
break;
case sof_ptyp:
C_hol_dnam(EM_holsize,
p->em_dnam,
p->em_off,
EM_holinit);
break;
case nof_ptyp:
C_hol_dlb(EM_holsize,
p->em_dlb,
p->em_off,
EM_holinit);
break;
case ilb_ptyp:
C_hol_ilb(EM_holsize,
p->em_ilb,
EM_holinit);
break;
case pro_ptyp:
C_hol_pnam(EM_holsize,
p->em_pnam,
EM_holinit);
break;
default:
C_error = "Illegal parameter type";
break;
}
break;
}
case ps_bss: {
if (! checkarg(&(p->em_arg), par_ptyp)) break;
switch(p->em_argtype) {
case cst_ptyp:
C_bss_cst(EM_bsssize,
p->em_cst,
EM_bssinit);
break;
case ico_ptyp:
C_bss_icon(EM_bsssize,
p->em_string,
p->em_size,
EM_bssinit);
break;
case uco_ptyp:
C_bss_ucon(EM_bsssize,
p->em_string,
p->em_size,
EM_bssinit);
break;
case fco_ptyp:
C_bss_fcon(EM_bsssize,
p->em_string,
p->em_size,
EM_bssinit);
break;
case sof_ptyp:
C_bss_dnam(EM_bsssize,
p->em_dnam,
p->em_off,
EM_bssinit);
break;
case nof_ptyp:
C_bss_dlb(EM_bsssize,
p->em_dlb,
p->em_off,
EM_bssinit);
break;
case ilb_ptyp:
C_bss_ilb(EM_bsssize,
p->em_ilb,
EM_bssinit);
break;
case pro_ptyp:
C_bss_pnam(EM_bsssize,
p->em_pnam,
EM_bssinit);
break;
default:
C_error = "Illegal parameter type";
break;
}
break;
}
case ps_end:
if (p->em_argtype != 0) {
if (! checkarg(&(p->em_arg), cst_ptyp)) break;
C_end(p->em_cst);
break;
}
C_end_narg();
break;
case ps_exa:
case ps_ina:
if (! checkarg(&(p->em_arg), lab_ptyp)) break;
if (p->em_argtype == nof_ptyp) {
if (p->em_opcode == ps_exa) {
C_exa_dlb(p->em_dlb);
}
else C_ina_dlb(p->em_dlb);
break;
}
if (p->em_opcode == ps_exa) {
C_exa_dnam(p->em_dnam);
}
else C_ina_dnam(p->em_dnam);
break;
case ps_exp:
if (! checkarg(&(p->em_arg), pro_ptyp)) break;
C_exp(p->em_pnam);
break;
case ps_inp:
if (! checkarg(&(p->em_arg), pro_ptyp)) break;
C_inp(p->em_pnam);
break;
case ps_pro:
if (! checkarg(&(p->em_arg), pro_ptyp)) break;
if (p->em_nlocals >= 0) {
C_pro(p->em_pnam, p->em_nlocals);
}
else C_pro_narg(p->em_pnam);
break;
case ps_con:
if (! checkarg(&(p->em_arg), val_ptyp)) break;
switch(p->em_argtype) {
case ilb_ptyp:
C_con_ilb(p->em_ilb);
break;
case nof_ptyp:
C_con_dlb(p->em_dlb, p->em_off);
break;
case sof_ptyp:
C_con_dnam(p->em_dnam, p->em_off);
break;
case cst_ptyp:
C_con_cst(p->em_cst);
break;
case pro_ptyp:
C_con_pnam(p->em_pnam);
break;
case str_ptyp:
C_con_scon(p->em_string, p->em_size);
break;
case ico_ptyp:
C_con_icon(p->em_string, p->em_size);
break;
case uco_ptyp:
C_con_ucon(p->em_string, p->em_size);
break;
case fco_ptyp:
C_con_fcon(p->em_string, p->em_size);
break;
default:
C_error = "Illegal argument type";
return;
}
break;
case ps_rom:
if (! checkarg(&(p->em_arg), val_ptyp)) break;
switch(p->em_argtype) {
case ilb_ptyp:
C_rom_ilb(p->em_ilb);
break;
case nof_ptyp:
C_rom_dlb(p->em_dlb, p->em_off);
break;
case sof_ptyp:
C_rom_dnam(p->em_dnam, p->em_off);
break;
case cst_ptyp:
C_rom_cst(p->em_cst);
break;
case pro_ptyp:
C_rom_pnam(p->em_pnam);
break;
case str_ptyp:
C_rom_scon(p->em_string, p->em_size);
break;
case ico_ptyp:
C_rom_icon(p->em_string, p->em_size);
break;
case uco_ptyp:
C_rom_ucon(p->em_string, p->em_size);
break;
case fco_ptyp:
C_rom_fcon(p->em_string, p->em_size);
break;
default:
C_error = "Illegal argument type";
return;
}
break;
default:
C_error = "Illegal pseudo instruction";
break;
}
}
PRIVATE
EM_docon(p)
register struct e_instr *p;
{
checkarg(&(p->em_arg), val_ptyp);
switch(p->em_argtype) {
case ilb_ptyp:
C_ilb(p->em_ilb);
break;
case nof_ptyp:
C_dlb(p->em_dlb, p->em_off);
break;
case sof_ptyp:
C_dnam(p->em_dnam, p->em_off);
break;
case cst_ptyp:
C_cst(p->em_cst);
break;
case pro_ptyp:
C_pnam(p->em_pnam);
break;
case str_ptyp:
C_scon(p->em_string, p->em_size);
break;
case ico_ptyp:
C_icon(p->em_string, p->em_size);
break;
case uco_ptyp:
C_ucon(p->em_string, p->em_size);
break;
case fco_ptyp:
C_fcon(p->em_string, p->em_size);
break;
default:
C_error = "Illegal argument type";
break;
}
}
PRIVATE
EM_dostartmes(p)
register struct e_instr *p;
{
if (listtype) {
C_error = "Message not ended";
return;
}
if (! checkarg(&(p->em_arg), cst_ptyp)) return;
C_mes_begin((int) (p->em_cst));
listtype = ps_mes;
}
EXPORT int
C_out(line)
register struct e_instr *line;
{
#ifdef CHECKING
if (listtype && line->em_type != EM_MESARG && line->em_type != EM_ENDMES) {
C_error = "Message not ended";
return 0;
}
#endif CHECKING
C_error = 0;
switch(line->em_type) {
default:
C_error = "Illegal EM line";
break;
case EM_MNEM:
/* normal instruction */
EM_doinstr(line);
break;
case EM_DEFILB:
/* defining occurrence of an instruction label */
C_df_ilb(line->em_ilb);
break;
case EM_DEFDLB:
/* defining occurrence of a global data label */
C_df_dlb(line->em_dlb);
break;
case EM_DEFDNAM:
/* defining occurrence of a non-numeric data label */
C_df_dnam(line->em_dnam);
break;
case EM_PSEU:
/* pseudo */
EM_dopseudo(line);
break;
case EM_STARTMES:
/* start of a MES pseudo */
EM_dostartmes(line);
break;
case EM_MESARG:
case EM_ENDMES:
#ifdef CHECKING
if (!listtype) {
C_error = "Message not started";
return 0;
}
#endif
if (line->em_type == EM_MESARG) {
EM_docon(line);
break;
}
C_mes_end();
listtype = 0;
break;
}
if (C_error) return 0;
return 1;
}

View file

@ -14,11 +14,12 @@ StorageList = C_bss_cst.c C_bss_dlb.c C_bss_dnam.c C_bss_ilb.c C_bss_pnam.c \
C_hol_pnam.c C_rom_cst.c C_rom_dlb.c C_rom_dnam.c C_rom_ilb.c \
C_rom_pnam.c C_rom_scon.c
all:
all: C_out.c
clean:
rm -f C_out.c C_mnem C_mnem_narg
install:
install: all
-mkdir $(CEGLIB)
-mkdir $(DEF)
-mkdir $(DEF)/message
@ -30,6 +31,7 @@ install:
for i in $(NotimplList) ; do cp not_impl/$$i $(DEF)/not_impl/$$i ; done
for i in $(PseudoList) ; do cp pseudo/$$i $(DEF)/pseudo/$$i ; done
for i in $(StorageList) ; do cp storage/$$i $(DEF)/storage/$$i ; done
cp C_out.c $(DEF)/C_out.c
cmp:
-cmp pseudo_vars.c $(DEF)/pseudo_vars.c
@ -37,6 +39,7 @@ cmp:
-for i in $(NotimplList) ; do cmp not_impl/$$i $(DEF)/not_impl/$$i ; done
-for i in $(PseudoList) ; do cmp pseudo/$$i $(DEF)/pseudo/$$i ; done
-for i in $(StorageList) ; do cmp storage/$$i $(DEF)/storage/$$i ; done
-cmp C_out.c $(DEF)/C_out.c
pr:
@for i in $(MessageList) ; do pr message/$$i ; done
@ -46,3 +49,12 @@ pr:
opr:
make pr | opr
C_out.c: C_out_skel.c C_mnem C_mnem_narg mk_C_out
mk_C_out > C_out.c
C_mnem: m_C_mnem argtype
sh m_C_mnem > C_mnem
C_mnem_narg: m_C_mnem_na argtype
sh m_C_mnem_na > C_mnem_narg

14
util/ceg/defaults/argtype Executable file
View file

@ -0,0 +1,14 @@
: argtype lists all em mnemonics that have an argument type equal to
: one of the letters specified in the argument
case x$# in
x2)
;;
x*) echo "Usage: $0 argtypes <em_table>" 1>&2
exit 1
;;
esac
ed - $2 << A
1,/^\$/d
1,/^\$/d
1,/^\$/g/^\(...\) [$1].*/s//\\1/gp
A

91
util/ceg/defaults/m_C_mnem Executable file
View file

@ -0,0 +1,91 @@
EM_TABLE=../../../etc/em_table
echo "switch(p->em_opcode) {"
for i in - cdflnorswz p b
do
list=`./argtype $i $EM_TABLE`
case $i in
-) args='()'
echo " /* no arguments */"
;;
cdflnorswz)
args='(p->em_cst)'
echo " /* one integer constant argument */"
;;
p)
args='(p->em_pnam)'
echo " /* a procedure name argument */"
;;
b)
: Grumbl, an instruction label as argument is encoded in a sp_cst2
args='((label) (p->em_cst))'
echo " /* An instruction label argument */"
;;
esac
for i in $list
do
cat << EOF
case op_$i:
C_$i$args;
break;
EOF
done
done
list=`./argtype g $EM_TABLE`
cat << 'EOF'
default:
/* a "g" argument */
if (p->em_argtype == nof_ptyp) {
switch(p->em_opcode) {
default:
C_error = "Illegal mnemonic";
break;
EOF
for i in $list
do
cat << EOF
case op_$i:
C_${i}_dlb(p->em_dlb, p->em_off);
break;
EOF
done
cat << 'EOF'
}
}
else if (p->em_argtype == sof_ptyp) {
switch(p->em_opcode) {
default:
C_error = "Illegal mnemonic";
break;
EOF
for i in $list
do
cat << EOF
case op_$i:
C_${i}_dnam(p->em_dnam, p->em_off);
break;
EOF
done
cat << 'EOF'
}
}
else /*argtype == cst_ptyp */ {
switch(p->em_opcode) {
default:
C_error = "Illegal mnemonic";
break;
EOF
for i in $list
do
cat << EOF
case op_$i:
C_$i(p->em_cst);
break;
EOF
done
cat << 'EOF'
}
}
}
EOF

15
util/ceg/defaults/m_C_mnem_na Executable file
View file

@ -0,0 +1,15 @@
EM_TABLE=../../../etc/em_table
list=`./argtype w $EM_TABLE`
echo "switch(p->em_opcode) {"
for i in $list
do
cat << EOF
case op_$i:
C_${i}_narg();
break;
EOF
done
cat << EOF
default: C_error = "Illegal mnemonic";
}
EOF

12
util/ceg/defaults/mk_C_out Executable file
View file

@ -0,0 +1,12 @@
trap "rm -f tmp$$" 1 2 3 15
cp C_out_skel.c tmp$$
ed - tmp$$ <<'EOF'
/^#include "C_mnem_narg"/d
.-1r C_mnem_narg
/^#include "C_mnem"/d
.-1r C_mnem
w
q
EOF
cat tmp$$
rm -f tmp$$