CBMC
Loading...
Searching...
No Matches
cw_mode.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Command line option container
4
5Author: 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
31{
32 if(cmdline.isset('?') || cmdline.isset("help"))
33 {
34 help();
35 return EX_OK;
36 }
37
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 =
50 const auto verbosity = messaget::eval_verbosity(
52
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
61
63
64 compiler.object_file_extension="o";
65
66 // determine actions to be taken
67 if(cmdline.isset('E'))
69 else if(cmdline.isset('c') || cmdline.isset('S'))
71 else
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
183{
184 std::cout << "goto-cw understands the options of "
185 << "gcc (mwcc mode) plus the following.\n\n";
186}
configt config
Definition config.cpp:25
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::string get_value(char option) const
Definition cmdline.cpp:48
virtual bool isset(char option) const
Definition cmdline.cpp:30
const std::list< std::string > & get_values(const std::string &option) const
Definition cmdline.cpp:119
@ PREPROCESS_ONLY
Definition compile.h:38
@ COMPILE_LINK_EXECUTABLE
Definition compile.h:43
@ COMPILE_ONLY
Definition compile.h:39
bool set(const cmdlinet &cmdline)
Definition config.cpp:863
struct configt::ansi_ct ansi_c
gcc_cmdlinet & cmdline
Definition cw_mode.h:35
virtual int doit()
does it.
Definition cw_mode.cpp:30
console_message_handlert message_handler
Definition cw_mode.h:36
virtual void help_mode()
display command line help
Definition cw_mode.cpp:182
const std::string base_name
void help()
display command line help
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
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
@ M_STATISTICS
Definition message.h:170
@ M_ERROR
Definition message.h:169
@ M_WARNING
Definition message.h:169
static eomt eom
Definition message.h:289
Compile and link source and object files.
bool has_prefix(const std::string &s, const std::string &prefix)
Definition converter.cpp:13
Base class for command line interpretation.
double log(double x)
Definition math.c:2449