Skip to content

Commit bfb69a1

Browse files
authored
Merge pull request #520 from diffblue/vcd1
VCD output: scoped reference names
2 parents 8dbbd22 + 1375b76 commit bfb69a1

File tree

4 files changed

+104
-17
lines changed

4 files changed

+104
-17
lines changed

regression/ebmc/traces/vcd1.desc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CORE
2+
vcd1.v
3+
--random-trace --trace-steps 1 --vcd -
4+
^\$date$
5+
^\$timescale$
6+
^ 1ns$
7+
^\$scope module main \$end$
8+
^ \$var wire 32 main\.some_input some_input \[31:0\] \$end$
9+
^ \$var wire 32 main\.x x \[31:0\] \$end$
10+
^ \$scope module sub \$end$
11+
^ \$var wire 32 main\.sub\.x x \[31:0\] \$end$
12+
^ \$upscope \$end$
13+
^\$upscope \$end$
14+
^\$enddefinitions \$end$
15+
^#0$
16+
^b\d+ main\.some_input$
17+
^b\d+ main\.x$
18+
^b00000000000000000000000001111011 main\.sub\.x$
19+
^#1$
20+
^b\d+ main\.some_input$
21+
^b\d+ main\.x$
22+
^EXIT=0$
23+
^SIGNAL=0$
24+
--
25+
^warning: ignoring

regression/ebmc/traces/vcd1.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module main(input [31:0] some_input);
2+
3+
wire [31:0] x = 456 + some_input;
4+
5+
sub sub();
6+
7+
endmodule
8+
9+
module sub;
10+
11+
wire [31:0] x = 123;
12+
13+
endmodule

src/ebmc/random_traces.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Author: Daniel Kroening, [email protected]
2727
#include "waveform.h"
2828

2929
#include <algorithm>
30+
#include <iostream>
3031
#include <random>
3132

3233
/*******************************************************************\
@@ -159,6 +160,9 @@ int random_traces(const cmdlinet &cmdline, message_handlert &message_handler)
159160
return 10; // default
160161
}();
161162

163+
if(cmdline.isset("vcd") && cmdline.get_value("vcd") == "-")
164+
throw ebmc_errort() << "no stdout output for multiple VCDs";
165+
162166
const auto outfile_prefix = [&cmdline]() -> std::optional<std::string> {
163167
if(cmdline.isset("vcd"))
164168
return cmdline.get_value("vcd") + ".";
@@ -285,6 +289,27 @@ int random_trace(const cmdlinet &cmdline, message_handlert &message_handler)
285289
messaget message(message_handler);
286290
show_trans_trace_numbered(trace, message, ns, consolet::out());
287291
}
292+
else if(cmdline.isset("vcd"))
293+
{
294+
auto filename = cmdline.get_value("vcd");
295+
messaget message(message_handler);
296+
297+
if(filename == "-")
298+
{
299+
show_trans_trace_vcd(trace, message, ns, std::cout);
300+
}
301+
else
302+
{
303+
std::ofstream out(widen_if_needed(filename));
304+
305+
if(!out)
306+
throw ebmc_errort() << "failed to write trace to " << filename;
307+
308+
consolet::out() << "*** Writing " << filename << '\n';
309+
310+
show_trans_trace_vcd(trace, message, ns, out);
311+
}
312+
}
288313
else // default
289314
{
290315
messaget message(message_handler);

src/trans-netlist/trans_trace.cpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,29 @@ std::string vcd_identifier(const std::string &id)
522522
result.erase(0, 9);
523523
else if(has_prefix(result, "smv::"))
524524
result.erase(0, 5);
525-
525+
526+
return result;
527+
}
528+
529+
/*******************************************************************\
530+
531+
Function: vcd_reference
532+
533+
Inputs:
534+
535+
Outputs:
536+
537+
Purpose:
538+
539+
\*******************************************************************/
540+
541+
std::string vcd_reference(const symbolt &symbol, const std::string &prefix)
542+
{
543+
std::string result = id2string(symbol.name);
544+
545+
if(!prefix.empty() && has_prefix(result, prefix))
546+
result.erase(0, prefix.size());
547+
526548
return result;
527549
}
528550

@@ -723,13 +745,10 @@ void vcd_hierarchy_rec(
723745
std::string suffix=vcd_suffix(symbol.type, ns);
724746

725747
if(width>=1)
726-
out << std::string(depth*2, ' ')
727-
<< "$var " << signal_class << " "
728-
<< width << " "
729-
<< vcd_identifier(display_name) << " "
730-
<< vcd_identifier(display_name)
731-
<< (suffix==""?"":" ") << suffix
732-
<< " $end" << '\n';
748+
out << std::string(depth * 2, ' ') << "$var " << signal_class << " "
749+
<< width << " " << vcd_identifier(display_name) << " "
750+
<< vcd_reference(symbol, prefix) << (suffix == "" ? "" : " ")
751+
<< suffix << " $end" << '\n';
733752
}
734753

735754
// now do sub modules
@@ -777,12 +796,6 @@ void show_trans_trace_vcd(
777796

778797
assert(!state.assignments.empty());
779798

780-
const symbolt &symbol1=ns.lookup(
781-
state.assignments.front().lhs.get(ID_identifier));
782-
783-
std::string module_name=id2string(symbol1.module);
784-
out << "$scope module " << vcd_identifier(module_name) << " $end\n";
785-
786799
// get identifiers
787800
std::set<irep_idt> ids;
788801

@@ -791,10 +804,21 @@ void show_trans_trace_vcd(
791804
assert(a.lhs.id()==ID_symbol);
792805
ids.insert(to_symbol_expr(a.lhs).get_identifier());
793806
}
794-
807+
808+
// determine module
809+
810+
const symbolt &symbol1 =
811+
ns.lookup(state.assignments.front().lhs.get(ID_identifier));
812+
813+
auto &module_symbol = ns.lookup(symbol1.module);
814+
815+
// print those in the top module
816+
817+
out << "$scope module " << module_symbol.display_name() << " $end\n";
818+
795819
// split up into hierarchy
796-
vcd_hierarchy_rec(ns, ids, module_name+".", out, 1);
797-
820+
vcd_hierarchy_rec(ns, ids, id2string(module_symbol.name) + ".", out, 1);
821+
798822
out << "$upscope $end\n";
799823

800824
out << "$enddefinitions $end\n";

0 commit comments

Comments
 (0)