Mercurial > hg > CbC > CbC_gcc
comparison gcc/cppspec.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | a06113de4d67 |
children |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
1 /* Specific flags and argument handling of the C preprocessor. | 1 /* Specific flags and argument handling of the C preprocessor. |
2 Copyright (C) 1999, 2007 Free Software Foundation, Inc. | 2 Copyright (C) 1999, 2007, 2010 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
7 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
20 #include "config.h" | 20 #include "config.h" |
21 #include "system.h" | 21 #include "system.h" |
22 #include "coretypes.h" | 22 #include "coretypes.h" |
23 #include "tm.h" | 23 #include "tm.h" |
24 #include "gcc.h" | 24 #include "gcc.h" |
25 #include "opts.h" | |
25 | 26 |
26 /* The `cpp' executable installed in $(bindir) and $(cpp_install_dir) | 27 /* The `cpp' executable installed in $(bindir) and $(cpp_install_dir) |
27 is a customized version of the gcc driver. It forces -E; -S and -c | 28 is a customized version of the gcc driver. It forces -E; -S and -c |
28 are errors. It defaults to -x c for files with unrecognized | 29 are errors. It defaults to -x c for files with unrecognized |
29 extensions, unless -x options appear in argv, in which case we | 30 extensions, unless -x options appear in argv, in which case we |
30 assume the user knows what they're doing. If no explicit input is | 31 assume the user knows what they're doing. If no explicit input is |
31 mentioned, it will read stdin. */ | 32 mentioned, it will read stdin. */ |
32 | |
33 #ifndef SWITCH_TAKES_ARG | |
34 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR) | |
35 #endif | |
36 | |
37 #ifndef WORD_SWITCH_TAKES_ARG | |
38 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR) | |
39 #endif | |
40 | 33 |
41 /* Suffixes for known sorts of input files. Note that we do not list | 34 /* Suffixes for known sorts of input files. Note that we do not list |
42 files which are normally considered to have been preprocessed already, | 35 files which are normally considered to have been preprocessed already, |
43 since the user's expectation is that `cpp' always preprocesses. */ | 36 since the user's expectation is that `cpp' always preprocesses. */ |
44 static const char *const known_suffixes[] = | 37 static const char *const known_suffixes[] = |
47 ".cc", ".cxx", ".cpp", ".cp", ".c++", | 40 ".cc", ".cxx", ".cpp", ".cp", ".c++", |
48 ".sx", | 41 ".sx", |
49 NULL | 42 NULL |
50 }; | 43 }; |
51 | 44 |
52 /* Filter argc and argv before processing by the gcc driver proper. */ | 45 /* Filter the command line before processing by the gcc driver proper. */ |
53 void | 46 void |
54 lang_specific_driver (int *in_argc, const char *const **in_argv, | 47 lang_specific_driver (struct cl_decoded_option **in_decoded_options, |
48 unsigned int *in_decoded_options_count, | |
55 int *in_added_libraries ATTRIBUTE_UNUSED) | 49 int *in_added_libraries ATTRIBUTE_UNUSED) |
56 { | 50 { |
57 int argc = *in_argc; | 51 struct cl_decoded_option *decoded_options = *in_decoded_options; |
58 const char *const *argv = *in_argv; | 52 unsigned int argc = *in_decoded_options_count; |
59 | 53 |
60 /* Do we need to read stdin? */ | 54 /* Do we need to read stdin? */ |
61 int read_stdin = 1; | 55 int read_stdin = 1; |
62 | 56 |
63 /* Do we need to insert -E? */ | 57 /* Do we need to insert -E? */ |
66 /* Have we seen an input file? */ | 60 /* Have we seen an input file? */ |
67 int seen_input = 0; | 61 int seen_input = 0; |
68 | 62 |
69 /* Positions to insert -xc, -xassembler-with-cpp, and -o, if necessary. | 63 /* Positions to insert -xc, -xassembler-with-cpp, and -o, if necessary. |
70 0 means unnecessary. */ | 64 0 means unnecessary. */ |
71 int lang_c_here = 0; | 65 unsigned int lang_c_here = 0; |
72 int lang_S_here = 0; | 66 unsigned int lang_S_here = 0; |
73 int o_here = 0; | 67 unsigned int o_here = 0; |
74 | 68 |
75 /* Do we need to fix up an input file with an unrecognized suffix? */ | 69 /* Do we need to fix up an input file with an unrecognized suffix? */ |
76 int need_fixups = 1; | 70 int need_fixups = 1; |
77 | 71 |
78 int i, j, quote = 0; | 72 unsigned int i, j; |
79 const char **new_argv; | 73 struct cl_decoded_option *new_decoded_options; |
80 int new_argc; | 74 unsigned int new_argc; |
81 extern int is_cpp_driver; | 75 extern int is_cpp_driver; |
82 | 76 |
83 is_cpp_driver = 1; | 77 is_cpp_driver = 1; |
84 | 78 |
85 /* First pass. If we see an -S or -c, barf. If we see an input file, | 79 /* First pass. If we see an -S or -c, barf. If we see an input file, |
86 turn off read_stdin. If we see a second input file, it is actually | 80 turn off read_stdin. If we see a second input file, it is actually |
87 the output file. If we see a third input file, barf. */ | 81 the output file. If we see a third input file, barf. */ |
88 for (i = 1; i < argc; i++) | 82 for (i = 1; i < argc; i++) |
89 { | 83 { |
90 if (quote == 1) | 84 switch (decoded_options[i].opt_index) |
91 { | 85 { |
92 quote = 0; | 86 case OPT_E: |
93 continue; | 87 need_E = 0; |
94 } | 88 break; |
95 | 89 |
96 if (argv[i][0] == '-') | 90 case OPT_S: |
97 { | 91 case OPT_c: |
98 if (argv[i][1] == '\0') | 92 fatal_error ("%qs is not a valid option to the preprocessor", |
99 read_stdin = 0; | 93 decoded_options[i].orig_option_with_args_text); |
100 else if (argv[i][2] == '\0') | 94 return; |
101 { | 95 |
102 if (argv[i][1] == 'E') | 96 case OPT_x: |
103 need_E = 0; | 97 need_fixups = 0; |
104 else if (argv[i][1] == 'S' || argv[i][1] == 'c') | 98 break; |
105 { | 99 |
106 fatal ("\"%s\" is not a valid option to the preprocessor", | 100 case OPT_SPECIAL_input_file: |
107 argv[i]); | 101 { |
108 return; | 102 const char *file = decoded_options[i].arg; |
109 } | 103 |
110 else if (argv[i][1] == 'x') | 104 if (strcmp (file, "-") == 0) |
111 { | |
112 need_fixups = 0; | |
113 quote = 1; | |
114 } | |
115 else if (SWITCH_TAKES_ARG (argv[i][1])) | |
116 quote = 1; | |
117 } | |
118 else if (argv[i][1] == 'x') | |
119 need_fixups = 0; | |
120 else if (WORD_SWITCH_TAKES_ARG (&argv[i][1])) | |
121 quote = 1; | |
122 } | |
123 else /* not an option */ | |
124 { | |
125 seen_input++; | |
126 if (seen_input == 3) | |
127 { | |
128 fatal ("too many input files"); | |
129 return; | |
130 } | |
131 else if (seen_input == 2) | |
132 { | |
133 o_here = i; | |
134 } | |
135 else | |
136 { | |
137 read_stdin = 0; | 105 read_stdin = 0; |
138 if (need_fixups) | 106 else |
139 { | 107 { |
140 int l = strlen (argv[i]); | 108 seen_input++; |
141 int known = 0; | 109 if (seen_input == 3) |
142 const char *const *suff; | 110 { |
111 fatal_error ("too many input files"); | |
112 return; | |
113 } | |
114 else if (seen_input == 2) | |
115 { | |
116 o_here = i; | |
117 } | |
118 else | |
119 { | |
120 read_stdin = 0; | |
121 if (need_fixups) | |
122 { | |
123 int l = strlen (file); | |
124 int known = 0; | |
125 const char *const *suff; | |
143 | 126 |
144 for (suff = known_suffixes; *suff; suff++) | 127 for (suff = known_suffixes; *suff; suff++) |
145 if (!strcmp (*suff, &argv[i][l - strlen(*suff)])) | 128 if (!strcmp (*suff, &file[l - strlen(*suff)])) |
146 { | 129 { |
147 known = 1; | 130 known = 1; |
148 break; | 131 break; |
132 } | |
133 | |
134 if (! known) | |
135 { | |
136 /* .s files are a special case; we have to | |
137 treat them like .S files so | |
138 -D__ASSEMBLER__ will be in effect. */ | |
139 if (!strcmp (".s", &file[l - 2])) | |
140 lang_S_here = i; | |
141 else | |
142 lang_c_here = i; | |
143 } | |
149 } | 144 } |
150 | 145 } |
151 if (! known) | 146 } |
152 { | 147 } |
153 /* .s files are a special case; we have to treat | 148 break; |
154 them like .S files so -D__ASSEMBLER__ will be | |
155 in effect. */ | |
156 if (!strcmp (".s", &argv[i][l - 2])) | |
157 lang_S_here = i; | |
158 else | |
159 lang_c_here = i; | |
160 } | |
161 } | |
162 } | |
163 } | 149 } |
164 } | 150 } |
165 | 151 |
166 /* If we don't need to edit the command line, we can bail early. */ | 152 /* If we don't need to edit the command line, we can bail early. */ |
167 | 153 |
168 new_argc = argc + need_E + read_stdin | 154 new_argc = argc + need_E + read_stdin + !!lang_c_here + !!lang_S_here; |
169 + !!o_here + !!lang_c_here + !!lang_S_here; | |
170 | 155 |
171 if (new_argc == argc) | 156 if (new_argc == argc && !o_here) |
172 return; | 157 return; |
173 | 158 |
174 /* One more slot for a terminating null. */ | 159 new_decoded_options = XNEWVEC (struct cl_decoded_option, new_argc); |
175 new_argv = XNEWVEC (const char *, new_argc + 1); | |
176 | 160 |
177 new_argv[0] = argv[0]; | 161 new_decoded_options[0] = new_decoded_options[0]; |
178 j = 1; | 162 j = 1; |
179 | 163 |
180 if (need_E) | 164 if (need_E) |
181 new_argv[j++] = "-E"; | 165 generate_option (OPT_E, NULL, 1, CL_DRIVER, &new_decoded_options[j++]); |
182 | 166 |
183 for (i = 1; i < argc; i++, j++) | 167 for (i = 1; i < argc; i++, j++) |
184 { | 168 { |
185 if (i == lang_c_here) | 169 if (i == lang_c_here) |
186 new_argv[j++] = "-xc"; | 170 generate_option (OPT_x, "c", 1, CL_DRIVER, &new_decoded_options[j++]); |
187 else if (i == lang_S_here) | 171 else if (i == lang_S_here) |
188 new_argv[j++] = "-xassembler-with-cpp"; | 172 generate_option (OPT_x, "assembler-with-cpp", 1, CL_DRIVER, |
173 &new_decoded_options[j++]); | |
189 else if (i == o_here) | 174 else if (i == o_here) |
190 new_argv[j++] = "-o"; | 175 { |
176 generate_option (OPT_o, decoded_options[i].arg, 1, CL_DRIVER, | |
177 &new_decoded_options[j]); | |
178 continue; | |
179 } | |
191 | 180 |
192 new_argv[j] = argv[i]; | 181 new_decoded_options[j] = decoded_options[i]; |
193 } | 182 } |
194 | 183 |
195 if (read_stdin) | 184 if (read_stdin) |
196 new_argv[j++] = "-"; | 185 generate_option_input_file ("-", &new_decoded_options[j++]); |
197 | 186 |
198 new_argv[j] = NULL; | 187 *in_decoded_options_count = new_argc; |
199 *in_argc = new_argc; | 188 *in_decoded_options = new_decoded_options; |
200 *in_argv = new_argv; | |
201 } | 189 } |
202 | 190 |
203 /* Called before linking. Returns 0 on success and -1 on failure. */ | 191 /* Called before linking. Returns 0 on success and -1 on failure. */ |
204 int lang_specific_pre_link (void) | 192 int lang_specific_pre_link (void) |
205 { | 193 { |