From 044ca9dde409e3c91542fe95513d6641110f8462 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Tue, 17 Mar 2020 09:34:31 +0000 Subject: Add support for SystemVerilog-style `define to Verilog frontend This patch should support things like `define foo(a, b = 3, c) a+b+c `foo(1, ,2) which will evaluate to 1+3+2. It also spots mistakes like `foo(1) (the 3rd argument doesn't have a default value, so a call site is required to set it). Most of the patch is a simple parser for the format in preproc.cc, but I've also taken the opportunity to wrap up the "name -> definition" map in a type, rather than use multiple std::map's. Since this type needs to be visible to code that touches defines, I've pulled it (and the frontend_verilog_preproc declaration) out into a new file at frontends/verilog/preproc.h and included that where necessary. Finally, the patch adds a few tests in tests/various to check that we are parsing everything correctly. --- tests/various/sv_defines.ys | 33 +++++++++++++++++++++++++++++++++ tests/various/sv_defines_dup.ys | 5 +++++ tests/various/sv_defines_mismatch.ys | 5 +++++ tests/various/sv_defines_too_few.ys | 7 +++++++ 4 files changed, 50 insertions(+) create mode 100644 tests/various/sv_defines.ys create mode 100644 tests/various/sv_defines_dup.ys create mode 100644 tests/various/sv_defines_mismatch.ys create mode 100644 tests/various/sv_defines_too_few.ys (limited to 'tests') diff --git a/tests/various/sv_defines.ys b/tests/various/sv_defines.ys new file mode 100644 index 000000000..8e70ee0ee --- /dev/null +++ b/tests/various/sv_defines.ys @@ -0,0 +1,33 @@ +# Check that basic macro expansions do what you'd expect + +read_verilog <