]> gcc.gnu.org Git - gcc.git/blame - gcc/toplev.c
(lang_options): Add -fhosted, -ffreestanding, and -Wmain.
[gcc.git] / gcc / toplev.c
CommitLineData
4291d9c8 1/* Top level of GNU C compiler
5ae3bec5 2 Copyright (C) 1987, 88, 89, 92-6, 1997 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",
5ae3bec5
RK
665 "-fhosted",
666 "-fno-hosted",
667 "-ffreestanding",
668 "-fno-freestanding",
4200c8de
RK
669 "-fcond-mismatch",
670 "-fno-cond-mismatch",
c7daad38 671 "-fdollars-in-identifiers",
57f0a224 672 "-fno-dollars-in-identifiers",
4200c8de
RK
673 "-fident",
674 "-fno-ident",
675 "-fshort-double",
676 "-fno-short-double",
677 "-fshort-enums",
678 "-fno-short-enums",
679
680 "-Wall",
289871f0
RK
681 "-Wbad-function-cast",
682 "-Wno-bad-function-cast",
b99933c7
RS
683 "-Wcast-qual",
684 "-Wno-cast-qual",
b99933c7
RS
685 "-Wchar-subscripts",
686 "-Wno-char-subscripts",
b99933c7
RS
687 "-Wcomment",
688 "-Wno-comment",
689 "-Wcomments",
690 "-Wno-comments",
4200c8de
RK
691 "-Wconversion",
692 "-Wno-conversion",
693 "-Wformat",
694 "-Wno-format",
b99933c7
RS
695 "-Wimport",
696 "-Wno-import",
4200c8de
RK
697 "-Wimplicit",
698 "-Wno-implicit",
5ae3bec5
RK
699 "-Wmain",
700 "-Wno-main",
f41372d4
RS
701 "-Wmissing-braces",
702 "-Wno-missing-braces",
4200c8de
RK
703 "-Wmissing-declarations",
704 "-Wno-missing-declarations",
705 "-Wmissing-prototypes",
706 "-Wno-missing-prototypes",
707 "-Wnested-externs",
708 "-Wno-nested-externs",
709 "-Wparentheses",
710 "-Wno-parentheses",
711 "-Wpointer-arith",
712 "-Wno-pointer-arith",
713 "-Wredundant-decls",
714 "-Wno-redundant-decls",
d51f9363
JM
715 "-Wsign-compare",
716 "-Wno-sign-compare",
4200c8de
RK
717 "-Wstrict-prototypes",
718 "-Wno-strict-prototypes",
719 "-Wtraditional",
720 "-Wno-traditional",
721 "-Wtrigraphs",
722 "-Wno-trigraphs",
723 "-Wwrite-strings",
724 "-Wno-write-strings",
b99933c7 725
65faa6a4
RS
726 /* these are for obj c */
727 "-lang-objc",
728 "-gen-decls",
f5309ddf
TW
729 "-fgnu-runtime",
730 "-fno-gnu-runtime",
731 "-fnext-runtime",
732 "-fno-next-runtime",
65faa6a4
RS
733 "-Wselector",
734 "-Wno-selector",
b800a01b
KKT
735 "-Wprotocol",
736 "-Wno-protocol",
a457294f 737
2a95de17 738#include "options.h"
b99933c7
RS
739 0
740};
4291d9c8
RS
741\f
742/* Options controlling warnings */
743
744/* Don't print warning messages. -w. */
745
746int inhibit_warnings = 0;
747
748/* Print various extra warnings. -W. */
749
750int extra_warnings = 0;
751
752/* Treat warnings as errors. -Werror. */
753
754int warnings_are_errors = 0;
755
756/* Nonzero to warn about unused local variables. */
757
758int warn_unused;
759
760/* Nonzero to warn about variables used before they are initialized. */
761
762int warn_uninitialized;
763
764/* Nonzero means warn about all declarations which shadow others. */
765
766int warn_shadow;
767
768/* Warn if a switch on an enum fails to have a case for every enum value. */
769
770int warn_switch;
771
772/* Nonzero means warn about function definitions that default the return type
773 or that use a null return and have a return-type other than void. */
774
775int warn_return_type;
776
777/* Nonzero means warn about pointer casts that increase the required
778 alignment of the target type (and might therefore lead to a crash
779 due to a misaligned access). */
780
781int warn_cast_align;
782
783/* Nonzero means warn about any identifiers that match in the first N
784 characters. The value N is in `id_clash_len'. */
785
786int warn_id_clash;
b51e9c62
RK
787unsigned id_clash_len;
788
789/* Nonzero means warn about any objects definitions whose size is larger
790 than N bytes. Also want about function definitions whose returned
791 values are larger than N bytes. The value N is in `larger_than_size'. */
792
793int warn_larger_than;
794unsigned larger_than_size;
4291d9c8
RS
795
796/* Nonzero means warn if inline function is too large. */
797
798int warn_inline;
799
800/* Warn if a function returns an aggregate,
801 since there are often incompatible calling conventions for doing this. */
802
803int warn_aggregate_return;
804
805/* Likewise for -W. */
806
807struct { char *string; int *variable; int on_value;} W_options[] =
808{
809 {"unused", &warn_unused, 1},
810 {"error", &warnings_are_errors, 1},
811 {"shadow", &warn_shadow, 1},
812 {"switch", &warn_switch, 1},
4291d9c8
RS
813 {"aggregate-return", &warn_aggregate_return, 1},
814 {"cast-align", &warn_cast_align, 1},
f246a305
RS
815 {"uninitialized", &warn_uninitialized, 1},
816 {"inline", &warn_inline, 1}
4291d9c8
RS
817};
818\f
819/* Output files for assembler code (real compiler output)
820 and debugging dumps. */
821
822FILE *asm_out_file;
823FILE *aux_info_file;
824FILE *rtl_dump_file;
825FILE *jump_opt_dump_file;
826FILE *cse_dump_file;
827FILE *loop_dump_file;
828FILE *cse2_dump_file;
829FILE *flow_dump_file;
830FILE *combine_dump_file;
831FILE *sched_dump_file;
832FILE *local_reg_dump_file;
833FILE *global_reg_dump_file;
834FILE *sched2_dump_file;
835FILE *jump2_opt_dump_file;
836FILE *dbr_sched_dump_file;
837FILE *stack_reg_dump_file;
838
839/* Time accumulators, to count the total time spent in various passes. */
840
841int parse_time;
842int varconst_time;
843int integration_time;
844int jump_time;
845int cse_time;
846int loop_time;
847int cse2_time;
848int flow_time;
849int combine_time;
850int sched_time;
851int local_alloc_time;
852int global_alloc_time;
853int sched2_time;
854int dbr_sched_time;
855int shorten_branch_time;
856int stack_reg_time;
857int final_time;
858int symout_time;
859int dump_time;
860\f
861/* Return time used so far, in microseconds. */
862
863int
864get_run_time ()
865{
9580b583 866#ifndef _WIN32
4291d9c8
RS
867#ifdef USG
868 struct tms tms;
869#else
870#ifndef VMS
871 struct rusage rusage;
15f00097 872#else
4291d9c8
RS
873 struct
874 {
875 int proc_user_time;
876 int proc_system_time;
877 int child_user_time;
878 int child_system_time;
879 } vms_times;
880#endif
15f00097 881#endif
4291d9c8
RS
882#endif
883
884 if (quiet_flag)
885 return 0;
9580b583 886#ifdef _WIN32
15f00097
RK
887 if (clock() < 0)
888 return 0;
889 else
890 return (clock() * 1000);
9580b583 891#else /* not _WIN32 */
4291d9c8
RS
892#ifdef USG
893 times (&tms);
894 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
895#else
896#ifndef VMS
897 getrusage (0, &rusage);
898 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
899 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
900#else /* VMS */
901 times (&vms_times);
902 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
903#endif
904#endif
eb910b5a 905#endif
4291d9c8
RS
906}
907
908#define TIMEVAR(VAR, BODY) \
909do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
910
911void
912print_time (str, total)
913 char *str;
914 int total;
915{
916 fprintf (stderr,
917 "time in %s: %d.%06d\n",
918 str, total / 1000000, total % 1000000);
919}
920
921/* Count an error or warning. Return 1 if the message should be printed. */
922
923int
924count_error (warningp)
925 int warningp;
926{
927 if (warningp && inhibit_warnings)
928 return 0;
929
930 if (warningp && !warnings_are_errors)
931 warningcount++;
932 else
933 {
934 static int warning_message = 0;
935
936 if (warningp && !warning_message)
937 {
938 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
939 warning_message = 1;
940 }
941 errorcount++;
942 }
943
944 return 1;
945}
946
947/* Print a fatal error message. NAME is the text.
948 Also include a system error message based on `errno'. */
949
950void
951pfatal_with_name (name)
952 char *name;
953{
954 fprintf (stderr, "%s: ", progname);
955 perror (name);
299846f2 956 exit (FATAL_EXIT_CODE);
4291d9c8
RS
957}
958
959void
960fatal_io_error (name)
961 char *name;
962{
963 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
299846f2 964 exit (FATAL_EXIT_CODE);
4291d9c8
RS
965}
966
a89b2cc4
MM
967/* Called to give a better error message for a bad insn rather than
968 just calling abort(). */
4291d9c8
RS
969
970void
a89b2cc4
MM
971fatal_insn (message, insn)
972 char *message;
4291d9c8
RS
973 rtx insn;
974{
ca695ac9
JB
975 if (!output_bytecode)
976 {
a89b2cc4 977 error (message);
ca695ac9
JB
978 debug_rtx (insn);
979 }
4291d9c8
RS
980 if (asm_out_file)
981 fflush (asm_out_file);
982 if (aux_info_file)
983 fflush (aux_info_file);
984 if (rtl_dump_file)
985 fflush (rtl_dump_file);
986 if (jump_opt_dump_file)
987 fflush (jump_opt_dump_file);
988 if (cse_dump_file)
989 fflush (cse_dump_file);
990 if (loop_dump_file)
991 fflush (loop_dump_file);
992 if (cse2_dump_file)
993 fflush (cse2_dump_file);
994 if (flow_dump_file)
995 fflush (flow_dump_file);
996 if (combine_dump_file)
997 fflush (combine_dump_file);
998 if (sched_dump_file)
999 fflush (sched_dump_file);
1000 if (local_reg_dump_file)
1001 fflush (local_reg_dump_file);
1002 if (global_reg_dump_file)
1003 fflush (global_reg_dump_file);
1004 if (sched2_dump_file)
1005 fflush (sched2_dump_file);
1006 if (jump2_opt_dump_file)
1007 fflush (jump2_opt_dump_file);
1008 if (dbr_sched_dump_file)
1009 fflush (dbr_sched_dump_file);
1010 if (stack_reg_dump_file)
1011 fflush (stack_reg_dump_file);
1902f7fd
MM
1012 fflush (stdout);
1013 fflush (stderr);
4291d9c8
RS
1014 abort ();
1015}
1016
a89b2cc4
MM
1017/* Called to give a better error message when we don't have an insn to match
1018 what we are looking for or if the insn's constraints aren't satisfied,
1019 rather than just calling abort(). */
1020
1021void
1022fatal_insn_not_found (insn)
1023 rtx insn;
1024{
1025 if (INSN_CODE (insn) < 0)
1026 fatal_insn ("internal error--unrecognizable insn:", insn);
1027 else
1028 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1029}
1030
4291d9c8
RS
1031/* This is the default decl_printable_name function. */
1032
1033static char *
1034decl_name (decl, kind)
1035 tree decl;
1036 char **kind;
1037{
1038 return IDENTIFIER_POINTER (DECL_NAME (decl));
1039}
1040\f
1041static int need_error_newline;
1042
1043/* Function of last error message;
1044 more generally, function such that if next error message is in it
1045 then we don't have to mention the function name. */
1046static tree last_error_function = NULL;
1047
1048/* Used to detect when input_file_stack has changed since last described. */
1049static int last_error_tick;
1050
1051/* Called when the start of a function definition is parsed,
1052 this function prints on stderr the name of the function. */
1053
1054void
1055announce_function (decl)
1056 tree decl;
1057{
1058 if (! quiet_flag)
1059 {
1060 char *junk;
1061 if (rtl_dump_and_exit)
1062 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1063 else
1064 fprintf (stderr, " %s", (*decl_printable_name) (decl, &junk));
1065 fflush (stderr);
1066 need_error_newline = 1;
1067 last_error_function = current_function_decl;
1068 }
1069}
1070
b64e9948
PB
1071/* The default function to print out name of current function that caused
1072 an error. */
4291d9c8
RS
1073
1074void
b64e9948 1075default_print_error_function (file)
4291d9c8
RS
1076 char *file;
1077{
4291d9c8
RS
1078 if (last_error_function != current_function_decl)
1079 {
1080 char *kind = "function";
1081 if (current_function_decl != 0
1082 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1083 kind = "method";
1084
1085 if (file)
1086 fprintf (stderr, "%s: ", file);
1087
1088 if (current_function_decl == NULL)
1089 fprintf (stderr, "At top level:\n");
1090 else
1091 {
1092 char *name = (*decl_printable_name) (current_function_decl, &kind);
1093 fprintf (stderr, "In %s `%s':\n", kind, name);
1094 }
1095
1096 last_error_function = current_function_decl;
1097 }
b64e9948
PB
1098}
1099
1100/* Called by report_error_function to print out function name.
0f41302f 1101 * Default may be overridden by language front-ends. */
b64e9948 1102
0f41302f 1103void (*print_error_function) PROTO((char *)) = default_print_error_function;
b64e9948
PB
1104
1105/* Prints out, if necessary, the name of the current function
1106 that caused an error. Called from all error and warning functions. */
1107
1108void
1109report_error_function (file)
1110 char *file;
1111{
1112 struct file_stack *p;
1113
1114 if (need_error_newline)
1115 {
1116 fprintf (stderr, "\n");
1117 need_error_newline = 0;
1118 }
1119
1120 (*print_error_function) (file);
1121
4291d9c8 1122 if (input_file_stack && input_file_stack->next != 0
2efc92ed
RK
1123 && input_file_stack_tick != last_error_tick
1124 && file == input_filename)
4291d9c8
RS
1125 {
1126 fprintf (stderr, "In file included");
1127 for (p = input_file_stack->next; p; p = p->next)
1128 {
1129 fprintf (stderr, " from %s:%d", p->name, p->line);
1130 if (p->next)
e5301904 1131 fprintf (stderr, ",\n ");
4291d9c8
RS
1132 }
1133 fprintf (stderr, ":\n");
1134 last_error_tick = input_file_stack_tick;
1135 }
1136}
eb711c86
RK
1137\f
1138/* Print a message. */
4291d9c8 1139
eb711c86
RK
1140static void
1141vmessage (prefix, s, ap)
1142 char *prefix;
4291d9c8 1143 char *s;
eb711c86 1144 va_list ap;
4291d9c8 1145{
eb711c86
RK
1146 if (prefix)
1147 fprintf (stderr, "%s: ", prefix);
1148
1149#ifdef HAVE_VPRINTF
1150 vfprintf (stderr, s, ap);
1151#else
1152 {
1153 HOST_WIDE_INT v1 = va_arg(ap, HOST_WIDE_INT);
1154 HOST_WIDE_INT v2 = va_arg(ap, HOST_WIDE_INT);
1155 HOST_WIDE_INT v3 = va_arg(ap, HOST_WIDE_INT);
a4326b4d
RK
1156 HOST_WIDE_INT v4 = va_arg(ap, HOST_WIDE_INT);
1157 fprintf (stderr, s, v1, v2, v3, v4);
eb711c86
RK
1158 }
1159#endif
4291d9c8
RS
1160}
1161
eb711c86 1162/* Print a message relevant to line LINE of file FILE. */
4291d9c8 1163
eb711c86
RK
1164static void
1165v_message_with_file_and_line (file, line, prefix, s, ap)
4291d9c8
RS
1166 char *file;
1167 int line;
eb711c86 1168 char *prefix;
4291d9c8 1169 char *s;
eb711c86 1170 va_list ap;
4291d9c8 1171{
4291d9c8
RS
1172 if (file)
1173 fprintf (stderr, "%s:%d: ", file, line);
1174 else
1175 fprintf (stderr, "%s: ", progname);
d78c6ad5 1176
eb711c86
RK
1177 vmessage (prefix, s, ap);
1178 fputc ('\n', stderr);
4291d9c8
RS
1179}
1180
eb711c86 1181/* Print a message relevant to the given DECL. */
4291d9c8 1182
eb711c86
RK
1183static void
1184v_message_with_decl (decl, prefix, s, ap)
4291d9c8 1185 tree decl;
eb711c86 1186 char *prefix;
4291d9c8 1187 char *s;
eb711c86 1188 va_list ap;
4291d9c8 1189{
eb711c86 1190 char *n, *p, *junk;
4291d9c8
RS
1191
1192 fprintf (stderr, "%s:%d: ",
1193 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1194
eb711c86
RK
1195 if (prefix)
1196 fprintf (stderr, "%s: ", prefix);
1197
1198 /* Do magic to get around lack of varargs support for insertion
1199 of arguments into existing list. We know that the decl is first;
1200 we ass_u_me that it will be printed with "%s". */
1201
1202 for (p = s; *p; ++p)
1203 {
1204 if (*p == '%')
1205 {
1206 if (*(p + 1) == '%')
1207 ++p;
1208 else
1209 break;
1210 }
1211 }
1212
cb039f8a
RK
1213 if (p > s) /* Print the left-hand substring. */
1214 {
1215 char fmt[sizeof "%.255s"];
1216 long width = p - s;
1217
1218 if (width > 255L) width = 255L; /* arbitrary */
1219 sprintf (fmt, "%%.%lds", width);
1220 fprintf (stderr, fmt, s);
1221 }
eb711c86 1222
cb039f8a 1223 if (*p == '%') /* Print the name. */
eb711c86
RK
1224 {
1225 char *n = (DECL_NAME (decl)
1226 ? (*decl_printable_name) (decl, &junk)
1227 : "((anonymous))");
1228 fputs (n, stderr);
1229 while (*p)
1230 {
1231 ++p;
1232 if (isalpha (*(p - 1) & 0xFF))
1233 break;
1234 }
1235 }
1236
cb039f8a 1237 if (*p) /* Print the rest of the message. */
eb711c86
RK
1238 vmessage ((char *)NULL, p, ap);
1239
1240 fputc ('\n', stderr);
4291d9c8
RS
1241}
1242
eb711c86 1243/* Figure file and line of the given INSN. */
4291d9c8 1244
eb711c86
RK
1245static void
1246file_and_line_for_asm (insn, pfile, pline)
4291d9c8 1247 rtx insn;
eb711c86
RK
1248 char **pfile;
1249 int *pline;
4291d9c8 1250{
4291d9c8
RS
1251 rtx body = PATTERN (insn);
1252 rtx asmop;
1253
1254 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1255 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1256 asmop = SET_SRC (body);
1257 else if (GET_CODE (body) == ASM_OPERANDS)
1258 asmop = body;
1259 else if (GET_CODE (body) == PARALLEL
1260 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1261 asmop = SET_SRC (XVECEXP (body, 0, 0));
1262 else if (GET_CODE (body) == PARALLEL
1263 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1264 asmop = XVECEXP (body, 0, 0);
eb711c86
RK
1265 else
1266 asmop = NULL;
1267
1268 if (asmop)
1269 {
1270 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1271 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1272 }
1273 else
1274 {
1275 *pfile = input_filename;
1276 *pline = lineno;
1277 }
1278}
4291d9c8 1279
eb711c86 1280/* Report an error at line LINE of file FILE. */
4291d9c8 1281
eb711c86
RK
1282static void
1283v_error_with_file_and_line (file, line, s, ap)
1284 char *file;
1285 int line;
1286 char *s;
1287 va_list ap;
1288{
1289 count_error (0);
1290 report_error_function (file);
1291 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
d78c6ad5
RK
1292}
1293
1294void
e0e2a8da 1295error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
d78c6ad5 1296{
e0e2a8da 1297#ifndef __STDC__
eb711c86
RK
1298 char *file;
1299 int line;
1300 char *s;
e0e2a8da
RK
1301#endif
1302 va_list ap;
1303
1304 VA_START (ap, s);
eb711c86 1305
e0e2a8da 1306#ifndef __STDC__
eb711c86
RK
1307 file = va_arg (ap, char *);
1308 line = va_arg (ap, int);
1309 s = va_arg (ap, char *);
e0e2a8da
RK
1310#endif
1311
eb711c86
RK
1312 v_error_with_file_and_line (file, line, s, ap);
1313 va_end (ap);
4291d9c8
RS
1314}
1315
eb711c86
RK
1316/* Report an error at the declaration DECL.
1317 S is a format string which uses %s to substitute the declaration
1318 name; subsequent substitutions are a la printf. */
1319
1320static void
1321v_error_with_decl (decl, s, ap)
1322 tree decl;
1323 char *s;
1324 va_list ap;
1325{
1326 count_error (0);
1327 report_error_function (DECL_SOURCE_FILE (decl));
1328 v_message_with_decl (decl, (char *)NULL, s, ap);
1329}
4291d9c8
RS
1330
1331void
e0e2a8da 1332error_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1333{
e0e2a8da 1334#ifndef __STDC__
eb711c86
RK
1335 tree decl;
1336 char *s;
e0e2a8da
RK
1337#endif
1338 va_list ap;
eb711c86 1339
e0e2a8da
RK
1340 VA_START (ap, s);
1341
1342#ifndef __STDC__
eb711c86
RK
1343 decl = va_arg (ap, tree);
1344 s = va_arg (ap, char *);
e0e2a8da
RK
1345#endif
1346
eb711c86
RK
1347 v_error_with_decl (decl, s, ap);
1348 va_end (ap);
1349}
1350
1351/* Report an error at the line number of the insn INSN.
1352 This is used only when INSN is an `asm' with operands,
1353 and each ASM_OPERANDS records its own source file and line. */
1354
1355static void
1356v_error_for_asm (insn, s, ap)
1357 rtx insn;
4291d9c8 1358 char *s;
eb711c86 1359 va_list ap;
4291d9c8 1360{
eb711c86
RK
1361 char *file;
1362 int line;
4291d9c8 1363
eb711c86
RK
1364 count_error (0);
1365 file_and_line_for_asm (insn, &file, &line);
4291d9c8 1366 report_error_function (file);
eb711c86
RK
1367 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1368}
4291d9c8 1369
eb711c86 1370void
e0e2a8da 1371error_for_asm VPROTO((rtx insn, char *s, ...))
eb711c86 1372{
e0e2a8da 1373#ifndef __STDC__
eb711c86
RK
1374 rtx insn;
1375 char *s;
e0e2a8da
RK
1376#endif
1377 va_list ap;
eb711c86 1378
e0e2a8da
RK
1379 VA_START (ap, s);
1380
1381#ifndef __STDC__
eb711c86
RK
1382 insn = va_arg (ap, rtx);
1383 s = va_arg (ap, char *);
e0e2a8da
RK
1384#endif
1385
eb711c86
RK
1386 v_error_for_asm (insn, s, ap);
1387 va_end (ap);
4291d9c8
RS
1388}
1389
eb711c86 1390/* Report an error at the current line number. */
4291d9c8 1391
eb711c86
RK
1392static void
1393verror (s, ap)
4291d9c8 1394 char *s;
eb711c86 1395 va_list ap;
4291d9c8 1396{
eb711c86 1397 v_error_with_file_and_line (input_filename, lineno, s, ap);
4291d9c8
RS
1398}
1399
eb711c86 1400void
e0e2a8da 1401error VPROTO((char *s, ...))
eb711c86 1402{
e0e2a8da 1403#ifndef __STDC__
eb711c86 1404 char *s;
e0e2a8da
RK
1405#endif
1406 va_list ap;
1407
1408 VA_START (ap, s);
eb711c86 1409
e0e2a8da 1410#ifndef __STDC__
eb711c86 1411 s = va_arg (ap, char *);
e0e2a8da
RK
1412#endif
1413
eb711c86
RK
1414 verror (s, ap);
1415 va_end (ap);
1416}
1417
1418/* Report a fatal error at the current line number. */
1419
1420static void
1421vfatal (s, ap)
1422 char *s;
1423 va_list ap;
1424{
1425 verror (s, ap);
299846f2 1426 exit (FATAL_EXIT_CODE);
eb711c86 1427}
4291d9c8
RS
1428
1429void
e0e2a8da 1430fatal VPROTO((char *s, ...))
eb711c86 1431{
e0e2a8da 1432#ifndef __STDC__
eb711c86 1433 char *s;
e0e2a8da
RK
1434#endif
1435 va_list ap;
1436
1437 VA_START (ap, s);
eb711c86 1438
e0e2a8da 1439#ifndef __STDC__
eb711c86 1440 s = va_arg (ap, char *);
e0e2a8da
RK
1441#endif
1442
eb711c86
RK
1443 vfatal (s, ap);
1444 va_end (ap);
1445}
1446
1447/* Report a warning at line LINE of file FILE. */
1448
1449static void
1450v_warning_with_file_and_line (file, line, s, ap)
1451 char *file;
1452 int line;
4291d9c8 1453 char *s;
eb711c86 1454 va_list ap;
4291d9c8 1455{
eb711c86
RK
1456 if (count_error (1))
1457 {
1458 report_error_function (file);
1459 v_message_with_file_and_line (file, line, "warning", s, ap);
1460 }
1461}
4291d9c8 1462
eb711c86 1463void
e0e2a8da 1464warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
eb711c86 1465{
e0e2a8da 1466#ifndef __STDC__
eb711c86
RK
1467 char *file;
1468 int line;
1469 char *s;
e0e2a8da
RK
1470#endif
1471 va_list ap;
1472
1473 VA_START (ap, s);
eb711c86 1474
e0e2a8da 1475#ifndef __STDC__
eb711c86
RK
1476 file = va_arg (ap, char *);
1477 line = va_arg (ap, int);
1478 s = va_arg (ap, char *);
e0e2a8da
RK
1479#endif
1480
eb711c86
RK
1481 v_warning_with_file_and_line (file, line, s, ap);
1482 va_end (ap);
1483}
4291d9c8 1484
eb711c86
RK
1485/* Report a warning at the declaration DECL.
1486 S is a format string which uses %s to substitute the declaration
1487 name; subsequent substitutions are a la printf. */
4291d9c8 1488
eb711c86
RK
1489static void
1490v_warning_with_decl (decl, s, ap)
1491 tree decl;
1492 char *s;
1493 va_list ap;
1494{
1495 if (count_error (1))
1496 {
1497 report_error_function (DECL_SOURCE_FILE (decl));
1498 v_message_with_decl (decl, "warning", s, ap);
1499 }
1500}
4291d9c8 1501
eb711c86 1502void
e0e2a8da 1503warning_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1504{
e0e2a8da 1505#ifndef __STDC__
eb711c86
RK
1506 tree decl;
1507 char *s;
e0e2a8da
RK
1508#endif
1509 va_list ap;
eb711c86 1510
e0e2a8da
RK
1511 VA_START (ap, s);
1512
1513#ifndef __STDC__
eb711c86
RK
1514 decl = va_arg (ap, tree);
1515 s = va_arg (ap, char *);
e0e2a8da
RK
1516#endif
1517
eb711c86
RK
1518 v_warning_with_decl (decl, s, ap);
1519 va_end (ap);
4291d9c8
RS
1520}
1521
1522/* Report a warning at the line number of the insn INSN.
4291d9c8
RS
1523 This is used only when INSN is an `asm' with operands,
1524 and each ASM_OPERANDS records its own source file and line. */
1525
eb711c86
RK
1526static void
1527v_warning_for_asm (insn, s, ap)
4291d9c8
RS
1528 rtx insn;
1529 char *s;
eb711c86 1530 va_list ap;
4291d9c8 1531{
eb711c86
RK
1532 if (count_error (1))
1533 {
1534 char *file;
1535 int line;
4291d9c8 1536
eb711c86
RK
1537 file_and_line_for_asm (insn, &file, &line);
1538 report_error_function (file);
1539 v_message_with_file_and_line (file, line, "warning", s, ap);
1540 }
1541}
4291d9c8 1542
eb711c86 1543void
e0e2a8da 1544warning_for_asm VPROTO((rtx insn, char *s, ...))
eb711c86 1545{
e0e2a8da 1546#ifndef __STDC__
eb711c86
RK
1547 rtx insn;
1548 char *s;
e0e2a8da
RK
1549#endif
1550 va_list ap;
1551
1552 VA_START (ap, s);
eb711c86 1553
e0e2a8da 1554#ifndef __STDC__
eb711c86
RK
1555 insn = va_arg (ap, rtx);
1556 s = va_arg (ap, char *);
e0e2a8da
RK
1557#endif
1558
eb711c86
RK
1559 v_warning_for_asm (insn, s, ap);
1560 va_end (ap);
1561}
4291d9c8 1562
eb711c86
RK
1563/* Report a warning at the current line number. */
1564
1565static void
1566vwarning (s, ap)
1567 char *s;
1568 va_list ap;
1569{
1570 v_warning_with_file_and_line (input_filename, lineno, s, ap);
4291d9c8 1571}
eb711c86
RK
1572
1573void
e0e2a8da 1574warning VPROTO((char *s, ...))
eb711c86 1575{
e0e2a8da 1576#ifndef __STDC__
eb711c86 1577 char *s;
e0e2a8da
RK
1578#endif
1579 va_list ap;
1580
1581 VA_START (ap, s);
eb711c86 1582
e0e2a8da 1583#ifndef __STDC__
eb711c86 1584 s = va_arg (ap, char *);
e0e2a8da
RK
1585#endif
1586
eb711c86
RK
1587 vwarning (s, ap);
1588 va_end (ap);
1589}
1590
4291d9c8
RS
1591/* These functions issue either warnings or errors depending on
1592 -pedantic-errors. */
1593
eb711c86
RK
1594static void
1595vpedwarn (s, ap)
4291d9c8 1596 char *s;
eb711c86 1597 va_list ap;
4291d9c8
RS
1598{
1599 if (flag_pedantic_errors)
eb711c86 1600 verror (s, ap);
4291d9c8 1601 else
eb711c86 1602 vwarning (s, ap);
4291d9c8
RS
1603}
1604
1605void
e0e2a8da 1606pedwarn VPROTO((char *s, ...))
eb711c86 1607{
e0e2a8da 1608#ifndef __STDC__
eb711c86 1609 char *s;
e0e2a8da
RK
1610#endif
1611 va_list ap;
1612
1613 VA_START (ap, s);
eb711c86 1614
e0e2a8da 1615#ifndef __STDC__
eb711c86 1616 s = va_arg (ap, char *);
e0e2a8da
RK
1617#endif
1618
eb711c86
RK
1619 vpedwarn (s, ap);
1620 va_end (ap);
1621}
1622
1623static void
1624v_pedwarn_with_decl (decl, s, ap)
4291d9c8
RS
1625 tree decl;
1626 char *s;
eb711c86 1627 va_list ap;
4291d9c8 1628{
1554cdf5
DE
1629 /* We don't want -pedantic-errors to cause the compilation to fail from
1630 "errors" in system header files. Sometimes fixincludes can't fix what's
1631 broken (eg: unsigned char bitfields - fixing it may change the alignment
1632 which will cause programs to mysteriously fail because the C library
22d74562
DE
1633 or kernel uses the original layout). There's no point in issuing a
1634 warning either, it's just unnecessary noise. */
1554cdf5 1635
22d74562
DE
1636 if (! DECL_IN_SYSTEM_HEADER (decl))
1637 {
1638 if (flag_pedantic_errors)
1639 v_error_with_decl (decl, s, ap);
1640 else
1641 v_warning_with_decl (decl, s, ap);
1642 }
4291d9c8
RS
1643}
1644
1645void
e0e2a8da 1646pedwarn_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1647{
e0e2a8da 1648#ifndef __STDC__
eb711c86
RK
1649 tree decl;
1650 char *s;
e0e2a8da
RK
1651#endif
1652 va_list ap;
eb711c86 1653
e0e2a8da
RK
1654 VA_START (ap, s);
1655
1656#ifndef __STDC__
eb711c86
RK
1657 decl = va_arg (ap, tree);
1658 s = va_arg (ap, char *);
e0e2a8da
RK
1659#endif
1660
eb711c86
RK
1661 v_pedwarn_with_decl (decl, s, ap);
1662 va_end (ap);
1663}
1664
1665static void
1666v_pedwarn_with_file_and_line (file, line, s, ap)
4291d9c8
RS
1667 char *file;
1668 int line;
1669 char *s;
eb711c86 1670 va_list ap;
4291d9c8
RS
1671{
1672 if (flag_pedantic_errors)
eb711c86 1673 v_error_with_file_and_line (file, line, s, ap);
4291d9c8 1674 else
eb711c86 1675 v_warning_with_file_and_line (file, line, s, ap);
4291d9c8
RS
1676}
1677
4291d9c8 1678void
e0e2a8da 1679pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
eb711c86 1680{
e0e2a8da 1681#ifndef __STDC__
eb711c86
RK
1682 char *file;
1683 int line;
1684 char *s;
e0e2a8da
RK
1685#endif
1686 va_list ap;
eb711c86 1687
e0e2a8da
RK
1688 VA_START (ap, s);
1689
1690#ifndef __STDC__
eb711c86
RK
1691 file = va_arg (ap, char *);
1692 line = va_arg (ap, int);
1693 s = va_arg (ap, char *);
e0e2a8da
RK
1694#endif
1695
eb711c86
RK
1696 v_pedwarn_with_file_and_line (file, line, s, ap);
1697 va_end (ap);
1698}
1699
1700/* Apologize for not implementing some feature. */
1701
1702static void
1703vsorry (s, ap)
4291d9c8 1704 char *s;
eb711c86 1705 va_list ap;
4291d9c8
RS
1706{
1707 sorrycount++;
1708 if (input_filename)
1709 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1710 else
1711 fprintf (stderr, "%s: ", progname);
eb711c86
RK
1712 vmessage ("sorry, not implemented", s, ap);
1713 fputc ('\n', stderr);
1714}
4291d9c8 1715
eb711c86 1716void
e0e2a8da 1717sorry VPROTO((char *s, ...))
eb711c86 1718{
e0e2a8da 1719#ifndef __STDC__
eb711c86 1720 char *s;
e0e2a8da
RK
1721#endif
1722 va_list ap;
1723
1724 VA_START (ap, s);
eb711c86 1725
e0e2a8da 1726#ifndef __STDC__
eb711c86 1727 s = va_arg (ap, char *);
e0e2a8da
RK
1728#endif
1729
eb711c86
RK
1730 vsorry (s, ap);
1731 va_end (ap);
4291d9c8
RS
1732}
1733
eb711c86 1734/* Apologize for not implementing some feature, then quit. */
4291d9c8 1735
eb711c86
RK
1736static void
1737v_really_sorry (s, ap)
4291d9c8 1738 char *s;
eb711c86 1739 va_list ap;
4291d9c8 1740{
eb711c86 1741 sorrycount++;
4291d9c8
RS
1742 if (input_filename)
1743 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1744 else
c10afc44 1745 fprintf (stderr, "%s: ", progname);
eb711c86 1746 vmessage ("sorry, not implemented", s, ap);
4291d9c8
RS
1747 fatal (" (fatal)\n");
1748}
eb711c86
RK
1749
1750void
e0e2a8da 1751really_sorry VPROTO((char *s, ...))
eb711c86 1752{
e0e2a8da 1753#ifndef __STDC__
eb711c86 1754 char *s;
e0e2a8da
RK
1755#endif
1756 va_list ap;
1757
1758 VA_START (ap, s);
eb711c86 1759
e0e2a8da 1760#ifndef __STDC__
eb711c86 1761 s = va_arg (ap, char *);
e0e2a8da
RK
1762#endif
1763
eb711c86
RK
1764 v_really_sorry (s, ap);
1765 va_end (ap);
1766}
4291d9c8
RS
1767\f
1768/* More 'friendly' abort that prints the line and file.
1769 config.h can #define abort fancy_abort if you like that sort of thing.
1770
1771 I don't think this is actually a good idea.
1772 Other sorts of crashes will look a certain way.
1773 It is a good thing if crashes from calling abort look the same way.
1774 -- RMS */
1775
1776void
1777fancy_abort ()
1778{
1779 fatal ("internal gcc abort");
1780}
1781
1782/* This calls abort and is used to avoid problems when abort if a macro.
1783 It is used when we need to pass the address of abort. */
1784
1785void
1786do_abort ()
1787{
1788 abort ();
1789}
1790
1791/* When `malloc.c' is compiled with `rcheck' defined,
1792 it calls this function to report clobberage. */
1793
1794void
1795botch (s)
1796{
1797 abort ();
1798}
1799
1800/* Same as `malloc' but report error if no memory available. */
1801
4b980e20 1802char *
4291d9c8
RS
1803xmalloc (size)
1804 unsigned size;
1805{
4b980e20 1806 register char *value = (char *) malloc (size);
4291d9c8
RS
1807 if (value == 0)
1808 fatal ("virtual memory exhausted");
1809 return value;
1810}
1811
1812/* Same as `realloc' but report error if no memory available. */
1813
4b980e20 1814char *
4291d9c8
RS
1815xrealloc (ptr, size)
1816 char *ptr;
1817 int size;
1818{
4b980e20 1819 char *result = (char *) realloc (ptr, size);
4291d9c8
RS
1820 if (!result)
1821 fatal ("virtual memory exhausted");
1822 return result;
1823}
3e386b9e
RK
1824
1825/* Same as `strdup' but report error if no memory available. */
1826
1827char *
1828xstrdup (s)
1829 register char *s;
1830{
1831 register char *result = (char *) malloc (strlen (s) + 1);
1832
1833 if (! result)
1834 fatal ("virtual memory exhausted");
1835 strcpy (result, s);
1836 return result;
1837}
4291d9c8
RS
1838\f
1839/* Return the logarithm of X, base 2, considering X unsigned,
37366632
RK
1840 if X is a power of 2. Otherwise, returns -1.
1841
1842 This should be used via the `exact_log2' macro. */
4291d9c8
RS
1843
1844int
37366632
RK
1845exact_log2_wide (x)
1846 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1847{
1848 register int log = 0;
1849 /* Test for 0 or a power of 2. */
1850 if (x == 0 || x != (x & -x))
1851 return -1;
1852 while ((x >>= 1) != 0)
1853 log++;
1854 return log;
1855}
1856
1857/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
37366632
RK
1858 If X is 0, return -1.
1859
1860 This should be used via the floor_log2 macro. */
4291d9c8
RS
1861
1862int
37366632
RK
1863floor_log2_wide (x)
1864 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1865{
1866 register int log = -1;
1867 while (x != 0)
1868 log++,
1869 x >>= 1;
1870 return log;
1871}
1872
1873int float_handled;
1874jmp_buf float_handler;
1875
1876/* Specify where to longjmp to when a floating arithmetic error happens.
1877 If HANDLER is 0, it means don't handle the errors any more. */
1878
1879void
1880set_float_handler (handler)
1881 jmp_buf handler;
1882{
1883 float_handled = (handler != 0);
1884 if (handler)
4c9a05bc 1885 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
4291d9c8
RS
1886}
1887
bff4b641
RS
1888/* Specify, in HANDLER, where to longjmp to when a floating arithmetic
1889 error happens, pushing the previous specification into OLD_HANDLER.
1890 Return an indication of whether there was a previous handler in effect. */
1891
1892int
1893push_float_handler (handler, old_handler)
dc2b15dc 1894 jmp_buf handler, old_handler;
bff4b641
RS
1895{
1896 int was_handled = float_handled;
1897
1898 float_handled = 1;
1899 if (was_handled)
4c9a05bc
RK
1900 bcopy ((char *) float_handler, (char *) old_handler,
1901 sizeof (float_handler));
1902
1903 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
bff4b641
RS
1904 return was_handled;
1905}
1906
1907/* Restore the previous specification of whether and where to longjmp to
1908 when a floating arithmetic error happens. */
1909
1910void
1911pop_float_handler (handled, handler)
1912 int handled;
1913 jmp_buf handler;
1914{
1915 float_handled = handled;
1916 if (handled)
4c9a05bc 1917 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
bff4b641
RS
1918}
1919
4291d9c8
RS
1920/* Signals actually come here. */
1921
1922static void
1923float_signal (signo)
1924 /* If this is missing, some compilers complain. */
1925 int signo;
1926{
1927 if (float_handled == 0)
1928 abort ();
1929#if defined (USG) || defined (hpux)
1930 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
1931#endif
1932 float_handled = 0;
1933 signal (SIGFPE, float_signal);
1934 longjmp (float_handler, 1);
1935}
1936
1937/* Handler for SIGPIPE. */
1938
1939static void
1940pipe_closed (signo)
1941 /* If this is missing, some compilers complain. */
1942 int signo;
1943{
1944 fatal ("output pipe has been closed");
1945}
1946
1947/* Strip off a legitimate source ending from the input string NAME of
c62bdc79
RK
1948 length LEN. Rather than having to know the names used by all of
1949 our front ends, we strip off an ending of a period followed by one,
1950 two, or three characters. */
4291d9c8
RS
1951
1952void
1953strip_off_ending (name, len)
1954 char *name;
1955 int len;
1956{
c62bdc79
RK
1957 if (len > 2 && name[len - 2] == '.')
1958 name[len - 2] = '\0';
1959 else if (len > 3 && name[len - 3] == '.')
1960 name[len - 3] = '\0';
1961 else if (len > 4 && name[len - 4] == '.')
1962 name[len - 4] = '\0';
4291d9c8
RS
1963}
1964
7dce5088 1965/* Output a quoted string. */
0f41302f 1966
7dce5088
PE
1967void
1968output_quoted_string (asm_file, string)
1969 FILE *asm_file;
1970 char *string;
1971{
1972 char c;
1973
1974 putc ('\"', asm_file);
1975 while ((c = *string++) != 0)
1976 {
1977 if (c == '\"' || c == '\\')
1978 putc ('\\', asm_file);
1979 putc (c, asm_file);
1980 }
1981 putc ('\"', asm_file);
1982}
1983
4291d9c8
RS
1984/* Output a file name in the form wanted by System V. */
1985
1986void
1987output_file_directive (asm_file, input_name)
1988 FILE *asm_file;
1989 char *input_name;
1990{
1991 int len = strlen (input_name);
1992 char *na = input_name + len;
1993
1994 /* NA gets INPUT_NAME sans directory names. */
1995 while (na > input_name)
1996 {
1997 if (na[-1] == '/')
1998 break;
1999 na--;
2000 }
2001
2002#ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2003 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2004#else
2005#ifdef ASM_OUTPUT_SOURCE_FILENAME
2006 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2007#else
7dce5088
PE
2008 fprintf (asm_file, "\t.file\t");
2009 output_quoted_string (asm_file, na);
2010 fputc ('\n', asm_file);
4291d9c8
RS
2011#endif
2012#endif
2013}
2014\f
0f41302f
MS
2015/* Routine to build language identifier for object file. */
2016
d0d4af87
MS
2017static void
2018output_lang_identify (asm_out_file)
2019 FILE *asm_out_file;
2020{
2021 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2022 char *s = (char *) alloca (len);
2023 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2024 ASM_OUTPUT_LABEL (asm_out_file, s);
2025}
2026
dfe1a916 2027/* Routine to open a dump file. */
0f41302f 2028
dfe1a916
DE
2029static FILE *
2030open_dump_file (base_name, suffix)
2031 char *base_name;
2032 char *suffix;
2033{
2034 FILE *f;
2035 char *dumpname = (char *) alloca (strlen (base_name) + strlen (suffix) + 1);
2036
2037 strcpy (dumpname, base_name);
2038 strcat (dumpname, suffix);
2039 f = fopen (dumpname, "w");
2040 if (f == 0)
2041 pfatal_with_name (dumpname);
2042 return f;
2043}
2044
4291d9c8
RS
2045/* Compile an entire file of output from cpp, named NAME.
2046 Write a file of assembly output and various debugging dumps. */
2047
2048static void
2049compile_file (name)
2050 char *name;
2051{
2052 tree globals;
2053 int start_time;
4291d9c8
RS
2054
2055 int name_specified = name != 0;
2056
2057 if (dump_base_name == 0)
2058 dump_base_name = name ? name : "gccdump";
4291d9c8
RS
2059
2060 parse_time = 0;
2061 varconst_time = 0;
2062 integration_time = 0;
2063 jump_time = 0;
2064 cse_time = 0;
2065 loop_time = 0;
2066 cse2_time = 0;
2067 flow_time = 0;
2068 combine_time = 0;
2069 sched_time = 0;
2070 local_alloc_time = 0;
2071 global_alloc_time = 0;
2072 sched2_time = 0;
2073 dbr_sched_time = 0;
2074 shorten_branch_time = 0;
2075 stack_reg_time = 0;
2076 final_time = 0;
2077 symout_time = 0;
2078 dump_time = 0;
2079
2080 /* Open input file. */
2081
2082 if (name == 0 || !strcmp (name, "-"))
2083 {
2084 finput = stdin;
2085 name = "stdin";
2086 }
2087 else
2088 finput = fopen (name, "r");
2089 if (finput == 0)
2090 pfatal_with_name (name);
2091
282ea52a 2092#ifdef IO_BUFFER_SIZE
d7cedf4b 2093 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
282ea52a
RS
2094#endif
2095
4291d9c8
RS
2096 /* Initialize data in various passes. */
2097
2098 init_obstacks ();
2099 init_tree_codes ();
2100 init_lex ();
ca695ac9
JB
2101 /* Some of these really don't need to be called when generating bytecode,
2102 but the options would have to be parsed first to know that. -bson */
4291d9c8
RS
2103 init_rtl ();
2104 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2105 || debug_info_level == DINFO_LEVEL_VERBOSE);
7f21d440 2106 init_regs ();
4291d9c8
RS
2107 init_decl_processing ();
2108 init_optabs ();
2109 init_stmt ();
2110 init_expmed ();
4fa52007 2111 init_expr_once ();
4291d9c8
RS
2112 init_loop ();
2113 init_reload ();
2114
2115 if (flag_caller_saves)
2116 init_caller_save ();
2117
f246a305
RS
2118 /* If auxiliary info generation is desired, open the output file.
2119 This goes in the same directory as the source file--unlike
2120 all the other output files. */
4291d9c8
RS
2121 if (flag_gen_aux_info)
2122 {
4291d9c8
RS
2123 aux_info_file = fopen (aux_info_file_name, "w");
2124 if (aux_info_file == 0)
2125 pfatal_with_name (aux_info_file_name);
2126 }
2127
2128 /* If rtl dump desired, open the output file. */
2129 if (rtl_dump)
dfe1a916 2130 rtl_dump_file = open_dump_file (dump_base_name, ".rtl");
4291d9c8
RS
2131
2132 /* If jump_opt dump desired, open the output file. */
2133 if (jump_opt_dump)
dfe1a916 2134 jump_opt_dump_file = open_dump_file (dump_base_name, ".jump");
4291d9c8
RS
2135
2136 /* If cse dump desired, open the output file. */
2137 if (cse_dump)
dfe1a916 2138 cse_dump_file = open_dump_file (dump_base_name, ".cse");
4291d9c8
RS
2139
2140 /* If loop dump desired, open the output file. */
2141 if (loop_dump)
dfe1a916 2142 loop_dump_file = open_dump_file (dump_base_name, ".loop");
4291d9c8
RS
2143
2144 /* If cse2 dump desired, open the output file. */
2145 if (cse2_dump)
dfe1a916 2146 cse2_dump_file = open_dump_file (dump_base_name, ".cse2");
4291d9c8
RS
2147
2148 /* If flow dump desired, open the output file. */
2149 if (flow_dump)
dfe1a916 2150 flow_dump_file = open_dump_file (dump_base_name, ".flow");
4291d9c8
RS
2151
2152 /* If combine dump desired, open the output file. */
2153 if (combine_dump)
dfe1a916 2154 combine_dump_file = open_dump_file (dump_base_name, ".combine");
4291d9c8
RS
2155
2156 /* If scheduling dump desired, open the output file. */
2157 if (sched_dump)
dfe1a916 2158 sched_dump_file = open_dump_file (dump_base_name, ".sched");
4291d9c8
RS
2159
2160 /* If local_reg dump desired, open the output file. */
2161 if (local_reg_dump)
dfe1a916 2162 local_reg_dump_file = open_dump_file (dump_base_name, ".lreg");
4291d9c8
RS
2163
2164 /* If global_reg dump desired, open the output file. */
2165 if (global_reg_dump)
dfe1a916 2166 global_reg_dump_file = open_dump_file (dump_base_name, ".greg");
4291d9c8
RS
2167
2168 /* If 2nd scheduling dump desired, open the output file. */
2169 if (sched2_dump)
dfe1a916 2170 sched2_dump_file = open_dump_file (dump_base_name, ".sched2");
4291d9c8
RS
2171
2172 /* If jump2_opt dump desired, open the output file. */
2173 if (jump2_opt_dump)
dfe1a916 2174 jump2_opt_dump_file = open_dump_file (dump_base_name, ".jump2");
4291d9c8
RS
2175
2176 /* If dbr_sched dump desired, open the output file. */
2177 if (dbr_sched_dump)
dfe1a916 2178 dbr_sched_dump_file = open_dump_file (dump_base_name, ".dbr");
4291d9c8
RS
2179
2180#ifdef STACK_REGS
2181
2182 /* If stack_reg dump desired, open the output file. */
2183 if (stack_reg_dump)
dfe1a916 2184 stack_reg_dump_file = open_dump_file (dump_base_name, ".stack");
4291d9c8
RS
2185
2186#endif
2187
2188 /* Open assembler code output file. */
2189
2190 if (! name_specified && asm_file_name == 0)
2191 asm_out_file = stdout;
2192 else
2193 {
4291d9c8 2194 int len = strlen (dump_base_name);
dfe1a916 2195 register char *dumpname = (char *) xmalloc (len + 6);
4291d9c8
RS
2196 strcpy (dumpname, dump_base_name);
2197 strip_off_ending (dumpname, len);
2198 strcat (dumpname, ".s");
2199 if (asm_file_name == 0)
2200 {
2201 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2202 strcpy (asm_file_name, dumpname);
2203 }
2204 if (!strcmp (asm_file_name, "-"))
2205 asm_out_file = stdout;
2206 else
2207 asm_out_file = fopen (asm_file_name, "w");
2208 if (asm_out_file == 0)
2209 pfatal_with_name (asm_file_name);
2210 }
2211
f246a305 2212#ifdef IO_BUFFER_SIZE
d7cedf4b
RS
2213 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2214 _IOFBF, IO_BUFFER_SIZE);
f246a305
RS
2215#endif
2216
4291d9c8
RS
2217 input_filename = name;
2218
18736654
RK
2219 /* Put an entry on the input file stack for the main input file. */
2220 input_file_stack
2221 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2222 input_file_stack->next = 0;
2223 input_file_stack->name = input_filename;
2224
4291d9c8
RS
2225 /* Perform language-specific initialization.
2226 This may set main_input_filename. */
2227 lang_init ();
2228
2229 /* If the input doesn't start with a #line, use the input name
2230 as the official input file name. */
2231 if (main_input_filename == 0)
2232 main_input_filename = name;
2233
ca695ac9
JB
2234 if (!output_bytecode)
2235 {
2236 ASM_FILE_START (asm_out_file);
3d5cdd42
DE
2237
2238#ifdef ASM_COMMENT_START
2239 if (flag_verbose_asm)
2240 {
2241 /* Print the list of options in effect. */
3d5cdd42
DE
2242 print_version (asm_out_file, ASM_COMMENT_START);
2243 print_switch_values (asm_out_file, 0, MAX_LINE,
2244 ASM_COMMENT_START, " ", "\n");
2245 /* Add a blank line here so it appears in assembler output but not
2246 screen output. */
2247 fprintf (asm_out_file, "\n");
2248 }
2249#endif
ca695ac9 2250 }
4291d9c8 2251
ca695ac9 2252 /* Output something to inform GDB that this compilation was by GCC. Also
0f41302f 2253 serves to tell GDB file consists of bytecodes. */
ca695ac9
JB
2254 if (output_bytecode)
2255 fprintf (asm_out_file, "bc_gcc2_compiled.:\n");
2256 else
2257 {
4291d9c8 2258#ifndef ASM_IDENTIFY_GCC
ca695ac9 2259 fprintf (asm_out_file, "gcc2_compiled.:\n");
4291d9c8 2260#else
ca695ac9 2261 ASM_IDENTIFY_GCC (asm_out_file);
4291d9c8 2262#endif
ca695ac9 2263 }
d0d4af87 2264
0f41302f 2265 /* Output something to identify which front-end produced this file. */
d0d4af87
MS
2266#ifdef ASM_IDENTIFY_LANGUAGE
2267 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2268#endif
2269
cf440348
JL
2270#ifndef ASM_OUTPUT_SECTION_NAME
2271 if (flag_function_sections)
2272 {
2273 warning ("-ffunction-sections not supported for this target.");
2274 flag_function_sections = 0;
2275 }
2276#endif
2277
2278 if (flag_function_sections
2279 && (profile_flag || profile_block_flag))
2280 {
2281 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2282 flag_function_sections = 0;
2283 }
2284
2285 if (flag_function_sections && write_symbols != NO_DEBUG)
2286 warning ("-ffunction-sections may affect debugging on some targets.");
2287
ca695ac9
JB
2288 if (output_bytecode)
2289 {
2290 if (profile_flag || profile_block_flag)
2291 error ("profiling not supported in bytecode compilation");
2292 }
2293 else
2294 {
2295 /* ??? Note: There used to be a conditional here
2296 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2297 This was to guarantee separation between gcc_compiled. and
2298 the first function, for the sake of dbx on Suns.
2299 However, having the extra zero here confused the Emacs
2300 code for unexec, and might confuse other programs too.
2301 Therefore, I took out that change.
2302 In future versions we should find another way to solve
2303 that dbx problem. -- rms, 23 May 93. */
2304
2305 /* Don't let the first function fall at the same address
2306 as gcc_compiled., if profiling. */
2307 if (profile_flag || profile_block_flag)
2308 assemble_zeros (UNITS_PER_WORD);
2309 }
4291d9c8
RS
2310
2311 /* If dbx symbol table desired, initialize writing it
2312 and output the predefined types. */
f246a305
RS
2313#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2314 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2315 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2316 getdecls ()));
2317#endif
2318#ifdef SDB_DEBUGGING_INFO
2319 if (write_symbols == SDB_DEBUG)
2320 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2321 getdecls ()));
2322#endif
2323#ifdef DWARF_DEBUGGING_INFO
2324 if (write_symbols == DWARF_DEBUG)
2325 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2326#endif
9a666dda
JM
2327#ifdef DWARF2_DEBUGGING_INFO
2328 if (write_symbols == DWARF2_DEBUG)
2329 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
2330#endif
4291d9c8
RS
2331
2332 /* Initialize yet another pass. */
2333
ca695ac9
JB
2334 if (!output_bytecode)
2335 init_final (main_input_filename);
4291d9c8
RS
2336
2337 start_time = get_run_time ();
2338
2339 /* Call the parser, which parses the entire file
2340 (calling rest_of_compilation for each function). */
2341
2342 if (yyparse () != 0)
453dfc78
JW
2343 {
2344 if (errorcount == 0)
2345 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2346
2347 /* In case there were missing closebraces,
2348 get us back to the global binding level. */
2349 while (! global_bindings_p ())
2350 poplevel (0, 0, 0);
2351 }
4291d9c8
RS
2352
2353 /* Compilation is now finished except for writing
2354 what's left of the symbol table output. */
2355
2356 parse_time += get_run_time () - start_time;
2357
2358 parse_time -= integration_time;
2359 parse_time -= varconst_time;
2360
2361 globals = getdecls ();
2362
2363 /* Really define vars that have had only a tentative definition.
2364 Really output inline functions that must actually be callable
2365 and have not been output so far. */
2366
2367 {
2368 int len = list_length (globals);
2369 tree *vec = (tree *) alloca (sizeof (tree) * len);
2370 int i;
2371 tree decl;
2b6c54d6 2372 int reconsider = 1;
4291d9c8
RS
2373
2374 /* Process the decls in reverse order--earliest first.
2375 Put them into VEC from back to front, then take out from front. */
2376
2377 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2378 vec[len - i - 1] = decl;
2379
2380 for (i = 0; i < len; i++)
2381 {
2382 decl = vec[i];
07af9d16
JM
2383
2384 /* We're not deferring this any longer. */
2385 DECL_DEFER_OUTPUT (decl) = 0;
2386
488b1f4f
RS
2387 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2388 && incomplete_decl_finalize_hook != 0)
2b599527 2389 (*incomplete_decl_finalize_hook) (decl);
2b6c54d6 2390 }
2b599527 2391
2b6c54d6
JM
2392 /* Now emit any global variables or functions that we have been putting
2393 off. We need to loop in case one of the things emitted here
2394 references another one which comes earlier in the list. */
2395 while (reconsider)
2396 {
2397 reconsider = 0;
2398 for (i = 0; i < len; i++)
4291d9c8 2399 {
2b6c54d6
JM
2400 decl = vec[i];
2401
2402 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2403 continue;
2404
6b2bd61e
PB
2405 /* Don't write out static consts, unless we still need them.
2406
fbe912dd
BK
2407 We also keep static consts if not optimizing (for debugging),
2408 unless the user specified -fno-keep-static-consts.
6b2bd61e
PB
2409 ??? They might be better written into the debug information.
2410 This is possible when using DWARF.
2411
2412 A language processor that wants static constants to be always
2413 written out (even if it is not used) is responsible for
2414 calling rest_of_decl_compilation itself. E.g. the C front-end
2415 calls rest_of_decl_compilation from finish_decl.
2416 One motivation for this is that is conventional in some
2417 environments to write things like:
2418 static const char rcsid[] = "... version string ...";
2419 intending to force the string to be in the executable.
2420
2421 A language processor that would prefer to have unneeded
2422 static constants "optimized away" would just defer writing
2423 them out until here. E.g. C++ does this, because static
2424 constants are often defined in header files.
2425
2426 ??? A tempting alternative (for both C and C++) would be
2427 to force a constant to be written if and only if it is
0f41302f 2428 defined in a main file, as opposed to an include file. */
6b2bd61e 2429
2b6c54d6
JM
2430 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2431 && (! TREE_READONLY (decl)
2432 || TREE_PUBLIC (decl)
fbe912dd 2433 || (!optimize && flag_keep_static_consts)
2b6c54d6
JM
2434 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2435 {
2436 reconsider = 1;
2437 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2438 }
2439
2440 if (TREE_CODE (decl) == FUNCTION_DECL
2441 && DECL_INITIAL (decl) != 0
2442 && DECL_SAVED_INSNS (decl) != 0
2443 && (flag_keep_inline_functions
2444 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2445 {
2446 reconsider = 1;
2447 temporary_allocation ();
2448 output_inline_function (decl);
2449 permanent_allocation (1);
2450 }
4291d9c8 2451 }
2b6c54d6 2452 }
4291d9c8 2453
3d195391
MS
2454 /* Now that all possible functions have been output, we can dump
2455 the exception table. */
2456
2457 if (exception_table_p ())
2458 output_exception_table ();
2459
2b6c54d6
JM
2460 for (i = 0; i < len; i++)
2461 {
2462 decl = vec[i];
2463
2464 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2465 && ! TREE_ASM_WRITTEN (decl))
2466 /* Cancel the RTL for this decl so that, if debugging info
2467 output for global variables is still to come,
2468 this one will be omitted. */
2469 DECL_RTL (decl) = NULL;
4291d9c8 2470
ac266247
RS
2471 /* Warn about any function
2472 declared static but not defined.
2473 We don't warn about variables,
2474 because many programs have static variables
2475 that exist only to get some text into the object file. */
8c461ea1
JM
2476 if (TREE_CODE (decl) == FUNCTION_DECL
2477 && (warn_unused
2478 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
4291d9c8 2479 && DECL_INITIAL (decl) == 0
216d5cdd 2480 && DECL_EXTERNAL (decl)
d1b01681 2481 && ! DECL_ARTIFICIAL (decl)
4291d9c8 2482 && ! TREE_PUBLIC (decl))
7d429c41 2483 {
8c461ea1 2484 pedwarn_with_decl (decl,
7d429c41
RS
2485 "`%s' declared `static' but never defined");
2486 /* This symbol is effectively an "extern" declaration now. */
2487 TREE_PUBLIC (decl) = 1;
2488 assemble_external (decl);
7d429c41 2489 }
8c461ea1 2490
4291d9c8 2491 /* Warn about static fns or vars defined but not used,
7062b881
PB
2492 but not about inline functions or static consts
2493 since defining those in header files is normal practice. */
4291d9c8 2494 if (warn_unused
7062b881
PB
2495 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2496 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
0c20aabf 2497 && ! DECL_IN_SYSTEM_HEADER (decl)
216d5cdd 2498 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2499 && ! TREE_PUBLIC (decl)
2500 && ! TREE_USED (decl)
f843649d 2501 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
4291d9c8
RS
2502 /* The TREE_USED bit for file-scope decls
2503 is kept in the identifier, to handle multiple
2504 external decls in different scopes. */
2505 && ! TREE_USED (DECL_NAME (decl)))
2506 warning_with_decl (decl, "`%s' defined but not used");
2507
2508#ifdef SDB_DEBUGGING_INFO
2509 /* The COFF linker can move initialized global vars to the end.
2510 And that can screw up the symbol ordering.
2511 By putting the symbols in that order to begin with,
2512 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2513 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2514 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
7efad3f7 2515 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2516 && DECL_RTL (decl) != 0)
2517 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2518
2519 /* Output COFF information for non-global
0f41302f 2520 file-scope initialized variables. */
4291d9c8
RS
2521 if (write_symbols == SDB_DEBUG
2522 && TREE_CODE (decl) == VAR_DECL
2523 && DECL_INITIAL (decl)
7efad3f7 2524 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2525 && DECL_RTL (decl) != 0
2526 && GET_CODE (DECL_RTL (decl)) == MEM)
2527 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2528#endif /* SDB_DEBUGGING_INFO */
2529#ifdef DWARF_DEBUGGING_INFO
6dc42e49 2530 /* Output DWARF information for file-scope tentative data object
4291d9c8
RS
2531 declarations, file-scope (extern) function declarations (which
2532 had no corresponding body) and file-scope tagged type declarations
2533 and definitions which have not yet been forced out. */
2534
2535 if (write_symbols == DWARF_DEBUG
2536 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2537 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
9a666dda
JM
2538#endif
2539#ifdef DWARF2_DEBUGGING_INFO
2540 /* Output DWARF2 information for file-scope tentative data object
2541 declarations, file-scope (extern) function declarations (which
2542 had no corresponding body) and file-scope tagged type declarations
2543 and definitions which have not yet been forced out. */
2544
2545 if (write_symbols == DWARF2_DEBUG
2546 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
88dad228 2547 TIMEVAR (symout_time, dwarf2out_decl (decl));
4291d9c8
RS
2548#endif
2549 }
2550 }
2551
4b8af8d9
JM
2552 /* Write out any pending weak symbol declarations. */
2553
2554 weak_finish ();
2555
4291d9c8 2556 /* Do dbx symbols */
f246a305
RS
2557#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2558 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2559 TIMEVAR (symout_time,
2560 {
2561 dbxout_finish (asm_out_file, main_input_filename);
2562 });
2563#endif
2564
2565#ifdef DWARF_DEBUGGING_INFO
2566 if (write_symbols == DWARF_DEBUG)
2567 TIMEVAR (symout_time,
2568 {
2569 dwarfout_finish ();
2570 });
2571#endif
2572
9a666dda
JM
2573#ifdef DWARF2_DEBUGGING_INFO
2574 if (write_symbols == DWARF2_DEBUG)
2575 TIMEVAR (symout_time,
2576 {
2577 dwarf2out_finish ();
2578 });
2579#endif
2580
4291d9c8
RS
2581 /* Output some stuff at end of file if nec. */
2582
ca695ac9
JB
2583 if (!output_bytecode)
2584 {
2585 end_final (main_input_filename);
4291d9c8
RS
2586
2587#ifdef ASM_FILE_END
ca695ac9 2588 ASM_FILE_END (asm_out_file);
4291d9c8 2589#endif
ca695ac9 2590 }
4291d9c8 2591
4291d9c8
RS
2592 /* Language-specific end of compilation actions. */
2593
2594 lang_finish ();
2595
0207ea82
RK
2596 if (output_bytecode)
2597 bc_write_file (asm_out_file);
2598
4291d9c8
RS
2599 /* Close the dump files. */
2600
2601 if (flag_gen_aux_info)
2602 {
2603 fclose (aux_info_file);
2604 if (errorcount)
2605 unlink (aux_info_file_name);
2606 }
2607
2608 if (rtl_dump)
2609 fclose (rtl_dump_file);
2610
2611 if (jump_opt_dump)
2612 fclose (jump_opt_dump_file);
2613
2614 if (cse_dump)
2615 fclose (cse_dump_file);
2616
2617 if (loop_dump)
2618 fclose (loop_dump_file);
2619
2620 if (cse2_dump)
2621 fclose (cse2_dump_file);
2622
2623 if (flow_dump)
2624 fclose (flow_dump_file);
2625
2626 if (combine_dump)
2627 {
2628 dump_combine_total_stats (combine_dump_file);
2629 fclose (combine_dump_file);
2630 }
2631
2632 if (sched_dump)
2633 fclose (sched_dump_file);
2634
2635 if (local_reg_dump)
2636 fclose (local_reg_dump_file);
2637
2638 if (global_reg_dump)
2639 fclose (global_reg_dump_file);
2640
2641 if (sched2_dump)
2642 fclose (sched2_dump_file);
2643
2644 if (jump2_opt_dump)
2645 fclose (jump2_opt_dump_file);
2646
2647 if (dbr_sched_dump)
2648 fclose (dbr_sched_dump_file);
2649
2650#ifdef STACK_REGS
2651 if (stack_reg_dump)
2652 fclose (stack_reg_dump_file);
2653#endif
2654
2655 /* Close non-debugging input and output files. Take special care to note
2656 whether fclose returns an error, since the pages might still be on the
2657 buffer chain while the file is open. */
2658
2659 fclose (finput);
2660 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2661 fatal_io_error (asm_file_name);
2662
2663 /* Print the times. */
2664
2665 if (! quiet_flag)
2666 {
2667 fprintf (stderr,"\n");
2668 print_time ("parse", parse_time);
ca695ac9
JB
2669
2670 if (!output_bytecode)
2671 {
2672 print_time ("integration", integration_time);
2673 print_time ("jump", jump_time);
2674 print_time ("cse", cse_time);
2675 print_time ("loop", loop_time);
2676 print_time ("cse2", cse2_time);
2677 print_time ("flow", flow_time);
2678 print_time ("combine", combine_time);
2679 print_time ("sched", sched_time);
2680 print_time ("local-alloc", local_alloc_time);
2681 print_time ("global-alloc", global_alloc_time);
2682 print_time ("sched2", sched2_time);
2683 print_time ("dbranch", dbr_sched_time);
2684 print_time ("shorten-branch", shorten_branch_time);
2685 print_time ("stack-reg", stack_reg_time);
2686 print_time ("final", final_time);
2687 print_time ("varconst", varconst_time);
2688 print_time ("symout", symout_time);
2689 print_time ("dump", dump_time);
2690 }
4291d9c8
RS
2691 }
2692}
2693\f
2694/* This is called from various places for FUNCTION_DECL, VAR_DECL,
2695 and TYPE_DECL nodes.
2696
2697 This does nothing for local (non-static) variables.
2698 Otherwise, it sets up the RTL and outputs any assembler code
2699 (label definition, storage allocation and initialization).
2700
2701 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2702 the assembler symbol name to be used. TOP_LEVEL is nonzero
2703 if this declaration is not within a function. */
2704
2705void
2706rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2707 tree decl;
2708 char *asmspec;
2709 int top_level;
2710 int at_end;
2711{
2712 /* Declarations of variables, and of functions defined elsewhere. */
2713
928eb380
RS
2714/* The most obvious approach, to put an #ifndef around where
2715 this macro is used, doesn't work since it's inside a macro call. */
2716#ifndef ASM_FINISH_DECLARE_OBJECT
2717#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2718#endif
2719
4291d9c8
RS
2720 /* Forward declarations for nested functions are not "external",
2721 but we need to treat them as if they were. */
216d5cdd 2722 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
4291d9c8
RS
2723 || TREE_CODE (decl) == FUNCTION_DECL)
2724 TIMEVAR (varconst_time,
2725 {
2726 make_decl_rtl (decl, asmspec, top_level);
9a9a9643
RS
2727 /* Initialized extern variable exists to be replaced
2728 with its value, or represents something that will be
2729 output in another file. */
6dbf678a 2730 if (! (TREE_CODE (decl) == VAR_DECL
9a9a9643
RS
2731 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
2732 && DECL_INITIAL (decl) != 0
5b272d50 2733 && DECL_INITIAL (decl) != error_mark_node))
6dbf678a
RS
2734 /* Don't output anything
2735 when a tentative file-scope definition is seen.
2736 But at end of compilation, do output code for them. */
2737 if (! (! at_end && top_level
2738 && (DECL_INITIAL (decl) == 0
9a9a9643 2739 || DECL_INITIAL (decl) == error_mark_node)))
8380e2f2 2740 assemble_variable (decl, top_level, at_end, 0);
5b7540b6
DE
2741 if (!output_bytecode
2742 && decl == last_assemble_variable_decl)
5e10b3cc
RS
2743 {
2744 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2745 top_level, at_end);
2746 }
4291d9c8 2747 });
216d5cdd 2748 else if (DECL_REGISTER (decl) && asmspec != 0)
4291d9c8
RS
2749 {
2750 if (decode_reg_name (asmspec) >= 0)
2751 {
2752 DECL_RTL (decl) = 0;
2753 make_decl_rtl (decl, asmspec, top_level);
2754 }
2755 else
2756 error ("invalid register name `%s' for register variable", asmspec);
2757 }
f246a305
RS
2758#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2759 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2760 && TREE_CODE (decl) == TYPE_DECL)
4291d9c8
RS
2761 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2762#endif
2763#ifdef SDB_DEBUGGING_INFO
2764 else if (write_symbols == SDB_DEBUG && top_level
2765 && TREE_CODE (decl) == TYPE_DECL)
2766 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2767#endif
2768}
2769
2770/* Called after finishing a record, union or enumeral type. */
2771
2772void
2773rest_of_type_compilation (type, toplev)
2774 tree type;
2775 int toplev;
2776{
f246a305
RS
2777#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2778 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2779 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2780#endif
2781#ifdef SDB_DEBUGGING_INFO
2782 if (write_symbols == SDB_DEBUG)
2783 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2784#endif
2785}
2786
2787/* This is called from finish_function (within yyparse)
2788 after each top-level definition is parsed.
2789 It is supposed to compile that function or variable
2790 and output the assembler code for it.
2791 After we return, the tree storage is freed. */
2792
2793void
2794rest_of_compilation (decl)
2795 tree decl;
2796{
2797 register rtx insns;
2798 int start_time = get_run_time ();
2799 int tem;
2800 /* Nonzero if we have saved the original DECL_INITIAL of the function,
2801 to be restored after we finish compiling the function
2802 (for use when compiling inline calls to this function). */
2803 tree saved_block_tree = 0;
8a958768
RS
2804 /* Likewise, for DECL_ARGUMENTS. */
2805 tree saved_arguments = 0;
ab40ad2b 2806 int failure = 0;
4291d9c8 2807
ca695ac9
JB
2808 if (output_bytecode)
2809 return;
2810
4291d9c8
RS
2811 /* If we are reconsidering an inline function
2812 at the end of compilation, skip the stuff for making it inline. */
2813
2814 if (DECL_SAVED_INSNS (decl) == 0)
2815 {
9deaf1b1 2816 int inlineable = 0;
4291d9c8
RS
2817 char *lose;
2818
2819 /* If requested, consider whether to make this function inline. */
9deaf1b1 2820 if (DECL_INLINE (decl) || flag_inline_functions)
4291d9c8
RS
2821 TIMEVAR (integration_time,
2822 {
2823 lose = function_cannot_inline_p (decl);
caa0eccd 2824 if (lose || ! optimize)
4291d9c8 2825 {
9deaf1b1 2826 if (warn_inline && DECL_INLINE (decl))
4291d9c8 2827 warning_with_decl (decl, lose);
9548c538 2828 DECL_ABSTRACT_ORIGIN (decl) = 0;
46dbb914
RS
2829 /* Don't really compile an extern inline function.
2830 If we can't make it inline, pretend
2831 it was only declared. */
2832 if (DECL_EXTERNAL (decl))
27937f46
RS
2833 {
2834 DECL_INITIAL (decl) = 0;
2835 goto exit_rest_of_compilation;
2836 }
4291d9c8
RS
2837 }
2838 else
9deaf1b1
RK
2839 /* ??? Note that this has the effect of making it look
2840 like "inline" was specified for a function if we choose
2841 to inline it. This isn't quite right, but it's
2842 probably not worth the trouble to fix. */
2843 inlineable = DECL_INLINE (decl) = 1;
4291d9c8
RS
2844 });
2845
2846 insns = get_insns ();
2847
2848 /* Dump the rtl code if we are dumping rtl. */
2849
2850 if (rtl_dump)
2851 TIMEVAR (dump_time,
2852 {
2853 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2854 IDENTIFIER_POINTER (DECL_NAME (decl)));
2855 if (DECL_SAVED_INSNS (decl))
2856 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2857 print_rtl (rtl_dump_file, insns);
2858 fflush (rtl_dump_file);
2859 });
2860
2861 /* If function is inline, and we don't yet know whether to
2862 compile it by itself, defer decision till end of compilation.
2863 finish_compilation will call rest_of_compilation again
16411ea6 2864 for those functions that need to be output. Also defer those
ec6c615d
RK
2865 functions that we are supposed to defer. We cannot defer
2866 functions containing nested functions since the nested function
2867 data is in our non-saved obstack. */
2868
2869 if (! current_function_contains_functions
2870 && (DECL_DEFER_OUTPUT (decl)
9deaf1b1 2871 || (DECL_INLINE (decl)
ec6c615d
RK
2872 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2873 && ! flag_keep_inline_functions)
2874 || DECL_EXTERNAL (decl)))))
4291d9c8 2875 {
951af26e
JM
2876 DECL_DEFER_OUTPUT (decl) = 1;
2877
2878 /* If -Wreturn-type, we have to do a bit of compilation. */
2879 if (! warn_return_type)
937522b5 2880 {
951af26e
JM
2881#ifdef DWARF_DEBUGGING_INFO
2882 /* Generate the DWARF info for the "abstract" instance
2883 of a function which we may later generate inlined and/or
2884 out-of-line instances of. */
2885 if (write_symbols == DWARF_DEBUG)
2886 {
2887 set_decl_abstract_flags (decl, 1);
2888 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2889 set_decl_abstract_flags (decl, 0);
2890 }
9a666dda
JM
2891#endif
2892#ifdef DWARF2_DEBUGGING_INFO
2893 /* Generate the DWARF2 info for the "abstract" instance
2894 of a function which we may later generate inlined and/or
2895 out-of-line instances of. */
2896 if (write_symbols == DWARF2_DEBUG)
2897 {
2898 set_decl_abstract_flags (decl, 1);
88dad228 2899 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
2900 set_decl_abstract_flags (decl, 0);
2901 }
951af26e
JM
2902#endif
2903 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
ac02eb62 2904 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
951af26e 2905 goto exit_rest_of_compilation;
937522b5 2906 }
4291d9c8
RS
2907 }
2908
8a958768 2909 /* If we have to compile the function now, save its rtl and subdecls
4291d9c8 2910 so that its compilation will not affect what others get. */
9deaf1b1 2911 if (inlineable || DECL_DEFER_OUTPUT (decl))
4291d9c8 2912 {
937522b5
RS
2913#ifdef DWARF_DEBUGGING_INFO
2914 /* Generate the DWARF info for the "abstract" instance of
2915 a function which we will generate an out-of-line instance
2916 of almost immediately (and which we may also later generate
2917 various inlined instances of). */
2918 if (write_symbols == DWARF_DEBUG)
2919 {
2920 set_decl_abstract_flags (decl, 1);
2921 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2922 set_decl_abstract_flags (decl, 0);
2923 }
9a666dda
JM
2924#endif
2925#ifdef DWARF2_DEBUGGING_INFO
2926 /* Generate the DWARF2 info for the "abstract" instance of
2927 a function which we will generate an out-of-line instance
2928 of almost immediately (and which we may also later generate
2929 various inlined instances of). */
2930 if (write_symbols == DWARF2_DEBUG)
2931 {
2932 set_decl_abstract_flags (decl, 1);
88dad228 2933 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
2934 set_decl_abstract_flags (decl, 0);
2935 }
937522b5 2936#endif
4291d9c8 2937 saved_block_tree = DECL_INITIAL (decl);
8a958768 2938 saved_arguments = DECL_ARGUMENTS (decl);
4291d9c8 2939 TIMEVAR (integration_time, save_for_inline_copying (decl));
912c4289 2940 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
4291d9c8 2941 }
4291d9c8 2942
b8471b65
RK
2943 /* If specified extern inline but we aren't inlining it, we are
2944 done. */
9deaf1b1 2945 if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
b8471b65
RK
2946 goto exit_rest_of_compilation;
2947 }
07af9d16 2948
951af26e
JM
2949 if (! DECL_DEFER_OUTPUT (decl))
2950 TREE_ASM_WRITTEN (decl) = 1;
4291d9c8
RS
2951
2952 /* Now that integrate will no longer see our rtl, we need not distinguish
2953 between the return value of this function and the return value of called
2954 functions. */
2955 rtx_equal_function_value_matters = 0;
2956
32235b30
RS
2957 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
2958 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
4291d9c8
RS
2959 {
2960 goto exit_rest_of_compilation;
2961 }
2962
89418a92
BK
2963 /* Add an unwinder for exception handling, if needed.
2964 This must be done before we finalize PIC code. */
2965 emit_unwinder ();
4291d9c8
RS
2966
2967#ifdef FINALIZE_PIC
2968 /* If we are doing position-independent code generation, now
2969 is the time to output special prologues and epilogues.
2970 We do not want to do this earlier, because it just clutters
2971 up inline functions with meaningless insns. */
2972 if (flag_pic)
2973 FINALIZE_PIC;
2974#endif
2975
89418a92
BK
2976 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
2977 Note that that may have been done above, in save_for_inline_copying.
2978 The call to resume_temporary_allocation near the end of this function
2979 goes back to the usual state of affairs. This must be done after
2980 we've built up any unwinders for exception handling, and done
2981 the FINALIZE_PIC work, if necessary. */
2982
2983 rtl_in_current_obstack ();
3d195391 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
3907 { "gdwarf", DWARF_DEBUG, 0 },
3908 { "gdwarf+", DWARF_DEBUG, 1 },
9a666dda 3909#endif
a94dbf2c
JM
3910#ifdef DWARF2_DEBUGGING_INFO
3911 { "gdwarf-2", DWARF2_DEBUG, 0 },
ff482cef
DE
3912#endif
3913#ifdef XCOFF_DEBUGGING_INFO
3914 { "gxcoff", XCOFF_DEBUG, 0 },
3915 { "gxcoff+", XCOFF_DEBUG, 1 },
3916#endif
3917#ifdef SDB_DEBUGGING_INFO
3918 { "gcoff", SDB_DEBUG, 0 },
3919#endif
3920 { 0, 0, 0 }
3921 };
3922 /* Indexed by enum debug_info_type. */
3923 static char *debug_type_names[] = {
9a666dda 3924 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
ff482cef 3925 };
4291d9c8 3926
ff482cef
DE
3927 /* Look up STR in the table. */
3928 for (da = debug_args; da->arg; da++)
3929 {
9a666dda 3930 if (! strncmp (str, da->arg, strlen (da->arg)))
ff482cef
DE
3931 {
3932 enum debug_info_type type = da->debug_type;
9a666dda
JM
3933 char *p, *q;
3934
3935 p = str + strlen (da->arg);
3936 if (*p && (*p < '0' || *p > '9'))
3937 continue;
3938 q = p;
3939 while (*q && (*q >= '0' && *q <= '9'))
3940 q++;
3941 if (*p)
3942 level = atoi (p);
3943 else
3944 level = 2; /* default debugging info level */
3945 if (*q || level > 3)
3946 {
3947 warning ("invalid debug level specification in option: `-%s'",
3948 str);
3949 /* ??? This error message is incorrect in the case of
3950 -g4 -g. */
3951 warning ("no debugging information will be generated");
3952 level = 0;
3953 }
3954
3955 /* ??? A few targets use STR in the
ff482cef
DE
3956 definition of PREFERRED_DEBUGGING_TYPE! */
3957 if (type == NO_DEBUG)
3958 type = PREFERRED_DEBUGGING_TYPE;
3959
3960 /* Does it conflict with an already selected type? */
3961 if (type_explicitly_set_p
3962 /* -g/-ggdb don't conflict with anything */
3963 && da->debug_type != NO_DEBUG
3964 && type != selected_debug_type)
3965 warning ("`-%s' ignored, conflicts with `-g%s'",
3966 str, debug_type_names[(int) selected_debug_type]);
3967 else
3968 {
3969 /* If the format has already been set, -g/-ggdb
3970 only change the debug level. */
3971 if (type_explicitly_set_p
3972 && da->debug_type == NO_DEBUG)
3973 ; /* don't change debugging type */
3974 else
3975 {
3976 selected_debug_type = type;
3977 type_explicitly_set_p = da->debug_type != NO_DEBUG;
3978 }
3979 write_symbols = (level == 0
3980 ? NO_DEBUG
3981 : selected_debug_type);
3982 use_gnu_debug_info_extensions = da->use_extensions_p;
3983 debug_info_level = (enum debug_info_level) level;
3984 }
3985 break;
3986 }
3987 }
3988 if (! da->arg)
7276e85d
RK
3989 warning ("`-%s' not supported by this configuration of GCC",
3990 str);
4291d9c8
RS
3991 }
3992 else if (!strcmp (str, "o"))
3993 {
3994 asm_file_name = argv[++i];
3995 }
3996 else if (str[0] == 'G')
3997 {
3998 g_switch_set = TRUE;
3999 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
4000 }
f246a305
RS
4001 else if (!strncmp (str, "aux-info", 8))
4002 {
4003 flag_gen_aux_info = 1;
4004 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
4005 }
4291d9c8
RS
4006 else
4007 error ("Invalid option `%s'", argv[i]);
4008 }
4009 else if (argv[i][0] == '+')
b99933c7 4010 error ("Invalid option `%s'", argv[i]);
4291d9c8
RS
4011 else
4012 filename = argv[i];
4013 }
4014
ca695ac9 4015 /* Initialize for bytecode output. A good idea to do this as soon as
0f41302f 4016 possible after the "-f" options have been parsed. */
ca695ac9
JB
4017 if (output_bytecode)
4018 {
4019#ifndef TARGET_SUPPORTS_BYTECODE
4020 /* Just die with a fatal error if not supported */
40e6003c 4021 fatal ("-fbytecode not supported for this target");
ca695ac9
JB
4022#else
4023 bc_initialize ();
4024#endif
4025 }
4026
f246a305
RS
4027 if (optimize == 0)
4028 {
a2468e45
BK
4029 /* Inlining does not work if not optimizing,
4030 so force it not to be done. */
f246a305
RS
4031 flag_no_inline = 1;
4032 warn_inline = 0;
a2468e45
BK
4033
4034 /* The c_decode_option and lang_decode_option functions set
4035 this to `2' if -Wall is used, so we can avoid giving out
4036 lots of errors for people who don't realize what -Wall does. */
4037 if (warn_uninitialized == 1)
4038 warning ("-Wuninitialized is not supported without -O");
f246a305
RS
4039 }
4040
4291d9c8
RS
4041#ifdef OVERRIDE_OPTIONS
4042 /* Some machines may reject certain combinations of options. */
4043 OVERRIDE_OPTIONS;
4044#endif
4045
ec6c615d
RK
4046 if (profile_block_flag == 3)
4047 {
4048 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4049 profile_block_flag = 2;
4050 }
4051
4291d9c8
RS
4052 /* Unrolling all loops implies that standard loop unrolling must also
4053 be done. */
4054 if (flag_unroll_all_loops)
4055 flag_unroll_loops = 1;
4056 /* Loop unrolling requires that strength_reduction be on also. Silently
4057 turn on strength reduction here if it isn't already on. Also, the loop
4058 unrolling code assumes that cse will be run after loop, so that must
4059 be turned on also. */
4060 if (flag_unroll_loops)
4061 {
4062 flag_strength_reduce = 1;
4063 flag_rerun_cse_after_loop = 1;
4064 }
4065
4066 /* Warn about options that are not supported on this machine. */
4067#ifndef INSN_SCHEDULING
4068 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4069 warning ("instruction scheduling not supported on this target machine");
4070#endif
4071#ifndef DELAY_SLOTS
4072 if (flag_delayed_branch)
4073 warning ("this target machine does not have delayed branches");
4074#endif
4075
4076 /* If we are in verbose mode, write out the version and maybe all the
4077 option flags in use. */
4078 if (version_flag)
4079 {
3d5cdd42 4080 print_version (stderr, "");
4291d9c8 4081 if (! quiet_flag)
3d5cdd42 4082 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4291d9c8
RS
4083 }
4084
4291d9c8
RS
4085 compile_file (filename);
4086
876ac40d 4087#if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN32__))
4291d9c8
RS
4088 if (flag_print_mem)
4089 {
4090 char *lim = (char *) sbrk (0);
4091
4092 fprintf (stderr, "Data size %d.\n",
b61b1c91 4093 lim - (char *) &environ);
4291d9c8
RS
4094 fflush (stderr);
4095
4096#ifdef USG
4097 system ("ps -l 1>&2");
4098#else /* not USG */
4099 system ("ps v");
4100#endif /* not USG */
4101 }
876ac40d 4102#endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN32) */
4291d9c8
RS
4103
4104 if (errorcount)
4105 exit (FATAL_EXIT_CODE);
4106 if (sorrycount)
4107 exit (FATAL_EXIT_CODE);
4108 exit (SUCCESS_EXIT_CODE);
299846f2 4109 return 0;
4291d9c8
RS
4110}
4111\f
4112/* Decode -m switches. */
4113
4114/* Here is a table, controlled by the tm.h file, listing each -m switch
4115 and which bits in `target_switches' it should set or clear.
4116 If VALUE is positive, it is bits to set.
4117 If VALUE is negative, -VALUE is bits to clear.
4118 (The sign bit is not used so there is no confusion.) */
4119
4120struct {char *name; int value;} target_switches []
4121 = TARGET_SWITCHES;
4122
4123/* This table is similar, but allows the switch to have a value. */
4124
4125#ifdef TARGET_OPTIONS
4126struct {char *prefix; char ** variable;} target_options []
4127 = TARGET_OPTIONS;
4128#endif
4129
4130/* Decode the switch -mNAME. */
4131
4132void
4133set_target_switch (name)
4134 char *name;
4135{
4136 register int j;
4137 int valid = 0;
4138
4139 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4140 if (!strcmp (target_switches[j].name, name))
4141 {
4142 if (target_switches[j].value < 0)
4143 target_flags &= ~-target_switches[j].value;
4144 else
4145 target_flags |= target_switches[j].value;
4146 valid = 1;
4147 }
4148
4149#ifdef TARGET_OPTIONS
4150 if (!valid)
4151 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4152 {
4153 int len = strlen (target_options[j].prefix);
4154 if (!strncmp (target_options[j].prefix, name, len))
4155 {
4156 *target_options[j].variable = name + len;
4157 valid = 1;
4158 }
4159 }
4160#endif
4161
4162 if (!valid)
4163 error ("Invalid option `%s'", name);
4164}
4165\f
3d5cdd42
DE
4166/* Print version information to FILE.
4167 Each line begins with INDENT (for the case where FILE is the
4168 assembler output file). */
4291d9c8 4169
3d5cdd42
DE
4170void
4171print_version (file, indent)
4172 FILE *file;
4173 char *indent;
4291d9c8 4174{
3d5cdd42
DE
4175 fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4176 language_string, version_string);
4177 fprintf (file, " (%s)", TARGET_NAME);
4178#ifdef __GNUC__
4179#ifndef __VERSION__
4180#define __VERSION__ "[unknown]"
4181#endif
4182 fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4183#else
4184 fprintf (file, " compiled by CC.\n");
4185#endif
4186}
4291d9c8 4187
3d5cdd42 4188/* Print an option value and return the adjusted position in the line.
309a8875
DE
4189 ??? We don't handle error returns from fprintf (disk full); presumably
4190 other code will catch a disk full though. */
4291d9c8 4191
3d5cdd42
DE
4192int
4193print_single_switch (file, pos, max, indent, sep, term, type, name)
4194 FILE *file;
4195 int pos, max;
4196 char *indent, *sep, *term, *type, *name;
4197{
309a8875
DE
4198 /* The ultrix fprintf returns 0 on success, so compute the result we want
4199 here since we need it for the following test. */
4200 int len = strlen (sep) + strlen (type) + strlen (name);
4201
3d5cdd42 4202 if (pos != 0
309a8875 4203 && pos + len > max)
4291d9c8 4204 {
3d5cdd42
DE
4205 fprintf (file, "%s", term);
4206 pos = 0;
4291d9c8 4207 }
3d5cdd42
DE
4208 if (pos == 0)
4209 {
309a8875
DE
4210 fprintf (file, "%s", indent);
4211 pos = strlen (indent);
3d5cdd42 4212 }
309a8875
DE
4213 fprintf (file, "%s%s%s", sep, type, name);
4214 pos += len;
3d5cdd42 4215 return pos;
4291d9c8
RS
4216}
4217
3d5cdd42
DE
4218/* Print active target switches to FILE.
4219 POS is the current cursor position and MAX is the size of a "line".
4220 Each line begins with INDENT and ends with TERM.
4221 Each switch is separated from the next by SEP. */
4291d9c8 4222
3d5cdd42
DE
4223void
4224print_switch_values (file, pos, max, indent, sep, term)
4225 FILE *file;
4226 int pos, max;
4227 char *indent, *sep, *term;
4291d9c8 4228{
3d5cdd42
DE
4229 int j, flags;
4230 char **p;
4231
4232 /* Print the options as passed. */
4291d9c8 4233
3d5cdd42
DE
4234 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4235 "options passed: ", "");
4236
520e7ff5 4237 for (p = &save_argv[1]; *p != NULL; p++)
3d5cdd42
DE
4238 if (**p == '-')
4239 {
4240 /* Ignore these. */
520e7ff5
DE
4241 if (strcmp (*p, "-o") == 0)
4242 {
4243 if (p[1] != NULL)
4244 p++;
4245 continue;
4246 }
3d5cdd42
DE
4247 if (strcmp (*p, "-quiet") == 0)
4248 continue;
4249 if (strcmp (*p, "-version") == 0)
4250 continue;
4251 if ((*p)[1] == 'd')
4252 continue;
4253
4254 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4255 }
4256 if (pos > 0)
4257 fprintf (file, "%s", term);
4258
4259 /* Print the -f and -m options that have been enabled.
4260 We don't handle language specific options but printing argv
4261 should suffice. */
4262
4263 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4264 "options enabled: ", "");
4291d9c8
RS
4265
4266 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
4267 if (*f_options[j].variable == f_options[j].on_value)
3d5cdd42
DE
4268 pos = print_single_switch (file, pos, max, indent, sep, term,
4269 "-f", f_options[j].string);
4291d9c8 4270
3d5cdd42 4271 /* Print target specific options. */
4291d9c8 4272
3d5cdd42 4273 flags = target_flags;
4291d9c8
RS
4274 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4275 if (target_switches[j].name[0] != '\0'
4276 && target_switches[j].value > 0
4277 && ((target_switches[j].value & target_flags)
4278 == target_switches[j].value))
3d5cdd42
DE
4279 {
4280 pos = print_single_switch (file, pos, max, indent, sep, term,
4281 "-m", target_switches[j].name);
4282 flags &= ~ target_switches[j].value;
4283 }
4284
4285#ifdef TARGET_OPTIONS
4286 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4287 if (*target_options[j].variable != NULL)
4288 {
4289 char prefix[256];
4290 sprintf (prefix, "-m%s", target_options[j].prefix);
4291 pos = print_single_switch (file, pos, max, indent, sep, term,
4292 prefix, *target_options[j].variable);
4293 }
4294#endif
4291d9c8 4295
3d5cdd42 4296 fprintf (file, "%s", term);
4291d9c8 4297}
9a666dda
JM
4298
4299/* Record the beginning of a new source file, named FILENAME. */
4300
4301void
4302debug_start_source_file (filename)
4303 register char *filename;
4304{
4305#ifdef DBX_DEBUGGING_INFO
4306 if (write_symbols == DBX_DEBUG)
4307 dbxout_start_new_source_file (filename);
4308#endif
4309#ifdef DWARF_DEBUGGING_INFO
4310 if (debug_info_level == DINFO_LEVEL_VERBOSE
4311 && write_symbols == DWARF_DEBUG)
4312 dwarfout_start_new_source_file (filename);
4313#endif /* DWARF_DEBUGGING_INFO */
4314#ifdef DWARF2_DEBUGGING_INFO
4315 if (debug_info_level == DINFO_LEVEL_VERBOSE
4316 && write_symbols == DWARF2_DEBUG)
4317 dwarf2out_start_source_file (filename);
4318#endif /* DWARF2_DEBUGGING_INFO */
cc694a81
DE
4319#ifdef SDB_DEBUGGING_INFO
4320 if (write_symbols == SDB_DEBUG)
4321 sdbout_start_new_source_file (filename);
4322#endif
9a666dda
JM
4323}
4324
4325/* Record the resumption of a source file. LINENO is the line number in
4326 the source file we are returning to. */
4327
4328void
4329debug_end_source_file (lineno)
4330 register unsigned lineno;
4331{
4332#ifdef DBX_DEBUGGING_INFO
4333 if (write_symbols == DBX_DEBUG)
4334 dbxout_resume_previous_source_file ();
4335#endif
4336#ifdef DWARF_DEBUGGING_INFO
4337 if (debug_info_level == DINFO_LEVEL_VERBOSE
4338 && write_symbols == DWARF_DEBUG)
4339 dwarfout_resume_previous_source_file (lineno);
4340#endif /* DWARF_DEBUGGING_INFO */
4341#ifdef DWARF2_DEBUGGING_INFO
4342 if (debug_info_level == DINFO_LEVEL_VERBOSE
4343 && write_symbols == DWARF2_DEBUG)
4344 dwarf2out_end_source_file ();
4345#endif /* DWARF2_DEBUGGING_INFO */
cc694a81
DE
4346#ifdef SDB_DEBUGGING_INFO
4347 if (write_symbols == SDB_DEBUG)
4348 sdbout_resume_previous_source_file ();
4349#endif
9a666dda
JM
4350}
4351
4352/* Called from check_newline in c-parse.y. The `buffer' parameter contains
4353 the tail part of the directive line, i.e. the part which is past the
4354 initial whitespace, #, whitespace, directive-name, whitespace part. */
4355
4356void
4357debug_define (lineno, buffer)
4358 register unsigned lineno;
4359 register char *buffer;
4360{
4361#ifdef DWARF_DEBUGGING_INFO
4362 if (debug_info_level == DINFO_LEVEL_VERBOSE
4363 && write_symbols == DWARF_DEBUG)
4364 dwarfout_define (lineno, buffer);
4365#endif /* DWARF_DEBUGGING_INFO */
4366#ifdef DWARF2_DEBUGGING_INFO
4367 if (debug_info_level == DINFO_LEVEL_VERBOSE
4368 && write_symbols == DWARF2_DEBUG)
4369 dwarf2out_define (lineno, buffer);
4370#endif /* DWARF2_DEBUGGING_INFO */
4371}
4372
4373/* Called from check_newline in c-parse.y. The `buffer' parameter contains
4374 the tail part of the directive line, i.e. the part which is past the
4375 initial whitespace, #, whitespace, directive-name, whitespace part. */
4376
4377void
4378debug_undef (lineno, buffer)
4379 register unsigned lineno;
4380 register char *buffer;
4381{
4382#ifdef DWARF_DEBUGGING_INFO
4383 if (debug_info_level == DINFO_LEVEL_VERBOSE
4384 && write_symbols == DWARF_DEBUG)
4385 dwarfout_undef (lineno, buffer);
4386#endif /* DWARF_DEBUGGING_INFO */
4387#ifdef DWARF2_DEBUGGING_INFO
4388 if (debug_info_level == DINFO_LEVEL_VERBOSE
4389 && write_symbols == DWARF2_DEBUG)
4390 dwarf2out_undef (lineno, buffer);
4391#endif /* DWARF2_DEBUGGING_INFO */
4392}
This page took 1.01577 seconds and 5 git commands to generate.