cprover
armcc_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 "armcc_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("diag_error="));
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_string2int(cmdline.get_value("verbosity"));
54 
55  compiler.set_message_handler(get_message_handler());
56  message_handler.set_verbosity(verbosity);
57 
58  debug() << "ARM mode" << eom;
59 
60  // get configuration
62 
64  config.ansi_c.arch="arm";
65 
66  // determine actions to be taken
67 
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('L'))
79  compiler.library_paths=cmdline.get_values('L');
80  // Don't add the system paths!
81 
82  // these take precedence over -I
83  if(cmdline.isset('J'))
84  {
85  const std::list<std::string> &values=
86  cmdline.get_values('J');
87 
88  for(std::list<std::string>::const_iterator
89  it=values.begin();
90  it!=values.end();
91  it++)
92  config.ansi_c.preprocessor_options.push_back("-J"+*it);
93  }
94 
95  if(cmdline.isset("preinclude="))
96  {
97  const std::list<std::string> &values=
98  cmdline.get_values("preinclude=");
99 
100  for(std::list<std::string>::const_iterator
101  it=values.begin();
102  it!=values.end();
103  it++)
104  config.ansi_c.preprocessor_options.push_back("--preinclude="+*it);
105  }
106 
107  // armcc's default is .o
108  if(cmdline.isset("default_extension="))
109  compiler.object_file_extension=
110  cmdline.get_value("default_extension=");
111  else
112  compiler.object_file_extension="o";
113 
114  // note that ARM's default is "unsigned_chars",
115  // in contrast to gcc's default!
116  if(cmdline.isset("signed_chars"))
118  else
120 
121  // ARM's default is 16 bits for wchar_t
122  if(cmdline.isset("wchar32"))
124  else
126 
127  if(cmdline.isset('o'))
128  {
129  // given goto-armcc -o file1 -o file2, we output to file2, not file1
130  compiler.output_file_object=cmdline.get_values('o').back();
131  compiler.output_file_executable=cmdline.get_values('o').back();
132  }
133  else
134  {
135  compiler.output_file_object="";
136  compiler.output_file_executable="a.out";
137  }
138 
139  if(verbosity>8)
140  {
141  std::list<std::string>::iterator it;
142 
143  std::cout << "Defines:\n";
144  for(it=config.ansi_c.defines.begin();
145  it!=config.ansi_c.defines.end();
146  it++)
147  {
148  std::cout << " " << (*it) << '\n';
149  }
150 
151  std::cout << "Undefines:\n";
152  for(it=config.ansi_c.undefines.begin();
153  it!=config.ansi_c.undefines.end();
154  it++)
155  {
156  std::cout << " " << (*it) << '\n';
157  }
158 
159  std::cout << "Preprocessor Options:\n";
160  for(it=config.ansi_c.preprocessor_options.begin();
162  it++)
163  {
164  std::cout << " " << (*it) << '\n';
165  }
166 
167  std::cout << "Include Paths:\n";
168  for(it=config.ansi_c.include_paths.begin();
169  it!=config.ansi_c.include_paths.end();
170  it++)
171  {
172  std::cout << " " << (*it) << '\n';
173  }
174 
175  std::cout << "Library Paths:\n";
176  for(it=compiler.library_paths.begin();
177  it!=compiler.library_paths.end();
178  it++)
179  {
180  std::cout << " " << (*it) << '\n';
181  }
182 
183  std::cout << "Output file (object): "
184  << compiler.output_file_object << '\n';
185  std::cout << "Output file (executable): "
186  << compiler.output_file_executable << '\n';
187  }
188 
189  // Parse input program, convert to goto program, write output
190  return compiler.doit() ? EX_USAGE : EX_OK;
191 }
192 
195 {
196  std::cout << "goto-armcc understands the options "
197  << "of armcc plus the following.\n\n";
198 }
const std::list< std::string > & get_values(const std::string &option) const
Definition: cmdline.cpp:90
struct configt::ansi_ct ansi_c
gcc_message_handlert message_handler
Definition: armcc_mode.h:38
armcc_cmdlinet & cmdline
Definition: armcc_mode.h:37
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
configt config
Definition: config.cpp:21
unsigned wchar_t_width
Definition: config.h:40
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
Base class for command line interpretation for CL.
int doit() final
does it.
Definition: armcc_mode.cpp:32
irep_idt arch
Definition: config.h:83
bool char_is_unsigned
Definition: config.h:43
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
Compile and link source and object files.
mstreamt & debug()
Definition: message.h:253
message_handlert & get_message_handler()
Definition: message.h:127
virtual void help()
display command line help
void set_verbosity(unsigned _verbosity)
Definition: message.h:44
std::list< std::string > preprocessor_options
Definition: config.h:113
int unsafe_string2int(const std::string &str, int base)
Definition: string2int.cpp:61
void help_mode() final
display command line help
Definition: armcc_mode.cpp:194
const std::string base_name
Definition: goto_cc_mode.h:38
std::list< std::string > include_paths
Definition: config.h:114