Skip to content

Commit 3a5d3d7

Browse files
committed
Verilog: introduce the Verilog indexer
This adds a recusive decent parser for quicky indexing large quantities of Verilog, tolerating parsing errors, for the purpose of creating overview data very quickly. A new executable, vlindex, is added to output it.
1 parent 0299e1d commit 3a5d3d7

15 files changed

+1896
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
nested_case1.v
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.property.p1\] .* PROVED up to bound 0$
7+
--
8+
^warning: ignoring
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module main(input x, input y);
2+
3+
reg result;
4+
5+
always @(x, y)
6+
case(x)
7+
0: result = 0;
8+
1:
9+
case(y)
10+
1: result = 1;
11+
0: result = 0;
12+
endcase
13+
endcase
14+
15+
always assert p1: result == (x && y);
16+
17+
endmodule

regression/vlindex/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
default: test
2+
3+
TEST_PL = ../../lib/cbmc/regression/test.pl
4+
5+
test:
6+
@$(TEST_PL) -e -p -c ../../../src/vlindex/vlindex
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
3+
--hierarchy
4+
^sub$
5+
^subsub$
6+
^top$
7+
^EXIT=0$
8+
^SIGNAL=0$
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module top;
2+
sub instance1();
3+
sub instance2();
4+
endmodule
5+
6+
module sub;
7+
subsub instance3();
8+
endmodule
9+
10+
module subsub;
11+
endmodule
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
3+
--modules
4+
^nested modules1.v line 5$
5+
^sub modules1.v line 4$
6+
^top modules1.v line 1$
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module top;
2+
endmodule
3+
4+
module sub;
5+
module nested;
6+
endmodule
7+
endmodule

src/Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
DIRS = ebmc hw-cbmc temporal-logic trans-word-level trans-netlist \
2-
verilog vhdl smvlang ic3 aiger
2+
verilog vhdl smvlang ic3 aiger vlindex
33

44
EBMC_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
55
CPROVER_DIR:=../lib/cbmc/src
66

7-
all: hw-cbmc.dir ebmc.dir
7+
all: hw-cbmc.dir ebmc.dir vlindex.dir
88

99
.PHONY: $(patsubst %, %.dir, $(DIRS))
1010
$(patsubst %, %.dir, $(DIRS)):
@@ -25,6 +25,8 @@ endif
2525
hw-cbmc.dir: trans-word-level.dir trans-netlist.dir verilog.dir \
2626
vhdl.dir smvlang.dir cprover.dir temporal-logic.dir
2727

28+
vlindex.dir: cprover.dir verilog.dir
29+
2830
# building cbmc proper
2931
.PHONY: cprover.dir
3032
cprover.dir:

src/verilog/verilog_preprocessor.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ Function: verilog_preprocessort::preprocessor
182182

183183
void verilog_preprocessort::preprocessor()
184184
{
185+
bool error_found = false;
186+
185187
try
186188
{
187189
// set up the initial defines
@@ -221,7 +223,18 @@ void verilog_preprocessort::preprocessor()
221223
// Read a token.
222224
auto token = tokenizer().next_token();
223225
if(token == '`')
224-
directive();
226+
{
227+
try
228+
{
229+
directive();
230+
}
231+
catch(const verilog_preprocessor_errort &e)
232+
{
233+
error().source_location = context().make_source_location();
234+
error() << e.what() << eom;
235+
error_found = true;
236+
}
237+
}
225238
else if(condition)
226239
{
227240
auto a_it = context().define_arguments.find(token.text);
@@ -256,8 +269,11 @@ void verilog_preprocessort::preprocessor()
256269
if(!context_stack.empty())
257270
error().source_location = context().make_source_location();
258271
error() << e.what() << eom;
259-
throw 0;
272+
error_found = true;
260273
}
274+
275+
if(error_found)
276+
throw 0;
261277
}
262278

263279
/*******************************************************************\

src/vlindex/Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
SRC = \
2+
verilog_indexer.cpp \
3+
vlindex_main.cpp \
4+
vlindex_parse_options.cpp \
5+
#empty line
6+
7+
OBJ+= $(CPROVER_DIR)/util/util$(LIBEXT) \
8+
$(CPROVER_DIR)/langapi/langapi$(LIBEXT) \
9+
$(CPROVER_DIR)/big-int/big-int$(LIBEXT) \
10+
../verilog/verilog$(LIBEXT)
11+
12+
include ../config.inc
13+
include ../common
14+
15+
CLEANFILES = vlindex$(EXEEXT)
16+
17+
all: vlindex$(EXEEXT)
18+
19+
ifdef DEBUG
20+
CXXFLAGS += -DDEBUG
21+
endif
22+
23+
###############################################################################
24+
25+
vlindex$(EXEEXT): $(OBJ)
26+
$(LINKBIN)

0 commit comments

Comments
 (0)