Skip to content

Commit 17b5f6b

Browse files
committed
C++ front-end now has its own library
Moved new/delete implementation from ansi-c to cpp.
1 parent 869b05e commit 17b5f6b

11 files changed

+135
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ src/ansi-c/gcc_builtin_headers_mips.inc
4949
src/ansi-c/gcc_builtin_headers_power.inc
5050
src/ansi-c/gcc_builtin_headers_ubsan.inc
5151
src/ansi-c/windows_builtin_headers.inc
52+
src/cpp/cprover_library.inc
5253

5354
# regression/test files
5455
*.out

.travis.yml

+1
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

src/cbmc/cbmc_parse_options.cpp

+4
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/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
file(GLOB cpp_library_sources "library/*.c")
2+
3+
add_custom_command(OUTPUT converter_input.txt
4+
COMMAND cat ${cpp_library_sources} > converter_input.txt
5+
DEPENDS ${cpp_library_sources}
6+
)
7+
8+
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
9+
COMMAND ../ansi-c/converter < "converter_input.txt" > "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
10+
DEPENDS "converter_input.txt" ../ansi-c/converter
11+
)
12+
13+
################################################################################
14+
15+
file(GLOB library_check_sources "library/*.c")
16+
17+
add_custom_command(
18+
DEPENDS ${library_check_sources}
19+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../ansi-c/library_check.sh ${CMAKE_C_COMPILER} ${library_check_sources}
20+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp
21+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23+
)
24+
25+
add_custom_target(library_check
26+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/library-check.stamp
27+
)
28+
29+
################################################################################
30+
131
file(GLOB_RECURSE sources "*.cpp" "*.h")
232
add_library(cpp ${sources})
333

src/cpp/Makefile

+18-1
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+
../ansi-c/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

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 << "#line 1 \"<builtin-library>\"\n"
24+
<< "#undef inline\n";
25+
26+
// cprover_library.inc may not have been generated when running Doxygen, thus
27+
// make Doxygen skip this part
28+
/// \cond
29+
const struct cprover_library_entryt cprover_library[] =
30+
#include "cprover_library.inc"
31+
; // NOLINT(whitespace/semicolon)
32+
/// \endcond
33+
34+
return get_cprover_library_text(
35+
functions, symbol_table, cprover_library, library_text.str());
36+
}
37+
38+
void add_cprover_cpp_library(
39+
const std::set<irep_idt> &functions,
40+
symbol_tablet &symbol_table,
41+
message_handlert &message_handler)
42+
{
43+
if(config.ansi_c.lib == configt::ansi_ct::libt::LIB_NONE)
44+
return;
45+
46+
const std::string library_text =
47+
get_cprover_library_text(functions, symbol_table);
48+
49+
add_library(library_text, symbol_table, message_handler);
50+
}

src/cpp/cprover_library.h

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

src/goto-analyzer/goto_analyzer_parse_options.cpp

+3
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

+2
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

+2
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)