Annotation of gcc/toplev.c, revision 1.1.1.8

1.1       root        1: /* Top level of GNU C compiler
1.1.1.2   root        2:    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1       root        3: 
                      4: This file is part of GNU CC.
                      5: 
                      6: GNU CC is distributed in the hope that it will be useful,
                      7: but WITHOUT ANY WARRANTY.  No author or distributor
                      8: accepts responsibility to anyone for the consequences of using it
                      9: or for whether it serves any particular purpose or works at all,
                     10: unless he says so in writing.  Refer to the GNU CC General Public
                     11: License for full details.
                     12: 
                     13: Everyone is granted permission to copy, modify and redistribute
                     14: GNU CC, but only under the conditions described in the
                     15: GNU CC General Public License.   A copy of this license is
                     16: supposed to have been given to you along with GNU CC so you
                     17: can know your rights and responsibilities.  It should be in a
                     18: file named COPYING.  Among other things, the copyright notice
                     19: and this notice must be preserved on all copies.  */
                     20: 
                     21: 
                     22: /* This is the top level of cc1.
                     23:    It parses command args, opens files, invokes the various passes
                     24:    in the proper order, and counts the time used by each.
                     25:    Error messages and low-level interface to malloc also handled here.  */
                     26: 
                     27: #include "config.h"
                     28: #include <stdio.h>
                     29: #include <signal.h>
1.1.1.2   root       30: 
1.1.1.4   root       31: #include <sys/types.h>
                     32: #include <sys/stat.h>
                     33: 
1.1.1.2   root       34: #ifdef USG
                     35: #include <sys/param.h>
                     36: #include <sys/times.h>
                     37: #include <time.h>   /* Correct for hpux at least.  Is it good on other USG?  */
                     38: #else
                     39: #ifndef VMS
1.1       root       40: #include <sys/time.h>
                     41: #include <sys/resource.h>
1.1.1.2   root       42: #endif
                     43: #endif
                     44: 
1.1       root       45: #include "tree.h"
                     46: #include "c-tree.h"
                     47: #include "rtl.h"
1.1.1.2   root       48: #include "flags.h"
1.1       root       49: 
                     50: extern int yydebug;
                     51: 
                     52: extern FILE *finput;
                     53: 
                     54: extern void init_lex ();
                     55: extern void init_decl_processing ();
                     56: extern void init_tree ();
                     57: extern void init_rtl ();
                     58: extern void init_optabs ();
1.1.1.2   root       59: extern void init_reg_sets ();
1.1       root       60: extern void dump_flow_info ();
                     61: extern void dump_local_alloc ();
                     62: 
1.1.1.2   root       63: void rest_of_decl_compilation ();
                     64: void error ();
                     65: void error_with_file_and_line ();
                     66: void set_target_switch ();
                     67: 
1.1       root       68: /* Bit flags that specify the machine subtype we are compiling for.
                     69:    Bits are tested using macros TARGET_... defined in the tm-...h file
                     70:    and set by `-m...' switches.  */
                     71: 
                     72: int target_flags;
                     73: 
1.1.1.2   root       74: /* Name of current original source file (what was input to cpp).
                     75:    This comes from each #-command in the actual input.  */
1.1       root       76: 
1.1.1.2   root       77: char *input_filename;
                     78: 
                     79: /* Name of top-level original source file (what was input to cpp).
1.1.1.8 ! root       80:    This comes from the #-command at the beginning of the actual input.
        !            81:    If there isn't any there, then this is the cc1 input file name.  */
1.1.1.2   root       82: 
                     83: char *main_input_filename;
1.1       root       84: 
                     85: /* Current line number in real source file.  */
                     86: 
                     87: extern int lineno;
                     88: 
                     89: /* FUNCTION_DECL for function now being parsed or compiled.  */
                     90: 
                     91: extern tree current_function_decl;
                     92: 
                     93: /* Name to use as base of names for dump output files.  */
                     94: 
                     95: char *dump_base_name;
                     96: 
                     97: /* Flags saying which kinds of debugging dump have been requested.  */
                     98: 
                     99: int rtl_dump = 0;
                    100: int rtl_dump_and_exit = 0;
                    101: int jump_opt_dump = 0;
                    102: int cse_dump = 0;
                    103: int loop_dump = 0;
                    104: int flow_dump = 0;
                    105: int combine_dump = 0;
                    106: int local_reg_dump = 0;
                    107: int global_reg_dump = 0;
1.1.1.2   root      108: int jump2_opt_dump = 0;
1.1       root      109: 
                    110: /* 1 => write gdb debugging output (using symout.c).  -g
1.1.1.6   root      111:    2 => write dbx debugging output (using dbxout.c).  -G
                    112:    3 => write sdb debugging output (using sdbout.c).  -g.  */
1.1       root      113: 
1.1.1.4   root      114: enum debugger write_symbols = NO_DEBUG;
1.1       root      115: 
1.1.1.6   root      116: /* Nonzero means can use our own extensions to DBX format.
                    117:    Relevant only with write_symbols == DBX_DEBUG.  */
                    118: 
                    119: int use_gdb_dbx_extensions;
                    120: 
1.1       root      121: /* Nonzero means do optimizations.  -opt.  */
                    122: 
                    123: int optimize = 0;
                    124: 
1.1.1.2   root      125: /* Nonzero for -fforce-mem: load memory value into a register
1.1       root      126:    before arithmetic on it.  This makes better cse but slower compilation.  */
                    127: 
1.1.1.2   root      128: int flag_force_mem = 0;
1.1       root      129: 
1.1.1.2   root      130: /* Nonzero for -fforce-addr: load memory address into a register before
1.1       root      131:    reference to memory.  This makes better cse but slower compilation.  */
                    132: 
1.1.1.2   root      133: int flag_force_addr = 0;
                    134: 
                    135: /* Nonzero for -fdefer-pop: don't pop args after each function call;
                    136:    instead save them up to pop many calls' args with one insns.  */
                    137: 
                    138: int flag_defer_pop = 1;
                    139: 
                    140: /* Nonzero for -ffloat-store: don't allocate floats and doubles
                    141:    in extended-precision registers.  */
                    142: 
                    143: int flag_float_store = 0;
                    144: 
                    145: /* Nonzero for -fcombine-regs:
                    146:    allow instruction combiner to combine an insn
                    147:    that just copies one reg to another.  */
                    148: 
                    149: int flag_combine_regs = 0;
                    150: 
                    151: /* Nonzero for -fwritable-strings:
                    152:    store string constants in data segment and don't uniquize them.  */
                    153: 
                    154: int flag_writable_strings = 0;
                    155: 
                    156: /* Nonzero means don't put addresses of constant functions in registers.
                    157:    Used for compiling the Unix kernel, where strange substitutions are
                    158:    done on the assembly output.  */
                    159: 
                    160: int flag_no_function_cse = 0;
                    161: 
                    162: /* Nonzero for -fomit-frame-pointer:
                    163:    don't make a frame pointer in simple functions that don't require one.  */
                    164: 
                    165: int flag_omit_frame_pointer = 0;
                    166: 
                    167: /* Nonzero to inhibit use of define_optimization peephole opts.  */
                    168: 
                    169: int flag_no_peephole = 0;
                    170: 
                    171: /* Nonzero means all references through pointers are volatile.  */
                    172: 
                    173: int flag_volatile;
1.1       root      174: 
                    175: /* Nonzero means do stupid register allocation.  -noreg.
1.1.1.2   root      176:    This and `optimize' are controlled by different switches in cc1,
1.1       root      177:    but normally cc controls them both with the -O switch.  */
                    178: 
                    179: int obey_regdecls = 0;
                    180: 
                    181: /* Don't print functions as they are compiled and don't print
                    182:    times taken by the various passes.  -quiet.  */
                    183: 
                    184: int quiet_flag = 0;
                    185: 
                    186: /* Don't print warning messages.  -w.  */
                    187: 
                    188: int inhibit_warnings = 0;
                    189: 
1.1.1.2   root      190: /* Do print extra warnings (such as for uninitialized variables).  -W.  */
                    191: 
                    192: int extra_warnings = 0;
                    193: 
1.1       root      194: /* Number of error messages and warning messages so far.  */
                    195: 
                    196: int errorcount = 0;
                    197: int warningcount = 0;
