cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
ms_cl_mode.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Visual Studio CL Mode
4
5
Author: CM Wintersteiger, 2006
6
7
\*******************************************************************/
8
11
12
#include "
ms_cl_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 <
util/config.h
>
23
#include <
util/get_base_name.h
>
24
#include <
util/message.h
>
25
26
#include "
compile.h
"
27
#include "
ms_cl_version.h
"
28
29
#include <filesystem>
30
#include <iostream>
31
32
static
bool
has_directory_suffix
(
const
std::string &path)
33
{
34
// MS CL decides whether a parameter is a directory on the
35
// basis of the / or \\ suffix; it doesn't matter
36
// whether the directory actually exists.
37
return
path.empty() ? false :
38
path.back()==
'/'
|| path.back()==
'\\'
;
39
}
40
42
int
ms_cl_modet::doit
()
43
{
44
if
(
cmdline
.isset(
'?'
) ||
45
cmdline
.isset(
"help"
))
46
{
47
help
();
48
return
EX_OK;
49
}
50
51
compilet
compiler(
cmdline
,
message_handler
,
cmdline
.isset(
"WX"
));
52
53
#if 0
54
bool
act_as_ld=
55
has_prefix
(
base_name
,
"link"
) ||
56
has_prefix
(
base_name
,
"goto-link"
);
57
#endif
58
59
const
auto
default_verbosity = (
cmdline
.isset(
"Wall"
) ||
cmdline
.isset(
"W4"
))
60
?
messaget::M_WARNING
61
:
messaget::M_ERROR
;
62
const
auto
verbosity =
messaget::eval_verbosity
(
63
cmdline
.get_value(
"verbosity"
), default_verbosity,
message_handler
);
64
message_handler
.print_warnings_as_errors(
cmdline
.isset(
"WX"
));
65
66
ms_cl_versiont
ms_cl_version;
67
ms_cl_version.
get
(
"cl.exe"
);
68
69
messaget
log{
message_handler
};
70
log.
debug
() <<
"Visual Studio mode "
<< ms_cl_version <<
messaget::eom
;
71
72
// model validation
73
compiler.
validate_goto_model
=
cmdline
.isset(
"validate-goto-model"
);
74
75
// get configuration
76
config
.set(
cmdline
);
77
78
if
(ms_cl_version.
target
==
ms_cl_versiont::targett::x86
)
79
config
.ansi_c.set_32();
80
else
if
(ms_cl_version.
target
==
ms_cl_versiont::targett::ARM
)
81
config
.ansi_c.set_32();
82
else
if
(ms_cl_version.
target
==
ms_cl_versiont::targett::x86
)
83
config
.ansi_c.set_64();
84
85
config
.ansi_c.mode=
configt::ansi_ct::flavourt::VISUAL_STUDIO
;
86
compiler.
object_file_extension
=
"obj"
;
87
88
// determine actions to be undertaken
89
90
if
(
cmdline
.isset(
'E'
) ||
cmdline
.isset(
'P'
))
91
compiler.
mode
=
compilet::PREPROCESS_ONLY
;
92
else
if
(
cmdline
.isset(
'c'
))
93
compiler.
mode
=
compilet::COMPILE_ONLY
;
94
else
95
compiler.
mode
=
compilet::COMPILE_LINK_EXECUTABLE
;
96
97
if
(
cmdline
.isset(
"std"
))
98
{
99
const
std::string std_string =
cmdline
.get_value(
"std"
);
100
101
if
(
102
std_string ==
":c++14"
|| std_string ==
"=c++14"
||
103
std_string ==
":c++17"
|| std_string ==
"=c++17"
||
104
std_string ==
":c++latest"
|| std_string ==
"=c++latest"
)
105
{
106
// we don't have any newer version at the moment
107
config
.cpp.set_cpp14();
108
}
109
else
if
(std_string ==
":c++11"
|| std_string ==
"=c++11"
)
110
{
111
// this isn't really a Visual Studio variant, we just do this for GCC
112
// command-line compatibility
113
config
.cpp.set_cpp11();
114
}
115
else
116
{
117
log.
warning
() <<
"unknown language standard "
<< std_string
118
<<
messaget::eom
;
119
}
120
}
121
else
122
config
.cpp.set_cpp14();
123
124
compiler.
echo_file_name
=
true
;
125
126
if
(
cmdline
.isset(
"Fo"
))
127
{
128
std::string Fo_value =
cmdline
.get_value(
"Fo"
);
129
130
// this could be a directory or a file name
131
if
(
has_directory_suffix
(Fo_value))
132
{
133
compiler.
output_directory_object
= Fo_value;
134
135
if
(!std::filesystem::is_directory(Fo_value))
136
log.
warning
() <<
"not a directory: "
<< Fo_value <<
messaget::eom
;
137
}
138
else
139
compiler.
output_file_object
= Fo_value;
140
}
141
142
if
(
143
compiler.
mode
==
compilet::COMPILE_ONLY
&&
144
cmdline
.args.size() > 1 &&
145
compiler.
output_directory_object
.empty())
146
{
147
log.
error
() <<
"output directory required for /c with multiple input files"
148
<<
messaget::eom
;
149
return
EX_USAGE;
150
}
151
152
if
(
cmdline
.isset(
"Fe"
))
153
{
154
compiler.
output_file_executable
=
cmdline
.get_value(
"Fe"
);
155
156
// this could be a directory
157
if
(
158
has_directory_suffix
(compiler.
output_file_executable
) &&
159
cmdline
.args.size() >= 1)
160
{
161
if
(!std::filesystem::is_directory(compiler.
output_file_executable
))
162
{
163
log.
warning
() <<
"not a directory: "
<< compiler.
output_file_executable
164
<<
messaget::eom
;
165
}
166
167
compiler.
output_file_executable
+=
168
get_base_name
(
cmdline
.args[0],
true
) +
".exe"
;
169
}
170
}
171
else
172
{
173
// We need at least one argument.
174
// CL uses the first file name it gets!
175
if
(
cmdline
.args.size()>=1)
176
compiler.
output_file_executable
=
177
get_base_name
(
cmdline
.args[0],
true
)+
".exe"
;
178
}
179
180
if
(
cmdline
.isset(
'J'
))
181
config
.ansi_c.char_is_unsigned=
true
;
182
183
if
(verbosity >
messaget::M_STATISTICS
)
184
{
185
std::list<std::string>::iterator it;
186
187
std::cout <<
"Defines:\n"
;
188
for
(it=
config
.ansi_c.defines.begin();
189
it!=
config
.ansi_c.defines.end();
190
it++)
191
{
192
std::cout <<
" "
<< (*it) <<
'\n'
;
193
}
194
195
std::cout <<
"Undefines:\n"
;
196
for
(it=
config
.ansi_c.undefines.begin();
197
it!=
config
.ansi_c.undefines.end();
198
it++)
199
{
200
std::cout <<
" "
<< (*it) <<
'\n'
;
201
}
202
203
std::cout <<
"Preprocessor Options:\n"
;
204
for
(it=
config
.ansi_c.preprocessor_options.begin();
205
it!=
config
.ansi_c.preprocessor_options.end();
206
it++)
207
{
208
std::cout <<
" "
<< (*it) <<
'\n'
;
209
}
210
211
std::cout <<
"Include Paths:\n"
;
212
for
(it=
config
.ansi_c.include_paths.begin();
213
it!=
config
.ansi_c.include_paths.end();
214
it++)
215
{
216
std::cout <<
" "
<< (*it) <<
'\n'
;
217
}
218
219
std::cout <<
"Library Paths:\n"
;
220
for
(it=compiler.
library_paths
.begin();
221
it!=compiler.
library_paths
.end();
222
it++)
223
{
224
std::cout <<
" "
<< (*it) <<
'\n'
;
225
}
226
227
std::cout <<
"Output file (object): "
228
<< compiler.
output_file_object
<<
'\n'
;
229
std::cout <<
"Output file (executable): "
230
<< compiler.
output_file_executable
<<
'\n'
;
231
}
232
233
// Parse input program, convert to goto program, write output
234
return
compiler.
doit
() ? EX_USAGE : EX_OK;
235
}
236
238
void
ms_cl_modet::help_mode
()
239
{
240
std::cout <<
"goto-cl understands the options of CL plus the following.\n\n"
;
241
}
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::echo_file_name
bool echo_file_name
Definition
compile.h:35
compilet::output_file_object
std::string output_file_object
Definition
compile.h:55
compilet::output_directory_object
std::string output_directory_object
Definition
compile.h:55
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
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::error
mstreamt & error() const
Definition
message.h:391
messaget::debug
mstreamt & debug() const
Definition
message.h:421
messaget::warning
mstreamt & warning() const
Definition
message.h:396
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
ms_cl_modet::cmdline
ms_cl_cmdlinet & cmdline
Definition
ms_cl_mode.h:36
ms_cl_modet::message_handler
cl_message_handlert message_handler
Definition
ms_cl_mode.h:37
ms_cl_modet::doit
virtual int doit()
does it.
Definition
ms_cl_mode.cpp:42
ms_cl_modet::help_mode
virtual void help_mode()
display command line help
Definition
ms_cl_mode.cpp:238
ms_cl_versiont
Definition
ms_cl_version.h:20
ms_cl_versiont::get
void get(const std::string &executable)
Definition
ms_cl_version.cpp:18
ms_cl_versiont::target
enum ms_cl_versiont::targett target
ms_cl_versiont::targett::ARM
@ ARM
Definition
ms_cl_version.h:44
ms_cl_versiont::targett::x86
@ x86
Definition
ms_cl_version.h:42
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
get_base_name
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
Definition
get_base_name.cpp:16
get_base_name.h
has_directory_suffix
static bool has_directory_suffix(const std::string &path)
Definition
ms_cl_mode.cpp:32
ms_cl_mode.h
Visual Studio CL Mode.
ms_cl_version.h
message.h
configt::ansi_ct::flavourt::VISUAL_STUDIO
@ VISUAL_STUDIO
Definition
config.h:277
goto-cc
ms_cl_mode.cpp
Generated by
1.17.0