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  compiler.object_file_extension =
109  cmdline.value_opt("default_extension=").value_or("o");
110 
111  // note that ARM's default is "unsigned_chars",
112  // in contrast to gcc's default!
113  if(cmdline.isset("signed_chars"))
115  else
117 
118  // ARM's default is 16 bits for wchar_t
119  if(cmdline.isset("wchar32"))
121  else
123 
124  if(cmdline.isset('o'))
125  {
126  // given goto-armcc -o file1 -o file2, we output to file2, not file1
127  compiler.output_file_object=cmdline.get_values('o').back();
128  compiler.output_file_executable=cmdline.get_values('o').back();
129  }
130  else
131  {
132  compiler.output_file_object.clear();
133  compiler.output_file_executable="a.out";
134  }
135 
136  if(verbosity > messaget::M_STATISTICS)
137  {
138  std::list<std::string>::iterator it;
139 
140  std::cout << "Defines:\n";
141  for(it=config.ansi_c.defines.begin();
142  it!=config.ansi_c.defines.end();
143  it++)
144  {
145  std::cout << " " << (*it) << '\n';
146  }
147 
148  std::cout << "Undefines:\n";
149  for(it=config.ansi_c.undefines.begin();
150  it!=config.ansi_c.undefines.end();
151  it++)
152  {
153  std::cout << " " << (*it) << '\n';
154  }
155 
156  std::cout << "Preprocessor Options:\n";
157  for(it=config.ansi_c.preprocessor_options.begin();
159  it++)
160  {
161  std::cout << " " << (*it) << '\n';
162  }
163 
164  std::cout << "Include Paths:\n";
165  for(it=config.ansi_c.include_paths.begin();
166  it!=config.ansi_c.include_paths.end();
167  it++)
168  {
169  std::cout << " " << (*it) << '\n';
170  }
171 
172  std::cout << "Library Paths:\n";
173  for(it=compiler.library_paths.begin();
174  it!=compiler.library_paths.end();
175  it++)
176  {
177  std::cout << " " << (*it) << '\n';
178  }
179 
180  std::cout << "Output file (object): "
181  << compiler.output_file_object << '\n';
182  std::cout << "Output file (executable): "
183  << compiler.output_file_executable << '\n';
184  }
185 
186  // Parse input program, convert to goto program, write output
187  return compiler.doit() ? EX_USAGE : EX_OK;
188 }
189 
192 {
193  std::cout << "goto-armcc understands the options "
194  << "of armcc plus the following.\n\n";
195 }
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:191
std::string get_value(char option) const
Definition: cmdline.cpp:48
virtual bool isset(char option) const
Definition: cmdline.cpp:30
std::optional< std::string > value_opt(char option) const
Definition: cmdline.cpp:53
const std::list< std::string > & get_values(const std::string &option) const
Definition: cmdline.cpp:119
@ 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