Skip to content

Commit 6da30f7

Browse files
committed
C++ front-end now has its own library
Moved new/delete implementation from ansi-c to cpp.
1 parent 5d47a33 commit 6da30f7

File tree

10 files changed

+104
-1
lines changed

10 files changed

+104
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ install:
286286
- make -C jbmc/src java-models-library-download
287287
- make -C src minisat2-download
288288
- make -C src/ansi-c library_check
289+
- make -C src/cpp library_check
289290
- make -C src "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j3
290291
- make -C src "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j3 clobber.dir memory-models.dir
291292
- make -C jbmc/src "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j3

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Author: Peter Schrammel
5656
#include <langapi/mode.h>
5757

5858
#include <ansi-c/cprover_library.h>
59+
#include <cpp/cprover_library.h>
5960

6061
#include <cbmc/version.h>
6162

@@ -342,6 +343,7 @@ bool jdiff_parse_optionst::process_goto_program(
342343
{
343344
// add the library
344345
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
346+
link_to_library(goto_model, get_message_handler(), add_cprover_cpp_library);
345347
link_to_library(goto_model, get_message_handler(), add_cprover_c_library);
346348

347349
// remove function pointers

src/cbmc/cbmc_parse_options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Author: Daniel Kroening, [email protected]
2626
#include <ansi-c/c_preprocess.h>
2727
#include <ansi-c/cprover_library.h>
2828

29+
#include <cpp/cprover_library.h>
30+
2931
#include <goto-programs/adjust_float_expressions.h>
3032
#include <goto-programs/initialize_goto_model.h>
3133
#include <goto-programs/instrument_preconditions.h>
@@ -714,6 +716,8 @@ bool cbmc_parse_optionst::process_goto_program(
714716
// add the library
715717
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
716718
<< eom;
719+
link_to_library(
720+
goto_model, log.get_message_handler(), add_cprover_cpp_library);
717721
link_to_library(
718722
goto_model, log.get_message_handler(), add_cprover_c_library);
719723

src/cpp/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SRC = cpp_constructor.cpp \
4242
cpp_typecheck_using.cpp \
4343
cpp_typecheck_virtual_table.cpp \
4444
cpp_util.cpp \
45+
cprover_library.cpp \
4546
expr2cpp.cpp \
4647
parse.cpp \
4748
template_map.cpp \
@@ -52,11 +53,27 @@ INCLUDES= -I ..
5253
include ../config.inc
5354
include ../common
5455

55-
CLEANFILES = cpp$(LIBEXT)
56+
CLEANFILES = cpp$(LIBEXT) cprover_library.inc library_check
5657

5758
all: cpp$(LIBEXT)
5859

5960
###############################################################################
6061

62+
../ansi-c/library/converter$(EXEEXT): ../ansi-c/library/converter.cpp
63+
$(MAKE) -C ../ansi-c library/converter$(EXEEXT)
64+
65+
library_check: library/*.c
66+
./library_check.sh $(CC) $^
67+
touch $@
68+
69+
cprover_library.inc: ../ansi-c/library/converter$(EXEEXT) library/*.c
70+
cat library/*.c | ../ansi-c/library/converter$(EXEEXT) > $@
71+
72+
cprover_library.cpp: cprover_library.inc
73+
74+
generated_files: cprover_library.inc
75+
76+
###############################################################################
77+
6178
cpp$(LIBEXT): $(OBJ)
6279
$(LINKLIB)

src/cpp/cprover_library.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*******************************************************************\
2+
3+
Module:
4+
5+
Author: Michael Tautschnig
6+
7+
\*******************************************************************/
8+
9+
#include "cprover_library.h"
10+
11+
#include <sstream>
12+
13+
#include <util/config.h>
14+
15+
#include <ansi-c/cprover_library.h>
16+
17+
static std::string get_cprover_library_text(
18+
const std::set<irep_idt> &functions,
19+
const symbol_tablet &symbol_table)
20+
{
21+
std::ostringstream library_text;
22+
23+
library_text <<
24+
"#line 1 \"<builtin-library>\"\n"
25+
"#undef inline\n";
26+
27+
const struct cprover_library_entryt cprover_library[] =
28+
#include "cprover_library.inc"
29+
; // NOLINT(whitespace/semicolon)
30+
31+
return get_cprover_library_text(
32+
functions, symbol_table, cprover_library, library_text.str());
33+
}
34+
35+
void add_cprover_cpp_library(
36+
const std::set<irep_idt> &functions,
37+
symbol_tablet &symbol_table,
38+
message_handlert &message_handler)
39+
{
40+
if(config.ansi_c.lib==configt::ansi_ct::libt::LIB_NONE)
41+
return;
42+
43+
const std::string library_text =
44+
get_cprover_library_text(functions, symbol_table);
45+
46+
add_library(library_text, symbol_table, message_handler);
47+
}

src/cpp/cprover_library.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************\
2+
3+
Module:
4+
5+
Author: Michael Tautschnig
6+
7+
\*******************************************************************/
8+
9+
10+
#ifndef CPROVER_CPP_CPROVER_LIBRARY_H
11+
#define CPROVER_CPP_CPROVER_LIBRARY_H
12+
13+
#include <set>
14+
15+
#include <util/irep.h>
16+
17+
class message_handlert;
18+
class symbol_tablet;
19+
20+
void add_cprover_cpp_library(
21+
const std::set<irep_idt> &functions,
22+
symbol_tablet &,
23+
message_handlert &);
24+
25+
#endif // CPROVER_CPP_CPROVER_LIBRARY_H
File renamed without changes.

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Author: Daniel Kroening, [email protected]
2020
#include <ansi-c/cprover_library.h>
2121

2222
#include <cpp/cpp_language.h>
23+
#include <cpp/cprover_library.h>
24+
2325
#include <jsil/jsil_language.h>
2426

2527
#include <goto-programs/initialize_goto_model.h>
@@ -727,6 +729,7 @@ bool goto_analyzer_parse_optionst::process_goto_program(
727729

728730
// add the library
729731
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
732+
link_to_library(goto_model, ui_message_handler, add_cprover_cpp_library);
730733
link_to_library(goto_model, ui_message_handler, add_cprover_c_library);
731734
#endif
732735

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Author: Peter Schrammel
5353
#include <langapi/mode.h>
5454

5555
#include <ansi-c/cprover_library.h>
56+
#include <cpp/cprover_library.h>
5657

5758
#include <cbmc/version.h>
5859

@@ -397,6 +398,7 @@ bool goto_diff_parse_optionst::process_goto_program(
397398

398399
// add the library
399400
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
401+
link_to_library(goto_model, get_message_handler(), add_cprover_cpp_library);
400402
link_to_library(goto_model, get_message_handler(), add_cprover_c_library);
401403

402404
// remove function pointers

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Author: Daniel Kroening, [email protected]
6363
#include <analyses/is_threaded.h>
6464

6565
#include <ansi-c/cprover_library.h>
66+
#include <cpp/cprover_library.h>
6667

6768
#include <cbmc/version.h>
6869

@@ -960,6 +961,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
960961

961962
// add the library
962963
status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom;
964+
link_to_library(goto_model, get_message_handler(), add_cprover_cpp_library);
963965
link_to_library(goto_model, get_message_handler(), add_cprover_c_library);
964966
}
965967

0 commit comments

Comments
 (0)