CBMC
goto_cc_main.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: GOTO-CC Main Module
4 
5 Authors: Daniel Kroening, kroening@kroening.com
6 
7 Date: May 2006
8 
9 \*******************************************************************/
10 
13 
14 #include <algorithm>
15 #include <iostream>
16 
17 #include <util/get_base_name.h>
18 
19 #ifdef _MSC_VER
20 # include <util/unicode.h>
21 #endif
22 
23 #include "armcc_cmdline.h"
24 #include "as86_cmdline.h"
25 #include "as_cmdline.h"
26 #include "bcc_cmdline.h"
27 #include "gcc_cmdline.h"
28 #include "ld_cmdline.h"
29 #include "ms_cl_cmdline.h"
30 #include "ms_link_cmdline.h"
31 
32 #include "armcc_mode.h"
33 #include "as_mode.h"
34 #include "cw_mode.h"
35 #include "gcc_mode.h"
36 #include "ld_mode.h"
37 #include "ms_cl_mode.h"
38 #include "ms_link_mode.h"
39 
40 std::string to_lower_string(const std::string &s)
41 {
42  std::string result=s;
43  transform(result.begin(), result.end(), result.begin(), tolower);
44  return result;
45 }
46 
47 #ifdef _MSC_VER
48 int wmain(int argc, const wchar_t **argv_wide)
49 #else
50 int main(int argc, const char **argv)
51 #endif
52 {
53  #ifdef _MSC_VER
54  auto vec=narrow_argv(argc, argv_wide);
55  auto narrow=to_c_str_array(std::begin(vec), std::end(vec));
56  auto argv=narrow.data();
57  #endif
58 
59  if(argv==nullptr || argc<1)
60  {
61  std::cerr << "failed to determine base name\n";
62  return 1;
63  }
64 
65  #ifdef _MSC_VER
66  // we do 'to_lower_string' because of Windows
67  std::string base_name=
68  to_lower_string(get_base_name(argv[0], true));
69  #else
70  std::string base_name=get_base_name(argv[0], false);
71  #endif
72 
73  if(base_name == "goto-cl" || base_name == "cl")
74  {
75  // this is the Visual Studio CL personality
76  ms_cl_cmdlinet cmdline;
77  cmdline.parse_env();
78  ms_cl_modet ms_cl_mode(cmdline, base_name);
79  return ms_cl_mode.main(argc, argv);
80  }
81  else if(base_name == "goto-link" || base_name == "link")
82  {
83  // this is the Visual Studio LINK personality
84  ms_link_cmdlinet cmdline;
85  ms_link_modet ms_link_mode(cmdline);
86  return ms_link_mode.main(argc, argv);
87  }
88  else if(base_name=="goto-cw" ||
89  base_name=="goto-cw-link")
90  {
91  // this is the CodeWarrior personality,
92  // but we use the gcc command line interface
93  gcc_cmdlinet cmdline;
94  cw_modet cw_mode(cmdline, base_name);
95  return cw_mode.main(argc, argv);
96  }
97  else if(base_name=="goto-armcc" ||
98  base_name=="goto-armlink")
99  {
100  // this is the armcc personality
101  armcc_cmdlinet cmdline;
102  armcc_modet armcc_mode(cmdline, base_name);
103  return armcc_mode.main(argc, argv);
104  }
105  // handle GCC names like x86_64-apple-darwin14-llvm-gcc-4.2
106  // via x86_64-apple-darwin14-llvm-goto-gcc-4.2
107  else if(base_name=="goto-clang" ||
108  base_name.find("goto-gcc")!=std::string::npos)
109  {
110  // this produces ELF/Mach-O "hybrid binaries",
111  // with a GCC-style command-line interface,
112  // but also disables CPROVER language extensions
113  gcc_cmdlinet cmdline;
114  gcc_modet gcc_mode(cmdline, base_name, true);
115  return gcc_mode.main(argc, argv);
116  }
117  else if(base_name.find("goto-ld")!=std::string::npos)
118  {
119  // this simulates "ld" for linking
120  ld_cmdlinet cmdline;
121  ld_modet ld_mode(cmdline, base_name);
122  return ld_mode.main(argc, argv);
123  }
124  else if(base_name.find("goto-bcc")!=std::string::npos)
125  {
126  // this simulates Bruce's C Compiler
127  bcc_cmdlinet cmdline;
128  // bcc does not build ELF objects -- hybrid mode is used
129  // with -S only
130  gcc_modet gcc_mode(cmdline, base_name, true);
131  return gcc_mode.main(argc, argv);
132  }
133  else if(base_name.find("goto-as86")!=std::string::npos)
134  {
135  // assembler used by Bruce's C Compiler
136  as86_cmdlinet cmdline;
137  // as86 does not build ELF objects, no hybrid binaries
138  as_modet as_mode(cmdline, base_name, false);
139  return as_mode.main(argc, argv);
140  }
141  else if(base_name.find("goto-as")!=std::string::npos)
142  {
143  // GNU assembler
144  as_cmdlinet cmdline;
145  as_modet as_mode(cmdline, base_name, true);
146  return as_mode.main(argc, argv);
147  }
148  else
149  {
150  // the default personality is GCC-style
151  gcc_cmdlinet cmdline;
152  gcc_modet gcc_mode(cmdline, base_name, false);
153  return gcc_mode.main(argc, argv);
154  }
155 }
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
A special command line object to mimic ARM's armcc.
Base class for command line interpretation for CL.
A special command line object for as86 (of Bruce's C Compiler) Author: Michael Tautschnig Date: July ...
A special command line object for GNU Assembler Author: Michael Tautschnig Date: July 2016.
Assembler Mode.
A special command line object for Bruce's C Compiler Author: Michael Tautschnig Date: July 2016.
int main(int argc, const char **argv)
starts the compiler
int tolower(int c)
Definition: ctype.c:109
Base class for command line interpretation.
A special command line object for the gcc-like options.
Base class for command line interpretation.
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
int main(int argc, const char **argv)
std::string to_lower_string(const std::string &s)
A special command line object for the ld-like options.
Base class for command line interpretation.
A special command line object for the gcc-like options.
Visual Studio CL Mode.
output_type narrow(input_type input)
Run-time checked narrowing cast.
Definition: narrow.h:34
std::vector< std::string > narrow_argv(int argc, const wchar_t **argv_wide)
Definition: unicode.cpp:149
std::vector< const char * > to_c_str_array(It b, It e)
Definition: unicode.h:66