-
Notifications
You must be signed in to change notification settings - Fork 0
/
gensyms.pl
executable file
·93 lines (80 loc) · 2.01 KB
/
gensyms.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl -w
use strict;
if (@ARGV != 3) {
die "usage: gensyms.pl <modelname> <src-h> <dst-h>\n";
}
my ($model, $srcname, $dstname) = @ARGV;
open (my $src, '<', $srcname)
or die "failed to open $srcname";
open (my $dst, '>', $dstname)
or die "failed to open $dstname";
# QData/*34:0*/ conan__DOT__u_command__DOT__rcv_param;
# QData/*63:0*/ conan__DOT__u_led7219__DOT__dout;
# CData/*7:0*/ conan__DOT__u_framing__DOT__recv_ring[256];
while (<$src>) {
last if (/^\s+\/\/ LOCAL SIGNALS$/);
}
my @signals;
while (<$src>) {
last if (/^\s+\/\/ LOCAL VARIABLES$/);
next if (/^\s*$/);
next if (/^\s*\/\//);
next if (/^\s*};/);
next if (/^\s*struct \{/);
if (!/^\s+([CIQSW])Data\/\*(\d+):(\d+)\*\/ (\w+)(\[\d+\])?(\[\d+\])?;$/) {
die "failed to parse $_";
}
my $type = $1;
my $range_start = $2;
my $range_end = $3;
my $name_raw = $4;
my $num1 = $5 // 1;
my $num2 = $6 // 1;
$num1 =~ s/[\[\]]//g;
$num2 =~ s/[\[\]]//g;
my $num = $num1 * $num2;
my $name_cooked = $name_raw;
$name_cooked =~ s/__DOT__/./g;
$name_cooked =~ s/__BRA__(\d+)__KET__/[$1]/g;
# first component is always the same, strip for convenience
$name_cooked =~ s/^$model\.//;
$type = "sig" . $type;
push @signals, {
type => $type,
range_start => $range_start,
range_end => $range_end,
name_raw => $name_raw,
name_cooked => $name_cooked,
num => $num,
};
}
print $dst <<"HERE";
#ifndef __VSYMS__H__
#define __VSYMS__H__
#include <verilated.h>
typedef enum _sigtype {
sigC,
sigI,
sigQ,
sigS,
sigW
} sigtype_t;
typedef struct _signal {
const char *name; /* cooked name */
sigtype_t type;
int range_start; /* bitfield range */
int range_end;
int num; /* number of entries in array */
int offset; /* offset of signal in structure */
} signal_t;
signal_t vsigs[] = {
HERE
for (@signals) {
print $dst "\t{ \"$_->{name_cooked}\", $_->{type}, $_->{range_start}, ";
print $dst "$_->{range_end}, $_->{num}, offsetof(V$model, $_->{name_raw}) },\n";
}
print $dst <<"HERE";
};
#define NSIGS (sizeof(vsigs) / sizeof(signal_t))
#endif
HERE