C:/Users/Dennis/src/lang/russell.orig/src/pass5d/compile_decl.c

Go to the documentation of this file.
00001 # include "parm.h"
00002 # include <stdio.h>
00003 # include "stree/ststructs.mh"
00004 # include "codegen.h"
00005 # include "op_codes.h"
00006 # include "pass4/sigs.h"
00007 # include "pass3/is_local.h"
00008 
00009 extern int yydebug;
00010 extern int yynerrs;
00011 
00012 extern FILE * Goutfile;
00013 
00014 extern NODE * Gcurrent;
00015 
00016 extern boolean Pflag;  /* Generate profiling code */
00017 extern boolean Tflag;  /* Generate trace code */
00018 extern boolean Vflag;  /* Optimization info */
00019 
00020 extern int avail_loc;
00021 
00022 /* Generate code corresponding for identifier binding corr. to declaration v */
00023 compile_decl(v)
00024 NODE * v;
00025 {
00026       int i = avail_loc++;
00027 
00028       if (!v -> decl_needed) {
00029           if (Vflag) {
00030               printf("Suppressing code to build %s:%s\n",
00031                      Gcurrent -> fc_code_label,
00032                      getname(v -> decl_id -> id_str_table_index));
00033           }
00034           /* Generate code for nested function       */
00035           /* constructions or modified primary nodes */
00036           /* that may be evaluated.  */
00037             Gtraverse (v -> decl_denotation);
00038           return;
00039       }
00040       if (v -> decl_special & VAR_ON_STACK) {
00041         ASSERT(v -> decl_signature -> kind == VARSIGNATURE,
00042                "codegen.c: bad stack allocated variable");
00043         /* initialize location */
00044         if (v -> decl_special & SIMPLE_VAR_ON_STACK) {
00045             gen3(STI, AR, v -> displacement, C0);
00046         } else if (v -> decl_special & PTR_VAR_ON_STACK) {
00047             gen2(HINT, OPT, 1);
00048             gen3(STI, AR, v -> displacement, UN);
00049         } else /* Initialized */ {
00050             NODE * appl = v -> decl_denotation;
00051             NODE * arg = first(appl -> ap_args);
00052 
00053             ASSERT(appl -> kind == APPLICATION,
00054                    "codegen.c: bad New application");
00055             gen2(DCL, i, DCL_INT);
00056             Gexpression (arg, i, FALSE);
00057             gen3(STI, AR, v -> displacement, i);
00058             gen1(UDC, i);
00059         }
00060       } else if (v -> decl_special & VAR_IN_REG) {
00061         ASSERT(v -> decl_signature -> kind == VARSIGNATURE,
00062                "codegen.c: bad register allocated variable");
00063         /* initialize location */
00064         if (v -> decl_special & SIMPLE_VAR_IN_REG) {
00065             gen2(MOV, C0, v -> displacement);
00066         } else if (v -> decl_special & PTR_VAR_IN_REG) {
00067             /* gen2(HINT, OPT, 1);  -- reduces effectiveness of -OO */
00068             gen2(MOV, UN, v -> displacement);
00069         } else /* Initialized */ {
00070             NODE * appl = v -> decl_denotation;
00071             NODE * arg = first(appl -> ap_args);
00072 
00073             ASSERT(appl -> kind == APPLICATION,
00074                    "codegen.c: bad New application");
00075             Gexpression (arg, v -> displacement, FALSE);
00076         }
00077       } else if (v -> decl_special & ARRAY_CONTIG) {
00078         NODE * op;
00079         int size;
00080 
00081         ASSERT(v -> decl_denotation -> kind == APPLICATION,
00082                "bad ARRAY_CONTIG flag");
00083         if (Vflag) {
00084             printf("Allocating contiguous array for %s:%s\n",
00085                     Gcurrent -> fc_code_label,
00086                     getname(v -> decl_id
00087                               -> id_str_table_index));
00088         }
00089         op = v -> decl_denotation -> ap_operator;
00090         size = special_val(op -> signature -> fsig_special);
00091         if (!Gpush_size(size, op)) {
00092             if (Vflag) {
00093                 printf("Couldn't get size of %s:%s\n",
00094                        Gcurrent -> fc_code_label,
00095                        getname(v -> decl_id
00096                                  -> id_str_table_index));
00097             }
00098             goto standard_decl;
00099         }
00100         if (special_tp(op -> signature -> fsig_special)
00101             == ARRAY_PTR_NEW) {
00102             genl(EXT, "_contig_pArray_New");
00103             genl(LBA, "_contig_pArray_New");
00104             gen1(CLC, 1);
00105             if (v -> decl_special & ID_IN_REG) {
00106                 gen2(MOV, RL, v -> displacement);
00107             } else {
00108                 gen3(STI, AR, v -> displacement, RL);
00109             }
00110         } else /* Non-pointer array */ {
00111             genl(EXT, "_contig_Array_New");
00112             genl(LBA, "_contig_Array_New");
00113             gen1(CLC, 1);
00114             if (v -> decl_special & ID_IN_REG) {
00115                 gen2(MOV, RL, v -> displacement);
00116             } else {
00117                 gen3(STI, AR, v -> displacement, RL);
00118             }
00119         }
00120       } else {
00121         standard_decl:
00122             if (v -> decl_special & ID_IN_REG) {
00123                 Gexpression(v -> decl_denotation,
00124                             v -> displacement, FALSE);
00125             } else {
00126                 gen2(DCL, i, DCL_INT);
00127                 Gexpression (v-> decl_denotation, i, FALSE);
00128                 gen3(STI, AR, v -> displacement, i);
00129                 gen1(UDC, i);
00130             }
00131       }
00132 }

Generated on Fri Jan 25 10:39:47 2008 for russell by  doxygen 1.5.4