1.1.1.7   root      198: int sorrycount = 0;
1.1       root      199: 
1.1.1.2   root      200: /* Nonzero if generating code to do profiling.  */
                    201: 
                    202: int profile_flag = 0;
                    203: 
1.1       root      204: /* Nonzero for -pedantic switch: warn about anything
1.1.1.7   root      205:    that standard spec forbids.  */
1.1       root      206: 
                    207: int pedantic = 0;
                    208: 
1.1.1.2   root      209: /* Nonzero for -finline-functions: ok to inline functions that look like
                    210:    good inline candidates.  */
                    211: 
                    212: int flag_inline_functions;
                    213: 
                    214: /* Nonzero for -fkeep-inline-functions: even if we make a function
                    215:    go inline everywhere, keep its defintion around for debugging
                    216:    purposes.  */
                    217: 
                    218: int flag_keep_inline_functions;
                    219: 
1.1       root      220: /* Name for output file of assembly code, specified with -o.  */
                    221: 
                    222: char *asm_file_name;
                    223: 
                    224: /* Name for output file of GDB symbol segment, specified with -symout.  */
                    225: 
                    226: char *sym_file_name;
                    227: 
                    228: /* Output files for assembler code (real compiler output)
                    229:    and debugging dumps.  */
                    230: 
                    231: FILE *asm_out_file;
                    232: FILE *rtl_dump_file;
                    233: FILE *jump_opt_dump_file;
                    234: FILE *cse_dump_file;
                    235: FILE *loop_dump_file;
                    236: FILE *flow_dump_file;
                    237: FILE *combine_dump_file;
                    238: FILE *local_reg_dump_file;
                    239: FILE *global_reg_dump_file;
1.1.1.2   root      240: FILE *jump2_opt_dump_file;
1.1       root      241: 
                    242: /* Time accumulators, to count the total time spent in various passes.  */
                    243: 
                    244: int parse_time;
                    245: int varconst_time;
1.1.1.2   root      246: int integration_time;
1.1       root      247: int jump_time;
                    248: int cse_time;
                    249: int loop_time;
                    250: int flow_time;
                    251: int combine_time;
                    252: int local_alloc_time;
                    253: int global_alloc_time;
                    254: int final_time;
                    255: int symout_time;
                    256: int dump_time;
                    257: 
                    258: /* Return time used so far, in microseconds.  */
                    259: 
1.1.1.2   root      260: int
1.1       root      261: gettime ()
                    262: {
1.1.1.2   root      263: #ifdef USG
                    264:   struct tms tms;
                    265: #else
                    266: #ifndef VMS
1.1       root      267:   struct rusage rusage;
1.1.1.2   root      268: #else /* VMS */
                    269:   struct
                    270:     {
                    271:       int proc_user_time;
                    272:       int proc_system_time;
                    273:       int child_user_time;
                    274:       int child_system_time;
                    275:     } vms_times;
                    276: #endif
                    277: #endif
                    278: 
1.1       root      279:   if (quiet_flag)
                    280:     return 0;
1.1.1.2   root      281: 
                    282: #ifdef USG
                    283:   times (&tms);
                    284:   return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
                    285: #else
                    286: #ifndef VMS
1.1       root      287:   getrusage (0, &rusage);
                    288:   return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
                    289:          + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1.1.1.2   root      290: #else /* VMS */
                    291:   times (&vms_times);
                    292:   return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
                    293: #endif
                    294: #endif
1.1       root      295: }
                    296: 
                    297: #define TIMEVAR(VAR, BODY)    \
1.1.1.3   root      298: do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
1.1       root      299: 
1.1.1.2   root      300: void
1.1       root      301: print_time (str, total)
                    302:      char *str;
                    303:      int total;
                    304: {
1.1.1.2   root      305:   fprintf (stderr,
                    306:           "time in %s: %d.%06d\n",
                    307:           str, total / 1000000, total % 1000000);
1.1       root      308: }
                    309: 
                    310: /* Count an error or warning.  Return 1 if the message should be printed.  */
                    311: 
                    312: int
                    313: count_error (warningp)
                    314:      int warningp;
                    315: {
                    316:   if (warningp && inhibit_warnings)
                    317:     return 0;
                    318: 
                    319:   if (warningp)
                    320:     warningcount++;
                    321:   else
                    322:     errorcount++;
                    323: 
                    324:   return 1;
                    325: }
                    326: 
                    327: /* Print a fatal error message.  NAME is the text.
                    328:    Also include a system error message based on `errno'.  */
                    329: 
1.1.1.2   root      330: void
1.1       root      331: pfatal_with_name (name)
1.1.1.2   root      332:      char *name;
1.1       root      333: {
                    334:   fprintf (stderr, "cc1: ");
                    335:   perror (name);
                    336:   exit (35);
                    337: }
                    338: 
                    339: void
1.1.1.2   root      340: fatal_io_error (name)
                    341:      char *name;
                    342: {
                    343:   fprintf (stderr, "cc1:%s: I/O error\n", name);
                    344:   exit (35);
                    345: }
                    346: 
                    347: void
1.1.1.7   root      348: fatal (s, v)
1.1       root      349:      char *s;
                    350: {
1.1.1.7   root      351:   error (s, v);
1.1       root      352:   exit (34);
                    353: }
1.1.1.8 ! root      354: 
        !           355: static int need_error_newline;
        !           356: 
        !           357: /* Function of last error message;
        !           358:    more generally, function such that if next error message is in it
        !           359:    then we don't have to mention the function name.  */
        !           360: static tree last_error_function = NULL;
