cprover
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
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 verbosity = messaget::eval_verbosity(
50
52 log.debug() << "CodeWarrior mode" << messaget::eom;
53
54 // model validation
55 compiler.validate_goto_model = cmdline.isset("validate-goto-model");
56
57 // get configuration
59
61
62 compiler.object_file_extension="o";
63
64 // determine actions to be taken
65 if(cmdline.isset('E'))
67 else if(cmdline.isset('c') || cmdline.isset('S'))
69 else
71
72 if(cmdline.isset('U'))
74
75 if(cmdline.isset("undef"))
76 config.ansi_c.preprocessor_options.push_back("-undef");
77
78 if(cmdline.isset("nostdinc"))
79 config.ansi_c.preprocessor_options.push_back("-nostdinc");
80
81 if(cmdline.isset('L'))
82 compiler.library_paths=cmdline.get_values('L');
83 // Don't add the system paths!
84
85 if(cmdline.isset('l'))
86 compiler.libraries=cmdline.get_values('l');
87
88 if(cmdline.isset('o'))
89 {
90 // given gcc -o file1 -o file2,
91 // gcc will output to file2, not file1
92 compiler.output_file_object=cmdline.get_values('o').back();
93 compiler.output_file_executable=cmdline.get_values('o').back();
94 }
95 else
96 {
97 compiler.output_file_object.clear();
98 compiler.output_file_executable="a.out";
99 }
100
101 if(cmdline.isset("Wp,"))
102 {
103 const std::list<std::string> &values=
104 cmdline.get_values("Wp,");
105
106 for(std::list<std::string>::const_iterator
107 it=values.begin();
108 it!=values.end();
109 it++)
110 config.ansi_c.preprocessor_options.push_back("-Wp,"+*it);
111 }
112
113 if(cmdline.isset("isystem"))
114 {
115 const std::list<std::string> &values=
116 cmdline.get_values("isystem");
117
118 for(std::list<std::string>::const_iterator
119 it=values.begin();
120 it!=values.end();
121 it++)
122 config.ansi_c.preprocessor_options.push_back("-isystem "+*it);
123 }
124
125 if(verbosity > messaget::M_STATISTICS)
126 {
127 std::list<std::string>::iterator it;
128
129 std::cout << "Defines:\n";
130 for(it=config.ansi_c.defines.begin();
131 it!=config.ansi_c.defines.end();
132 it++)
133 {
134 std::cout << " " << (*it) << '\n';
135 }
136
137 std::cout << "Undefines:\n";
138 for(it=config.ansi_c.undefines.begin();
139 it!=config.ansi_c.undefines.end();
140 it++)
141 {
142 std::cout << " " << (*it) << '\n';
143 }
144
145 std::cout << "Preprocessor Options:\n";
146 for(it=config.ansi_c.preprocessor_options.begin();
148 it++)
149 {
150 std::cout << " " << (*it) << '\n';
151 }
152
153 std::cout << "Include Paths:\n";
154 for(it=config.ansi_c.include_paths.begin();
155 it!=config.ansi_c.include_paths.end();
156 it++)
157 {
158 std::cout << " " << (*it) << '\n';
159 }
160
161 std::cout << "Library Paths:\n";
162 for(it=compiler.library_paths.begin();
163 it!=compiler.library_paths.end();
164 it++)
165 {
166 std::cout << " " << (*it) << '\n';
167 }
168
169 std::cout << "Output file (object): "
170 << compiler.output_file_object << '\n';
171 std::cout << "Output file (executable): "
172 << compiler.output_file_executable << '\n';
173 }
174
175 // Parse input program, convert to goto program, write output
176 return compiler.doit() ? EX_USAGE : EX_OK;
177}
178
181{
182 std::cout << "goto-cw understands the options of "
183 << "gcc (mwcc mode) plus the following.\n\n";
184}
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:109
@ PREPROCESS_ONLY
Definition: compile.h:37
@ COMPILE_LINK_EXECUTABLE
Definition: compile.h:42
@ COMPILE_ONLY
Definition: compile.h:38
std::string output_file_object
Definition: compile.h:54
std::list< std::string > libraries
Definition: compile.h:48
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:60
std::string object_file_extension
Definition: compile.h:50
bool validate_goto_model
Definition: compile.h:35
enum compilet::@3 mode
std::list< std::string > library_paths
Definition: compile.h:45
std::string output_file_executable
Definition: compile.h:51
bool set(const cmdlinet &cmdline)
Definition: config.cpp:798
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:180
const std::string base_name
Definition: goto_cc_mode.h:39
void help()
display command line help
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
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:171
@ M_ERROR
Definition: message.h:170
static eomt eom
Definition: message.h:297
Compile and link source and object files.
configt config
Definition: config.cpp:25
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
Base class for command line interpretation.
std::list< std::string > include_paths
Definition: config.h:238
std::list< std::string > undefines
Definition: config.h:236
std::list< std::string > preprocessor_options
Definition: config.h:237
std::list< std::string > defines
Definition: config.h:235
flavourt mode
Definition: config.h:222