-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcw_mode.cpp
186 lines (148 loc) · 4.53 KB
/
cw_mode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*******************************************************************\
Module: Command line option container
Author: CM Wintersteiger, 2006
\*******************************************************************/
/// \file
/// Command line option container
#include "cw_mode.h"
#ifdef _WIN32
#define EX_OK 0
#define EX_USAGE 64
#define EX_SOFTWARE 70
#else
#include <sysexits.h>
#endif
#include <iostream>
#include <util/message.h>
#include <util/config.h>
#include "compile.h"
/// does it.
int cw_modet::doit()
{
if(cmdline.isset('?') || cmdline.isset("help"))
{
help();
return EX_OK;
}
compilet compiler(cmdline, message_handler, cmdline.isset("Werror"));
#if 0
bool act_as_ld=
has_prefix(base_name, "ld") ||
has_prefix(base_name, "goto-ld") ||
has_prefix(base_name, "link") ||
has_prefix(base_name, "goto-link");
#endif
const auto default_verbosity =
cmdline.isset("Wall") ? messaget::M_WARNING : messaget::M_ERROR;
const auto verbosity = messaget::eval_verbosity(
cmdline.get_value("verbosity"), default_verbosity, message_handler);
messaget log{message_handler};
log.debug() << "CodeWarrior mode" << messaget::eom;
// model validation
compiler.validate_goto_model = cmdline.isset("validate-goto-model");
// get configuration
config.set(cmdline);
config.ansi_c.mode=configt::ansi_ct::flavourt::CODEWARRIOR;
compiler.object_file_extension="o";
// determine actions to be taken
if(cmdline.isset('E'))
compiler.mode=compilet::PREPROCESS_ONLY;
else if(cmdline.isset('c') || cmdline.isset('S'))
compiler.mode=compilet::COMPILE_ONLY;
else
compiler.mode=compilet::COMPILE_LINK_EXECUTABLE;
if(cmdline.isset('U'))
config.ansi_c.undefines=cmdline.get_values('U');
if(cmdline.isset("undef"))
config.ansi_c.preprocessor_options.push_back("-undef");
if(cmdline.isset("nostdinc"))
config.ansi_c.preprocessor_options.push_back("-nostdinc");
if(cmdline.isset('L'))
compiler.library_paths=cmdline.get_values('L');
// Don't add the system paths!
if(cmdline.isset('l'))
compiler.libraries=cmdline.get_values('l');
if(cmdline.isset('o'))
{
// given gcc -o file1 -o file2,
// gcc will output to file2, not file1
compiler.output_file_object=cmdline.get_values('o').back();
compiler.output_file_executable=cmdline.get_values('o').back();
}
else
{
compiler.output_file_object.clear();
compiler.output_file_executable="a.out";
}
if(cmdline.isset("Wp,"))
{
const std::list<std::string> &values=
cmdline.get_values("Wp,");
for(std::list<std::string>::const_iterator
it=values.begin();
it!=values.end();
it++)
config.ansi_c.preprocessor_options.push_back("-Wp,"+*it);
}
if(cmdline.isset("isystem"))
{
const std::list<std::string> &values=
cmdline.get_values("isystem");
for(std::list<std::string>::const_iterator
it=values.begin();
it!=values.end();
it++)
config.ansi_c.preprocessor_options.push_back("-isystem "+*it);
}
if(verbosity > messaget::M_STATISTICS)
{
std::list<std::string>::iterator it;
std::cout << "Defines:\n";
for(it=config.ansi_c.defines.begin();
it!=config.ansi_c.defines.end();
it++)
{
std::cout << " " << (*it) << '\n';
}
std::cout << "Undefines:\n";
for(it=config.ansi_c.undefines.begin();
it!=config.ansi_c.undefines.end();
it++)
{
std::cout << " " << (*it) << '\n';
}
std::cout << "Preprocessor Options:\n";
for(it=config.ansi_c.preprocessor_options.begin();
it!=config.ansi_c.preprocessor_options.end();
it++)
{
std::cout << " " << (*it) << '\n';
}
std::cout << "Include Paths:\n";
for(it=config.ansi_c.include_paths.begin();
it!=config.ansi_c.include_paths.end();
it++)
{
std::cout << " " << (*it) << '\n';
}
std::cout << "Library Paths:\n";
for(it=compiler.library_paths.begin();
it!=compiler.library_paths.end();
it++)
{
std::cout << " " << (*it) << '\n';
}
std::cout << "Output file (object): "
<< compiler.output_file_object << '\n';
std::cout << "Output file (executable): "
<< compiler.output_file_executable << '\n';
}
// Parse input program, convert to goto program, write output
return compiler.doit() ? EX_USAGE : EX_OK;
}
/// display command line help
void cw_modet::help_mode()
{
std::cout << "goto-cw understands the options of "
<< "gcc (mwcc mode) plus the following.\n\n";
}