1.1       root      361: 
                    362: /* Called when the start of a function definition is parsed,
                    363:    this function prints on stderr the name of the function.  */
                    364: 
                    365: void
                    366: announce_function (decl)
                    367:      tree decl;
                    368: {
                    369:   if (! quiet_flag)
                    370:     {
                    371:       fprintf (stderr, " %s", IDENTIFIER_POINTER (DECL_NAME (decl)));
                    372:       fflush (stderr);
                    373:     }
1.1.1.8 ! root      374:   need_error_newline = 1;
        !           375:   last_error_function = current_function_decl;
1.1       root      376: }
1.1.1.8 ! root      377: 
1.1.1.2   root      378: /* Prints out, if necessary, the name of the current function
                    379:    which caused an error.  Called from all error and warning functions.  */
                    380: 
                    381: void
                    382: report_error_function()
                    383: {
1.1.1.8 ! root      384:   if (need_error_newline)
        !           385:     {
        !           386:       fprintf (stderr, "\n");
        !           387:       need_error_newline = 0;
        !           388:     }
1.1.1.2   root      389: 
                    390:   if (last_error_function != current_function_decl)
                    391:     {
                    392:       if (current_function_decl == NULL)
1.1.1.8 ! root      393:        fprintf (stderr, "At top level:\n");
1.1.1.2   root      394:       else
1.1.1.8 ! root      395:        fprintf (stderr, "In function %s:\n",
        !           396:                 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
        !           397: 
1.1.1.2   root      398:       last_error_function = current_function_decl;
                    399:     }
                    400: }
1.1       root      401: 
                    402: /* Report an error at the current line number.
                    403:    S and V are a string and an arg for `printf'.  */
                    404: 
                    405: void
1.1.1.7   root      406: error (s, v, v2)
1.1       root      407:      char *s;
                    408:      int v;                    /* @@also used as pointer */
1.1.1.7   root      409:      int v2;                   /* @@also used as pointer */
1.1       root      410: {
1.1.1.7   root      411:   error_with_file_and_line (input_filename, lineno, s, v, v2);
1.1       root      412: }
                    413: 
1.1.1.2   root      414: /* Report an error at line LINE of file FILE.
1.1       root      415:    S and V are a string and an arg for `printf'.  */
                    416: 
1.1.1.2   root      417: void
1.1.1.7   root      418: error_with_file_and_line (file, line, s, v, v2)
1.1.1.2   root      419:      char *file;
1.1       root      420:      int line;
                    421:      char *s;
                    422:      int v;
1.1.1.7   root      423:      int v2;
1.1       root      424: {
                    425:   count_error (0);
                    426: 
1.1.1.2   root      427:   report_error_function ();
                    428: 
                    429:   if (file)
                    430:     fprintf (stderr, "%s:%d: ", file, line);
                    431:   else
                    432:     fprintf (stderr, "cc1: ");
1.1.1.7   root      433:   fprintf (stderr, s, v, v2);
1.1       root      434:   fprintf (stderr, "\n");
                    435: }
                    436: 
1.1.1.2   root      437: /* Report an error at the declaration DECL.
                    438:    S is string which uses %s to substitute the declaration name.  */
1.1       root      439: 
                    440: void
1.1.1.2   root      441: error_with_decl (decl, s)
                    442:      tree decl;
1.1       root      443:      char *s;
                    444: {
1.1.1.2   root      445:   count_error (0);
                    446: 
                    447:   report_error_function ();
                    448: 
                    449:   fprintf (stderr, "%s:%d: ",
                    450:           DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
                    451: 
                    452:   if (DECL_NAME (decl))
                    453:     fprintf (stderr, s, IDENTIFIER_POINTER (DECL_NAME (decl)));
                    454:   else
                    455:     fprintf (stderr, s, "((anonymous))");
                    456:   fprintf (stderr, "\n");
1.1       root      457: }
                    458: 
                    459: /* Report a warning at line LINE.
                    460:    S and V are a string and an arg for `printf'.  */
                    461: 
1.1.1.2   root      462: void
1.1.1.7   root      463: warning_with_line (line, s, v, v2)
1.1       root      464:      int line;
                    465:      char *s;
                    466:      int v;
1.1.1.7   root      467:      int v2;
1.1       root      468: {
                    469:   if (count_error (1) == 0)
                    470:     return;
                    471: 
1.1.1.2   root      472:   report_error_function ();
                    473: 
                    474:   if (input_filename)
                    475:     fprintf (stderr, "%s:%d: ", input_filename, line);
                    476:   else
                    477:     fprintf (stderr, "cc1: ");
1.1       root      478: 
                    479:   fprintf (stderr, "warning: ");
1.1.1.7   root      480:   fprintf (stderr, s, v, v2);
1.1       root      481:   fprintf (stderr, "\n");
                    482: }
1.1.1.2   root      483: 
                    484: /* Report a warning at the current line number.
                    485:    S and V are a string and an arg for `printf'.  */
                    486: 
                    487: void
1.1.1.7   root      488: warning (s, v, v2)
1.1.1.2   root      489:      char *s;
                    490:      int v;                    /* @@also used as pointer */
1.1.1.7   root      491:      int v2;
1.1.1.2   root      492: {
1.1.1.7   root      493:   warning_with_line (lineno, s, v, v2);
1.1.1.2   root      494: }
                    495: 
                    496: /* Report a warning at the declaration DECL.
                    497:    S is string which uses %s to substitute the declaration name.  */
                    498: 
                    499: void
                    500: warning_with_decl (decl, s)
                    501:      tree decl;
                    502:      char *s;
                    503: {
                    504:   if (count_error (1) == 0)
                    505:     return;
                    506: 
                    507:   report_error_function ();
                    508: 
                    509:   fprintf (stderr, "%s:%d: ",
                    510:           DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
                    511: 
                    512:   fprintf (stderr, "warning: ");
                    513:   if (DECL_NAME (decl))
                    514:     fprintf (stderr, s, IDENTIFIER_POINTER (DECL_NAME (decl)));
                    515:   else
                    516:     fprintf (stderr, s, "((anonymous))");
                    517:   fprintf (stderr, "\n");
                    518: }
1.1.1.7   root      519: 
                    520: /* Apologize for not implementing some feature.
                    521:    S, V, and V2 are a string and args for `printf'.  */
                    522: 
                    523: void
                    524: sorry (s, v, v2)
                    525:      char *s;
                    526:      int v, v2;
                    527: {
                    528:   sorrycount++;
                    529:   if (input_filename)
                    530:     fprintf (stderr, "%s:%d: ", input_filename, lineno);
                    531:   else
                    532:     fprintf (stderr, "cc1: ");
                    533: 
                    534:   fprintf (stderr, "sorry, not implemented: ");
                    535:   fprintf (stderr, s, v, v2);
                    536:   fprintf (stderr, "\n");
                    537: }
                    538: 
                    539: /* Apologize for not implementing some feature, then quit.
                    540:    S, V, and V2 are a string and args for `printf'.  */
                    541: 
                    542: void
                    543: really_sorry (s, v, v2)
                    544:      char *s;
                    545:      int v, v2;
                    546: {
                    547:   if (input_filename)
                    548:     fprintf (stderr, "%s:%d: ", input_filename, lineno);
                    549:   else
                    550:     fprintf (stderr, "c++: ");
                    551: 
                    552:   fprintf (stderr, "sorry, not implemented: ");
                    553:   fprintf (stderr, s, v, v2);
                    554:   fatal (" (fatal)\n");
                    555: }
1.1       root      556: 
                    557: /* When `malloc.c' is compiled with `rcheck' defined,
                    558:    it calls this function to report clobberage.  */
                    559: 
1.1.1.2   root      560: void
1.1       root      561: botch (s)
                    562: {
                    563:   abort ();
                    564: }
                    565: 
                    566: /* Same as `malloc' but report error if no memory available.  */
                    567: 
1.1.1.2   root      568: int
1.1       root      569: xmalloc (size)
                    570:      unsigned size;
                    571: {
                    572:   register int value = (int) malloc (size);
                    573:   if (value == 0)
                    574:     fatal ("Virtual memory exhausted.");
                    575:   return value;
                    576: }
                    577: 
                    578: /* Same as `realloc' but report error if no memory available.  */
                    579: 
                    580: int
                    581: xrealloc (ptr, size)
                    582:      char *ptr;
                    583:      int size;
                    584: {
                    585:   int result = realloc (ptr, size);
                    586:   if (!result)
1.1.1.2   root      587:     fatal ("Virtual memory exhausted.");
1.1       root      588:   return result;
                    589: }
                    590: 
                    591: /* Return the logarithm of X, base 2, considering X unsigned,
                    592:    if X is a power of 2.  Otherwise, returns -1.  */
                    593: 
                    594: int
                    595: exact_log2 (x)
                    596:      register unsigned int x;
                    597: {
                    598:   register int log = 0;
                    599:   for (log = 0; log < HOST_BITS_PER_INT; log++)
                    600:     if (x == (1 << log))
                    601:       return log;
                    602:   return -1;
                    603: }
                    604: 
                    605: /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
                    606:    If X is 0, return -1.  */
                    607: 
                    608: int
                    609: floor_log2 (x)
                    610:      register unsigned int x;
                    611: {
                    612:   register int log = 0;
                    613:   for (log = 0; log < HOST_BITS_PER_INT; log++)
                    614:     if ((x & ((-1) << log)) == 0)
                    615:       return log - 1;
                    616:   return HOST_BITS_PER_INT - 1;
                    617: }
                    618: 
                    619: /* Compile an entire file of output from cpp, named NAME.
                    620:    Write a file of assembly output and various debugging dumps.  */
                    621: 
                    622: static void
                    623: compile_file (name)
                    624:      char *name;
                    625: {
                    626:   tree globals;
                    627:   int start_time;
                    628:   int dump_base_name_length = strlen (dump_base_name);
                    629: 
                    630:   parse_time = 0;
                    631:   varconst_time = 0;
1.1.1.2   root      632:   integration_time = 0;
1.1       root      633:   jump_time = 0;
                    634:   cse_time = 0;
                    635:   loop_time = 0;
                    636:   flow_time = 0;
                    637:   combine_time = 0;
                    638:   local_alloc_time = 0;
                    639:   global_alloc_time = 0;
                    640:   final_time = 0;
                    641:   symout_time = 0;
1.1.1.2   root      642:   dump_time = 0;
1.1       root      643: 
                    644:   /* Open input file.  */
                    645: 
                    646:   finput = fopen (name, "r");
                    647:   if (finput == 0)
                    648:     pfatal_with_name (name);
                    649: 
                    650:   /* Initialize data in various passes.  */
                    651: 
                    652:   init_tree ();
                    653:   init_lex ();
                    654:   init_rtl ();
1.1.1.2   root      655:   init_emit_once ();
1.1       root      656:   init_decl_processing ();
                    657:   init_optabs ();
                    658: 
                    659:   /* If rtl dump desired, open the output file.  */
                    660:   if (rtl_dump)
                    661:     {
                    662:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    663:       strcpy (dumpname, dump_base_name);
                    664:       strcat (dumpname, ".rtl");
                    665:       rtl_dump_file = fopen (dumpname, "w");
                    666:       if (rtl_dump_file == 0)
                    667:        pfatal_with_name (dumpname);
                    668:     }
                    669: 
                    670:   /* If jump_opt dump desired, open the output file.  */
                    671:   if (jump_opt_dump)
                    672:     {
                    673:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    674:       strcpy (dumpname, dump_base_name);
                    675:       strcat (dumpname, ".jump");
                    676:       jump_opt_dump_file = fopen (dumpname, "w");
                    677:       if (jump_opt_dump_file == 0)
                    678:        pfatal_with_name (dumpname);
                    679:     }
                    680: 
                    681:   /* If cse dump desired, open the output file.  */
                    682:   if (cse_dump)
                    683:     {
                    684:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    685:       strcpy (dumpname, dump_base_name);
                    686:       strcat (dumpname, ".cse");
                    687:       cse_dump_file = fopen (dumpname, "w");
                    688:       if (cse_dump_file == 0)
                    689:        pfatal_with_name (dumpname);
                    690:     }
                    691: 
                    692:   /* If loop dump desired, open the output file.  */
                    693:   if (loop_dump)
                    694:     {
                    695:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    696:       strcpy (dumpname, dump_base_name);
                    697:       strcat (dumpname, ".loop");
                    698:       loop_dump_file = fopen (dumpname, "w");
                    699:       if (loop_dump_file == 0)
                    700:        pfatal_with_name (dumpname);
                    701:     }
                    702: 
                    703:   /* If flow dump desired, open the output file.  */
                    704:   if (flow_dump)
                    705:     {
                    706:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    707:       strcpy (dumpname, dump_base_name);
                    708:       strcat (dumpname, ".flow");
                    709:       flow_dump_file = fopen (dumpname, "w");
                    710:       if (flow_dump_file == 0)
                    711:        pfatal_with_name (dumpname);
                    712:     }
                    713: 
                    714:   /* If combine dump desired, open the output file.  */
                    715:   if (combine_dump)
                    716:     {
                    717:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
                    718:       strcpy (dumpname, dump_base_name);
                    719:       strcat (dumpname, ".combine");
                    720:       combine_dump_file = fopen (dumpname, "w");
                    721:       if (combine_dump_file == 0)
                    722:        pfatal_with_name (dumpname);
                    723:     }
                    724: 
                    725:   /* If local_reg dump desired, open the output file.  */
                    726:   if (local_reg_dump)
                    727:     {
                    728:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    729:       strcpy (dumpname, dump_base_name);
                    730:       strcat (dumpname, ".lreg");
                    731:       local_reg_dump_file = fopen (dumpname, "w");
                    732:       if (local_reg_dump_file == 0)
                    733:        pfatal_with_name (dumpname);
                    734:     }
                    735: 
                    736:   /* If global_reg dump desired, open the output file.  */
                    737:   if (global_reg_dump)
                    738:     {
                    739:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
                    740:       strcpy (dumpname, dump_base_name);
                    741:       strcat (dumpname, ".greg");
                    742:       global_reg_dump_file = fopen (dumpname, "w");
                    743:       if (global_reg_dump_file == 0)
                    744:        pfatal_with_name (dumpname);
                    745:     }
                    746: 
1.1.1.2   root      747:   /* If jump2_opt dump desired, open the output file.  */
                    748:   if (jump2_opt_dump)
                    749:     {
                    750:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
                    751:       strcpy (dumpname, dump_base_name);
                    752:       strcat (dumpname, ".jump2");
                    753:       jump2_opt_dump_file = fopen (dumpname, "w");
                    754:       if (jump2_opt_dump_file == 0)
                    755:        pfatal_with_name (dumpname);
                    756:     }
                    757: 
1.1       root      758:   /* Open assembler code output file.  */
                    759:  
                    760:   {
                    761:     register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1.1.1.2   root      762:     int len = strlen (dump_base_name);
1.1       root      763:     strcpy (dumpname, dump_base_name);
1.1.1.2   root      764:     if (len > 2 && ! strcmp (".c", dumpname + len - 2))
                    765:       dumpname[len - 2] = 0;
1.1.1.7   root      766:     else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
                    767:       dumpname[len - 2] = 0;
1.1.1.2   root      768:     else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
                    769:       dumpname[len - 3] = 0;
1.1       root      770:     strcat (dumpname, ".s");
1.1.1.2   root      771:     if (asm_file_name == 0)
                    772:       {
                    773:        asm_file_name = (char *) malloc (strlen (dumpname) + 1);
                    774:        strcpy (asm_file_name, dumpname);
                    775:       }
                    776:     asm_out_file = fopen (asm_file_name, "w");
1.1       root      777:     if (asm_out_file == 0)
                    778:       pfatal_with_name (asm_file_name ? asm_file_name : dumpname);
                    779:   }
                    780: 
                    781:   input_filename = name;
                    782: 
                    783:   /* the beginning of the file is a new line; check for # */
                    784:   /* With luck, we discover the real source file's name from that
                    785:      and put it in input_filename.  */
1.1.1.4   root      786:   ungetc (check_newline (), finput);
                    787: 
1.1.1.8 ! root      788:   /* If the input doesn't start with a #line, use the input name
        !           789:      as the official input file name.  */
        !           790:   if (main_input_filename == 0)
        !           791:     main_input_filename = name;
        !           792: 
1.1.1.4   root      793:   ASM_FILE_START (asm_out_file);
1.1       root      794: 
                    795:   /* If GDB symbol table desired, open the GDB symbol output file.  */
1.1.1.4   root      796:   if (write_symbols == GDB_DEBUG)
1.1       root      797:     {
                    798:       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1.1.1.2   root      799:       int len = strlen (dump_base_name);
1.1       root      800:       strcpy (dumpname, dump_base_name);
1.1.1.2   root      801:       if (len > 2 && ! strcmp (".c", dumpname + len - 2))
                    802:        dumpname[len - 2] = 0;
1.1.1.7   root      803:       else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
                    804:        dumpname[len - 2] = 0;
1.1.1.2   root      805:       else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
                    806:        dumpname[len - 3] = 0;
1.1       root      807:       strcat (dumpname, ".sym");
                    808:       if (sym_file_name == 0)
                    809:        sym_file_name = dumpname;
1.1.1.4   root      810:       symout_init (sym_file_name, asm_out_file, main_input_filename);
1.1       root      811:     }
                    812: 
                    813:   /* If dbx symbol table desired, initialize writing it
                    814:      and output the predefined types.  */
1.1.1.4   root      815: #ifdef DBX_DEBUGGING_INFO
                    816:   if (write_symbols == DBX_DEBUG)
1.1.1.2   root      817:     dbxout_init (asm_out_file, main_input_filename);
1.1.1.4   root      818: #endif
                    819: #ifdef SDB_DEBUGGING_INFO
                    820:   if (write_symbols == SDB_DEBUG)
                    821:     sdbout_init (asm_out_file, main_input_filename);
                    822: #endif
1.1       root      823: 
                    824:   /* Initialize yet another pass.  */
                    825: 
1.1.1.2   root      826:   init_final (main_input_filename);
1.1       root      827: 
                    828:   start_time = gettime ();
                    829: 
                    830:   /* Call the parser, which parses the entire file
                    831:      (calling rest_of_compilation for each function).  */
                    832: 
                    833:   yyparse ();
                    834: 
                    835:   /* Compilation is now finished except for writing
                    836:      what's left of the symbol table output.  */
                    837: 
                    838:   parse_time += gettime () - start_time;
                    839: 
1.1.1.2   root      840:   parse_time -= varconst_time;
                    841: 
1.1       root      842:   globals = getdecls ();
                    843: 
1.1.1.2   root      844:   /* Really define vars that have had only a tentative definition.
                    845:      Really output inline functions that must actually be callable
                    846:      and have not been output so far.  */
                    847: 
                    848:   {
                    849:     tree decl;
                    850:     for (decl = globals; decl; decl = TREE_CHAIN (decl))
                    851:       {
                    852:        if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
                    853:            && ! TREE_ASM_WRITTEN (decl))
                    854:          rest_of_decl_compilation (decl, 0, 1, 1);
                    855:        if (TREE_CODE (decl) == FUNCTION_DECL
                    856:            && ! TREE_ASM_WRITTEN (decl)
                    857:            && DECL_INITIAL (decl) != 0
                    858:            && TREE_ADDRESSABLE (decl))
                    859:          output_inline_function (decl);
                    860:       }
                    861:   }
                    862: 
1.1       root      863:   /* Do dbx symbols */
1.1.1.4   root      864: #ifdef DBX_DEBUGGING_INFO
                    865:   if (write_symbols == DBX_DEBUG)
1.1       root      866:     TIMEVAR (symout_time,
                    867:             {
                    868:               dbxout_tags (gettags ());
                    869:               dbxout_types (get_permanent_types ());
                    870:             });
1.1.1.4   root      871: #endif
                    872: 
                    873: #ifdef SDB_DEBUGGING_INFO
                    874:   if (write_symbols == SDB_DEBUG)
                    875:     TIMEVAR (symout_time,
                    876:             {
                    877:               sdbout_tags (gettags ());
                    878:               sdbout_types (get_permanent_types ());
                    879:             });
                    880: #endif
1.1       root      881: 
                    882:   /* Do gdb symbols */
1.1.1.4   root      883:   if (write_symbols == GDB_DEBUG)
1.1       root      884:     TIMEVAR (symout_time,
                    885:             {
                    886:               struct stat statbuf;
                    887:               fstat (fileno (finput), &statbuf);
                    888:               symout_types (get_permanent_types ());
                    889:               symout_top_blocks (globals, gettags ());
                    890:               symout_finish (name, statbuf.st_ctime);
                    891:             });
                    892: 
1.1.1.2   root      893:   /* Close the dump files.  */
1.1       root      894: 
                    895:   if (rtl_dump)
                    896:     fclose (rtl_dump_file);
                    897: 
                    898:   if (jump_opt_dump)
                    899:     fclose (jump_opt_dump_file);
                    900: 
                    901:   if (cse_dump)
                    902:     fclose (cse_dump_file);
                    903: 
                    904:   if (loop_dump)
                    905:     fclose (loop_dump_file);
                    906: 
                    907:   if (flow_dump)
                    908:     fclose (flow_dump_file);
                    909: 
                    910:   if (combine_dump)
                    911:     {
                    912:       dump_combine_total_stats (combine_dump_file);
                    913:       fclose (combine_dump_file);
                    914:     }
                    915: 
                    916:   if (local_reg_dump)
                    917:     fclose (local_reg_dump_file);
                    918: 
                    919:   if (global_reg_dump)
                    920:     fclose (global_reg_dump_file);
                    921: 
1.1.1.2   root      922:   if (jump2_opt_dump)
                    923:     fclose (jump2_opt_dump_file);
                    924: 
                    925:   /* Close non-debugging input and output files.  */
                    926: 
                    927:   fclose (finput);
                    928:   if (ferror (asm_out_file) != 0)
                    929:     fatal_io_error (asm_file_name);
                    930:   fclose (asm_out_file);
                    931: 
1.1       root      932:   /* Print the times.  */
                    933: 
                    934:   if (! quiet_flag)
                    935:     {
1.1.1.2   root      936:       fprintf (stderr,"\n");
1.1       root      937:       print_time ("parse", parse_time);
1.1.1.2   root      938:       print_time ("integration", integration_time);
1.1       root      939:       print_time ("jump", jump_time);
                    940:       print_time ("cse", cse_time);
                    941:       print_time ("loop", loop_time);
                    942:       print_time ("flow", flow_time);
                    943:       print_time ("combine", combine_time);
                    944:       print_time ("local-alloc", local_alloc_time);
                    945:       print_time ("global-alloc", global_alloc_time);
                    946:       print_time ("final", final_time);
                    947:       print_time ("varconst", varconst_time);
                    948:       print_time ("symout", symout_time);
                    949:       print_time ("dump", dump_time);
                    950:     }
                    951: }
                    952: 
1.1.1.2   root      953: /* This is called from finish_decl (within yyparse)
                    954:    for each declaration of a function or variable.
                    955:    This does nothing for automatic variables.
                    956:    Otherwise, it sets up the RTL and outputs any assembler code
                    957:    (label definition, storage allocation and initialization).
                    958: 
                    959:    DECL is the declaration.  If ASMSPEC is nonzero, it specifies
                    960:    the assembler symbol name to be used.  TOP_LEVEL is nonzero
                    961:    if this declaration is not within a function.  */
                    962: 
                    963: void
                    964: rest_of_decl_compilation (decl, asmspec, top_level, at_end)
                    965:      tree decl;
                    966:      tree asmspec;
                    967:      int top_level;
                    968:      int at_end;
                    969: {
                    970:   /* Declarations of variables, and of functions defined elsewhere.  */
                    971: 
                    972:   if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
                    973:     TIMEVAR (varconst_time,
                    974:             {
1.1.1.5   root      975:               assemble_variable (decl, asmspec, top_level,
                    976:                                  write_symbols, at_end);
1.1.1.2   root      977:             });
1.1.1.4   root      978: #ifdef DBX_DEBUGGING_INFO
                    979:   else if (write_symbols == DBX_DEBUG && TREE_CODE (decl) == TYPE_DECL)
1.1.1.3   root      980:     TIMEVAR (varconst_time, dbxout_symbol (decl, 0));
1.1.1.4   root      981: #endif
                    982: #ifdef SDB_DEBUGGING_INFO
                    983:   else if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == TYPE_DECL)
                    984:     TIMEVAR (varconst_time, sdbout_symbol (decl, 0));
                    985: #endif
1.1.1.2   root      986: 
                    987:   if (top_level)
                    988:     {
1.1.1.4   root      989:       if (write_symbols == GDB_DEBUG)
1.1.1.2   root      990:        {
                    991:          TIMEVAR (symout_time,
                    992:                   {
                    993:                     /* The initizations make types when they contain
                    994:                        string constants.  The types are on the temporary
                    995:                        obstack, so output them now before they go away.  */
                    996:                     symout_types (get_temporary_types ());
                    997:                   });
                    998:        }
                    999:       else
                   1000:        /* Clean out the temporary type list, since the types will go away.  */
                   1001:        get_temporary_types ();
                   1002:     }
                   1003: }
                   1004: 
1.1       root     1005: /* This is called from finish_function (within yyparse)
1.1.1.2   root     1006:    after each top-level definition is parsed.
1.1       root     1007:    It is supposed to compile that function or variable
                   1008:    and output the assembler code for it.
                   1009:    After we return, the tree storage is freed.  */
                   1010: 
                   1011: void
1.1.1.2   root     1012: rest_of_compilation (decl)
1.1       root     1013:      tree decl;
                   1014: {
                   1015:   register rtx insns;
                   1016:   int start_time = gettime ();
                   1017:   int tem;
                   1018: 
1.1.1.2   root     1019:   /* If we are reconsidering an inline function
                   1020:      at the end of compilation, skip the stuff for making it inline.  */
1.1       root     1021: 
1.1.1.2   root     1022:   if (DECL_SAVED_INSNS (decl) == 0)
1.1       root     1023:     {
                   1024: 
1.1.1.2   root     1025:       /* If requested, consider whether to make this function inline.  */
                   1026:       if (flag_inline_functions || TREE_INLINE (decl))
                   1027:        {
                   1028:          TIMEVAR (integration_time,
                   1029:                   {
                   1030:                     int specd = TREE_INLINE (decl);
                   1031:                     char *lose = function_cannot_inline_p (decl);
                   1032:                     if (lose != 0 && specd)
                   1033:                       warning_with_decl (decl, lose);
                   1034:                     if (lose == 0)
                   1035:                       save_for_inline (decl);
                   1036:                     else
                   1037:                       TREE_INLINE (decl) = 0;
                   1038:                   });
                   1039:        }
1.1       root     1040: 
1.1.1.2   root     1041:       insns = get_insns ();
1.1       root     1042: 
                   1043:       /* Dump the rtl code if we are dumping rtl.  */
                   1044: 
                   1045:       if (rtl_dump)
                   1046:        TIMEVAR (dump_time,
                   1047:                 {
                   1048:                   fprintf (rtl_dump_file, "\n;; Function %s\n\n",
                   1049:                            IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1.1.2   root     1050:                   if (DECL_SAVED_INSNS (decl))
                   1051:                     fprintf (rtl_dump_file, ";; (integrable)\n\n");
1.1       root     1052:                   print_rtl (rtl_dump_file, insns);
                   1053:                   fflush (rtl_dump_file);
                   1054:                 });
                   1055: 
1.1.1.2   root     1056:       /* If function is inline, and we don't yet know whether to
                   1057:         compile it by itself, defer decision till end of compilation.
                   1058:         finish_compilation will call rest_of_compilation again
                   1059:         for those functions that need to be output.  */
                   1060: 
                   1061:       if (TREE_PUBLIC (decl) == 0
                   1062:          && TREE_INLINE (decl)
                   1063:          && ! flag_keep_inline_functions)
1.1       root     1064:        goto exit_rest_of_compilation;
1.1.1.2   root     1065:     }
1.1       root     1066: 
1.1.1.2   root     1067:   if (rtl_dump_and_exit)
                   1068:     goto exit_rest_of_compilation;
1.1       root     1069: 
1.1.1.2   root     1070:   TREE_ASM_WRITTEN (decl) = 1;
1.1       root     1071: 
1.1.1.2   root     1072:   insns = get_insns ();
1.1       root     1073: 
1.1.1.2   root     1074:   /* Copy any shared structure that should not be shared.  */
1.1       root     1075: 
1.1.1.2   root     1076:   unshare_all_rtl (insns);
1.1       root     1077: 
1.1.1.2   root     1078:   /* See if we have allocated stack slots that are not directly addressable.
                   1079:      If so, scan all the insns and create explicit address computation
                   1080:      for all references to such slots.  */
                   1081: /*   fixup_stack_slots (); */
1.1       root     1082: 
1.1.1.2   root     1083:   /* Do jump optimization the first time, if -opt.
                   1084:      Also do it if -W, but in that case it doesn't change the rtl code,
                   1085:      it only computes whether control can drop off the end of the function.  */
1.1       root     1086: 
1.1.1.2   root     1087:   if (optimize || extra_warnings || warn_return_type)
                   1088:     TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
1.1       root     1089: 
1.1.1.2   root     1090:   /* Dump rtl code after jump, if we are doing that.  */
1.1       root     1091: 
1.1.1.2   root     1092:   if (jump_opt_dump)
                   1093:     TIMEVAR (dump_time,
                   1094:             {
                   1095:               fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
                   1096:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1097:               print_rtl (jump_opt_dump_file, insns);
                   1098:               fflush (jump_opt_dump_file);
                   1099:             });
1.1       root     1100: 
1.1.1.2   root     1101:   /* Perform common subexpression elimination.
                   1102:      Nonzero value from `cse_main' means that jumps were simplified
                   1103:      and some code may now be unreachable, so do
                   1104:      jump optimization again.  */
1.1       root     1105: 
1.1.1.2   root     1106:   if (optimize)
                   1107:     {
                   1108:       TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 0));
1.1       root     1109: 
1.1.1.2   root     1110:       TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num ()));
1.1       root     1111: 
1.1.1.2   root     1112:       if (tem)
                   1113:        TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
                   1114:     }
