Skip to content

Verilog: introduce the Verilog indexer #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/pull-request-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
run: make -C regression/verilog test
- name: Run the verilog tests with Z3
run: make -C regression/verilog test-z3
- name: Run the vlindex tests
run: make -C regression/vlindex test
- name: Print ccache stats
run: ccache -s

Expand Down Expand Up @@ -103,6 +105,8 @@ jobs:
run: make -C regression/verilog test
- name: Run the verilog tests with Z3
run: make -C regression/verilog test-z3
- name: Run the vlindex tests
run: make -C regression/vlindex test
- name: Print ccache stats
run: ccache -s
- name: Upload the ebmc binary
Expand Down Expand Up @@ -181,6 +185,8 @@ jobs:
make -C regression/ebmc test
- name: Run the verilog tests
run: make -C regression/verilog test
- name: Run the vlindex tests
run: make -C regression/vlindex test
- name: Print ccache stats
run: ccache -s

Expand Down Expand Up @@ -222,6 +228,8 @@ jobs:
run: make -C regression/verilog test
- name: Run the verilog tests with Z3
run: make -C regression/verilog test-z3
- name: Run the vlindex tests
run: make -C regression/vlindex test
- name: Print ccache stats
run: ccache -s

Expand Down
8 changes: 8 additions & 0 deletions regression/verilog/case/nested_case1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
nested_case1.v
--bound 0
^EXIT=0$
^SIGNAL=0$
^\[main.property.p1\] .* PROVED up to bound 0$
--
^warning: ignoring
17 changes: 17 additions & 0 deletions regression/verilog/case/nested_case1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module main(input x, input y);

reg result;

always @(x, y)
case(x)
0: result = 0;
1:
case(y)
1: result = 1;
0: result = 0;
endcase
endcase

always assert p1: result == (x && y);

endmodule
Comment on lines +1 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way is this test exercising the new indexer?

6 changes: 6 additions & 0 deletions regression/vlindex/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default: test

TEST_PL = ../../lib/cbmc/regression/test.pl

test:
@$(TEST_PL) -e -p -c ../../../src/vlindex/vlindex
8 changes: 8 additions & 0 deletions regression/vlindex/hierarchy1/hierarchy1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE

--hierarchy
^sub$
^subsub$
^top$
^EXIT=0$
^SIGNAL=0$
11 changes: 11 additions & 0 deletions regression/vlindex/hierarchy1/hierarchy1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module top;
sub instance1();
sub instance2();
endmodule

module sub;
subsub instance3();
endmodule

module subsub;
endmodule
9 changes: 9 additions & 0 deletions regression/vlindex/modules1/modules1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE

--modules
^nested modules1.v line 5$
^sub modules1.v line 4$
^top modules1.v line 1$
^EXIT=0$
^SIGNAL=0$

7 changes: 7 additions & 0 deletions regression/vlindex/modules1/modules1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module top;
endmodule

module sub;
module nested;
endmodule
endmodule
6 changes: 4 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
DIRS = ebmc hw-cbmc temporal-logic trans-word-level trans-netlist \
verilog vhdl smvlang ic3 aiger
verilog vhdl smvlang ic3 aiger vlindex

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

all: hw-cbmc.dir ebmc.dir
all: hw-cbmc.dir ebmc.dir vlindex.dir

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

vlindex.dir: cprover.dir verilog.dir

# building cbmc proper
.PHONY: cprover.dir
cprover.dir:
Expand Down
20 changes: 18 additions & 2 deletions src/verilog/verilog_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ Function: verilog_preprocessort::preprocessor

void verilog_preprocessort::preprocessor()
{
bool error_found = false;

try
{
// set up the initial defines
Expand Down Expand Up @@ -221,7 +223,18 @@ void verilog_preprocessort::preprocessor()
// Read a token.
auto token = tokenizer().next_token();
if(token == '`')
directive();
{
try
{
directive();
}
catch(const verilog_preprocessor_errort &e)
{
error().source_location = context().make_source_location();
error() << e.what() << eom;
error_found = true;
}
}
else if(condition)
{
auto a_it = context().define_arguments.find(token.text);
Expand Down Expand Up @@ -256,8 +269,11 @@ void verilog_preprocessort::preprocessor()
if(!context_stack.empty())
error().source_location = context().make_source_location();
error() << e.what() << eom;
throw 0;
error_found = true;
}

if(error_found)
throw 0;
}

/*******************************************************************\
Expand Down
26 changes: 26 additions & 0 deletions src/vlindex/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
SRC = \
verilog_indexer.cpp \
vlindex_main.cpp \
vlindex_parse_options.cpp \
#empty line

OBJ+= $(CPROVER_DIR)/util/util$(LIBEXT) \
$(CPROVER_DIR)/langapi/langapi$(LIBEXT) \
$(CPROVER_DIR)/big-int/big-int$(LIBEXT) \
../verilog/verilog$(LIBEXT)

include ../config.inc
include ../common

CLEANFILES = vlindex$(EXEEXT)

all: vlindex$(EXEEXT)

ifdef DEBUG
CXXFLAGS += -DDEBUG
endif

###############################################################################

vlindex$(EXEEXT): $(OBJ)
$(LINKBIN)
Loading