diff options
author | nickc <nickc@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-12-07 10:54:13 +0000 |
---|---|---|
committer | nickc <nickc@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-12-07 10:54:13 +0000 |
commit | 7c6733e83d719397e14db3fe220bc544132a6550 (patch) | |
tree | 46d6178c94554a22a20fe838a94fbf98cec94d4d /gcc/toplev.c | |
parent | 90bf0a0066d0e93b78eb3012c17b323cd084ff8b (diff) | |
download | gcc-7c6733e83d719397e14db3fe220bc544132a6550.tar.gz |
* common.opt (record-gcc-switches): New command line switch.
* target.h (print_switch_type): New enum.
(print_switch_fn_type): New typedef for a function pointer.
(struct gcc_target): Add record_gcc_switches and record_gcc_switches_section fields.
* target-def.h (TARGET_ASM_RECORD_GCC_SWITCHES): Provide a default definition.
(TARGET_ASM_RECORD_GCC_SWITCHES_SECTION): Provide a default definition.
* toplev.c (print_single_switch): Simplify by providing a pointer to function that will format and output the switch appropriately.
(print_switch_values): Likewise.
(print_to_asm_out_file): New function.
(print_to_stderr): New function.
(init_asm_output): If flag_record_gcc_switches is set then if the target supports recording the switches then emit them into the assembler output file, otherwise tell the user that the switch is not supported.
* varasm.c (eld_record_gcc_switches): New function. Example handler for the record_gcc_switches target hook.
* doc/tm.texi (TARGET_ASM_RECORD_GCC_SWITCHES): Document the new target hook.
(TARGET_ASM_RECORD_GCC_SWITCHES_SECTION): Likewise.
* doc/invoke.texi (-frecord-gcc-switches): Document.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119615 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r-- | gcc/toplev.c | 194 |
1 files changed, 136 insertions, 58 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c index 9cc814d7fd0..5fd8c4d3b4c 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -112,12 +112,6 @@ static void crash_signal (int) ATTRIBUTE_NORETURN; static void setup_core_dumping (void); static void compile_file (void); -static int print_single_switch (FILE *, int, int, const char *, - const char *, const char *, - const char *, const char *); -static void print_switch_values (FILE *, int, int, const char *, - const char *, const char *); - /* Nonzero to dump debug info whilst parsing (-dy option). */ static int set_yydebug; @@ -1182,44 +1176,107 @@ print_version (FILE *file, const char *indent) PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE)); } +#ifdef ASM_COMMENT_START +static int +print_to_asm_out_file (print_switch_type type, const char * text) +{ + bool prepend_sep = true; + + switch (type) + { + case SWITCH_TYPE_LINE_END: + putc ('\n', asm_out_file); + return 1; + + case SWITCH_TYPE_LINE_START: + fputs (ASM_COMMENT_START, asm_out_file); + return strlen (ASM_COMMENT_START); + + case SWITCH_TYPE_DESCRIPTIVE: + if (ASM_COMMENT_START[0] == 0) + prepend_sep = false; + /* Drop through. */ + case SWITCH_TYPE_PASSED: + case SWITCH_TYPE_ENABLED: + if (prepend_sep) + fputc (' ', asm_out_file); + fprintf (asm_out_file, text); + /* No need to return the length here as + print_single_switch has already done it. */ + return 0; + + default: + return -1; + } +} +#endif + +static int +print_to_stderr (print_switch_type type, const char * text) +{ + switch (type) + { + case SWITCH_TYPE_LINE_END: + putc ('\n', stderr); + return 1; + + case SWITCH_TYPE_LINE_START: + return 0; + + case SWITCH_TYPE_PASSED: + case SWITCH_TYPE_ENABLED: + fputc (' ', stderr); + /* Drop through. */ + + case SWITCH_TYPE_DESCRIPTIVE: + fprintf (stderr, text); + /* No need to return the length here as + print_single_switch has already done it. */ + return 0; + + default: + return -1; + } +} + /* Print an option value and return the adjusted position in the line. - ??? We don't handle error returns from fprintf (disk full); presumably - other code will catch a disk full though. */ + ??? print_fn doesn't handle errors, eg disk full; presumably other + code will catch a disk full though. */ static int -print_single_switch (FILE *file, int pos, int max, - const char *indent, const char *sep, const char *term, - const char *type, const char *name) +print_single_switch (print_switch_fn_type print_fn, + int pos, + print_switch_type type, + const char * text) { - /* The ultrix fprintf returns 0 on success, so compute the result we want - here since we need it for the following test. */ - int len = strlen (sep) + strlen (type) + strlen (name); + /* The ultrix fprintf returns 0 on success, so compute the result + we want here since we need it for the following test. The +1 + is for the seperator character that will probably be emitted. */ + int len = strlen (text) + 1; if (pos != 0 - && pos + len > max) + && pos + len > MAX_LINE) { - fprintf (file, "%s", term); + print_fn (SWITCH_TYPE_LINE_END, NULL); pos = 0; } + if (pos == 0) - { - fprintf (file, "%s", indent); - pos = strlen (indent); - } - fprintf (file, "%s%s%s", sep, type, name); - pos += len; - return pos; + pos += print_fn (SWITCH_TYPE_LINE_START, NULL); + + print_fn (type, text); + return pos + len; } -/* Print active target switches to FILE. +/* Print active target switches using PRINT_FN. POS is the current cursor position and MAX is the size of a "line". Each line begins with INDENT and ends with TERM. Each switch is separated from the next by SEP. */ static void -print_switch_values (FILE *file, int pos, int max, - const char *indent, const char *sep, const char *term) +print_switch_values (print_switch_fn_type print_fn) { + int pos = 0; size_t j; const char **p; @@ -1228,45 +1285,50 @@ print_switch_values (FILE *file, int pos, int max, randomize (); /* Print the options as passed. */ - pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term, - _("options passed: "), ""); + pos = print_single_switch (print_fn, pos, + SWITCH_TYPE_DESCRIPTIVE, _("options passed: ")); for (p = &save_argv[1]; *p != NULL; p++) - if (**p == '-') - { - /* Ignore these. */ - if (strcmp (*p, "-o") == 0) - { - if (p[1] != NULL) - p++; + { + if (**p == '-') + { + /* Ignore these. */ + if (strcmp (*p, "-o") == 0 + || strcmp (*p, "-dumpbase") == 0 + || strcmp (*p, "-auxbase") == 0) + { + if (p[1] != NULL) + p++; + continue; + } + + if (strcmp (*p, "-quiet") == 0 + || strcmp (*p, "-version") == 0) continue; - } - if (strcmp (*p, "-quiet") == 0) - continue; - if (strcmp (*p, "-version") == 0) - continue; - if ((*p)[1] == 'd') - continue; - - pos = print_single_switch (file, pos, max, indent, sep, term, *p, ""); - } + + if ((*p)[1] == 'd') + continue; + } + + pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p); + } + if (pos > 0) - fprintf (file, "%s", term); + print_fn (SWITCH_TYPE_LINE_END, NULL); /* Print the -f and -m options that have been enabled. We don't handle language specific options but printing argv should suffice. */ - - pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term, - _("options enabled: "), ""); + pos = print_single_switch (print_fn, 0, + SWITCH_TYPE_DESCRIPTIVE, _("options enabled: ")); for (j = 0; j < cl_options_count; j++) if ((cl_options[j].flags & CL_REPORT) && option_enabled (j) > 0) - pos = print_single_switch (file, pos, max, indent, sep, term, - "", cl_options[j].opt_text); + pos = print_single_switch (print_fn, pos, + SWITCH_TYPE_ENABLED, cl_options[j].opt_text); - fprintf (file, "%s", term); + print_fn (SWITCH_TYPE_LINE_END, NULL); } /* Open assembly code output file. Do this even if -fsyntax-only is @@ -1284,6 +1346,7 @@ init_asm_output (const char *name) { int len = strlen (dump_base_name); char *dumpname = XNEWVEC (char, len + 6); + memcpy (dumpname, dump_base_name, len + 1); strip_off_ending (dumpname, len); strcat (dumpname, ".s"); @@ -1301,15 +1364,30 @@ init_asm_output (const char *name) { targetm.asm_out.file_start (); + if (flag_record_gcc_switches) + { + if (targetm.asm_out.record_gcc_switches) + { + /* Let the target know that we are about to start recording. */ + targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE, + NULL); + /* Now record the switches. */ + print_switch_values (targetm.asm_out.record_gcc_switches); + /* Let the target know that the recording is over. */ + targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE, + NULL); + } + else + inform ("-frecord-gcc-switches is not supported by the current target"); + } + #ifdef ASM_COMMENT_START if (flag_verbose_asm) { - /* Print the list of options in effect. */ + /* Print the list of switches in effect + into the assembler file as comments. */ print_version (asm_out_file, ASM_COMMENT_START); - print_switch_values (asm_out_file, 0, MAX_LINE, - ASM_COMMENT_START, " ", "\n"); - /* Add a blank line here so it appears in assembler output but not - screen output. */ + print_switch_values (print_to_asm_out_file); fprintf (asm_out_file, "\n"); } #endif @@ -1677,7 +1755,7 @@ process_options (void) { print_version (stderr, ""); if (! quiet_flag) - print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n"); + print_switch_values (print_to_stderr); } if (flag_syntax_only) |