simplified 0-padding, minor cosmetic changes

This commit is contained in:
ceriel 1986-12-10 12:00:55 +00:00
parent df86573d4c
commit 42162f7b37
7 changed files with 90 additions and 104 deletions

View file

@ -169,6 +169,7 @@ begin_proc(name, def) /* to be called when entering a procedure */
- a fil pseudo instruction - a fil pseudo instruction
*/ */
arith size; arith size;
register struct type *tp = def->df_type;
#ifndef USE_TMP #ifndef USE_TMP
code_scope(name, def); code_scope(name, def);
@ -178,15 +179,16 @@ begin_proc(name, def) /* to be called when entering a procedure */
DfaStartFunction(name); DfaStartFunction(name);
#endif DATAFLOW #endif DATAFLOW
if (def->df_type->tp_fund != FUNCTION) { if (tp->tp_fund != FUNCTION) {
error("making function body for non-function"); error("making function body for non-function");
func_tp = error_type; tp = error_type;
} }
else else
func_tp = def->df_type->tp_up; tp = tp->tp_up;
size = ATW(func_tp->tp_size); func_tp = tp;
size = ATW(tp->tp_size);
C_pro_narg(name); C_pro_narg(name);
if (is_struct_or_union(func_tp->tp_fund)) { if (is_struct_or_union(tp->tp_fund)) {
C_df_dlb(func_res_label = data_label()); C_df_dlb(func_res_label = data_label());
C_bss_cst(size, (arith)0, 1); C_bss_cst(size, (arith)0, 1);
} }
@ -309,7 +311,7 @@ code_declaration(idf, expr, lvl, sc)
*/ */
char *text = idf->id_text; char *text = idf->id_text;
register struct def *def = idf->id_def; register struct def *def = idf->id_def;
arith size = def->df_type->tp_size; register arith size = def->df_type->tp_size;
int def_sc = def->df_sc; int def_sc = def->df_sc;
if (def_sc == TYPEDEF) /* no code for typedefs */ if (def_sc == TYPEDEF) /* no code for typedefs */
@ -387,6 +389,7 @@ loc_init(expr, id)
It frees the expression afterwards. It frees the expression afterwards.
*/ */
register struct type *tp = id->id_def->df_type; register struct type *tp = id->id_def->df_type;
register struct expr *e = expr;
ASSERT(id->id_def->df_sc != STATIC); ASSERT(id->id_def->df_sc != STATIC);
switch (tp->tp_fund) { switch (tp->tp_fund) {
@ -394,20 +397,20 @@ loc_init(expr, id)
case STRUCT: case STRUCT:
case UNION: case UNION:
error("no automatic aggregate initialisation"); error("no automatic aggregate initialisation");
free_expression(expr); free_expression(e);
return; return;
} }
if (ISCOMMA(expr)) { /* embraced: int i = {12}; */ if (ISCOMMA(e)) { /* embraced: int i = {12}; */
if (options['R']) { if (options['R']) {
if (ISCOMMA(expr->OP_LEFT)) /* int i = {{1}} */ if (ISCOMMA(e->OP_LEFT)) /* int i = {{1}} */
expr_error(expr, "extra braces not allowed"); expr_error(e, "extra braces not allowed");
else else
if (expr->OP_RIGHT != 0) /* int i = {1 , 2} */ if (e->OP_RIGHT != 0) /* int i = {1 , 2} */
expr_error(expr, "too many initializers"); expr_error(e, "too many initializers");
} }
while (expr) { while (e) {
loc_init(expr->OP_LEFT, id); loc_init(e->OP_LEFT, id);
expr = expr->OP_RIGHT; e = e->OP_RIGHT;
} }
} }
else { /* not embraced */ else { /* not embraced */
@ -428,11 +431,10 @@ bss(idf)
{ {
/* bss() allocates bss space for the global idf. /* bss() allocates bss space for the global idf.
*/ */
register struct def *def = idf->id_def; arith size = idf->id_def->df_type->tp_size;
arith size = def->df_type->tp_size;
#ifndef USE_TMP #ifndef USE_TMP
code_scope(idf->id_text, def); code_scope(idf->id_text, idf->id_def);
#endif USE_TMP #endif USE_TMP
/* Since bss() is only called if df_alloc is non-zero, and /* Since bss() is only called if df_alloc is non-zero, and
since df_alloc is only non-zero if size >= 0, we have: since df_alloc is only non-zero if size >= 0, we have:

View file

@ -134,7 +134,7 @@ skip_block()
seen. seen.
*/ */
register int ch; register int ch;
register skiplevel = nestlevel; /* current nesting level */ register int skiplevel = nestlevel; /* current nesting level */
struct token tk; struct token tk;
NoUnstack++; NoUnstack++;
@ -530,10 +530,10 @@ get_text(formals, length)
identifiers, because they might be replaced by some actual identifiers, because they might be replaced by some actual
parameter. Other tokens will not be seen as such. parameter. Other tokens will not be seen as such.
*/ */
register c; register int c;
register text_size; register int text_size;
char *text = Malloc(text_size = ITEXTSIZE); char *text = Malloc(text_size = ITEXTSIZE);
register pos = 0; register int pos = 0;
LoadChar(c); LoadChar(c);

View file

@ -426,7 +426,6 @@ global_redecl(idf, new_sc, tp)
else { else {
warning("%s redeclared to static", warning("%s redeclared to static",
idf->id_text); idf->id_text);
def->df_sc = STATIC;
} }
def->df_sc = new_sc; def->df_sc = new_sc;
break; break;

View file

@ -25,6 +25,7 @@
char *symbol2str(); char *symbol2str();
char *long2str(); char *long2str();
struct expr *do_array(), *do_struct(), *IVAL(); struct expr *do_array(), *do_struct(), *IVAL();
extern char options[];
/* 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().
@ -325,59 +326,40 @@ check_and_pad(ex, tpp)
pad(tp) pad(tp)
register struct type *tp; register struct type *tp;
{ {
register arith sz = tp->tp_size;
switch (tp->tp_fund) { switch (tp->tp_fund) {
case ARRAY: case ARRAY:
{
register long dim;
if (valid_type(tp->tp_up, "array element") == 0) if (valid_type(tp->tp_up, "array element") == 0)
return; return;
dim = tp->tp_size / tp->tp_up->tp_size;
/* assume dimension is known */
while (dim-- > 0)
pad(tp->tp_up);
break; break;
}
case STRUCT: case STRUCT:
{
register struct sdef *sdef = tp->tp_sdef;
if (valid_type(tp, "struct") == 0) if (valid_type(tp, "struct") == 0)
return; return;
do {
pad(sdef->sd_type);
if (sdef->sd_sdef)
zero_bytes(sdef);
} while (sdef = sdef->sd_sdef);
break; break;
case UNION:
if (valid_type(tp, "union") == 0)
return;
if (options['R']) {
warning("initialisation of unions not allowed");
} }
break;
#ifndef NOBITFIELD #ifndef NOBITFIELD
case FIELD: case FIELD:
put_bf(tp, (arith)0); put_bf(tp, (arith)0);
break; return;
#endif NOBITFIELD #endif NOBITFIELD
case INT:
case SHORT:
case LONG:
case CHAR:
case ENUM:
case POINTER:
C_con_ucon("0", tp->tp_size);
break;
#ifndef NOFLOAT
case FLOAT:
case DOUBLE:
C_con_fcon("0", tp->tp_size);
break;
#endif NOFLOAT
case UNION:
error("initialisation of unions not allowed");
break;
case ERRONEOUS: case ERRONEOUS:
break; return;
default: }
crash("(generate) bad fundamental type %s\n",
symbol2str(tp->tp_fund)); while (sz >= word_size) {
C_con_cst((arith) 0);
sz -= word_size;
}
while (sz) {
C_con_icon("0", (arith) 1);
sz--;
} }
} }
@ -387,8 +369,8 @@ pad(tp)
No further comment is needed to explain the internal structure No further comment is needed to explain the internal structure
of this straightforward function. of this straightforward function.
*/ */
check_ival(ex, tp) check_ival(expr, tp)
struct expr *ex; register struct expr *expr;
register struct type *tp; register struct type *tp;
{ {
/* The philosophy here is that ch7cast puts an explicit /* The philosophy here is that ch7cast puts an explicit
@ -396,6 +378,7 @@ check_ival(ex, tp)
are not compatible. In this case, the initialisation are not compatible. In this case, the initialisation
expression is no longer a constant. expression is no longer a constant.
*/ */
struct expr *ex = expr;
switch (tp->tp_fund) { switch (tp->tp_fund) {
case CHAR: case CHAR:
@ -405,66 +388,68 @@ check_ival(ex, tp)
case ENUM: case ENUM:
case POINTER: case POINTER:
ch7cast(&ex, '=', tp); ch7cast(&ex, '=', tp);
expr = ex;
#ifdef DEBUG #ifdef DEBUG
print_expr("init-expr after cast", ex); print_expr("init-expr after cast", expr);
#endif DEBUG #endif DEBUG
if (!is_ld_cst(ex)) if (!is_ld_cst(expr))
illegal_init_cst(ex); illegal_init_cst(expr);
else else
if (ex->VL_CLASS == Const) if (expr->VL_CLASS == Const)
con_int(ex); con_int(expr);
else else
if (ex->VL_CLASS == Name) { if (expr->VL_CLASS == Name) {
register struct idf *id = ex->VL_IDF; register struct idf *idf = expr->VL_IDF;
register struct def *df = id->id_def;
if (df->df_level >= L_LOCAL) if (idf->id_def->df_level >= L_LOCAL)
illegal_init_cst(ex); illegal_init_cst(expr);
else /* e.g., int f(); int p = f; */ else /* e.g., int f(); int p = f; */
if (df->df_type->tp_fund == FUNCTION) if (idf->id_def->df_type->tp_fund == FUNCTION)
C_con_pnam(id->id_text); C_con_pnam(idf->id_text);
else /* e.g., int a; int *p = &a; */ else /* e.g., int a; int *p = &a; */
C_con_dnam(id->id_text, ex->VL_VALUE); C_con_dnam(idf->id_text, expr->VL_VALUE);
} }
else { else {
ASSERT(ex->VL_CLASS == Label); ASSERT(expr->VL_CLASS == Label);
C_con_dlb(ex->VL_LBL, ex->VL_VALUE); C_con_dlb(expr->VL_LBL, expr->VL_VALUE);
} }
break; break;
#ifndef NOFLOAT #ifndef NOFLOAT
case FLOAT: case FLOAT:
case DOUBLE: case DOUBLE:
ch7cast(&ex, '=', tp); ch7cast(&ex, '=', tp);
expr = ex;
#ifdef DEBUG #ifdef DEBUG
print_expr("init-expr after cast", ex); print_expr("init-expr after cast", expr);
#endif DEBUG #endif DEBUG
if (ex->ex_class == Float) if (expr->ex_class == Float)
C_con_fcon(ex->FL_VALUE, ex->ex_type->tp_size); C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
else else
if (ex->ex_class == Oper && ex->OP_OPER == INT2FLOAT) { if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) {
/* float f = 1; */ /* float f = 1; */
ex = ex->OP_RIGHT; expr = expr->OP_RIGHT;
if (is_cp_cst(ex)) if (is_cp_cst(expr))
C_con_fcon(long2str((long)ex->VL_VALUE, 10), C_con_fcon(long2str((long)expr->VL_VALUE, 10),
tp->tp_size); tp->tp_size);
else else
illegal_init_cst(ex); illegal_init_cst(expr);
} }
else else
illegal_init_cst(ex); illegal_init_cst(expr);
break; break;
#endif NOFLOAT #endif NOFLOAT
#ifndef NOBITFIELD #ifndef NOBITFIELD
case FIELD: case FIELD:
ch7cast(&ex, '=', tp->tp_up); ch7cast(&ex, '=', tp->tp_up);
expr = ex;
#ifdef DEBUG #ifdef DEBUG
print_expr("init-expr after cast", ex); print_expr("init-expr after cast", expr);
#endif DEBUG #endif DEBUG
if (is_cp_cst(ex)) if (is_cp_cst(expr))
put_bf(tp, ex->VL_VALUE); put_bf(tp, expr->VL_VALUE);
else else
illegal_init_cst(ex); illegal_init_cst(expr);
break; break;
#endif NOBITFIELD #endif NOBITFIELD
@ -574,7 +559,7 @@ zero_bytes(sd)
*/ */
register int n = sd->sd_sdef->sd_offset - sd->sd_offset - register int n = sd->sd_sdef->sd_offset - sd->sd_offset -
size_of_type(sd->sd_type, "struct member"); size_of_type(sd->sd_type, "struct member");
register count = n; register int count = n;
while (n-- > 0) while (n-- > 0)
con_nullbyte(); con_nullbyte();

View file

@ -251,6 +251,7 @@ unstack_world()
) { ) {
/* space must be allocated */ /* space must be allocated */
bss(idf); bss(idf);
if (def->df_sc != STATIC)
namelist(idf->id_text); /* may be common */ namelist(idf->id_text); /* may be common */
def->df_alloc = ALLOC_DONE; /* see Note below */ def->df_alloc = ALLOC_DONE; /* see Note below */
} }

View file

@ -158,7 +158,7 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */
} }
check_selector(idf, stp) check_selector(idf, stp)
struct idf *idf; register struct idf *idf;
struct type *stp; /* the type of the struct */ struct type *stp; /* the type of the struct */
{ {
/* checks if idf occurs already as a selector in /* checks if idf occurs already as a selector in

View file

@ -37,7 +37,7 @@ struct type *pa_type; /* Pointer-Arithmetic type */
struct type * struct type *
create_type(fund) create_type(fund)
register int fund; int fund;
{ {
/* A brand new struct type is created, and its tp_fund set /* A brand new struct type is created, and its tp_fund set
to fund. to fund.
@ -180,7 +180,7 @@ size_of_type(tp, nm)
} }
idf2type(idf, tpp) idf2type(idf, tpp)
register struct idf *idf; struct idf *idf;
struct type **tpp; struct type **tpp;
{ {
/* Decoding a typedef-ed identifier: if the size is yet /* Decoding a typedef-ed identifier: if the size is yet
@ -188,16 +188,15 @@ idf2type(idf, tpp)
prevent garbage at the initialisation of arrays with prevent garbage at the initialisation of arrays with
unknown size. unknown size.
*/ */
if ( idf->id_def->df_type->tp_size < (arith)0 && register struct type *tp = idf->id_def->df_type;
idf->id_def->df_type->tp_fund == ARRAY
) { if ( tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) {
struct type *ntp = new_type(); *tpp = new_type();
*ntp = *(idf->id_def->df_type); **tpp = *tp;
/* this is really a structure assignment, AAGH!!! */ /* this is really a structure assignment, AAGH!!! */
*tpp = ntp;
} }
else { else {
*tpp = idf->id_def->df_type; *tpp = tp;
} }
} }