Skip to content

Commit 43bff6c

Browse files
committed
add PERL section to config file, standardize filters
1 parent add90e8 commit 43bff6c

File tree

4 files changed

+161
-49
lines changed

4 files changed

+161
-49
lines changed

verilogpp

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,11 +1222,11 @@ sub generate_output_decode_for_state($$$) {
12221222
}
12231223
# now override with more blocking assignments for each conditional:
12241224
# Conditions are strictly ordered as if-else chains.
1225-
my $else_if = "if"; # First condition gets "if", rest get "else if"
1225+
my $else_if = "if"; # First condition gets "if", rest get "elsif"
12261226
foreach my $condition (@{$decode->{$k_condition_list}}) {
12271227
next if ($condition eq "all");
12281228
print "${indent}${else_if} (${condition}) begin\n";
1229-
$else_if = "else if";
1229+
$else_if = "elsif";
12301230
foreach my $var (sort keys %{$decode->{$condition}}) {
12311231
print "${indent} ${var} = " . $decode->{$condition}->{$var} . ";\n";
12321232
}
@@ -1878,7 +1878,7 @@ sub keep_track_of_used_net {
18781878
}
18791879
}
18801880
while ($normalized_net =~ s/\s*(\[ [^\]]* \])\s*//x) {
1881-
main::log_info("${normalized_net}: removed slice: ${1}");
1881+
main::log_debug("${normalized_net}: removed slice: ${1}");
18821882
}
18831883
if (!defined($self->{NETS}->{$normalized_net})) {
18841884
# This is the first time we've encountered this
@@ -1936,6 +1936,54 @@ sub extract_iterables($) {
19361936
return $text, \@items;
19371937
}
19381938

1939+
sub extract_filters($) {
1940+
my $macro = shift;
1941+
my @pos_filters = ();
1942+
my @neg_filters = ();
1943+
my @macro_lines = split(/\s*[\r\n]\s*/, $macro);
1944+
foreach my $line (@macro_lines) {
1945+
$line =~ s/^\s+//;
1946+
$line =~ s/\s+$//;
1947+
if ($line =~ m/^\s*$/) {
1948+
next;
1949+
} elsif ($line =~ m/^!(.*)/) {
1950+
push(@neg_filters, $1);
1951+
} else {
1952+
push(@pos_filters, $line);
1953+
}
1954+
}
1955+
return (\@pos_filters, \@neg_filters);
1956+
}
1957+
1958+
sub apply_filters($@) {
1959+
my $text = shift;
1960+
my $pos_filters_ref = shift;
1961+
my $neg_filters_ref = shift;
1962+
1963+
my $matched = 1;
1964+
if ($#$pos_filters_ref > -1) {
1965+
$matched = 0;
1966+
$_ = $text;
1967+
foreach my $filt (@$pos_filters_ref) {
1968+
my $result = eval($filt);
1969+
if ($result) {
1970+
$matched = 1;
1971+
last;
1972+
}
1973+
}
1974+
}
1975+
if ($#$neg_filters_ref > -1) {
1976+
foreach my $filt (@$neg_filters_ref) {
1977+
my $result = eval($filt);
1978+
if ($result) {
1979+
$matched = 0;
1980+
last;
1981+
}
1982+
}
1983+
}
1984+
return $matched;
1985+
}
1986+
19391987
$MacroHelp{'FORINST'} = <<EOT ;
19401988
FORINST is a iterated version of the INST macro.
19411989
@@ -2577,15 +2625,7 @@ sub expand_autointerface($$) {
25772625
$sort_autoif = 1;
25782626
}
25792627

2580-
my @filters = ();
2581-
my @macro_lines = split(/\s*[\r\n]\s*/, $macro);
2582-
foreach my $line (@macro_lines) {
2583-
$line =~ s/^\s+//;
2584-
$line =~ s/\s+$//;
2585-
if ($line =~ m/^m/) {
2586-
push(@filters, $line);
2587-
}
2588-
}
2628+
my @filters = extract_filters($macro);
25892629

25902630
# parse the input and output ports of this module
25912631
my $my_interface = new ModuleSpec()->parse_prototype($self->{text});
@@ -2603,21 +2643,8 @@ sub expand_autointerface($$) {
26032643
next unless ($s =~ m/[[:alpha:]]/); # Must have a letter
26042644
next if ($s =~ m/\W/); # Must only contain "word" characters.
26052645

2606-
# If we have filters enabled, skip signals that don't match filters.
2607-
if ($#filters > -1) {
2608-
my $matched = 0;
2609-
$_ = $s;
2610-
foreach my $filt (@filters) {
2611-
my $result = eval($filt);
2612-
if ($result) {
2613-
$matched = 1;
2614-
last;
2615-
}
2616-
}
2617-
if (!$matched) {
2618-
next;
2619-
}
2620-
}
2646+
my $match = apply_filters($s, @filters);
2647+
if (!$match) { next; }
26212648

26222649
# examine each net:
26232650
my $ref = $self->{NETS}->{$s};
@@ -2776,15 +2803,7 @@ sub expand_autonet($$) {
27762803
$style = $2;
27772804
}
27782805

2779-
my @filters = ();
2780-
my @macro_lines = split(/\s*[\r\n]\s*/, $macro);
2781-
foreach my $line (@macro_lines) {
2782-
$line =~ s/^\s+//;
2783-
$line =~ s/\s+$//;
2784-
if ($line =~ m/^m/) {
2785-
push(@filters, $line);
2786-
}
2787-
}
2806+
my @filters = extract_filters($macro);
27882807

27892808
# parse the input and output ports of this module
27902809
my $my_interface = new ModuleSpec()->parse_prototype($self->{text});
@@ -2797,18 +2816,11 @@ sub expand_autonet($$) {
27972816
my $cb_signals = new SignalSet();
27982817

27992818
foreach my $s (@sigs) {
2800-
if ($#filters > -1) {
2801-
my $matched = 0;
2802-
$_ = $s;
2803-
foreach my $filt (@filters) {
2804-
my $result = eval($filt);
2805-
if ($result) { $matched = 1; }
2806-
}
2807-
2808-
if (!$matched) {
2809-
next;
2810-
}
2819+
my $match = apply_filters($s, @filters);
2820+
if (!$match) {
2821+
next;
28112822
}
2823+
28122824
# if signal is in this module's interface, autonet should
28132825
# skip it:
28142826
if ($my_interface->HasPort($s)) {
@@ -3054,7 +3066,7 @@ Currently, only one attribute is supported:
30543066
* "SUBPATH=<path>"
30553067
30563068
This attribute can be supplied multiple times, to specific multiple subpaths.
3057-
This subpath specifies an additional path component to be searched for files
3069+
This subpath specifies an additional path component to be searched for file !m/^(dft_clk_en|dft_rst_n_bypass_in|dft_rst_n_bypass_en)/
30583070
referred to by INST and FORINST macros. The search is performed by iterating
30593071
through each INCDIR path, and then looking for the file in each SUBPATH
30603072
beneath each INCDIR path.
@@ -3672,6 +3684,18 @@ EOT
36723684
sub parse_config($) {
36733685
my $configtext = shift;
36743686

3687+
my @data = split m/^\s*PERL:\s*$/mso, $configtext;
3688+
my $perlcode = "";
3689+
if ($#data > 0) {
3690+
$configtext = $data[0];
3691+
my $perlcode = $data[1];
3692+
eval($perlcode);
3693+
if ($@) {
3694+
print "PERL ERROR:\n$@\n";
3695+
print STDERR "PERL ERROR in config file:\n$@\n\n$perlcode\n";
3696+
}
3697+
}
3698+
36753699
# remove comments
36763700
$configtext =~ s/(?<!\\)#.*\n/\n/g; # but not \#
36773701
$configtext =~ s/\\#/#/g; # turn \# into #
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// inst_of_unpacked instantiates an unpacked from unpacked.v
2+
3+
module autonet_genvar (
4+
input wire clk,
5+
input wire reset_n );
6+
7+
axi4_if axi(.clk, .reset_n);
8+
9+
/**AUTONET --init --skipif **/
10+
/*PPSTART*/
11+
my_fancy_t[6-1:0][1:0] fwd_data;
12+
wire [6-1:0] fwd_ready;
13+
wire [6-1:0] fwd_valid;
14+
my_fancy_t[1:0] rev_data;
15+
reg rev_ready = '0;
16+
wire rev_valid;
17+
reg rst_n = '{default: '0};
18+
/*PPSTOP*/
19+
20+
/**INST typed_module.v typed_mod1 --style=v2 --indent_like_macro
21+
parameter TYPE_T my_fancy_t[1:0]
22+
s/rev_(\S+)/fwd_${1}[1]/;
23+
**/
24+
/*PPSTART*/
25+
typed_moduled #(
26+
.TYPE_T(my_fancy_t[1:0])
27+
) typed_mod1 (
28+
.clk, // input
29+
.rst_n, // input
30+
.fwd_data, // input
31+
.fwd_valid, // input
32+
.fwd_ready, // output
33+
.rev_data (fwd_data[1]), // output
34+
.rev_valid (fwd_valid[1]), // output
35+
.rev_ready (fwd_ready[1]) // input
36+
);
37+
/*PPSTOP*/
38+
39+
40+
/**INST typed_module.v typed_mod0 --style=v2 --indent_like_macro
41+
parameter TYPE_T my_fancy_t[1:0]
42+
s/rev_(\S+)/fwd_${1}[0]/;
43+
**/
44+
/*PPSTART*/
45+
typed_moduled #(
46+
.TYPE_T(my_fancy_t[1:0])
47+
) typed_mod0 (
48+
.clk, // input
49+
.rst_n, // input
50+
.fwd_data, // input
51+
.fwd_valid, // input
52+
.fwd_ready, // output
53+
.rev_data (fwd_data[0]), // output
54+
.rev_valid (fwd_valid[0]), // output
55+
.rev_ready (fwd_ready[0]) // input
56+
);
57+
/*PPSTOP*/
58+
59+
for (array_dims ii = 0; ii < 6; ii++) begin : gen_instances
60+
/**INST typed_module.v typed_module --style=v2 --indent_like_macro
61+
parameter TYPE_T my_fancy_t[1:0]
62+
array_dims ii 6-1:0
63+
s/fwd_(\S+)/fwd_${1}[ii]/;
64+
**/
65+
/*PPSTART*/
66+
typed_moduled #(
67+
.TYPE_T(my_fancy_t[1:0])
68+
) typed_module (
69+
.clk, // input
70+
.rst_n, // input
71+
.fwd_data (fwd_data[ii]), // input
72+
.fwd_valid (fwd_valid[ii]), // input
73+
.fwd_ready (fwd_ready[ii]), // output
74+
.rev_data, // output
75+
.rev_valid, // output
76+
.rev_ready // input
77+
);
78+
/*PPSTOP*/
79+
end : gen_instances
80+
81+
endmodule

verilogpp_tests/autonet_filtered.vpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module autonet_filtered (
77
/**AUTONET --init --skipif
88
m/^fwd_/;
99
m/_valid$/;
10+
!m/^fwd_read/;
1011
**/
1112
/*PPSTART*/
1213
my_type_t fwd_data = '0;
13-
wire fwd_ready;
1414
reg fwd_valid = '0;
1515
wire rev_valid;
1616
/*PPSTOP*/

verilogpp_tests/verilogpp.fortest.rc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ disable_always_ff = 1
1717

1818
manifest=./preproc.manifest
1919

20+
PERL:
21+
22+
sub foo($) {
23+
my $x = shift;
24+
$x =~ s/foo/bar/;
25+
return $x;
26+
}

0 commit comments

Comments
 (0)