diff options
| author | ruki <[email protected]> | 2023-01-14 00:36:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-01-14 00:36:18 +0800 |
| commit | 75b97c2509fd3d8eeec884c01c3eb6fc3635459a (patch) | |
| tree | 9bd327815a9217673fb1e2d08a4ced70c3822212 | |
| parent | af36e0b08cf70100ae8cd15ff7dc4f33066d9ff5 (diff) | |
add verilator toolchains
| -rw-r--r-- | tests/projects/embed/verilator/hello/src/main.v | 8 | ||||
| -rw-r--r-- | tests/projects/embed/verilator/hello/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_verilator.lua | 50 | ||||
| -rw-r--r-- | xmake/rules/verilator/xmake.lua | 29 | ||||
| -rw-r--r-- | xmake/toolchains/verilator/xmake.lua | 46 |
5 files changed, 138 insertions, 0 deletions
diff --git a/tests/projects/embed/verilator/hello/src/main.v b/tests/projects/embed/verilator/hello/src/main.v new file mode 100644 index 000000000..9661c433e --- /dev/null +++ b/tests/projects/embed/verilator/hello/src/main.v @@ -0,0 +1,8 @@ +module hello; + initial begin + $display("hello world!"); + $dumpfile("hello.vcd"); + $dumpvars(0, hello); + $finish ; + end +endmodule diff --git a/tests/projects/embed/verilator/hello/xmake.lua b/tests/projects/embed/verilator/hello/xmake.lua new file mode 100644 index 000000000..b472abb37 --- /dev/null +++ b/tests/projects/embed/verilator/hello/xmake.lua @@ -0,0 +1,5 @@ +add_requires("verilator") +target("hello") + add_rules("verilator.binary") + set_toolchains("@verilator") + add_files("src/*.v") diff --git a/xmake/modules/detect/tools/find_verilator.lua b/xmake/modules/detect/tools/find_verilator.lua new file mode 100644 index 000000000..3c3b57180 --- /dev/null +++ b/xmake/modules/detect/tools/find_verilator.lua @@ -0,0 +1,50 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_verilator.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find verilator +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local verilator = find_verilator() +-- +-- @endcode +-- +function main(opt) + + -- find program + opt = opt or {} + local program = find_program(opt.program or "verilator", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + return program, version +end + diff --git a/xmake/rules/verilator/xmake.lua b/xmake/rules/verilator/xmake.lua new file mode 100644 index 000000000..d2d8b9d5d --- /dev/null +++ b/xmake/rules/verilator/xmake.lua @@ -0,0 +1,29 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +rule("verilator.binary") + set_extensions(".v") + on_load(function (target) + target:set("kind", "binary") + end) + + on_buildcmd_files(function(target, batchcmds, sourcebatch, opt) + end) + diff --git a/xmake/toolchains/verilator/xmake.lua b/xmake/toolchains/verilator/xmake.lua new file mode 100644 index 000000000..2419b1f34 --- /dev/null +++ b/xmake/toolchains/verilator/xmake.lua @@ -0,0 +1,46 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +toolchain("verilator") + set_homepage("https://verilator.org/") + set_description("Verilator open-source SystemVerilog simulator and lint system") + + set_kind("standalone") + + on_check(function (toolchain) + import("lib.detect.find_tool") + local paths = {} + for _, package in ipairs(toolchain:packages()) do + local envs = package:get("envs") + if envs then + table.join2(paths, envs.PATH) + end + end + local verilator = find_tool("verilator", {paths = paths}) + if verilator and verilator.program then + toolchain:config_set("verilator", verilator.program) + cprint("${dim}checking for verilator ... ${color.success}%s", path.filename(verilator.program)) + else + cprint("${dim}checking for verilator ... ${color.nothing}${text.nothing}") + raise("verilator not found!") + end + toolchain:configs_save() + return true + end) |
