Skip to content
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all

.PHONY: all init build install appimage test test_all test_vpi_all test_mem_direct_all \
test_all_java test_all_scala clean wheel wheel_install tests smoke_tests unit_tests
Expand Down
5 changes: 5 additions & 0 deletions example/MultiFileRTL/design.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
+incdir+inc
inc/defs.vh
inc/outer.svh
leaf.v
top.sv
29 changes: 29 additions & 0 deletions example/MultiFileRTL/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
try:
from UT_MultiFileRTLTop import *
except:
try:
from MultiFileRTLTop import *
except:
from __init__ import *


if __name__ == "__main__":
dut = DUTMultiFileRTLTop()

test_vectors = [
0x0,
0x1,
0x5A,
0x123,
0xABC,
0xFFF,
]

for idx, value in enumerate(test_vectors):
dut.a.value = value
dut.Step(1)
print(f"case {idx}: a=0x{value:x}, b=0x{dut.b.value:x}")
assert dut.b.value == value, "output mismatch"

print("Test Passed, destroy UTMultiFileRTLTop")
dut.Finish()
1 change: 1 addition & 0 deletions example/MultiFileRTL/inc/defs.vh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`define MULTI_FILE_RTL_W 8
2 changes: 2 additions & 0 deletions example/MultiFileRTL/inc/outer.svh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`include "defs.vh"
`define MULTI_FILE_RTL_OUT_W (`MULTI_FILE_RTL_W + 4)
8 changes: 8 additions & 0 deletions example/MultiFileRTL/leaf.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module MultiFileRTLLeaf #(
parameter WIDTH = 8
) (
input [WIDTH-1:0] a,
output [WIDTH-1:0] b
);
assign b = a;
endmodule
29 changes: 29 additions & 0 deletions example/MultiFileRTL/release-vcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

OUT_ROOT="${OUT_ROOT:-output}"
OUT_DIR="$(realpath -m "${OUT_ROOT}/MultiFileRTL")"
LANGUAGE_ARGS=()

rm -rf "$OUT_DIR"
if [[ $* == *"python"* ]]; then
LANGUAGE_ARGS+=(--lang python)
fi

./build/bin/picker export \
--fs example/MultiFileRTL/design.f \
--autobuild true \
--sim vcs \
--verdi-mode modern \
-w MultiFileRTLTop.fsdb \
--sname MultiFileRTLTop \
--tdir "$OUT_DIR" \
--sdir template \
"${LANGUAGE_ARGS[@]}" \
"$@"

if [[ $* == *"python"* ]]; then
cp example/MultiFileRTL/example.py "$OUT_DIR"
cd "$OUT_DIR"
python3 example.py
fi
13 changes: 13 additions & 0 deletions example/MultiFileRTL/top.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
`include "outer.svh"

module MultiFileRTLTop(
input logic [`MULTI_FILE_RTL_OUT_W-1:0] a,
output logic [`MULTI_FILE_RTL_OUT_W-1:0] b
);
MultiFileRTLLeaf #(
.WIDTH(`MULTI_FILE_RTL_OUT_W)
) u_leaf (
.a(a),
.b(b)
);
endmodule
17 changes: 15 additions & 2 deletions src/codegen/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ namespace picker { namespace codegen {
std::string &ofilelist, std::vector<std::string> &incdirs)
{
std::vector<std::pair<std::string, std::string>> path_list;
const std::vector<std::string> allow_file_types = {".sv", ".v", ".cpp", ".c", ".cc", ".cxx", ".so", ".a", ".o"};
const std::vector<std::string> allow_file_types = {
".sv", ".v", ".svh", ".vh", ".cpp", ".c", ".cc", ".cxx", ".so", ".a", ".o"};
const std::vector<std::string> header_file_types = {".svh", ".vh"};
std::unordered_set<std::string> incdir_set;
auto resolve_input_path = [](const std::string &path, const std::string &base_dir) {
auto resolved = std::filesystem::path(path);
Expand Down Expand Up @@ -129,6 +131,10 @@ namespace picker { namespace codegen {
if (!std::filesystem::exists(resolved_file)) PK_FATAL("File not found: %s\n", target_file.c_str());
path = std::filesystem::absolute(resolved_file).lexically_normal().string();
if (source_file_set.count(path) != 0) { continue; } // skip source file
if (check_file_type(path, header_file_types)) {
add_incdir(std::filesystem::path(path).parent_path().string(), "");
continue;
}
ofilelist += path + "\n";
} else if (path.ends_with("/")) { // directory
auto target_dir = path;
Expand All @@ -138,7 +144,14 @@ namespace picker { namespace codegen {
for (const auto &entry : iter) {
if (entry.is_regular_file()) {
std::string filename = entry.path().filename().string();
if (check_file_type(filename, allow_file_types)) { ofilelist += entry.path().string() + "\n"; }
if (check_file_type(filename, allow_file_types)) {
const auto entry_path = entry.path().string();
if (check_file_type(entry_path, header_file_types)) {
add_incdir(entry.path().parent_path().string(), "");
continue;
}
ofilelist += entry_path + "\n";
}
}
}
} else {
Expand Down
22 changes: 22 additions & 0 deletions test/test_codegen_filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ int main()
fs::create_directories(cwd_base / "inc_shadow");

write_text(base / "rtl1.sv", "module m; endmodule\n");
write_text(base / "defs.vh", "`define DEF_W 8\n");
write_text(base / "macro.svh", "`include \"defs.vh\"\n");
write_text(base / "sub" / "rtl2.v", "module n; endmodule\n");
write_text(base / "sub2" / "ignore.txt", "noop\n");
write_text(base / "sub2" / "rtl3.sv", "module p; endmodule\n");
Expand Down Expand Up @@ -154,6 +156,26 @@ int main()
assert(contains_line(ofilelist3, (base / "rtl1.sv").string()));
assert(!contains_line(ofilelist3, (cwd_base / "rtl1.sv").string()));

const fs::path filelist4 = base / "filelist4.f";
write_text(filelist4,
"defs.vh\n"
"macro.svh\n"
"rtl1.sv\n");

std::string ofilelist4;
std::vector<std::string> incdirs4;
stderr_output = capture_stderr([&]() {
picker::codegen::gen_filelist({}, {filelist4.string()}, ofilelist4, incdirs4);
});

assert(stderr_output.empty());
assert(contains_line(ofilelist4, (base / "rtl1.sv").string()));
assert(!contains_line(ofilelist4, (base / "defs.vh").string()));
assert(!contains_line(ofilelist4, (base / "macro.svh").string()));
std::set<std::string> incset4(incdirs4.begin(), incdirs4.end());
assert(incset4.size() == 1);
assert(incset4.count(base.string()) == 1);

fs::remove_all(cwd_base);
fs::remove_all(base);
return 0;
Expand Down
Loading