Skip to content

Commit

Permalink
Enable waveform tracing for VCS
Browse files Browse the repository at this point in the history
Internal-tag: [#70134]
Signed-off-by: Maciej Kurc <[email protected]>
  • Loading branch information
mkurc-ant committed Dec 20, 2024
1 parent 9d3a977 commit cf0f335
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions vcs/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Functions for VCS."""

load("//common:providers.bzl", "LogInfo")
load("//common:providers.bzl", "LogInfo", "WaveformInfo")
load("//verilog:defs.bzl", "VerilogInfo")

_RUNFILES = ["dat", "mem"]
Expand Down Expand Up @@ -63,6 +63,7 @@ def _vcs_binary(ctx):
command += " -l " + vcs_log.path
command += " -o " + vcs_out.path
command += " -top " + ctx.attr.module_top
command += " -debug_access -debug_region=cell+encrpt +v2k"

for opt in ctx.attr.opts:
command += " " + opt
Expand Down Expand Up @@ -133,12 +134,25 @@ vcs_binary = rule(
def _vcs_run(ctx):
args = []
outputs = []
result = []

# Capture log
run_log = ctx.actions.declare_file("{}.log".format(ctx.label.name))
args.extend(["-l", run_log.path])
outputs.append(run_log)

# Waveform
if ctx.attr.trace:
trace_file = ctx.actions.declare_file("{}.vcd".format(ctx.label.name))
args.extend(["-vcd", trace_file.path])
args.append("+vcs+dumpon+0+0")
args.append("+vcs+dumparrays")
outputs.append(trace_file)

result.append(WaveformInfo(
vcd_files = depset([trace_file]),
))

# Target binary args
for arg in ctx.attr.args:
args.append(arg)
Expand All @@ -156,15 +170,17 @@ def _vcs_run(ctx):
use_default_shell_env = False,
)

return [
result.extend([
DefaultInfo(
files = depset(outputs),
runfiles = ctx.runfiles(files = runfiles),
),
LogInfo(
files = [run_log],
),
]
])

return result

vcs_run = rule(
implementation = _vcs_run,
Expand All @@ -178,6 +194,10 @@ vcs_run = rule(
executable = True,
cfg = "exec",
),
"trace": attr.bool(
doc = "Enable trace output",
default = False,
),
},
provides = [
DefaultInfo,
Expand Down

0 comments on commit cf0f335

Please sign in to comment.