Skip to content

Commit 3d4c9e0

Browse files
Michael Tautschnigtautschnig
Michael Tautschnig
authored andcommitted
Properly separate gcc from non-gcc options to avoid repeated special case
Previously, any new non-gcc option (such as verbosity, native-compiler, etc required handling this option in more than one place). This is no longer necessary and instead testing for them via cmdline.get_value/cmdline.isset suffices.
1 parent dca19fd commit 3d4c9e0

File tree

3 files changed

+127
-45
lines changed

3 files changed

+127
-45
lines changed

src/goto-cc/gcc_cmdline.cpp

+79-26
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,40 @@ Function: gcc_cmdlinet::parse
2727
2828
\*******************************************************************/
2929

30+
// non-gcc options
31+
const char *goto_cc_options_with_separated_argument[]=
32+
{
33+
"--verbosity",
34+
"--function",
35+
"--native-compiler",
36+
"--native-linker",
37+
"--print-rejected-preprocessed-source",
38+
NULL
39+
};
40+
41+
// non-gcc options
42+
const char *goto_cc_options_without_argument[]=
43+
{
44+
"--show-symbol-table",
45+
"--show-function-table",
46+
"--ppc-macos",
47+
"--i386-linux",
48+
"--i386-win32",
49+
"--i386-macos",
50+
"--winx64",
51+
"--string-abstraction",
52+
"--no-library",
53+
"--16",
54+
"--32",
55+
"--64",
56+
"--little-endian",
57+
"--big-endian",
58+
"--no-arch",
59+
"--partial-inlining",
60+
"-?",
61+
NULL
62+
};
63+
3064
// separated or concatenated
3165
const char *gcc_options_with_argument[]=
3266
{
@@ -51,11 +85,6 @@ const char *gcc_options_with_argument[]=
5185

5286
const char *gcc_options_with_separated_argument[]=
5387
{
54-
"--verbosity", // non-gcc
55-
"--function", // non-gcc
56-
"--native-compiler", // non-gcc
57-
"--native-linker", // non-gcc
58-
"--print-rejected-preprocessed-source", // non-gcc
5988
"-aux-info",
6089
"--param", // Apple only
6190
"-imacros",
@@ -94,25 +123,8 @@ const char *gcc_options_with_concatenated_argument[]=
94123

95124
const char *gcc_options_without_argument[]=
96125
{
97-
"--show-symbol-table", // NON-GCC
98-
"--show-function-table", // NON-GCC
99-
"--ppc-macos", // NON-GCC
100-
"--i386-linux", // NON-GCC
101-
"--i386-win32", // NON-GCC
102-
"--i386-macos", // NON-GCC
103-
"--winx64", // NON_GCC
104-
"--string-abstraction", // NON-GCC
105-
"--no-library", // NON-GCC
106-
"--16", // NON-GCC
107-
"--32", // NON-GCC
108-
"--64", // NON-GCC
109-
"--little-endian", // NON-GCC
110-
"--big-endian", // NON-GCC
111-
"--no-arch", // NON-GCC
112-
"--partial-inlining", // NON-GCC
126+
"--help",
113127
"-h",
114-
"--help", // NON-GCC
115-
"-?", // NON-GCC
116128
"-r", // for ld mimicking
117129
"-dylib", // for ld mimicking on MacOS
118130
"-c",
@@ -261,14 +273,55 @@ bool gcc_cmdlinet::parse_arguments(
261273
// file?
262274
if(argv_i=="-" || !has_prefix(argv_i, "-"))
263275
{
264-
if(!spec_file)
276+
if(!in_spec_file)
265277
add_infile_arg(argv_i);
266278
continue;
267279
}
268280

269-
// add to new_argv
270-
if(!spec_file)
281+
if(!in_spec_file)
282+
{
283+
argst::const_iterator next=it;
284+
++next;
285+
286+
bool found=false;
287+
288+
if(in_list(argv_i.c_str(),
289+
goto_cc_options_without_argument)) // without argument
290+
{
291+
set(argv_i);
292+
found=true;
293+
}
294+
295+
// separated only, and also allow concatenation with "="
296+
for(const char **o=goto_cc_options_with_separated_argument;
297+
*o!=NULL && !found;
298+
++o)
299+
{
300+
if(argv_i==*o) // separated
301+
{
302+
found=true;
303+
if(next!=args.end())
304+
{
305+
set(argv_i, *next);
306+
++it;
307+
}
308+
else
309+
set(argv_i, "");
310+
}
311+
// concatenated with "="
312+
else if(has_prefix(argv_i, std::string(*o)+"="))
313+
{
314+
found=true;
315+
set(*o, argv_i.substr(strlen(*o)+1));
316+
}
317+
}
318+
319+
if(found)
320+
continue;
321+
322+
// add to new_argv
271323
add_arg(argv_i);
324+
}
272325

273326
// also store in cmdlinet
274327

src/goto-cc/gcc_mode.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -565,20 +565,6 @@ int gcc_modet::preprocess(
565565
{
566566
// ignore
567567
}
568-
else if(it->arg=="--function" ||
569-
it->arg=="--verbosity" ||
570-
it->arg=="--native-linker" ||
571-
it->arg=="--print-rejected-preprocessed-source")
572-
{
573-
// ignore here
574-
skip_next=true;
575-
}
576-
else if(it->arg=="--native-compiler")
577-
{
578-
++it;
579-
assert(it!=cmdline.parsed_argv.end());
580-
compiler=it->arg.c_str();
581-
}
582568
else
583569
new_argv.push_back(it->arg);
584570
}
@@ -634,10 +620,13 @@ Function: gcc_modet::run_gcc
634620

635621
int gcc_modet::run_gcc()
636622
{
637-
// build new argv
638-
std::vector<std::string> new_argv(1);
623+
assert(!cmdline.parsed_argv.empty());
639624

625+
// build new argv
626+
std::vector<std::string> new_argv;
640627
new_argv.reserve(cmdline.parsed_argv.size());
628+
for(const auto &a : cmdline.parsed_argv)
629+
new_argv.push_back(a.arg);
641630

642631
// overwrite argv[0]
643632
new_argv[0]=native_tool_name;

src/goto-cc/ld_cmdline.cpp

+43-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Function: ld_cmdlinet::parse
2525
2626
\*******************************************************************/
2727

28+
const char *goto_ld_options_with_argument[]=
29+
{
30+
"--verbosity",
31+
"--native-compiler",
32+
"--native-linker",
33+
NULL
34+
};
35+
2836
const char *ld_options_with_argument[]=
2937
{
3038
"-a",
@@ -93,7 +101,6 @@ const char *ld_options_with_argument[]=
93101
"--wrap",
94102
"--hash-style",
95103
"-z",
96-
"--verbosity", // non-ld
97104
"--arch", // Apple only
98105
"--ios_version_min", // Apple only
99106
"--macosx_version_min", // Apple only
@@ -258,13 +265,46 @@ bool ld_cmdlinet::parse(int argc, const char **argv)
258265
continue;
259266
}
260267

268+
bool found=false;
269+
270+
for(const char **o=goto_ld_options_with_argument;
271+
*o!=NULL && !found;
272+
++o)
273+
{
274+
std::string os(*o);
275+
276+
// separated?
277+
if(argv_i==os ||
278+
(os.size()>=3 && os[0]=='-' && os[1]=='-' && "-"+argv_i==os))
279+
{
280+
found=true;
281+
if(i!=argc-1)
282+
{
283+
set(os, argv[i+1]);
284+
i++;
285+
}
286+
else
287+
{
288+
std::cerr << "Warning: missing argument for " << argv_i << std::endl;
289+
set(os, ""); // end of command line
290+
}
291+
}
292+
else if(os.size()>2 && has_prefix(argv_i, os+"=")) // concatenated, long
293+
{
294+
found=true;
295+
set(os, argv[i]+os.size()+1);
296+
}
297+
}
298+
299+
// goto-ld-only command line argument found
300+
if(found)
301+
continue;
302+
261303
// add to new_argv
262304
add_arg(argv_i);
263305

264306
// also store in cmdlinet
265307

266-
bool found=false;
267-
268308
for(const char **o=ld_options_without_argument; *o!=NULL && !found; o++)
269309
{
270310
std::string os(*o);

0 commit comments

Comments
 (0)