Skip to content

Commit ed05d3e

Browse files
committed
Refactor add_cprover_library to make parts re-usable by the C++ front-end
1 parent 0ea6143 commit ed05d3e

7 files changed

+39
-19
lines changed

src/ansi-c/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ add_custom_command(
5050
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5151
)
5252

53-
add_custom_target(library_check
53+
add_custom_target(c_library_check
5454
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp
5555
)
5656

src/ansi-c/cprover_library.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include "ansi_c_language.h"
1616

17-
struct cprover_library_entryt
18-
{
19-
const char *function;
20-
const char *model;
21-
} cprover_library[]=
22-
#include "cprover_library.inc"
23-
; // NOLINT(whitespace/semicolon)
24-
25-
std::string get_cprover_library_text(
17+
static std::string get_cprover_library_text(
2618
const std::set<irep_idt> &functions,
2719
const symbol_tablet &symbol_table)
2820
{
@@ -35,10 +27,29 @@ std::string get_cprover_library_text(
3527
if(config.ansi_c.string_abstraction)
3628
library_text << "#define __CPROVER_STRING_ABSTRACTION\n";
3729

30+
// cprover_library.inc may not have been generated when running Doxygen, thus
31+
// make Doxygen skip this part
32+
/// \cond
33+
const struct cprover_library_entryt cprover_library[] =
34+
#include "cprover_library.inc"
35+
; // NOLINT(whitespace/semicolon)
36+
/// \endcond
37+
38+
return get_cprover_library_text(
39+
functions, symbol_table, cprover_library, library_text.str());
40+
}
41+
42+
std::string get_cprover_library_text(
43+
const std::set<irep_idt> &functions,
44+
const symbol_tablet &symbol_table,
45+
const struct cprover_library_entryt cprover_library[],
46+
const std::string &prologue)
47+
{
48+
std::ostringstream library_text(prologue);
49+
3850
std::size_t count=0;
3951

40-
for(cprover_library_entryt *e=cprover_library;
41-
e->function!=nullptr;
52+
for(const cprover_library_entryt *e = cprover_library; e->function != nullptr;
4253
e++)
4354
{
4455
irep_idt id=e->function;
@@ -63,7 +74,7 @@ std::string get_cprover_library_text(
6374
return library_text.str();
6475
}
6576

66-
void add_cprover_library(
77+
void add_cprover_c_library(
6778
const std::set<irep_idt> &functions,
6879
symbol_tablet &symbol_table,
6980
message_handlert &message_handler)

src/ansi-c/cprover_library.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/symbol_table.h>
1616
#include <util/message.h>
1717

18+
struct cprover_library_entryt
19+
{
20+
const char *function;
21+
const char *model;
22+
};
23+
1824
std::string get_cprover_library_text(
1925
const std::set<irep_idt> &functions,
20-
const symbol_tablet &);
26+
const symbol_tablet &,
27+
const struct cprover_library_entryt[],
28+
const std::string &prologue);
2129

2230
void add_library(
2331
const std::string &src,
2432
symbol_tablet &,
2533
message_handlert &);
2634

27-
void add_cprover_library(
35+
void add_cprover_c_library(
2836
const std::set<irep_idt> &functions,
2937
symbol_tablet &,
3038
message_handlert &);

src/cbmc/cbmc_parse_options.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ bool cbmc_parse_optionst::process_goto_program(
714714
// add the library
715715
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
716716
<< eom;
717-
link_to_library(goto_model, log.get_message_handler(), add_cprover_library);
717+
link_to_library(
718+
goto_model, log.get_message_handler(), add_cprover_c_library);
718719

719720
if(options.get_bool_option("string-abstraction"))
720721
string_instrumentation(goto_model, log.get_message_handler());

src/goto-analyzer/goto_analyzer_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ bool goto_analyzer_parse_optionst::process_goto_program(
727727

728728
// add the library
729729
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
730-
link_to_library(goto_model, ui_message_handler, add_cprover_library);
730+
link_to_library(goto_model, ui_message_handler, add_cprover_c_library);
731731
#endif
732732

733733
// remove function pointers

src/goto-diff/goto_diff_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ bool goto_diff_parse_optionst::process_goto_program(
397397

398398
// add the library
399399
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
400-
link_to_library(goto_model, get_message_handler(), add_cprover_library);
400+
link_to_library(goto_model, get_message_handler(), add_cprover_c_library);
401401

402402
// remove function pointers
403403
status() << "Removal of function pointers and virtual functions" << eom;

src/goto-instrument/goto_instrument_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
960960

961961
// add the library
962962
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
963-
link_to_library(goto_model, get_message_handler(), add_cprover_library);
963+
link_to_library(goto_model, get_message_handler(), add_cprover_c_library);
964964
}
965965

966966
// now do full inlining, if requested

0 commit comments

Comments
 (0)