systemc-clang
2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
plugins
hdl
parselib
transforms
comma_transformation.py
Go to the documentation of this file.
1
from
lark
import
Tree, Token
2
from
parselib.utils
import
dprint
3
from
parselib.transforms
import
TopDown
4
from
..utils
import
dprint, is_tree_types
5
6
7
class
CommaTransformation
(
TopDown
):
8
"""
9
The comma transformation is aimed to handle the case such as
10
k = (i++, j++)
11
in the code.
12
This type of operator is not supported in Verilog and thus we need to break
13
the code into sequence of code such as:
14
i++
15
k = j++
16
Note: k = j++ will be handled by another pass that gets j and j++ correctly
17
To handle this, we break a hBinop , [ lhs rhs ] node into two.
18
lhs will be appended to the parent and rhs remains
19
"""
20
def
__init__
(self):
21
super().
__init__
()
22
self.
broken_down_ops
= []
# stores the operations broken down by ,
23
self.
has_comma
=
False
24
self.
lifted
= set()
25
self.
nesting_assign
=
False
26
27
def
hcomma
(self, tree):
28
self.
__push_up
(tree)
29
self.
has_comma
=
True
30
lhs, rhs = tree.children
31
self.
broken_down_ops
.append(lhs)
32
return
rhs
33
34
def
blkassign
(self, tree):
35
if
self.
nesting_assign
:
36
self.
__push_up
(tree)
37
lhs, rhs = tree.children
38
self.
broken_down_ops
.append(tree)
39
return
lhs
40
else
:
41
self.
nesting_assign
=
True
42
self.
__push_up
(tree)
43
return
tree
44
45
def
hbinop
(self, tree):
46
op = tree.children[0]
47
if
op
in
[
'+='
,
'-='
,
'*='
,
'/='
]:
48
self.
nesting_assign
=
True
49
self.
__push_up
(tree)
50
op, lhs, rhs = tree.children
51
if
op
in
[
'+='
,
'-='
,
'*='
,
'/='
]:
52
self.
broken_down_ops
.append(tree)
53
return
lhs
54
else
:
55
return
tree
56
57
def
hnsbinop
(self, tree):
58
op = tree.children[0]
59
if
op
in
[
'+='
,
'-='
,
'*='
,
'/='
]:
60
self.
nesting_assign
=
True
61
self.
__push_up
(tree)
62
op, lhs, rhs = tree.children
63
if
op
in
[
'+='
,
'-='
,
'*='
,
'/='
]:
64
self.
broken_down_ops
.append(tree)
65
return
lhs
66
else
:
67
return
tree
68
69
def
stmts
(self, tree):
70
# TODO: this only covers a small case, and does not support for cases like
71
# for(...) a += b++;
72
new_children = []
73
for
ch
in
tree.children:
74
self.
broken_down_ops
= []
75
self.
nesting_assign
=
False
76
if
isinstance(ch, Tree)
and
is_tree_types(ch, [
"hbinop"
,
"hnsbinop"
,
"blkassign"
]):
77
ch_new = self.visit(ch)
78
new_children.extend(map(
lambda
x: Tree(
'stmt'
, [x]), self.
broken_down_ops
))
79
new_children.append(ch_new)
80
else
:
81
self.
__push_up
(ch)
82
new_children.append(ch)
83
tree.children = new_children
84
return
tree
parselib.transforms.comma_transformation.CommaTransformation
Definition
comma_transformation.py:7
parselib.transforms.comma_transformation.CommaTransformation.hbinop
hbinop(self, tree)
Definition
comma_transformation.py:45
parselib.transforms.comma_transformation.CommaTransformation.stmts
stmts(self, tree)
Definition
comma_transformation.py:69
parselib.transforms.comma_transformation.CommaTransformation.broken_down_ops
list broken_down_ops
Definition
comma_transformation.py:22
parselib.transforms.comma_transformation.CommaTransformation.hnsbinop
hnsbinop(self, tree)
Definition
comma_transformation.py:57
parselib.transforms.comma_transformation.CommaTransformation.__init__
__init__(self)
Definition
comma_transformation.py:20
parselib.transforms.comma_transformation.CommaTransformation.blkassign
blkassign(self, tree)
Definition
comma_transformation.py:34
parselib.transforms.comma_transformation.CommaTransformation.nesting_assign
bool nesting_assign
Definition
comma_transformation.py:25
parselib.transforms.comma_transformation.CommaTransformation.lifted
lifted
Definition
comma_transformation.py:24
parselib.transforms.comma_transformation.CommaTransformation.has_comma
bool has_comma
Definition
comma_transformation.py:23
parselib.transforms.comma_transformation.CommaTransformation.hcomma
hcomma(self, tree)
Definition
comma_transformation.py:27
parselib.transforms.top_down.TopDown
Definition
top_down.py:24
parselib.transforms.top_down.TopDown.__push_up
__push_up(self, current_node)
Definition
top_down.py:29
parselib.transforms
Definition
__init__.py:1
parselib.utils
Definition
utils.py:1
Generated by
1.12.0