simplified 0-padding, minor cosmetic changes
authorceriel <none@none>
Wed, 10 Dec 1986 12:00:55 +0000 (12:00 +0000)
committerceriel <none@none>
Wed, 10 Dec 1986 12:00:55 +0000 (12:00 +0000)
lang/cem/cemcom/code.c
lang/cem/cemcom/domacro.c
lang/cem/cemcom/idf.c
lang/cem/cemcom/ival.c
lang/cem/cemcom/stack.c
lang/cem/cemcom/struct.c
lang/cem/cemcom/type.c

index ca5013c..e7cadc6 100644 (file)
@@ -169,6 +169,7 @@ begin_proc(name, def)       /* to be called when entering a procedure       */
                -       a fil pseudo instruction
        */
        arith size;
+       register struct type *tp = def->df_type;
 
 #ifndef        USE_TMP
        code_scope(name, def);
@@ -178,15 +179,16 @@ begin_proc(name, def)     /* to be called when entering a procedure       */
                DfaStartFunction(name);
 #endif DATAFLOW
 
-       if (def->df_type->tp_fund != FUNCTION) {
+       if (tp->tp_fund != FUNCTION) {
                error("making function body for non-function");
-               func_tp = error_type;
+               tp = error_type;
        }
        else
-               func_tp = def->df_type->tp_up;
-       size = ATW(func_tp->tp_size);
+               tp = tp->tp_up;
+       func_tp = tp;
+       size = ATW(tp->tp_size);
        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_bss_cst(size, (arith)0, 1);
        }
@@ -309,7 +311,7 @@ code_declaration(idf, expr, lvl, sc)
        */
        char *text = idf->id_text;
        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;
        
        if (def_sc == TYPEDEF)  /* no code for typedefs         */
@@ -387,6 +389,7 @@ loc_init(expr, id)
                It frees the expression afterwards.
        */
        register struct type *tp = id->id_def->df_type;
+       register struct expr *e = expr;
        
        ASSERT(id->id_def->df_sc != STATIC);
        switch (tp->tp_fund)    {
@@ -394,20 +397,20 @@ loc_init(expr, id)
        case STRUCT:
        case UNION:
                error("no automatic aggregate initialisation");
-               free_expression(expr);
+               free_expression(e);
                return;
        }
