simplified the EM con/rom functions (86/03/13)

This commit is contained in:
erikb 1986-03-13 13:27:44 +00:00
parent 43e75cec60
commit 6e53274b6a
6 changed files with 60 additions and 117 deletions

View file

@ -174,9 +174,7 @@ begin_proc(name, def) /* to be called when entering a procedure */
if (strcmp(last_fn_given, FileName) != 0) { if (strcmp(last_fn_given, FileName) != 0) {
/* previous function came from other file */ /* previous function came from other file */
C_df_dlb(file_name_label = data_label()); C_df_dlb(file_name_label = data_label());
C_con_begin(); C_con_scon(last_fn_given = FileName, (arith)0);
C_scon(last_fn_given = FileName, (arith)0);
C_con_end();
} }
/* enable debug trace of EM source */ /* enable debug trace of EM source */
C_fil_dlb(file_name_label, (arith)0); C_fil_dlb(file_name_label, (arith)0);

View file

@ -61,30 +61,6 @@ C_busy()
return ofd >= 0; /* true if code is being generated */ return ofd >= 0; /* true if code is being generated */
} }
/*** front end for generating long CON/ROM lists ***/
static arg_count;
static arg_rom;
DC_start(rom){
arg_count = 0;
arg_rom = rom;
}
DC_check(){
if (arg_count++ >= MAX_ARG_CNT) {
switch (arg_rom) {
case ps_con:
C_con_end();
C_con_begin();
break;
case ps_rom:
C_rom_end();
C_rom_begin();
break;
}
}
}
/*** the compact code generating routines ***/ /*** the compact code generating routines ***/
#define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF) #define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF)
#define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ #define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */

View file

@ -85,22 +85,35 @@ C_df_ilb(l) | label l; | ILB(l)
C_bss_cst(n, w, i) | arith n, w; int i; | C_bss_cst(n, w, i) | arith n, w; int i; |
PS(ps_bss), DCST(n), CST(w), CST((arith)i) PS(ps_bss), DCST(n), CST(w), CST((arith)i)
% %
C_con_begin() | | DC_start(ps_con), PS(ps_con) C_con_icon(val, siz) | char *val; arith siz; |
C_con_end() | | CEND() PS(ps_con), WCON(sp_icon, val, siz), CEND()
C_rom_begin() | | DC_start(ps_rom), PS(ps_rom) C_con_ucon(val, siz) | char *val; arith siz; |
C_rom_end() | | CEND() PS(ps_con), WCON(sp_ucon, val, siz), CEND()
C_cst(l) | arith l; | DC_check(), CST(l) C_con_fcon(val, siz) | char *val; arith siz; |
C_icon(val, siz) | char *val; arith siz; | PS(ps_con), WCON(sp_fcon, val, siz), CEND()
DC_check(), WCON(sp_icon, val, siz) C_con_scon(str, siz) | char *str; arith siz; | PS(ps_con), CSTR(str), CEND()
C_ucon(val, siz) | char *val; arith siz; | C_con_dnam(str, val) | char *str; arith val; |
DC_check(), WCON(sp_ucon, val, siz) PS(ps_con), NOFF(str, val), CEND()
C_fcon(val, siz) | char *val; arith siz; | C_con_dlb(l, val) | label l; arith val; |
DC_check(), WCON(sp_fcon, val, siz) PS(ps_con), DOFF(l, val), CEND()
C_scon(str, siz) | char *str; arith siz; | DC_check(), CSTR(str) C_con_pnam(str) | char *str; | PS(ps_con), PNAM(str), CEND()
C_dnam(str, val) | char *str; arith val; | DC_check(), NOFF(str, val) %
C_dlb(l, val) | label l; arith val; | DC_check(), DOFF(l, val) C_rom_cst(l) | arith l; | PS(ps_rom), CST(l), CEND()
C_pnam(str) | char *str; | DC_check(), PNAM(str) C_rom_icon(val, siz) | char *val; arith siz; |
C_ilb(l) | label l; | DC_check(), ILB(l) PS(ps_rom), WCON(sp_icon, val, siz), CEND()
C_rom_fcon(val, siz) | char *val; arith siz; |
PS(ps_rom), WCON(sp_fcon, val, siz), CEND()
C_rom_ilb(l) | label l; | PS(ps_rom), ILB(l), CEND()
%
C_cst(l) | arith l; | CST(l)
C_icon(val, siz) | char *val; arith siz; | WCON(sp_icon, val, siz)
C_ucon(val, siz) | char *val; arith siz; | WCON(sp_ucon, val, siz)
C_fcon(val, siz) | char *val; arith siz; | WCON(sp_fcon, val, siz)
C_scon(str, siz) | char *str; arith siz; | CSTR(str)
C_dnam(str, val) | char *str; arith val; | NOFF(str, val)
C_dlb(l, val) | label l; arith val; | DOFF(l, val)
C_pnam(str) | char *str; | PNAM(str)
C_ilb(l) | label l; | ILB(l)
% %
C_pro_narg(p1) | char *p1; | PS(ps_pro), PNAM(p1), CEND() C_pro_narg(p1) | char *p1; | PS(ps_pro), PNAM(p1), CEND()
C_end(l) | arith l; | PS(ps_end), CST(l) C_end(l) | arith l; | PS(ps_end), CST(l)

