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