diff options
| -rw-r--r-- | tests/projects/embed/verilator/modules/src/main.v | 6 | ||||
| -rw-r--r-- | tests/projects/embed/verilator/modules/src/mod.mpp | 10 | ||||
| -rw-r--r-- | tests/projects/embed/verilator/modules/src/sim_main.cpp | 16 | ||||
| -rw-r--r-- | tests/projects/embed/verilator/modules/xmake.lua | 11 | ||||
| -rw-r--r-- | xmake/rules/verilator/verilator.lua | 32 | ||||
| -rw-r--r-- | xmake/rules/verilator/xmake.lua | 26 |
6 files changed, 51 insertions, 50 deletions
diff --git a/tests/projects/embed/verilator/modules/src/main.v b/tests/projects/embed/verilator/modules/src/main.v new file mode 100644 index 000000000..b7f80008d --- /dev/null +++ b/tests/projects/embed/verilator/modules/src/main.v @@ -0,0 +1,6 @@ +module hello; + initial begin + $display("hello world!"); + $finish ; + end +endmodule diff --git a/tests/projects/embed/verilator/modules/src/mod.mpp b/tests/projects/embed/verilator/modules/src/mod.mpp new file mode 100644 index 000000000..dcbf2ee71 --- /dev/null +++ b/tests/projects/embed/verilator/modules/src/mod.mpp @@ -0,0 +1,10 @@ +module; +#include <cstdio> + +export module mod; + +export namespace mod { + void say(const char* str) { + printf("%s\n", str); + } +} diff --git a/tests/projects/embed/verilator/modules/src/sim_main.cpp b/tests/projects/embed/verilator/modules/src/sim_main.cpp new file mode 100644 index 000000000..aff1c83ba --- /dev/null +++ b/tests/projects/embed/verilator/modules/src/sim_main.cpp @@ -0,0 +1,16 @@ +#include "hello.h" +#include "verilated.h" +import mod; + +double sc_time_stamp() { return 0; } + +int main(int argc, char** argv) { + VerilatedContext* contextp = new VerilatedContext; + contextp->commandArgs(argc, argv); + hello* top = new hello{contextp}; + mod::say("hello module!"); + while (!contextp->gotFinish()) { top->eval(); } + delete top; + delete contextp; + return 0; +} diff --git a/tests/projects/embed/verilator/modules/xmake.lua b/tests/projects/embed/verilator/modules/xmake.lua new file mode 100644 index 000000000..324f9bfb6 --- /dev/null +++ b/tests/projects/embed/verilator/modules/xmake.lua @@ -0,0 +1,11 @@ +add_requires("verilator") + +-- @see https://github.com/xmake-io/xmake/issues/7624 +target("hello") + add_rules("verilator.binary") + set_toolchains("@verilator") + set_languages("c++20") + set_policy("build.c++.modules", true) + add_files("src/*.v") + add_files("src/*.cpp") + add_files("src/*.mpp") diff --git a/xmake/rules/verilator/verilator.lua b/xmake/rules/verilator/verilator.lua index 72de7b91b..dbf6192bc 100644 --- a/xmake/rules/verilator/verilator.lua +++ b/xmake/rules/verilator/verilator.lua @@ -309,38 +309,6 @@ function build_cppfiles(target, jobgraph, sourcebatch, opt) local targetname = target:name() local makefile = path.join(autogendir, targetname .. "." .. makefile_type) - -- build verilog files - depend.on_changed(function() - local argv = { "--cc", "--make", makefile_type, "--prefix", targetname, "--Mdir", autogendir } - local flags = _get_verilator_flags(target) - if flags then - table.join2(argv, flags) - end - local language_flags = _get_lanuage_flags(target) - if language_flags then - table.join2(argv, language_flags) - end - local sourcefiles = sourcebatch.sourcefiles - for _, sourcefile in ipairs(sourcefiles) do - local sourcefile = sourcefile - progress.show(opt.progress or 0, "${color.build.object}compiling.verilog %s", sourcefile) - -- we need to use slashes to fix it on windows - -- @see https://github.com/verilator/verilator/issues/3873 - if is_host("windows") then - sourcefile = sourcefile:gsub("\\", "/") - end - table.insert(argv, sourcefile) - end - - -- generate c++ sourcefiles - os.vrunv(verilator, argv, { envs = toolchain:runenvs() }) - end, { - dependfile = makefile .. ".d", - files = sourcebatch.sourcefiles, - changed = target:is_rebuilt(), - lastmtime = os.mtime(makefile) - }) - -- get compiled source files local sourcefiles if support_json then diff --git a/xmake/rules/verilator/xmake.lua b/xmake/rules/verilator/xmake.lua index 6d9a0b7b0..a04d0cd55 100644 --- a/xmake/rules/verilator/xmake.lua +++ b/xmake/rules/verilator/xmake.lua @@ -30,18 +30,16 @@ rule("verilator.binary") import("verilator").config(target) end) - before_build_files(function (target, sourcebatch) - -- Just to avoid before_buildcmd_files being executed at build time + -- we need to generate cpp files before scanning c++ modules + -- https://github.com/xmake-io/xmake/issues/7624 + before_preparecmd_files(function(target, batchcmds, sourcebatch, opt) + import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt) end) on_build_files(function (target, jobgraph, sourcebatch, opt) import("verilator").build_cppfiles(target, jobgraph, sourcebatch, opt) end, {jobgraph = true, batch = true, distcc = true}) - before_buildcmd_files(function(target, batchcmds, sourcebatch, opt) - import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt) - end) - on_buildcmd_files(function (target, batchcmds, sourcebatch, opt) import("verilator").buildcmd_cppfiles(target, batchcmds, sourcebatch, opt) end) @@ -57,18 +55,14 @@ rule("verilator.static") import("verilator").config(target) end) - before_build_files(function (target, sourcebatch) - -- Just to avoid before_buildcmd_files being executed at build time + before_preparecmd_files(function(target, batchcmds, sourcebatch, opt) + import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt) end) on_build_files(function (target, jobgraph, sourcebatch, opt) import("verilator").build_cppfiles(target, jobgraph, sourcebatch, opt) end, {jobgraph = true, batch = true, distcc = true}) - before_buildcmd_files(function(target, batchcmds, sourcebatch, opt) - import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt) - end) - on_buildcmd_files(function (target, batchcmds, sourcebatch, opt) import("verilator").buildcmd_cppfiles(target, batchcmds, sourcebatch, opt) end) @@ -84,18 +78,14 @@ rule("verilator.shared") import("verilator").config(target) end) - before_build_files(function (target, sourcebatch) - -- Just to avoid before_buildcmd_files being executed at build time + before_preparecmd_files(function(target, batchcmds, sourcebatch, opt) + import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt) end) on_build_files(function (target, jobgraph, sourcebatch, opt) import("verilator").build_cppfiles(target, jobgraph, sourcebatch, opt) end, {jobgraph = true, batch = true, distcc = true}) - before_buildcmd_files(function(target, batchcmds, sourcebatch, opt) - import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt) - end) - on_buildcmd_files(function (target, batchcmds, sourcebatch, opt) import("verilator").buildcmd_cppfiles(target, batchcmds, sourcebatch, opt) end) |
