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