Commit 5b8104c
verilator@5.036.bcr.3 (#6231)
- Add unit test for hierarchical verilation
- Add `verilator_includes` to expose header files required for
hierarchical verilation, use as `data` for `verilator_bin` target
Diff from 5.036.bcr.2:
```diff
diff --git a/5.036.bcr.2/MODULE.bazel b/5.036.bcr.3/MODULE.bazel
index 7138221..498f2f6 100644
--- a/5.036.bcr.2/MODULE.bazel
+++ b/5.036.bcr.3/MODULE.bazel
@@ -2,7 +2,7 @@
module(
name = "verilator",
- version = "5.036.bcr.2",
+ version = "5.036.bcr.3",
bazel_compatibility = [">=7.2.1"],
)
diff --git a/5.036.bcr.2/overlay/BUILD.bazel b/5.036.bcr.3/overlay/BUILD.bazel
index bb7d5dd..50d4f66 100644
--- a/5.036.bcr.2/overlay/BUILD.bazel
+++ b/5.036.bcr.3/overlay/BUILD.bazel
@@ -338,9 +338,16 @@ cc_library(
visibility = ["//visibility:public"],
)
+filegroup(
+ name = "verilator_include",
+ srcs = glob(["include/**"]),
+ visibility = ["//visibility:public"],
+)
+
cc_binary(
name = "bin/verilator",
srcs = ["src/Verilator.cpp"],
+ data = ["verilator_include"],
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [
diff --git a/5.036.bcr.2/overlay/private/verilator_utils.bzl b/5.036.bcr.3/overlay/private/verilator_utils.bzl
index 581ecc1..e8a82d3 100644
--- a/5.036.bcr.2/overlay/private/verilator_utils.bzl
+++ b/5.036.bcr.3/overlay/private/verilator_utils.bzl
@@ -311,3 +311,73 @@ verilator_build_template = rule(
),
},
)
+
+def _verilator_test_impl(ctx):
+ script = ctx.actions.declare_file(ctx.label.name + ".sh")
+
+ # Get runfiles path to verilator binary
+ repo = ctx.executable.verilator.owner.workspace_name or ctx.workspace_name
+ verilator_rf = "{}/{}".format(repo, ctx.executable.verilator.short_path)
+
+ # Build runfiles paths for sources
+ def _rf(ctx, f):
+ repo = f.owner.workspace_name or ctx.workspace_name
+ return "{}/{}".format(repo, f.short_path)
+ src_rfs = [_rf(ctx, f) for f in ctx.files.srcs]
+ src_args = " ".join(['"${TEST_SRCDIR}/%s"' % s for s in src_rfs])
+
+ # Unique include dirs based on sources (also runfiles paths)
+ def _rf_dir(ctx, f):
+ repo = f.owner.workspace_name or ctx.workspace_name
+ return repo if not f.dirname else "%s/%s" % (repo, f.dirname)
+ seen = {}
+ inc_dirs = []
+ for f in ctx.files.srcs:
+ d = _rf_dir(ctx, f)
+ if d not in seen:
+ seen[d] = True
+ inc_dirs.append(d)
+ inc_flags = " ".join(['-I"${TEST_SRCDIR}/%s"' % d for d in inc_dirs])
+
+ # Arguments to verilator
+ args = " ".join([a for a in ctx.attr.verilator_args])
+
+ # Always specify top module
+ top = "--top-module {}".format(ctx.attr.top_module)
+
+ content = "\n".join([
+ "#!/usr/bin/env bash",
+ "set -euo pipefail",
+ # Get correct path to binary, set VERILATOR_ROOT accordingly
+ 'VERILATOR="${TEST_SRCDIR}/%s"' % verilator_rf,
+ 'export VERILATOR_ROOT="$(dirname "$(dirname "$VERILATOR")")"',
+ # Setup working directory and output directory
+ 'WORKDIR="${TEST_TMPDIR}"',
+ 'mkdir -p "${WORKDIR}"',
+ 'cd "${WORKDIR}"',
+ 'OUTDIR=obj_dir',
+ 'mkdir "$OUTDIR"',
+ '"${VERILATOR}" --Mdir "${OUTDIR}" -I${OUTDIR} ' + args + " " + inc_flags + " " + src_args + " " + top,
+ ])
+
+ ctx.actions.write(output = script, content = content, is_executable = True)
+
+ # Ensure the executable and its runfiles are present in the test’s runfiles.
+ runfiles = ctx.runfiles(files = ctx.files.srcs + [ctx.executable.verilator])
+ runfiles = runfiles.merge(ctx.attr.verilator[DefaultInfo].default_runfiles)
+
+ return DefaultInfo(
+ executable = script,
+ runfiles = runfiles
+ )
+
+verilator_test = rule(
+ implementation = _verilator_test_impl,
+ test = True,
+ attrs = {
+ "verilator": attr.label(executable = True, cfg = "target", default = "//:verilator_bin"),
+ "srcs": attr.label_list(allow_files = [".sv", ".svh", ".v"]),
+ "top_module": attr.string(doc = "The top module name"),
+ "verilator_args": attr.string_list(),
+ },
+)
diff --git a/5.036.bcr.3/overlay/tests/BUILD.bazel b/5.036.bcr.3/overlay/tests/BUILD.bazel
new file mode 100644
index 00000000..3587d2c
--- /dev/null
+++ b/5.036.bcr.3/overlay/tests/BUILD.bazel
@@ -0,0 +1,9 @@
+load("//private:verilator_utils.bzl", "verilator_test")
+
+verilator_test(
+ # Demonstrate hermetic build works with `--hierarchical` switch
+ name = "test_hierarchical",
+ srcs = ["child.sv", "parent.sv"],
+ top_module = "parent",
+ verilator_args = ["--cc", "--hierarchical"],
+)
diff --git a/5.036.bcr.3/overlay/tests/child.sv b/5.036.bcr.3/overlay/tests/child.sv
new file mode 100644
index 00000000..5b25ecf
--- /dev/null
+++ b/5.036.bcr.3/overlay/tests/child.sv
@@ -0,0 +1,19 @@
+module child (
+ input logic clk,
+ input logic rst_n,
+ input logic in,
+ output logic out
+);
+ /*verilator hier_block*/
+
+ logic in_reg;
+
+ always_ff @(posedge clk or negedge rst_n)
+ if (!rst_n)
+ in_reg <= 1'b0;
+ else
+ in_reg <= in;
+
+ assign out = in_reg;
+
+endmodule
diff --git a/5.036.bcr.3/overlay/tests/parent.sv b/5.036.bcr.3/overlay/tests/parent.sv
new file mode 100644
index 00000000..4a25ad5
--- /dev/null
+++ b/5.036.bcr.3/overlay/tests/parent.sv
@@ -0,0 +1,19 @@
+module parent #(
+ parameter int NUM_CHILDREN = 8
+) (
+ input logic clk,
+ input logic rst_n,
+ input logic [NUM_CHILDREN-1:0] in,
+ output logic [NUM_CHILDREN-1:0] out
+);
+
+ for (genvar i=0; i<NUM_CHILDREN; i++) begin: g_children
+ child u_child(
+ .clk(clk),
+ .rst_n(rst_n),
+ .in(in[i]),
+ .out(out[i])
+ );
+ end
+
+endmodule
\ No newline at end of file
diff --git a/5.036.bcr.2/presubmit.yml b/5.036.bcr.3/presubmit.yml
index 882cf0e..32b4ebf 100644
--- a/5.036.bcr.2/presubmit.yml
+++ b/5.036.bcr.3/presubmit.yml
@@ -10,3 +10,5 @@ bcr_test_module:
bazel: ${{ bazel }}
build_targets:
- "//..."
+ test_targets:
+ - "//..."
diff --git a/5.036.bcr.2/source.json b/5.036.bcr.3/source.json
index 868d805..4c6e553 100644
--- a/5.036.bcr.2/source.json
+++ b/5.036.bcr.3/source.json
@@ -4,14 +4,17 @@
"strip_prefix": "verilator-5.036",
"overlay": {
".bazelignore": "sha256-4Yz6+7DIt5CedRfM7s3dxN7HstNIP9KBMBXro1MaVu0=",
- "BUILD.bazel": "sha256-ohpdBx+dn0egYfEDf8bP6sSt8bydqD0wFhMM8P4zGjQ=",
- "MODULE.bazel": "sha256-WNpu950cevXY1hodO6FJUIxwTWRHWjCNOSDTR3URb8c=",
+ "BUILD.bazel": "sha256-Bbz54cFplT9cqiquPz3Ortv3uGt/g0TjT2h8+syMs4I=",
+ "MODULE.bazel": "sha256-Gf98apEz9AQVew1Jn/jJO/x+mOfo11abUeUPeaWjPRs=",
"private/BUILD.bazel": "sha256-um1vB3qYV9jNLMhTue172PCrJbZf/4Nc9gFiwpXqWYY=",
"private/verilator_astgen.py": "sha256-aBHwsUzSKEEEseMUDdXS2XTT8X0jHfAJw7Yu8qvKqPA=",
"private/verilator_bisonpre.py": "sha256-G92zsCtKeJSK2WtjbM47gwwKY19i5QolU6eKp6yUnr0=",
"private/verilator_build_template.py": "sha256-fmqPyHGZcYsgM4mpJX8mHDYMSMPQXBpCTLYZ/NFTv9o=",
"private/verilator_flexfix.py": "sha256-eMDxDSMiytb//P2Ej8KfCTwsblf+/WEsGa1gk2GkfK8=",
- "private/verilator_utils.bzl": "sha256-0nDLkhOTQfvlyjg+B57KXhru4e2unIBOr87YcCbCzq8=",
- "private/verilator_version.py": "sha256-GOQW7JAmkikFKdk7KzNQOiAt8Wk2WZvpC6V2UdLV36U="
+ "private/verilator_utils.bzl": "sha256-OvXHXIQEItxL+cdZuMkAuPC3ypR9+F1fqsJzFkrz4jw=",
+ "private/verilator_version.py": "sha256-GOQW7JAmkikFKdk7KzNQOiAt8Wk2WZvpC6V2UdLV36U=",
+ "tests/BUILD.bazel": "sha256-9++clrqKhaK1T+mkJReBRtHWm+OxAGx9U5VqDOZYZX4=",
+ "tests/child.sv": "sha256-dFhxCaZZ75jbuI/sYVdqm4k5m/Xa4NKduCXkHITS7r4=",
+ "tests/parent.sv": "sha256-rbIzpMk1t+0QYPIJlShSW3mFyJWAfmrfuEi/D/3r50s="
}
}
```
---------
Co-authored-by: Kush Raval <kush@fractile.ai>1 parent af8bebb commit 5b8104c
File tree
15 files changed
+1135
-1
lines changed- modules/verilator
- 5.036.bcr.3
- overlay
- private
- test_regress
15 files changed
+1135
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments