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