View file

@ -88,9 +88,7 @@ EVAL(expr, val, code, true_label, false_label)
label datlab = data_label(); label datlab = data_label();
C_df_dlb(datlab); C_df_dlb(datlab);
C_con_begin(); C_con_scon(expr->SG_VALUE, (arith)0);
C_scon(expr->SG_VALUE, (arith)0);
C_con_end();
C_lae_dlb(datlab, (arith)0); C_lae_dlb(datlab, (arith)0);
} }
break; break;
@ -100,9 +98,7 @@ EVAL(expr, val, code, true_label, false_label)
label datlab = data_label(); label datlab = data_label();
C_df_dlb(datlab); C_df_dlb(datlab);
C_rom_begin(); C_rom_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
C_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
C_rom_end();
C_lae_dlb(datlab, (arith)0); C_lae_dlb(datlab, (arith)0);
C_loi(expr->ex_type->tp_size); C_loi(expr->ex_type->tp_size);
} }
@ -1019,9 +1015,7 @@ load_cst(val, siz)
label datlab; label datlab;
C_df_dlb(datlab = data_label()); C_df_dlb(datlab = data_label());
C_rom_begin(); C_rom_icon(itos(val), siz);
C_icon(itos(val), siz);
C_rom_end();
C_lae_dlb(datlab, (arith)0); C_lae_dlb(datlab, (arith)0);
C_loi(siz); C_loi(siz);
} }

View file

