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