cprover
ms_cl_mode.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Visual Studio CL Mode
4 
5 Author: CM Wintersteiger, 2006
6 
7 \*******************************************************************/
8 
11 
12 #include "ms_cl_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/prefix.h>
26 #include <util/config.h>
27 #include <util/get_base_name.h>
28 
29 #include "compile.h"
30 
32 static bool is_directory(const std::string &s)
33 {
34  if(s.empty())
35  return false;
36  char last_char=s[s.size()-1];
37  // Visual CL recognizes both
38  return last_char=='\\' || last_char=='/';
39 }
40 
42 {
43  if(cmdline.isset('?') ||
44  cmdline.isset("help"))
45  {
46  help();
47  return EX_OK;
48  }
49 
50  compilet compiler(cmdline, message_handler, cmdline.isset("WX"));
51 
52  #if 0
53  bool act_as_ld=
54  has_prefix(base_name, "link") ||
55  has_prefix(base_name, "goto-link");
56  #endif
57 
58  const auto verbosity = eval_verbosity(
60 
61  debug() << "Visual Studio mode" << eom;
62 
63  // get configuration
65 
67  compiler.object_file_extension="obj";
68 
69  // determine actions to be undertaken
70 
71  if(cmdline.isset('E') || cmdline.isset('P'))
72  compiler.mode=compilet::PREPROCESS_ONLY;
73  else if(cmdline.isset('c'))
74  compiler.mode=compilet::COMPILE_ONLY;
75  else
77 
78  if(cmdline.isset("std"))
79  {
80  const std::string std_string = cmdline.get_value("std");
81 
82  if(
83  std_string == ":c++14" || std_string == "=c++14" ||
84  std_string == ":c++17" || std_string == "=c++17" ||
85  std_string == ":c++latest" || std_string == "=c++latest")
86  {
87  // we don't have any newer version at the moment
89  }
90  else if(std_string == ":c++11" || std_string == "=c++11")
91  {
92  // this isn't really a Visual Studio variant, we just do this for GCC
93  // command-line compatibility
95  }
96  else
97  warning() << "unknown language standard " << std_string << eom;
98  }
99  else
100  config.cpp.set_cpp14();
101 
102  compiler.echo_file_name=true;
103 
104  if(cmdline.isset("Fo"))
105  {
106  compiler.output_file_object=cmdline.get_value("Fo");
107 
108  // this could be a directory
109  if(is_directory(compiler.output_file_object) &&
110  cmdline.args.size()>=1)
111  compiler.output_file_object+=
112  get_base_name(cmdline.args[0], true)+".obj";
113  }
114 
115  if(cmdline.isset("Fe"))
116  {
117  compiler.output_file_executable=cmdline.get_value("Fe");
118 
119  // this could be a directory
120  if(is_directory(compiler.output_file_executable) &&
121  cmdline.args.size()>=1)
122  compiler.output_file_executable+=
123  get_base_name(cmdline.args[0], true)+".exe";
124  }
125  else
126  {
127  // We need at least one argument.
128  // CL uses the first file name it gets!
129  if(cmdline.args.size()>=1)
130  compiler.output_file_executable=
131  get_base_name(cmdline.args[0], true)+".exe";
132  }
133 
134  if(cmdline.isset('J'))
136 
137  if(verbosity > messaget::M_STATISTICS)
138  {
139  std::list<std::string>::iterator it;
140 
141  std::cout << "Defines:\n";
142  for(it=config.ansi_c.defines.begin();
143  it!=config.ansi_c.defines.end();
144  it++)
145  {
146  std::cout << " " << (*it) << '\n';
147  }
148 
149  std::cout << "Undefines:\n";
150  for(it=config.ansi_c.undefines.begin();
151  it!=config.ansi_c.undefines.end();
152  it++)
153  {
154  std::cout << " " << (*it) << '\n';
155  }
156 
157  std::cout << "Preprocessor Options:\n";
158  for(it=config.ansi_c.preprocessor_options.begin();
160  it++)
161  {
162  std::cout << " " << (*it) << '\n';
163  }
164 
165  std::cout << "Include Paths:\n";
166  for(it=config.ansi_c.include_paths.begin();
167  it!=config.ansi_c.include_paths.end();
168  it++)
169  {
170  std::cout << " " << (*it) << '\n';
171  }
172 
173  std::cout << "Library Paths:\n";
174  for(it=compiler.library_paths.begin();
175  it!=compiler.library_paths.end();
176  it++)
177  {
178  std::cout << " " << (*it) << '\n';
179  }
180 
181  std::cout << "Output file (object): "
182  << compiler.output_file_object << '\n';
183  std::cout << "Output file (executable): "
184  << compiler.output_file_executable << '\n';
185  }
186 
187  // Parse input program, convert to goto program, write output
188  return compiler.doit() ? EX_USAGE : EX_OK;
189 }
190 
193 {
194  std::cout << "goto-cl understands the options of CL plus the following.\n\n";
195 }
struct configt::ansi_ct ansi_c
ms_cl_cmdlinet & cmdline
Definition: ms_cl_mode.h:37
static bool is_directory(const std::string &s)
does it.
Definition: ms_cl_mode.cpp:32
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:78
std::list< std::string > defines
Definition: config.h:112
std::string get_value(char option) const
Definition: cmdline.cpp:45
std::list< std::string > undefines
Definition: config.h:113
virtual void help_mode()
display command line help
Definition: ms_cl_mode.cpp:192
static mstreamt & eom(mstreamt &m)
Definition: message.h:272
configt config
Definition: config.cpp:23
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
Visual Studio CL Mode.
mstreamt & warning() const
Definition: message.h:307
void set_cpp14()
Definition: config.h:134
bool set(const cmdlinet &cmdline)
Definition: config.cpp:737
argst args
Definition: cmdline.h:37
virtual bool isset(char option) const
Definition: cmdline.cpp:27
flavourt mode
Definition: config.h:106
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
bool char_is_unsigned
Definition: config.h:43
Compile and link source and object files.
struct configt::cppt cpp
void set_cpp11()
Definition: config.h:133
virtual void help()
display command line help
virtual int doit()
Definition: ms_cl_mode.cpp:41
console_message_handlert message_handler
Definition: ms_cl_mode.h:38
mstreamt & debug() const
Definition: message.h:332
std::list< std::string > preprocessor_options
Definition: config.h:114
const std::string base_name
Definition: goto_cc_mode.h:38
std::list< std::string > include_paths
Definition: config.h:115