cprover
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/prefix.h>
26 #include <util/config.h>
27 
28 #include "compile.h"
29 
32 {
33  if(cmdline.isset('?') || cmdline.isset("help"))
34  {
35  help();
36  return EX_OK;
37  }
38 
39  compilet compiler(cmdline, message_handler, cmdline.isset("Werror"));
40 
41  #if 0
42  bool act_as_ld=
43  has_prefix(base_name, "ld") ||
44  has_prefix(base_name, "goto-ld") ||
45  has_prefix(base_name, "link") ||
46  has_prefix(base_name, "goto-link");
47  #endif
48 
49  const auto verbosity = eval_verbosity(
51 
52  debug() << "CodeWarrior mode" << eom;
53 
54  // get configuration
56 
58 
59  compiler.object_file_extension="o";
60 
61  // determine actions to be taken
62  if(cmdline.isset('E'))
63  compiler.mode=compilet::PREPROCESS_ONLY;
64  else if(cmdline.isset('c') || cmdline.isset('S'))
65  compiler.mode=compilet::COMPILE_ONLY;
66  else
68 
69  if(cmdline.isset('U'))
71 
72  if(cmdline.isset("undef"))
73  config.ansi_c.preprocessor_options.push_back("-undef");
74 
75  if(cmdline.isset("nostdinc"))
76  config.ansi_c.preprocessor_options.push_back("-nostdinc");
77 
78  if(cmdline.isset('L'))
79  compiler.library_paths=cmdline.get_values('L');
80  // Don't add the system paths!
81 
82  if(cmdline.isset('l'))
83  compiler.libraries=cmdline.get_values('l');
84 
85  if(cmdline.isset('o'))
86  {
87  // given gcc -o file1 -o file2,
88  // gcc will output to file2, not file1
89  compiler.output_file_object=cmdline.get_values('o').back();
90  compiler.output_file_executable=cmdline.get_values('o').back();
91  }
92  else
93  {
94  compiler.output_file_object="";
95  compiler.output_file_executable="a.out";
96  }
97 
98  if(cmdline.isset("Wp,"))
99  {
100  const std::list<std::string> &values=
101  cmdline.get_values("Wp,");
102 
103  for(std::list<std::string>::const_iterator
104  it=values.begin();
105  it!=values.end();
106  it++)
107  config.ansi_c.preprocessor_options.push_back("-Wp,"+*it);
108  }
109 
110  if(cmdline.isset("isystem"))
111  {
112  const std::list<std::string> &values=
113  cmdline.get_values("isystem");
114 
115  for(std::list<std::string>::const_iterator
116  it=values.begin();
117  it!=values.end();
118  it++)
119  config.ansi_c.preprocessor_options.push_back("-isystem "+*it);
120  }
121 
122  if(verbosity > messaget::M_STATISTICS)
123  {
124  std::list<std::string>::iterator it;
125 
126  std::cout << "Defines:\n";
127  for(it=config.ansi_c.defines.begin();
128  it!=config.ansi_c.defines.end();
129  it++)
130  {
131  std::cout << " " << (*it) << '\n';
132  }
133 
134  std::cout << "Undefines:\n";
135  for(it=config.ansi_c.undefines.begin();
136  it!=config.ansi_c.undefines.end();
137  it++)
138  {
139  std::cout << " " << (*it) << '\n';
140  }
141 
142  std::cout << "Preprocessor Options:\n";
143  for(it=config.ansi_c.preprocessor_options.begin();
145  it++)
146  {
147  std::cout << " " << (*it) << '\n';
148  }
149 
150  std::cout << "Include Paths:\n";
151  for(it=config.ansi_c.include_paths.begin();
152  it!=config.ansi_c.include_paths.end();
153  it++)
154  {
155  std::cout << " " << (*it) << '\n';
156  }
157 
158  std::cout << "Library Paths:\n";
159  for(it=compiler.library_paths.begin();
160  it!=compiler.library_paths.end();
161  it++)
162  {
163  std::cout << " " << (*it) << '\n';
164  }
165 
166  std::cout << "Output file (object): "
167  << compiler.output_file_object << '\n';
168  std::cout << "Output file (executable): "
169  << compiler.output_file_executable << '\n';
170  }
171 
172  // Parse input program, convert to goto program, write output
173  return compiler.doit() ? EX_USAGE : EX_OK;
174 }
175 
178 {
179  std::cout << "goto-cw understands the options of "
180  << "gcc (mwcc mode) plus the following.\n\n";
181 }
const std::list< std::string > & get_values(const std::string &option) const
Definition: cmdline.cpp:110
struct configt::ansi_ct ansi_c
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:78
std::list< std::string > defines
Definition: config.h:120
std::string get_value(char option) const
Definition: cmdline.cpp:45
std::list< std::string > undefines
Definition: config.h:121
static mstreamt & eom(mstreamt &m)
Definition: message.h:272
virtual int doit()
does it.
Definition: cw_mode.cpp:31
configt config
Definition: config.cpp:23
bool set(const cmdlinet &cmdline)
Definition: config.cpp:738
virtual bool isset(char option) const
Definition: cmdline.cpp:27
flavourt mode
Definition: config.h:114
virtual void help_mode()
display command line help
Definition: cw_mode.cpp:177
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
console_message_handlert message_handler
Definition: cw_mode.h:36
Compile and link source and object files.
Base class for command line interpretation.
virtual void help()
display command line help
gcc_cmdlinet & cmdline
Definition: cw_mode.h:35
mstreamt & debug() const
Definition: message.h:332
std::list< std::string > preprocessor_options
Definition: config.h:122
const std::string base_name
Definition: goto_cc_mode.h:38
std::list< std::string > include_paths
Definition: config.h:123