Annotation of gcc/toplev.c, revision 1.1.1.11

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

unix.superglobalmegacorp.com

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