Skip to content

Commit eb4f82d

Browse files
committed
verilator: Generate SystemC
1 parent 31c4a16 commit eb4f82d

File tree

7 files changed

+108
-3
lines changed

7 files changed

+108
-3
lines changed

dependency_support/dependency_support.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ load("//dependency_support/org_theopenroadproject_asap7sc6t_26:org_theopenroadpr
6161
load("//dependency_support/org_theopenroadproject_asap7sc7p5t_27:org_theopenroadproject_asap7sc7p5t_27.bzl", "org_theopenroadproject_asap7sc7p5t_27")
6262
load("//dependency_support/org_theopenroadproject_asap7sc7p5t_28:org_theopenroadproject_asap7sc7p5t_28.bzl", "org_theopenroadproject_asap7sc7p5t_28")
6363
load("//dependency_support/rules_license:rules_license.bzl", "rules_license")
64+
load("//dependency_support/systemc:systemc.bzl", "systemc")
6465
load("//dependency_support/tk_tcl:tk_tcl.bzl", "tk_tcl")
6566
load("//dependency_support/verilator:verilator.bzl", "verilator")
6667

@@ -114,6 +115,7 @@ def dependency_support(register_toolchains = True):
114115
org_theopenroadproject_asap7sc7p5t_27()
115116
org_theopenroadproject_asap7sc7p5t_28()
116117
rules_license()
118+
systemc()
117119
tk_tcl()
118120
verilator()
119121

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2025 bazel_rules_hdl Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(
16+
default_applicable_licenses = ["//:package_license"],
17+
default_visibility = ["//visibility:private"],
18+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cc_library(
2+
name = "systemc",
3+
srcs = glob(
4+
["src/**/*.cpp"],
5+
exclude = ["src/sysc/packages/qt/**"],
6+
) +
7+
[
8+
"src/sysc/packages/qt/qt.c",
9+
"src/sysc/packages/qt/md/iX86_64.s",
10+
],
11+
hdrs = glob([
12+
"src/**/*.h",
13+
"src/systemc",
14+
"src/tlm",
15+
]),
16+
cxxopts = ["-std=c++23"],
17+
strip_include_prefix = "src",
18+
local_defines = [
19+
"SC_BUILD",
20+
"SC_INCLUDE_FX",
21+
],
22+
visibility = ["//visibility:public"],
23+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Loads the SystemC library."""
16+
17+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
19+
20+
def systemc():
21+
maybe(
22+
http_archive,
23+
name = "systemc",
24+
urls = [
25+
"https://github.com/accellera-official/systemc/archive/refs/tags/3.0.1.tar.gz",
26+
],
27+
strip_prefix = "systemc-3.0.1",
28+
sha256 = "d07765d0d2ffd6c01767880d0c6aaf53cd9487975f898c593ffffd713258fcbb",
29+
build_file = Label("//dependency_support:systemc/systemc.BUILD.bazel"),
30+
)

dependency_support/verilator/verilator.BUILD.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,24 @@ cc_library(
280280
strip_include_prefix = "include/vltstd",
281281
)
282282

283+
cc_library(
284+
name = "systemc",
285+
hdrs = [
286+
"include/verilated_fst_sc.cpp",
287+
"include/verilated_fst_sc.h",
288+
"include/verilated_sc.h",
289+
"include/verilated_vcd_sc.cpp",
290+
"include/verilated_vcd_sc.h",
291+
"include/verilated_sc_trace.h",
292+
],
293+
cxxopts = ["-std=c++23"],
294+
strip_include_prefix = "include",
295+
deps = [
296+
"@systemc//:systemc",
297+
],
298+
visibility = ["//visibility:public"],
299+
)
300+
283301
cc_library(
284302
name = "verilator",
285303
srcs = [
@@ -302,7 +320,6 @@ cc_library(
302320
"include/verilated_fst_c.h",
303321
"include/verilated_funcs.h",
304322
"include/verilated_intrinsics.h",
305-
"include/verilated_sc.h",
306323
"include/verilated_sym_props.h",
307324
"include/verilated_threads.h",
308325
"include/verilated_timing.h",

verilator/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ toolchain_type(
2626

2727
verilator_toolchain(
2828
name = "verilator_toolchain_impl",
29+
systemc = "@verilator//:systemc",
2930
verilator = "@verilator//:verilator_executable",
3031
deps = [
3132
"@net_zlib//:zlib",

verilator/defs.bzl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,16 @@ def _verilator_cc_library(ctx):
133133
args = ctx.actions.args()
134134
args.add(verilator_toolchain.verilator)
135135
args.add("--no-std")
136-
args.add("--cc")
137136
args.add("--Mdir", verilator_output.path)
138137
args.add("--top-module", ctx.attr.module_top)
139138
args.add("--prefix", prefix)
140139
if ctx.attr.trace:
141140
args.add("--trace")
141+
if ctx.attr.systemc:
142+
args.add("--sc")
143+
else:
144+
args.add("--cc")
145+
142146
args.add_all(all_includes, format_each = "-I%s")
143147
args.add_all(verilog_files, expand_directories = True, map_each = _only_sv)
144148
args.add_all(verilator_toolchain.extra_vopts)
@@ -186,7 +190,7 @@ def _verilator_cc_library(ctx):
186190
defines = defines,
187191
runfiles = runfiles,
188192
includes = [verilator_output_hpp.path],
189-
deps = verilator_toolchain.deps,
193+
deps = (verilator_toolchain.deps + [verilator_toolchain.systemc]) if ctx.attr.systemc else verilator_toolchain.deps,
190194
)
191195

192196
verilator_cc_library = rule(
@@ -205,6 +209,10 @@ verilator_cc_library = rule(
205209
doc = "The name of the verilog module to verilate.",
206210
mandatory = True,
207211
),
212+
"systemc": attr.bool(
213+
doc = "Generate SystemC code.",
214+
default = False,
215+
),
208216
"trace": attr.bool(
209217
doc = "Enable tracing for Verilator",
210218
default = False,
@@ -246,6 +254,7 @@ def _verilator_toolchain_impl(ctx):
246254

247255
return [platform_common.ToolchainInfo(
248256
verilator = ctx.executable.verilator,
257+
systemc = ctx.attr.systemc,
249258
deps = ctx.attr.deps,
250259
extra_vopts = ctx.attr.extra_vopts,
251260
all_files = all_files,
@@ -266,6 +275,11 @@ verilator_toolchain = rule(
266275
"extra_vopts": attr.string_list(
267276
doc = "Extra flags to pass to Verilator compile actions.",
268277
),
278+
"systemc": attr.label(
279+
doc = "SystemC dependency to link into downstream targets.",
280+
providers = [CcInfo],
281+
mandatory = True,
282+
),
269283
"verilator": attr.label(
270284
doc = "The Verilator binary.",
271285
executable = True,

0 commit comments

Comments
 (0)