Skip to content

Commit

Permalink
feat(rules/iverilog): Improve the iverilog build rules
Browse files Browse the repository at this point in the history
1. Add System Verilog support
2. Support add_defines by add_options
3. Use vcd format instead of lxt2 to support WaveTrace plugin
  • Loading branch information
24bit-xjkp committed Sep 29, 2024
1 parent 0f7e1ea commit 6f209ca
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions xmake/rules/iverilog/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

-- @see https://github.com/xmake-io/xmake/issues/3257
rule("iverilog.binary")
set_extensions(".v", ".vhd")
-- support SystemVerilog
set_extensions(".v", ".sv", ".vhd")
on_load(function (target)
target:set("kind", "binary")
if not target:get("extension") then
Expand All @@ -32,6 +33,7 @@ rule("iverilog.binary")
end)

on_linkcmd(function (target, batchcmds, opt)
import("core.project.project")
local toolchain = assert(target:toolchain("iverilog"), 'we need set_toolchains("iverilog") in target("%s")', target:name())
local iverilog = assert(toolchain:config("iverilog"), "iverilog not found!")

Expand Down Expand Up @@ -80,12 +82,17 @@ rule("iverilog.binary")
end

-- get defines
local defines = target:get("defines")
if defines then
for _, define in ipairs(defines) do
local add_defines = function(defines)
for _, define in ipairs(defines or {}) do
table.insert(argv, "-D" .. define)
end
end
add_defines(target:get("defines"))
-- support add_defines in options
for _, option_name in ipairs(target:get("options") or {}) do
local option = project.option(option_name)
add_defines(option:enabled() and option:get("defines"))
end

-- get includedirs
local includedirs = target:get("includedirs")
Expand Down Expand Up @@ -115,5 +122,6 @@ rule("iverilog.binary")
local toolchain = assert(target:toolchain("iverilog"), 'we need set_toolchains("iverilog") in target("%s")', target:name())
local vvp = assert(toolchain:config("vvp"), "vvp not found!")

os.execv(vvp, {"-n", target:targetfile(), "-lxt2"})
-- some oscilloscopes do not support lxt2
os.execv(vvp, {"-n", target:targetfile()})
end)

0 comments on commit 6f209ca

Please sign in to comment.