CBMC
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/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("diag_error="));
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(
51  cmdline.get_value("verbosity"), default_verbosity, message_handler);
53 
55  log.debug() << "ARM mode" << messaget::eom;
56 
57  // model validation
58  compiler.validate_goto_model = cmdline.isset("validate-goto-model");
59 
60  // get configuration
62 
64  config.ansi_c.arch="arm";
65 
66  // determine actions to be taken
67 
68  if(cmdline.isset('E'))
70  else if(cmdline.isset('c') || cmdline.isset('S'))
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.clear();
136  compiler.output_file_executable="a.out";
137  }
138 
139  if(verbosity > messaget::M_STATISTICS)
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 }
configt config
Definition: config.cpp:25
Base class for command line interpretation for CL.
gcc_message_handlert message_handler
Definition: armcc_mode.h:37
int doit() final
does it.
Definition: armcc_mode.cpp:30
armcc_cmdlinet & cmdline
Definition: armcc_mode.h:36
void help_mode() final
display command line help
Definition: armcc_mode.cpp:194
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:38
@ COMPILE_LINK_EXECUTABLE
Definition: compile.h:43
@ COMPILE_ONLY
Definition: compile.h:39
std::string output_file_object
Definition: compile.h:55
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:54
std::string object_file_extension
Definition: compile.h:51
bool validate_goto_model
Definition: compile.h:36
enum compilet::@3 mode
std::list< std::string > library_paths
Definition: compile.h:46
std::string output_file_executable
Definition: compile.h:52
bool set(const cmdlinet &cmdline)
Definition: config.cpp:863
struct configt::ansi_ct ansi_c
void print_warnings_as_errors(bool yes)
With yes set to true, prefix warnings with "error:" instead of "warning:".
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: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
double log(double x)
Definition: math.c:2776
std::list< std::string > include_paths
Definition: config.h:272
irep_idt arch
Definition: config.h:223
std::list< std::string > undefines
Definition: config.h:270
std::list< std::string > preprocessor_options
Definition: config.h:271
std::list< std::string > defines
Definition: config.h:269
std::size_t wchar_t_width
Definition: config.h:147
bool char_is_unsigned
Definition: config.h:150
flavourt mode
Definition: config.h:256