Skip to content

Commit 74f74d2

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 bd4b223 commit 74f74d2

10 files changed

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

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)):
@@ -21,6 +21,8 @@ ebmc.dir: trans-word-level.dir trans-netlist.dir verilog.dir vhdl.dir \
2121
hw-cbmc.dir: trans-word-level.dir trans-netlist.dir verilog.dir \
2222
vhdl.dir smvlang.dir cprover.dir temporal-logic.dir
2323

24+
vlindex.dir: cprover.dir verilog.dir
25+
2426
# building cbmc proper
2527
.PHONY: cprover.dir
2628
cprover.dir:

src/verilog/verilog_preprocessor.cpp

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

160160
void verilog_preprocessort::preprocessor()
161161
{
162+
bool error_found = false;
163+
162164
try
163165
{
164166
// the first context is the input file
@@ -180,7 +182,18 @@ void verilog_preprocessort::preprocessor()
180182
// Read a token.
181183
auto token = tokenizer().next_token();
182184
if(token == '`')
183-
directive();
185+
{
186+
try
187+
{
188+
directive();
189+
}
190+
catch(const verilog_preprocessor_errort &e)
191+
{
192+
error().source_location = context().make_source_location();
193+
error() << e.what() << eom;
194+
error_found = true;
195+
}
196+
}
184197
else if(condition)
185198
{
186199
auto a_it = context().define_arguments.find(token.text);
@@ -215,8 +228,11 @@ void verilog_preprocessort::preprocessor()
215228
if(!context_stack.empty())
216229
error().source_location = context().make_source_location();
217230
error() << e.what() << eom;
218-
throw 0;
231+
error_found = true;
219232
}
233+
234+
if(error_found)
235+
throw 0;
220236
}
221237

222238
/*******************************************************************\

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)