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/string2int.h>
25 #include <util/message.h>
26 #include <util/prefix.h>
27 #include <util/config.h>
28 #include <util/get_base_name.h>
29 
30 #include <cbmc/version.h>
31 
32 #include "compile.h"
33 
35 static bool is_directory(const std::string &s)
36 {
37  if(s.empty())
38  return false;
39  char last_char=s[s.size()-1];
40  // Visual CL recognizes both
41  return last_char=='\\' || last_char=='/';
42 }
43 
45 {
46  if(cmdline.isset('?') ||
47  cmdline.isset("help"))
48  {
49  help();
50  return EX_OK;
51  }
52 
53  unsigned int verbosity=1;
54 
55  compilet compiler(cmdline, message_handler, cmdline.isset("WX"));
56 
57  #if 0
58  bool act_as_ld=
59  has_prefix(base_name, "link") ||
60  has_prefix(base_name, "goto-link");
61  #endif
62 
63  if(cmdline.isset("verbosity"))
64  verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity"));
65 
66  compiler.set_message_handler(get_message_handler());
67  message_handler.set_verbosity(verbosity);
68 
69  debug() << "Visual Studio mode" << eom;
70 
71  // get configuration
73 
75  compiler.object_file_extension="obj";
76 
77  // determine actions to be undertaken
78 
79  if(cmdline.isset('E') || cmdline.isset('P'))
80  compiler.mode=compilet::PREPROCESS_ONLY;
81  else if(cmdline.isset('c'))
82  compiler.mode=compilet::COMPILE_ONLY;
83  else
85 
86  compiler.echo_file_name=true;
87 
88  if(cmdline.isset("Fo"))
89  {
90  compiler.output_file_object=cmdline.get_value("Fo");
91 
92  // this could be a directory
93  if(is_directory(compiler.output_file_object) &&
94  cmdline.args.size()>=1)
95  compiler.output_file_object+=
96  get_base_name(cmdline.args[0], true)+".obj";
97  }
98 
99  if(cmdline.isset("Fe"))
100  {
101  compiler.output_file_executable=cmdline.get_value("Fe");
102 
103  // this could be a directory
104  if(is_directory(compiler.output_file_executable) &&
105  cmdline.args.size()>=1)
106  compiler.output_file_executable+=
107  get_base_name(cmdline.args[0], true)+".exe";
108  }
109  else
110  {
111  // We need at least one argument.
112  // CL uses the first file name it gets!
113  if(cmdline.args.size()>=1)
114  compiler.output_file_executable=
115  get_base_name(cmdline.args[0], true)+".exe";
116  }
117 
118  if(cmdline.isset('J'))
120 
121  if(verbosity>8)
122  {
123  std::list<std::string>::iterator it;
124 
125  std::cout << "Defines:\n";
126  for(it=config.ansi_c.defines.begin();
127  it!=config.ansi_c.defines.end();
128  it++)
129  {
130  std::cout << " " << (*it) << '\n';
131  }
132 
133  std::cout << "Undefines:\n";
134  for(it=config.ansi_c.undefines.begin();
135  it!=config.ansi_c.undefines.end();
136  it++)
137  {
138  std::cout << " " << (*it) << '\n';
139  }
140 
141  std::cout << "Preprocessor Options:\n";
142  for(it=config.ansi_c.preprocessor_options.begin();
144  it++)
145  {
146  std::cout << " " << (*it) << '\n';
147  }
148 
149  std::cout << "Include Paths:\n";
150  for(it=config.ansi_c.include_paths.begin();
151  it!=config.ansi_c.include_paths.end();
152  it++)
153  {
154  std::cout << " " << (*it) << '\n';
155  }
156 
157  std::cout << "Library Paths:\n";
158  for(it=compiler.library_paths.begin();
159  it!=compiler.library_paths.end();
160  it++)
161  {
162  std::cout << " " << (*it) << '\n';
163  }
164 
165  std::cout << "Output file (object): "
166  << compiler.output_file_object << '\n';
167  std::cout << "Output file (executable): "
168  << compiler.output_file_executable << '\n';
169  }
170 
171  // Parse input program, convert to goto program, write output
172  return compiler.doit() ? EX_USAGE : EX_OK;
173 }
174 
177 {
178  std::cout << "goto-cl understands the options of CL plus the following.\n\n";
179 }
struct configt::ansi_ct ansi_c
ms_cl_cmdlinet & cmdline
Definition: ms_cl_mode.h:37
unsigned unsafe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:66
static bool is_directory(const std::string &s)
does it.
Definition: ms_cl_mode.cpp:35
std::list< std::string > defines
Definition: config.h:111
std::string get_value(char option) const
Definition: cmdline.cpp:46
std::list< std::string > undefines
Definition: config.h:112
virtual void help_mode()
display command line help
Definition: ms_cl_mode.cpp:176
static mstreamt & eom(mstreamt &m)
Definition: message.h:193
configt config
Definition: config.cpp:21
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
Visual Studio CL Mode.
bool set(const cmdlinet &cmdline)
Definition: config.cpp:727
argst args
Definition: cmdline.h:35
virtual bool isset(char option) const
Definition: cmdline.cpp:30
flavourt mode
Definition: config.h:105
bool char_is_unsigned
Definition: config.h:43
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
Compile and link source and object files.
mstreamt & debug()
Definition: message.h:253
message_handlert & get_message_handler()
Definition: message.h:127
virtual void help()
display command line help
virtual int doit()
Definition: ms_cl_mode.cpp:44
void set_verbosity(unsigned _verbosity)
Definition: message.h:44
console_message_handlert message_handler
Definition: ms_cl_mode.h:38
std::list< std::string > preprocessor_options
Definition: config.h:113
const std::string base_name
Definition: goto_cc_mode.h:38
std::list< std::string > include_paths
Definition: config.h:114