CBMC
ms_cl_version.cpp
Go to the documentation of this file.
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
}
tempfile.h
string_utils.h
ms_cl_versiont::v_major
unsigned v_major
Definition:
ms_cl_version.h:22
run
int run(const std::string &what, const std::vector< std::string > &argv)
Definition:
run.cpp:48
ms_cl_versiont::v_minor
unsigned v_minor
Definition:
ms_cl_version.h:22
run.h
ms_cl_versiont::targett::UNKNOWN
@ UNKNOWN
string2int.h
split_string
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
Definition:
string_utils.cpp:39
operator<<
std::ostream & operator<<(std::ostream &out, const ms_cl_versiont &v)
Definition:
ms_cl_version.cpp:70
ms_cl_versiont::targett::ARM
@ ARM
safe_string2unsigned
unsigned safe_string2unsigned(const std::string &str, int base)
Definition:
string2int.cpp:16
ms_cl_versiont
Definition:
ms_cl_version.h:19
ms_cl_versiont::targett::x86
@ x86
ms_cl_version.h
ms_cl_versiont::is_at_least
bool is_at_least(unsigned v_major, unsigned v_minor=0) const
Definition:
ms_cl_version.cpp:65
ms_cl_versiont::targett::x64
@ x64
ms_cl_versiont::get
void get(const std::string &executable)
Definition:
ms_cl_version.cpp:18
temporary_filet
Definition:
tempfile.h:23
ms_cl_versiont::target
enum ms_cl_versiont::targett target
src
goto-cc
ms_cl_version.cpp
Generated by
1.8.17