@ -23,11 +23,10 @@
extern char *symbol2str(); extern char *symbol2str();
#define con_byte(c) C_ucon(itos((long)(c) & 0xFF), (arith)1) #define con_byte(c) C_con_ucon(itos((long)(c) & 0xFF), (arith)1)
struct expr *do_array(), *do_struct(), *IVAL(); struct expr *do_array(), *do_struct(), *IVAL();
struct expr *strings = 0; /* list of string constants within initialiser */ struct expr *strings = 0; /* list of string constants within initialiser */
static ConStarted; /* indicates the generation of a 'con' pseudo */
/* do_ival() performs the initialisation of a global variable /* do_ival() performs the initialisation of a global variable
of type tp with the initialisation expression expr by calling IVAL(). of type tp with the initialisation expression expr by calling IVAL().
@ -37,9 +36,9 @@ do_ival(tpp, expr)
struct type **tpp; struct type **tpp;
struct expr *expr; struct expr *expr;
{ {
ConStarted = 0;
if (IVAL(tpp, expr) != 0) if (IVAL(tpp, expr) != 0)
too_many_initialisers(expr); too_many_initialisers(expr);
/* The following loop declares the string constants /* The following loop declares the string constants
used in the initialisation. used in the initialisation.
The code for these string constants may not appear in The code for these string constants may not appear in
@ -47,12 +46,9 @@ do_ival(tpp, expr)
in EM causes the current initialisation to be completed. in EM causes the current initialisation to be completed.
E.g. char *s[] = {"hello", "world"}; E.g. char *s[] = {"hello", "world"};
*/ */
C_con_end();
while (strings != 0) { while (strings != 0) {
C_df_dlb(strings->SG_DATLAB); C_df_dlb(strings->SG_DATLAB);
C_con_begin(); C_con_scon(strings->SG_VALUE, (arith)0);
C_scon(strings->SG_VALUE, (arith)0);
C_con_end();
strings = strings->next; strings = strings->next;
} }
} }
@ -341,8 +337,7 @@ check_and_pad(expr, tpp)
/* no size specified upto here: just /* no size specified upto here: just
set it to the size of one member. set it to the size of one member.
*/ */
tp = *tpp = tp = *tpp = construct_type(ARRAY, tp->tp_up, (arith)1);
construct_type(ARRAY, tp->tp_up, (arith)1);
else { else {
register dim = tp->tp_size / tp->tp_up->tp_size; register dim = tp->tp_size / tp->tp_up->tp_size;
/* pad remaining members with zeroes */ /* pad remaining members with zeroes */
@ -376,10 +371,6 @@ check_and_pad(expr, tpp)
pad(tp) pad(tp)
struct type *tp; struct type *tp;
{ {
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
switch (tp->tp_fund) { switch (tp->tp_fund) {
case ARRAY: case ARRAY:
{ {
@ -420,11 +411,11 @@ pad(tp)
case CHAR: case CHAR:
case ENUM: case ENUM:
case POINTER: case POINTER:
C_ucon("0", tp->tp_size); C_con_ucon("0", tp->tp_size);
break; break;
case FLOAT: case FLOAT:
case DOUBLE: case DOUBLE:
C_fcon("0", tp->tp_size); C_con_fcon("0", tp->tp_size);
break; break;
case UNION: case UNION:
error("initialisation of unions not allowed"); error("initialisation of unions not allowed");
@ -463,10 +454,6 @@ check_ival(expr, type)
break; break;
} }
ch7cast(&expr, '=', type); ch7cast(&expr, '=', type);
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
con_int(expr); con_int(expr);
break; break;
#ifndef NOBITFIELD #ifndef NOBITFIELD
@ -485,26 +472,18 @@ check_ival(expr, type)
break; break;
} }
ch7cast(&expr, '=', type); ch7cast(&expr, '=', type);
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
con_int(expr); con_int(expr);
break; break;
case FLOAT: case FLOAT:
case DOUBLE: case DOUBLE:
ch7cast(&expr, '=', type); ch7cast(&expr, '=', type);
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
if (expr->ex_class == Float) if (expr->ex_class == Float)
C_fcon(expr->FL_VALUE, expr->ex_type->tp_size); C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
else else
if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) {
expr = expr->OP_RIGHT; expr = expr->OP_RIGHT;
if (expr->ex_class == Value && expr->VL_IDF == 0) if (expr->ex_class == Value && expr->VL_IDF == 0)
C_fcon(itos(expr->VL_VALUE), type->tp_size); C_con_fcon(itos(expr->VL_VALUE), type->tp_size);
else else
illegal_init_cst(expr); illegal_init_cst(expr);
} }
@ -521,13 +500,8 @@ check_ival(expr, type)
{ {
label datlab = data_label(); label datlab = data_label();
if (ConStarted)
C_con_end();
else
ConStarted = 1; /* ??? */
C_ina_pt(datlab); C_ina_pt(datlab);
C_con_begin(); C_con_dlb(datlab, (arith)0);
C_dlb(datlab, (arith)0);
expr->SG_DATLAB = datlab; expr->SG_DATLAB = datlab;
store_string(expr); store_string(expr);
break; break;
@ -538,13 +512,9 @@ check_ival(expr, type)
struct idf *idf = vl->vl_idf; struct idf *idf = vl->vl_idf;
ASSERT(expr->ex_type->tp_fund == POINTER); ASSERT(expr->ex_type->tp_fund == POINTER);
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
if (expr->ex_type->tp_up->tp_fund == FUNCTION) { if (expr->ex_type->tp_up->tp_fund == FUNCTION) {
if (idf) if (idf)
C_pnam(idf->id_text); C_con_pnam(idf->id_text);
else /* int (*func)() = 0 */ else /* int (*func)() = 0 */
con_int(expr); con_int(expr);
} }
@ -558,13 +528,16 @@ check_ival(expr, type)
static int *p = &a; static int *p = &a;
*/ */
expr_error(expr, expr_error(expr,
"illegal initialisation"); "illegal initialisation"
);
else else
C_dlb((label)def->df_address, C_con_dlb(
vl->vl_value); (label)def->df_address,
vl->vl_value
);
} }
else else
C_dnam(idf->id_text, vl->vl_value); C_con_dnam(idf->id_text, vl->vl_value);
} }
else else
con_int(expr); con_int(expr);
@ -611,10 +584,6 @@ init_string(tpp, expr)
expr_error(expr, expr_error(expr,
"too many characters in initialiser string"); "too many characters in initialiser string");
} }
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
/* throw out the characters of the already prepared string */ /* throw out the characters of the already prepared string */
do do
con_byte(*s++); con_byte(*s++);
@ -721,10 +690,6 @@ put_bf(tp, val)
if (sd->sd_sdef == 0 || sd->sd_sdef->sd_offset != offset) { if (sd->sd_sdef == 0 || sd->sd_sdef->sd_offset != offset) {
/* the selector was the last stored at this address */ /* the selector was the last stored at this address */
expr.VL_VALUE = field; expr.VL_VALUE = field;
if (ConStarted == 0) {
C_con_begin();
ConStarted = 1;
}
con_int(&expr); con_int(&expr);
field = (arith)0; field = (arith)0;
offset = (arith)-1; offset = (arith)-1;
@ -767,9 +732,9 @@ con_int(expr)
register struct type *tp = expr->ex_type; register struct type *tp = expr->ex_type;
if (tp->tp_unsigned) if (tp->tp_unsigned)
C_ucon(itos(expr->VL_VALUE), tp->tp_size); C_con_ucon(itos(expr->VL_VALUE), tp->tp_size);
else else
C_icon(itos(expr->VL_VALUE), tp->tp_size); C_con_icon(itos(expr->VL_VALUE), tp->tp_size);
} }
illegal_init_cst(expr) illegal_init_cst(expr)

