diff options
| author | ruki <[email protected]> | 2023-01-14 10:55:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-01-14 10:55:03 +0800 |
| commit | 6ebcc5c4bc3df9459904c777f5c3d4ceb0b6b261 (patch) | |
| tree | b5222713d029936fd84473e3131522d3df28e787 | |
| parent | 096498b2d1cb6b813a4545ffc407ebceddf596e4 (diff) | |
add switches
| -rw-r--r-- | tests/projects/embed/verilator/hello/src/sim_main.cpp | 4 | ||||
| -rw-r--r-- | tests/projects/embed/verilator/hello/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/rules/verilator/xmake.lua | 41 |
3 files changed, 38 insertions, 8 deletions
diff --git a/tests/projects/embed/verilator/hello/src/sim_main.cpp b/tests/projects/embed/verilator/hello/src/sim_main.cpp index 093fdac3e..95660029b 100644 --- a/tests/projects/embed/verilator/hello/src/sim_main.cpp +++ b/tests/projects/embed/verilator/hello/src/sim_main.cpp @@ -1,6 +1,10 @@ #include "hello.h" #include "verilated.h" + double sc_time_stamp() { + return 0; + } + int main(int argc, char** argv) { VerilatedContext* contextp = new VerilatedContext; contextp->commandArgs(argc, argv); diff --git a/tests/projects/embed/verilator/hello/xmake.lua b/tests/projects/embed/verilator/hello/xmake.lua index 2f2d6d158..786dc5332 100644 --- a/tests/projects/embed/verilator/hello/xmake.lua +++ b/tests/projects/embed/verilator/hello/xmake.lua @@ -4,3 +4,4 @@ target("hello") set_toolchains("@verilator") add_files("src/*.v") add_files("src/*.cpp") + add_values("verilator.flags", "--trace", "--timing") diff --git a/xmake/rules/verilator/xmake.lua b/xmake/rules/verilator/xmake.lua index 4e9823c09..0029dc0b7 100644 --- a/xmake/rules/verilator/xmake.lua +++ b/xmake/rules/verilator/xmake.lua @@ -33,6 +33,10 @@ rule("verilator.binary") local cmakefile = path.join(tmpdir, "test.cmake") local sourcefile = path.join(tmpdir, "main.v") local argv = {"--cc", "--make", "cmake", "--prefix", "test", "--Mdir", tmpdir, sourcefile} + local flags = target:values("verilator.flags") + if flags then + table.join2(argv, flags) + end io.writefile(sourcefile, [[ module hello; initial begin @@ -45,7 +49,7 @@ endmodule]]) -- parse some configurations from cmakefile local verilator_root - local global_classes + local switches = {} local targetname = target:name() io.gsub(cmakefile, "set%((%S-) (.-)%)", function (key, values) if key == "VERILATOR_ROOT" then @@ -53,7 +57,26 @@ endmodule]]) if not verilator_root then verilator_root = values:match("(.-) CACHE PATH") end + elseif key == "test_SC" then + -- SystemC output mode? 0/1 (from --sc) + switches.SC = values:trim() + elseif key == "test_COVERAGE" then + -- Coverage output mode? 0/1 (from --coverage) + switches.COVERAGE = values:trim() + elseif key == "test_TIMING" then + -- Timing mode? 0/1 (from --timing) + switches.TIMING = values:trim() + elseif key == "test_THREADS" then + -- Threaded output mode? 1/N threads (from --threads) + switches.THREADS = values:trim() + elseif key == "test_TRACE_VCD" then + -- VCD Tracing output mode? 0/1 (from --trace) + switches.TRACE_VCD = values:trim() + elseif key == "test_TRACE_FST" then + -- FST Tracing output mode? 0/1 (from --trace-fst) + switches.TRACE_FST = values:trim() end + end) assert(verilator_root, "the verilator root directory not found!") target:data_set("verilator.root", verilator_root) @@ -79,15 +102,13 @@ endmodule]]) target:set("languages", "c++20") end - -- TODO add defines - target:add("defines", "VM_COVERAGE=0") - target:add("defines", "VM_SC=0") - target:add("defines", "VM_TRACE=1") - target:add("defines", "VM_TRACE_FST=0") - target:add("defines", "VM_TRACE_VCD=1") + -- add defines for switches + for k, v in pairs(switches) do + target:add("defines", "VM_" .. k .. "=" .. v) + end -- add syslinks - if target:is_plat("linux", "macosx") then + if target:is_plat("linux", "macosx") and switches.THREADS == "1" then target:add("syslinks", "pthread") end @@ -103,6 +124,10 @@ endmodule]]) local dependfile = cmakefile .. ".d" local argv = {"--cc", "--make", "cmake", "--prefix", targetname, "--Mdir", path(autogendir)} + local flags = target:values("verilator.flags") + if flags then + table.join2(argv, flags) + end local sourcefiles = sourcebatch.sourcefiles for _, sourcefile in ipairs(sourcefiles) do batchcmds:show_progress(opt.progress, "${color.build.target}compiling.verilator %s", path.filename(sourcefile)) |
