-
Notifications
You must be signed in to change notification settings - Fork 2
/
VCDSimulation.g
68 lines (55 loc) · 1.43 KB
/
VCDSimulation.g
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
tree grammar VCDSimulation;
options {
language=Python;
tokenVocab=ValueChangeDump;
ASTLabelType=CommonTree;
}
@init {
self.vars={};
self.empty=[];
}
vcd_header returns [result]: ^(HEADER decl_command_list[stack=self.empty])
{$result=self.vars}
;
decl_command_list [stack]
: ^(DECLS decl_command[stack=stack]+)
;
decl_command [stack]
: ^(TIMESCALE DEC_NUM TIME_UNIT)
| ^(NEWVAR type=. size=DEC_NUM id_code=IDENTIFIER ref=IDENTIFIER)
{
myvar={'code':$id_code.text,'ref':$ref.text,'scope':$stack};
self.vars[$id_code.text]=myvar;
}
| vcd_scope[stack=stack]
;
vcd_decl_timescale
: ^(TIMESCALE DEC_NUM TIME_UNIT)
;
vcd_scope [stack]
: ^(NEWSCOPE vcd_decl_scope decl_command_list[stack=stack+list(($vcd_decl_scope.label,))])
;
vcd_decl_scope returns [label]
: ^(DECLSCOPE type=. IDENTIFIER)
{$label=$IDENTIFIER.text}
;
simulation_command [context]
: ^(SIM_COMMAND sim_time [context])
| ^(SIM_COMMAND value_change [context])
;
sim_time [context]
: ^(TIME DEC_NUM)
{
context.note_time(int($DEC_NUM.text))
}
;
value_change [context]
: ^(SCALAR_CHANGE id=IDENTIFIER v=SCALAR_VALUE)
{
context.scalar_change($id.text, $v.text)
}
| ^(VECTOR_CHANGE id=IDENTIFIER BINVEC)
{
context.vector_change($id.text, $BINVEC.text)
}
;