1.1       root     1115: 
1.1.1.2   root     1116:   /* Dump rtl code after cse, if we are doing that.  */
1.1       root     1117: 
1.1.1.2   root     1118:   if (cse_dump)
                   1119:     TIMEVAR (dump_time,
                   1120:             {
                   1121:               fprintf (cse_dump_file, "\n;; Function %s\n\n",
                   1122:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1123:               print_rtl (cse_dump_file, insns);
                   1124:               fflush (cse_dump_file);
                   1125:             });
1.1       root     1126: 
1.1.1.2   root     1127:   if (loop_dump)
                   1128:     TIMEVAR (dump_time,
                   1129:             {
                   1130:               fprintf (loop_dump_file, "\n;; Function %s\n\n",
                   1131:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1132:             });
1.1       root     1133: 
1.1.1.2   root     1134:   /* Move constant computations out of loops.  */
1.1       root     1135: 
1.1.1.2   root     1136:   if (optimize)
                   1137:     {
                   1138:       TIMEVAR (loop_time,
                   1139:               {
                   1140:                 reg_scan (insns, max_reg_num (), 1);
                   1141:                 loop_optimize (insns, max_reg_num (),
                   1142:                                loop_dump ? loop_dump_file : 0);
                   1143:               });
                   1144:     }
1.1       root     1145: 
1.1.1.2   root     1146:   /* Dump rtl code after loop opt, if we are doing that.  */
1.1       root     1147: 
1.1.1.2   root     1148:   if (loop_dump)
                   1149:     TIMEVAR (dump_time,
                   1150:             {
                   1151:               print_rtl (loop_dump_file, insns);
                   1152:               fflush (loop_dump_file);
                   1153:             });
1.1       root     1154: 
1.1.1.2   root     1155:   /* Now we choose between stupid (pcc-like) register allocation
                   1156:      (if we got the -noreg switch and not -opt)
                   1157:      and smart register allocation.  */
1.1       root     1158: 
1.1.1.2   root     1159:   if (optimize)                /* Stupid allocation probably won't work */
                   1160:     obey_regdecls = 0; /* if optimizations being done.  */
1.1       root     1161: 
1.1.1.2   root     1162:   regclass_init ();
1.1       root     1163: 
1.1.1.2   root     1164:   /* Print function header into flow dump now
                   1165:      because doing the flow analysis makes some of the dump.  */
1.1       root     1166: 
1.1.1.2   root     1167:   if (flow_dump)
                   1168:     TIMEVAR (dump_time,
                   1169:             {
                   1170:               fprintf (flow_dump_file, "\n;; Function %s\n\n",
                   1171:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1172:             });
                   1173: 
                   1174:   if (obey_regdecls)
                   1175:     {
                   1176:       TIMEVAR (flow_time,
                   1177:               {
                   1178:                 regclass (insns, max_reg_num ());
                   1179:                 stupid_life_analysis (insns, max_reg_num (),
                   1180:                                       flow_dump_file);
                   1181:               });
                   1182:     }
                   1183:   else
                   1184:     {
                   1185:       /* Do control and data flow analysis,
                   1186:         and write some of the results to dump file.  */
1.1       root     1187: 
1.1.1.2   root     1188:       TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
                   1189:                                         flow_dump_file));
                   1190:       if (extra_warnings)
                   1191:        uninitialized_vars_warning (DECL_INITIAL (decl));
                   1192:     }
1.1       root     1193: 
1.1.1.2   root     1194:   /* Dump rtl after flow analysis.  */
1.1       root     1195: 
1.1.1.2   root     1196:   if (flow_dump)
                   1197:     TIMEVAR (dump_time,
                   1198:             {
                   1199:               print_rtl (flow_dump_file, insns);
                   1200:               fflush (flow_dump_file);
                   1201:             });
1.1       root     1202: 
1.1.1.2   root     1203:   /* If -opt, try combining insns through substitution.  */
1.1       root     1204: 
1.1.1.2   root     1205:   if (optimize)
                   1206:     TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
1.1       root     1207: 
1.1.1.2   root     1208:   /* Dump rtl code after insn combination.  */
1.1       root     1209: 
1.1.1.2   root     1210:   if (combine_dump)
                   1211:     TIMEVAR (dump_time,
                   1212:             {
                   1213:               fprintf (combine_dump_file, "\n;; Function %s\n\n",
                   1214:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1215:               dump_combine_stats (combine_dump_file);
                   1216:               print_rtl (combine_dump_file, insns);
                   1217:               fflush (combine_dump_file);
                   1218:             });
1.1       root     1219: 
1.1.1.2   root     1220:   /* Unless we did stupid register allocation,
                   1221:      allocate pseudo-regs that are used only within 1 basic block.  */
1.1       root     1222: 
1.1.1.2   root     1223:   if (!obey_regdecls)
                   1224:     TIMEVAR (local_alloc_time,
                   1225:             {
                   1226:               regclass (insns, max_reg_num ());
                   1227:               local_alloc ();
                   1228:             });
1.1       root     1229: 
1.1.1.2   root     1230:   /* Dump rtl code after allocating regs within basic blocks.  */
1.1       root     1231: 
1.1.1.2   root     1232:   if (local_reg_dump)
                   1233:     TIMEVAR (dump_time,
                   1234:             {
                   1235:               fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
                   1236:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1237:               dump_flow_info (local_reg_dump_file);
                   1238:               dump_local_alloc (local_reg_dump_file);
                   1239:               print_rtl (local_reg_dump_file, insns);
                   1240:               fflush (local_reg_dump_file);
                   1241:             });
1.1       root     1242: 
1.1.1.2   root     1243:   if (global_reg_dump)
                   1244:     TIMEVAR (dump_time,
                   1245:             fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
                   1246:                      IDENTIFIER_POINTER (DECL_NAME (decl))));
                   1247: 
                   1248:   /* Unless we did stupid register allocation,
                   1249:      allocate remaining pseudo-regs, then do the reload pass
                   1250:      fixing up any insns that are invalid.  */
                   1251: 
                   1252:   TIMEVAR (global_alloc_time,
                   1253:           {
                   1254:             if (!obey_regdecls)
                   1255:               global_alloc (global_reg_dump ? global_reg_dump_file : 0);
                   1256:             else
                   1257:               reload (insns, 0,
                   1258:                       global_reg_dump ? global_reg_dump_file : 0);
                   1259:           });
                   1260: 
                   1261:   if (global_reg_dump)
                   1262:     TIMEVAR (dump_time,
                   1263:             {
                   1264:               dump_global_regs (global_reg_dump_file);
                   1265:               print_rtl (global_reg_dump_file, insns);
                   1266:               fflush (global_reg_dump_file);
                   1267:             });
1.1       root     1268: 
1.1.1.2   root     1269:   /* One more attempt to remove jumps to .+1
                   1270:      left by dead-store-elimination.
                   1271:      Also do cross-jumping this time
                   1272:      and delete no-op move insns.  */
1.1       root     1273: 
1.1.1.2   root     1274:   if (optimize)
                   1275:     {
                   1276:       TIMEVAR (jump_time, jump_optimize (insns, 1, 1));
                   1277:     }
1.1       root     1278: 
1.1.1.2   root     1279:   /* Dump rtl code after jump, if we are doing that.  */
                   1280: 
                   1281:   if (jump2_opt_dump)
                   1282:     TIMEVAR (dump_time,
                   1283:             {
                   1284:               fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
                   1285:                        IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1286:               print_rtl (jump2_opt_dump_file, insns);
                   1287:               fflush (jump2_opt_dump_file);
                   1288:             });
                   1289: 
                   1290:   /* Now turn the rtl into assembler code.  */
                   1291: 
                   1292:   TIMEVAR (final_time,
                   1293:           {
                   1294:             assemble_function (decl);
                   1295:             final_start_function (insns, asm_out_file,
                   1296:                                   write_symbols, optimize);
                   1297:             final (insns, asm_out_file,
                   1298:                    write_symbols, optimize);
                   1299:             final_end_function (insns, asm_out_file,
                   1300:                                 write_symbols, optimize);
                   1301:             fflush (asm_out_file);
                   1302:           });
1.1       root     1303: 
1.1.1.2   root     1304:   /* Write GDB symbols if requested */
1.1       root     1305: 
1.1.1.4   root     1306:   if (write_symbols == GDB_DEBUG)
1.1.1.2   root     1307:     {
                   1308:       TIMEVAR (symout_time,
                   1309:               {
                   1310:                 symout_types (get_permanent_types ());
                   1311:                 symout_types (get_temporary_types ());
                   1312: 
                   1313:                 DECL_BLOCK_SYMTAB_ADDRESS (decl)
                   1314:                   = symout_function (DECL_INITIAL (decl),
                   1315:                                      DECL_ARGUMENTS (decl), 0);
1.1.1.6   root     1316:                 symout_function_end ();
1.1.1.2   root     1317:               });
1.1       root     1318:     }
1.1.1.2   root     1319:   else
                   1320:     get_temporary_types ();
                   1321: 
                   1322:   /* Write DBX symbols if requested */
                   1323: 
1.1.1.4   root     1324: #ifdef DBX_DEBUGGING_INFO
                   1325:   if (write_symbols == DBX_DEBUG)
1.1.1.2   root     1326:     TIMEVAR (symout_time, dbxout_function (decl));
1.1.1.4   root     1327: #endif
1.1       root     1328: 
                   1329:  exit_rest_of_compilation:
                   1330: 
1.1.1.8 ! root     1331:   /* Clear out the real_constant_chain before some of the rtx's
        !          1332:      it runs through become garbage.  */
        !          1333: 
        !          1334:   clear_const_double_mem ();
        !          1335: 
1.1       root     1336:   /* The parsing time is all the time spent in yyparse
                   1337:      *except* what is spent in this function.  */
                   1338: 
                   1339:   parse_time -= gettime () - start_time;
                   1340: }
                   1341: 
                   1342: /* Entry point of cc1.  Decode command args, then call compile_file.
1.1.1.2   root     1343:    Exit code is 35 if can't open files, 34 if fatal error,
                   1344:    33 if had nonfatal errors, else success.  */
