Removed switches on longs (portability) and added packed subranges

This commit is contained in:
ceriel 1991-02-14 18:15:22 +00:00
parent 1ed0f8180f
commit 3e0c73690c
5 changed files with 100 additions and 87 deletions

View file

@ -116,10 +116,8 @@ CodeBeginBlock(df)
TmpOpen(df->prc_vis->sc_scope); TmpOpen(df->prc_vis->sc_scope);
switch( df->df_kind ) { if ( df->df_kind == D_MODULE) /* nothing */ ;
else if (df->df_kind == D_PROGRAM ) {
case D_MODULE : break; /* nothing */
case D_PROGRAM :
C_exp("m_a_i_n"); C_exp("m_a_i_n");
C_pro_narg("m_a_i_n"); C_pro_narg("m_a_i_n");
C_ms_par((arith) 0); C_ms_par((arith) 0);
@ -133,11 +131,8 @@ CodeBeginBlock(df)
C_loc((arith) (1 << EFUNFL)); C_loc((arith) (1 << EFUNFL));
C_ior(int_size); C_ior(int_size);
C_sim(); C_sim();
}
break; else if (df->df_kind & (D_PROCEDURE | D_FUNCTION)) {
case D_PROCEDURE :
case D_FUNCTION : {
struct type *tp; struct type *tp;
register struct paramlist *param; register struct paramlist *param;
@ -162,7 +157,7 @@ CodeBeginBlock(df)
C_zer((arith) int_size); C_zer((arith) int_size);
C_stl(df->prc_bool); C_stl(df->prc_bool);
} }
for( param = ParamList(df->df_type); param; param = param->next) for( param = ParamList(df->df_type); param; param = param->next) {
if( !IsVarParam(param) ) { if( !IsVarParam(param) ) {
tp = TypeOfParam(param); tp = TypeOfParam(param);
@ -213,10 +208,9 @@ CodeBeginBlock(df)
C_stl(param->par_def->var_off); C_stl(param->par_def->var_off);
} }
} }
break;
} }
}
default : else {
crash("(CodeBeginBlock)"); crash("(CodeBeginBlock)");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -233,14 +227,11 @@ CodeEndBlock(df, StackAdjustment)
register struct def *df; register struct def *df;
arith StackAdjustment; arith StackAdjustment;
{ {
switch( df->df_kind ) { if( df->df_kind == D_PROGRAM) {
case D_PROGRAM :
C_loc((arith) 0); C_loc((arith) 0);
C_cal("_hlt"); C_cal("_hlt");
break; }
else if (df->df_kind & (D_PROCEDURE | D_FUNCTION)) {
case D_PROCEDURE :
case D_FUNCTION : {
struct type *tp; struct type *tp;
if( StackAdjustment ) { if( StackAdjustment ) {
@ -277,11 +268,8 @@ CodeEndBlock(df, StackAdjustment)
} }
else else
C_ret((arith) 0); C_ret((arith) 0);
break;
} }
else {
default :
crash("(CodeEndBlock)"); crash("(CodeEndBlock)");
/*NOTREACHED*/ /*NOTREACHED*/
} }

View file

@ -53,14 +53,20 @@ define(id, scope, kind)
register struct def *df; register struct def *df;
if( df = lookup(id, scope, 0) ) { if( df = lookup(id, scope, 0) ) {
switch( df->df_kind ) { if (df->df_kind == D_INUSE) {
case D_INUSE :
if( kind != D_INUSE ) { if( kind != D_INUSE ) {
error("\"%s\" already used in this block", error("\"%s\" already used in this block",
id->id_text); id->id_text);
} }
return MkDef(id, scope, kind); return MkDef(id, scope, kind);
}
if (df->df_kind == D_ERROR ) {
/* used in forward references */
df->df_kind = kind;
return df;
}
/* other cases fit in an int (assume at least 2 bytes) */
switch((int) df->df_kind ) {
case D_LABEL : case D_LABEL :
/* generate error message somewhere else */ /* generate error message somewhere else */
@ -96,10 +102,6 @@ define(id, scope, kind)
id->id_text); id->id_text);
return NULLDEF; return NULLDEF;
case D_ERROR :
/* used in forward references */
df->df_kind = kind;
return df;
} }
if( kind != D_ERROR ) if( kind != D_ERROR )
/* avoid spurious error messages */ /* avoid spurious error messages */
@ -129,19 +131,16 @@ DoDirective(directive, nd, tp, scl, function)
return; return;
} }
switch( df->df_kind) { if (df->df_kind == D_FORWARD) {
case D_FORWARD:
kind = function ? D_FWFUNCTION : D_FWPROCEDURE; kind = function ? D_FWFUNCTION : D_FWPROCEDURE;
inp = (proclevel > 1); inp = (proclevel > 1);
break; }
else if (df->df_kind == D_EXTERN) {
case D_EXTERN:
kind = function ? D_FUNCTION : D_PROCEDURE; kind = function ? D_FUNCTION : D_PROCEDURE;
inp = 0; inp = 0;
ext = 1; ext = 1;
break; }
else {
default:
node_error(nd, "\"%s\" unknown directive", node_error(nd, "\"%s\" unknown directive",
directive->id_text); directive->id_text);
return; return;

View file

@ -161,7 +161,7 @@ CodeValue(ds, tp)
switch( ds->dsg_kind ) { switch( ds->dsg_kind ) {
case DSG_LOADED: case DSG_LOADED:
break; return;
case DSG_FIXED: case DSG_FIXED:
if( ds->dsg_offset % word_size == 0 ) { if( ds->dsg_offset % word_size == 0 ) {
@ -199,6 +199,12 @@ CodeValue(ds, tp)
/*NOTREACHED*/ /*NOTREACHED*/
} }
if (size < word_size && tp->tp_fund == T_SUBRANGE &&
BaseType(tp)->tp_fund == T_INTEGER && tp->sub_lb < 0) {
C_loc(size);
C_loc(word_size);
C_cii();
}
ds->dsg_kind = DSG_LOADED; ds->dsg_kind = DSG_LOADED;
} }
@ -502,7 +508,7 @@ CodeDesig(nd, ds)
case Def: case Def:
df = nd->nd_def; df = nd->nd_def;
switch( df->df_kind ) { switch( (int) df->df_kind ) {
case D_FIELD: case D_FIELD:
CodeFieldDesig(df, ds); CodeFieldDesig(df, ds);
break; break;

View file

@ -306,7 +306,7 @@ stb_string(df, kind)
N_LSYM, N_LSYM,
tp == void_type || tp->tp_size > 32767 tp == void_type || tp->tp_size > 32767
? 0 ? 0
: (int)tp->tp_size, : (IsPacked(tp) ? (int) tp->tp_psize : (int)tp->tp_size),
(arith) 0); (arith) 0);
break; break;
case D_CONST: case D_CONST:

View file

@ -296,6 +296,26 @@ subr_type(lb, ub)
res = construct_type(T_SUBRANGE, tp); res = construct_type(T_SUBRANGE, tp);
res->sub_lb = lb->nd_INT; res->sub_lb = lb->nd_INT;
res->sub_ub = ub->nd_INT; res->sub_ub = ub->nd_INT;
if (res->sub_lb >= 0) {
if (ufit(res->sub_ub, 1)) {
res->tp_psize = 1;
res->tp_palign = 1;
}
else if (ufit(res->sub_ub, 2)) {
res->tp_psize = 2;
res->tp_palign = 2 < word_align ? 2 : word_align;
}
}
else {
if (fit(res->sub_lb, 1) && fit(res->sub_ub, 1)) {
res->tp_psize = 1;
res->tp_palign = 1;
}
else if (fit(res->sub_lb, 2) && fit(res->sub_ub, 2)) {
res->tp_psize = 2;
res->tp_palign = 2 < word_align ? 2 : word_align;
}
}
return res; return res;
} }