Skip to content

Commit

Permalink
Add Intel ROHD vcd support
Browse files Browse the repository at this point in the history
  • Loading branch information
yne committed Mar 27, 2022
1 parent adf0558 commit f2b1627
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 8 deletions.
138 changes: 138 additions & 0 deletions samples/rohd.vcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
$date
2022-03-12T16:14:46.339792
$end
$version
ROHD v0.2.0
$end
$comment
Generated by ROHD - www.github.com/intel/rohd
$end
$timescale 1ps $end
$scope module counter $end
$var wire 1 s0 en $end
$var wire 1 s1 reset $end
$var wire 1 s2 clk $end
$var wire 8 s3 val $end
$var wire 8 s4 s0 $end
$var wire 8 s5 nextVal $end
$scope module sequential $end
$var wire 1 s6 _in0_reset $end
$var wire 8 s7 _in1_s0 $end
$var wire 1 s8 _in2_en $end
$var wire 8 s9 _in3_nextVal $end
$var wire 1 s10 _clk0_clk $end
$var wire 8 s11 _out4_val $end
$upscope $end
$upscope $end
$enddefinitions $end
$dumpvars
zs0
zs1
0s2
bzzzzzzzz s3
b00000000 s4
bxxxxxxxx s5
zs6
b00000000 s7
zs8
bxxxxxxxx s9
0s10
bzzzzzzzz s11
$end
#0
0s0
1s1
1s6
0s8
#5
1s2
b00000000 s3
b00000001 s5
b00000001 s9
1s10
b00000000 s11
#10
0s2
0s10
#15
1s2
1s10
#20
0s2
0s10
#25
0s1
1s2
0s6
1s10
#30
0s2
0s10
#35
1s2
1s10
#40
0s2
0s10
#45
1s0
1s2
b00000001 s3
b00000010 s5
1s8
b00000010 s9
1s10
b00000001 s11
#50
0s2
0s10
#55
1s2
b00000010 s3
b00000011 s5
b00000011 s9
1s10
b00000010 s11
#60
0s2
0s10
#65
1s2
b00000011 s3
b00000100 s5
b00000100 s9
1s10
b00000011 s11
#70
0s2
0s10
#75
1s2
b00000100 s3
b00000101 s5
b00000101 s9
1s10
b00000100 s11
#80
0s2
0s10
#85
1s2
b00000101 s3
b00000110 s5
b00000110 s9
1s10
b00000101 s11
#90
0s2
0s10
#95
1s2
b00000110 s3
b00000111 s5
b00000111 s9
1s10
b00000110 s11
#100
0s2
0s10
23 changes: 15 additions & 8 deletions vcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>

#define USAGE "USAGE: vcd < in.vcd > out.ascii :\n"
#define PROLOG "Fatal error. Send your VCD at https://github.com/yne/vcd/issue"
#define PROLOG "Fatal error. Send the VCD on https://github.com/yne/vcd/issues"
#define REBUILD(D) #D " reached (" VAL(D) "), rebuild with -D" #D "=...\n"
#define die(...) exit(fprintf(stderr, PROLOG "\nReason: " __VA_ARGS__))

Expand Down Expand Up @@ -46,19 +46,23 @@ typedef struct {
typedef struct {
Channel ch[MAX_CHANNEL]; // [0] = timestamps
Token scopes[MAX_SCOPE]; // [0] = default
unsigned total, scope_count;
unsigned total, scope_count, chan_str;
float scale; // duration of each sample
Token date, version, unit; // file info
// parsing related values
unsigned scope_cur;
unsigned scope_lim, ch_lim, sz_lim;
} ParseCtx;

/* convert a base-94 chan id (!...~) to it integer equivalent (0...93) */
size_t chanId(char* str_id) {
/* convert a base-94 or 'c'+num chan id (!...~) to integer */
size_t chanId(char* str_id, unsigned isStr) {
size_t id = 0;
for (size_t i = strlen(str_id); i >= 1; i--) {
id = (id * 94) + str_id[i - 1] - '!';
if (isStr) {
id = atoi(str_id + 1);
} else {
for (size_t i = strlen(str_id); i >= 1; i--) {
id = (id * 94) + str_id[i - 1] - '!';
}
}
if (id > MAX_CHANNEL) die(REBUILD(MAX_CHANNEL));
return id;
Expand All @@ -80,7 +84,7 @@ void parseVcdInstruction(ParseCtx* p) {
scanf(" %*s %d %" TXT(SFL) "[^ ] %" TXT(SFL) "[^$]", &c.size, id, c.name);
p->ch_lim = MAX(p->ch_lim, strlen(c.name));
p->sz_lim = MAX(p->sz_lim, c.size);
p->ch[chanId(id)] = c;
p->ch[chanId(id, p->chan_str)] = c;
} else if (!strcmp("scope", token)) {
p->scope_count++;
if (p->scope_count == MAX_SCOPE) die(REBUILD(MAX_SCOPE));
Expand All @@ -91,6 +95,8 @@ void parseVcdInstruction(ParseCtx* p) {
scanf("\n%" TXT(SFL) "[^$\n]", p->date);
} else if (!strcmp("version", token)) {
scanf("\n%" TXT(SFL) "[^$\n]", p->version);
// ROHD use 's'+digit channel ID sequencing
p->chan_str = strstr(p->version, "ROHD") != NULL;
} else if (!strcmp("timescale", token)) {
scanf("\n%f%" TXT(SFL) "[^$\n]", &p->scale, p->unit);
} else if (!strcmp("comment", token)) {
Expand Down Expand Up @@ -145,7 +151,8 @@ void parseVcdSample(ParseCtx* p, int c) {
}
Token id_str;
scanf("%" TXT(SFL) "[^ \n]", id_str);
p->ch[chanId(id_str)].samples[p->total - 1] = s;
if (!p->total) return; // ROHD define value BEFORE timestamp #0
p->ch[chanId(id_str, p->chan_str)].samples[p->total - 1] = s;
}

void parseVcd(ParseCtx* p) {
Expand Down

0 comments on commit f2b1627

Please sign in to comment.