1.1       root     1345: 
                   1346: int
                   1347: main (argc, argv, envp)
                   1348:      int argc;
                   1349:      char **argv;
                   1350:      char **envp;
                   1351: {
                   1352:   register int i;
1.1.1.2   root     1353:   char *filename = 0;
                   1354:   int print_mem_flag = 0;
                   1355: 
                   1356: #ifdef RLIMIT_STACK
                   1357:   /* Get rid of any avoidable limit on stack size.  */
                   1358:   {
                   1359:     struct rlimit rlim;
                   1360: 
                   1361:     /* Set the stack limit huge so that alloca does not fail. */
                   1362:     getrlimit (RLIMIT_STACK, &rlim);
                   1363:     rlim.rlim_cur = rlim.rlim_max;
                   1364:     setrlimit (RLIMIT_STACK, &rlim);
                   1365:   }
                   1366: #endif /* RLIMIT_STACK */
                   1367: 
                   1368:   /* Initialize whether `char' is signed.  */
                   1369:   flag_signed_char = DEFAULT_SIGNED_CHAR;
                   1370: 
1.1.1.4   root     1371:   /* This is zeroed by -O.  */
                   1372:   obey_regdecls = 1;
                   1373: 
                   1374:   /* Initialize register usage now so switches may override.  */
1.1.1.2   root     1375:   init_reg_sets ();
1.1       root     1376: 
                   1377:   target_flags = 0;
                   1378:   set_target_switch ("");
                   1379: 
                   1380:   for (i = 1; i < argc; i++)
                   1381:     if (argv[i][0] == '-')
                   1382:       {
                   1383:        register char *str = argv[i] + 1;
                   1384:        if (str[0] == 'Y')
                   1385:          str++;
                   1386: 
                   1387:        if (str[0] == 'm')
                   1388:          set_target_switch (&str[1]);
                   1389:        else if (!strcmp (str, "dumpbase"))
                   1390:          {
                   1391:            dump_base_name = argv[++i];
                   1392:          }
                   1393:        else if (str[0] == 'd')
                   1394:          {
                   1395:            register char *p = &str[1];
                   1396:            while (*p)
                   1397:              switch (*p++)
                   1398:                {
                   1399:                case 'c':
                   1400:                  combine_dump = 1;
                   1401:                  break;
                   1402:                case 'f':
                   1403:                  flow_dump = 1;
                   1404:                  break;
                   1405:                case 'g':
                   1406:                  global_reg_dump = 1;
                   1407:                  break;
                   1408:                case 'j':
                   1409:                  jump_opt_dump = 1;
                   1410:                  break;
1.1.1.2   root     1411:                case 'J':
                   1412:                  jump2_opt_dump = 1;
                   1413:                  break;
1.1       root     1414:                case 'l':
                   1415:                  local_reg_dump = 1;
                   1416:                  break;
                   1417:                case 'L':
                   1418:                  loop_dump = 1;
                   1419:                  break;
1.1.1.2   root     1420:                case 'm':
                   1421:                  print_mem_flag = 1;
                   1422:                  break;
1.1       root     1423:                case 'r':
                   1424:                  rtl_dump = 1;
                   1425:                  break;
                   1426:                case 's':
                   1427:                  cse_dump = 1;
                   1428:                  break;
                   1429:                case 'y':
                   1430:                  yydebug = 1;
                   1431:                  break;
                   1432:                }
                   1433:          }
1.1.1.2   root     1434:        else if (str[0] == 'f')
                   1435:          {
                   1436:            register char *p = &str[1];
                   1437:            if (!strcmp (p, "float-store"))
                   1438:              flag_float_store = 1;
                   1439:            else if (!strcmp (p, "volatile"))
                   1440:              flag_volatile = 1;
                   1441:            else if (!strcmp (p, "defer-pop"))
                   1442:              flag_defer_pop = 1;
                   1443:            else if (!strcmp (p, "no-defer-pop"))
                   1444:              flag_defer_pop = 0;
                   1445:            else if (!strcmp (p, "omit-frame-pointer"))
                   1446:              flag_omit_frame_pointer = 1;
                   1447:            else if (!strcmp (p, "no-omit-frame-pointer"))
                   1448:              flag_omit_frame_pointer = 0;
1.1.1.7   root     1449:            else if (!strcmp (p, "writable-strings"))
                   1450:              flag_writable_strings = 1;
1.1.1.2   root     1451:            else if (!strcmp (p, "no-peephole"))
                   1452:              flag_no_peephole = 1;
                   1453:            else if (!strcmp (p, "force-mem"))
                   1454:              flag_force_mem = 1;
                   1455:            else if (!strcmp (p, "force-addr"))
                   1456:              flag_force_addr = 1;
                   1457:            else if (!strcmp (p, "combine-regs"))
                   1458:              flag_combine_regs = 1;
                   1459:            else if (!strcmp (p, "no-function-cse"))
                   1460:              flag_no_function_cse = 1;
                   1461:            else if (!strncmp (p, "fixed-", 6))
                   1462:              fix_register (&p[6], 1, 1);
                   1463:            else if (!strncmp (p, "call-used-", 10))
                   1464:              fix_register (&p[10], 0, 1);
                   1465:            else if (!strncmp (p, "call-saved-", 11))
                   1466:              fix_register (&p[11], 0, 0);
                   1467:            else if (!strcmp (p, "inline-functions"))
                   1468:              flag_inline_functions = 1;
                   1469:            else if (!strcmp (p, "keep-inline-functions"))
                   1470:              flag_keep_inline_functions = 1;
1.1.1.7   root     1471:            else if (! lang_decode_option (argv[i]))
                   1472:              error ("Invalid option `%s'", argv[i]);         
1.1.1.2   root     1473:          }
1.1       root     1474:        else if (!strcmp (str, "noreg"))
1.1.1.4   root     1475:          ;
1.1.1.2   root     1476:        else if (!strcmp (str, "opt"))
1.1.1.4   root     1477:          optimize = 1, obey_regdecls = 0;
                   1478:        else if (!strcmp (str, "O"))
                   1479:          optimize = 1, obey_regdecls = 0;
1.1.1.2   root     1480:        else if (!strcmp (str, "pedantic"))
                   1481:          pedantic = 1;
1.1.1.7   root     1482:        else if (lang_decode_option (argv[i]))
                   1483:          ;
1.1.1.2   root     1484:        else if (!strcmp (str, "quiet"))
                   1485:          quiet_flag = 1;
                   1486:        else if (!strcmp (str, "version"))
                   1487:          {
1.1.1.7   root     1488:            extern char *version_string, *language_string;
                   1489:            printf ("%s version %s", language_string, version_string);
1.1.1.2   root     1490: #ifdef TARGET_VERSION
                   1491:            TARGET_VERSION;
                   1492: #endif
                   1493: #ifdef __GNUC__
                   1494: #ifndef __VERSION__
                   1495: #define __VERSION__ "[unknown]"
                   1496: #endif
                   1497:            printf (" compiled by GNU C version %s.\n", __VERSION__);
                   1498: #else
                   1499:            printf (" compiled by CC.\n");
                   1500: #endif
                   1501:          }
1.1       root     1502:        else if (!strcmp (str, "w"))
                   1503:          inhibit_warnings = 1;
1.1.1.2   root     1504:        else if (!strcmp (str, "W"))
                   1505:          extra_warnings = 1;
                   1506:        else if (!strcmp (str, "p"))
                   1507:          profile_flag = 1;
1.1.1.4   root     1508:        else if (!strcmp (str, "gg"))
                   1509:          write_symbols = GDB_DEBUG;
                   1510: #ifdef DBX_DEBUGGING_INFO
1.1       root     1511:        else if (!strcmp (str, "g"))
1.1.1.4   root     1512:          write_symbols = DBX_DEBUG;
1.1       root     1513:        else if (!strcmp (str, "G"))
1.1.1.4   root     1514:          write_symbols = DBX_DEBUG;
                   1515: #endif
                   1516: #ifdef SDB_DEBUGGING_INFO
                   1517:        else if (!strcmp (str, "g"))
                   1518:          write_symbols = SDB_DEBUG;
                   1519:        else if (!strcmp (str, "G"))
                   1520:          write_symbols = SDB_DEBUG;
                   1521: #endif
1.1       root     1522:        else if (!strcmp (str, "symout"))
                   1523:          {
1.1.1.4   root     1524:            if (write_symbols == NO_DEBUG)
                   1525:              write_symbols = GDB_DEBUG;
1.1       root     1526:            sym_file_name = argv[++i];
                   1527:          }
                   1528:        else if (!strcmp (str, "o"))
                   1529:          {
                   1530:            asm_file_name = argv[++i];
                   1531:          }
                   1532:        else
1.1.1.7   root     1533:          error ("Invalid option `%s'", argv[i]);
1.1       root     1534:       }
                   1535:     else
                   1536:       filename = argv[i];
                   1537: 
                   1538:   if (filename == 0)
                   1539:     fatal ("no input file specified");
                   1540: 
                   1541:   if (dump_base_name == 0)
                   1542:     dump_base_name = filename;
1.1.1.2   root     1543: 
                   1544: #ifdef OVERRIDE_OPTIONS
                   1545:   /* Some machines may reject certain combinations of options.  */
                   1546:   OVERRIDE_OPTIONS;
                   1547: #endif
                   1548: 
1.1.1.4   root     1549:   /* Now that register usage is specified, convert it to HARD_REG_SETs.  */
                   1550:   init_reg_sets_1 ();
                   1551: 
1.1       root     1552:   compile_file (filename);
                   1553: 
1.1.1.2   root     1554: #ifndef USG
                   1555: #ifndef VMS
                   1556:   if (print_mem_flag)
                   1557:     {
                   1558:       extern char **environ;
                   1559:       caddr_t lim = (caddr_t) sbrk (0);
                   1560:       
                   1561:       fprintf (stderr, "Data size %d.\n",
                   1562:               (int) lim - (int) &environ);
                   1563:       fflush (stderr);
                   1564: 
                   1565:       system ("ps v");
                   1566:     }
                   1567: #endif /* not VMS */
                   1568: #endif /* not USG */
                   1569: 
1.1       root     1570:   if (errorcount)
1.1.1.2   root     1571:     exit (FATAL_EXIT_CODE);
1.1.1.7   root     1572:   if (sorrycount)
                   1573:     exit (FATAL_EXIT_CODE);
1.1.1.2   root     1574:   exit (SUCCESS_EXIT_CODE);
                   1575:   return 34;
1.1       root     1576: }
                   1577: 
                   1578: /* Decode -m switches.  */
                   1579: 
                   1580: /* Here is a table, controlled by the tm-...h file, listing each -m switch
                   1581:    and which bits in `target_switches' it should set or clear.
                   1582:    If VALUE is positive, it is bits to set.
                   1583:    If VALUE is negative, -VALUE is bits to clear.
                   1584:    (The sign bit is not used so there is no confusion.)  */
                   1585: 
                   1586: struct {char *name; int value;} target_switches []
                   1587:   = TARGET_SWITCHES;
                   1588: 
                   1589: /* Decode the switch -mNAME.  */
                   1590: 
1.1.1.2   root     1591: void
1.1       root     1592: set_target_switch (name)
                   1593:      char *name;
                   1594: {
1.1.1.2   root     1595:   register int j;
1.1       root     1596:   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
                   1597:     if (!strcmp (target_switches[j].name, name))
                   1598:       {
                   1599:        if (target_switches[j].value < 0)
                   1600:          target_flags &= ~-target_switches[j].value;
                   1601:        else
                   1602:          target_flags |= target_switches[j].value;
1.1.1.7   root     1603:        return;
1.1       root     1604:       }
1.1.1.7   root     1605:   error ("Invalid option `%s'", name);
1.1       root     1606: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.