cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cprover_library.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#include "
cprover_library.h
"
10
11
#include <
util/config.h
>
12
#include <
util/cprover_prefix.h
>
13
#include <
util/symbol_table_base.h
>
14
15
#include "
ansi_c_language.h
"
16
17
#include <sstream>
18
19
static
std::string
get_cprover_library_text
(
20
const
std::set<irep_idt> &functions,
21
const
symbol_table_baset
&symbol_table,
22
const
bool
force_load)
23
{
24
std::ostringstream library_text;
25
26
library_text <<
"#line 1 \"<built-in-additions>\"\n"
27
"#define "
CPROVER_PREFIX
"malloc_failure_mode "
28
<< std::to_string(
config
.ansi_c.malloc_failure_mode)
29
<<
"\n"
30
"#define "
CPROVER_PREFIX
"malloc_failure_mode_return_null "
31
<< std::to_string(
config
.ansi_c.malloc_failure_mode_return_null)
32
<<
"\n"
33
"#define "
CPROVER_PREFIX
34
"malloc_failure_mode_assert_then_assume "
35
<< std::to_string(
36
config
.ansi_c.malloc_failure_mode_assert_then_assume)
37
<<
"\n"
38
"#define "
CPROVER_PREFIX
"malloc_may_fail "
39
<< std::to_string(
config
.ansi_c.malloc_may_fail) <<
"\n"
;
40
41
library_text <<
42
"#line 1 \"<builtin-library>\"\n"
43
"#undef inline\n"
;
44
45
if
(
config
.ansi_c.string_abstraction)
46
library_text <<
"#define "
CPROVER_PREFIX
"STRING_ABSTRACTION\n"
;
47
48
if
(
config
.ansi_c.dfcc_debug_lib)
49
library_text <<
"#define "
CPROVER_PREFIX
"DFCC_DEBUG_LIB\n"
;
50
51
if
(
config
.ansi_c.simple_invalid_pointer_model)
52
library_text <<
"#define "
CPROVER_PREFIX
53
"DFCC_SIMPLE_INVALID_POINTER_MODEL\n"
;
54
55
// cprover_library.inc may not have been generated when running Doxygen, thus
56
// make Doxygen skip this part
58
const
struct
cprover_library_entryt
cprover_library[] =
59
#include "cprover_library.inc"
// IWYU pragma: keep
60
;
// NOLINT(whitespace/semicolon)
62
63
return
get_cprover_library_text
(
64
functions, symbol_table, cprover_library, library_text.str(), force_load);
65
}
66
67
std::string
get_cprover_library_text
(
68
const
std::set<irep_idt> &functions,
69
const
symbol_table_baset
&symbol_table,
70
const
struct
cprover_library_entryt
cprover_library[],
71
const
std::string &prologue,
72
const
bool
force_load)
73
{
74
// the default mode is ios_base::out which means subsequent write to the
75
// stream will overwrite the original content
76
std::ostringstream library_text(prologue, std::ios_base::ate);
77
78
std::size_t count=0;
79
80
for
(
const
cprover_library_entryt
*e = cprover_library; e->
function
!=
nullptr
;
81
e++)
82
{
83
irep_idt
id
=e->function;
84
85
if
(functions.find(
id
)!=functions.end())
86
{
87
symbol_table_baset::symbolst::const_iterator old =
88
symbol_table.
symbols
.find(
id
);
89
90
if
(
91
force_load ||
92
(old != symbol_table.
symbols
.end() && old->second.value.is_nil()))
93
{
94
count++;
95
library_text << e->model <<
'\n'
;
96
}
97
}
98
}
99
100
if
(count==0)
101
return
std::string();
102
else
103
return
library_text.str();
104
}
105
106
void
cprover_c_library_factory
(
107
const
std::set<irep_idt> &functions,
108
const
symbol_table_baset
&symbol_table,
109
symbol_table_baset
&dest_symbol_table,
110
message_handlert
&message_handler)
111
{
112
if
(
config
.ansi_c.lib==
configt::ansi_ct::libt::LIB_NONE
)
113
return
;
114
115
std::string library_text =
116
get_cprover_library_text
(functions, symbol_table,
false
);
117
118
add_library
(library_text, dest_symbol_table, message_handler);
119
}
120
121
void
add_library
(
122
const
std::string &src,
123
symbol_table_baset
&symbol_table,
124
message_handlert
&message_handler,
125
const
std::set<irep_idt> &keep)
126
{
127
if
(src.empty())
128
return
;
129
130
std::istringstream in(src);
131
132
ansi_c_languaget
ansi_c_language;
133
ansi_c_language.
parse
(in,
""
, message_handler);
134
135
ansi_c_language.
typecheck
(
136
symbol_table,
"<built-in-library>"
, message_handler,
true
, keep);
137
}
138
139
void
cprover_c_library_factory_force_load
(
140
const
std::set<irep_idt> &functions,
141
symbol_table_baset
&symbol_table,
142
message_handlert
&message_handler)
143
{
144
std::string library_text =
145
get_cprover_library_text
(functions, symbol_table,
true
);
146
add_library
(library_text, symbol_table, message_handler, functions);
147
}
get_cprover_library_text
static std::string get_cprover_library_text(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, const bool force_load)
Definition
cprover_library.cpp:19
add_library
void add_library(const std::string &src, symbol_table_baset &symbol_table, message_handlert &message_handler, const std::set< irep_idt > &keep)
Parses and typechecks the given src and adds its contents to the symbol table.
Definition
cprover_library.cpp:121
cprover_c_library_factory_force_load
void cprover_c_library_factory_force_load(const std::set< irep_idt > &functions, symbol_table_baset &symbol_table, message_handlert &message_handler)
Load the requested function symbols from the cprover library and add them to the symbol table regardl...
Definition
cprover_library.cpp:139
cprover_c_library_factory
void cprover_c_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
Definition
cprover_library.cpp:106
cprover_library.h
ansi_c_language.h
config
configt config
Definition
config.cpp:25
ansi_c_languaget
Definition
ansi_c_language.h:35
ansi_c_languaget::typecheck
bool typecheck(symbol_table_baset &symbol_table, const std::string &module, message_handlert &message_handler, const bool keep_file_local) override
typecheck without removing specified entries from the symbol table
Definition
ansi_c_language.cpp:109
ansi_c_languaget::parse
bool parse(std::istream &instream, const std::string &path, message_handlert &message_handler) override
Definition
ansi_c_language.cpp:50
message_handlert
Definition
message.h:27
symbol_table_baset
The symbol table base class interface.
Definition
symbol_table_base.h:23
symbol_table_baset::symbols
const symbolst & symbols
Read-only field, used to look up symbols given their names.
Definition
symbol_table_base.h:31
config.h
cprover_prefix.h
CPROVER_PREFIX
#define CPROVER_PREFIX
Definition
cprover_prefix.h:14
configt::ansi_ct::libt::LIB_NONE
@ LIB_NONE
Definition
config.h:301
cprover_library_entryt
Definition
cprover_library.h:21
cprover_library_entryt::function
const char * function
Definition
cprover_library.h:22
symbol_table_base.h
Author: Diffblue Ltd.
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
ansi-c
cprover_library.cpp
Generated by
1.17.0