Skip to content

Commit 4c15fce

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
Get version number and target from Visual Studio CL
1 parent 0ec4e7d commit 4c15fce

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

src/goto-cc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SRC = armcc_cmdline.cpp \
1919
linker_script_merge.cpp \
2020
ms_cl_cmdline.cpp \
2121
ms_cl_mode.cpp \
22+
ms_cl_version.cpp \
2223
ms_link_cmdline.cpp \
2324
ms_link_mode.cpp \
2425
# Empty last line

src/goto-cc/ms_cl_version.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*******************************************************************\
2+
3+
Module: Visual Studio CL version numbering scheme
4+
5+
Author: Daniel Kroening, 2018
6+
7+
\*******************************************************************/
8+
9+
#include "ms_cl_version.h"
10+
11+
#include <util/run.h>
12+
#include <util/string2int.h>
13+
#include <util/string_utils.h>
14+
#include <util/tempfile.h>
15+
16+
#include <fstream>
17+
18+
void ms_cl_versiont::get(const std::string &executable)
19+
{
20+
// stdout will have the help output, we just want to discard it
21+
temporary_filet tmp_file_out("goto-cl.", ".out");
22+
// stderr has the version string
23+
temporary_filet tmp_file_err("goto-cl.", ".err");
24+
const int result =
25+
run(executable, {executable}, "", tmp_file_out(), tmp_file_err());
26+
27+
v_major = v_minor = 0;
28+
target = targett::UNKNOWN;
29+
30+
if(result >= 0)
31+
{
32+
std::ifstream in(tmp_file_err());
33+
std::string line;
34+
35+
if(std::getline(in, line))
36+
{
37+
// Example:
38+
//
39+
// NOLINTNEXTLINE (whitespace/braces)
40+
// Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
41+
auto split = split_string(line, ' ');
42+
if(split.size() > 3)
43+
{
44+
if(split.back() == "x86" || split.back() == "80x86")
45+
target = targett::x86;
46+
else if(split.back() == "x64")
47+
target = targett::x64;
48+
else if(split.back() == "ARM")
49+
target = targett::ARM;
50+
else
51+
target = targett::UNKNOWN;
52+
53+
auto split_v = split_string(split[split.size() - 3], '.');
54+
55+
if(split_v.size() >= 2)
56+
{
57+
v_major = safe_string2unsigned(split_v[0]);
58+
v_minor = safe_string2unsigned(split_v[1]);
59+
}
60+
}
61+
}
62+
}
63+
}
64+
65+
bool ms_cl_versiont::is_at_least(unsigned _major, unsigned _minor) const
66+
{
67+
return v_major > _major || (v_major == _major && v_minor >= _minor);
68+
}
69+
70+
std::ostream &operator<<(std::ostream &out, const ms_cl_versiont &v)
71+
{
72+
out << v.v_major << '.' << v.v_minor;
73+
74+
switch(v.target)
75+
{
76+
case ms_cl_versiont::targett::x86:
77+
out << " x86";
78+
break;
79+
case ms_cl_versiont::targett::x64:
80+
out << " x64";
81+
break;
82+
case ms_cl_versiont::targett::ARM:
83+
out << " ARM";
84+
break;
85+
case ms_cl_versiont::targett::UNKNOWN:
86+
break;
87+
}
88+
89+
return out;
90+
}

src/goto-cc/ms_cl_version.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*******************************************************************\
2+
3+
Module: Visual Studio CL version numbering scheme
4+
5+
Author: Daniel Kroening
6+
7+
Date: August 2018
8+
9+
\*******************************************************************/
10+
11+
#ifndef CPROVER_GOTO_CC_MS_CL_VERSION_H
12+
#define CPROVER_GOTO_CC_MS_CL_VERSION_H
13+
14+
#include <iosfwd>
15+
#include <string>
16+
17+
#include <util/config.h>
18+
19+
class ms_cl_versiont
20+
{
21+
public:
22+
unsigned v_major, v_minor;
23+
24+
void get(const std::string &executable);
25+
26+
bool is_at_least(unsigned v_major, unsigned v_minor = 0) const;
27+
28+
configt::ansi_ct::c_standardt default_c_standard;
29+
configt::cppt::cpp_standardt default_cxx_standard;
30+
31+
ms_cl_versiont()
32+
: v_major(0),
33+
v_minor(0),
34+
default_c_standard(configt::ansi_ct::c_standardt::C89),
35+
default_cxx_standard(configt::cppt::cpp_standardt::CPP98)
36+
{
37+
}
38+
39+
enum class targett
40+
{
41+
UNKNOWN,
42+
x86,
43+
x64,
44+
ARM
45+
} target;
46+
};
47+
48+
std::ostream &operator<<(std::ostream &, const ms_cl_versiont &);
49+
50+
#endif // CPROVER_GOTO_CC_MS_CL_VERSION_H

0 commit comments

Comments
 (0)