]> gcc.gnu.org Git - gcc.git/blame - gcc/toplev.c
(jump_optimize): Don't move initialization if there is a label between it and the...
[gcc.git] / gcc / toplev.c
CommitLineData
4291d9c8 1/* Top level of GNU C compiler
912c4289 2 Copyright (C) 1987, 88, 89, 92-5, 1996 Free Software Foundation, Inc.
4291d9c8
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
4291d9c8 20
4291d9c8
RS
21/* This is the top level of cc1/c++.
22 It parses command args, opens files, invokes the various passes
23 in the proper order, and counts the time used by each.
24 Error messages and low-level interface to malloc also handled here. */
25
26#include "config.h"
e0e2a8da 27#ifdef __STDC__
04fe4385 28#include <stdarg.h>
e0e2a8da 29#else
04fe4385 30#include <varargs.h>
e0e2a8da 31#endif
4291d9c8
RS
32#include <stdio.h>
33#include <signal.h>
34#include <setjmp.h>
eb711c86 35#include <sys/types.h>
ea9182cd 36#include <ctype.h>
4291d9c8
RS
37#include <sys/stat.h>
38
9580b583 39#ifndef _WIN32
4291d9c8
RS
40#ifdef USG
41#undef FLOAT
42#include <sys/param.h>
43/* This is for hpux. It is a real screw. They should change hpux. */
44#undef FLOAT
45#include <sys/times.h>
46#include <time.h> /* Correct for hpux at least. Is it good on other USG? */
47#undef FFS /* Some systems define this in param.h. */
48#else
49#ifndef VMS
50#include <sys/time.h>
51#include <sys/resource.h>
52#endif
53#endif
eb910b5a 54#endif
4291d9c8
RS
55
56#include "input.h"
57#include "tree.h"
4291d9c8
RS
58#include "rtl.h"
59#include "flags.h"
60#include "insn-attr.h"
d0d4af87 61#include "defaults.h"
e14417fa
RK
62#include "output.h"
63#include "bytecode.h"
64#include "bc-emit.h"
3d195391 65#include "except.h"
f246a305
RS
66
67#ifdef XCOFF_DEBUGGING_INFO
68#include "xcoffout.h"
69#endif
4291d9c8
RS
70\f
71#ifdef VMS
72/* The extra parameters substantially improve the I/O performance. */
73static FILE *
37c9f674 74vms_fopen (fname, type)
4291d9c8
RS
75 char * fname;
76 char * type;
77{
37c9f674
RK
78 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
79 fixed arguments, which matches ANSI's specification but not VAXCRTL's
80 pre-ANSI implementation. This hack circumvents the mismatch problem. */
81 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
82
83 if (*type == 'w')
84 return (*vmslib_fopen) (fname, type, "mbc=32",
85 "deq=64", "fop=tef", "shr=nil");
86 else
87 return (*vmslib_fopen) (fname, type, "mbc=32");
4291d9c8 88}
37c9f674
RK
89#define fopen vms_fopen
90#endif /* VMS */
4291d9c8
RS
91
92#ifndef DEFAULT_GDB_EXTENSIONS
93#define DEFAULT_GDB_EXTENSIONS 1
94#endif
95
30657ee3
RK
96/* If more than one debugging type is supported, you must define
97 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
98
99 This is one long line cause VAXC can't handle a \-newline. */
9a666dda 100#if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
30657ee3
RK
101#ifndef PREFERRED_DEBUGGING_TYPE
102You Lose! You must define PREFERRED_DEBUGGING_TYPE!
103#endif /* no PREFERRED_DEBUGGING_TYPE */
104#else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
105 so the following code needn't care. */
106#ifdef DBX_DEBUGGING_INFO
107#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
108#endif
109#ifdef SDB_DEBUGGING_INFO
110#define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
111#endif
112#ifdef DWARF_DEBUGGING_INFO
113#define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
114#endif
9a666dda
JM
115#ifdef DWARF2_DEBUGGING_INFO
116#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
117#endif
30657ee3
RK
118#ifdef XCOFF_DEBUGGING_INFO
119#define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
120#endif
121#endif /* More than one debugger format enabled. */
122
123/* If still not defined, must have been because no debugging formats
124 are supported. */
125#ifndef PREFERRED_DEBUGGING_TYPE
126#define PREFERRED_DEBUGGING_TYPE NO_DEBUG
127#endif
128
4291d9c8
RS
129extern int rtx_equal_function_value_matters;
130
72c8bb7f 131#if ! (defined (VMS) || defined (OS2))
4291d9c8 132extern char **environ;
4d7e336b 133#endif
4291d9c8
RS
134extern char *version_string, *language_string;
135
b0316e35
RS
136/* Carry information from ASM_DECLARE_OBJECT_NAME
137 to ASM_FINISH_DECLARE_OBJECT. */
138
139extern int size_directive_output;
5e10b3cc 140extern tree last_assemble_variable_decl;
b0316e35 141
4291d9c8
RS
142extern void init_lex ();
143extern void init_decl_processing ();
144extern void init_obstacks ();
145extern void init_tree_codes ();
146extern void init_rtl ();
34d0205f 147extern void init_regs ();
4291d9c8
RS
148extern void init_optabs ();
149extern void init_stmt ();
150extern void init_reg_sets ();
151extern void dump_flow_info ();
152extern void dump_sched_info ();
153extern void dump_local_alloc ();
154
155void rest_of_decl_compilation ();
d18225c4
RK
156void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
157void error_with_decl PVPROTO((tree decl, char *s, ...));
158void error_for_asm PVPROTO((rtx insn, char *s, ...));
159void error PVPROTO((char *s, ...));
160void fatal PVPROTO((char *s, ...));
161void warning_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
162void warning_with_decl PVPROTO((tree decl, char *s, ...));
163void warning_for_asm PVPROTO((rtx insn, char *s, ...));
164void warning PVPROTO((char *s, ...));
165void pedwarn PVPROTO((char *s, ...));
166void pedwarn_with_decl PVPROTO((tree decl, char *s, ...));
167void pedwarn_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
168void sorry PVPROTO((char *s, ...));
169void really_sorry PVPROTO((char *s, ...));
4291d9c8
RS
170void fancy_abort ();
171#ifndef abort
172void abort ();
173#endif
174void set_target_switch ();
4291d9c8
RS
175static char *decl_name ();
176
3d5cdd42
DE
177void print_version ();
178int print_single_switch ();
179void print_switch_values ();
180/* Length of line when printing switch values. */
181#define MAX_LINE 75
182
efa00f4e
RK
183#ifdef __alpha
184extern char *sbrk ();
185#endif
186
4291d9c8
RS
187/* Name of program invoked, sans directories. */
188
189char *progname;
190
191/* Copy of arguments to main. */
192int save_argc;
193char **save_argv;
194\f
195/* Name of current original source file (what was input to cpp).
196 This comes from each #-command in the actual input. */
197
198char *input_filename;
199
200/* Name of top-level original source file (what was input to cpp).
201 This comes from the #-command at the beginning of the actual input.
202 If there isn't any there, then this is the cc1 input file name. */
203
204char *main_input_filename;
205
206/* Stream for reading from the input file. */
207
208FILE *finput;
209
210/* Current line number in real source file. */
211
212int lineno;
213
214/* Stack of currently pending input files. */
215
216struct file_stack *input_file_stack;
217
218/* Incremented on each change to input_file_stack. */
219int input_file_stack_tick;
220
221/* FUNCTION_DECL for function now being parsed or compiled. */
222
223extern tree current_function_decl;
224
225/* Name to use as base of names for dump output files. */
226
227char *dump_base_name;
228
229/* Bit flags that specify the machine subtype we are compiling for.
230 Bits are tested using macros TARGET_... defined in the tm.h file
231 and set by `-m...' switches. Must be defined in rtlanal.c. */
232
233extern int target_flags;
234
235/* Flags saying which kinds of debugging dump have been requested. */
236
237int rtl_dump = 0;
238int rtl_dump_and_exit = 0;
239int jump_opt_dump = 0;
240int cse_dump = 0;
241int loop_dump = 0;
242int cse2_dump = 0;
243int flow_dump = 0;
244int combine_dump = 0;
245int sched_dump = 0;
246int local_reg_dump = 0;
247int global_reg_dump = 0;
248int sched2_dump = 0;
249int jump2_opt_dump = 0;
250int dbr_sched_dump = 0;
251int flag_print_asm_name = 0;
252int stack_reg_dump = 0;
253
254/* Name for output file of assembly code, specified with -o. */
255
256char *asm_file_name;
257
258/* Value of the -G xx switch, and whether it was passed or not. */
259int g_switch_value;
260int g_switch_set;
261
262/* Type(s) of debugging information we are producing (if any).
263 See flags.h for the definitions of the different possible
264 types of debugging information. */
265enum debug_info_type write_symbols = NO_DEBUG;
266
267/* Level of debugging information we are producing. See flags.h
268 for the definitions of the different possible levels. */
269enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
270
a53d0bcc
RS
271/* Nonzero means use GNU-only extensions in the generated symbolic
272 debugging information. */
273/* Currently, this only has an effect when write_symbols is set to
274 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
275int use_gnu_debug_info_extensions = 0;
4291d9c8
RS
276
277/* Nonzero means do optimizations. -O.
278 Particular numeric values stand for particular amounts of optimization;
279 thus, -O2 stores 2 here. However, the optimizations beyond the basic
280 ones are not controlled directly by this variable. Instead, they are
281 controlled by individual `flag_...' variables that are defaulted
282 based on this variable. */
283
284int optimize = 0;
285
286/* Number of error messages and warning messages so far. */
287
288int errorcount = 0;
289int warningcount = 0;
290int sorrycount = 0;
291
ca695ac9
JB
292/* Flag to output bytecode instead of native assembler */
293int output_bytecode = 0;
294
4291d9c8
RS
295/* Pointer to function to compute the name to use to print a declaration. */
296
297char *(*decl_printable_name) ();
298
299/* Pointer to function to compute rtl for a language-specific tree code. */
300
301struct rtx_def *(*lang_expand_expr) ();
302
2b599527
RS
303/* Pointer to function to finish handling an incomplete decl at the
304 end of compilation. */
305
306void (*incomplete_decl_finalize_hook) () = 0;
307
bf8b4985
RK
308/* Highest label number used at the end of reload. */
309
310int max_label_num_after_reload;
311
4291d9c8
RS
312/* Nonzero if generating code to do profiling. */
313
314int profile_flag = 0;
315
316/* Nonzero if generating code to do profiling on a line-by-line basis. */
317
318int profile_block_flag;
319
320/* Nonzero for -pedantic switch: warn about anything
321 that standard spec forbids. */
322
323int pedantic = 0;
324
325/* Temporarily suppress certain warnings.
326 This is set while reading code from a system header file. */
327
328int in_system_header = 0;
329
330/* Nonzero means do stupid register allocation.
331 Currently, this is 1 if `optimize' is 0. */
332
333int obey_regdecls = 0;
334
335/* Don't print functions as they are compiled and don't print
336 times taken by the various passes. -quiet. */
337
338int quiet_flag = 0;
339\f
340/* -f flags. */
341
342/* Nonzero means `char' should be signed. */
343
344int flag_signed_char;
345
346/* Nonzero means give an enum type only as many bytes as it needs. */
347
348int flag_short_enums;
349
350/* Nonzero for -fcaller-saves: allocate values in regs that need to
351 be saved across function calls, if that produces overall better code.
352 Optional now, so people can test it. */
353
354#ifdef DEFAULT_CALLER_SAVES
355int flag_caller_saves = 1;
356#else
357int flag_caller_saves = 0;
358#endif
359
958ec8ca
JW
360/* Nonzero if structures and unions should be returned in memory.
361
362 This should only be defined if compatibility with another compiler or
363 with an ABI is needed, because it results in slower code. */
364
365#ifndef DEFAULT_PCC_STRUCT_RETURN
366#define DEFAULT_PCC_STRUCT_RETURN 1
367#endif
368
4291d9c8
RS
369/* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
370
958ec8ca 371int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
4291d9c8
RS
372
373/* Nonzero for -fforce-mem: load memory value into a register
374 before arithmetic on it. This makes better cse but slower compilation. */
375
376int flag_force_mem = 0;
377
378/* Nonzero for -fforce-addr: load memory address into a register before
379 reference to memory. This makes better cse but slower compilation. */
380
381int flag_force_addr = 0;
382
383/* Nonzero for -fdefer-pop: don't pop args after each function call;
384 instead save them up to pop many calls' args with one insns. */
385
6731a3e3 386int flag_defer_pop = 0;
4291d9c8
RS
387
388/* Nonzero for -ffloat-store: don't allocate floats and doubles
389 in extended-precision registers. */
390
391int flag_float_store = 0;
392
393/* Nonzero for -fcse-follow-jumps:
394 have cse follow jumps to do a more extensive job. */
395
396int flag_cse_follow_jumps;
397
8b3686ed
RK
398/* Nonzero for -fcse-skip-blocks:
399 have cse follow a branch around a block. */
400int flag_cse_skip_blocks;
401
4291d9c8
RS
402/* Nonzero for -fexpensive-optimizations:
403 perform miscellaneous relatively-expensive optimizations. */
404int flag_expensive_optimizations;
405
406/* Nonzero for -fthread-jumps:
407 have jump optimize output of loop. */
408
409int flag_thread_jumps;
410
411/* Nonzero enables strength-reduction in loop.c. */
412
413int flag_strength_reduce = 0;
414
415/* Nonzero enables loop unrolling in unroll.c. Only loops for which the
416 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
417 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
418 unrolled. */
419
420int flag_unroll_loops;
421
422/* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
423 This is generally not a win. */
424
425int flag_unroll_all_loops;
426
427/* Nonzero for -fwritable-strings:
428 store string constants in data segment and don't uniquize them. */
429
430int flag_writable_strings = 0;
431
432/* Nonzero means don't put addresses of constant functions in registers.
433 Used for compiling the Unix kernel, where strange substitutions are
434 done on the assembly output. */
435
436int flag_no_function_cse = 0;
437
438/* Nonzero for -fomit-frame-pointer:
439 don't make a frame pointer in simple functions that don't require one. */
440
441int flag_omit_frame_pointer = 0;
442
cf440348
JL
443/* Nonzero means place each function into its own section on those platforms
444 which support arbitrary section names and unlimited numbers of sections. */
445
446int flag_function_sections = 0;
447
4291d9c8
RS
448/* Nonzero to inhibit use of define_optimization peephole opts. */
449
450int flag_no_peephole = 0;
451
43855b28
JL
452/* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
453 operations in the interest of optimization. For example it allows
454 GCC to assume arguments to sqrt are nonnegative numbers, allowing
0f41302f 455 faster code for sqrt to be generated. */
43855b28
JL
456
457int flag_fast_math = 0;
458
4291d9c8
RS
459/* Nonzero means all references through pointers are volatile. */
460
461int flag_volatile;
c6e75897
RS
462
463/* Nonzero means treat all global and extern variables as global. */
464
38d4d0c2 465int flag_volatile_global;
4291d9c8
RS
466
467/* Nonzero means just do syntax checking; don't output anything. */
468
469int flag_syntax_only = 0;
470
471/* Nonzero means to rerun cse after loop optimization. This increases
472 compilation time about 20% and picks up a few more common expressions. */
473
474static int flag_rerun_cse_after_loop;
475
476/* Nonzero for -finline-functions: ok to inline functions that look like
477 good inline candidates. */
478
479int flag_inline_functions;
480
481/* Nonzero for -fkeep-inline-functions: even if we make a function
ac2a9454 482 go inline everywhere, keep its definition around for debugging
4291d9c8
RS
483 purposes. */
484
485int flag_keep_inline_functions;
486
fadb3bc9 487/* Nonzero means that functions will not be inlined. */
4291d9c8
RS
488
489int flag_no_inline;
490
fbe912dd
BK
491/* Nonzero means that we should emit static const variables
492 regardless of whether or not optimization is turned on. */
493
494int flag_keep_static_consts = 1;
495
4291d9c8
RS
496/* Nonzero means we should be saving declaration info into a .X file. */
497
498int flag_gen_aux_info = 0;
499
f246a305
RS
500/* Specified name of aux-info file. */
501
502static char *aux_info_file_name;
503
4291d9c8
RS
504/* Nonzero means make the text shared if supported. */
505
506int flag_shared_data;
507
508/* Nonzero means schedule into delayed branch slots if supported. */
509
510int flag_delayed_branch;
511
5dab5552
MS
512/* Nonzero means to run cleanups after CALL_EXPRs. */
513
514int flag_short_temps;
515
4291d9c8
RS
516/* Nonzero if we are compiling pure (sharable) code.
517 Value is 1 if we are doing reasonable (i.e. simple
518 offset into offset table) pic. Value is 2 if we can
519 only perform register offsets. */
520
521int flag_pic;
522
3d195391
MS
523/* Nonzero means generate extra code for exception handling and enable
524 exception handling. */
525
526int flag_exceptions = 1;
527
2786cbad 528/* Nonzero means don't place uninitialized global data in common storage
3d195391 529 by default. */
4291d9c8
RS
530
531int flag_no_common;
532
533/* Nonzero means pretend it is OK to examine bits of target floats,
534 even if that isn't true. The resulting code will have incorrect constants,
535 but the same series of instructions that the native compiler would make. */
536
537int flag_pretend_float;
538
539/* Nonzero means change certain warnings into errors.
540 Usually these are warnings about failure to conform to some standard. */
541
542int flag_pedantic_errors = 0;
543
544/* flag_schedule_insns means schedule insns within basic blocks (before
545 local_alloc).
546 flag_schedule_insns_after_reload means schedule insns after
547 global_alloc. */
548
549int flag_schedule_insns = 0;
550int flag_schedule_insns_after_reload = 0;
551
552/* -finhibit-size-directive inhibits output of .size for ELF.
553 This is used only for compiling crtstuff.c,
554 and it may be extended to other effects
555 needed for crtstuff.c on other systems. */
556int flag_inhibit_size_directive = 0;
557
9a631e8e
RS
558/* -fverbose-asm causes extra commentary information to be produced in
559 the generated assembly code (to make it more readable). This option
560 is generally only of use to those who actually need to read the
3d5cdd42
DE
561 generated assembly code (perhaps while debugging the compiler itself).
562 -fverbose-asm is the default. -fno-verbose-asm causes the extra information
563 to be omitted and is useful when comparing two assembler files. */
564
565int flag_verbose_asm = 1;
9a631e8e 566
3d5cdd42
DE
567/* -dA causes debug commentary information to be produced in
568 the generated assembly code (to make it more readable). This option
569 is generally only of use to those who actually need to read the
570 generated assembly code (perhaps while debugging the compiler itself).
571 Currently, this switch is only used by dwarfout.c; however, it is intended
572 to be a catchall for printing debug information in the assembler file. */
573
574int flag_debug_asm = 0;
9a631e8e 575
4291d9c8 576/* -fgnu-linker specifies use of the GNU linker for initializations.
d68c507d
RS
577 (Or, more generally, a linker that handles initializations.)
578 -fno-gnu-linker says that collect2 will be used. */
579#ifdef USE_COLLECT2
580int flag_gnu_linker = 0;
581#else
4291d9c8 582int flag_gnu_linker = 1;
d68c507d 583#endif
4291d9c8 584
566cdc73
MM
585/* Tag all structures with __attribute__(packed) */
586int flag_pack_struct = 0;
587
4291d9c8
RS
588/* Table of language-independent -f options.
589 STRING is the option name. VARIABLE is the address of the variable.
590 ON_VALUE is the value to store in VARIABLE
591 if `-fSTRING' is seen as an option.
592 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
593
594struct { char *string; int *variable; int on_value;} f_options[] =
595{
596 {"float-store", &flag_float_store, 1},
597 {"volatile", &flag_volatile, 1},
38d4d0c2 598 {"volatile-global", &flag_volatile_global, 1},
4291d9c8
RS
599 {"defer-pop", &flag_defer_pop, 1},
600 {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
601 {"cse-follow-jumps", &flag_cse_follow_jumps, 1},
8b3686ed 602 {"cse-skip-blocks", &flag_cse_skip_blocks, 1},
4291d9c8
RS
603 {"expensive-optimizations", &flag_expensive_optimizations, 1},
604 {"thread-jumps", &flag_thread_jumps, 1},
605 {"strength-reduce", &flag_strength_reduce, 1},
606 {"unroll-loops", &flag_unroll_loops, 1},
607 {"unroll-all-loops", &flag_unroll_all_loops, 1},
608 {"writable-strings", &flag_writable_strings, 1},
609 {"peephole", &flag_no_peephole, 0},
610 {"force-mem", &flag_force_mem, 1},
611 {"force-addr", &flag_force_addr, 1},
612 {"function-cse", &flag_no_function_cse, 0},
613 {"inline-functions", &flag_inline_functions, 1},
614 {"keep-inline-functions", &flag_keep_inline_functions, 1},
615 {"inline", &flag_no_inline, 0},
fbe912dd 616 {"keep-static-consts", &flag_keep_static_consts, 1},
4291d9c8 617 {"syntax-only", &flag_syntax_only, 1},
4291d9c8
RS
618 {"shared-data", &flag_shared_data, 1},
619 {"caller-saves", &flag_caller_saves, 1},
620 {"pcc-struct-return", &flag_pcc_struct_return, 1},
958ec8ca 621 {"reg-struct-return", &flag_pcc_struct_return, 0},
4291d9c8
RS
622 {"delayed-branch", &flag_delayed_branch, 1},
623 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1},
624 {"pretend-float", &flag_pretend_float, 1},
625 {"schedule-insns", &flag_schedule_insns, 1},
626 {"schedule-insns2", &flag_schedule_insns_after_reload, 1},
627 {"pic", &flag_pic, 1},
628 {"PIC", &flag_pic, 2},
3d195391 629 {"exceptions", &flag_exceptions, 1},
43855b28 630 {"fast-math", &flag_fast_math, 1},
4291d9c8
RS
631 {"common", &flag_no_common, 0},
632 {"inhibit-size-directive", &flag_inhibit_size_directive, 1},
cf440348 633 {"function-sections", &flag_function_sections, 1},
9a631e8e 634 {"verbose-asm", &flag_verbose_asm, 1},
422e2ed3 635 {"gnu-linker", &flag_gnu_linker, 1},
566cdc73 636 {"pack-struct", &flag_pack_struct, 1},
ca695ac9 637 {"bytecode", &output_bytecode, 1}
4291d9c8 638};
b99933c7
RS
639
640/* Table of language-specific options. */
641
642char *lang_options[] =
643{
4200c8de 644 "-ansi",
8305445b 645 "-fallow-single-precision",
4200c8de 646
b99933c7
RS
647 "-fsigned-bitfields",
648 "-funsigned-bitfields",
649 "-fno-signed-bitfields",
650 "-fno-unsigned-bitfields",
4200c8de
RK
651 "-fsigned-char",
652 "-funsigned-char",
653 "-fno-signed-char",
654 "-fno-unsigned-char",
655
656 "-ftraditional",
657 "-traditional",
658 "-fnotraditional",
659 "-fno-traditional",
660
b99933c7
RS
661 "-fasm",
662 "-fno-asm",
663 "-fbuiltin",
664 "-fno-builtin",
4200c8de
RK
665 "-fcond-mismatch",
666 "-fno-cond-mismatch",
c7daad38 667 "-fdollars-in-identifiers",
57f0a224 668 "-fno-dollars-in-identifiers",
4200c8de
RK
669 "-fident",
670 "-fno-ident",
671 "-fshort-double",
672 "-fno-short-double",
673 "-fshort-enums",
674 "-fno-short-enums",
675
676 "-Wall",
289871f0
RK
677 "-Wbad-function-cast",
678 "-Wno-bad-function-cast",
b99933c7
RS
679 "-Wcast-qual",
680 "-Wno-cast-qual",
b99933c7
RS
681 "-Wchar-subscripts",
682 "-Wno-char-subscripts",
b99933c7
RS
683 "-Wcomment",
684 "-Wno-comment",
685 "-Wcomments",
686 "-Wno-comments",
4200c8de
RK
687 "-Wconversion",
688 "-Wno-conversion",
689 "-Wformat",
690 "-Wno-format",
b99933c7
RS
691 "-Wimport",
692 "-Wno-import",
4200c8de
RK
693 "-Wimplicit",
694 "-Wno-implicit",
f41372d4
RS
695 "-Wmissing-braces",
696 "-Wno-missing-braces",
4200c8de
RK
697 "-Wmissing-declarations",
698 "-Wno-missing-declarations",
699 "-Wmissing-prototypes",
700 "-Wno-missing-prototypes",
701 "-Wnested-externs",
702 "-Wno-nested-externs",
703 "-Wparentheses",
704 "-Wno-parentheses",
705 "-Wpointer-arith",
706 "-Wno-pointer-arith",
707 "-Wredundant-decls",
708 "-Wno-redundant-decls",
d51f9363
JM
709 "-Wsign-compare",
710 "-Wno-sign-compare",
4200c8de
RK
711 "-Wstrict-prototypes",
712 "-Wno-strict-prototypes",
713 "-Wtraditional",
714 "-Wno-traditional",
715 "-Wtrigraphs",
716 "-Wno-trigraphs",
717 "-Wwrite-strings",
718 "-Wno-write-strings",
b99933c7 719
65faa6a4
RS
720 /* these are for obj c */
721 "-lang-objc",
722 "-gen-decls",
f5309ddf
TW
723 "-fgnu-runtime",
724 "-fno-gnu-runtime",
725 "-fnext-runtime",
726 "-fno-next-runtime",
65faa6a4
RS
727 "-Wselector",
728 "-Wno-selector",
b800a01b
KKT
729 "-Wprotocol",
730 "-Wno-protocol",
a457294f 731
2a95de17 732#include "options.h"
b99933c7
RS
733 0
734};
4291d9c8
RS
735\f
736/* Options controlling warnings */
737
738/* Don't print warning messages. -w. */
739
740int inhibit_warnings = 0;
741
742/* Print various extra warnings. -W. */
743
744int extra_warnings = 0;
745
746/* Treat warnings as errors. -Werror. */
747
748int warnings_are_errors = 0;
749
750/* Nonzero to warn about unused local variables. */
751
752int warn_unused;
753
754/* Nonzero to warn about variables used before they are initialized. */
755
756int warn_uninitialized;
757
758/* Nonzero means warn about all declarations which shadow others. */
759
760int warn_shadow;
761
762/* Warn if a switch on an enum fails to have a case for every enum value. */
763
764int warn_switch;
765
766/* Nonzero means warn about function definitions that default the return type
767 or that use a null return and have a return-type other than void. */
768
769int warn_return_type;
770
771/* Nonzero means warn about pointer casts that increase the required
772 alignment of the target type (and might therefore lead to a crash
773 due to a misaligned access). */
774
775int warn_cast_align;
776
777/* Nonzero means warn about any identifiers that match in the first N
778 characters. The value N is in `id_clash_len'. */
779
780int warn_id_clash;
b51e9c62
RK
781unsigned id_clash_len;
782
783/* Nonzero means warn about any objects definitions whose size is larger
784 than N bytes. Also want about function definitions whose returned
785 values are larger than N bytes. The value N is in `larger_than_size'. */
786
787int warn_larger_than;
788unsigned larger_than_size;
4291d9c8
RS
789
790/* Nonzero means warn if inline function is too large. */
791
792int warn_inline;
793
794/* Warn if a function returns an aggregate,
795 since there are often incompatible calling conventions for doing this. */
796
797int warn_aggregate_return;
798
799/* Likewise for -W. */
800
801struct { char *string; int *variable; int on_value;} W_options[] =
802{
803 {"unused", &warn_unused, 1},
804 {"error", &warnings_are_errors, 1},
805 {"shadow", &warn_shadow, 1},
806 {"switch", &warn_switch, 1},
4291d9c8
RS
807 {"aggregate-return", &warn_aggregate_return, 1},
808 {"cast-align", &warn_cast_align, 1},
f246a305
RS
809 {"uninitialized", &warn_uninitialized, 1},
810 {"inline", &warn_inline, 1}
4291d9c8
RS
811};
812\f
813/* Output files for assembler code (real compiler output)
814 and debugging dumps. */
815
816FILE *asm_out_file;
817FILE *aux_info_file;
818FILE *rtl_dump_file;
819FILE *jump_opt_dump_file;
820FILE *cse_dump_file;
821FILE *loop_dump_file;
822FILE *cse2_dump_file;
823FILE *flow_dump_file;
824FILE *combine_dump_file;
825FILE *sched_dump_file;
826FILE *local_reg_dump_file;
827FILE *global_reg_dump_file;
828FILE *sched2_dump_file;
829FILE *jump2_opt_dump_file;
830FILE *dbr_sched_dump_file;
831FILE *stack_reg_dump_file;
832
833/* Time accumulators, to count the total time spent in various passes. */
834
835int parse_time;
836int varconst_time;
837int integration_time;
838int jump_time;
839int cse_time;
840int loop_time;
841int cse2_time;
842int flow_time;
843int combine_time;
844int sched_time;
845int local_alloc_time;
846int global_alloc_time;
847int sched2_time;
848int dbr_sched_time;
849int shorten_branch_time;
850int stack_reg_time;
851int final_time;
852int symout_time;
853int dump_time;
854\f
855/* Return time used so far, in microseconds. */
856
857int
858get_run_time ()
859{
9580b583 860#ifndef _WIN32
4291d9c8
RS
861#ifdef USG
862 struct tms tms;
863#else
864#ifndef VMS
865 struct rusage rusage;
15f00097 866#else
4291d9c8
RS
867 struct
868 {
869 int proc_user_time;
870 int proc_system_time;
871 int child_user_time;
872 int child_system_time;
873 } vms_times;
874#endif
15f00097 875#endif
4291d9c8
RS
876#endif
877
878 if (quiet_flag)
879 return 0;
9580b583 880#ifdef _WIN32
15f00097
RK
881 if (clock() < 0)
882 return 0;
883 else
884 return (clock() * 1000);
9580b583 885#else /* not _WIN32 */
4291d9c8
RS
886#ifdef USG
887 times (&tms);
888 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
889#else
890#ifndef VMS
891 getrusage (0, &rusage);
892 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
893 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
894#else /* VMS */
895 times (&vms_times);
896 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
897#endif
898#endif
eb910b5a 899#endif
4291d9c8
RS
900}
901
902#define TIMEVAR(VAR, BODY) \
903do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
904
905void
906print_time (str, total)
907 char *str;
908 int total;
909{
910 fprintf (stderr,
911 "time in %s: %d.%06d\n",
912 str, total / 1000000, total % 1000000);
913}
914
915/* Count an error or warning. Return 1 if the message should be printed. */
916
917int
918count_error (warningp)
919 int warningp;
920{
921 if (warningp && inhibit_warnings)
922 return 0;
923
924 if (warningp && !warnings_are_errors)
925 warningcount++;
926 else
927 {
928 static int warning_message = 0;
929
930 if (warningp && !warning_message)
931 {
932 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
933 warning_message = 1;
934 }
935 errorcount++;
936 }
937
938 return 1;
939}
940
941/* Print a fatal error message. NAME is the text.
942 Also include a system error message based on `errno'. */
943
944void
945pfatal_with_name (name)
946 char *name;
947{
948 fprintf (stderr, "%s: ", progname);
949 perror (name);
299846f2 950 exit (FATAL_EXIT_CODE);
4291d9c8
RS
951}
952
953void
954fatal_io_error (name)
955 char *name;
956{
957 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
299846f2 958 exit (FATAL_EXIT_CODE);
4291d9c8
RS
959}
960
a89b2cc4
MM
961/* Called to give a better error message for a bad insn rather than
962 just calling abort(). */
4291d9c8
RS
963
964void
a89b2cc4
MM
965fatal_insn (message, insn)
966 char *message;
4291d9c8
RS
967 rtx insn;
968{
ca695ac9
JB
969 if (!output_bytecode)
970 {
a89b2cc4 971 error (message);
ca695ac9
JB
972 debug_rtx (insn);
973 }
4291d9c8
RS
974 if (asm_out_file)
975 fflush (asm_out_file);
976 if (aux_info_file)
977 fflush (aux_info_file);
978 if (rtl_dump_file)
979 fflush (rtl_dump_file);
980 if (jump_opt_dump_file)
981 fflush (jump_opt_dump_file);
982 if (cse_dump_file)
983 fflush (cse_dump_file);
984 if (loop_dump_file)
985 fflush (loop_dump_file);
986 if (cse2_dump_file)
987 fflush (cse2_dump_file);
988 if (flow_dump_file)
989 fflush (flow_dump_file);
990 if (combine_dump_file)
991 fflush (combine_dump_file);
992 if (sched_dump_file)
993 fflush (sched_dump_file);
994 if (local_reg_dump_file)
995 fflush (local_reg_dump_file);
996 if (global_reg_dump_file)
997 fflush (global_reg_dump_file);
998 if (sched2_dump_file)
999 fflush (sched2_dump_file);
1000 if (jump2_opt_dump_file)
1001 fflush (jump2_opt_dump_file);
1002 if (dbr_sched_dump_file)
1003 fflush (dbr_sched_dump_file);
1004 if (stack_reg_dump_file)
1005 fflush (stack_reg_dump_file);
1902f7fd
MM
1006 fflush (stdout);
1007 fflush (stderr);
4291d9c8
RS
1008 abort ();
1009}
1010
a89b2cc4
MM
1011/* Called to give a better error message when we don't have an insn to match
1012 what we are looking for or if the insn's constraints aren't satisfied,
1013 rather than just calling abort(). */
1014
1015void
1016fatal_insn_not_found (insn)
1017 rtx insn;
1018{
1019 if (INSN_CODE (insn) < 0)
1020 fatal_insn ("internal error--unrecognizable insn:", insn);
1021 else
1022 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1023}
1024
4291d9c8
RS
1025/* This is the default decl_printable_name function. */
1026
1027static char *
1028decl_name (decl, kind)
1029 tree decl;
1030 char **kind;
1031{
1032 return IDENTIFIER_POINTER (DECL_NAME (decl));
1033}
1034\f
1035static int need_error_newline;
1036
1037/* Function of last error message;
1038 more generally, function such that if next error message is in it
1039 then we don't have to mention the function name. */
1040static tree last_error_function = NULL;
1041
1042/* Used to detect when input_file_stack has changed since last described. */
1043static int last_error_tick;
1044
1045/* Called when the start of a function definition is parsed,
1046 this function prints on stderr the name of the function. */
1047
1048void
1049announce_function (decl)
1050 tree decl;
1051{
1052 if (! quiet_flag)
1053 {
1054 char *junk;
1055 if (rtl_dump_and_exit)
1056 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1057 else
1058 fprintf (stderr, " %s", (*decl_printable_name) (decl, &junk));
1059 fflush (stderr);
1060 need_error_newline = 1;
1061 last_error_function = current_function_decl;
1062 }
1063}
1064
b64e9948
PB
1065/* The default function to print out name of current function that caused
1066 an error. */
4291d9c8
RS
1067
1068void
b64e9948 1069default_print_error_function (file)
4291d9c8
RS
1070 char *file;
1071{
4291d9c8
RS
1072 if (last_error_function != current_function_decl)
1073 {
1074 char *kind = "function";
1075 if (current_function_decl != 0
1076 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1077 kind = "method";
1078
1079 if (file)
1080 fprintf (stderr, "%s: ", file);
1081
1082 if (current_function_decl == NULL)
1083 fprintf (stderr, "At top level:\n");
1084 else
1085 {
1086 char *name = (*decl_printable_name) (current_function_decl, &kind);
1087 fprintf (stderr, "In %s `%s':\n", kind, name);
1088 }
1089
1090 last_error_function = current_function_decl;
1091 }
b64e9948
PB
1092}
1093
1094/* Called by report_error_function to print out function name.
0f41302f 1095 * Default may be overridden by language front-ends. */
b64e9948 1096
0f41302f 1097void (*print_error_function) PROTO((char *)) = default_print_error_function;
b64e9948
PB
1098
1099/* Prints out, if necessary, the name of the current function
1100 that caused an error. Called from all error and warning functions. */
1101
1102void
1103report_error_function (file)
1104 char *file;
1105{
1106 struct file_stack *p;
1107
1108 if (need_error_newline)
1109 {
1110 fprintf (stderr, "\n");
1111 need_error_newline = 0;
1112 }
1113
1114 (*print_error_function) (file);
1115
4291d9c8 1116 if (input_file_stack && input_file_stack->next != 0
2efc92ed
RK
1117 && input_file_stack_tick != last_error_tick
1118 && file == input_filename)
4291d9c8
RS
1119 {
1120 fprintf (stderr, "In file included");
1121 for (p = input_file_stack->next; p; p = p->next)
1122 {
1123 fprintf (stderr, " from %s:%d", p->name, p->line);
1124 if (p->next)
e5301904 1125 fprintf (stderr, ",\n ");
4291d9c8
RS
1126 }
1127 fprintf (stderr, ":\n");
1128 last_error_tick = input_file_stack_tick;
1129 }
1130}
eb711c86
RK
1131\f
1132/* Print a message. */
4291d9c8 1133
eb711c86
RK
1134static void
1135vmessage (prefix, s, ap)
1136 char *prefix;
4291d9c8 1137 char *s;
eb711c86 1138 va_list ap;
4291d9c8 1139{
eb711c86
RK
1140 if (prefix)
1141 fprintf (stderr, "%s: ", prefix);
1142
1143#ifdef HAVE_VPRINTF
1144 vfprintf (stderr, s, ap);
1145#else
1146 {
1147 HOST_WIDE_INT v1 = va_arg(ap, HOST_WIDE_INT);
1148 HOST_WIDE_INT v2 = va_arg(ap, HOST_WIDE_INT);
1149 HOST_WIDE_INT v3 = va_arg(ap, HOST_WIDE_INT);
a4326b4d
RK
1150 HOST_WIDE_INT v4 = va_arg(ap, HOST_WIDE_INT);
1151 fprintf (stderr, s, v1, v2, v3, v4);
eb711c86
RK
1152 }
1153#endif
4291d9c8
RS
1154}
1155
eb711c86 1156/* Print a message relevant to line LINE of file FILE. */
4291d9c8 1157
eb711c86
RK
1158static void
1159v_message_with_file_and_line (file, line, prefix, s, ap)
4291d9c8
RS
1160 char *file;
1161 int line;
eb711c86 1162 char *prefix;
4291d9c8 1163 char *s;
eb711c86 1164 va_list ap;
4291d9c8 1165{
4291d9c8
RS
1166 if (file)
1167 fprintf (stderr, "%s:%d: ", file, line);
1168 else
1169 fprintf (stderr, "%s: ", progname);
d78c6ad5 1170
eb711c86
RK
1171 vmessage (prefix, s, ap);
1172 fputc ('\n', stderr);
4291d9c8
RS
1173}
1174
eb711c86 1175/* Print a message relevant to the given DECL. */
4291d9c8 1176
eb711c86
RK
1177static void
1178v_message_with_decl (decl, prefix, s, ap)
4291d9c8 1179 tree decl;
eb711c86 1180 char *prefix;
4291d9c8 1181 char *s;
eb711c86 1182 va_list ap;
4291d9c8 1183{
eb711c86 1184 char *n, *p, *junk;
4291d9c8
RS
1185
1186 fprintf (stderr, "%s:%d: ",
1187 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1188
eb711c86
RK
1189 if (prefix)
1190 fprintf (stderr, "%s: ", prefix);
1191
1192 /* Do magic to get around lack of varargs support for insertion
1193 of arguments into existing list. We know that the decl is first;
1194 we ass_u_me that it will be printed with "%s". */
1195
1196 for (p = s; *p; ++p)
1197 {
1198 if (*p == '%')
1199 {
1200 if (*(p + 1) == '%')
1201 ++p;
1202 else
1203 break;
1204 }
1205 }
1206
cb039f8a
RK
1207 if (p > s) /* Print the left-hand substring. */
1208 {
1209 char fmt[sizeof "%.255s"];
1210 long width = p - s;
1211
1212 if (width > 255L) width = 255L; /* arbitrary */
1213 sprintf (fmt, "%%.%lds", width);
1214 fprintf (stderr, fmt, s);
1215 }
eb711c86 1216
cb039f8a 1217 if (*p == '%') /* Print the name. */
eb711c86
RK
1218 {
1219 char *n = (DECL_NAME (decl)
1220 ? (*decl_printable_name) (decl, &junk)
1221 : "((anonymous))");
1222 fputs (n, stderr);
1223 while (*p)
1224 {
1225 ++p;
1226 if (isalpha (*(p - 1) & 0xFF))
1227 break;
1228 }
1229 }
1230
cb039f8a 1231 if (*p) /* Print the rest of the message. */
eb711c86
RK
1232 vmessage ((char *)NULL, p, ap);
1233
1234 fputc ('\n', stderr);
4291d9c8
RS
1235}
1236
eb711c86 1237/* Figure file and line of the given INSN. */
4291d9c8 1238
eb711c86
RK
1239static void
1240file_and_line_for_asm (insn, pfile, pline)
4291d9c8 1241 rtx insn;
eb711c86
RK
1242 char **pfile;
1243 int *pline;
4291d9c8 1244{
4291d9c8
RS
1245 rtx body = PATTERN (insn);
1246 rtx asmop;
1247
1248 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1249 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1250 asmop = SET_SRC (body);
1251 else if (GET_CODE (body) == ASM_OPERANDS)
1252 asmop = body;
1253 else if (GET_CODE (body) == PARALLEL
1254 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1255 asmop = SET_SRC (XVECEXP (body, 0, 0));
1256 else if (GET_CODE (body) == PARALLEL
1257 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1258 asmop = XVECEXP (body, 0, 0);
eb711c86
RK
1259 else
1260 asmop = NULL;
1261
1262 if (asmop)
1263 {
1264 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1265 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1266 }
1267 else
1268 {
1269 *pfile = input_filename;
1270 *pline = lineno;
1271 }
1272}
4291d9c8 1273
eb711c86 1274/* Report an error at line LINE of file FILE. */
4291d9c8 1275
eb711c86
RK
1276static void
1277v_error_with_file_and_line (file, line, s, ap)
1278 char *file;
1279 int line;
1280 char *s;
1281 va_list ap;
1282{
1283 count_error (0);
1284 report_error_function (file);
1285 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
d78c6ad5
RK
1286}
1287
1288void
e0e2a8da 1289error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
d78c6ad5 1290{
e0e2a8da 1291#ifndef __STDC__
eb711c86
RK
1292 char *file;
1293 int line;
1294 char *s;
e0e2a8da
RK
1295#endif
1296 va_list ap;
1297
1298 VA_START (ap, s);
eb711c86 1299
e0e2a8da 1300#ifndef __STDC__
eb711c86
RK
1301 file = va_arg (ap, char *);
1302 line = va_arg (ap, int);
1303 s = va_arg (ap, char *);
e0e2a8da
RK
1304#endif
1305
eb711c86
RK
1306 v_error_with_file_and_line (file, line, s, ap);
1307 va_end (ap);
4291d9c8
RS
1308}
1309
eb711c86
RK
1310/* Report an error at the declaration DECL.
1311 S is a format string which uses %s to substitute the declaration
1312 name; subsequent substitutions are a la printf. */
1313
1314static void
1315v_error_with_decl (decl, s, ap)
1316 tree decl;
1317 char *s;
1318 va_list ap;
1319{
1320 count_error (0);
1321 report_error_function (DECL_SOURCE_FILE (decl));
1322 v_message_with_decl (decl, (char *)NULL, s, ap);
1323}
4291d9c8
RS
1324
1325void
e0e2a8da 1326error_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1327{
e0e2a8da 1328#ifndef __STDC__
eb711c86
RK
1329 tree decl;
1330 char *s;
e0e2a8da
RK
1331#endif
1332 va_list ap;
eb711c86 1333
e0e2a8da
RK
1334 VA_START (ap, s);
1335
1336#ifndef __STDC__
eb711c86
RK
1337 decl = va_arg (ap, tree);
1338 s = va_arg (ap, char *);
e0e2a8da
RK
1339#endif
1340
eb711c86
RK
1341 v_error_with_decl (decl, s, ap);
1342 va_end (ap);
1343}
1344
1345/* Report an error at the line number of the insn INSN.
1346 This is used only when INSN is an `asm' with operands,
1347 and each ASM_OPERANDS records its own source file and line. */
1348
1349static void
1350v_error_for_asm (insn, s, ap)
1351 rtx insn;
4291d9c8 1352 char *s;
eb711c86 1353 va_list ap;
4291d9c8 1354{
eb711c86
RK
1355 char *file;
1356 int line;
4291d9c8 1357
eb711c86
RK
1358 count_error (0);
1359 file_and_line_for_asm (insn, &file, &line);
4291d9c8 1360 report_error_function (file);
eb711c86
RK
1361 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1362}
4291d9c8 1363
eb711c86 1364void
e0e2a8da 1365error_for_asm VPROTO((rtx insn, char *s, ...))
eb711c86 1366{
e0e2a8da 1367#ifndef __STDC__
eb711c86
RK
1368 rtx insn;
1369 char *s;
e0e2a8da
RK
1370#endif
1371 va_list ap;
eb711c86 1372
e0e2a8da
RK
1373 VA_START (ap, s);
1374
1375#ifndef __STDC__
eb711c86
RK
1376 insn = va_arg (ap, rtx);
1377 s = va_arg (ap, char *);
e0e2a8da
RK
1378#endif
1379
eb711c86
RK
1380 v_error_for_asm (insn, s, ap);
1381 va_end (ap);
4291d9c8
RS
1382}
1383
eb711c86 1384/* Report an error at the current line number. */
4291d9c8 1385
eb711c86
RK
1386static void
1387verror (s, ap)
4291d9c8 1388 char *s;
eb711c86 1389 va_list ap;
4291d9c8 1390{
eb711c86 1391 v_error_with_file_and_line (input_filename, lineno, s, ap);
4291d9c8
RS
1392}
1393
eb711c86 1394void
e0e2a8da 1395error VPROTO((char *s, ...))
eb711c86 1396{
e0e2a8da 1397#ifndef __STDC__
eb711c86 1398 char *s;
e0e2a8da
RK
1399#endif
1400 va_list ap;
1401
1402 VA_START (ap, s);
eb711c86 1403
e0e2a8da 1404#ifndef __STDC__
eb711c86 1405 s = va_arg (ap, char *);
e0e2a8da
RK
1406#endif
1407
eb711c86
RK
1408 verror (s, ap);
1409 va_end (ap);
1410}
1411
1412/* Report a fatal error at the current line number. */
1413
1414static void
1415vfatal (s, ap)
1416 char *s;
1417 va_list ap;
1418{
1419 verror (s, ap);
299846f2 1420 exit (FATAL_EXIT_CODE);
eb711c86 1421}
4291d9c8
RS
1422
1423void
e0e2a8da 1424fatal VPROTO((char *s, ...))
eb711c86 1425{
e0e2a8da 1426#ifndef __STDC__
eb711c86 1427 char *s;
e0e2a8da
RK
1428#endif
1429 va_list ap;
1430
1431 VA_START (ap, s);
eb711c86 1432
e0e2a8da 1433#ifndef __STDC__
eb711c86 1434 s = va_arg (ap, char *);
e0e2a8da
RK
1435#endif
1436
eb711c86
RK
1437 vfatal (s, ap);
1438 va_end (ap);
1439}
1440
1441/* Report a warning at line LINE of file FILE. */
1442
1443static void
1444v_warning_with_file_and_line (file, line, s, ap)
1445 char *file;
1446 int line;
4291d9c8 1447 char *s;
eb711c86 1448 va_list ap;
4291d9c8 1449{
eb711c86
RK
1450 if (count_error (1))
1451 {
1452 report_error_function (file);
1453 v_message_with_file_and_line (file, line, "warning", s, ap);
1454 }
1455}
4291d9c8 1456
eb711c86 1457void
e0e2a8da 1458warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
eb711c86 1459{
e0e2a8da 1460#ifndef __STDC__
eb711c86
RK
1461 char *file;
1462 int line;
1463 char *s;
e0e2a8da
RK
1464#endif
1465 va_list ap;
1466
1467 VA_START (ap, s);
eb711c86 1468
e0e2a8da 1469#ifndef __STDC__
eb711c86
RK
1470 file = va_arg (ap, char *);
1471 line = va_arg (ap, int);
1472 s = va_arg (ap, char *);
e0e2a8da
RK
1473#endif
1474
eb711c86
RK
1475 v_warning_with_file_and_line (file, line, s, ap);
1476 va_end (ap);
1477}
4291d9c8 1478
eb711c86
RK
1479/* Report a warning at the declaration DECL.
1480 S is a format string which uses %s to substitute the declaration
1481 name; subsequent substitutions are a la printf. */
4291d9c8 1482
eb711c86
RK
1483static void
1484v_warning_with_decl (decl, s, ap)
1485 tree decl;
1486 char *s;
1487 va_list ap;
1488{
1489 if (count_error (1))
1490 {
1491 report_error_function (DECL_SOURCE_FILE (decl));
1492 v_message_with_decl (decl, "warning", s, ap);
1493 }
1494}
4291d9c8 1495
eb711c86 1496void
e0e2a8da 1497warning_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1498{
e0e2a8da 1499#ifndef __STDC__
eb711c86
RK
1500 tree decl;
1501 char *s;
e0e2a8da
RK
1502#endif
1503 va_list ap;
eb711c86 1504
e0e2a8da
RK
1505 VA_START (ap, s);
1506
1507#ifndef __STDC__
eb711c86
RK
1508 decl = va_arg (ap, tree);
1509 s = va_arg (ap, char *);
e0e2a8da
RK
1510#endif
1511
eb711c86
RK
1512 v_warning_with_decl (decl, s, ap);
1513 va_end (ap);
4291d9c8
RS
1514}
1515
1516/* Report a warning at the line number of the insn INSN.
4291d9c8
RS
1517 This is used only when INSN is an `asm' with operands,
1518 and each ASM_OPERANDS records its own source file and line. */
1519
eb711c86
RK
1520static void
1521v_warning_for_asm (insn, s, ap)
4291d9c8
RS
1522 rtx insn;
1523 char *s;
eb711c86 1524 va_list ap;
4291d9c8 1525{
eb711c86
RK
1526 if (count_error (1))
1527 {
1528 char *file;
1529 int line;
4291d9c8 1530
eb711c86
RK
1531 file_and_line_for_asm (insn, &file, &line);
1532 report_error_function (file);
1533 v_message_with_file_and_line (file, line, "warning", s, ap);
1534 }
1535}
4291d9c8 1536
eb711c86 1537void
e0e2a8da 1538warning_for_asm VPROTO((rtx insn, char *s, ...))
eb711c86 1539{
e0e2a8da 1540#ifndef __STDC__
eb711c86
RK
1541 rtx insn;
1542 char *s;
e0e2a8da
RK
1543#endif
1544 va_list ap;
1545
1546 VA_START (ap, s);
eb711c86 1547
e0e2a8da 1548#ifndef __STDC__
eb711c86
RK
1549 insn = va_arg (ap, rtx);
1550 s = va_arg (ap, char *);
e0e2a8da
RK
1551#endif
1552
eb711c86
RK
1553 v_warning_for_asm (insn, s, ap);
1554 va_end (ap);
1555}
4291d9c8 1556
eb711c86
RK
1557/* Report a warning at the current line number. */
1558
1559static void
1560vwarning (s, ap)
1561 char *s;
1562 va_list ap;
1563{
1564 v_warning_with_file_and_line (input_filename, lineno, s, ap);
4291d9c8 1565}
eb711c86
RK
1566
1567void
e0e2a8da 1568warning VPROTO((char *s, ...))
eb711c86 1569{
e0e2a8da 1570#ifndef __STDC__
eb711c86 1571 char *s;
e0e2a8da
RK
1572#endif
1573 va_list ap;
1574
1575 VA_START (ap, s);
eb711c86 1576
e0e2a8da 1577#ifndef __STDC__
eb711c86 1578 s = va_arg (ap, char *);
e0e2a8da
RK
1579#endif
1580
eb711c86
RK
1581 vwarning (s, ap);
1582 va_end (ap);
1583}
1584
4291d9c8
RS
1585/* These functions issue either warnings or errors depending on
1586 -pedantic-errors. */
1587
eb711c86
RK
1588static void
1589vpedwarn (s, ap)
4291d9c8 1590 char *s;
eb711c86 1591 va_list ap;
4291d9c8
RS
1592{
1593 if (flag_pedantic_errors)
eb711c86 1594 verror (s, ap);
4291d9c8 1595 else
eb711c86 1596 vwarning (s, ap);
4291d9c8
RS
1597}
1598
1599void
e0e2a8da 1600pedwarn VPROTO((char *s, ...))
eb711c86 1601{
e0e2a8da 1602#ifndef __STDC__
eb711c86 1603 char *s;
e0e2a8da
RK
1604#endif
1605 va_list ap;
1606
1607 VA_START (ap, s);
eb711c86 1608
e0e2a8da 1609#ifndef __STDC__
eb711c86 1610 s = va_arg (ap, char *);
e0e2a8da
RK
1611#endif
1612
eb711c86
RK
1613 vpedwarn (s, ap);
1614 va_end (ap);
1615}
1616
1617static void
1618v_pedwarn_with_decl (decl, s, ap)
4291d9c8
RS
1619 tree decl;
1620 char *s;
eb711c86 1621 va_list ap;
4291d9c8 1622{
1554cdf5
DE
1623 /* We don't want -pedantic-errors to cause the compilation to fail from
1624 "errors" in system header files. Sometimes fixincludes can't fix what's
1625 broken (eg: unsigned char bitfields - fixing it may change the alignment
1626 which will cause programs to mysteriously fail because the C library
22d74562
DE
1627 or kernel uses the original layout). There's no point in issuing a
1628 warning either, it's just unnecessary noise. */
1554cdf5 1629
22d74562
DE
1630 if (! DECL_IN_SYSTEM_HEADER (decl))
1631 {
1632 if (flag_pedantic_errors)
1633 v_error_with_decl (decl, s, ap);
1634 else
1635 v_warning_with_decl (decl, s, ap);
1636 }
4291d9c8
RS
1637}
1638
1639void
e0e2a8da 1640pedwarn_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1641{
e0e2a8da 1642#ifndef __STDC__
eb711c86
RK
1643 tree decl;
1644 char *s;
e0e2a8da
RK
1645#endif
1646 va_list ap;
eb711c86 1647
e0e2a8da
RK
1648 VA_START (ap, s);
1649
1650#ifndef __STDC__
eb711c86
RK
1651 decl = va_arg (ap, tree);
1652 s = va_arg (ap, char *);
e0e2a8da
RK
1653#endif
1654
eb711c86
RK
1655 v_pedwarn_with_decl (decl, s, ap);
1656 va_end (ap);
1657}
1658
1659static void
1660v_pedwarn_with_file_and_line (file, line, s, ap)
4291d9c8
RS
1661 char *file;
1662 int line;
1663 char *s;
eb711c86 1664 va_list ap;
4291d9c8
RS
1665{
1666 if (flag_pedantic_errors)
eb711c86 1667 v_error_with_file_and_line (file, line, s, ap);
4291d9c8 1668 else
eb711c86 1669 v_warning_with_file_and_line (file, line, s, ap);
4291d9c8
RS
1670}
1671
4291d9c8 1672void
e0e2a8da 1673pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
eb711c86 1674{
e0e2a8da 1675#ifndef __STDC__
eb711c86
RK
1676 char *file;
1677 int line;
1678 char *s;
e0e2a8da
RK
1679#endif
1680 va_list ap;
eb711c86 1681
e0e2a8da
RK
1682 VA_START (ap, s);
1683
1684#ifndef __STDC__
eb711c86
RK
1685 file = va_arg (ap, char *);
1686 line = va_arg (ap, int);
1687 s = va_arg (ap, char *);
e0e2a8da
RK
1688#endif
1689
eb711c86
RK
1690 v_pedwarn_with_file_and_line (file, line, s, ap);
1691 va_end (ap);
1692}
1693
1694/* Apologize for not implementing some feature. */
1695
1696static void
1697vsorry (s, ap)
4291d9c8 1698 char *s;
eb711c86 1699 va_list ap;
4291d9c8
RS
1700{
1701 sorrycount++;
1702 if (input_filename)
1703 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1704 else
1705 fprintf (stderr, "%s: ", progname);
eb711c86
RK
1706 vmessage ("sorry, not implemented", s, ap);
1707 fputc ('\n', stderr);
1708}
4291d9c8 1709
eb711c86 1710void
e0e2a8da 1711sorry VPROTO((char *s, ...))
eb711c86 1712{
e0e2a8da 1713#ifndef __STDC__
eb711c86 1714 char *s;
e0e2a8da
RK
1715#endif
1716 va_list ap;
1717
1718 VA_START (ap, s);
eb711c86 1719
e0e2a8da 1720#ifndef __STDC__
eb711c86 1721 s = va_arg (ap, char *);
e0e2a8da
RK
1722#endif
1723
eb711c86
RK
1724 vsorry (s, ap);
1725 va_end (ap);
4291d9c8
RS
1726}
1727
eb711c86 1728/* Apologize for not implementing some feature, then quit. */
4291d9c8 1729
eb711c86
RK
1730static void
1731v_really_sorry (s, ap)
4291d9c8 1732 char *s;
eb711c86 1733 va_list ap;
4291d9c8 1734{
eb711c86 1735 sorrycount++;
4291d9c8
RS
1736 if (input_filename)
1737 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1738 else
c10afc44 1739 fprintf (stderr, "%s: ", progname);
eb711c86 1740 vmessage ("sorry, not implemented", s, ap);
4291d9c8
RS
1741 fatal (" (fatal)\n");
1742}
eb711c86
RK
1743
1744void
e0e2a8da 1745really_sorry VPROTO((char *s, ...))
eb711c86 1746{
e0e2a8da 1747#ifndef __STDC__
eb711c86 1748 char *s;
e0e2a8da
RK
1749#endif
1750 va_list ap;
1751
1752 VA_START (ap, s);
eb711c86 1753
e0e2a8da 1754#ifndef __STDC__
eb711c86 1755 s = va_arg (ap, char *);
e0e2a8da
RK
1756#endif
1757
eb711c86
RK
1758 v_really_sorry (s, ap);
1759 va_end (ap);
1760}
4291d9c8
RS
1761\f
1762/* More 'friendly' abort that prints the line and file.
1763 config.h can #define abort fancy_abort if you like that sort of thing.
1764
1765 I don't think this is actually a good idea.
1766 Other sorts of crashes will look a certain way.
1767 It is a good thing if crashes from calling abort look the same way.
1768 -- RMS */
1769
1770void
1771fancy_abort ()
1772{
1773 fatal ("internal gcc abort");
1774}
1775
1776/* This calls abort and is used to avoid problems when abort if a macro.
1777 It is used when we need to pass the address of abort. */
1778
1779void
1780do_abort ()
1781{
1782 abort ();
1783}
1784
1785/* When `malloc.c' is compiled with `rcheck' defined,
1786 it calls this function to report clobberage. */
1787
1788void
1789botch (s)
1790{
1791 abort ();
1792}
1793
1794/* Same as `malloc' but report error if no memory available. */
1795
4b980e20 1796char *
4291d9c8
RS
1797xmalloc (size)
1798 unsigned size;
1799{
4b980e20 1800 register char *value = (char *) malloc (size);
4291d9c8
RS
1801 if (value == 0)
1802 fatal ("virtual memory exhausted");
1803 return value;
1804}
1805
1806/* Same as `realloc' but report error if no memory available. */
1807
4b980e20 1808char *
4291d9c8
RS
1809xrealloc (ptr, size)
1810 char *ptr;
1811 int size;
1812{
4b980e20 1813 char *result = (char *) realloc (ptr, size);
4291d9c8
RS
1814 if (!result)
1815 fatal ("virtual memory exhausted");
1816 return result;
1817}
3e386b9e
RK
1818
1819/* Same as `strdup' but report error if no memory available. */
1820
1821char *
1822xstrdup (s)
1823 register char *s;
1824{
1825 register char *result = (char *) malloc (strlen (s) + 1);
1826
1827 if (! result)
1828 fatal ("virtual memory exhausted");
1829 strcpy (result, s);
1830 return result;
1831}
4291d9c8
RS
1832\f
1833/* Return the logarithm of X, base 2, considering X unsigned,
37366632
RK
1834 if X is a power of 2. Otherwise, returns -1.
1835
1836 This should be used via the `exact_log2' macro. */
4291d9c8
RS
1837
1838int
37366632
RK
1839exact_log2_wide (x)
1840 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1841{
1842 register int log = 0;
1843 /* Test for 0 or a power of 2. */
1844 if (x == 0 || x != (x & -x))
1845 return -1;
1846 while ((x >>= 1) != 0)
1847 log++;
1848 return log;
1849}
1850
1851/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
37366632
RK
1852 If X is 0, return -1.
1853
1854 This should be used via the floor_log2 macro. */
4291d9c8
RS
1855
1856int
37366632
RK
1857floor_log2_wide (x)
1858 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1859{
1860 register int log = -1;
1861 while (x != 0)
1862 log++,
1863 x >>= 1;
1864 return log;
1865}
1866
1867int float_handled;
1868jmp_buf float_handler;
1869
1870/* Specify where to longjmp to when a floating arithmetic error happens.
1871 If HANDLER is 0, it means don't handle the errors any more. */
1872
1873void
1874set_float_handler (handler)
1875 jmp_buf handler;
1876{
1877 float_handled = (handler != 0);
1878 if (handler)
4c9a05bc 1879 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
4291d9c8
RS
1880}
1881
bff4b641
RS
1882/* Specify, in HANDLER, where to longjmp to when a floating arithmetic
1883 error happens, pushing the previous specification into OLD_HANDLER.
1884 Return an indication of whether there was a previous handler in effect. */
1885
1886int
1887push_float_handler (handler, old_handler)
dc2b15dc 1888 jmp_buf handler, old_handler;
bff4b641
RS
1889{
1890 int was_handled = float_handled;
1891
1892 float_handled = 1;
1893 if (was_handled)
4c9a05bc
RK
1894 bcopy ((char *) float_handler, (char *) old_handler,
1895 sizeof (float_handler));
1896
1897 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
bff4b641
RS
1898 return was_handled;
1899}
1900
1901/* Restore the previous specification of whether and where to longjmp to
1902 when a floating arithmetic error happens. */
1903
1904void
1905pop_float_handler (handled, handler)
1906 int handled;
1907 jmp_buf handler;
1908{
1909 float_handled = handled;
1910 if (handled)
4c9a05bc 1911 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
bff4b641
RS
1912}
1913
4291d9c8
RS
1914/* Signals actually come here. */
1915
1916static void
1917float_signal (signo)
1918 /* If this is missing, some compilers complain. */
1919 int signo;
1920{
1921 if (float_handled == 0)
1922 abort ();
1923#if defined (USG) || defined (hpux)
1924 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
1925#endif
1926 float_handled = 0;
1927 signal (SIGFPE, float_signal);
1928 longjmp (float_handler, 1);
1929}
1930
1931/* Handler for SIGPIPE. */
1932
1933static void
1934pipe_closed (signo)
1935 /* If this is missing, some compilers complain. */
1936 int signo;
1937{
1938 fatal ("output pipe has been closed");
1939}
1940
1941/* Strip off a legitimate source ending from the input string NAME of
c62bdc79
RK
1942 length LEN. Rather than having to know the names used by all of
1943 our front ends, we strip off an ending of a period followed by one,
1944 two, or three characters. */
4291d9c8
RS
1945
1946void
1947strip_off_ending (name, len)
1948 char *name;
1949 int len;
1950{
c62bdc79
RK
1951 if (len > 2 && name[len - 2] == '.')
1952 name[len - 2] = '\0';
1953 else if (len > 3 && name[len - 3] == '.')
1954 name[len - 3] = '\0';
1955 else if (len > 4 && name[len - 4] == '.')
1956 name[len - 4] = '\0';
4291d9c8
RS
1957}
1958
7dce5088 1959/* Output a quoted string. */
0f41302f 1960
7dce5088
PE
1961void
1962output_quoted_string (asm_file, string)
1963 FILE *asm_file;
1964 char *string;
1965{
1966 char c;
1967
1968 putc ('\"', asm_file);
1969 while ((c = *string++) != 0)
1970 {
1971 if (c == '\"' || c == '\\')
1972 putc ('\\', asm_file);
1973 putc (c, asm_file);
1974 }
1975 putc ('\"', asm_file);
1976}
1977
4291d9c8
RS
1978/* Output a file name in the form wanted by System V. */
1979
1980void
1981output_file_directive (asm_file, input_name)
1982 FILE *asm_file;
1983 char *input_name;
1984{
1985 int len = strlen (input_name);
1986 char *na = input_name + len;
1987
1988 /* NA gets INPUT_NAME sans directory names. */
1989 while (na > input_name)
1990 {
1991 if (na[-1] == '/')
1992 break;
1993 na--;
1994 }
1995
1996#ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1997 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1998#else
1999#ifdef ASM_OUTPUT_SOURCE_FILENAME
2000 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2001#else
7dce5088
PE
2002 fprintf (asm_file, "\t.file\t");
2003 output_quoted_string (asm_file, na);
2004 fputc ('\n', asm_file);
4291d9c8
RS
2005#endif
2006#endif
2007}
2008\f
0f41302f
MS
2009/* Routine to build language identifier for object file. */
2010
d0d4af87
MS
2011static void
2012output_lang_identify (asm_out_file)
2013 FILE *asm_out_file;
2014{
2015 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2016 char *s = (char *) alloca (len);
2017 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2018 ASM_OUTPUT_LABEL (asm_out_file, s);
2019}
2020
dfe1a916 2021/* Routine to open a dump file. */
0f41302f 2022
dfe1a916
DE
2023static FILE *
2024open_dump_file (base_name, suffix)
2025 char *base_name;
2026 char *suffix;
2027{
2028 FILE *f;
2029 char *dumpname = (char *) alloca (strlen (base_name) + strlen (suffix) + 1);
2030
2031 strcpy (dumpname, base_name);
2032 strcat (dumpname, suffix);
2033 f = fopen (dumpname, "w");
2034 if (f == 0)
2035 pfatal_with_name (dumpname);
2036 return f;
2037}
2038
4291d9c8
RS
2039/* Compile an entire file of output from cpp, named NAME.
2040 Write a file of assembly output and various debugging dumps. */
2041
2042static void
2043compile_file (name)
2044 char *name;
2045{
2046 tree globals;
2047 int start_time;
4291d9c8
RS
2048
2049 int name_specified = name != 0;
2050
2051 if (dump_base_name == 0)
2052 dump_base_name = name ? name : "gccdump";
4291d9c8
RS
2053
2054 parse_time = 0;
2055 varconst_time = 0;
2056 integration_time = 0;
2057 jump_time = 0;
2058 cse_time = 0;
2059 loop_time = 0;
2060 cse2_time = 0;
2061 flow_time = 0;
2062 combine_time = 0;
2063 sched_time = 0;
2064 local_alloc_time = 0;
2065 global_alloc_time = 0;
2066 sched2_time = 0;
2067 dbr_sched_time = 0;
2068 shorten_branch_time = 0;
2069 stack_reg_time = 0;
2070 final_time = 0;
2071 symout_time = 0;
2072 dump_time = 0;
2073
2074 /* Open input file. */
2075
2076 if (name == 0 || !strcmp (name, "-"))
2077 {
2078 finput = stdin;
2079 name = "stdin";
2080 }
2081 else
2082 finput = fopen (name, "r");
2083 if (finput == 0)
2084 pfatal_with_name (name);
2085
282ea52a 2086#ifdef IO_BUFFER_SIZE
d7cedf4b 2087 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
282ea52a
RS
2088#endif
2089
4291d9c8
RS
2090 /* Initialize data in various passes. */
2091
2092 init_obstacks ();
2093 init_tree_codes ();
2094 init_lex ();
ca695ac9
JB
2095 /* Some of these really don't need to be called when generating bytecode,
2096 but the options would have to be parsed first to know that. -bson */
4291d9c8
RS
2097 init_rtl ();
2098 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2099 || debug_info_level == DINFO_LEVEL_VERBOSE);
7f21d440 2100 init_regs ();
4291d9c8
RS
2101 init_decl_processing ();
2102 init_optabs ();
2103 init_stmt ();
2104 init_expmed ();
4fa52007 2105 init_expr_once ();
4291d9c8
RS
2106 init_loop ();
2107 init_reload ();
2108
2109 if (flag_caller_saves)
2110 init_caller_save ();
2111
f246a305
RS
2112 /* If auxiliary info generation is desired, open the output file.
2113 This goes in the same directory as the source file--unlike
2114 all the other output files. */
4291d9c8
RS
2115 if (flag_gen_aux_info)
2116 {
4291d9c8
RS
2117 aux_info_file = fopen (aux_info_file_name, "w");
2118 if (aux_info_file == 0)
2119 pfatal_with_name (aux_info_file_name);
2120 }
2121
2122 /* If rtl dump desired, open the output file. */
2123 if (rtl_dump)
dfe1a916 2124 rtl_dump_file = open_dump_file (dump_base_name, ".rtl");
4291d9c8
RS
2125
2126 /* If jump_opt dump desired, open the output file. */
2127 if (jump_opt_dump)
dfe1a916 2128 jump_opt_dump_file = open_dump_file (dump_base_name, ".jump");
4291d9c8
RS
2129
2130 /* If cse dump desired, open the output file. */
2131 if (cse_dump)
dfe1a916 2132 cse_dump_file = open_dump_file (dump_base_name, ".cse");
4291d9c8
RS
2133
2134 /* If loop dump desired, open the output file. */
2135 if (loop_dump)
dfe1a916 2136 loop_dump_file = open_dump_file (dump_base_name, ".loop");
4291d9c8
RS
2137
2138 /* If cse2 dump desired, open the output file. */
2139 if (cse2_dump)
dfe1a916 2140 cse2_dump_file = open_dump_file (dump_base_name, ".cse2");
4291d9c8
RS
2141
2142 /* If flow dump desired, open the output file. */
2143 if (flow_dump)
dfe1a916 2144 flow_dump_file = open_dump_file (dump_base_name, ".flow");
4291d9c8
RS
2145
2146 /* If combine dump desired, open the output file. */
2147 if (combine_dump)
dfe1a916 2148 combine_dump_file = open_dump_file (dump_base_name, ".combine");
4291d9c8
RS
2149
2150 /* If scheduling dump desired, open the output file. */
2151 if (sched_dump)
dfe1a916 2152 sched_dump_file = open_dump_file (dump_base_name, ".sched");
4291d9c8
RS
2153
2154 /* If local_reg dump desired, open the output file. */
2155 if (local_reg_dump)
dfe1a916 2156 local_reg_dump_file = open_dump_file (dump_base_name, ".lreg");
4291d9c8
RS
2157
2158 /* If global_reg dump desired, open the output file. */
2159 if (global_reg_dump)
dfe1a916 2160 global_reg_dump_file = open_dump_file (dump_base_name, ".greg");
4291d9c8
RS
2161
2162 /* If 2nd scheduling dump desired, open the output file. */
2163 if (sched2_dump)
dfe1a916 2164 sched2_dump_file = open_dump_file (dump_base_name, ".sched2");
4291d9c8
RS
2165
2166 /* If jump2_opt dump desired, open the output file. */
2167 if (jump2_opt_dump)
dfe1a916 2168 jump2_opt_dump_file = open_dump_file (dump_base_name, ".jump2");
4291d9c8
RS
2169
2170 /* If dbr_sched dump desired, open the output file. */
2171 if (dbr_sched_dump)
dfe1a916 2172 dbr_sched_dump_file = open_dump_file (dump_base_name, ".dbr");
4291d9c8
RS
2173
2174#ifdef STACK_REGS
2175
2176 /* If stack_reg dump desired, open the output file. */
2177 if (stack_reg_dump)
dfe1a916 2178 stack_reg_dump_file = open_dump_file (dump_base_name, ".stack");
4291d9c8
RS
2179
2180#endif
2181
2182 /* Open assembler code output file. */
2183
2184 if (! name_specified && asm_file_name == 0)
2185 asm_out_file = stdout;
2186 else
2187 {
4291d9c8 2188 int len = strlen (dump_base_name);
dfe1a916 2189 register char *dumpname = (char *) xmalloc (len + 6);
4291d9c8
RS
2190 strcpy (dumpname, dump_base_name);
2191 strip_off_ending (dumpname, len);
2192 strcat (dumpname, ".s");
2193 if (asm_file_name == 0)
2194 {
2195 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2196 strcpy (asm_file_name, dumpname);
2197 }
2198 if (!strcmp (asm_file_name, "-"))
2199 asm_out_file = stdout;
2200 else
2201 asm_out_file = fopen (asm_file_name, "w");
2202 if (asm_out_file == 0)
2203 pfatal_with_name (asm_file_name);
2204 }
2205
f246a305 2206#ifdef IO_BUFFER_SIZE
d7cedf4b
RS
2207 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2208 _IOFBF, IO_BUFFER_SIZE);
f246a305
RS
2209#endif
2210
4291d9c8
RS
2211 input_filename = name;
2212
18736654
RK
2213 /* Put an entry on the input file stack for the main input file. */
2214 input_file_stack
2215 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2216 input_file_stack->next = 0;
2217 input_file_stack->name = input_filename;
2218
4291d9c8
RS
2219 /* Perform language-specific initialization.
2220 This may set main_input_filename. */
2221 lang_init ();
2222
2223 /* If the input doesn't start with a #line, use the input name
2224 as the official input file name. */
2225 if (main_input_filename == 0)
2226 main_input_filename = name;
2227
ca695ac9
JB
2228 if (!output_bytecode)
2229 {
2230 ASM_FILE_START (asm_out_file);
3d5cdd42
DE
2231
2232#ifdef ASM_COMMENT_START
2233 if (flag_verbose_asm)
2234 {
2235 /* Print the list of options in effect. */
3d5cdd42
DE
2236 print_version (asm_out_file, ASM_COMMENT_START);
2237 print_switch_values (asm_out_file, 0, MAX_LINE,
2238 ASM_COMMENT_START, " ", "\n");
2239 /* Add a blank line here so it appears in assembler output but not
2240 screen output. */
2241 fprintf (asm_out_file, "\n");
2242 }
2243#endif
ca695ac9 2244 }
4291d9c8 2245
ca695ac9 2246 /* Output something to inform GDB that this compilation was by GCC. Also
0f41302f 2247 serves to tell GDB file consists of bytecodes. */
ca695ac9
JB
2248 if (output_bytecode)
2249 fprintf (asm_out_file, "bc_gcc2_compiled.:\n");
2250 else
2251 {
4291d9c8 2252#ifndef ASM_IDENTIFY_GCC
ca695ac9 2253 fprintf (asm_out_file, "gcc2_compiled.:\n");
4291d9c8 2254#else
ca695ac9 2255 ASM_IDENTIFY_GCC (asm_out_file);
4291d9c8 2256#endif
ca695ac9 2257 }
d0d4af87 2258
0f41302f 2259 /* Output something to identify which front-end produced this file. */
d0d4af87
MS
2260#ifdef ASM_IDENTIFY_LANGUAGE
2261 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2262#endif
2263
cf440348
JL
2264#ifndef ASM_OUTPUT_SECTION_NAME
2265 if (flag_function_sections)
2266 {
2267 warning ("-ffunction-sections not supported for this target.");
2268 flag_function_sections = 0;
2269 }
2270#endif
2271
2272 if (flag_function_sections
2273 && (profile_flag || profile_block_flag))
2274 {
2275 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2276 flag_function_sections = 0;
2277 }
2278
2279 if (flag_function_sections && write_symbols != NO_DEBUG)
2280 warning ("-ffunction-sections may affect debugging on some targets.");
2281
ca695ac9
JB
2282 if (output_bytecode)
2283 {
2284 if (profile_flag || profile_block_flag)
2285 error ("profiling not supported in bytecode compilation");
2286 }
2287 else
2288 {
2289 /* ??? Note: There used to be a conditional here
2290 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2291 This was to guarantee separation between gcc_compiled. and
2292 the first function, for the sake of dbx on Suns.
2293 However, having the extra zero here confused the Emacs
2294 code for unexec, and might confuse other programs too.
2295 Therefore, I took out that change.
2296 In future versions we should find another way to solve
2297 that dbx problem. -- rms, 23 May 93. */
2298
2299 /* Don't let the first function fall at the same address
2300 as gcc_compiled., if profiling. */
2301 if (profile_flag || profile_block_flag)
2302 assemble_zeros (UNITS_PER_WORD);
2303 }
4291d9c8
RS
2304
2305 /* If dbx symbol table desired, initialize writing it
2306 and output the predefined types. */
f246a305
RS
2307#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2308 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2309 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2310 getdecls ()));
2311#endif
2312#ifdef SDB_DEBUGGING_INFO
2313 if (write_symbols == SDB_DEBUG)
2314 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2315 getdecls ()));
2316#endif
2317#ifdef DWARF_DEBUGGING_INFO
2318 if (write_symbols == DWARF_DEBUG)
2319 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2320#endif
9a666dda
JM
2321#ifdef DWARF2_DEBUGGING_INFO
2322 if (write_symbols == DWARF2_DEBUG)
2323 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
2324#endif
4291d9c8
RS
2325
2326 /* Initialize yet another pass. */
2327
ca695ac9
JB
2328 if (!output_bytecode)
2329 init_final (main_input_filename);
4291d9c8
RS
2330
2331 start_time = get_run_time ();
2332
2333 /* Call the parser, which parses the entire file
2334 (calling rest_of_compilation for each function). */
2335
2336 if (yyparse () != 0)
453dfc78
JW
2337 {
2338 if (errorcount == 0)
2339 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2340
2341 /* In case there were missing closebraces,
2342 get us back to the global binding level. */
2343 while (! global_bindings_p ())
2344 poplevel (0, 0, 0);
2345 }
4291d9c8
RS
2346
2347 /* Compilation is now finished except for writing
2348 what's left of the symbol table output. */
2349
2350 parse_time += get_run_time () - start_time;
2351
2352 parse_time -= integration_time;
2353 parse_time -= varconst_time;
2354
2355 globals = getdecls ();
2356
2357 /* Really define vars that have had only a tentative definition.
2358 Really output inline functions that must actually be callable
2359 and have not been output so far. */
2360
2361 {
2362 int len = list_length (globals);
2363 tree *vec = (tree *) alloca (sizeof (tree) * len);
2364 int i;
2365 tree decl;
2b6c54d6 2366 int reconsider = 1;
4291d9c8
RS
2367
2368 /* Process the decls in reverse order--earliest first.
2369 Put them into VEC from back to front, then take out from front. */
2370
2371 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2372 vec[len - i - 1] = decl;
2373
2374 for (i = 0; i < len; i++)
2375 {
2376 decl = vec[i];
07af9d16
JM
2377
2378 /* We're not deferring this any longer. */
2379 DECL_DEFER_OUTPUT (decl) = 0;
2380
488b1f4f
RS
2381 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2382 && incomplete_decl_finalize_hook != 0)
2b599527 2383 (*incomplete_decl_finalize_hook) (decl);
2b6c54d6 2384 }
2b599527 2385
2b6c54d6
JM
2386 /* Now emit any global variables or functions that we have been putting
2387 off. We need to loop in case one of the things emitted here
2388 references another one which comes earlier in the list. */
2389 while (reconsider)
2390 {
2391 reconsider = 0;
2392 for (i = 0; i < len; i++)
4291d9c8 2393 {
2b6c54d6
JM
2394 decl = vec[i];
2395
2396 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2397 continue;
2398
6b2bd61e
PB
2399 /* Don't write out static consts, unless we still need them.
2400
fbe912dd
BK
2401 We also keep static consts if not optimizing (for debugging),
2402 unless the user specified -fno-keep-static-consts.
6b2bd61e
PB
2403 ??? They might be better written into the debug information.
2404 This is possible when using DWARF.
2405
2406 A language processor that wants static constants to be always
2407 written out (even if it is not used) is responsible for
2408 calling rest_of_decl_compilation itself. E.g. the C front-end
2409 calls rest_of_decl_compilation from finish_decl.
2410 One motivation for this is that is conventional in some
2411 environments to write things like:
2412 static const char rcsid[] = "... version string ...";
2413 intending to force the string to be in the executable.
2414
2415 A language processor that would prefer to have unneeded
2416 static constants "optimized away" would just defer writing
2417 them out until here. E.g. C++ does this, because static
2418 constants are often defined in header files.
2419
2420 ??? A tempting alternative (for both C and C++) would be
2421 to force a constant to be written if and only if it is
0f41302f 2422 defined in a main file, as opposed to an include file. */
6b2bd61e 2423
2b6c54d6
JM
2424 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2425 && (! TREE_READONLY (decl)
2426 || TREE_PUBLIC (decl)
fbe912dd 2427 || (!optimize && flag_keep_static_consts)
2b6c54d6
JM
2428 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2429 {
2430 reconsider = 1;
2431 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2432 }
2433
2434 if (TREE_CODE (decl) == FUNCTION_DECL
2435 && DECL_INITIAL (decl) != 0
2436 && DECL_SAVED_INSNS (decl) != 0
2437 && (flag_keep_inline_functions
2438 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2439 {
2440 reconsider = 1;
2441 temporary_allocation ();
2442 output_inline_function (decl);
2443 permanent_allocation (1);
2444 }
4291d9c8 2445 }
2b6c54d6 2446 }
4291d9c8 2447
3d195391
MS
2448 /* Now that all possible functions have been output, we can dump
2449 the exception table. */
2450
2451 if (exception_table_p ())
2452 output_exception_table ();
2453
2b6c54d6
JM
2454 for (i = 0; i < len; i++)
2455 {
2456 decl = vec[i];
2457
2458 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2459 && ! TREE_ASM_WRITTEN (decl))
2460 /* Cancel the RTL for this decl so that, if debugging info
2461 output for global variables is still to come,
2462 this one will be omitted. */
2463 DECL_RTL (decl) = NULL;
4291d9c8 2464
ac266247
RS
2465 /* Warn about any function
2466 declared static but not defined.
2467 We don't warn about variables,
2468 because many programs have static variables
2469 that exist only to get some text into the object file. */
8c461ea1
JM
2470 if (TREE_CODE (decl) == FUNCTION_DECL
2471 && (warn_unused
2472 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
4291d9c8 2473 && DECL_INITIAL (decl) == 0
216d5cdd 2474 && DECL_EXTERNAL (decl)
d1b01681 2475 && ! DECL_ARTIFICIAL (decl)
4291d9c8 2476 && ! TREE_PUBLIC (decl))
7d429c41 2477 {
8c461ea1 2478 pedwarn_with_decl (decl,
7d429c41
RS
2479 "`%s' declared `static' but never defined");
2480 /* This symbol is effectively an "extern" declaration now. */
2481 TREE_PUBLIC (decl) = 1;
2482 assemble_external (decl);
7d429c41 2483 }
8c461ea1 2484
4291d9c8 2485 /* Warn about static fns or vars defined but not used,
7062b881
PB
2486 but not about inline functions or static consts
2487 since defining those in header files is normal practice. */
4291d9c8 2488 if (warn_unused
7062b881
PB
2489 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2490 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
0c20aabf 2491 && ! DECL_IN_SYSTEM_HEADER (decl)
216d5cdd 2492 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2493 && ! TREE_PUBLIC (decl)
2494 && ! TREE_USED (decl)
f843649d 2495 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
4291d9c8
RS
2496 /* The TREE_USED bit for file-scope decls
2497 is kept in the identifier, to handle multiple
2498 external decls in different scopes. */
2499 && ! TREE_USED (DECL_NAME (decl)))
2500 warning_with_decl (decl, "`%s' defined but not used");
2501
2502#ifdef SDB_DEBUGGING_INFO
2503 /* The COFF linker can move initialized global vars to the end.
2504 And that can screw up the symbol ordering.
2505 By putting the symbols in that order to begin with,
2506 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2507 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2508 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
7efad3f7 2509 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2510 && DECL_RTL (decl) != 0)
2511 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2512
2513 /* Output COFF information for non-global
0f41302f 2514 file-scope initialized variables. */
4291d9c8
RS
2515 if (write_symbols == SDB_DEBUG
2516 && TREE_CODE (decl) == VAR_DECL
2517 && DECL_INITIAL (decl)
7efad3f7 2518 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2519 && DECL_RTL (decl) != 0
2520 && GET_CODE (DECL_RTL (decl)) == MEM)
2521 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2522#endif /* SDB_DEBUGGING_INFO */
2523#ifdef DWARF_DEBUGGING_INFO
6dc42e49 2524 /* Output DWARF information for file-scope tentative data object
4291d9c8
RS
2525 declarations, file-scope (extern) function declarations (which
2526 had no corresponding body) and file-scope tagged type declarations
2527 and definitions which have not yet been forced out. */
2528
2529 if (write_symbols == DWARF_DEBUG
2530 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2531 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
9a666dda
JM
2532#endif
2533#ifdef DWARF2_DEBUGGING_INFO
2534 /* Output DWARF2 information for file-scope tentative data object
2535 declarations, file-scope (extern) function declarations (which
2536 had no corresponding body) and file-scope tagged type declarations
2537 and definitions which have not yet been forced out. */
2538
2539 if (write_symbols == DWARF2_DEBUG
2540 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
88dad228 2541 TIMEVAR (symout_time, dwarf2out_decl (decl));
4291d9c8
RS
2542#endif
2543 }
2544 }
2545
4b8af8d9
JM
2546 /* Write out any pending weak symbol declarations. */
2547
2548 weak_finish ();
2549
4291d9c8 2550 /* Do dbx symbols */
f246a305
RS
2551#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2552 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2553 TIMEVAR (symout_time,
2554 {
2555 dbxout_finish (asm_out_file, main_input_filename);
2556 });
2557#endif
2558
2559#ifdef DWARF_DEBUGGING_INFO
2560 if (write_symbols == DWARF_DEBUG)
2561 TIMEVAR (symout_time,
2562 {
2563 dwarfout_finish ();
2564 });
2565#endif
2566
9a666dda
JM
2567#ifdef DWARF2_DEBUGGING_INFO
2568 if (write_symbols == DWARF2_DEBUG)
2569 TIMEVAR (symout_time,
2570 {
2571 dwarf2out_finish ();
2572 });
2573#endif
2574
4291d9c8
RS
2575 /* Output some stuff at end of file if nec. */
2576
ca695ac9
JB
2577 if (!output_bytecode)
2578 {
2579 end_final (main_input_filename);
4291d9c8
RS
2580
2581#ifdef ASM_FILE_END
ca695ac9 2582 ASM_FILE_END (asm_out_file);
4291d9c8 2583#endif
ca695ac9 2584 }
4291d9c8 2585
4291d9c8
RS
2586 /* Language-specific end of compilation actions. */
2587
2588 lang_finish ();
2589
0207ea82
RK
2590 if (output_bytecode)
2591 bc_write_file (asm_out_file);
2592
4291d9c8
RS
2593 /* Close the dump files. */
2594
2595 if (flag_gen_aux_info)
2596 {
2597 fclose (aux_info_file);
2598 if (errorcount)
2599 unlink (aux_info_file_name);
2600 }
2601
2602 if (rtl_dump)
2603 fclose (rtl_dump_file);
2604
2605 if (jump_opt_dump)
2606 fclose (jump_opt_dump_file);
2607
2608 if (cse_dump)
2609 fclose (cse_dump_file);
2610
2611 if (loop_dump)
2612 fclose (loop_dump_file);
2613
2614 if (cse2_dump)
2615 fclose (cse2_dump_file);
2616
2617 if (flow_dump)
2618 fclose (flow_dump_file);
2619
2620 if (combine_dump)
2621 {
2622 dump_combine_total_stats (combine_dump_file);
2623 fclose (combine_dump_file);
2624 }
2625
2626 if (sched_dump)
2627 fclose (sched_dump_file);
2628
2629 if (local_reg_dump)
2630 fclose (local_reg_dump_file);
2631
2632 if (global_reg_dump)
2633 fclose (global_reg_dump_file);
2634
2635 if (sched2_dump)
2636 fclose (sched2_dump_file);
2637
2638 if (jump2_opt_dump)
2639 fclose (jump2_opt_dump_file);
2640
2641 if (dbr_sched_dump)
2642 fclose (dbr_sched_dump_file);
2643
2644#ifdef STACK_REGS
2645 if (stack_reg_dump)
2646 fclose (stack_reg_dump_file);
2647#endif
2648
2649 /* Close non-debugging input and output files. Take special care to note
2650 whether fclose returns an error, since the pages might still be on the
2651 buffer chain while the file is open. */
2652
2653 fclose (finput);
2654 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2655 fatal_io_error (asm_file_name);
2656
2657 /* Print the times. */
2658
2659 if (! quiet_flag)
2660 {
2661 fprintf (stderr,"\n");
2662 print_time ("parse", parse_time);
ca695ac9
JB
2663
2664 if (!output_bytecode)
2665 {
2666 print_time ("integration", integration_time);
2667 print_time ("jump", jump_time);
2668 print_time ("cse", cse_time);
2669 print_time ("loop", loop_time);
2670 print_time ("cse2", cse2_time);
2671 print_time ("flow", flow_time);
2672 print_time ("combine", combine_time);
2673 print_time ("sched", sched_time);
2674 print_time ("local-alloc", local_alloc_time);
2675 print_time ("global-alloc", global_alloc_time);
2676 print_time ("sched2", sched2_time);
2677 print_time ("dbranch", dbr_sched_time);
2678 print_time ("shorten-branch", shorten_branch_time);
2679 print_time ("stack-reg", stack_reg_time);
2680 print_time ("final", final_time);
2681 print_time ("varconst", varconst_time);
2682 print_time ("symout", symout_time);
2683 print_time ("dump", dump_time);
2684 }
4291d9c8
RS
2685 }
2686}
2687\f
2688/* This is called from various places for FUNCTION_DECL, VAR_DECL,
2689 and TYPE_DECL nodes.
2690
2691 This does nothing for local (non-static) variables.
2692 Otherwise, it sets up the RTL and outputs any assembler code
2693 (label definition, storage allocation and initialization).
2694
2695 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2696 the assembler symbol name to be used. TOP_LEVEL is nonzero
2697 if this declaration is not within a function. */
2698
2699void
2700rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2701 tree decl;
2702 char *asmspec;
2703 int top_level;
2704 int at_end;
2705{
2706 /* Declarations of variables, and of functions defined elsewhere. */
2707
928eb380
RS
2708/* The most obvious approach, to put an #ifndef around where
2709 this macro is used, doesn't work since it's inside a macro call. */
2710#ifndef ASM_FINISH_DECLARE_OBJECT
2711#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2712#endif
2713
4291d9c8
RS
2714 /* Forward declarations for nested functions are not "external",
2715 but we need to treat them as if they were. */
216d5cdd 2716 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
4291d9c8
RS
2717 || TREE_CODE (decl) == FUNCTION_DECL)
2718 TIMEVAR (varconst_time,
2719 {
2720 make_decl_rtl (decl, asmspec, top_level);
9a9a9643
RS
2721 /* Initialized extern variable exists to be replaced
2722 with its value, or represents something that will be
2723 output in another file. */
6dbf678a 2724 if (! (TREE_CODE (decl) == VAR_DECL
9a9a9643
RS
2725 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
2726 && DECL_INITIAL (decl) != 0
5b272d50 2727 && DECL_INITIAL (decl) != error_mark_node))
6dbf678a
RS
2728 /* Don't output anything
2729 when a tentative file-scope definition is seen.
2730 But at end of compilation, do output code for them. */
2731 if (! (! at_end && top_level
2732 && (DECL_INITIAL (decl) == 0
9a9a9643 2733 || DECL_INITIAL (decl) == error_mark_node)))
8380e2f2 2734 assemble_variable (decl, top_level, at_end, 0);
5b7540b6
DE
2735 if (!output_bytecode
2736 && decl == last_assemble_variable_decl)
5e10b3cc
RS
2737 {
2738 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2739 top_level, at_end);
2740 }
4291d9c8 2741 });
216d5cdd 2742 else if (DECL_REGISTER (decl) && asmspec != 0)
4291d9c8
RS
2743 {
2744 if (decode_reg_name (asmspec) >= 0)
2745 {
2746 DECL_RTL (decl) = 0;
2747 make_decl_rtl (decl, asmspec, top_level);
2748 }
2749 else
2750 error ("invalid register name `%s' for register variable", asmspec);
2751 }
f246a305
RS
2752#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2753 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2754 && TREE_CODE (decl) == TYPE_DECL)
4291d9c8
RS
2755 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2756#endif
2757#ifdef SDB_DEBUGGING_INFO
2758 else if (write_symbols == SDB_DEBUG && top_level
2759 && TREE_CODE (decl) == TYPE_DECL)
2760 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2761#endif
2762}
2763
2764/* Called after finishing a record, union or enumeral type. */
2765
2766void
2767rest_of_type_compilation (type, toplev)
2768 tree type;
2769 int toplev;
2770{
f246a305
RS
2771#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2772 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2773 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2774#endif
2775#ifdef SDB_DEBUGGING_INFO
2776 if (write_symbols == SDB_DEBUG)
2777 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2778#endif
2b77decc 2779#ifdef DWARF_DEBUGGING_INFO
a082c85a
JM
2780 /* Don't write out function-scope types here. */
2781 if (write_symbols == DWARF_DEBUG && toplev)
2b77decc
JM
2782 TIMEVAR (symout_time, dwarfout_file_scope_decl (TYPE_STUB_DECL (type), 0));
2783#endif
9a666dda 2784#ifdef DWARF2_DEBUGGING_INFO
88dad228
JM
2785 if (write_symbols == DWARF2_DEBUG)
2786 TIMEVAR (symout_time, dwarf2out_decl (TYPE_STUB_DECL (type)));
9a666dda 2787#endif
4291d9c8
RS
2788}
2789
2790/* This is called from finish_function (within yyparse)
2791 after each top-level definition is parsed.
2792 It is supposed to compile that function or variable
2793 and output the assembler code for it.
2794 After we return, the tree storage is freed. */
2795
2796void
2797rest_of_compilation (decl)
2798 tree decl;
2799{
2800 register rtx insns;
2801 int start_time = get_run_time ();
2802 int tem;
2803 /* Nonzero if we have saved the original DECL_INITIAL of the function,
2804 to be restored after we finish compiling the function
2805 (for use when compiling inline calls to this function). */
2806 tree saved_block_tree = 0;
8a958768
RS
2807 /* Likewise, for DECL_ARGUMENTS. */
2808 tree saved_arguments = 0;
ab40ad2b 2809 int failure = 0;
4291d9c8 2810
ca695ac9
JB
2811 if (output_bytecode)
2812 return;
2813
4291d9c8
RS
2814 /* If we are reconsidering an inline function
2815 at the end of compilation, skip the stuff for making it inline. */
2816
2817 if (DECL_SAVED_INSNS (decl) == 0)
2818 {
9deaf1b1 2819 int inlineable = 0;
4291d9c8
RS
2820 char *lose;
2821
2822 /* If requested, consider whether to make this function inline. */
9deaf1b1 2823 if (DECL_INLINE (decl) || flag_inline_functions)
4291d9c8
RS
2824 TIMEVAR (integration_time,
2825 {
2826 lose = function_cannot_inline_p (decl);
caa0eccd 2827 if (lose || ! optimize)
4291d9c8 2828 {
9deaf1b1 2829 if (warn_inline && DECL_INLINE (decl))
4291d9c8 2830 warning_with_decl (decl, lose);
9548c538 2831 DECL_ABSTRACT_ORIGIN (decl) = 0;
46dbb914
RS
2832 /* Don't really compile an extern inline function.
2833 If we can't make it inline, pretend
2834 it was only declared. */
2835 if (DECL_EXTERNAL (decl))
27937f46
RS
2836 {
2837 DECL_INITIAL (decl) = 0;
2838 goto exit_rest_of_compilation;
2839 }
4291d9c8
RS
2840 }
2841 else
9deaf1b1
RK
2842 /* ??? Note that this has the effect of making it look
2843 like "inline" was specified for a function if we choose
2844 to inline it. This isn't quite right, but it's
2845 probably not worth the trouble to fix. */
2846 inlineable = DECL_INLINE (decl) = 1;
4291d9c8
RS
2847 });
2848
2849 insns = get_insns ();
2850
2851 /* Dump the rtl code if we are dumping rtl. */
2852
2853 if (rtl_dump)
2854 TIMEVAR (dump_time,
2855 {
2856 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2857 IDENTIFIER_POINTER (DECL_NAME (decl)));
2858 if (DECL_SAVED_INSNS (decl))
2859 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2860 print_rtl (rtl_dump_file, insns);
2861 fflush (rtl_dump_file);
2862 });
2863
2864 /* If function is inline, and we don't yet know whether to
2865 compile it by itself, defer decision till end of compilation.
2866 finish_compilation will call rest_of_compilation again
16411ea6 2867 for those functions that need to be output. Also defer those
ec6c615d
RK
2868 functions that we are supposed to defer. We cannot defer
2869 functions containing nested functions since the nested function
2870 data is in our non-saved obstack. */
2871
2872 if (! current_function_contains_functions
2873 && (DECL_DEFER_OUTPUT (decl)
9deaf1b1 2874 || (DECL_INLINE (decl)
ec6c615d
RK
2875 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2876 && ! flag_keep_inline_functions)
2877 || DECL_EXTERNAL (decl)))))
4291d9c8 2878 {
951af26e
JM
2879 DECL_DEFER_OUTPUT (decl) = 1;
2880
2881 /* If -Wreturn-type, we have to do a bit of compilation. */
2882 if (! warn_return_type)
937522b5 2883 {
951af26e
JM
2884#ifdef DWARF_DEBUGGING_INFO
2885 /* Generate the DWARF info for the "abstract" instance
2886 of a function which we may later generate inlined and/or
2887 out-of-line instances of. */
2888 if (write_symbols == DWARF_DEBUG)
2889 {
2890 set_decl_abstract_flags (decl, 1);
2891 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2892 set_decl_abstract_flags (decl, 0);
2893 }
9a666dda
JM
2894#endif
2895#ifdef DWARF2_DEBUGGING_INFO
2896 /* Generate the DWARF2 info for the "abstract" instance
2897 of a function which we may later generate inlined and/or
2898 out-of-line instances of. */
2899 if (write_symbols == DWARF2_DEBUG)
2900 {
2901 set_decl_abstract_flags (decl, 1);
88dad228 2902 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
2903 set_decl_abstract_flags (decl, 0);
2904 }
951af26e
JM
2905#endif
2906 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
ac02eb62 2907 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
951af26e 2908 goto exit_rest_of_compilation;
937522b5 2909 }
4291d9c8
RS
2910 }
2911
8a958768 2912 /* If we have to compile the function now, save its rtl and subdecls
4291d9c8 2913 so that its compilation will not affect what others get. */
9deaf1b1 2914 if (inlineable || DECL_DEFER_OUTPUT (decl))
4291d9c8 2915 {
937522b5
RS
2916#ifdef DWARF_DEBUGGING_INFO
2917 /* Generate the DWARF info for the "abstract" instance of
2918 a function which we will generate an out-of-line instance
2919 of almost immediately (and which we may also later generate
2920 various inlined instances of). */
2921 if (write_symbols == DWARF_DEBUG)
2922 {
2923 set_decl_abstract_flags (decl, 1);
2924 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2925 set_decl_abstract_flags (decl, 0);
2926 }
9a666dda
JM
2927#endif
2928#ifdef DWARF2_DEBUGGING_INFO
2929 /* Generate the DWARF2 info for the "abstract" instance of
2930 a function which we will generate an out-of-line instance
2931 of almost immediately (and which we may also later generate
2932 various inlined instances of). */
2933 if (write_symbols == DWARF2_DEBUG)
2934 {
2935 set_decl_abstract_flags (decl, 1);
88dad228 2936 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
2937 set_decl_abstract_flags (decl, 0);
2938 }
937522b5 2939#endif
4291d9c8 2940 saved_block_tree = DECL_INITIAL (decl);
8a958768 2941 saved_arguments = DECL_ARGUMENTS (decl);
4291d9c8 2942 TIMEVAR (integration_time, save_for_inline_copying (decl));
912c4289 2943 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
4291d9c8 2944 }
4291d9c8 2945
b8471b65
RK
2946 /* If specified extern inline but we aren't inlining it, we are
2947 done. */
9deaf1b1 2948 if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
b8471b65
RK
2949 goto exit_rest_of_compilation;
2950 }
07af9d16 2951
951af26e
JM
2952 if (! DECL_DEFER_OUTPUT (decl))
2953 TREE_ASM_WRITTEN (decl) = 1;
4291d9c8
RS
2954
2955 /* Now that integrate will no longer see our rtl, we need not distinguish
2956 between the return value of this function and the return value of called
2957 functions. */
2958 rtx_equal_function_value_matters = 0;
2959
32235b30
RS
2960 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
2961 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
4291d9c8
RS
2962 {
2963 goto exit_rest_of_compilation;
2964 }
2965
2966 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
2967 Note that that may have been done above, in save_for_inline_copying.
2968 The call to resume_temporary_allocation near the end of this function
2969 goes back to the usual state of affairs. */
2970
2971 rtl_in_current_obstack ();
2972
2973#ifdef FINALIZE_PIC
2974 /* If we are doing position-independent code generation, now
2975 is the time to output special prologues and epilogues.
2976 We do not want to do this earlier, because it just clutters
2977 up inline functions with meaningless insns. */
2978 if (flag_pic)
2979 FINALIZE_PIC;
2980#endif
2981
3d195391
MS
2982 /* Add an unwinder for exception handling, if needed. */
2983 emit_unwinder ();
2984
4291d9c8
RS
2985 insns = get_insns ();
2986
2987 /* Copy any shared structure that should not be shared. */
2988
2989 unshare_all_rtl (insns);
2990
2991 /* Instantiate all virtual registers. */
2992
2993 instantiate_virtual_regs (current_function_decl, get_insns ());
2994
2995 /* See if we have allocated stack slots that are not directly addressable.
2996 If so, scan all the insns and create explicit address computation
2997 for all references to such slots. */
2998/* fixup_stack_slots (); */
2999
3d195391
MS
3000 /* Find all the EH handlers. */
3001 find_exception_handler_labels ();
3002
cc4e79d8
JL
3003 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3004 are initialized and to compute whether control can drop off the end
3005 of the function. */
3006 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3007 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
4291d9c8 3008
32235b30 3009 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
951af26e 3010 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
32235b30
RS
3011 goto exit_rest_of_compilation;
3012
4291d9c8
RS
3013 /* Dump rtl code after jump, if we are doing that. */
3014
3015 if (jump_opt_dump)
3016 TIMEVAR (dump_time,
3017 {
3018 fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
3019 IDENTIFIER_POINTER (DECL_NAME (decl)));
3020 print_rtl (jump_opt_dump_file, insns);
3021 fflush (jump_opt_dump_file);
3022 });
3023
3024 /* Perform common subexpression elimination.
3025 Nonzero value from `cse_main' means that jumps were simplified
3026 and some code may now be unreachable, so do
3027 jump optimization again. */
3028
3029 if (cse_dump)
3030 TIMEVAR (dump_time,
3031 {
3032 fprintf (cse_dump_file, "\n;; Function %s\n\n",
3033 IDENTIFIER_POINTER (DECL_NAME (decl)));
3034 });
3035
3036 if (optimize > 0)
3037 {
3038 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3039
3040 if (flag_thread_jumps)
3041 /* Hacks by tiemann & kenner. */
6f606d63 3042 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
4291d9c8
RS
3043
3044 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3045 0, cse_dump_file));
3046 TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
3047
534bfae4 3048 if (tem || optimize > 1)
4291d9c8
RS
3049 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3050 }
3051
3052 /* Dump rtl code after cse, if we are doing that. */
3053
3054 if (cse_dump)
3055 TIMEVAR (dump_time,
3056 {
3057 print_rtl (cse_dump_file, insns);
3058 fflush (cse_dump_file);
3059 });
3060
3061 if (loop_dump)
3062 TIMEVAR (dump_time,
3063 {
3064 fprintf (loop_dump_file, "\n;; Function %s\n\n",
3065 IDENTIFIER_POINTER (DECL_NAME (decl)));
3066 });
3067
3068 /* Move constant computations out of loops. */
3069
3070 if (optimize > 0)
3071 {
3072 TIMEVAR (loop_time,
3073 {
37366632 3074 loop_optimize (insns, loop_dump_file);
4291d9c8
RS
3075 });
3076 }
3077
3078 /* Dump rtl code after loop opt, if we are doing that. */
3079
3080 if (loop_dump)
3081 TIMEVAR (dump_time,
3082 {
3083 print_rtl (loop_dump_file, insns);
3084 fflush (loop_dump_file);
3085 });
3086
3087 if (cse2_dump)
3088 TIMEVAR (dump_time,
3089 {
3090 fprintf (cse2_dump_file, "\n;; Function %s\n\n",
3091 IDENTIFIER_POINTER (DECL_NAME (decl)));
3092 });
3093
3094 if (optimize > 0 && flag_rerun_cse_after_loop)
3095 {
44333223
JL
3096 /* Running another jump optimization pass before the second
3097 cse pass sometimes simplifies the RTL enough to allow
9e9b48a4
DE
3098 the second CSE pass to do a better job. Jump_optimize can change
3099 max_reg_num so we must rerun reg_scan afterwards.
3100 ??? Rework to not call reg_scan so often. */
3101 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
44333223 3102 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
4291d9c8 3103
9e9b48a4 3104 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
4291d9c8
RS
3105 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3106 1, cse2_dump_file));
3107 if (tem)
3108 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3109 }
3110
3111 if (optimize > 0 && flag_thread_jumps)
c2f006ec
RK
3112 {
3113 /* This pass of jump threading straightens out code
3114 that was kinked by loop optimization. */
3115 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3116 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3117 }
4291d9c8
RS
3118 /* Dump rtl code after cse, if we are doing that. */
3119
3120 if (cse2_dump)
3121 TIMEVAR (dump_time,
3122 {
3123 print_rtl (cse2_dump_file, insns);
3124 fflush (cse2_dump_file);
3125 });
3126
3127 /* We are no longer anticipating cse in this function, at least. */
3128
3129 cse_not_expected = 1;
3130
3131 /* Now we choose between stupid (pcc-like) register allocation
3132 (if we got the -noreg switch and not -opt)
3133 and smart register allocation. */
3134
3135 if (optimize > 0) /* Stupid allocation probably won't work */
3136 obey_regdecls = 0; /* if optimizations being done. */
3137
3138 regclass_init ();
3139
3140 /* Print function header into flow dump now
3141 because doing the flow analysis makes some of the dump. */
3142
3143 if (flow_dump)
3144 TIMEVAR (dump_time,
3145 {
3146 fprintf (flow_dump_file, "\n;; Function %s\n\n",
3147 IDENTIFIER_POINTER (DECL_NAME (decl)));
3148 });
3149
3150 if (obey_regdecls)
3151 {
3152 TIMEVAR (flow_time,
3153 {
3154 regclass (insns, max_reg_num ());
3155 stupid_life_analysis (insns, max_reg_num (),
3156 flow_dump_file);
3157 });
3158 }
3159 else
3160 {
3161 /* Do control and data flow analysis,
3162 and write some of the results to dump file. */
3163
3164 TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
3165 flow_dump_file));
3166 if (warn_uninitialized)
3167 {
3168 uninitialized_vars_warning (DECL_INITIAL (decl));
3169 setjmp_args_warning ();
3170 }
3171 }
3172
3173 /* Dump rtl after flow analysis. */
3174
3175 if (flow_dump)
3176 TIMEVAR (dump_time,
3177 {
3178 print_rtl (flow_dump_file, insns);
3179 fflush (flow_dump_file);
3180 });
3181
3182 /* If -opt, try combining insns through substitution. */
3183
3184 if (optimize > 0)
3185 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3186
3187 /* Dump rtl code after insn combination. */
3188
3189 if (combine_dump)
3190 TIMEVAR (dump_time,
3191 {
3192 fprintf (combine_dump_file, "\n;; Function %s\n\n",
3193 IDENTIFIER_POINTER (DECL_NAME (decl)));
3194 dump_combine_stats (combine_dump_file);
3195 print_rtl (combine_dump_file, insns);
3196 fflush (combine_dump_file);
3197 });
3198
3199 /* Print function header into sched dump now
3200 because doing the sched analysis makes some of the dump. */
3201
3202 if (sched_dump)
3203 TIMEVAR (dump_time,
3204 {
3205 fprintf (sched_dump_file, "\n;; Function %s\n\n",
3206 IDENTIFIER_POINTER (DECL_NAME (decl)));
3207 });
3208
3209 if (optimize > 0 && flag_schedule_insns)
3210 {
3211 /* Do control and data sched analysis,
3212 and write some of the results to dump file. */
3213
3214 TIMEVAR (sched_time, schedule_insns (sched_dump_file));
3215 }
3216
3217 /* Dump rtl after instruction scheduling. */
3218
3219 if (sched_dump)
3220 TIMEVAR (dump_time,
3221 {
3222 print_rtl (sched_dump_file, insns);
3223 fflush (sched_dump_file);
3224 });
3225
3226 /* Unless we did stupid register allocation,
3227 allocate pseudo-regs that are used only within 1 basic block. */
3228
3229 if (!obey_regdecls)
3230 TIMEVAR (local_alloc_time,
3231 {
3232 regclass (insns, max_reg_num ());
3233 local_alloc ();
3234 });
3235
3236 /* Dump rtl code after allocating regs within basic blocks. */
3237
3238 if (local_reg_dump)
3239 TIMEVAR (dump_time,
3240 {
3241 fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
3242 IDENTIFIER_POINTER (DECL_NAME (decl)));
3243 dump_flow_info (local_reg_dump_file);
3244 dump_local_alloc (local_reg_dump_file);
3245 print_rtl (local_reg_dump_file, insns);
3246 fflush (local_reg_dump_file);
3247 });
3248
3249 if (global_reg_dump)
3250 TIMEVAR (dump_time,
3251 fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
3252 IDENTIFIER_POINTER (DECL_NAME (decl))));
3253
bf8b4985
RK
3254 /* Save the last label number used so far, so reorg can tell
3255 when it's safe to kill spill regs. */
3256 max_label_num_after_reload = max_label_num ();
3257
4291d9c8
RS
3258 /* Unless we did stupid register allocation,
3259 allocate remaining pseudo-regs, then do the reload pass
3260 fixing up any insns that are invalid. */
3261
3262 TIMEVAR (global_alloc_time,
3263 {
3264 if (!obey_regdecls)
37366632 3265 failure = global_alloc (global_reg_dump_file);
4291d9c8 3266 else
37366632 3267 failure = reload (insns, 0, global_reg_dump_file);
4291d9c8
RS
3268 });
3269
3270 if (global_reg_dump)
3271 TIMEVAR (dump_time,
3272 {
3273 dump_global_regs (global_reg_dump_file);
3274 print_rtl (global_reg_dump_file, insns);
3275 fflush (global_reg_dump_file);
3276 });
3277
ab40ad2b
RS
3278 if (failure)
3279 goto exit_rest_of_compilation;
3280
4291d9c8
RS
3281 reload_completed = 1;
3282
bdac5f58
TW
3283 /* On some machines, the prologue and epilogue code, or parts thereof,
3284 can be represented as RTL. Doing so lets us schedule insns between
3285 it and the rest of the code and also allows delayed branch
3286 scheduling to operate in the epilogue. */
3287
3288 thread_prologue_and_epilogue_insns (insns);
3289
4291d9c8
RS
3290 if (optimize > 0 && flag_schedule_insns_after_reload)
3291 {
3292 if (sched2_dump)
3293 TIMEVAR (dump_time,
3294 {
3295 fprintf (sched2_dump_file, "\n;; Function %s\n\n",
3296 IDENTIFIER_POINTER (DECL_NAME (decl)));
3297 });
3298
3299 /* Do control and data sched analysis again,
3300 and write some more of the results to dump file. */
3301
3302 TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
3303
3304 /* Dump rtl after post-reorder instruction scheduling. */
3305
3306 if (sched2_dump)
3307 TIMEVAR (dump_time,
3308 {
3309 print_rtl (sched2_dump_file, insns);
3310 fflush (sched2_dump_file);
3311 });
3312 }
3313
3314#ifdef LEAF_REGISTERS
3315 leaf_function = 0;
3316 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
ab40ad2b 3317 leaf_function = 1;
4291d9c8
RS
3318#endif
3319
3320 /* One more attempt to remove jumps to .+1
3321 left by dead-store-elimination.
3322 Also do cross-jumping this time
3323 and delete no-op move insns. */
3324
3325 if (optimize > 0)
3326 {
3327 TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
3328 }
3329
3330 /* Dump rtl code after jump, if we are doing that. */
3331
3332 if (jump2_opt_dump)
3333 TIMEVAR (dump_time,
3334 {
3335 fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
3336 IDENTIFIER_POINTER (DECL_NAME (decl)));
3337 print_rtl (jump2_opt_dump_file, insns);
3338 fflush (jump2_opt_dump_file);
3339 });
3340
2c65021a
RK
3341 /* If a machine dependent reorganization is needed, call it. */
3342#ifdef MACHINE_DEPENDENT_REORG
3343 MACHINE_DEPENDENT_REORG (insns);
3344#endif
3345
4291d9c8 3346 /* If a scheduling pass for delayed branches is to be done,
0f41302f 3347 call the scheduling code. */
4291d9c8
RS
3348
3349#ifdef DELAY_SLOTS
3350 if (optimize > 0 && flag_delayed_branch)
3351 {
3352 TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
3353 if (dbr_sched_dump)
3354 {
3355 TIMEVAR (dump_time,
3356 {
3357 fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
3358 IDENTIFIER_POINTER (DECL_NAME (decl)));
3359 print_rtl (dbr_sched_dump_file, insns);
3360 fflush (dbr_sched_dump_file);
3361 });
3362 }
3363 }
3364#endif
3365
d0c874f6
TG
3366 /* Shorten branches. */
3367 TIMEVAR (shorten_branch_time,
3368 {
3369 shorten_branches (get_insns ());
3370 });
4291d9c8
RS
3371
3372#ifdef STACK_REGS
3373 TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
3374 if (stack_reg_dump)
3375 {
3376 TIMEVAR (dump_time,
3377 {
3378 fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
3379 IDENTIFIER_POINTER (DECL_NAME (decl)));
3380 print_rtl (stack_reg_dump_file, insns);
3381 fflush (stack_reg_dump_file);
3382 });
3383 }
3384#endif
3385
3386 /* Now turn the rtl into assembler code. */
3387
3388 TIMEVAR (final_time,
3389 {
3390 rtx x;
3391 char *fnname;
3392
3393 /* Get the function's name, as described by its RTL.
3394 This may be different from the DECL_NAME name used
3395 in the source file. */
3396
3397 x = DECL_RTL (decl);
3398 if (GET_CODE (x) != MEM)
3399 abort ();
3400 x = XEXP (x, 0);
3401 if (GET_CODE (x) != SYMBOL_REF)
3402 abort ();
3403 fnname = XSTR (x, 0);
3404
3405 assemble_start_function (decl, fnname);
3406 final_start_function (insns, asm_out_file, optimize);
3407 final (insns, asm_out_file, optimize, 0);
3408 final_end_function (insns, asm_out_file, optimize);
3409 assemble_end_function (decl, fnname);
3410 fflush (asm_out_file);
3411 });
3412
3413 /* Write DBX symbols if requested */
3414
3415 /* Note that for those inline functions where we don't initially
3416 know for certain that we will be generating an out-of-line copy,
3417 the first invocation of this routine (rest_of_compilation) will
3418 skip over this code by doing a `goto exit_rest_of_compilation;'.
3419 Later on, finish_compilation will call rest_of_compilation again
3420 for those inline functions that need to have out-of-line copies
3421 generated. During that call, we *will* be routed past here. */
3422
3423#ifdef DBX_DEBUGGING_INFO
3424 if (write_symbols == DBX_DEBUG)
3425 TIMEVAR (symout_time, dbxout_function (decl));
3426#endif
3427
3428#ifdef DWARF_DEBUGGING_INFO
3429 if (write_symbols == DWARF_DEBUG)
3430 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3431#endif
3432
9a666dda
JM
3433#ifdef DWARF2_DEBUGGING_INFO
3434 if (write_symbols == DWARF2_DEBUG)
88dad228 3435 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
3436#endif
3437
4291d9c8
RS
3438 exit_rest_of_compilation:
3439
f246a305
RS
3440 /* In case the function was not output,
3441 don't leave any temporary anonymous types
3442 queued up for sdb output. */
3443#ifdef SDB_DEBUGGING_INFO
3444 if (write_symbols == SDB_DEBUG)
37366632 3445 sdbout_types (NULL_TREE);
f246a305
RS
3446#endif
3447
8a958768
RS
3448 /* Put back the tree of subblocks and list of arguments
3449 from before we copied them.
4291d9c8
RS
3450 Code generation and the output of debugging info may have modified
3451 the copy, but the original is unchanged. */
3452
3453 if (saved_block_tree != 0)
fb19c456
JM
3454 {
3455 DECL_INITIAL (decl) = saved_block_tree;
3456 DECL_ARGUMENTS (decl) = saved_arguments;
3457 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
3458 }
4291d9c8
RS
3459
3460 reload_completed = 0;
3461
9fe320d7
RK
3462 /* Clear out the insn_length contents now that they are no longer valid. */
3463 init_insn_lengths ();
3464
4291d9c8
RS
3465 /* Clear out the real_constant_chain before some of the rtx's
3466 it runs through become garbage. */
3467
3468 clear_const_double_mem ();
3469
3470 /* Cancel the effect of rtl_in_current_obstack. */
3471
3472 resume_temporary_allocation ();
3473
adcd38c9
RK
3474 /* Show no temporary slots allocated. */
3475
3476 init_temp_slots ();
3477
4291d9c8
RS
3478 /* The parsing time is all the time spent in yyparse
3479 *except* what is spent in this function. */
3480
3481 parse_time -= get_run_time () - start_time;
3482}
3483\f
3484/* Entry point of cc1/c++. Decode command args, then call compile_file.
3485 Exit code is 35 if can't open files, 34 if fatal error,
3486 33 if had nonfatal errors, else success. */
3487
3488int
3489main (argc, argv, envp)
3490 int argc;
3491 char **argv;
3492 char **envp;
3493{
3494 register int i;
3495 char *filename = 0;
3496 int flag_print_mem = 0;
3497 int version_flag = 0;
3498 char *p;
3499
3500 /* save in case md file wants to emit args as a comment. */
3501 save_argc = argc;
3502 save_argv = argv;
3503
3504 p = argv[0] + strlen (argv[0]);
128373ac
RK
3505 while (p != argv[0] && p[-1] != '/'
3506#ifdef DIR_SEPARATOR
3507 && p[-1] != DIR_SEPARATOR
3508#endif
3509 )
3510 --p;
4291d9c8
RS
3511 progname = p;
3512
3513#ifdef RLIMIT_STACK
3514 /* Get rid of any avoidable limit on stack size. */
3515 {
3516 struct rlimit rlim;
3517
0f41302f 3518 /* Set the stack limit huge so that alloca does not fail. */
4291d9c8
RS
3519 getrlimit (RLIMIT_STACK, &rlim);
3520 rlim.rlim_cur = rlim.rlim_max;
3521 setrlimit (RLIMIT_STACK, &rlim);
3522 }
3523#endif /* RLIMIT_STACK */
3524
3525 signal (SIGFPE, float_signal);
3526
935d4b07 3527#ifdef SIGPIPE
4291d9c8 3528 signal (SIGPIPE, pipe_closed);
935d4b07 3529#endif
4291d9c8
RS
3530
3531 decl_printable_name = decl_name;
3532 lang_expand_expr = (struct rtx_def *(*)()) do_abort;
3533
3534 /* Initialize whether `char' is signed. */
3535 flag_signed_char = DEFAULT_SIGNED_CHAR;
3536#ifdef DEFAULT_SHORT_ENUMS
3537 /* Initialize how much space enums occupy, by default. */
3538 flag_short_enums = DEFAULT_SHORT_ENUMS;
3539#endif
3540
3541 /* Scan to see what optimization level has been specified. That will
3542 determine the default value of many flags. */
3543 for (i = 1; i < argc; i++)
3544 {
3545 if (!strcmp (argv[i], "-O"))
3546 {
3547 optimize = 1;
3548 }
3549 else if (argv[i][0] == '-' && argv[i][1] == 'O')
3550 {
3551 /* Handle -O2, -O3, -O69, ... */
3552 char *p = &argv[i][2];
3553 int c;
3554
3555 while (c = *p++)
3556 if (! (c >= '0' && c <= '9'))
3557 break;
3558 if (c == 0)
3559 optimize = atoi (&argv[i][2]);
3560 }
3561 }
3562
3563 obey_regdecls = (optimize == 0);
f246a305
RS
3564 if (optimize == 0)
3565 {
3566 flag_no_inline = 1;
3567 warn_inline = 0;
3568 }
4291d9c8
RS
3569
3570 if (optimize >= 1)
3571 {
6731a3e3 3572 flag_defer_pop = 1;
4291d9c8
RS
3573 flag_thread_jumps = 1;
3574#ifdef DELAY_SLOTS
3575 flag_delayed_branch = 1;
7e89c3a3
RK
3576#endif
3577#ifdef CAN_DEBUG_WITHOUT_FP
3578 flag_omit_frame_pointer = 1;
4291d9c8
RS
3579#endif
3580 }
3581
3582 if (optimize >= 2)
3583 {
3584 flag_cse_follow_jumps = 1;
8b3686ed 3585 flag_cse_skip_blocks = 1;
4291d9c8
RS
3586 flag_expensive_optimizations = 1;
3587 flag_strength_reduce = 1;
3588 flag_rerun_cse_after_loop = 1;
ac266247 3589 flag_caller_saves = 1;
4ac8e06e 3590 flag_force_mem = 1;
4291d9c8
RS
3591#ifdef INSN_SCHEDULING
3592 flag_schedule_insns = 1;
3593 flag_schedule_insns_after_reload = 1;
3594#endif
3595 }
3596
7e89c3a3
RK
3597 if (optimize >= 3)
3598 {
3599 flag_inline_functions = 1;
3600 }
3601
c1da383f
DE
3602 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
3603 modify it. */
3604 target_flags = 0;
3605 set_target_switch ("");
3606
4291d9c8
RS
3607#ifdef OPTIMIZATION_OPTIONS
3608 /* Allow default optimizations to be specified on a per-machine basis. */
3609 OPTIMIZATION_OPTIONS (optimize);
3610#endif
3611
3612 /* Initialize register usage now so switches may override. */
3613 init_reg_sets ();
3614
4291d9c8
RS
3615 for (i = 1; i < argc; i++)
3616 {
b99933c7
RS
3617 int j;
3618 /* If this is a language-specific option,
3619 decode it in a language-specific way. */
3620 for (j = 0; lang_options[j] != 0; j++)
7e6c0864
RK
3621 if (!strncmp (argv[i], lang_options[j],
3622 strlen (lang_options[j])))
b99933c7
RS
3623 break;
3624 if (lang_options[j] != 0)
3625 /* If the option is valid for *some* language,
3626 treat it as valid even if this language doesn't understand it. */
3627 lang_decode_option (argv[i]);
3628 else if (argv[i][0] == '-' && argv[i][1] != 0)
4291d9c8
RS
3629 {
3630 register char *str = argv[i] + 1;
3631 if (str[0] == 'Y')
3632 str++;
3633
3634 if (str[0] == 'm')
3635 set_target_switch (&str[1]);
3636 else if (!strcmp (str, "dumpbase"))
3637 {
3638 dump_base_name = argv[++i];
3639 }
3640 else if (str[0] == 'd')
3641 {
3642 register char *p = &str[1];
3643 while (*p)
3644 switch (*p++)
3645 {
3646 case 'a':
3647 combine_dump = 1;
3648 dbr_sched_dump = 1;
3649 flow_dump = 1;
3650 global_reg_dump = 1;
3651 jump_opt_dump = 1;
3652 jump2_opt_dump = 1;
3653 local_reg_dump = 1;
3654 loop_dump = 1;
3655 rtl_dump = 1;
3656 cse_dump = 1, cse2_dump = 1;
3657 sched_dump = 1;
3658 sched2_dump = 1;
3659 stack_reg_dump = 1;
3660 break;
3661 case 'k':
3662 stack_reg_dump = 1;
3663 break;
3664 case 'c':
3665 combine_dump = 1;
3666 break;
3667 case 'd':
3668 dbr_sched_dump = 1;
3669 break;
3670 case 'f':
3671 flow_dump = 1;
3672 break;
3673 case 'g':
3674 global_reg_dump = 1;
3675 break;
3676 case 'j':
3677 jump_opt_dump = 1;
3678 break;
3679 case 'J':
3680 jump2_opt_dump = 1;
3681 break;
3682 case 'l':
3683 local_reg_dump = 1;
3684 break;
3685 case 'L':
3686 loop_dump = 1;
3687 break;
3688 case 'm':
3689 flag_print_mem = 1;
3690 break;
3691 case 'p':
3692 flag_print_asm_name = 1;
3693 break;
3694 case 'r':
3695 rtl_dump = 1;
3696 break;
3697 case 's':
3698 cse_dump = 1;
3699 break;
3700 case 't':
3701 cse2_dump = 1;
3702 break;
3703 case 'S':
3704 sched_dump = 1;
3705 break;
3706 case 'R':
3707 sched2_dump = 1;
3708 break;
3709 case 'y':
3710 set_yydebug (1);
3711 break;
4291d9c8
RS
3712 case 'x':
3713 rtl_dump_and_exit = 1;
3714 break;
3d5cdd42
DE
3715 case 'A':
3716 flag_debug_asm = 1;
3717 break;
4291d9c8
RS
3718 }
3719 }
3720 else if (str[0] == 'f')
3721 {
4291d9c8
RS
3722 register char *p = &str[1];
3723 int found = 0;
3724
3725 /* Some kind of -f option.
3726 P's value is the option sans `-f'.
3727 Search for it in the table of options. */
3728
3729 for (j = 0;
3730 !found && j < sizeof (f_options) / sizeof (f_options[0]);
3731 j++)
3732 {
3733 if (!strcmp (p, f_options[j].string))
3734 {
3735 *f_options[j].variable = f_options[j].on_value;
3736 /* A goto here would be cleaner,
3737 but breaks the vax pcc. */
3738 found = 1;
3739 }
3740 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3741 && ! strcmp (p+3, f_options[j].string))
3742 {
3743 *f_options[j].variable = ! f_options[j].on_value;
3744 found = 1;
3745 }
3746 }
3747
3748 if (found)
3749 ;
3750 else if (!strncmp (p, "fixed-", 6))
3751 fix_register (&p[6], 1, 1);
3752 else if (!strncmp (p, "call-used-", 10))
3753 fix_register (&p[10], 0, 1);
3754 else if (!strncmp (p, "call-saved-", 11))
3755 fix_register (&p[11], 0, 0);
b99933c7 3756 else
4291d9c8
RS
3757 error ("Invalid option `%s'", argv[i]);
3758 }
3759 else if (str[0] == 'O')
3760 {
3761 register char *p = str+1;
3762 while (*p && *p >= '0' && *p <= '9')
3763 p++;
3764 if (*p == '\0')
3765 ;
3766 else
3767 error ("Invalid option `%s'", argv[i]);
3768 }
3769 else if (!strcmp (str, "pedantic"))
3770 pedantic = 1;
3771 else if (!strcmp (str, "pedantic-errors"))
3772 flag_pedantic_errors = pedantic = 1;
4291d9c8
RS
3773 else if (!strcmp (str, "quiet"))
3774 quiet_flag = 1;
3775 else if (!strcmp (str, "version"))
3776 version_flag = 1;
3777 else if (!strcmp (str, "w"))
3778 inhibit_warnings = 1;
3779 else if (!strcmp (str, "W"))
3780 {
3781 extra_warnings = 1;
fa1a4543
RS
3782 /* We save the value of warn_uninitialized, since if they put
3783 -Wuninitialized on the command line, we need to generate a
3784 warning about not using it without also specifying -O. */
3785 if (warn_uninitialized != 1)
3786 warn_uninitialized = 2;
4291d9c8
RS
3787 }
3788 else if (str[0] == 'W')
3789 {
4291d9c8
RS
3790 register char *p = &str[1];
3791 int found = 0;
3792
3793 /* Some kind of -W option.
3794 P's value is the option sans `-W'.
3795 Search for it in the table of options. */
3796
3797 for (j = 0;
3798 !found && j < sizeof (W_options) / sizeof (W_options[0]);
3799 j++)
3800 {
3801 if (!strcmp (p, W_options[j].string))
3802 {
3803 *W_options[j].variable = W_options[j].on_value;
3804 /* A goto here would be cleaner,
3805 but breaks the vax pcc. */
3806 found = 1;
3807 }
3808 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3809 && ! strcmp (p+3, W_options[j].string))
3810 {
3811 *W_options[j].variable = ! W_options[j].on_value;
3812 found = 1;
3813 }
3814 }
3815
3816 if (found)
3817 ;
3818 else if (!strncmp (p, "id-clash-", 9))
3819 {
3820 char *endp = p + 9;
3821
3822 while (*endp)
3823 {
3824 if (*endp >= '0' && *endp <= '9')
3825 endp++;
3826 else
7085b873
RS
3827 {
3828 error ("Invalid option `%s'", argv[i]);
3829 goto id_clash_lose;
3830 }
4291d9c8
RS
3831 }
3832 warn_id_clash = 1;
3833 id_clash_len = atoi (str + 10);
7085b873 3834 id_clash_lose: ;
4291d9c8 3835 }
b51e9c62
RK
3836 else if (!strncmp (p, "larger-than-", 12))
3837 {
3838 char *endp = p + 12;
3839
3840 while (*endp)
3841 {
3842 if (*endp >= '0' && *endp <= '9')
3843 endp++;
3844 else
3845 {
3846 error ("Invalid option `%s'", argv[i]);
3847 goto larger_than_lose;
3848 }
3849 }
3850 warn_larger_than = 1;
3851 larger_than_size = atoi (str + 13);
3852 larger_than_lose: ;
3853 }
4291d9c8
RS
3854 else
3855 error ("Invalid option `%s'", argv[i]);
3856 }
3857 else if (!strcmp (str, "p"))
ca695ac9 3858 {
c2d12c8b 3859 profile_flag = 1;
ca695ac9 3860 }
4291d9c8
RS
3861 else if (!strcmp (str, "a"))
3862 {
3863#if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
3864 warning ("`-a' option (basic block profile) not supported");
3865#else
ec6c615d
RK
3866 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
3867#endif
3868 }
3869 else if (!strcmp (str, "ax"))
3870 {
3871#if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
3872 warning ("`-ax' option (jump profiling) not supported");
3873#else
3874 profile_block_flag = (!profile_block_flag
3875 || profile_block_flag == 2) ? 2 : 3;
4291d9c8
RS
3876#endif
3877 }
3878 else if (str[0] == 'g')
3879 {
4291d9c8
RS
3880 unsigned len;
3881 unsigned level;
ff482cef
DE
3882 /* A lot of code assumes write_symbols == NO_DEBUG if the
3883 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
3884 of what debugging type has been selected). This records the
3885 selected type. It is an error to specify more than one
3886 debugging type. */
3887 static enum debug_info_type selected_debug_type = NO_DEBUG;
3888 /* Non-zero if debugging format has been explicitly set.
3889 -g and -ggdb don't explicitly set the debugging format so
3890 -gdwarf -g3 is equivalent to -gdwarf3. */
3891 static int type_explicitly_set_p = 0;
3892 /* Table of supported debugging formats. */
3893 static struct {
3894 char *arg;
3895 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
3896 constant expression, we use NO_DEBUG in its place. */
3897 enum debug_info_type debug_type;
3898 int use_extensions_p;
3899 } *da, debug_args[] = {
3900 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS },
3901 { "ggdb", NO_DEBUG, 1 },
3902#ifdef DBX_DEBUGGING_INFO
3903 { "gstabs", DBX_DEBUG, 0 },
3904 { "gstabs+", DBX_DEBUG, 1 },
3905#endif
3906#ifdef DWARF_DEBUGGING_INFO
9a666dda
JM
3907 { "gdwarf-1", DWARF_DEBUG, 0 },
3908 { "gdwarf-1+", DWARF_DEBUG, 1 },
3909#endif
3910#ifdef DWARF2_DEBUGGING_INFO
3911 { "gdwarf-2", DWARF2_DEBUG, 0 },
3912#endif
3913#if defined (DWARF_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
3914#if PREFERRED_DEBUGGING_TYPE == DWARF_DEBUG || !defined (DWARF2_DEBUGGING_INFO)
ff482cef
DE
3915 { "gdwarf", DWARF_DEBUG, 0 },
3916 { "gdwarf+", DWARF_DEBUG, 1 },
9a666dda
JM
3917#else
3918 { "gdwarf", DWARF2_DEBUG, 0 },
3919#endif
ff482cef
DE
3920#endif
3921#ifdef XCOFF_DEBUGGING_INFO
3922 { "gxcoff", XCOFF_DEBUG, 0 },
3923 { "gxcoff+", XCOFF_DEBUG, 1 },
3924#endif
3925#ifdef SDB_DEBUGGING_INFO
3926 { "gcoff", SDB_DEBUG, 0 },
3927#endif
3928 { 0, 0, 0 }
3929 };
3930 /* Indexed by enum debug_info_type. */
3931 static char *debug_type_names[] = {
9a666dda 3932 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
ff482cef 3933 };
4291d9c8 3934
ff482cef
DE
3935 /* Look up STR in the table. */
3936 for (da = debug_args; da->arg; da++)
3937 {
9a666dda 3938 if (! strncmp (str, da->arg, strlen (da->arg)))
ff482cef
DE
3939 {
3940 enum debug_info_type type = da->debug_type;
9a666dda
JM
3941 char *p, *q;
3942
3943 p = str + strlen (da->arg);
3944 if (*p && (*p < '0' || *p > '9'))
3945 continue;
3946 q = p;
3947 while (*q && (*q >= '0' && *q <= '9'))
3948 q++;
3949 if (*p)
3950 level = atoi (p);
3951 else
3952 level = 2; /* default debugging info level */
3953 if (*q || level > 3)
3954 {
3955 warning ("invalid debug level specification in option: `-%s'",
3956 str);
3957 /* ??? This error message is incorrect in the case of
3958 -g4 -g. */
3959 warning ("no debugging information will be generated");
3960 level = 0;
3961 }
3962
3963 /* ??? A few targets use STR in the
ff482cef
DE
3964 definition of PREFERRED_DEBUGGING_TYPE! */
3965 if (type == NO_DEBUG)
3966 type = PREFERRED_DEBUGGING_TYPE;
3967
3968 /* Does it conflict with an already selected type? */
3969 if (type_explicitly_set_p
3970 /* -g/-ggdb don't conflict with anything */
3971 && da->debug_type != NO_DEBUG
3972 && type != selected_debug_type)
3973 warning ("`-%s' ignored, conflicts with `-g%s'",
3974 str, debug_type_names[(int) selected_debug_type]);
3975 else
3976 {
3977 /* If the format has already been set, -g/-ggdb
3978 only change the debug level. */
3979 if (type_explicitly_set_p
3980 && da->debug_type == NO_DEBUG)
3981 ; /* don't change debugging type */
3982 else
3983 {
3984 selected_debug_type = type;
3985 type_explicitly_set_p = da->debug_type != NO_DEBUG;
3986 }
3987 write_symbols = (level == 0
3988 ? NO_DEBUG
3989 : selected_debug_type);
3990 use_gnu_debug_info_extensions = da->use_extensions_p;
3991 debug_info_level = (enum debug_info_level) level;
3992 }
3993 break;
3994 }
3995 }
3996 if (! da->arg)
7276e85d
RK
3997 warning ("`-%s' not supported by this configuration of GCC",
3998 str);
4291d9c8
RS
3999 }
4000 else if (!strcmp (str, "o"))
4001 {
4002 asm_file_name = argv[++i];
4003 }
4004 else if (str[0] == 'G')
4005 {
4006 g_switch_set = TRUE;
4007 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
4008 }
f246a305
RS
4009 else if (!strncmp (str, "aux-info", 8))
4010 {
4011 flag_gen_aux_info = 1;
4012 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
4013 }
4291d9c8
RS
4014 else
4015 error ("Invalid option `%s'", argv[i]);
4016 }
4017 else if (argv[i][0] == '+')
b99933c7 4018 error ("Invalid option `%s'", argv[i]);
4291d9c8
RS
4019 else
4020 filename = argv[i];
4021 }
4022
ca695ac9 4023 /* Initialize for bytecode output. A good idea to do this as soon as
0f41302f 4024 possible after the "-f" options have been parsed. */
ca695ac9
JB
4025 if (output_bytecode)
4026 {
4027#ifndef TARGET_SUPPORTS_BYTECODE
4028 /* Just die with a fatal error if not supported */
40e6003c 4029 fatal ("-fbytecode not supported for this target");
ca695ac9
JB
4030#else
4031 bc_initialize ();
4032#endif
4033 }
4034
f246a305
RS
4035 if (optimize == 0)
4036 {
a2468e45
BK
4037 /* Inlining does not work if not optimizing,
4038 so force it not to be done. */
f246a305
RS
4039 flag_no_inline = 1;
4040 warn_inline = 0;
a2468e45
BK
4041
4042 /* The c_decode_option and lang_decode_option functions set
4043 this to `2' if -Wall is used, so we can avoid giving out
4044 lots of errors for people who don't realize what -Wall does. */
4045 if (warn_uninitialized == 1)
4046 warning ("-Wuninitialized is not supported without -O");
f246a305
RS
4047 }
4048
4291d9c8
RS
4049#ifdef OVERRIDE_OPTIONS
4050 /* Some machines may reject certain combinations of options. */
4051 OVERRIDE_OPTIONS;
4052#endif
4053
ec6c615d
RK
4054 if (profile_block_flag == 3)
4055 {
4056 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4057 profile_block_flag = 2;
4058 }
4059
4291d9c8
RS
4060 /* Unrolling all loops implies that standard loop unrolling must also
4061 be done. */
4062 if (flag_unroll_all_loops)
4063 flag_unroll_loops = 1;
4064 /* Loop unrolling requires that strength_reduction be on also. Silently
4065 turn on strength reduction here if it isn't already on. Also, the loop
4066 unrolling code assumes that cse will be run after loop, so that must
4067 be turned on also. */
4068 if (flag_unroll_loops)
4069 {
4070 flag_strength_reduce = 1;
4071 flag_rerun_cse_after_loop = 1;
4072 }
4073
4074 /* Warn about options that are not supported on this machine. */
4075#ifndef INSN_SCHEDULING
4076 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4077 warning ("instruction scheduling not supported on this target machine");
4078#endif
4079#ifndef DELAY_SLOTS
4080 if (flag_delayed_branch)
4081 warning ("this target machine does not have delayed branches");
4082#endif
4083
4084 /* If we are in verbose mode, write out the version and maybe all the
4085 option flags in use. */
4086 if (version_flag)
4087 {
3d5cdd42 4088 print_version (stderr, "");
4291d9c8 4089 if (! quiet_flag)
3d5cdd42 4090 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4291d9c8
RS
4091 }
4092
4291d9c8
RS
4093 compile_file (filename);
4094
876ac40d 4095#if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN32__))
4291d9c8
RS
4096 if (flag_print_mem)
4097 {
4098 char *lim = (char *) sbrk (0);
4099
4100 fprintf (stderr, "Data size %d.\n",
b61b1c91 4101 lim - (char *) &environ);
4291d9c8
RS
4102 fflush (stderr);
4103
4104#ifdef USG
4105 system ("ps -l 1>&2");
4106#else /* not USG */
4107 system ("ps v");
4108#endif /* not USG */
4109 }
876ac40d 4110#endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN32) */
4291d9c8
RS
4111
4112 if (errorcount)
4113 exit (FATAL_EXIT_CODE);
4114 if (sorrycount)
4115 exit (FATAL_EXIT_CODE);
4116 exit (SUCCESS_EXIT_CODE);
299846f2 4117 return 0;
4291d9c8
RS
4118}
4119\f
4120/* Decode -m switches. */
4121
4122/* Here is a table, controlled by the tm.h file, listing each -m switch
4123 and which bits in `target_switches' it should set or clear.
4124 If VALUE is positive, it is bits to set.
4125 If VALUE is negative, -VALUE is bits to clear.
4126 (The sign bit is not used so there is no confusion.) */
4127
4128struct {char *name; int value;} target_switches []
4129 = TARGET_SWITCHES;
4130
4131/* This table is similar, but allows the switch to have a value. */
4132
4133#ifdef TARGET_OPTIONS
4134struct {char *prefix; char ** variable;} target_options []
4135 = TARGET_OPTIONS;
4136#endif
4137
4138/* Decode the switch -mNAME. */
4139
4140void
4141set_target_switch (name)
4142 char *name;
4143{
4144 register int j;
4145 int valid = 0;
4146
4147 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4148 if (!strcmp (target_switches[j].name, name))
4149 {
4150 if (target_switches[j].value < 0)
4151 target_flags &= ~-target_switches[j].value;
4152 else
4153 target_flags |= target_switches[j].value;
4154 valid = 1;
4155 }
4156
4157#ifdef TARGET_OPTIONS
4158 if (!valid)
4159 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4160 {
4161 int len = strlen (target_options[j].prefix);
4162 if (!strncmp (target_options[j].prefix, name, len))
4163 {
4164 *target_options[j].variable = name + len;
4165 valid = 1;
4166 }
4167 }
4168#endif
4169
4170 if (!valid)
4171 error ("Invalid option `%s'", name);
4172}
4173\f
3d5cdd42
DE
4174/* Print version information to FILE.
4175 Each line begins with INDENT (for the case where FILE is the
4176 assembler output file). */
4291d9c8 4177
3d5cdd42
DE
4178void
4179print_version (file, indent)
4180 FILE *file;
4181 char *indent;
4291d9c8 4182{
3d5cdd42
DE
4183 fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4184 language_string, version_string);
4185 fprintf (file, " (%s)", TARGET_NAME);
4186#ifdef __GNUC__
4187#ifndef __VERSION__
4188#define __VERSION__ "[unknown]"
4189#endif
4190 fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4191#else
4192 fprintf (file, " compiled by CC.\n");
4193#endif
4194}
4291d9c8 4195
3d5cdd42 4196/* Print an option value and return the adjusted position in the line.
309a8875
DE
4197 ??? We don't handle error returns from fprintf (disk full); presumably
4198 other code will catch a disk full though. */
4291d9c8 4199
3d5cdd42
DE
4200int
4201print_single_switch (file, pos, max, indent, sep, term, type, name)
4202 FILE *file;
4203 int pos, max;
4204 char *indent, *sep, *term, *type, *name;
4205{
309a8875
DE
4206 /* The ultrix fprintf returns 0 on success, so compute the result we want
4207 here since we need it for the following test. */
4208 int len = strlen (sep) + strlen (type) + strlen (name);
4209
3d5cdd42 4210 if (pos != 0
309a8875 4211 && pos + len > max)
4291d9c8 4212 {
3d5cdd42
DE
4213 fprintf (file, "%s", term);
4214 pos = 0;
4291d9c8 4215 }
3d5cdd42
DE
4216 if (pos == 0)
4217 {
309a8875
DE
4218 fprintf (file, "%s", indent);
4219 pos = strlen (indent);
3d5cdd42 4220 }
309a8875
DE
4221 fprintf (file, "%s%s%s", sep, type, name);
4222 pos += len;
3d5cdd42 4223 return pos;
4291d9c8
RS
4224}
4225
3d5cdd42
DE
4226/* Print active target switches to FILE.
4227 POS is the current cursor position and MAX is the size of a "line".
4228 Each line begins with INDENT and ends with TERM.
4229 Each switch is separated from the next by SEP. */
4291d9c8 4230
3d5cdd42
DE
4231void
4232print_switch_values (file, pos, max, indent, sep, term)
4233 FILE *file;
4234 int pos, max;
4235 char *indent, *sep, *term;
4291d9c8 4236{
3d5cdd42
DE
4237 int j, flags;
4238 char **p;
4239
4240 /* Print the options as passed. */
4291d9c8 4241
3d5cdd42
DE
4242 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4243 "options passed: ", "");
4244
520e7ff5 4245 for (p = &save_argv[1]; *p != NULL; p++)
3d5cdd42
DE
4246 if (**p == '-')
4247 {
4248 /* Ignore these. */
520e7ff5
DE
4249 if (strcmp (*p, "-o") == 0)
4250 {
4251 if (p[1] != NULL)
4252 p++;
4253 continue;
4254 }
3d5cdd42
DE
4255 if (strcmp (*p, "-quiet") == 0)
4256 continue;
4257 if (strcmp (*p, "-version") == 0)
4258 continue;
4259 if ((*p)[1] == 'd')
4260 continue;
4261
4262 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4263 }
4264 if (pos > 0)
4265 fprintf (file, "%s", term);
4266
4267 /* Print the -f and -m options that have been enabled.
4268 We don't handle language specific options but printing argv
4269 should suffice. */
4270
4271 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4272 "options enabled: ", "");
4291d9c8
RS
4273
4274 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
4275 if (*f_options[j].variable == f_options[j].on_value)
3d5cdd42
DE
4276 pos = print_single_switch (file, pos, max, indent, sep, term,
4277 "-f", f_options[j].string);
4291d9c8 4278
3d5cdd42 4279 /* Print target specific options. */
4291d9c8 4280
3d5cdd42 4281 flags = target_flags;
4291d9c8
RS
4282 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4283 if (target_switches[j].name[0] != '\0'
4284 && target_switches[j].value > 0
4285 && ((target_switches[j].value & target_flags)
4286 == target_switches[j].value))
3d5cdd42
DE
4287 {
4288 pos = print_single_switch (file, pos, max, indent, sep, term,
4289 "-m", target_switches[j].name);
4290 flags &= ~ target_switches[j].value;
4291 }
4292
4293#ifdef TARGET_OPTIONS
4294 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4295 if (*target_options[j].variable != NULL)
4296 {
4297 char prefix[256];
4298 sprintf (prefix, "-m%s", target_options[j].prefix);
4299 pos = print_single_switch (file, pos, max, indent, sep, term,
4300 prefix, *target_options[j].variable);
4301 }
4302#endif
4291d9c8 4303
3d5cdd42 4304 fprintf (file, "%s", term);
4291d9c8 4305}
9a666dda
JM
4306
4307/* Record the beginning of a new source file, named FILENAME. */
4308
4309void
4310debug_start_source_file (filename)
4311 register char *filename;
4312{
4313#ifdef DBX_DEBUGGING_INFO
4314 if (write_symbols == DBX_DEBUG)
4315 dbxout_start_new_source_file (filename);
4316#endif
4317#ifdef DWARF_DEBUGGING_INFO
4318 if (debug_info_level == DINFO_LEVEL_VERBOSE
4319 && write_symbols == DWARF_DEBUG)
4320 dwarfout_start_new_source_file (filename);
4321#endif /* DWARF_DEBUGGING_INFO */
4322#ifdef DWARF2_DEBUGGING_INFO
4323 if (debug_info_level == DINFO_LEVEL_VERBOSE
4324 && write_symbols == DWARF2_DEBUG)
4325 dwarf2out_start_source_file (filename);
4326#endif /* DWARF2_DEBUGGING_INFO */
cc694a81
DE
4327#ifdef SDB_DEBUGGING_INFO
4328 if (write_symbols == SDB_DEBUG)
4329 sdbout_start_new_source_file (filename);
4330#endif
9a666dda
JM
4331}
4332
4333/* Record the resumption of a source file. LINENO is the line number in
4334 the source file we are returning to. */
4335
4336void
4337debug_end_source_file (lineno)
4338 register unsigned lineno;
4339{
4340#ifdef DBX_DEBUGGING_INFO
4341 if (write_symbols == DBX_DEBUG)
4342 dbxout_resume_previous_source_file ();
4343#endif
4344#ifdef DWARF_DEBUGGING_INFO
4345 if (debug_info_level == DINFO_LEVEL_VERBOSE
4346 && write_symbols == DWARF_DEBUG)
4347 dwarfout_resume_previous_source_file (lineno);
4348#endif /* DWARF_DEBUGGING_INFO */
4349#ifdef DWARF2_DEBUGGING_INFO
4350 if (debug_info_level == DINFO_LEVEL_VERBOSE
4351 && write_symbols == DWARF2_DEBUG)
4352 dwarf2out_end_source_file ();
4353#endif /* DWARF2_DEBUGGING_INFO */
cc694a81
DE
4354#ifdef SDB_DEBUGGING_INFO
4355 if (write_symbols == SDB_DEBUG)
4356 sdbout_resume_previous_source_file ();
4357#endif
9a666dda
JM
4358}
4359
4360/* Called from check_newline in c-parse.y. The `buffer' parameter contains
4361 the tail part of the directive line, i.e. the part which is past the
4362 initial whitespace, #, whitespace, directive-name, whitespace part. */
4363
4364void
4365debug_define (lineno, buffer)
4366 register unsigned lineno;
4367 register char *buffer;
4368{
4369#ifdef DWARF_DEBUGGING_INFO
4370 if (debug_info_level == DINFO_LEVEL_VERBOSE
4371 && write_symbols == DWARF_DEBUG)
4372 dwarfout_define (lineno, buffer);
4373#endif /* DWARF_DEBUGGING_INFO */
4374#ifdef DWARF2_DEBUGGING_INFO
4375 if (debug_info_level == DINFO_LEVEL_VERBOSE
4376 && write_symbols == DWARF2_DEBUG)
4377 dwarf2out_define (lineno, buffer);
4378#endif /* DWARF2_DEBUGGING_INFO */
4379}
4380
4381/* Called from check_newline in c-parse.y. The `buffer' parameter contains
4382 the tail part of the directive line, i.e. the part which is past the
4383 initial whitespace, #, whitespace, directive-name, whitespace part. */
4384
4385void
4386debug_undef (lineno, buffer)
4387 register unsigned lineno;
4388 register char *buffer;
4389{
4390#ifdef DWARF_DEBUGGING_INFO
4391 if (debug_info_level == DINFO_LEVEL_VERBOSE
4392 && write_symbols == DWARF_DEBUG)
4393 dwarfout_undef (lineno, buffer);
4394#endif /* DWARF_DEBUGGING_INFO */
4395#ifdef DWARF2_DEBUGGING_INFO
4396 if (debug_info_level == DINFO_LEVEL_VERBOSE
4397 && write_symbols == DWARF2_DEBUG)
4398 dwarf2out_undef (lineno, buffer);
4399#endif /* DWARF2_DEBUGGING_INFO */
4400}
This page took 1.072773 seconds and 5 git commands to generate.