CBMC
ms_link_mode.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Visual Studio Link Mode
4 
5 Author: Daniel Kroening
6 
7 \*******************************************************************/
8 
11 
12 #include "ms_link_mode.h"
13 
14 #include <iostream>
15 
16 #include <util/config.h>
17 #include <util/get_base_name.h>
18 
19 #include "compile.h"
20 #include "goto_cc_cmdline.h"
21 
23  : goto_cc_modet(_cmdline, "link", message_handler)
24 {
25 }
26 
29 {
30  if(cmdline.isset("help"))
31  {
32  help();
33  return 0;
34  }
35 
38 
39  compilet compiler(cmdline, message_handler, false);
40 
41  // determine actions to be undertaken
42  compiler.mode = compilet::LINK_LIBRARY;
43 
44  // get configuration
46 
47  compiler.object_file_extension = "obj";
48 
49  if(cmdline.isset("LIBPATH"))
50  compiler.library_paths = cmdline.get_values("LIBPATH");
51  // Don't add the system paths!
52 
53  if(cmdline.isset("OUT"))
54  {
55  // This must be a file, not a directory.
56  // If the option is given multiple times, the last instance wins.
57  const auto &values = cmdline.get_values("OUT");
58  if(!values.empty())
59  compiler.output_file_executable = values.back();
60  }
61  else
62  {
63  // The first input file is used to determine the default
64  // name of the executable.
65  if(!cmdline.args.empty())
66  compiler.output_file_executable = get_base_name(cmdline.args[0], true)+".exe";
67  }
68 
69  // We now iterate over any input files
70 
71  for(const auto &arg : cmdline.parsed_argv)
72  if(arg.is_infile_name)
73  compiler.add_input_file(arg.arg);
74 
75  // do all the rest
76  if(compiler.doit())
77  return 1;
78 
79  return 0;
80 }
81 
84 {
85  std::cout << "goto-link understands the options of "
86  << "link plus the following.\n\n";
87 }
cmdlinet::args
argst args
Definition: cmdline.h:145
get_base_name
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
Definition: get_base_name.cpp:16
goto_cc_cmdlinet::parsed_argv
parsed_argvt parsed_argv
Definition: goto_cc_cmdline.h:64
cmdlinet::isset
virtual bool isset(char option) const
Definition: cmdline.cpp:30
compilet::doit
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:60
goto_cc_cmdline.h
compilet::mode
enum compilet::@3 mode
compilet::output_file_executable
std::string output_file_executable
Definition: compile.h:51
messaget::M_ERROR
@ M_ERROR
Definition: message.h:170
cmdlinet::get_value
std::string get_value(char option) const
Definition: cmdline.cpp:48
compilet::library_paths
std::list< std::string > library_paths
Definition: compile.h:45
compile.h
compilet::object_file_extension
std::string object_file_extension
Definition: compile.h:50
get_base_name.h
goto_cc_modet::cmdline
goto_cc_cmdlinet & cmdline
Definition: goto_cc_mode.h:38
compilet::add_input_file
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
Definition: compile.cpp:173
config
configt config
Definition: config.cpp:25
configt::set
bool set(const cmdlinet &cmdline)
Definition: config.cpp:798
goto_cc_modet
Definition: goto_cc_mode.h:22
compilet::LINK_LIBRARY
@ LINK_LIBRARY
Definition: compile.h:40
config.h
goto_cc_modet::help
void help()
display command line help
Definition: goto_cc_mode.cpp:47
compilet
Definition: compile.h:30
messaget::eval_verbosity
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:105
cmdlinet::get_values
const std::list< std::string > & get_values(const std::string &option) const
Definition: cmdline.cpp:109
goto_cc_cmdlinet
Definition: goto_cc_cmdline.h:19