View file

@ -56,36 +56,33 @@ code_endswitch()
C_df_ilb(sh->sh_table); /* switch table entry */ C_df_ilb(sh->sh_table); /* switch table entry */
tablabel = data_label(); /* the rom must have a label */ tablabel = data_label(); /* the rom must have a label */
C_df_dlb(tablabel); C_df_dlb(tablabel);
C_rom_begin(); C_rom_ilb(sh->sh_default);
C_ilb(sh->sh_default);
if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) {
/* CSA */ /* CSA */
register arith val; register arith val;
C_cst(sh->sh_lowerbd); C_rom_cst(sh->sh_lowerbd);
C_cst(sh->sh_upperbd - sh->sh_lowerbd); C_rom_cst(sh->sh_upperbd - sh->sh_lowerbd);
ce = sh->sh_entries; ce = sh->sh_entries;
for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) {
ASSERT(ce); ASSERT(ce);
if (val == ce->ce_value) { if (val == ce->ce_value) {
C_ilb(ce->ce_label); C_rom_ilb(ce->ce_label);
ce = ce->next; ce = ce->next;
} }
else else
C_ilb(sh->sh_default); C_rom_ilb(sh->sh_default);
} }
C_rom_end();
C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_lae_dlb(tablabel, (arith)0); /* perform the switch */
C_csa(sh->sh_type->tp_size); C_csa(sh->sh_type->tp_size);
} }
else { /* CSB */ else { /* CSB */
C_cst((arith)sh->sh_nrofentries); C_rom_cst((arith)sh->sh_nrofentries);
for (ce = sh->sh_entries; ce; ce = ce->next) { for (ce = sh->sh_entries; ce; ce = ce->next) {
/* generate the entries: value + prog.label */ /* generate the entries: value + prog.label */
C_cst(ce->ce_value); C_rom_cst(ce->ce_value);
C_ilb(ce->ce_label); C_rom_ilb(ce->ce_label);
} }
C_rom_end();
C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_lae_dlb(tablabel, (arith)0); /* perform the switch */
C_csb(sh->sh_type->tp_size); C_csb(sh->sh_type->tp_size);
} }