Skip to content

Commit ff1e81e

Browse files
authored
Merge pull request #2289 from tautschnig/interpreter-deduplicate
Interpreter: de-duplicate code
2 parents 561b33e + eba686f commit ff1e81e

File tree

20 files changed

+268
-75
lines changed

20 files changed

+268
-75
lines changed

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ add_subdirectory(linking-goto-binaries)
6161
add_subdirectory(symtab2gb)
6262
add_subdirectory(validate-trace-xml-schema)
6363
add_subdirectory(cbmc-primitives)
64+
add_subdirectory(goto-interpreter)
6465
add_subdirectory(cbmc-sequentialization)
6566

6667
if(WITH_MEMORY_ANALYZER)

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ DIRS = cbmc \
3535
goto-ld \
3636
validate-trace-xml-schema \
3737
cbmc-primitives \
38+
goto-interpreter \
3839
# Empty last line
3940

4041
ifeq ($(OS),Windows_NT)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-instrument> ${is_windows}"
9+
)

regression/goto-interpreter/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
default: tests.log
2+
3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
is_windows=true
9+
else
10+
exe=../../../src/goto-cc/goto-cc
11+
is_windows=false
12+
endif
13+
14+
test:
15+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument $(is_windows)'
16+
17+
tests.log:
18+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument $(is_windows)'
19+
20+
show:
21+
@for dir in *; do \
22+
if [ -d "$$dir" ]; then \
23+
vim -o "$$dir/*.c" "$$dir/*.out"; \
24+
fi; \
25+
done;
26+
27+
clean:
28+
@for dir in *; do \
29+
$(RM) tests.log; \
30+
if [ -d "$$dir" ]; then \
31+
cd "$$dir"; \
32+
$(RM) *.out *.gb; \
33+
cd ..; \
34+
fi \
35+
done
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
union U {
2+
int x;
3+
char c[sizeof(int)];
4+
};
5+
6+
int main()
7+
{
8+
union U u;
9+
// make the lowest and highest byte 1
10+
u.x = 1 | (1 << (sizeof(int) * 8 - 8));
11+
int i = u.x;
12+
char c0 = u.c[0];
13+
char c1 = u.c[1];
14+
char c2 = u.c[2];
15+
char c3 = u.c[3];
16+
17+
__CPROVER_assert(u.c[0] == 1, "");
18+
19+
return 0;
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
KNOWNBUG
2+
main.c
3+
se
4+
^Starting interpreter$
5+
^\d+- Program End\.$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^assertion failed at \d+$
10+
--
11+
The memory model of the interpreter does not record individual bytes. Therefore,
12+
an access to individual bytes still yields the full object, making the assertion
13+
in this test spuriously fail.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
se
4+
^Starting interpreter$
5+
^\d+- Program End\.$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--

regression/goto-interpreter/chain.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
goto_cc=$1
6+
goto_instrument=$2
7+
is_windows=$3
8+
9+
options=${*:4:$#-4}
10+
name=${*:$#}
11+
base_name=${name%.c}
12+
13+
if [[ "${is_windows}" == "true" ]]; then
14+
"${goto_cc}" "${name}"
15+
mv "${base_name}.exe" "${base_name}.gb"
16+
else
17+
"${goto_cc}" "${name}" -o "${base_name}.gb"
18+
fi
19+
20+
echo ${options} | tr , '\n' | "${goto_instrument}" --interpreter "${base_name}.gb"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main()
2+
{
3+
return 0;
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CORE
2+
main.c
3+
h,q
4+
^Starting interpreter$
5+
^Interpreter help$
6+
^h: display this menu$
7+
^j: output json trace$
8+
^m: output memory dump$
9+
^o: output goto trace$
10+
^q: quit$
11+
^r: run up to entry point$
12+
^s#: step a number of instructions$
13+
^sa: step across a function$
14+
^so: step out of a function$
15+
^se: step until end of program$
16+
^\d+- Program End\.$
17+
^EXIT=0$
18+
^SIGNAL=0$
19+
--

0 commit comments

Comments
 (0)