-       if (ISCOMMA(expr))      {       /* embraced: int i = {12};      */
+       if (ISCOMMA(e)) {       /* embraced: int i = {12};      */
                if (options['R'])       {
-                       if (ISCOMMA(expr->OP_LEFT)) /* int i = {{1}} */
-                               expr_error(expr, "extra braces not allowed");
+                       if (ISCOMMA(e->OP_LEFT)) /* int i = {{1}} */
+                               expr_error(e, "extra braces not allowed");
                        else
-                       if (expr->OP_RIGHT != 0) /* int i = {1 , 2} */
-                               expr_error(expr, "too many initializers");
+                       if (e->OP_RIGHT != 0) /* int i = {1 , 2} */
+                               expr_error(e, "too many initializers");
                }
-               while (expr)    {
-                       loc_init(expr->OP_LEFT, id);
-                       expr = expr->OP_RIGHT;
+               while (e)       {
+                       loc_init(e->OP_LEFT, id);
+                       e = e->OP_RIGHT;
                }
        }
        else    {       /* not embraced */
@@ -428,11 +431,10 @@ bss(idf)
 {
        /*      bss() allocates bss space for the global idf.
        */
-       register struct def *def = idf->id_def;
-       arith size = def->df_type->tp_size;
+       arith size = idf->id_def->df_type->tp_size;
        
 #ifndef        USE_TMP
-       code_scope(idf->id_text, def);
+       code_scope(idf->id_text, idf->id_def);
 #endif USE_TMP
        /*      Since bss() is only called if df_alloc is non-zero, and
                since df_alloc is only non-zero if size >= 0, we have:
index fe2f9f1..ba92c11 100644 (file)
@@ -134,7 +134,7 @@ skip_block()
                        seen.
        */
        register int ch;
-       register skiplevel = nestlevel; /* current nesting level        */
+       register int skiplevel = nestlevel; /* current nesting level    */
        struct token tk;
 
        NoUnstack++;
@@ -530,10 +530,10 @@ get_text(formals, length)
                identifiers, because they might be replaced by some actual
                parameter.  Other tokens will not be seen as such.
        */
-       register c;
-       register text_size;
+       register int c;
+       register int text_size;
        char *text = Malloc(text_size = ITEXTSIZE);
-       register pos = 0;
+       register int pos = 0;
 
        LoadChar(c);
 
index de39185..9baace1 100644 (file)
@@ -426,7 +426,6 @@ global_redecl(idf, new_sc, tp)
                        else    {
                                warning("%s redeclared to static",
                                                idf->id_text);
-                               def->df_sc = STATIC;
                        }
                        def->df_sc = new_sc;
                        break;
index f7e9412..b64577d 100644 (file)
@@ -25,6 +25,7 @@
 char *symbol2str();
 char *long2str();
 struct expr *do_array(), *do_struct(), *IVAL();
+extern char options[];
 
 /*     do_ival() performs the initialisation of a global variable
        of type tp with the initialisation expression expr by calling IVAL().
@@ -325,59 +326,40 @@ check_and_pad(ex, tpp)
 pad(tp)
        register struct type *tp;
 {
+       register arith sz = tp->tp_size;
+
        switch (tp->tp_fund) {
        case ARRAY:
-       {
-               register long dim;
-
                if (valid_type(tp->tp_up, "array element") == 0)
                        return;
-               dim = tp->tp_size / tp->tp_up->tp_size;
-               /* assume dimension is known    */
-               while (dim-- > 0)
-                       pad(tp->tp_up);
                break;
-       }
        case STRUCT:
-       {
-               register struct sdef *sdef = tp->tp_sdef;
-
                if (valid_type(tp, "struct") == 0)
                        return;
-               do {
-                       pad(sdef->sd_type);
-                       if (sdef->sd_sdef)
-                               zero_bytes(sdef);
-               } while (sdef = sdef->sd_sdef);
                break;
-       }
+       case UNION:
+               if (valid_type(tp, "union") == 0)
+                       return;
+               if (options['R']) {
+                       warning("initialisation of unions not allowed");
+               }
+               break;
 #ifndef NOBITFIELD
        case FIELD:
                put_bf(tp, (arith)0);
-               break;
+               return;
 #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:
-               break;
-       default:
-               crash("(generate) bad fundamental type %s\n",
-                       symbol2str(tp->tp_fund));
+               return;
+       }
+
+       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
        of this straightforward function.
 */
-check_ival(ex, tp)
-       struct expr *ex;
+check_ival(expr, tp)
+       register struct expr *expr;
        register struct type *tp;
 {
        /*      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
                expression is no longer a constant.
        */
+       struct expr *ex = expr;
        
        switch (tp->tp_fund) {
        case CHAR:
@@ -405,66 +388,68 @@ check_ival(ex, tp)
        case ENUM:
        case POINTER:
                ch7cast(&ex, '=', tp);
+               expr = ex;
 #ifdef DEBUG
-               print_expr("init-expr after cast", ex);
+               print_expr("init-expr after cast", expr);
 #endif DEBUG
-               if (!is_ld_cst(ex))
-                       illegal_init_cst(ex);
+               if (!is_ld_cst(expr))
+                       illegal_init_cst(expr);
                else
-               if (ex->VL_CLASS == Const)
-                       con_int(ex);
+               if (expr->VL_CLASS == Const)
+                       con_int(expr);
                else
-               if (ex->VL_CLASS == Name) {
-                       register struct idf *id = ex->VL_IDF;
-                       register struct def *df = id->id_def;
+               if (expr->VL_CLASS == Name) {
+                       register struct idf *idf = expr->VL_IDF;
 
-                       if (df->df_level >= L_LOCAL)
-                               illegal_init_cst(ex);
+                       if (idf->id_def->df_level >= L_LOCAL)
+                               illegal_init_cst(expr);
                        else    /* e.g., int f(); int p = f; */
-                       if (df->df_type->tp_fund == FUNCTION)
-                               C_con_pnam(id->id_text);
+                       if (idf->id_def->df_type->tp_fund == FUNCTION)
+                               C_con_pnam(idf->id_text);
                        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 {
-                       ASSERT(ex->VL_CLASS == Label);
-                       C_con_dlb(ex->VL_LBL, ex->VL_VALUE);
+                       ASSERT(expr->VL_CLASS == Label);
+                       C_con_dlb(expr->VL_LBL, expr->VL_VALUE);
                }
                break;
 #ifndef NOFLOAT
        case FLOAT:
        case DOUBLE:
                ch7cast(&ex, '=', tp);
+               expr = ex;
 #ifdef DEBUG
-               print_expr("init-expr after cast", ex);
+               print_expr("init-expr after cast", expr);
 #endif DEBUG
-               if (ex->ex_class == Float)
-                       C_con_fcon(ex->FL_VALUE, ex->ex_type->tp_size);
+               if (expr->ex_class == Float)
+                       C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
                else
-               if (ex->ex_class == Oper && ex->OP_OPER == INT2FLOAT) {
+               if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) {
                        /* float f = 1; */
-                       ex = ex->OP_RIGHT;
-                       if (is_cp_cst(ex))
-                               C_con_fcon(long2str((long)ex->VL_VALUE, 10),
+                       expr = expr->OP_RIGHT;
+                       if (is_cp_cst(expr))
+                               C_con_fcon(long2str((long)expr->VL_VALUE, 10),
                                        tp->tp_size);
                        else 
-                               illegal_init_cst(ex);
+                               illegal_init_cst(expr);
                }
                else
-                       illegal_init_cst(ex);
+                       illegal_init_cst(expr);
                break;
 #endif NOFLOAT
 
 #ifndef NOBITFIELD
        case FIELD:
                ch7cast(&ex, '=', tp->tp_up);
+               expr = ex;
 #ifdef DEBUG
-               print_expr("init-expr after cast", ex);
+               print_expr("init-expr after cast", expr);
 #endif DEBUG
-               if (is_cp_cst(ex))
-                       put_bf(tp, ex->VL_VALUE);
+               if (is_cp_cst(expr))
+                       put_bf(tp, expr->VL_VALUE);
                else
-                       illegal_init_cst(ex);
+                       illegal_init_cst(expr);
                break;
 #endif NOBITFIELD
 
@@ -574,7 +559,7 @@ zero_bytes(sd)
        */
        register int n = sd->sd_sdef->sd_offset - sd->sd_offset -
                size_of_type(sd->sd_type, "struct member");
-       register count = n;
+       register int count = n;
 
        while (n-- > 0)
                con_nullbyte();
index 7b0119d..237fdf2 100644 (file)
@@ -251,7 +251,8 @@ unstack_world()
                )       {
                        /* space must be allocated */
                        bss(idf);
-                       namelist(idf->id_text);         /* may be common */
+                       if (def->df_sc != STATIC)
+                               namelist(idf->id_text); /* may be common */
                        def->df_alloc = ALLOC_DONE;     /* see Note below */
                }
                se = se->next;
index 7eea59d..2728738 100644 (file)
@@ -158,7 +158,7 @@ add_sel(stp, tp, idf, sdefpp, szp, fd)      /* this is horrible */
 }
 
 check_selector(idf, stp)
-       struct idf *idf;
+       register struct idf *idf;
        struct type *stp;       /* the type of the struct */
 {
        /*      checks if idf occurs already as a selector in
index ec2c96b..6243395 100644 (file)
@@ -37,7 +37,7 @@ struct type *pa_type; /* Pointer-Arithmetic type      */
 
 struct type *
 create_type(fund)
-       register int fund;
+       int fund;
 {
        /*      A brand new struct type is created, and its tp_fund set
                to fund.
@@ -180,7 +180,7 @@ size_of_type(tp, nm)
 }
 
 idf2type(idf, tpp)
-       register struct idf *idf;
+       struct idf *idf;
        struct type **tpp;
 {
        /*      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
                unknown size.
        */
-       if (    idf->id_def->df_type->tp_size < (arith)0 &&
-               idf->id_def->df_type->tp_fund == ARRAY
-       )       {
-               struct type *ntp = new_type();
-               *ntp = *(idf->id_def->df_type);
+       register struct type *tp = idf->id_def->df_type;
+
+       if (    tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) {
+               *tpp = new_type();
+               **tpp = *tp;
                        /* this is really a structure assignment, AAGH!!! */
-               *tpp = ntp;
        }
        else    {
-               *tpp = idf->id_def->df_type;
+               *tpp = tp;
        }
 }