summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-01-12 21:03:58 +0800
committerruki <[email protected]>2023-01-13 20:50:57 +0800
commitaf36e0b08cf70100ae8cd15ff7dc4f33066d9ff5 (patch)
treeaea99aedfac1bbc90cd8444bcc6b458dbc15062f
parent48180268bf262c80f5b43af5f496236023259613 (diff)
add flags for iverilog
-rw-r--r--xmake/rules/iverilog/xmake.lua64
1 files changed, 60 insertions, 4 deletions
diff --git a/xmake/rules/iverilog/xmake.lua b/xmake/rules/iverilog/xmake.lua
index dfedb530e..01c5ef951 100644
--- a/xmake/rules/iverilog/xmake.lua
+++ b/xmake/rules/iverilog/xmake.lua
@@ -34,17 +34,73 @@ rule("iverilog.binary")
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!")
- -- compile wave file
local targetfile = target:targetfile()
local targetdir = path.directory(targetfile)
local argv = {"-o", targetfile}
local sourcebatch = target:sourcebatches()["iverilog.binary"]
local sourcefiles = table.wrap(sourcebatch.sourcefiles)
assert(#sourcefiles > 0, "no source files!")
- local extension = path.extension(sourcefiles[1])
- if extension == ".vhd" then
- table.insert(argv, "-g2012")
+
+ -- get languages
+ --
+ -- Select the Verilog language generation to support in the compiler.
+ -- This selects between IEEE1364-1995, IEEE1364-2001, IEEE1364-2005, IEEE1800-2005, IEEE1800-2009, IEEE1800-2012.
+ --
+ local language_ieee
+ local languages = target:get("languages")
+ if languages then
+ for _, language in ipairs(languages) do
+ if language:startswith("IEEE") then
+ language_ieee = language
+ break
+ end
+ end
+ end
+ if language_ieee then
+ local maps = {
+ ["IEEE1364-1995"] = "-g1995",
+ ["IEEE1364-2001"] = "-g2001",
+ ["IEEE1364-2005"] = "-g2005",
+ ["IEEE1800-2005"] = "-g2005-sv",
+ ["IEEE1800-2009"] = "-g2009",
+ ["IEEE1800-2012"] = "-g2012",
+ }
+ local flag = maps[language_ieee]
+ if flag then
+ table.insert(argv, flag)
+ else
+ assert("unknown language(%s) for iverilog!", language_ieee)
+ end
+ else
+ local extension = path.extension(sourcefiles[1])
+ if extension == ".vhd" then
+ table.insert(argv, "-g2012")
+ end
end
+
+ -- get defines
+ local defines = target:get("defines")
+ if defines then
+ for _, define in ipairs(defines) do
+ table.insert(argv, "-D" .. define)
+ end
+ end
+
+ -- get includedirs
+ local includedirs = target:get("includedirs")
+ if includedirs then
+ for _, includedir in ipairs(includedirs) do
+ table.insert(argv, path(includedir, function (v) return "-I" .. v end))
+ end
+ end
+
+ -- get flags
+ local flags = target:values("iverilog.flags")
+ if flags then
+ table.join2(argv, flags)
+ end
+
+ -- do build
table.join2(argv, sourcefiles)
batchcmds:show_progress(opt.progress, "${color.build.target}linking.iverilog %s", path.filename(targetfile))
batchcmds:mkdir(targetdir)