Skip to content

Commit 5d47a33

Browse files
committed
Refactor add_cprover_library to make parts re-usable by the C++ front-end
1 parent cf8034f commit 5d47a33

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ bool jdiff_parse_optionst::process_goto_program(
342342
{
343343
// add the library
344344
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
345-
link_to_library(goto_model, get_message_handler(), add_cprover_library);
345+
link_to_library(goto_model, get_message_handler(), add_cprover_c_library);
346346

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

src/ansi-c/cprover_library.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com
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,9 +27,25 @@ std::string get_cprover_library_text(
3527
if(config.ansi_c.string_abstraction)
3628
library_text << "#define __CPROVER_STRING_ABSTRACTION\n";
3729

30+
const struct cprover_library_entryt cprover_library[] =
31+
#include "cprover_library.inc"
32+
; // NOLINT(whitespace/semicolon)
33+
34+
return get_cprover_library_text(
35+
functions, symbol_table, cprover_library, library_text.str());
36+
}
37+
38+
std::string get_cprover_library_text(
39+
const std::set<irep_idt> &functions,
40+
const symbol_tablet &symbol_table,
41+
const struct cprover_library_entryt cprover_library[],
42+
const std::string &prologue)
43+
{
44+
std::ostringstream library_text(prologue);
45+
3846
std::size_t count=0;
3947

40-
for(cprover_library_entryt *e=cprover_library;
48+
for(const cprover_library_entryt *e=cprover_library;
4149
e->function!=nullptr;
4250
e++)
4351
{
@@ -63,7 +71,7 @@ std::string get_cprover_library_text(
6371
return library_text.str();
6472
}
6573

66-
void add_cprover_library(
74+
void add_cprover_c_library(
6775
const std::set<irep_idt> &functions,
6876
symbol_tablet &symbol_table,
6977
message_handlert &message_handler)

src/ansi-c/cprover_library.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ Author: Daniel Kroening, kroening@kroening.com
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)