Skip to content

Commit bf4ed8b

Browse files
kroeningtautschnig
authored andcommitted
Add the crangler tool
This is a command-line utility that makes changes to a preprocessed C file that are prescribed in a JSON configuration file. The initial set of transformations is as follows. * add a contract (pre/post/assigns) to a named C function * add a loop invariant to a loop identified by the name of the function its in and a loop number * remove the 'static' storage classifier from a function The resulting source file is written to standard output or to file specified in the JSON configuration.
1 parent ce3fcaa commit bf4ed8b

29 files changed

+1791
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
150150
"$<TARGET_FILE:unit>"
151151
"$<TARGET_FILE:goto-harness>"
152152
"$<TARGET_FILE:cbmc>"
153+
"$<TARGET_FILE:crangler>"
153154
"$<TARGET_FILE:driver>"
154155
"$<TARGET_FILE:goto-analyzer>"
155156
"$<TARGET_FILE:goto-cc>"
@@ -213,6 +214,8 @@ cprover_default_properties(
213214
cbmc
214215
cbmc-lib
215216
cpp
217+
crangler
218+
crangler-lib
216219
driver
217220
goto-analyzer
218221
goto-analyzer-lib

regression/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ if(WITH_MEMORY_ANALYZER)
8383
add_subdirectory(memory-analyzer)
8484
add_subdirectory(extract_type_header)
8585
endif()
86+
87+
if(NOT WIN32)
88+
add_subdirectory(crangler)
89+
endif()

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# listed with decreasing runtimes (i.e. longest running at the top)
44
DIRS = cbmc \
55
cbmc-library \
6+
crangler \
67
goto-analyzer \
78
ansi-c \
89
goto-instrument \

regression/crangler/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_test_pl_tests(
2+
"$<TARGET_FILE:crangler>"
3+
)

regression/crangler/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
default: tests.log
2+
3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
test:
8+
9+
tests.log:
10+
11+
else
12+
test:
13+
@../test.pl -e -p -c '../../../src/crangler/crangler'
14+
15+
tests.log:
16+
@../test.pl -e -p -c '../../../src/crangler/crangler'
17+
endif
18+
19+
clean:
20+
@for dir in *; do \
21+
$(RM) tests.log; \
22+
if [ -d "$$dir" ]; then \
23+
cd "$$dir"; \
24+
$(RM) *.out *.gb; \
25+
cd ..; \
26+
fi \
27+
done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int foo()
2+
{
3+
return 0;
4+
}
5+
6+
int bar();
7+
8+
static void foobar1()
9+
{
10+
}
11+
12+
void static foobar2()
13+
{
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
remove_static1.json
3+
4+
^\s+void foobar1\(\)$
5+
^void\s+foobar2\(\)$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"sources": [
3+
"remove_static1.c"
4+
],
5+
"functions": [
6+
{
7+
"foobar1": [
8+
"remove static"
9+
]
10+
},
11+
{
12+
"foobar2": [
13+
"remove static"
14+
]
15+
}
16+
],
17+
"output": "stdout"
18+
}

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ add_subdirectory(statement-list)
106106
add_subdirectory(util)
107107

108108
add_subdirectory(cbmc)
109+
add_subdirectory(crangler)
109110
add_subdirectory(goto-cc)
110111
add_subdirectory(goto-instrument)
111112
add_subdirectory(goto-analyzer)

src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ DIRS = analyses \
44
big-int \
55
cbmc \
66
cpp \
7+
crangler \
78
goto-analyzer \
89
goto-cc \
910
goto-checker \
@@ -27,6 +28,7 @@ DIRS = analyses \
2728
# Empty last line
2829

2930
all: cbmc.dir \
31+
crangler.dir \
3032
goto-analyzer.dir \
3133
goto-cc.dir \
3234
goto-diff.dir \
@@ -59,6 +61,8 @@ $(patsubst %, %.dir, $(filter-out big-int util, $(DIRS))): util.dir
5961

6062
cpp.dir: ansi-c.dir linking.dir
6163

64+
crangler.dir: util.dir json.dir
65+
6266
languages: util.dir langapi.dir \
6367
cpp.dir ansi-c.dir xmllang.dir assembler.dir \
6468
jsil.dir json.dir json-symtab-language.dir statement-list.dir

0 commit comments

Comments
 (0)