Skip to content

Commit 864df21

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 3c31174 commit 864df21

File tree

10 files changed

+1475
-4
lines changed

10 files changed

+1475
-4
lines changed
Lines changed: 8 additions & 0 deletions
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
Lines changed: 17 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Function: verilog_preprocessort::preprocessor
161161

162162
void verilog_preprocessort::preprocessor()
163163
{
164+
bool error_found = false;
165+
164166
try
165167
{
166168
// the first context is the input file
@@ -182,7 +184,18 @@ void verilog_preprocessort::preprocessor()
182184
// Read a token.
183185
auto token = tokenizer().next_token();
184186
if(token == '`')
185-
directive();
187+
{
188+
try
189+
{
190+
directive();
191+
}
192+
catch(const verilog_preprocessor_errort &e)
193+
{
194+
error().source_location = context().make_source_location();
195+
error() << e.what() << eom;
196+
error_found = true;
197+
}
198+
}
186199
else if(condition)
187200
{
188201
auto a_it = context().define_arguments.find(token.text);
@@ -217,8 +230,11 @@ void verilog_preprocessort::preprocessor()
217230
if(!context_stack.empty())
218231
error().source_location = context().make_source_location();
219232
error() << e.what() << eom;
220-
throw 0;
233+
error_found = true;
221234
}
235+
236+
if(error_found)
237+
throw 0;
222238
}
223239

224240
/*******************************************************************\

src/vlindex/Makefile

Lines changed: 26 additions & 0 deletions
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)