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