]> gcc.gnu.org Git - gcc.git/blame - gcc/toplev.c
(stamp-proto): Pass LOCAL_INCLUDE_DIR based on local_prefix.
[gcc.git] / gcc / toplev.c
CommitLineData
4291d9c8
RS
1/* Top level of GNU C compiler
2 Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
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
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
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"
27#include <sys/types.h>
28#include <stdio.h>
29#include <signal.h>
30#include <setjmp.h>
31
32#include <sys/stat.h>
33
34#ifdef USG
35#undef FLOAT
36#include <sys/param.h>
37/* This is for hpux. It is a real screw. They should change hpux. */
38#undef FLOAT
39#include <sys/times.h>
40#include <time.h> /* Correct for hpux at least. Is it good on other USG? */
41#undef FFS /* Some systems define this in param.h. */
42#else
43#ifndef VMS
44#include <sys/time.h>
45#include <sys/resource.h>
46#endif
47#endif
48
49#include "input.h"
50#include "tree.h"
51/* #include "c-tree.h" */
52#include "rtl.h"
53#include "flags.h"
54#include "insn-attr.h"
d0d4af87 55#include "defaults.h"
f246a305
RS
56
57#ifdef XCOFF_DEBUGGING_INFO
58#include "xcoffout.h"
59#endif
4291d9c8
RS
60\f
61#ifdef VMS
62/* The extra parameters substantially improve the I/O performance. */
63static FILE *
64VMS_fopen (fname, type)
65 char * fname;
66 char * type;
67{
68 if (strcmp (type, "w") == 0)
69 return fopen (fname, type, "mbc=16", "deq=64", "fop=tef", "shr=nil");
70 return fopen (fname, type, "mbc=16");
71}
72#define fopen VMS_fopen
73#endif
74
75#ifndef DEFAULT_GDB_EXTENSIONS
76#define DEFAULT_GDB_EXTENSIONS 1
77#endif
78
79extern int rtx_equal_function_value_matters;
80
72c8bb7f 81#if ! (defined (VMS) || defined (OS2))
4291d9c8 82extern char **environ;
4d7e336b 83#endif
4291d9c8
RS
84extern char *version_string, *language_string;
85
86extern void init_lex ();
87extern void init_decl_processing ();
88extern void init_obstacks ();
89extern void init_tree_codes ();
90extern void init_rtl ();
91extern void init_optabs ();
92extern void init_stmt ();
93extern void init_reg_sets ();
94extern void dump_flow_info ();
95extern void dump_sched_info ();
96extern void dump_local_alloc ();
97
98void rest_of_decl_compilation ();
99void error ();
100void error_with_file_and_line ();
101void fancy_abort ();
102#ifndef abort
103void abort ();
104#endif
105void set_target_switch ();
106static void print_switch_values ();
107static char *decl_name ();
108
109/* Name of program invoked, sans directories. */
110
111char *progname;
112
113/* Copy of arguments to main. */
114int save_argc;
115char **save_argv;
116\f
117/* Name of current original source file (what was input to cpp).
118 This comes from each #-command in the actual input. */
119
120char *input_filename;
121
122/* Name of top-level original source file (what was input to cpp).
123 This comes from the #-command at the beginning of the actual input.
124 If there isn't any there, then this is the cc1 input file name. */
125
126char *main_input_filename;
127
128/* Stream for reading from the input file. */
129
130FILE *finput;
131
132/* Current line number in real source file. */
133
134int lineno;
135
136/* Stack of currently pending input files. */
137
138struct file_stack *input_file_stack;
139
140/* Incremented on each change to input_file_stack. */
141int input_file_stack_tick;
142
143/* FUNCTION_DECL for function now being parsed or compiled. */
144
145extern tree current_function_decl;
146
147/* Name to use as base of names for dump output files. */
148
149char *dump_base_name;
150
151/* Bit flags that specify the machine subtype we are compiling for.
152 Bits are tested using macros TARGET_... defined in the tm.h file
153 and set by `-m...' switches. Must be defined in rtlanal.c. */
154
155extern int target_flags;
156
157/* Flags saying which kinds of debugging dump have been requested. */
158
159int rtl_dump = 0;
160int rtl_dump_and_exit = 0;
161int jump_opt_dump = 0;
162int cse_dump = 0;
163int loop_dump = 0;
164int cse2_dump = 0;
165int flow_dump = 0;
166int combine_dump = 0;
167int sched_dump = 0;
168int local_reg_dump = 0;
169int global_reg_dump = 0;
170int sched2_dump = 0;
171int jump2_opt_dump = 0;
172int dbr_sched_dump = 0;
173int flag_print_asm_name = 0;
174int stack_reg_dump = 0;
175
176/* Name for output file of assembly code, specified with -o. */
177
178char *asm_file_name;
179
180/* Value of the -G xx switch, and whether it was passed or not. */
181int g_switch_value;
182int g_switch_set;
183
184/* Type(s) of debugging information we are producing (if any).
185 See flags.h for the definitions of the different possible
186 types of debugging information. */
187enum debug_info_type write_symbols = NO_DEBUG;
188
189/* Level of debugging information we are producing. See flags.h
190 for the definitions of the different possible levels. */
191enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
192
a53d0bcc
RS
193/* Nonzero means use GNU-only extensions in the generated symbolic
194 debugging information. */
195/* Currently, this only has an effect when write_symbols is set to
196 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
197int use_gnu_debug_info_extensions = 0;
4291d9c8
RS
198
199/* Nonzero means do optimizations. -O.
200 Particular numeric values stand for particular amounts of optimization;
201 thus, -O2 stores 2 here. However, the optimizations beyond the basic
202 ones are not controlled directly by this variable. Instead, they are
203 controlled by individual `flag_...' variables that are defaulted
204 based on this variable. */
205
206int optimize = 0;
207
208/* Number of error messages and warning messages so far. */
209
210int errorcount = 0;
211int warningcount = 0;
212int sorrycount = 0;
213
214/* Pointer to function to compute the name to use to print a declaration. */
215
216char *(*decl_printable_name) ();
217
218/* Pointer to function to compute rtl for a language-specific tree code. */
219
220struct rtx_def *(*lang_expand_expr) ();
221
2b599527
RS
222/* Pointer to function to finish handling an incomplete decl at the
223 end of compilation. */
224
225void (*incomplete_decl_finalize_hook) () = 0;
226
4291d9c8
RS
227/* Nonzero if generating code to do profiling. */
228
229int profile_flag = 0;
230
231/* Nonzero if generating code to do profiling on a line-by-line basis. */
232
233int profile_block_flag;
234
235/* Nonzero for -pedantic switch: warn about anything
236 that standard spec forbids. */
237
238int pedantic = 0;
239
240/* Temporarily suppress certain warnings.
241 This is set while reading code from a system header file. */
242
243int in_system_header = 0;
244
245/* Nonzero means do stupid register allocation.
246 Currently, this is 1 if `optimize' is 0. */
247
248int obey_regdecls = 0;
249
250/* Don't print functions as they are compiled and don't print
251 times taken by the various passes. -quiet. */
252
253int quiet_flag = 0;
254\f
255/* -f flags. */
256
257/* Nonzero means `char' should be signed. */
258
259int flag_signed_char;
260
261/* Nonzero means give an enum type only as many bytes as it needs. */
262
263int flag_short_enums;
264
265/* Nonzero for -fcaller-saves: allocate values in regs that need to
266 be saved across function calls, if that produces overall better code.
267 Optional now, so people can test it. */
268
269#ifdef DEFAULT_CALLER_SAVES
270int flag_caller_saves = 1;
271#else
272int flag_caller_saves = 0;
273#endif
274
958ec8ca
JW
275/* Nonzero if structures and unions should be returned in memory.
276
277 This should only be defined if compatibility with another compiler or
278 with an ABI is needed, because it results in slower code. */
279
280#ifndef DEFAULT_PCC_STRUCT_RETURN
281#define DEFAULT_PCC_STRUCT_RETURN 1
282#endif
283
4291d9c8
RS
284/* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
285
958ec8ca 286int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
4291d9c8
RS
287
288/* Nonzero for -fforce-mem: load memory value into a register
289 before arithmetic on it. This makes better cse but slower compilation. */
290
291int flag_force_mem = 0;
292
293/* Nonzero for -fforce-addr: load memory address into a register before
294 reference to memory. This makes better cse but slower compilation. */
295
296int flag_force_addr = 0;
297
298/* Nonzero for -fdefer-pop: don't pop args after each function call;
299 instead save them up to pop many calls' args with one insns. */
300
6731a3e3 301int flag_defer_pop = 0;
4291d9c8
RS
302
303/* Nonzero for -ffloat-store: don't allocate floats and doubles
304 in extended-precision registers. */
305
306int flag_float_store = 0;
307
308/* Nonzero for -fcse-follow-jumps:
309 have cse follow jumps to do a more extensive job. */
310
311int flag_cse_follow_jumps;
312
8b3686ed
RK
313/* Nonzero for -fcse-skip-blocks:
314 have cse follow a branch around a block. */
315int flag_cse_skip_blocks;
316
4291d9c8
RS
317/* Nonzero for -fexpensive-optimizations:
318 perform miscellaneous relatively-expensive optimizations. */
319int flag_expensive_optimizations;
320
321/* Nonzero for -fthread-jumps:
322 have jump optimize output of loop. */
323
324int flag_thread_jumps;
325
326/* Nonzero enables strength-reduction in loop.c. */
327
328int flag_strength_reduce = 0;
329
330/* Nonzero enables loop unrolling in unroll.c. Only loops for which the
331 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
332 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
333 unrolled. */
334
335int flag_unroll_loops;
336
337/* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
338 This is generally not a win. */
339
340int flag_unroll_all_loops;
341
342/* Nonzero for -fwritable-strings:
343 store string constants in data segment and don't uniquize them. */
344
345int flag_writable_strings = 0;
346
347/* Nonzero means don't put addresses of constant functions in registers.
348 Used for compiling the Unix kernel, where strange substitutions are
349 done on the assembly output. */
350
351int flag_no_function_cse = 0;
352
353/* Nonzero for -fomit-frame-pointer:
354 don't make a frame pointer in simple functions that don't require one. */
355
356int flag_omit_frame_pointer = 0;
357
358/* Nonzero to inhibit use of define_optimization peephole opts. */
359
360int flag_no_peephole = 0;
361
43855b28
JL
362/* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
363 operations in the interest of optimization. For example it allows
364 GCC to assume arguments to sqrt are nonnegative numbers, allowing
365 faster code for sqrt to be generated. */
366
367int flag_fast_math = 0;
368
4291d9c8
RS
369/* Nonzero means all references through pointers are volatile. */
370
371int flag_volatile;
c6e75897
RS
372
373/* Nonzero means treat all global and extern variables as global. */
374
38d4d0c2 375int flag_volatile_global;
4291d9c8
RS
376
377/* Nonzero means just do syntax checking; don't output anything. */
378
379int flag_syntax_only = 0;
380
381/* Nonzero means to rerun cse after loop optimization. This increases
382 compilation time about 20% and picks up a few more common expressions. */
383
384static int flag_rerun_cse_after_loop;
385
386/* Nonzero for -finline-functions: ok to inline functions that look like
387 good inline candidates. */
388
389int flag_inline_functions;
390
391/* Nonzero for -fkeep-inline-functions: even if we make a function
ac2a9454 392 go inline everywhere, keep its definition around for debugging
4291d9c8
RS
393 purposes. */
394
395int flag_keep_inline_functions;
396
397/* Nonzero means that functions declared `inline' will be treated
398 as `static'. Prevents generation of zillions of copies of unused
399 static inline functions; instead, `inlines' are written out
400 only when actually used. Used in conjunction with -g. Also
401 does the right thing with #pragma interface. */
402
403int flag_no_inline;
404
405/* Nonzero means we should be saving declaration info into a .X file. */
406
407int flag_gen_aux_info = 0;
408
f246a305
RS
409/* Specified name of aux-info file. */
410
411static char *aux_info_file_name;
412
4291d9c8
RS
413/* Nonzero means make the text shared if supported. */
414
415int flag_shared_data;
416
417/* Nonzero means schedule into delayed branch slots if supported. */
418
419int flag_delayed_branch;
420
421/* Nonzero if we are compiling pure (sharable) code.
422 Value is 1 if we are doing reasonable (i.e. simple
423 offset into offset table) pic. Value is 2 if we can
424 only perform register offsets. */
425
426int flag_pic;
427
0382002b 428/* Nonzero means place uninitialized global data in the bss section. */
4291d9c8
RS
429
430int flag_no_common;
431
432/* Nonzero means pretend it is OK to examine bits of target floats,
433 even if that isn't true. The resulting code will have incorrect constants,
434 but the same series of instructions that the native compiler would make. */
435
436int flag_pretend_float;
437
438/* Nonzero means change certain warnings into errors.
439 Usually these are warnings about failure to conform to some standard. */
440
441int flag_pedantic_errors = 0;
442
443/* flag_schedule_insns means schedule insns within basic blocks (before
444 local_alloc).
445 flag_schedule_insns_after_reload means schedule insns after
446 global_alloc. */
447
448int flag_schedule_insns = 0;
449int flag_schedule_insns_after_reload = 0;
450
451/* -finhibit-size-directive inhibits output of .size for ELF.
452 This is used only for compiling crtstuff.c,
453 and it may be extended to other effects
454 needed for crtstuff.c on other systems. */
455int flag_inhibit_size_directive = 0;
456
9a631e8e
RS
457/* -fverbose-asm causes extra commentary information to be produced in
458 the generated assembly code (to make it more readable). This option
459 is generally only of use to those who actually need to read the
460 generated assembly code (perhaps while debugging the compiler itself). */
461
462int flag_verbose_asm = 0;
463
4291d9c8 464/* -fgnu-linker specifies use of the GNU linker for initializations.
d68c507d
RS
465 (Or, more generally, a linker that handles initializations.)
466 -fno-gnu-linker says that collect2 will be used. */
467#ifdef USE_COLLECT2
468int flag_gnu_linker = 0;
469#else
4291d9c8 470int flag_gnu_linker = 1;
d68c507d 471#endif
4291d9c8
RS
472
473/* Table of language-independent -f options.
474 STRING is the option name. VARIABLE is the address of the variable.
475 ON_VALUE is the value to store in VARIABLE
476 if `-fSTRING' is seen as an option.
477 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
478
479struct { char *string; int *variable; int on_value;} f_options[] =
480{
481 {"float-store", &flag_float_store, 1},
482 {"volatile", &flag_volatile, 1},
38d4d0c2 483 {"volatile-global", &flag_volatile_global, 1},
4291d9c8
RS
484 {"defer-pop", &flag_defer_pop, 1},
485 {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
486 {"cse-follow-jumps", &flag_cse_follow_jumps, 1},
8b3686ed 487 {"cse-skip-blocks", &flag_cse_skip_blocks, 1},
4291d9c8
RS
488 {"expensive-optimizations", &flag_expensive_optimizations, 1},
489 {"thread-jumps", &flag_thread_jumps, 1},
490 {"strength-reduce", &flag_strength_reduce, 1},
491 {"unroll-loops", &flag_unroll_loops, 1},
492 {"unroll-all-loops", &flag_unroll_all_loops, 1},
493 {"writable-strings", &flag_writable_strings, 1},
494 {"peephole", &flag_no_peephole, 0},
495 {"force-mem", &flag_force_mem, 1},
496 {"force-addr", &flag_force_addr, 1},
497 {"function-cse", &flag_no_function_cse, 0},
498 {"inline-functions", &flag_inline_functions, 1},
499 {"keep-inline-functions", &flag_keep_inline_functions, 1},
500 {"inline", &flag_no_inline, 0},
501 {"syntax-only", &flag_syntax_only, 1},
4291d9c8
RS
502 {"shared-data", &flag_shared_data, 1},
503 {"caller-saves", &flag_caller_saves, 1},
504 {"pcc-struct-return", &flag_pcc_struct_return, 1},
958ec8ca 505 {"reg-struct-return", &flag_pcc_struct_return, 0},
4291d9c8
RS
506 {"delayed-branch", &flag_delayed_branch, 1},
507 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1},
508 {"pretend-float", &flag_pretend_float, 1},
509 {"schedule-insns", &flag_schedule_insns, 1},
510 {"schedule-insns2", &flag_schedule_insns_after_reload, 1},
511 {"pic", &flag_pic, 1},
512 {"PIC", &flag_pic, 2},
43855b28 513 {"fast-math", &flag_fast_math, 1},
4291d9c8
RS
514 {"common", &flag_no_common, 0},
515 {"inhibit-size-directive", &flag_inhibit_size_directive, 1},
9a631e8e 516 {"verbose-asm", &flag_verbose_asm, 1},
4291d9c8
RS
517 {"gnu-linker", &flag_gnu_linker, 1}
518};
b99933c7
RS
519
520/* Table of language-specific options. */
521
522char *lang_options[] =
523{
524 "-ftraditional",
525 "-traditional",
526 "-fnotraditional",
527 "-fno-traditional",
528 "-fsigned-char",
529 "-funsigned-char",
530 "-fno-signed-char",
531 "-fno-unsigned-char",
532 "-fsigned-bitfields",
533 "-funsigned-bitfields",
534 "-fno-signed-bitfields",
535 "-fno-unsigned-bitfields",
536 "-fshort-enums",
537 "-fno-short-enums",
538 "-fcond-mismatch",
539 "-fno-cond-mismatch",
540 "-fshort-double",
541 "-fno-short-double",
542 "-fasm",
543 "-fno-asm",
544 "-fbuiltin",
545 "-fno-builtin",
546 "-fno-ident",
547 "-fident",
548 "-ansi",
549 "-Wimplicit",
550 "-Wno-implicit",
551 "-Wwrite-strings",
552 "-Wno-write-strings",
553 "-Wcast-qual",
554 "-Wno-cast-qual",
555 "-Wpointer-arith",
556 "-Wno-pointer-arith",
557 "-Wstrict-prototypes",
558 "-Wno-strict-prototypes",
559 "-Wmissing-prototypes",
560 "-Wno-missing-prototypes",
561 "-Wredundant-decls",
562 "-Wno-redundant-decls",
563 "-Wnested-externs",
564 "-Wno-nested-externs",
565 "-Wtraditional",
566 "-Wno-traditional",
567 "-Wformat",
568 "-Wno-format",
569 "-Wchar-subscripts",
570 "-Wno-char-subscripts",
571 "-Wconversion",
572 "-Wno-conversion",
573 "-Wparentheses",
574 "-Wno-parentheses",
575 "-Wcomment",
576 "-Wno-comment",
577 "-Wcomments",
578 "-Wno-comments",
579 "-Wtrigraphs",
580 "-Wno-trigraphs",
581 "-Wimport",
582 "-Wno-import",
f41372d4
RS
583 "-Wmissing-braces",
584 "-Wno-missing-braces",
b99933c7
RS
585 "-Wall",
586
587 /* These are for C++. */
6419d860
RS
588 "-+e0", /* gcc.c tacks the `-' on the front. */
589 "-+e1",
590 "-+e2",
b99933c7
RS
591 "-fsave-memoized",
592 "-fno-save-memoized",
b99933c7
RS
593 "-fcadillac",
594 "-fno-cadillac",
595 "-fgc",
596 "-fno-gc",
597 "-flabels-ok",
598 "-fno-labels-ok",
599 "-fstats",
600 "-fno-stats",
601 "-fthis-is-variable",
602 "-fno-this-is-variable",
603 "-fstrict-prototype",
604 "-fno-strict-prototype",
605 "-fall-virtual",
606 "-fno-all-virtual",
607 "-fmemoize-lookups",
608 "-fno-memoize-lookups",
609 "-felide-constructors",
610 "-fno-elide-constructors",
611 "-finline-debug",
612 "-fno-inline-debug",
613 "-fhandle-exceptions",
614 "-fno-handle-exceptions",
615 "-fansi-exceptions",
616 "-fno-ansi-exceptions",
617 "-fspring-exceptions",
618 "-fno-spring-exceptions",
619 "-fdefault-inline",
620 "-fno-default-inline",
621 "-fenum-int-equiv",
622 "-fno-enum-int-equiv",
623 "-fdossier",
624 "-fno-dossier",
625 "-fxref",
626 "-fno-xref",
627 "-fnonnull-objects",
628 "-fno-nonnull-objects",
17140e94
BK
629 "-fimplement-inlines",
630 "-fno-implement-inlines",
b99933c7
RS
631
632 "-Wreturn-type",
633 "-Wno-return-type",
634 "-Woverloaded-virtual",
635 "-Wno-overloaded-virtual",
636 "-Wenum-clash",
637 "-Wno-enum-clash",
a2468e45
BK
638 "-Wtemplate-debugging",
639 "-Wno-template-debugging",
65faa6a4
RS
640
641 /* these are for obj c */
642 "-lang-objc",
643 "-gen-decls",
f5309ddf
TW
644 "-fgnu-runtime",
645 "-fno-gnu-runtime",
646 "-fnext-runtime",
647 "-fno-next-runtime",
65faa6a4
RS
648 "-Wselector",
649 "-Wno-selector",
b800a01b
KKT
650 "-Wprotocol",
651 "-Wno-protocol",
b99933c7
RS
652 0
653};
4291d9c8
RS
654\f
655/* Options controlling warnings */
656
657/* Don't print warning messages. -w. */
658
659int inhibit_warnings = 0;
660
661/* Print various extra warnings. -W. */
662
663int extra_warnings = 0;
664
665/* Treat warnings as errors. -Werror. */
666
667int warnings_are_errors = 0;
668
669/* Nonzero to warn about unused local variables. */
670
671int warn_unused;
672
673/* Nonzero to warn about variables used before they are initialized. */
674
675int warn_uninitialized;
676
677/* Nonzero means warn about all declarations which shadow others. */
678
679int warn_shadow;
680
681/* Warn if a switch on an enum fails to have a case for every enum value. */
682
683int warn_switch;
684
685/* Nonzero means warn about function definitions that default the return type
686 or that use a null return and have a return-type other than void. */
687
688int warn_return_type;
689
690/* Nonzero means warn about pointer casts that increase the required
691 alignment of the target type (and might therefore lead to a crash
692 due to a misaligned access). */
693
694int warn_cast_align;
695
696/* Nonzero means warn about any identifiers that match in the first N
697 characters. The value N is in `id_clash_len'. */
698
699int warn_id_clash;
700int id_clash_len;
701
702/* Nonzero means warn if inline function is too large. */
703
704int warn_inline;
705
706/* Warn if a function returns an aggregate,
707 since there are often incompatible calling conventions for doing this. */
708
709int warn_aggregate_return;
710
711/* Likewise for -W. */
712
713struct { char *string; int *variable; int on_value;} W_options[] =
714{
715 {"unused", &warn_unused, 1},
716 {"error", &warnings_are_errors, 1},
717 {"shadow", &warn_shadow, 1},
718 {"switch", &warn_switch, 1},
4291d9c8
RS
719 {"aggregate-return", &warn_aggregate_return, 1},
720 {"cast-align", &warn_cast_align, 1},
f246a305
RS
721 {"uninitialized", &warn_uninitialized, 1},
722 {"inline", &warn_inline, 1}
4291d9c8
RS
723};
724\f
725/* Output files for assembler code (real compiler output)
726 and debugging dumps. */
727
728FILE *asm_out_file;
729FILE *aux_info_file;
730FILE *rtl_dump_file;
731FILE *jump_opt_dump_file;
732FILE *cse_dump_file;
733FILE *loop_dump_file;
734FILE *cse2_dump_file;
735FILE *flow_dump_file;
736FILE *combine_dump_file;
737FILE *sched_dump_file;
738FILE *local_reg_dump_file;
739FILE *global_reg_dump_file;
740FILE *sched2_dump_file;
741FILE *jump2_opt_dump_file;
742FILE *dbr_sched_dump_file;
743FILE *stack_reg_dump_file;
744
745/* Time accumulators, to count the total time spent in various passes. */
746
747int parse_time;
748int varconst_time;
749int integration_time;
750int jump_time;
751int cse_time;
752int loop_time;
753int cse2_time;
754int flow_time;
755int combine_time;
756int sched_time;
757int local_alloc_time;
758int global_alloc_time;
759int sched2_time;
760int dbr_sched_time;
761int shorten_branch_time;
762int stack_reg_time;
763int final_time;
764int symout_time;
765int dump_time;
766\f
767/* Return time used so far, in microseconds. */
768
769int
770get_run_time ()
771{
772#ifdef USG
773 struct tms tms;
774#else
775#ifndef VMS
776 struct rusage rusage;
777#else /* VMS */
778 struct
779 {
780 int proc_user_time;
781 int proc_system_time;
782 int child_user_time;
783 int child_system_time;
784 } vms_times;
785#endif
786#endif
787
788 if (quiet_flag)
789 return 0;
790
791#ifdef USG
792 times (&tms);
793 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
794#else
795#ifndef VMS
796 getrusage (0, &rusage);
797 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
798 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
799#else /* VMS */
800 times (&vms_times);
801 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
802#endif
803#endif
804}
805
806#define TIMEVAR(VAR, BODY) \
807do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
808
809void
810print_time (str, total)
811 char *str;
812 int total;
813{
814 fprintf (stderr,
815 "time in %s: %d.%06d\n",
816 str, total / 1000000, total % 1000000);
817}
818
819/* Count an error or warning. Return 1 if the message should be printed. */
820
821int
822count_error (warningp)
823 int warningp;
824{
825 if (warningp && inhibit_warnings)
826 return 0;
827
828 if (warningp && !warnings_are_errors)
829 warningcount++;
830 else
831 {
832 static int warning_message = 0;
833
834 if (warningp && !warning_message)
835 {
836 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
837 warning_message = 1;
838 }
839 errorcount++;
840 }
841
842 return 1;
843}
844
845/* Print a fatal error message. NAME is the text.
846 Also include a system error message based on `errno'. */
847
848void
849pfatal_with_name (name)
850 char *name;
851{
852 fprintf (stderr, "%s: ", progname);
853 perror (name);
854 exit (35);
855}
856
857void
858fatal_io_error (name)
859 char *name;
860{
861 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
862 exit (35);
863}
864
865void
866fatal (s, v)
867 char *s;
868 int v;
869{
870 error (s, v);
871 exit (34);
872}
873
874/* Called to give a better error message when we don't have an insn to match
875 what we are looking for or if the insn's constraints aren't satisfied,
876 rather than just calling abort(). */
877
878void
879fatal_insn_not_found (insn)
880 rtx insn;
881{
882 if (INSN_CODE (insn) < 0)
883 error ("internal error--unrecognizable insn:", 0);
884 else
885 error ("internal error--insn does not satisfy its constraints:", 0);
886 debug_rtx (insn);
887 if (asm_out_file)
888 fflush (asm_out_file);
889 if (aux_info_file)
890 fflush (aux_info_file);
891 if (rtl_dump_file)
892 fflush (rtl_dump_file);
893 if (jump_opt_dump_file)
894 fflush (jump_opt_dump_file);
895 if (cse_dump_file)
896 fflush (cse_dump_file);
897 if (loop_dump_file)
898 fflush (loop_dump_file);
899 if (cse2_dump_file)
900 fflush (cse2_dump_file);
901 if (flow_dump_file)
902 fflush (flow_dump_file);
903 if (combine_dump_file)
904 fflush (combine_dump_file);
905 if (sched_dump_file)
906 fflush (sched_dump_file);
907 if (local_reg_dump_file)
908 fflush (local_reg_dump_file);
909 if (global_reg_dump_file)
910 fflush (global_reg_dump_file);
911 if (sched2_dump_file)
912 fflush (sched2_dump_file);
913 if (jump2_opt_dump_file)
914 fflush (jump2_opt_dump_file);
915 if (dbr_sched_dump_file)
916 fflush (dbr_sched_dump_file);
917 if (stack_reg_dump_file)
918 fflush (stack_reg_dump_file);
919 abort ();
920}
921
922/* This is the default decl_printable_name function. */
923
924static char *
925decl_name (decl, kind)
926 tree decl;
927 char **kind;
928{
929 return IDENTIFIER_POINTER (DECL_NAME (decl));
930}
931\f
932static int need_error_newline;
933
934/* Function of last error message;
935 more generally, function such that if next error message is in it
936 then we don't have to mention the function name. */
937static tree last_error_function = NULL;
938
939/* Used to detect when input_file_stack has changed since last described. */
940static int last_error_tick;
941
942/* Called when the start of a function definition is parsed,
943 this function prints on stderr the name of the function. */
944
945void
946announce_function (decl)
947 tree decl;
948{
949 if (! quiet_flag)
950 {
951 char *junk;
952 if (rtl_dump_and_exit)
953 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
954 else
955 fprintf (stderr, " %s", (*decl_printable_name) (decl, &junk));
956 fflush (stderr);
957 need_error_newline = 1;
958 last_error_function = current_function_decl;
959 }
960}
961
962/* Prints out, if necessary, the name of the current function
963 which caused an error. Called from all error and warning functions. */
964
965void
966report_error_function (file)
967 char *file;
968{
969 struct file_stack *p;
970
971 if (need_error_newline)
972 {
973 fprintf (stderr, "\n");
974 need_error_newline = 0;
975 }
976
977 if (last_error_function != current_function_decl)
978 {
979 char *kind = "function";
980 if (current_function_decl != 0
981 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
982 kind = "method";
983
984 if (file)
985 fprintf (stderr, "%s: ", file);
986
987 if (current_function_decl == NULL)
988 fprintf (stderr, "At top level:\n");
989 else
990 {
991 char *name = (*decl_printable_name) (current_function_decl, &kind);
992 fprintf (stderr, "In %s `%s':\n", kind, name);
993 }
994
995 last_error_function = current_function_decl;
996 }
997 if (input_file_stack && input_file_stack->next != 0
998 && input_file_stack_tick != last_error_tick)
999 {
1000 fprintf (stderr, "In file included");
1001 for (p = input_file_stack->next; p; p = p->next)
1002 {
1003 fprintf (stderr, " from %s:%d", p->name, p->line);
1004 if (p->next)
1005 fprintf (stderr, ",");
1006 }
1007 fprintf (stderr, ":\n");
1008 last_error_tick = input_file_stack_tick;
1009 }
1010}
1011
1012/* Report an error at the current line number.
37366632
RK
1013 S is a string and V and V2 are args for `printf'. We use HOST_WIDE_INT
1014 as the type for these args assuming it is wide enough to hold a
1015 pointer. This isn't terribly portable, but is the best we can do
1016 without vprintf universally available. */
4291d9c8
RS
1017
1018void
1019error (s, v, v2)
1020 char *s;
37366632
RK
1021 HOST_WIDE_INT v; /* Also used as pointer */
1022 HOST_WIDE_INT v2; /* Also used as pointer */
4291d9c8
RS
1023{
1024 error_with_file_and_line (input_filename, lineno, s, v, v2);
1025}
1026
1027/* Report an error at line LINE of file FILE.
1028 S and V are a string and an arg for `printf'. */
1029
1030void
1031error_with_file_and_line (file, line, s, v, v2)
1032 char *file;
1033 int line;
1034 char *s;
37366632
RK
1035 HOST_WIDE_INT v;
1036 HOST_WIDE_INT v2;
4291d9c8
RS
1037{
1038 count_error (0);
1039
1040 report_error_function (file);
1041
1042 if (file)
1043 fprintf (stderr, "%s:%d: ", file, line);
1044 else
1045 fprintf (stderr, "%s: ", progname);
1046 fprintf (stderr, s, v, v2);
1047 fprintf (stderr, "\n");
1048}
1049
1050/* Report an error at the declaration DECL.
37366632
RK
1051 S and V are a string and an arg which uses %s to substitute
1052 the declaration name. */
4291d9c8
RS
1053
1054void
1055error_with_decl (decl, s, v)
1056 tree decl;
1057 char *s;
37366632 1058 HOST_WIDE_INT v;
4291d9c8
RS
1059{
1060 char *junk;
1061 count_error (0);
1062
1063 report_error_function (DECL_SOURCE_FILE (decl));
1064
1065 fprintf (stderr, "%s:%d: ",
1066 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1067
1068 if (DECL_NAME (decl))
1069 fprintf (stderr, s, (*decl_printable_name) (decl, &junk), v);
1070 else
1071 fprintf (stderr, s, "((anonymous))", v);
1072 fprintf (stderr, "\n");
1073}
1074
1075/* Report an error at the line number of the insn INSN.
1076 S and V are a string and an arg for `printf'.
1077 This is used only when INSN is an `asm' with operands,
1078 and each ASM_OPERANDS records its own source file and line. */
1079
1080void
1081error_for_asm (insn, s, v, v2)
1082 rtx insn;
1083 char *s;
37366632
RK
1084 HOST_WIDE_INT v; /* Also used as pointer */
1085 HOST_WIDE_INT v2; /* Also used as pointer */
4291d9c8
RS
1086{
1087 char *filename;
1088 int line;
1089 rtx body = PATTERN (insn);
1090 rtx asmop;
1091
1092 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1093 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1094 asmop = SET_SRC (body);
1095 else if (GET_CODE (body) == ASM_OPERANDS)
1096 asmop = body;
1097 else if (GET_CODE (body) == PARALLEL
1098 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1099 asmop = SET_SRC (XVECEXP (body, 0, 0));
1100 else if (GET_CODE (body) == PARALLEL
1101 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1102 asmop = XVECEXP (body, 0, 0);
1103
1104 filename = ASM_OPERANDS_SOURCE_FILE (asmop);
1105 line = ASM_OPERANDS_SOURCE_LINE (asmop);
1106
1107 error_with_file_and_line (filename, line, s, v, v2);
1108}
1109
1110/* Report a warning at line LINE.
1111 S and V are a string and an arg for `printf'. */
1112
1113void
1114warning_with_file_and_line (file, line, s, v, v2, v3)
1115 char *file;
1116 int line;
1117 char *s;
37366632 1118 HOST_WIDE_INT v, v2, v3;
4291d9c8
RS
1119{
1120 if (count_error (1) == 0)
1121 return;
1122
1123 report_error_function (file);
1124
1125 if (file)
1126 fprintf (stderr, "%s:%d: ", file, line);
1127 else
1128 fprintf (stderr, "%s: ", progname);
1129
1130 fprintf (stderr, "warning: ");
1131 fprintf (stderr, s, v, v2, v3);
1132 fprintf (stderr, "\n");
1133}
1134
1135/* Report a warning at the current line number.
1136 S and V are a string and an arg for `printf'. */
1137
1138void
1139warning (s, v, v2, v3)
1140 char *s;
37366632 1141 HOST_WIDE_INT v, v2, v3; /* Also used as pointer */
4291d9c8
RS
1142{
1143 warning_with_file_and_line (input_filename, lineno, s, v, v2, v3);
1144}
1145
1146/* Report a warning at the declaration DECL.
1147 S is string which uses %s to substitute the declaration name.
1148 V is a second parameter that S can refer to. */
1149
1150void
1151warning_with_decl (decl, s, v)
1152 tree decl;
1153 char *s;
37366632 1154 HOST_WIDE_INT v;
4291d9c8
RS
1155{
1156 char *junk;
1157
1158 if (count_error (1) == 0)
1159 return;
1160
1161 report_error_function (DECL_SOURCE_FILE (decl));
1162
1163 fprintf (stderr, "%s:%d: ",
1164 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1165
1166 fprintf (stderr, "warning: ");
1167 if (DECL_NAME (decl))
1168 fprintf (stderr, s, (*decl_printable_name) (decl, &junk), v);
1169 else
1170 fprintf (stderr, s, "((anonymous))", v);
1171 fprintf (stderr, "\n");
1172}
1173
1174/* Report a warning at the line number of the insn INSN.
1175 S and V are a string and an arg for `printf'.
1176 This is used only when INSN is an `asm' with operands,
1177 and each ASM_OPERANDS records its own source file and line. */
1178
1179void
1180warning_for_asm (insn, s, v, v2)
1181 rtx insn;
1182 char *s;
37366632
RK
1183 HOST_WIDE_INT v; /* Also used as pointer */
1184 HOST_WIDE_INT v2; /* Also used as pointer */
4291d9c8
RS
1185{
1186 char *filename;
1187 int line;
1188 rtx body = PATTERN (insn);
1189 rtx asmop;
1190
1191 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1192 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1193 asmop = SET_SRC (body);
1194 else if (GET_CODE (body) == ASM_OPERANDS)
1195 asmop = body;
1196 else if (GET_CODE (body) == PARALLEL
1197 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1198 asmop = SET_SRC (XVECEXP (body, 0, 0));
1199 else if (GET_CODE (body) == PARALLEL
1200 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1201 asmop = XVECEXP (body, 0, 0);
1202
1203 filename = ASM_OPERANDS_SOURCE_FILE (asmop);
1204 line = ASM_OPERANDS_SOURCE_LINE (asmop);
1205
1206 warning_with_file_and_line (filename, line, s, v, v2);
1207}
1208\f
1209/* These functions issue either warnings or errors depending on
1210 -pedantic-errors. */
1211
1212void
1213pedwarn (s, v, v2)
1214 char *s;
37366632
RK
1215 HOST_WIDE_INT v; /* Also used as pointer */
1216 HOST_WIDE_INT v2;
4291d9c8
RS
1217{
1218 if (flag_pedantic_errors)
1219 error (s, v, v2);
1220 else
1221 warning (s, v, v2);
1222}
1223
1224void
1225pedwarn_with_decl (decl, s, v)
1226 tree decl;
1227 char *s;
37366632 1228 HOST_WIDE_INT v;
4291d9c8
RS
1229{
1230 if (flag_pedantic_errors)
1231 error_with_decl (decl, s, v);
1232 else
1233 warning_with_decl (decl, s, v);
1234}
1235
1236void
1237pedwarn_with_file_and_line (file, line, s, v, v2)
1238 char *file;
1239 int line;
1240 char *s;
37366632
RK
1241 HOST_WIDE_INT v;
1242 HOST_WIDE_INT v2;
4291d9c8
RS
1243{
1244 if (flag_pedantic_errors)
1245 error_with_file_and_line (file, line, s, v, v2);
1246 else
1247 warning_with_file_and_line (file, line, s, v, v2);
1248}
1249
1250/* Apologize for not implementing some feature.
1251 S, V, and V2 are a string and args for `printf'. */
1252
1253void
1254sorry (s, v, v2)
1255 char *s;
37366632 1256 HOST_WIDE_INT v, v2;
4291d9c8
RS
1257{
1258 sorrycount++;
1259 if (input_filename)
1260 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1261 else
1262 fprintf (stderr, "%s: ", progname);
1263
1264 fprintf (stderr, "sorry, not implemented: ");
1265 fprintf (stderr, s, v, v2);
1266 fprintf (stderr, "\n");
1267}
1268
1269/* Apologize for not implementing some feature, then quit.
1270 S, V, and V2 are a string and args for `printf'. */
1271
1272void
1273really_sorry (s, v, v2)
1274 char *s;
37366632 1275 HOST_WIDE_INT v, v2;
4291d9c8
RS
1276{
1277 if (input_filename)
1278 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1279 else
c10afc44 1280 fprintf (stderr, "%s: ", progname);
4291d9c8
RS
1281
1282 fprintf (stderr, "sorry, not implemented: ");
1283 fprintf (stderr, s, v, v2);
1284 fatal (" (fatal)\n");
1285}
1286\f
1287/* More 'friendly' abort that prints the line and file.
1288 config.h can #define abort fancy_abort if you like that sort of thing.
1289
1290 I don't think this is actually a good idea.
1291 Other sorts of crashes will look a certain way.
1292 It is a good thing if crashes from calling abort look the same way.
1293 -- RMS */
1294
1295void
1296fancy_abort ()
1297{
1298 fatal ("internal gcc abort");
1299}
1300
1301/* This calls abort and is used to avoid problems when abort if a macro.
1302 It is used when we need to pass the address of abort. */
1303
1304void
1305do_abort ()
1306{
1307 abort ();
1308}
1309
1310/* When `malloc.c' is compiled with `rcheck' defined,
1311 it calls this function to report clobberage. */
1312
1313void
1314botch (s)
1315{
1316 abort ();
1317}
1318
1319/* Same as `malloc' but report error if no memory available. */
1320
4b980e20 1321char *
4291d9c8
RS
1322xmalloc (size)
1323 unsigned size;
1324{
4b980e20 1325 register char *value = (char *) malloc (size);
4291d9c8
RS
1326 if (value == 0)
1327 fatal ("virtual memory exhausted");
1328 return value;
1329}
1330
1331/* Same as `realloc' but report error if no memory available. */
1332
4b980e20 1333char *
4291d9c8
RS
1334xrealloc (ptr, size)
1335 char *ptr;
1336 int size;
1337{
4b980e20 1338 char *result = (char *) realloc (ptr, size);
4291d9c8
RS
1339 if (!result)
1340 fatal ("virtual memory exhausted");
1341 return result;
1342}
1343\f
1344/* Return the logarithm of X, base 2, considering X unsigned,
37366632
RK
1345 if X is a power of 2. Otherwise, returns -1.
1346
1347 This should be used via the `exact_log2' macro. */
4291d9c8
RS
1348
1349int
37366632
RK
1350exact_log2_wide (x)
1351 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1352{
1353 register int log = 0;
1354 /* Test for 0 or a power of 2. */
1355 if (x == 0 || x != (x & -x))
1356 return -1;
1357 while ((x >>= 1) != 0)
1358 log++;
1359 return log;
1360}
1361
1362/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
37366632
RK
1363 If X is 0, return -1.
1364
1365 This should be used via the floor_log2 macro. */
4291d9c8
RS
1366
1367int
37366632
RK
1368floor_log2_wide (x)
1369 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1370{
1371 register int log = -1;
1372 while (x != 0)
1373 log++,
1374 x >>= 1;
1375 return log;
1376}
1377
1378int float_handled;
1379jmp_buf float_handler;
1380
1381/* Specify where to longjmp to when a floating arithmetic error happens.
1382 If HANDLER is 0, it means don't handle the errors any more. */
1383
1384void
1385set_float_handler (handler)
1386 jmp_buf handler;
1387{
1388 float_handled = (handler != 0);
1389 if (handler)
1390 bcopy (handler, float_handler, sizeof (float_handler));
1391}
1392
bff4b641
RS
1393/* Specify, in HANDLER, where to longjmp to when a floating arithmetic
1394 error happens, pushing the previous specification into OLD_HANDLER.
1395 Return an indication of whether there was a previous handler in effect. */
1396
1397int
1398push_float_handler (handler, old_handler)
dc2b15dc 1399 jmp_buf handler, old_handler;
bff4b641
RS
1400{
1401 int was_handled = float_handled;
1402
1403 float_handled = 1;
1404 if (was_handled)
1405 bcopy (float_handler, old_handler, sizeof (float_handler));
1406 bcopy (handler, float_handler, sizeof (float_handler));
1407 return was_handled;
1408}
1409
1410/* Restore the previous specification of whether and where to longjmp to
1411 when a floating arithmetic error happens. */
1412
1413void
1414pop_float_handler (handled, handler)
1415 int handled;
1416 jmp_buf handler;
1417{
1418 float_handled = handled;
1419 if (handled)
1420 bcopy (handler, float_handler, sizeof (float_handler));
1421}
1422
4291d9c8
RS
1423/* Signals actually come here. */
1424
1425static void
1426float_signal (signo)
1427 /* If this is missing, some compilers complain. */
1428 int signo;
1429{
1430 if (float_handled == 0)
1431 abort ();
1432#if defined (USG) || defined (hpux)
1433 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
1434#endif
1435 float_handled = 0;
1436 signal (SIGFPE, float_signal);
1437 longjmp (float_handler, 1);
1438}
1439
1440/* Handler for SIGPIPE. */
1441
1442static void
1443pipe_closed (signo)
1444 /* If this is missing, some compilers complain. */
1445 int signo;
1446{
1447 fatal ("output pipe has been closed");
1448}
1449
1450/* Strip off a legitimate source ending from the input string NAME of
1451 length LEN. */
1452
1453void
1454strip_off_ending (name, len)
1455 char *name;
1456 int len;
1457{
1458 if (len > 2 && ! strcmp (".c", name + len - 2))
1459 name[len - 2] = 0;
1460 else if (len > 2 && ! strcmp (".m", name + len - 2))
1461 name[len - 2] = 0;
1462 else if (len > 2 && ! strcmp (".i", name + len - 2))
1463 name[len - 2] = 0;
1464 else if (len > 3 && ! strcmp (".ii", name + len - 3))
1465 name[len - 3] = 0;
1466 else if (len > 3 && ! strcmp (".co", name + len - 3))
1467 name[len - 3] = 0;
1468 else if (len > 3 && ! strcmp (".cc", name + len - 3))
1469 name[len - 3] = 0;
9cc00e36
RS
1470 else if (len > 2 && ! strcmp (".C", name + len - 2))
1471 name[len - 2] = 0;
1472 else if (len > 4 && ! strcmp (".cxx", name + len - 4))
1473 name[len - 4] = 0;
4291d9c8
RS
1474 else if (len > 2 && ! strcmp (".f", name + len - 2))
1475 name[len - 2] = 0;
1476 else if (len > 4 && ! strcmp (".ada", name + len - 4))
1477 name[len - 4] = 0;
be07ab12
RK
1478 else if (len > 4 && ! strcmp (".atr", name + len - 4))
1479 name[len - 4] = 0;
4291d9c8
RS
1480}
1481
1482/* Output a file name in the form wanted by System V. */
1483
1484void
1485output_file_directive (asm_file, input_name)
1486 FILE *asm_file;
1487 char *input_name;
1488{
1489 int len = strlen (input_name);
1490 char *na = input_name + len;
1491
1492 /* NA gets INPUT_NAME sans directory names. */
1493 while (na > input_name)
1494 {
1495 if (na[-1] == '/')
1496 break;
1497 na--;
1498 }
1499
1500#ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1501 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1502#else
1503#ifdef ASM_OUTPUT_SOURCE_FILENAME
1504 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1505#else
1506 fprintf (asm_file, "\t.file\t\"%s\"\n", na);
1507#endif
1508#endif
1509}
1510\f
d0d4af87
MS
1511/* Routine to build language identifier for object file. */
1512static void
1513output_lang_identify (asm_out_file)
1514 FILE *asm_out_file;
1515{
1516 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
1517 char *s = (char *) alloca (len);
1518 sprintf (s, "__gnu_compiled_%s", lang_identify ());
1519 ASM_OUTPUT_LABEL (asm_out_file, s);
1520}
1521
4291d9c8
RS
1522/* Compile an entire file of output from cpp, named NAME.
1523 Write a file of assembly output and various debugging dumps. */
1524
1525static void
1526compile_file (name)
1527 char *name;
1528{
1529 tree globals;
1530 int start_time;
1531 int dump_base_name_length;
4291d9c8
RS
1532
1533 int name_specified = name != 0;
1534
1535 if (dump_base_name == 0)
1536 dump_base_name = name ? name : "gccdump";
1537 dump_base_name_length = strlen (dump_base_name);
1538
1539 parse_time = 0;
1540 varconst_time = 0;
1541 integration_time = 0;
1542 jump_time = 0;
1543 cse_time = 0;
1544 loop_time = 0;
1545 cse2_time = 0;
1546 flow_time = 0;
1547 combine_time = 0;
1548 sched_time = 0;
1549 local_alloc_time = 0;
1550 global_alloc_time = 0;
1551 sched2_time = 0;
1552 dbr_sched_time = 0;
1553 shorten_branch_time = 0;
1554 stack_reg_time = 0;
1555 final_time = 0;
1556 symout_time = 0;
1557 dump_time = 0;
1558
1559 /* Open input file. */
1560
1561 if (name == 0 || !strcmp (name, "-"))
1562 {
1563 finput = stdin;
1564 name = "stdin";
1565 }
1566 else
1567 finput = fopen (name, "r");
1568 if (finput == 0)
1569 pfatal_with_name (name);
1570
282ea52a 1571#ifdef IO_BUFFER_SIZE
d7cedf4b 1572 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
282ea52a
RS
1573#endif
1574
4291d9c8
RS
1575 /* Initialize data in various passes. */
1576
1577 init_obstacks ();
1578 init_tree_codes ();
1579 init_lex ();
1580 init_rtl ();
1581 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1582 || debug_info_level == DINFO_LEVEL_VERBOSE);
1583 init_decl_processing ();
1584 init_optabs ();
1585 init_stmt ();
1586 init_expmed ();
4fa52007 1587 init_expr_once ();
4291d9c8
RS
1588 init_loop ();
1589 init_reload ();
1590
1591 if (flag_caller_saves)
1592 init_caller_save ();
1593
f246a305
RS
1594 /* If auxiliary info generation is desired, open the output file.
1595 This goes in the same directory as the source file--unlike
1596 all the other output files. */
4291d9c8
RS
1597 if (flag_gen_aux_info)
1598 {
4291d9c8
RS
1599 aux_info_file = fopen (aux_info_file_name, "w");
1600 if (aux_info_file == 0)
1601 pfatal_with_name (aux_info_file_name);
1602 }
1603
1604 /* If rtl dump desired, open the output file. */
1605 if (rtl_dump)
1606 {
1607 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1608 strcpy (dumpname, dump_base_name);
1609 strcat (dumpname, ".rtl");
1610 rtl_dump_file = fopen (dumpname, "w");
1611 if (rtl_dump_file == 0)
1612 pfatal_with_name (dumpname);
1613 }
1614
1615 /* If jump_opt dump desired, open the output file. */
1616 if (jump_opt_dump)
1617 {
1618 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1619 strcpy (dumpname, dump_base_name);
1620 strcat (dumpname, ".jump");
1621 jump_opt_dump_file = fopen (dumpname, "w");
1622 if (jump_opt_dump_file == 0)
1623 pfatal_with_name (dumpname);
1624 }
1625
1626 /* If cse dump desired, open the output file. */
1627 if (cse_dump)
1628 {
1629 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1630 strcpy (dumpname, dump_base_name);
1631 strcat (dumpname, ".cse");
1632 cse_dump_file = fopen (dumpname, "w");
1633 if (cse_dump_file == 0)
1634 pfatal_with_name (dumpname);
1635 }
1636
1637 /* If loop dump desired, open the output file. */
1638 if (loop_dump)
1639 {
1640 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1641 strcpy (dumpname, dump_base_name);
1642 strcat (dumpname, ".loop");
1643 loop_dump_file = fopen (dumpname, "w");
1644 if (loop_dump_file == 0)
1645 pfatal_with_name (dumpname);
1646 }
1647
1648 /* If cse2 dump desired, open the output file. */
1649 if (cse2_dump)
1650 {
1651 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1652 strcpy (dumpname, dump_base_name);
1653 strcat (dumpname, ".cse2");
1654 cse2_dump_file = fopen (dumpname, "w");
1655 if (cse2_dump_file == 0)
1656 pfatal_with_name (dumpname);
1657 }
1658
1659 /* If flow dump desired, open the output file. */
1660 if (flow_dump)
1661 {
1662 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1663 strcpy (dumpname, dump_base_name);
1664 strcat (dumpname, ".flow");
1665 flow_dump_file = fopen (dumpname, "w");
1666 if (flow_dump_file == 0)
1667 pfatal_with_name (dumpname);
1668 }
1669
1670 /* If combine dump desired, open the output file. */
1671 if (combine_dump)
1672 {
1673 register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
1674 strcpy (dumpname, dump_base_name);
1675 strcat (dumpname, ".combine");
1676 combine_dump_file = fopen (dumpname, "w");
1677 if (combine_dump_file == 0)
1678 pfatal_with_name (dumpname);
1679 }
1680
1681 /* If scheduling dump desired, open the output file. */
1682 if (sched_dump)
1683 {
1684 register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
1685 strcpy (dumpname, dump_base_name);
1686 strcat (dumpname, ".sched");
1687 sched_dump_file = fopen (dumpname, "w");
1688 if (sched_dump_file == 0)
1689 pfatal_with_name (dumpname);
1690 }
1691
1692 /* If local_reg dump desired, open the output file. */
1693 if (local_reg_dump)
1694 {
1695 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1696 strcpy (dumpname, dump_base_name);
1697 strcat (dumpname, ".lreg");
1698 local_reg_dump_file = fopen (dumpname, "w");
1699 if (local_reg_dump_file == 0)
1700 pfatal_with_name (dumpname);
1701 }
1702
1703 /* If global_reg dump desired, open the output file. */
1704 if (global_reg_dump)
1705 {
1706 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1707 strcpy (dumpname, dump_base_name);
1708 strcat (dumpname, ".greg");
1709 global_reg_dump_file = fopen (dumpname, "w");
1710 if (global_reg_dump_file == 0)
1711 pfatal_with_name (dumpname);
1712 }
1713
1714 /* If 2nd scheduling dump desired, open the output file. */
1715 if (sched2_dump)
1716 {
1717 register char *dumpname = (char *) xmalloc (dump_base_name_length + 8);
1718 strcpy (dumpname, dump_base_name);
1719 strcat (dumpname, ".sched2");
1720 sched2_dump_file = fopen (dumpname, "w");
1721 if (sched2_dump_file == 0)
1722 pfatal_with_name (dumpname);
1723 }
1724
1725 /* If jump2_opt dump desired, open the output file. */
1726 if (jump2_opt_dump)
1727 {
1728 register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
1729 strcpy (dumpname, dump_base_name);
1730 strcat (dumpname, ".jump2");
1731 jump2_opt_dump_file = fopen (dumpname, "w");
1732 if (jump2_opt_dump_file == 0)
1733 pfatal_with_name (dumpname);
1734 }
1735
1736 /* If dbr_sched dump desired, open the output file. */
1737 if (dbr_sched_dump)
1738 {
1739 register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
1740 strcpy (dumpname, dump_base_name);
1741 strcat (dumpname, ".dbr");
1742 dbr_sched_dump_file = fopen (dumpname, "w");
1743 if (dbr_sched_dump_file == 0)
1744 pfatal_with_name (dumpname);
1745 }
1746
1747#ifdef STACK_REGS
1748
1749 /* If stack_reg dump desired, open the output file. */
1750 if (stack_reg_dump)
1751 {
1752 register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
1753 strcpy (dumpname, dump_base_name);
1754 strcat (dumpname, ".stack");
1755 stack_reg_dump_file = fopen (dumpname, "w");
1756 if (stack_reg_dump_file == 0)
1757 pfatal_with_name (dumpname);
1758 }
1759
1760#endif
1761
1762 /* Open assembler code output file. */
1763
1764 if (! name_specified && asm_file_name == 0)
1765 asm_out_file = stdout;
1766 else
1767 {
1768 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1769 int len = strlen (dump_base_name);
1770 strcpy (dumpname, dump_base_name);
1771 strip_off_ending (dumpname, len);
1772 strcat (dumpname, ".s");
1773 if (asm_file_name == 0)
1774 {
1775 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
1776 strcpy (asm_file_name, dumpname);
1777 }
1778 if (!strcmp (asm_file_name, "-"))
1779 asm_out_file = stdout;
1780 else
1781 asm_out_file = fopen (asm_file_name, "w");
1782 if (asm_out_file == 0)
1783 pfatal_with_name (asm_file_name);
1784 }
1785
f246a305 1786#ifdef IO_BUFFER_SIZE
d7cedf4b
RS
1787 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
1788 _IOFBF, IO_BUFFER_SIZE);
f246a305
RS
1789#endif
1790
4291d9c8
RS
1791 input_filename = name;
1792
1793 /* Perform language-specific initialization.
1794 This may set main_input_filename. */
1795 lang_init ();
1796
1797 /* If the input doesn't start with a #line, use the input name
1798 as the official input file name. */
1799 if (main_input_filename == 0)
1800 main_input_filename = name;
1801
1802 /* Put an entry on the input file stack for the main input file. */
1803 input_file_stack
1804 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1805 input_file_stack->next = 0;
1806 input_file_stack->name = input_filename;
1807
1808 ASM_FILE_START (asm_out_file);
1809
1810 /* Output something to inform GDB that this compilation was by GCC. */
1811#ifndef ASM_IDENTIFY_GCC
1812 fprintf (asm_out_file, "gcc2_compiled.:\n");
1813#else
1814 ASM_IDENTIFY_GCC (asm_out_file);
1815#endif
d0d4af87
MS
1816
1817 /* Output something to identify which front-end produced this file. */
1818#ifdef ASM_IDENTIFY_LANGUAGE
1819 ASM_IDENTIFY_LANGUAGE (asm_out_file);
1820#endif
1821
bd405e3e
RS
1822/* ??? Note: There used to be a conditional here
1823 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
1824 This was to guarantee separation between gcc_compiled. and
1825 the first function, for the sake of dbx on Suns.
1826 However, having the extra zero here confused the Emacs
1827 code for unexec, and might confuse other programs too.
1828 Therefore, I took out that change.
1829 In future versions we should find another way to solve
1830 that dbx problem. -- rms, 23 May 93. */
1831
4291d9c8
RS
1832 /* Don't let the first function fall at the same address
1833 as gcc_compiled., if profiling. */
1834 if (profile_flag || profile_block_flag)
1835 assemble_zeros (UNITS_PER_WORD);
1836
1837 /* If dbx symbol table desired, initialize writing it
1838 and output the predefined types. */
f246a305
RS
1839#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1840 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
1841 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
1842 getdecls ()));
1843#endif
1844#ifdef SDB_DEBUGGING_INFO
1845 if (write_symbols == SDB_DEBUG)
1846 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
1847 getdecls ()));
1848#endif
1849#ifdef DWARF_DEBUGGING_INFO
1850 if (write_symbols == DWARF_DEBUG)
1851 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
1852#endif
1853
1854 /* Initialize yet another pass. */
1855
1856 init_final (main_input_filename);
1857
1858 start_time = get_run_time ();
1859
1860 /* Call the parser, which parses the entire file
1861 (calling rest_of_compilation for each function). */
1862
1863 if (yyparse () != 0)
1864 if (errorcount == 0)
1865 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
1866
1867 /* Compilation is now finished except for writing
1868 what's left of the symbol table output. */
1869
1870 parse_time += get_run_time () - start_time;
1871
1872 parse_time -= integration_time;
1873 parse_time -= varconst_time;
1874
1875 globals = getdecls ();
1876
1877 /* Really define vars that have had only a tentative definition.
1878 Really output inline functions that must actually be callable
1879 and have not been output so far. */
1880
1881 {
1882 int len = list_length (globals);
1883 tree *vec = (tree *) alloca (sizeof (tree) * len);
1884 int i;
1885 tree decl;
1886
1887 /* Process the decls in reverse order--earliest first.
1888 Put them into VEC from back to front, then take out from front. */
1889
1890 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
1891 vec[len - i - 1] = decl;
1892
1893 for (i = 0; i < len; i++)
1894 {
1895 decl = vec[i];
488b1f4f
RS
1896 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
1897 && incomplete_decl_finalize_hook != 0)
2b599527
RS
1898 (*incomplete_decl_finalize_hook) (decl);
1899
4291d9c8
RS
1900 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1901 && ! TREE_ASM_WRITTEN (decl))
1902 {
1903 /* Don't write out static consts, unless we used them.
1904 (This used to write them out only if the address was
1905 taken, but that was wrong; if the variable was simply
1906 referred to, it still needs to exist or else it will
1907 be undefined in the linker.) */
1908 if (! TREE_READONLY (decl)
1909 || TREE_PUBLIC (decl)
1910 || TREE_USED (decl)
1911 || TREE_ADDRESSABLE (decl)
1912 || TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl)))
37366632 1913 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
4291d9c8
RS
1914 else
1915 /* Cancel the RTL for this decl so that, if debugging info
1916 output for global variables is still to come,
1917 this one will be omitted. */
1918 DECL_RTL (decl) = NULL;
1919 }
1920
1921 if (TREE_CODE (decl) == FUNCTION_DECL
1922 && ! TREE_ASM_WRITTEN (decl)
1923 && DECL_INITIAL (decl) != 0
1924 && (TREE_ADDRESSABLE (decl)
1925 || TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl)))
216d5cdd 1926 && ! DECL_EXTERNAL (decl))
4291d9c8
RS
1927 output_inline_function (decl);
1928
ac266247
RS
1929 /* Warn about any function
1930 declared static but not defined.
1931 We don't warn about variables,
1932 because many programs have static variables
1933 that exist only to get some text into the object file. */
4291d9c8
RS
1934 if ((warn_unused
1935 || TREE_USED (decl)
1936 || (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl))))
ac266247 1937 && TREE_CODE (decl) == FUNCTION_DECL
4291d9c8 1938 && DECL_INITIAL (decl) == 0
216d5cdd 1939 && DECL_EXTERNAL (decl)
4291d9c8 1940 && ! TREE_PUBLIC (decl))
7d429c41
RS
1941 {
1942 pedwarn_with_decl (decl,
1943 "`%s' declared `static' but never defined");
1944 /* This symbol is effectively an "extern" declaration now. */
1945 TREE_PUBLIC (decl) = 1;
1946 assemble_external (decl);
1947
1948 }
4291d9c8
RS
1949 /* Warn about static fns or vars defined but not used,
1950 but not about inline functions
1951 since unused inline statics is normal practice. */
1952 if (warn_unused
1953 && (TREE_CODE (decl) == FUNCTION_DECL
1954 || TREE_CODE (decl) == VAR_DECL)
0c20aabf 1955 && ! DECL_IN_SYSTEM_HEADER (decl)
216d5cdd 1956 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
1957 && ! TREE_PUBLIC (decl)
1958 && ! TREE_USED (decl)
216d5cdd 1959 && ! DECL_INLINE (decl)
f2dabd38 1960 && ! DECL_REGISTER (decl)
4291d9c8
RS
1961 /* The TREE_USED bit for file-scope decls
1962 is kept in the identifier, to handle multiple
1963 external decls in different scopes. */
1964 && ! TREE_USED (DECL_NAME (decl)))
1965 warning_with_decl (decl, "`%s' defined but not used");
1966
1967#ifdef SDB_DEBUGGING_INFO
1968 /* The COFF linker can move initialized global vars to the end.
1969 And that can screw up the symbol ordering.
1970 By putting the symbols in that order to begin with,
1971 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
1972 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
1973 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
1974 && DECL_RTL (decl) != 0)
1975 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
1976
1977 /* Output COFF information for non-global
1978 file-scope initialized variables. */
1979 if (write_symbols == SDB_DEBUG
1980 && TREE_CODE (decl) == VAR_DECL
1981 && DECL_INITIAL (decl)
1982 && DECL_RTL (decl) != 0
1983 && GET_CODE (DECL_RTL (decl)) == MEM)
1984 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
1985#endif /* SDB_DEBUGGING_INFO */
1986#ifdef DWARF_DEBUGGING_INFO
6dc42e49 1987 /* Output DWARF information for file-scope tentative data object
4291d9c8
RS
1988 declarations, file-scope (extern) function declarations (which
1989 had no corresponding body) and file-scope tagged type declarations
1990 and definitions which have not yet been forced out. */
1991
1992 if (write_symbols == DWARF_DEBUG
1993 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
1994 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
1995#endif
1996 }
1997 }
1998
1999 /* Do dbx symbols */
f246a305
RS
2000#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2001 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2002 TIMEVAR (symout_time,
2003 {
2004 dbxout_finish (asm_out_file, main_input_filename);
2005 });
2006#endif
2007
2008#ifdef DWARF_DEBUGGING_INFO
2009 if (write_symbols == DWARF_DEBUG)
2010 TIMEVAR (symout_time,
2011 {
2012 dwarfout_finish ();
2013 });
2014#endif
2015
2016 /* Output some stuff at end of file if nec. */
2017
2018 end_final (main_input_filename);
2019
2020#ifdef ASM_FILE_END
2021 ASM_FILE_END (asm_out_file);
2022#endif
2023
2024 after_finish_compilation:
2025
2026 /* Language-specific end of compilation actions. */
2027
2028 lang_finish ();
2029
2030 /* Close the dump files. */
2031
2032 if (flag_gen_aux_info)
2033 {
2034 fclose (aux_info_file);
2035 if (errorcount)
2036 unlink (aux_info_file_name);
2037 }
2038
2039 if (rtl_dump)
2040 fclose (rtl_dump_file);
2041
2042 if (jump_opt_dump)
2043 fclose (jump_opt_dump_file);
2044
2045 if (cse_dump)
2046 fclose (cse_dump_file);
2047
2048 if (loop_dump)
2049 fclose (loop_dump_file);
2050
2051 if (cse2_dump)
2052 fclose (cse2_dump_file);
2053
2054 if (flow_dump)
2055 fclose (flow_dump_file);
2056
2057 if (combine_dump)
2058 {
2059 dump_combine_total_stats (combine_dump_file);
2060 fclose (combine_dump_file);
2061 }
2062
2063 if (sched_dump)
2064 fclose (sched_dump_file);
2065
2066 if (local_reg_dump)
2067 fclose (local_reg_dump_file);
2068
2069 if (global_reg_dump)
2070 fclose (global_reg_dump_file);
2071
2072 if (sched2_dump)
2073 fclose (sched2_dump_file);
2074
2075 if (jump2_opt_dump)
2076 fclose (jump2_opt_dump_file);
2077
2078 if (dbr_sched_dump)
2079 fclose (dbr_sched_dump_file);
2080
2081#ifdef STACK_REGS
2082 if (stack_reg_dump)
2083 fclose (stack_reg_dump_file);
2084#endif
2085
2086 /* Close non-debugging input and output files. Take special care to note
2087 whether fclose returns an error, since the pages might still be on the
2088 buffer chain while the file is open. */
2089
2090 fclose (finput);
2091 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2092 fatal_io_error (asm_file_name);
2093
2094 /* Print the times. */
2095
2096 if (! quiet_flag)
2097 {
2098 fprintf (stderr,"\n");
2099 print_time ("parse", parse_time);
2100 print_time ("integration", integration_time);
2101 print_time ("jump", jump_time);
2102 print_time ("cse", cse_time);
2103 print_time ("loop", loop_time);
2104 print_time ("cse2", cse2_time);
2105 print_time ("flow", flow_time);
2106 print_time ("combine", combine_time);
2107 print_time ("sched", sched_time);
2108 print_time ("local-alloc", local_alloc_time);
2109 print_time ("global-alloc", global_alloc_time);
2110 print_time ("sched2", sched2_time);
2111 print_time ("dbranch", dbr_sched_time);
2112 print_time ("shorten-branch", shorten_branch_time);
2113 print_time ("stack-reg", stack_reg_time);
2114 print_time ("final", final_time);
2115 print_time ("varconst", varconst_time);
2116 print_time ("symout", symout_time);
2117 print_time ("dump", dump_time);
2118 }
2119}
2120\f
2121/* This is called from various places for FUNCTION_DECL, VAR_DECL,
2122 and TYPE_DECL nodes.
2123
2124 This does nothing for local (non-static) variables.
2125 Otherwise, it sets up the RTL and outputs any assembler code
2126 (label definition, storage allocation and initialization).
2127
2128 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2129 the assembler symbol name to be used. TOP_LEVEL is nonzero
2130 if this declaration is not within a function. */
2131
2132void
2133rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2134 tree decl;
2135 char *asmspec;
2136 int top_level;
2137 int at_end;
2138{
2139 /* Declarations of variables, and of functions defined elsewhere. */
2140
2141 /* Forward declarations for nested functions are not "external",
2142 but we need to treat them as if they were. */
216d5cdd 2143 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
4291d9c8
RS
2144 || TREE_CODE (decl) == FUNCTION_DECL)
2145 TIMEVAR (varconst_time,
2146 {
2147 make_decl_rtl (decl, asmspec, top_level);
6dbf678a
RS
2148 /* For a user-invisible decl that should be replaced
2149 by its value when used, don't output anything. */
2150 if (! (TREE_CODE (decl) == VAR_DECL
2151 && DECL_IGNORED_P (decl) && TREE_READONLY (decl)
2152 && DECL_INITIAL (decl) != 0))
2153 /* Don't output anything
2154 when a tentative file-scope definition is seen.
2155 But at end of compilation, do output code for them. */
2156 if (! (! at_end && top_level
2157 && (DECL_INITIAL (decl) == 0
2158 || DECL_INITIAL (decl) == error_mark_node
2159 || DECL_IGNORED_P (decl))))
2160 assemble_variable (decl, top_level, at_end);
4291d9c8 2161 });
216d5cdd 2162 else if (DECL_REGISTER (decl) && asmspec != 0)
4291d9c8
RS
2163 {
2164 if (decode_reg_name (asmspec) >= 0)
2165 {
2166 DECL_RTL (decl) = 0;
2167 make_decl_rtl (decl, asmspec, top_level);
2168 }
2169 else
2170 error ("invalid register name `%s' for register variable", asmspec);
2171 }
f246a305
RS
2172#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2173 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2174 && TREE_CODE (decl) == TYPE_DECL)
4291d9c8
RS
2175 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2176#endif
2177#ifdef SDB_DEBUGGING_INFO
2178 else if (write_symbols == SDB_DEBUG && top_level
2179 && TREE_CODE (decl) == TYPE_DECL)
2180 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2181#endif
2182}
2183
2184/* Called after finishing a record, union or enumeral type. */
2185
2186void
2187rest_of_type_compilation (type, toplev)
2188 tree type;
2189 int toplev;
2190{
f246a305
RS
2191#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2192 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2193 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2194#endif
2195#ifdef SDB_DEBUGGING_INFO
2196 if (write_symbols == SDB_DEBUG)
2197 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2198#endif
2199}
2200
2201/* This is called from finish_function (within yyparse)
2202 after each top-level definition is parsed.
2203 It is supposed to compile that function or variable
2204 and output the assembler code for it.
2205 After we return, the tree storage is freed. */
2206
2207void
2208rest_of_compilation (decl)
2209 tree decl;
2210{
2211 register rtx insns;
2212 int start_time = get_run_time ();
2213 int tem;
2214 /* Nonzero if we have saved the original DECL_INITIAL of the function,
2215 to be restored after we finish compiling the function
2216 (for use when compiling inline calls to this function). */
2217 tree saved_block_tree = 0;
8a958768
RS
2218 /* Likewise, for DECL_ARGUMENTS. */
2219 tree saved_arguments = 0;
ab40ad2b 2220 int failure = 0;
4291d9c8
RS
2221
2222 /* If we are reconsidering an inline function
2223 at the end of compilation, skip the stuff for making it inline. */
2224
2225 if (DECL_SAVED_INSNS (decl) == 0)
2226 {
216d5cdd 2227 int specd = DECL_INLINE (decl);
4291d9c8
RS
2228 char *lose;
2229
2230 /* If requested, consider whether to make this function inline. */
2231 if (specd || flag_inline_functions)
2232 TIMEVAR (integration_time,
2233 {
2234 lose = function_cannot_inline_p (decl);
2235 if (lose)
2236 {
2237 if (warn_inline && specd)
2238 warning_with_decl (decl, lose);
216d5cdd 2239 DECL_INLINE (decl) = 0;
4291d9c8
RS
2240 }
2241 else
216d5cdd 2242 DECL_INLINE (decl) = 1;
4291d9c8
RS
2243 });
2244
2245 insns = get_insns ();
2246
2247 /* Dump the rtl code if we are dumping rtl. */
2248
2249 if (rtl_dump)
2250 TIMEVAR (dump_time,
2251 {
2252 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2253 IDENTIFIER_POINTER (DECL_NAME (decl)));
2254 if (DECL_SAVED_INSNS (decl))
2255 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2256 print_rtl (rtl_dump_file, insns);
2257 fflush (rtl_dump_file);
2258 });
2259
2260 /* If function is inline, and we don't yet know whether to
2261 compile it by itself, defer decision till end of compilation.
2262 finish_compilation will call rest_of_compilation again
2263 for those functions that need to be output. */
2264
216d5cdd 2265 if (DECL_INLINE (decl)
4291d9c8
RS
2266 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2267 && ! flag_keep_inline_functions)
216d5cdd 2268 || DECL_EXTERNAL (decl)))
4291d9c8 2269 {
937522b5
RS
2270#ifdef DWARF_DEBUGGING_INFO
2271 /* Generate the DWARF info for the "abstract" instance
2272 of a function which we may later generate inlined and/or
2273 out-of-line instances of. */
2274 if (write_symbols == DWARF_DEBUG)
2275 {
2276 set_decl_abstract_flags (decl, 1);
2277 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2278 set_decl_abstract_flags (decl, 0);
2279 }
2280#endif
4291d9c8
RS
2281 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
2282 goto exit_rest_of_compilation;
2283 }
2284
8a958768 2285 /* If we have to compile the function now, save its rtl and subdecls
4291d9c8 2286 so that its compilation will not affect what others get. */
216d5cdd 2287 if (DECL_INLINE (decl))
4291d9c8 2288 {
937522b5
RS
2289#ifdef DWARF_DEBUGGING_INFO
2290 /* Generate the DWARF info for the "abstract" instance of
2291 a function which we will generate an out-of-line instance
2292 of almost immediately (and which we may also later generate
2293 various inlined instances of). */
2294 if (write_symbols == DWARF_DEBUG)
2295 {
2296 set_decl_abstract_flags (decl, 1);
2297 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2298 set_decl_abstract_flags (decl, 0);
2299 }
2300#endif
4291d9c8 2301 saved_block_tree = DECL_INITIAL (decl);
8a958768 2302 saved_arguments = DECL_ARGUMENTS (decl);
4291d9c8
RS
2303 TIMEVAR (integration_time, save_for_inline_copying (decl));
2304 }
2305 }
2306
4291d9c8
RS
2307 TREE_ASM_WRITTEN (decl) = 1;
2308
2309 /* Now that integrate will no longer see our rtl, we need not distinguish
2310 between the return value of this function and the return value of called
2311 functions. */
2312 rtx_equal_function_value_matters = 0;
2313
32235b30
RS
2314 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
2315 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
4291d9c8
RS
2316 {
2317 goto exit_rest_of_compilation;
2318 }
2319
2320 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
2321 Note that that may have been done above, in save_for_inline_copying.
2322 The call to resume_temporary_allocation near the end of this function
2323 goes back to the usual state of affairs. */
2324
2325 rtl_in_current_obstack ();
2326
2327#ifdef FINALIZE_PIC
2328 /* If we are doing position-independent code generation, now
2329 is the time to output special prologues and epilogues.
2330 We do not want to do this earlier, because it just clutters
2331 up inline functions with meaningless insns. */
2332 if (flag_pic)
2333 FINALIZE_PIC;
2334#endif
2335
2336 insns = get_insns ();
2337
2338 /* Copy any shared structure that should not be shared. */
2339
2340 unshare_all_rtl (insns);
2341
2342 /* Instantiate all virtual registers. */
2343
2344 instantiate_virtual_regs (current_function_decl, get_insns ());
2345
2346 /* See if we have allocated stack slots that are not directly addressable.
2347 If so, scan all the insns and create explicit address computation
2348 for all references to such slots. */
2349/* fixup_stack_slots (); */
2350
2351 /* Do jump optimization the first time, if -opt.
2352 Also do it if -W, but in that case it doesn't change the rtl code,
2353 it only computes whether control can drop off the end of the function. */
2354
2355 if (optimize > 0 || extra_warnings || warn_return_type
2356 /* If function is `volatile', we should warn if it tries to return. */
2357 || TREE_THIS_VOLATILE (decl))
2358 {
2359 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
2360 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
2361 }
2362
32235b30
RS
2363 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
2364 if (rtl_dump_and_exit || flag_syntax_only)
2365 goto exit_rest_of_compilation;
2366
4291d9c8
RS
2367 /* Dump rtl code after jump, if we are doing that. */
2368
2369 if (jump_opt_dump)
2370 TIMEVAR (dump_time,
2371 {
2372 fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
2373 IDENTIFIER_POINTER (DECL_NAME (decl)));
2374 print_rtl (jump_opt_dump_file, insns);
2375 fflush (jump_opt_dump_file);
2376 });
2377
2378 /* Perform common subexpression elimination.
2379 Nonzero value from `cse_main' means that jumps were simplified
2380 and some code may now be unreachable, so do
2381 jump optimization again. */
2382
2383 if (cse_dump)
2384 TIMEVAR (dump_time,
2385 {
2386 fprintf (cse_dump_file, "\n;; Function %s\n\n",
2387 IDENTIFIER_POINTER (DECL_NAME (decl)));
2388 });
2389
2390 if (optimize > 0)
2391 {
2392 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
2393
2394 if (flag_thread_jumps)
2395 /* Hacks by tiemann & kenner. */
2396 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
2397
2398 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
2399 0, cse_dump_file));
2400 TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
2401
2402 if (tem)
2403 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
2404 }
2405
2406 /* Dump rtl code after cse, if we are doing that. */
2407
2408 if (cse_dump)
2409 TIMEVAR (dump_time,
2410 {
2411 print_rtl (cse_dump_file, insns);
2412 fflush (cse_dump_file);
2413 });
2414
2415 if (loop_dump)
2416 TIMEVAR (dump_time,
2417 {
2418 fprintf (loop_dump_file, "\n;; Function %s\n\n",
2419 IDENTIFIER_POINTER (DECL_NAME (decl)));
2420 });
2421
2422 /* Move constant computations out of loops. */
2423
2424 if (optimize > 0)
2425 {
2426 TIMEVAR (loop_time,
2427 {
37366632 2428 loop_optimize (insns, loop_dump_file);
4291d9c8
RS
2429 });
2430 }
2431
2432 /* Dump rtl code after loop opt, if we are doing that. */
2433
2434 if (loop_dump)
2435 TIMEVAR (dump_time,
2436 {
2437 print_rtl (loop_dump_file, insns);
2438 fflush (loop_dump_file);
2439 });
2440
2441 if (cse2_dump)
2442 TIMEVAR (dump_time,
2443 {
2444 fprintf (cse2_dump_file, "\n;; Function %s\n\n",
2445 IDENTIFIER_POINTER (DECL_NAME (decl)));
2446 });
2447
2448 if (optimize > 0 && flag_rerun_cse_after_loop)
2449 {
2450 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
2451
2452 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
2453 1, cse2_dump_file));
2454 if (tem)
2455 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
2456 }
2457
2458 if (optimize > 0 && flag_thread_jumps)
2459 /* This pass of jump threading straightens out code
2460 that was kinked by loop optimization. */
2461 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
2462
2463 /* Dump rtl code after cse, if we are doing that. */
2464
2465 if (cse2_dump)
2466 TIMEVAR (dump_time,
2467 {
2468 print_rtl (cse2_dump_file, insns);
2469 fflush (cse2_dump_file);
2470 });
2471
2472 /* We are no longer anticipating cse in this function, at least. */
2473
2474 cse_not_expected = 1;
2475
2476 /* Now we choose between stupid (pcc-like) register allocation
2477 (if we got the -noreg switch and not -opt)
2478 and smart register allocation. */
2479
2480 if (optimize > 0) /* Stupid allocation probably won't work */
2481 obey_regdecls = 0; /* if optimizations being done. */
2482
2483 regclass_init ();
2484
2485 /* Print function header into flow dump now
2486 because doing the flow analysis makes some of the dump. */
2487
2488 if (flow_dump)
2489 TIMEVAR (dump_time,
2490 {
2491 fprintf (flow_dump_file, "\n;; Function %s\n\n",
2492 IDENTIFIER_POINTER (DECL_NAME (decl)));
2493 });
2494
2495 if (obey_regdecls)
2496 {
2497 TIMEVAR (flow_time,
2498 {
2499 regclass (insns, max_reg_num ());
2500 stupid_life_analysis (insns, max_reg_num (),
2501 flow_dump_file);
2502 });
2503 }
2504 else
2505 {
2506 /* Do control and data flow analysis,
2507 and write some of the results to dump file. */
2508
2509 TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
2510 flow_dump_file));
2511 if (warn_uninitialized)
2512 {
2513 uninitialized_vars_warning (DECL_INITIAL (decl));
2514 setjmp_args_warning ();
2515 }
2516 }
2517
2518 /* Dump rtl after flow analysis. */
2519
2520 if (flow_dump)
2521 TIMEVAR (dump_time,
2522 {
2523 print_rtl (flow_dump_file, insns);
2524 fflush (flow_dump_file);
2525 });
2526
2527 /* If -opt, try combining insns through substitution. */
2528
2529 if (optimize > 0)
2530 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
2531
2532 /* Dump rtl code after insn combination. */
2533
2534 if (combine_dump)
2535 TIMEVAR (dump_time,
2536 {
2537 fprintf (combine_dump_file, "\n;; Function %s\n\n",
2538 IDENTIFIER_POINTER (DECL_NAME (decl)));
2539 dump_combine_stats (combine_dump_file);
2540 print_rtl (combine_dump_file, insns);
2541 fflush (combine_dump_file);
2542 });
2543
2544 /* Print function header into sched dump now
2545 because doing the sched analysis makes some of the dump. */
2546
2547 if (sched_dump)
2548 TIMEVAR (dump_time,
2549 {
2550 fprintf (sched_dump_file, "\n;; Function %s\n\n",
2551 IDENTIFIER_POINTER (DECL_NAME (decl)));
2552 });
2553
2554 if (optimize > 0 && flag_schedule_insns)
2555 {
2556 /* Do control and data sched analysis,
2557 and write some of the results to dump file. */
2558
2559 TIMEVAR (sched_time, schedule_insns (sched_dump_file));
2560 }
2561
2562 /* Dump rtl after instruction scheduling. */
2563
2564 if (sched_dump)
2565 TIMEVAR (dump_time,
2566 {
2567 print_rtl (sched_dump_file, insns);
2568 fflush (sched_dump_file);
2569 });
2570
2571 /* Unless we did stupid register allocation,
2572 allocate pseudo-regs that are used only within 1 basic block. */
2573
2574 if (!obey_regdecls)
2575 TIMEVAR (local_alloc_time,
2576 {
2577 regclass (insns, max_reg_num ());
2578 local_alloc ();
2579 });
2580
2581 /* Dump rtl code after allocating regs within basic blocks. */
2582
2583 if (local_reg_dump)
2584 TIMEVAR (dump_time,
2585 {
2586 fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
2587 IDENTIFIER_POINTER (DECL_NAME (decl)));
2588 dump_flow_info (local_reg_dump_file);
2589 dump_local_alloc (local_reg_dump_file);
2590 print_rtl (local_reg_dump_file, insns);
2591 fflush (local_reg_dump_file);
2592 });
2593
2594 if (global_reg_dump)
2595 TIMEVAR (dump_time,
2596 fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
2597 IDENTIFIER_POINTER (DECL_NAME (decl))));
2598
2599 /* Unless we did stupid register allocation,
2600 allocate remaining pseudo-regs, then do the reload pass
2601 fixing up any insns that are invalid. */
2602
2603 TIMEVAR (global_alloc_time,
2604 {
2605 if (!obey_regdecls)
37366632 2606 failure = global_alloc (global_reg_dump_file);
4291d9c8 2607 else
37366632 2608 failure = reload (insns, 0, global_reg_dump_file);
4291d9c8
RS
2609 });
2610
2611 if (global_reg_dump)
2612 TIMEVAR (dump_time,
2613 {
2614 dump_global_regs (global_reg_dump_file);
2615 print_rtl (global_reg_dump_file, insns);
2616 fflush (global_reg_dump_file);
2617 });
2618
ab40ad2b
RS
2619 if (failure)
2620 goto exit_rest_of_compilation;
2621
4291d9c8
RS
2622 reload_completed = 1;
2623
bdac5f58
TW
2624 /* On some machines, the prologue and epilogue code, or parts thereof,
2625 can be represented as RTL. Doing so lets us schedule insns between
2626 it and the rest of the code and also allows delayed branch
2627 scheduling to operate in the epilogue. */
2628
2629 thread_prologue_and_epilogue_insns (insns);
2630
4291d9c8
RS
2631 if (optimize > 0 && flag_schedule_insns_after_reload)
2632 {
2633 if (sched2_dump)
2634 TIMEVAR (dump_time,
2635 {
2636 fprintf (sched2_dump_file, "\n;; Function %s\n\n",
2637 IDENTIFIER_POINTER (DECL_NAME (decl)));
2638 });
2639
2640 /* Do control and data sched analysis again,
2641 and write some more of the results to dump file. */
2642
2643 TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
2644
2645 /* Dump rtl after post-reorder instruction scheduling. */
2646
2647 if (sched2_dump)
2648 TIMEVAR (dump_time,
2649 {
2650 print_rtl (sched2_dump_file, insns);
2651 fflush (sched2_dump_file);
2652 });
2653 }
2654
2655#ifdef LEAF_REGISTERS
2656 leaf_function = 0;
2657 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
ab40ad2b 2658 leaf_function = 1;
4291d9c8
RS
2659#endif
2660
2661 /* One more attempt to remove jumps to .+1
2662 left by dead-store-elimination.
2663 Also do cross-jumping this time
2664 and delete no-op move insns. */
2665
2666 if (optimize > 0)
2667 {
2668 TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
2669 }
2670
2671 /* Dump rtl code after jump, if we are doing that. */
2672
2673 if (jump2_opt_dump)
2674 TIMEVAR (dump_time,
2675 {
2676 fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
2677 IDENTIFIER_POINTER (DECL_NAME (decl)));
2678 print_rtl (jump2_opt_dump_file, insns);
2679 fflush (jump2_opt_dump_file);
2680 });
2681
2682 /* If a scheduling pass for delayed branches is to be done,
2683 call the scheduling code. */
2684
2685#ifdef DELAY_SLOTS
2686 if (optimize > 0 && flag_delayed_branch)
2687 {
2688 TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
2689 if (dbr_sched_dump)
2690 {
2691 TIMEVAR (dump_time,
2692 {
2693 fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
2694 IDENTIFIER_POINTER (DECL_NAME (decl)));
2695 print_rtl (dbr_sched_dump_file, insns);
2696 fflush (dbr_sched_dump_file);
2697 });
2698 }
2699 }
2700#endif
2701
2702 if (optimize > 0)
2703 /* Shorten branches. */
2704 TIMEVAR (shorten_branch_time,
2705 {
2706 shorten_branches (get_insns ());
2707 });
2708
2709#ifdef STACK_REGS
2710 TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
2711 if (stack_reg_dump)
2712 {
2713 TIMEVAR (dump_time,
2714 {
2715 fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
2716 IDENTIFIER_POINTER (DECL_NAME (decl)));
2717 print_rtl (stack_reg_dump_file, insns);
2718 fflush (stack_reg_dump_file);
2719 });
2720 }
2721#endif
2722
2723 /* Now turn the rtl into assembler code. */
2724
2725 TIMEVAR (final_time,
2726 {
2727 rtx x;
2728 char *fnname;
2729
2730 /* Get the function's name, as described by its RTL.
2731 This may be different from the DECL_NAME name used
2732 in the source file. */
2733
2734 x = DECL_RTL (decl);
2735 if (GET_CODE (x) != MEM)
2736 abort ();
2737 x = XEXP (x, 0);
2738 if (GET_CODE (x) != SYMBOL_REF)
2739 abort ();
2740 fnname = XSTR (x, 0);
2741
2742 assemble_start_function (decl, fnname);
2743 final_start_function (insns, asm_out_file, optimize);
2744 final (insns, asm_out_file, optimize, 0);
2745 final_end_function (insns, asm_out_file, optimize);
2746 assemble_end_function (decl, fnname);
2747 fflush (asm_out_file);
2748 });
2749
2750 /* Write DBX symbols if requested */
2751
2752 /* Note that for those inline functions where we don't initially
2753 know for certain that we will be generating an out-of-line copy,
2754 the first invocation of this routine (rest_of_compilation) will
2755 skip over this code by doing a `goto exit_rest_of_compilation;'.
2756 Later on, finish_compilation will call rest_of_compilation again
2757 for those inline functions that need to have out-of-line copies
2758 generated. During that call, we *will* be routed past here. */
2759
2760#ifdef DBX_DEBUGGING_INFO
2761 if (write_symbols == DBX_DEBUG)
2762 TIMEVAR (symout_time, dbxout_function (decl));
2763#endif
2764
2765#ifdef DWARF_DEBUGGING_INFO
2766 if (write_symbols == DWARF_DEBUG)
2767 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2768#endif
2769
2770 exit_rest_of_compilation:
2771
f246a305
RS
2772 /* In case the function was not output,
2773 don't leave any temporary anonymous types
2774 queued up for sdb output. */
2775#ifdef SDB_DEBUGGING_INFO
2776 if (write_symbols == SDB_DEBUG)
37366632 2777 sdbout_types (NULL_TREE);
f246a305
RS
2778#endif
2779
8a958768
RS
2780 /* Put back the tree of subblocks and list of arguments
2781 from before we copied them.
4291d9c8
RS
2782 Code generation and the output of debugging info may have modified
2783 the copy, but the original is unchanged. */
2784
2785 if (saved_block_tree != 0)
2786 DECL_INITIAL (decl) = saved_block_tree;
8a958768
RS
2787 if (saved_arguments != 0)
2788 DECL_ARGUMENTS (decl) = saved_arguments;
4291d9c8
RS
2789
2790 reload_completed = 0;
2791
2792 /* Clear out the real_constant_chain before some of the rtx's
2793 it runs through become garbage. */
2794
2795 clear_const_double_mem ();
2796
2797 /* Cancel the effect of rtl_in_current_obstack. */
2798
2799 resume_temporary_allocation ();
2800
2801 /* The parsing time is all the time spent in yyparse
2802 *except* what is spent in this function. */
2803
2804 parse_time -= get_run_time () - start_time;
2805}
2806\f
2807/* Entry point of cc1/c++. Decode command args, then call compile_file.
2808 Exit code is 35 if can't open files, 34 if fatal error,
2809 33 if had nonfatal errors, else success. */
2810
2811int
2812main (argc, argv, envp)
2813 int argc;
2814 char **argv;
2815 char **envp;
2816{
2817 register int i;
2818 char *filename = 0;
2819 int flag_print_mem = 0;
2820 int version_flag = 0;
2821 char *p;
2822
2823 /* save in case md file wants to emit args as a comment. */
2824 save_argc = argc;
2825 save_argv = argv;
2826
2827 p = argv[0] + strlen (argv[0]);
2828 while (p != argv[0] && p[-1] != '/') --p;
2829 progname = p;
2830
2831#ifdef RLIMIT_STACK
2832 /* Get rid of any avoidable limit on stack size. */
2833 {
2834 struct rlimit rlim;
2835
2836 /* Set the stack limit huge so that alloca does not fail. */
2837 getrlimit (RLIMIT_STACK, &rlim);
2838 rlim.rlim_cur = rlim.rlim_max;
2839 setrlimit (RLIMIT_STACK, &rlim);
2840 }
2841#endif /* RLIMIT_STACK */
2842
2843 signal (SIGFPE, float_signal);
2844
935d4b07 2845#ifdef SIGPIPE
4291d9c8 2846 signal (SIGPIPE, pipe_closed);
935d4b07 2847#endif
4291d9c8
RS
2848
2849 decl_printable_name = decl_name;
2850 lang_expand_expr = (struct rtx_def *(*)()) do_abort;
2851
2852 /* Initialize whether `char' is signed. */
2853 flag_signed_char = DEFAULT_SIGNED_CHAR;
2854#ifdef DEFAULT_SHORT_ENUMS
2855 /* Initialize how much space enums occupy, by default. */
2856 flag_short_enums = DEFAULT_SHORT_ENUMS;
2857#endif
2858
2859 /* Scan to see what optimization level has been specified. That will
2860 determine the default value of many flags. */
2861 for (i = 1; i < argc; i++)
2862 {
2863 if (!strcmp (argv[i], "-O"))
2864 {
2865 optimize = 1;
2866 }
2867 else if (argv[i][0] == '-' && argv[i][1] == 'O')
2868 {
2869 /* Handle -O2, -O3, -O69, ... */
2870 char *p = &argv[i][2];
2871 int c;
2872
2873 while (c = *p++)
2874 if (! (c >= '0' && c <= '9'))
2875 break;
2876 if (c == 0)
2877 optimize = atoi (&argv[i][2]);
2878 }
2879 }
2880
2881 obey_regdecls = (optimize == 0);
f246a305
RS
2882 if (optimize == 0)
2883 {
2884 flag_no_inline = 1;
2885 warn_inline = 0;
2886 }
4291d9c8
RS
2887
2888 if (optimize >= 1)
2889 {
6731a3e3 2890 flag_defer_pop = 1;
4291d9c8
RS
2891 flag_thread_jumps = 1;
2892#ifdef DELAY_SLOTS
2893 flag_delayed_branch = 1;
2894#endif
2895 }
2896
2897 if (optimize >= 2)
2898 {
2899 flag_cse_follow_jumps = 1;
8b3686ed 2900 flag_cse_skip_blocks = 1;
4291d9c8
RS
2901 flag_expensive_optimizations = 1;
2902 flag_strength_reduce = 1;
2903 flag_rerun_cse_after_loop = 1;
ac266247 2904 flag_caller_saves = 1;
4291d9c8
RS
2905#ifdef INSN_SCHEDULING
2906 flag_schedule_insns = 1;
2907 flag_schedule_insns_after_reload = 1;
2908#endif
2909 }
2910
2911#ifdef OPTIMIZATION_OPTIONS
2912 /* Allow default optimizations to be specified on a per-machine basis. */
2913 OPTIMIZATION_OPTIONS (optimize);
2914#endif
2915
2916 /* Initialize register usage now so switches may override. */
2917 init_reg_sets ();
2918
2919 target_flags = 0;
2920 set_target_switch ("");
2921
2922 for (i = 1; i < argc; i++)
2923 {
b99933c7
RS
2924 int j;
2925 /* If this is a language-specific option,
2926 decode it in a language-specific way. */
2927 for (j = 0; lang_options[j] != 0; j++)
2928 if (!strncmp (argv[i], lang_options[j],
2929 strlen (lang_options[j])))
2930 break;
2931 if (lang_options[j] != 0)
2932 /* If the option is valid for *some* language,
2933 treat it as valid even if this language doesn't understand it. */
2934 lang_decode_option (argv[i]);
2935 else if (argv[i][0] == '-' && argv[i][1] != 0)
4291d9c8
RS
2936 {
2937 register char *str = argv[i] + 1;
2938 if (str[0] == 'Y')
2939 str++;
2940
2941 if (str[0] == 'm')
2942 set_target_switch (&str[1]);
2943 else if (!strcmp (str, "dumpbase"))
2944 {
2945 dump_base_name = argv[++i];
2946 }
2947 else if (str[0] == 'd')
2948 {
2949 register char *p = &str[1];
2950 while (*p)
2951 switch (*p++)
2952 {
2953 case 'a':
2954 combine_dump = 1;
2955 dbr_sched_dump = 1;
2956 flow_dump = 1;
2957 global_reg_dump = 1;
2958 jump_opt_dump = 1;
2959 jump2_opt_dump = 1;
2960 local_reg_dump = 1;
2961 loop_dump = 1;
2962 rtl_dump = 1;
2963 cse_dump = 1, cse2_dump = 1;
2964 sched_dump = 1;
2965 sched2_dump = 1;
2966 stack_reg_dump = 1;
2967 break;
2968 case 'k':
2969 stack_reg_dump = 1;
2970 break;
2971 case 'c':
2972 combine_dump = 1;
2973 break;
2974 case 'd':
2975 dbr_sched_dump = 1;
2976 break;
2977 case 'f':
2978 flow_dump = 1;
2979 break;
2980 case 'g':
2981 global_reg_dump = 1;
2982 break;
2983 case 'j':
2984 jump_opt_dump = 1;
2985 break;
2986 case 'J':
2987 jump2_opt_dump = 1;
2988 break;
2989 case 'l':
2990 local_reg_dump = 1;
2991 break;
2992 case 'L':
2993 loop_dump = 1;
2994 break;
2995 case 'm':
2996 flag_print_mem = 1;
2997 break;
2998 case 'p':
2999 flag_print_asm_name = 1;
3000 break;
3001 case 'r':
3002 rtl_dump = 1;
3003 break;
3004 case 's':
3005 cse_dump = 1;
3006 break;
3007 case 't':
3008 cse2_dump = 1;
3009 break;
3010 case 'S':
3011 sched_dump = 1;
3012 break;
3013 case 'R':
3014 sched2_dump = 1;
3015 break;
3016 case 'y':
3017 set_yydebug (1);
3018 break;
3019
3020 case 'x':
3021 rtl_dump_and_exit = 1;
3022 break;
3023 }
3024 }
3025 else if (str[0] == 'f')
3026 {
4291d9c8
RS
3027 register char *p = &str[1];
3028 int found = 0;
3029
3030 /* Some kind of -f option.
3031 P's value is the option sans `-f'.
3032 Search for it in the table of options. */
3033
3034 for (j = 0;
3035 !found && j < sizeof (f_options) / sizeof (f_options[0]);
3036 j++)
3037 {
3038 if (!strcmp (p, f_options[j].string))
3039 {
3040 *f_options[j].variable = f_options[j].on_value;
3041 /* A goto here would be cleaner,
3042 but breaks the vax pcc. */
3043 found = 1;
3044 }
3045 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3046 && ! strcmp (p+3, f_options[j].string))
3047 {
3048 *f_options[j].variable = ! f_options[j].on_value;
3049 found = 1;
3050 }
3051 }
3052
3053 if (found)
3054 ;
3055 else if (!strncmp (p, "fixed-", 6))
3056 fix_register (&p[6], 1, 1);
3057 else if (!strncmp (p, "call-used-", 10))
3058 fix_register (&p[10], 0, 1);
3059 else if (!strncmp (p, "call-saved-", 11))
3060 fix_register (&p[11], 0, 0);
b99933c7 3061 else
4291d9c8
RS
3062 error ("Invalid option `%s'", argv[i]);
3063 }
3064 else if (str[0] == 'O')
3065 {
3066 register char *p = str+1;
3067 while (*p && *p >= '0' && *p <= '9')
3068 p++;
3069 if (*p == '\0')
3070 ;
3071 else
3072 error ("Invalid option `%s'", argv[i]);
3073 }
3074 else if (!strcmp (str, "pedantic"))
3075 pedantic = 1;
3076 else if (!strcmp (str, "pedantic-errors"))
3077 flag_pedantic_errors = pedantic = 1;
4291d9c8
RS
3078 else if (!strcmp (str, "quiet"))
3079 quiet_flag = 1;
3080 else if (!strcmp (str, "version"))
3081 version_flag = 1;
3082 else if (!strcmp (str, "w"))
3083 inhibit_warnings = 1;
3084 else if (!strcmp (str, "W"))
3085 {
3086 extra_warnings = 1;
3087 warn_uninitialized = 1;
3088 }
3089 else if (str[0] == 'W')
3090 {
4291d9c8
RS
3091 register char *p = &str[1];
3092 int found = 0;
3093
3094 /* Some kind of -W option.
3095 P's value is the option sans `-W'.
3096 Search for it in the table of options. */
3097
3098 for (j = 0;
3099 !found && j < sizeof (W_options) / sizeof (W_options[0]);
3100 j++)
3101 {
3102 if (!strcmp (p, W_options[j].string))
3103 {
3104 *W_options[j].variable = W_options[j].on_value;
3105 /* A goto here would be cleaner,
3106 but breaks the vax pcc. */
3107 found = 1;
3108 }
3109 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3110 && ! strcmp (p+3, W_options[j].string))
3111 {
3112 *W_options[j].variable = ! W_options[j].on_value;
3113 found = 1;
3114 }
3115 }
3116
3117 if (found)
3118 ;
3119 else if (!strncmp (p, "id-clash-", 9))
3120 {
3121 char *endp = p + 9;
3122
3123 while (*endp)
3124 {
3125 if (*endp >= '0' && *endp <= '9')
3126 endp++;
3127 else
7085b873
RS
3128 {
3129 error ("Invalid option `%s'", argv[i]);
3130 goto id_clash_lose;
3131 }
4291d9c8
RS
3132 }
3133 warn_id_clash = 1;
3134 id_clash_len = atoi (str + 10);
7085b873 3135 id_clash_lose: ;
4291d9c8
RS
3136 }
3137 else
3138 error ("Invalid option `%s'", argv[i]);
3139 }
3140 else if (!strcmp (str, "p"))
3141 profile_flag = 1;
3142 else if (!strcmp (str, "a"))
3143 {
3144#if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
3145 warning ("`-a' option (basic block profile) not supported");
3146#else
3147 profile_block_flag = 1;
3148#endif
3149 }
3150 else if (str[0] == 'g')
3151 {
3152 char *p = str + 1;
3153 char *q;
3154 unsigned len;
3155 unsigned level;
3156
3157 while (*p && (*p < '0' || *p > '9'))
3158 p++;
3159 len = p - str;
3160 q = p;
3161 while (*q && (*q >= '0' && *q <= '9'))
3162 q++;
3163 if (*p)
3164 level = atoi (p);
3165 else
3166 level = 2; /* default debugging info level */
3167 if (*q || level > 3)
3168 {
3169 warning ("invalid debug level specification in option: `-%s'",
3170 str);
3171 warning ("no debugging information will be generated");
3172 level = 0;
3173 }
3174
3175 /* If more than one debugging type is supported,
3176 you must define PREFERRED_DEBUGGING_TYPE
3177 to choose a format in a system-dependent way. */
4d7e336b
RS
3178 /* This is one long line cause VAXC can't handle a \-newline. */
3179#if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
4291d9c8
RS
3180#ifdef PREFERRED_DEBUGGING_TYPE
3181 if (!strncmp (str, "ggdb", len))
3182 write_symbols = PREFERRED_DEBUGGING_TYPE;
3183#else /* no PREFERRED_DEBUGGING_TYPE */
3184You Lose! You must define PREFERRED_DEBUGGING_TYPE!
3185#endif /* no PREFERRED_DEBUGGING_TYPE */
3186#endif /* More than one debugger format enabled. */
3187#ifdef DBX_DEBUGGING_INFO
3188 if (write_symbols != NO_DEBUG)
3189 ;
3190 else if (!strncmp (str, "ggdb", len))
3191 write_symbols = DBX_DEBUG;
3192 else if (!strncmp (str, "gstabs", len))
3193 write_symbols = DBX_DEBUG;
efa89fb3
RS
3194 else if (!strncmp (str, "gstabs+", len))
3195 write_symbols = DBX_DEBUG;
4291d9c8
RS
3196
3197 /* Always enable extensions for -ggdb or -gstabs+,
3198 always disable for -gstabs.
3199 For plain -g, use system-specific default. */
3200 if (write_symbols == DBX_DEBUG && !strncmp (str, "ggdb", len)
3201 && len >= 2)
a53d0bcc 3202 use_gnu_debug_info_extensions = 1;
166792f0
RS
3203 else if (write_symbols == DBX_DEBUG && !strncmp (str, "gstabs+", len)
3204 && len >= 7)
a53d0bcc 3205 use_gnu_debug_info_extensions = 1;
4291d9c8
RS
3206 else if (write_symbols == DBX_DEBUG
3207 && !strncmp (str, "gstabs", len) && len >= 2)
a53d0bcc 3208 use_gnu_debug_info_extensions = 0;
4291d9c8 3209 else
a53d0bcc 3210 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
4291d9c8
RS
3211#endif /* DBX_DEBUGGING_INFO */
3212#ifdef DWARF_DEBUGGING_INFO
3213 if (write_symbols != NO_DEBUG)
3214 ;
a53d0bcc
RS
3215 else if (!strncmp (str, "g", len))
3216 write_symbols = DWARF_DEBUG;
4291d9c8
RS
3217 else if (!strncmp (str, "ggdb", len))
3218 write_symbols = DWARF_DEBUG;
4291d9c8
RS
3219 else if (!strncmp (str, "gdwarf", len))
3220 write_symbols = DWARF_DEBUG;
a53d0bcc
RS
3221
3222 /* Always enable extensions for -ggdb or -gdwarf+,
3223 always disable for -gdwarf.
3224 For plain -g, use system-specific default. */
3225 if (write_symbols == DWARF_DEBUG && !strncmp (str, "ggdb", len)
3226 && len >= 2)
3227 use_gnu_debug_info_extensions = 1;
3228 else if (write_symbols == DWARF_DEBUG && !strcmp (str, "gdwarf+"))
3229 use_gnu_debug_info_extensions = 1;
3230 else if (write_symbols == DWARF_DEBUG
3231 && !strncmp (str, "gdwarf", len) && len >= 2)
3232 use_gnu_debug_info_extensions = 0;
3233 else
3234 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
4291d9c8
RS
3235#endif
3236#ifdef SDB_DEBUGGING_INFO
3237 if (write_symbols != NO_DEBUG)
3238 ;
a53d0bcc
RS
3239 else if (!strncmp (str, "g", len))
3240 write_symbols = SDB_DEBUG;
3241 else if (!strncmp (str, "gdb", len))
4291d9c8
RS
3242 write_symbols = SDB_DEBUG;
3243 else if (!strncmp (str, "gcoff", len))
3244 write_symbols = SDB_DEBUG;
3245#endif /* SDB_DEBUGGING_INFO */
f246a305
RS
3246#ifdef XCOFF_DEBUGGING_INFO
3247 if (write_symbols != NO_DEBUG)
3248 ;
a53d0bcc
RS
3249 else if (!strncmp (str, "g", len))
3250 write_symbols = XCOFF_DEBUG;
f246a305
RS
3251 else if (!strncmp (str, "ggdb", len))
3252 write_symbols = XCOFF_DEBUG;
3253 else if (!strncmp (str, "gxcoff", len))
3254 write_symbols = XCOFF_DEBUG;
3255
a53d0bcc 3256 /* Always enable extensions for -ggdb or -gxcoff+,
f246a305
RS
3257 always disable for -gxcoff.
3258 For plain -g, use system-specific default. */
3259 if (write_symbols == XCOFF_DEBUG && !strncmp (str, "ggdb", len)
3260 && len >= 2)
a53d0bcc
RS
3261 use_gnu_debug_info_extensions = 1;
3262 else if (write_symbols == XCOFF_DEBUG && !strcmp (str, "gxcoff+"))
3263 use_gnu_debug_info_extensions = 1;
a56addeb 3264 else if (write_symbols == XCOFF_DEBUG
f246a305 3265 && !strncmp (str, "gxcoff", len) && len >= 2)
a53d0bcc 3266 use_gnu_debug_info_extensions = 0;
f246a305 3267 else
a53d0bcc 3268 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
f246a305 3269#endif
4291d9c8
RS
3270 if (write_symbols == NO_DEBUG)
3271 warning ("`-%s' option not supported on this version of GCC", str);
3272 else if (level == 0)
3273 write_symbols = NO_DEBUG;
3274 else
d68c507d 3275 debug_info_level = (enum debug_info_level) level;
4291d9c8
RS
3276 }
3277 else if (!strcmp (str, "o"))
3278 {
3279 asm_file_name = argv[++i];
3280 }
3281 else if (str[0] == 'G')
3282 {
3283 g_switch_set = TRUE;
3284 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
3285 }
f246a305
RS
3286 else if (!strncmp (str, "aux-info", 8))
3287 {
3288 flag_gen_aux_info = 1;
3289 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
3290 }
4291d9c8
RS
3291 else
3292 error ("Invalid option `%s'", argv[i]);
3293 }
3294 else if (argv[i][0] == '+')
b99933c7 3295 error ("Invalid option `%s'", argv[i]);
4291d9c8
RS
3296 else
3297 filename = argv[i];
3298 }
3299
f246a305
RS
3300 if (optimize == 0)
3301 {
a2468e45
BK
3302 /* Inlining does not work if not optimizing,
3303 so force it not to be done. */
f246a305
RS
3304 flag_no_inline = 1;
3305 warn_inline = 0;
a2468e45
BK
3306
3307 /* The c_decode_option and lang_decode_option functions set
3308 this to `2' if -Wall is used, so we can avoid giving out
3309 lots of errors for people who don't realize what -Wall does. */
3310 if (warn_uninitialized == 1)
3311 warning ("-Wuninitialized is not supported without -O");
f246a305
RS
3312 }
3313
7877bbb3
RS
3314#if defined(DWARF_DEBUGGING_INFO)
3315 if (write_symbols == DWARF_DEBUG
3316 && strcmp (language_string, "GNU C++") == 0)
3317 {
2b5ddaab 3318 warning ("-g option not supported for C++ on SVR4 systems");
7877bbb3
RS
3319 write_symbols = NO_DEBUG;
3320 }
3321#endif /* defined(DWARF_DEBUGGING_INFO) */
3322
4291d9c8
RS
3323#ifdef OVERRIDE_OPTIONS
3324 /* Some machines may reject certain combinations of options. */
3325 OVERRIDE_OPTIONS;
3326#endif
3327
3328 /* Unrolling all loops implies that standard loop unrolling must also
3329 be done. */
3330 if (flag_unroll_all_loops)
3331 flag_unroll_loops = 1;
3332 /* Loop unrolling requires that strength_reduction be on also. Silently
3333 turn on strength reduction here if it isn't already on. Also, the loop
3334 unrolling code assumes that cse will be run after loop, so that must
3335 be turned on also. */
3336 if (flag_unroll_loops)
3337 {
3338 flag_strength_reduce = 1;
3339 flag_rerun_cse_after_loop = 1;
3340 }
3341
3342 /* Warn about options that are not supported on this machine. */
3343#ifndef INSN_SCHEDULING
3344 if (flag_schedule_insns || flag_schedule_insns_after_reload)
3345 warning ("instruction scheduling not supported on this target machine");
3346#endif
3347#ifndef DELAY_SLOTS
3348 if (flag_delayed_branch)
3349 warning ("this target machine does not have delayed branches");
3350#endif
3351
3352 /* If we are in verbose mode, write out the version and maybe all the
3353 option flags in use. */
3354 if (version_flag)
3355 {
3356 fprintf (stderr, "%s version %s", language_string, version_string);
3357#ifdef TARGET_VERSION
3358 TARGET_VERSION;
3359#endif
3360#ifdef __GNUC__
3361#ifndef __VERSION__
3362#define __VERSION__ "[unknown]"
3363#endif
3364 fprintf (stderr, " compiled by GNU C version %s.\n", __VERSION__);
3365#else
3366 fprintf (stderr, " compiled by CC.\n");
3367#endif
3368 if (! quiet_flag)
3369 print_switch_values ();
3370 }
3371
3372 /* Now that register usage is specified, convert it to HARD_REG_SETs. */
3373 init_reg_sets_1 ();
3374
3375 compile_file (filename);
3376
a56addeb 3377#ifndef OS2
4291d9c8
RS
3378#ifndef VMS
3379 if (flag_print_mem)
3380 {
3381 char *lim = (char *) sbrk (0);
3382
3383 fprintf (stderr, "Data size %d.\n",
b61b1c91 3384 lim - (char *) &environ);
4291d9c8
RS
3385 fflush (stderr);
3386
3387#ifdef USG
3388 system ("ps -l 1>&2");
3389#else /* not USG */
3390 system ("ps v");
3391#endif /* not USG */
3392 }
3393#endif /* not VMS */
a56addeb 3394#endif /* not OS2 */
4291d9c8
RS
3395
3396 if (errorcount)
3397 exit (FATAL_EXIT_CODE);
3398 if (sorrycount)
3399 exit (FATAL_EXIT_CODE);
3400 exit (SUCCESS_EXIT_CODE);
3401 return 34;
3402}
3403\f
3404/* Decode -m switches. */
3405
3406/* Here is a table, controlled by the tm.h file, listing each -m switch
3407 and which bits in `target_switches' it should set or clear.
3408 If VALUE is positive, it is bits to set.
3409 If VALUE is negative, -VALUE is bits to clear.
3410 (The sign bit is not used so there is no confusion.) */
3411
3412struct {char *name; int value;} target_switches []
3413 = TARGET_SWITCHES;
3414
3415/* This table is similar, but allows the switch to have a value. */
3416
3417#ifdef TARGET_OPTIONS
3418struct {char *prefix; char ** variable;} target_options []
3419 = TARGET_OPTIONS;
3420#endif
3421
3422/* Decode the switch -mNAME. */
3423
3424void
3425set_target_switch (name)
3426 char *name;
3427{
3428 register int j;
3429 int valid = 0;
3430
3431 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
3432 if (!strcmp (target_switches[j].name, name))
3433 {
3434 if (target_switches[j].value < 0)
3435 target_flags &= ~-target_switches[j].value;
3436 else
3437 target_flags |= target_switches[j].value;
3438 valid = 1;
3439 }
3440
3441#ifdef TARGET_OPTIONS
3442 if (!valid)
3443 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
3444 {
3445 int len = strlen (target_options[j].prefix);
3446 if (!strncmp (target_options[j].prefix, name, len))
3447 {
3448 *target_options[j].variable = name + len;
3449 valid = 1;
3450 }
3451 }
3452#endif
3453
3454 if (!valid)
3455 error ("Invalid option `%s'", name);
3456}
3457\f
3458/* Variable used for communication between the following two routines. */
3459
3460static int line_position;
3461
3462/* Print an option value and adjust the position in the line. */
3463
3464static void
3465print_single_switch (type, name)
3466 char *type, *name;
3467{
3468 fprintf (stderr, " %s%s", type, name);
3469
3470 line_position += strlen (type) + strlen (name) + 1;
3471
3472 if (line_position > 65)
3473 {
3474 fprintf (stderr, "\n\t");
3475 line_position = 8;
3476 }
3477}
3478
3479/* Print default target switches for -version. */
3480
3481static void
3482print_switch_values ()
3483{
3484 register int j;
3485
3486 fprintf (stderr, "enabled:");
3487 line_position = 8;
3488
3489 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
3490 if (*f_options[j].variable == f_options[j].on_value)
3491 print_single_switch ("-f", f_options[j].string);
3492
3493 for (j = 0; j < sizeof W_options / sizeof W_options[0]; j++)
3494 if (*W_options[j].variable == W_options[j].on_value)
3495 print_single_switch ("-W", W_options[j].string);
3496
3497 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
3498 if (target_switches[j].name[0] != '\0'
3499 && target_switches[j].value > 0
3500 && ((target_switches[j].value & target_flags)
3501 == target_switches[j].value))
3502 print_single_switch ("-m", target_switches[j].name);
3503
3504 fprintf (stderr, "\n");
3505}
This page took 0.492422 seconds and 5 git commands to generate.