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

Go to the documentation of this file.
00001 #define VERBOSE
00002 #undef VERBOSE
00003 /*
00004  *  Sets the decl_needed, mp_needed, and fc_body_needed fields 
00005  * in subtrees of p which might be executed if control reaches p.
00006  */
00007 
00008 # include "parm.h"
00009 # include <stdio.h>
00010 # include "stree/ststructs.mh"
00011 # include "codegen.h"
00012 # include "op_codes.h"
00013 
00014 extern LIST declsort();
00015 
00016 # ifdef VERBOSE
00017 #   define IFVERBOSE(x) x
00018 # else
00019 #   define IFVERBOSE(x)
00020 # endif
00021 
00022 extern FILE * Goutfile;
00023 
00024 extern FILE * unparse_file;
00025 
00026 extern boolean Tflag; /* generate trace code */
00027 
00028 extern boolean Vflag; /* generate optimization messages */
00029 
00030 extern unsigned indx_put; /* should be sttrelptr ... */
00031 
00032 extern int avail_loc;
00033 
00034 extern void Gexpression();
00035 extern void Gfc_add();
00036 extern int Glevel;  /* Current nesting level */
00037 
00038 /*
00039  *  Traverse the subtree headed by p and generate code for subexpressions
00040  * which might need to be evaluated.
00041  */
00042 Gtraverse(p)
00043 register NODE * p;
00044 {
00045 register NODE * v;
00046 
00047     if (p == NIL) return;
00048 
00049     switch ( p -> kind ) {
00050 
00051         case BLOCKDENOTATION :
00052                 {
00053 #                   ifdef VERBOSE
00054                         unparse_file = stdout;
00055                         printf("Traversing BLOCKDENOTATION:\n");
00056                         unparse(p);
00057                         printf("\n");
00058 #                   endif
00059                     if ( p -> bld_flags & REQUIRES_AR ) {
00060                         Glevel++;
00061                     }
00062                     maplist (v, (LIST)decl_sort(p->bld_declaration_list), {
00063                         ASSERT (v->kind == DECLARATION,
00064                                 "Gtraverse: decl expected");
00065                         if (v -> decl_needed) {
00066                             int tmp_loc = avail_loc++;
00067 
00068                             IFVERBOSE(
00069                                 printf("Compiling rhs: ");
00070                                 unparse(v -> decl_id);
00071                                 printf("\n");
00072                             )
00073                             /* Evaluate rhs. Store into a.r. */
00074                               gen2(DCL, tmp_loc, DCL_INT);
00075                               Gexpression (v-> decl_denotation, tmp_loc, FALSE);
00076                               gen3(STI, AR, v -> displacement, tmp_loc);
00077                               gen1(UDC, tmp_loc);
00078                         } else {
00079                           /* Generate code for nested function       */
00080                           /* constructions or modified primary nodes */
00081                           /* that may be evaluated.                  */
00082                             IFVERBOSE(
00083                                 printf("Traversing rhs: ");
00084                                 unparse(v -> decl_id);
00085                                 printf("\n");
00086                             )
00087                             Gtraverse (v -> decl_denotation);
00088                         }
00089                     }
00090                     );
00091                     maplist (v,p->bld_den_seq, {
00092                         IFVERBOSE(
00093                             printf("Traversing body expression:\n");
00094                             unparse(v);
00095                             printf("\n");
00096                         )
00097                         Gtraverse(v);
00098                     });
00099                     if ( p -> bld_flags & REQUIRES_AR ) {
00100                         Glevel--;
00101                     }
00102                     break;
00103                 }
00104                 
00105         case APPLICATION:
00106                 Gtraverse(p -> ap_operator);
00107                 maplist(v,p->ap_args,Gtraverse(v));
00108                 break;
00109 
00110         case LOOPDENOTATION:
00111         case GUARDEDLIST:
00112                 maplist(v,p->gl_list,Gtraverse(v));
00113                 break;
00114 
00115         case GUARDEDELEMENT:
00116                 Gtraverse(p->ge_guard);
00117                 Gtraverse(p->ge_element);
00118                 break;
00119 
00120         case OPRID:
00121         case LETTERID:
00122                 if (p -> sel_type != NIL) {
00123                     Gtraverse(p->sel_type);
00124                 }
00125                 break;
00126 
00127         case FUNCCONSTR:
00128                 if (p -> fc_body_needed) {
00129                   if (p -> fc_complexity & NO_SL) {
00130                     Gfc_add(p, Glevel+1, TRUE /* only fast version */);
00131                   } else {
00132                     Gfc_add(p, Glevel+1, FALSE);
00133                   }
00134                 } else {
00135                   if (Vflag) {
00136                     printf("Suppressing code generation for %s\n",
00137                            p -> fc_code_label);
00138                   }
00139                   Glevel++;  /* presumably not necessary, but ... */
00140                   Gtraverse(p -> fc_body);
00141                   Glevel--;
00142                 }
00143                 break;
00144 
00145         case USELIST:
00146                 maplist(q, p -> usl_den_seq, Gtraverse(q));
00147                 break;
00148 
00149         case MODPRIMARY:
00150 #               ifdef VERBOSE
00151                     unparse_file = stdout;
00152                     printf("Traversing MODPRIMARY:\n");
00153                     unparse(p);
00154                     printf("\n");
00155 #               endif
00156                 if (p -> mp_needed) {
00157 #                   ifdef VERBOSE
00158                         printf("Compiling primary\n");
00159 #                   endif
00160                     Gexpression(p, SK, FALSE);
00161                 } else {
00162 #                   ifdef VERBOSE
00163                         printf("Traversing primary\n");
00164 #                   endif
00165                     Gtraverse(p -> mp_primary);
00166                     if (p -> mp_type_modifier != NIL
00167                         && p -> mp_type_modifier -> kind == WITHLIST) {
00168                       maplist (q, p -> mp_type_modifier -> wl_component_list, {
00169                         IFVERBOSE(
00170                             printf("Traversing with list component:\n");
00171                             unparse(q -> decl_id);
00172                             printf("\n");
00173                         )
00174                         Gtraverse(q -> decl_denotation);
00175                       });
00176                     }
00177                 }
00178                 break;
00179 
00180         case ENUMERATION:
00181         case PRODCONSTRUCTION:
00182         case UNIONCONSTRUCTION:
00183                 /* Subexpressions are not evaluated */
00184                 break;
00185 
00186         case QSTR:
00187         case UQSTR:
00188                 Gtraverse(p -> sel_type);
00189                 /* There can't be anything of interest in the expansion */
00190                 break;
00191 
00192         case WORDELSE:
00193         case EXTERNDEF:
00194         case REXTERNDEF:
00195                 break;
00196 
00197         case RECORDCONSTRUCTION:
00198                 maplist(s, p -> rec_component_list, {
00199                   Gtraverse(s -> re_denotation);
00200                 });
00201                 break;
00202 
00203         case EXTENSION:
00204                 Gtraverse(p -> ext_denotation);
00205                 break;
00206 
00207         case VALSIGNATURE:
00208         case VARSIGNATURE:
00209         case FUNCSIGNATURE:
00210         case TYPESIGNATURE:
00211         case SIGNATURESIG:
00212                 break;
00213 
00214         case RECORDELEMENT:
00215         case DECLARATION:
00216         case PARAMETER:
00217         case LISTHEADER: /* should never get here */
00218         case TSCOMPONENT:
00219         case DEFCHARSIGS:
00220         case WITHLIST:
00221         case EXPORTLIST:
00222         case EXPORTELEMENT:
00223         case ALLCONSTANTS:
00224         case HIDELIST:
00225         case WORDCAND:
00226         case WORDCOR:
00227         default:
00228                 dbgmsg("Gtraverse: bad kind, kind = %d\n", p -> kind);
00229                 abort();
00230 
00231     };
00232     return;
00233 }

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