systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
comma_transformation.py
Go to the documentation of this file.
1from lark import Tree, Token
2from parselib.utils import dprint
3from parselib.transforms import TopDown
4from ..utils import dprint, is_tree_types
5
6
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
__push_up(self, current_node)
Definition top_down.py:29