Skip to content

Commit f766114

Browse files
committed
add subdir for experimental dot backend [wip]
1 parent 463da3d commit f766114

File tree

4 files changed

+673
-0
lines changed

4 files changed

+673
-0
lines changed

seal5/backends/dot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""This module contains the graphical M2-ISA-R module viewer."""

seal5/backends/dot/treegen.py

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4+
#
5+
# Copyright (C) 2022
6+
# Chair of Electrical Design Automation
7+
# Technical University of Munich
8+
9+
"""Generate a ttk.Treeview representation of a M2-ISA-R model structure."""
10+
11+
# import tkinter as tk
12+
13+
from m2isar.metamodel import behav
14+
from .utils import TreeGenContext
15+
16+
# pylint: disable=unused-argument
17+
18+
19+
def operation(self: behav.Operation, context: "TreeGenContext"):
20+
context.insert("Operation")
21+
print("operation", self.statements)
22+
23+
for stmt in self.statements:
24+
if stmt is None:
25+
continue
26+
stmt.generate(context)
27+
28+
context.pop()
29+
30+
31+
def block(self: behav.Block, context: "TreeGenContext"):
32+
context.insert("Block")
33+
34+
for stmt in self.statements:
35+
if stmt is None:
36+
continue
37+
stmt.generate(context)
38+
39+
context.pop()
40+
41+
42+
def binary_operation(self: behav.BinaryOperation, context: "TreeGenContext"):
43+
context.insert("Binary Operation")
44+
45+
context.insert("Left")
46+
self.left.generate(context)
47+
context.pop()
48+
49+
context.insert("Right")
50+
self.right.generate(context)
51+
context.pop()
52+
53+
context.insert2("Op", values=(self.op.value,))
54+
55+
context.pop()
56+
57+
58+
def slice_operation(self: behav.SliceOperation, context: "TreeGenContext"):
59+
context.insert("Slice Operation")
60+
61+
context.insert("Expr")
62+
self.expr.generate(context)
63+
context.pop()
64+
65+
context.insert("Left")
66+
self.left.generate(context)
67+
context.pop()
68+
69+
context.insert("Right")
70+
self.right.generate(context)
71+
context.pop()
72+
73+
context.pop()
74+
75+
76+
def concat_operation(self: behav.ConcatOperation, context: "TreeGenContext"):
77+
context.insert("Concat Operation")
78+
79+
context.insert("Left")
80+
self.left.generate(context)
81+
context.pop()
82+
83+
context.insert("Right")
84+
self.right.generate(context)
85+
context.pop()
86+
87+
context.pop()
88+
89+
90+
def number_literal(self: behav.IntLiteral, context: "TreeGenContext"):
91+
context.insert2("Number Literal", values=(self.value,))
92+
93+
94+
def int_literal(self: behav.IntLiteral, context: "TreeGenContext"):
95+
context.insert2("Int Literal", values=(self.value,))
96+
97+
98+
def scalar_definition(self: behav.ScalarDefinition, context: "TreeGenContext"):
99+
context.insert2("Scalar Definition", values=(self.scalar.name,))
100+
101+
102+
def break_(self: behav.Break, context: "TreeGenContext"):
103+
context.insert2("Break")
104+
105+
106+
def assignment(self: behav.Assignment, context: "TreeGenContext"):
107+
context.insert("Assignment")
108+
109+
context.insert("Target")
110+
self.target.generate(context)
111+
context.pop()
112+
113+
context.insert("Expr")
114+
self.expr.generate(context)
115+
context.pop()
116+
117+
context.pop()
118+
119+
120+
def conditional(self: behav.Conditional, context: "TreeGenContext"):
121+
context.insert("Conditional")
122+
123+
context.insert("Conditions")
124+
for cond in self.conds:
125+
cond.generate(context)
126+
context.pop()
127+
128+
context.insert("Statements")
129+
for stmt in self.stmts:
130+
if stmt is None:
131+
continue
132+
stmt.generate(context)
133+
context.pop()
134+
135+
context.pop()
136+
137+
138+
def loop(self: behav.Loop, context: "TreeGenContext"):
139+
context.insert("Loop")
140+
141+
context.insert2("Post Test", values=(self.post_test,))
142+
143+
context.insert("Condition")
144+
self.cond.generate(context)
145+
context.pop()
146+
147+
context.insert("Statements")
148+
for stmt in self.stmts:
149+
stmt.generate(context)
150+
context.pop()
151+
152+
context.pop()
153+
154+
155+
def ternary(self: behav.Ternary, context: "TreeGenContext"):
156+
context.insert("Ternary")
157+
158+
context.insert("Cond")
159+
self.cond.generate(context)
160+
context.pop()
161+
162+
context.insert("Then Expression")
163+
self.then_expr.generate(context)
164+
context.pop()
165+
166+
context.insert("Else Expression")
167+
self.else_expr.generate(context)
168+
context.pop()
169+
170+
context.pop()
171+
172+
173+
def return_(self: behav.Return, context: "TreeGenContext"):
174+
context.insert("Return")
175+
176+
if self.expr is not None:
177+
context.insert("Expression")
178+
self.expr.generate(context)
179+
context.pop()
180+
181+
context.pop()
182+
183+
184+
def unary_operation(self: behav.UnaryOperation, context: "TreeGenContext"):
185+
context.insert("Unary Operation")
186+
187+
context.insert("Right")
188+
self.right.generate(context)
189+
context.pop()
190+
191+
context.insert2("Op", values=(self.op.value,))
192+
193+
context.pop()
194+
195+
196+
def named_reference(self: behav.NamedReference, context: "TreeGenContext"):
197+
context.insert2("Named Reference", values=(f"{self.reference}",))
198+
199+
200+
def indexed_reference(self: behav.IndexedReference, context: "TreeGenContext"):
201+
context.insert("Indexed Reference")
202+
203+
context.insert2("Reference", values=(f"{self.reference}",))
204+
205+
context.insert("Index")
206+
self.index.generate(context)
207+
context.pop()
208+
209+
context.pop()
210+
211+
212+
def type_conv(self: behav.TypeConv, context: "TreeGenContext"):
213+
context.insert("Type Conv")
214+
215+
context.insert2("Type", values=(self.data_type,))
216+
context.insert2("Size", values=(self.size,))
217+
218+
context.insert("Expr")
219+
self.expr.generate(context)
220+
context.pop()
221+
222+
context.pop()
223+
224+
225+
def callable_(self: behav.Callable, context: "TreeGenContext"):
226+
context.insert("Callable", values=(self.ref_or_name.name,))
227+
228+
for arg, arg_descr in zip(self.args, self.ref_or_name.args):
229+
context.insert("Arg", values=(arg_descr,))
230+
arg.generate(context)
231+
context.pop()
232+
233+
context.pop()
234+
235+
236+
def group(self: behav.Group, context: "TreeGenContext"):
237+
context.insert("Group")
238+
239+
context.insert("Expr")
240+
self.expr.generate(context)
241+
context.pop()
242+
243+
context.pop()

seal5/backends/dot/utils.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# This file is part of the M2-ISA-R project: https://github.com/tum-ei-eda/M2-ISA-R
4+
#
5+
# Copyright (C) 2022
6+
# Chair of Electrical Design Automation
7+
# Technical University of Munich
8+
9+
"""Utility stuff for M2-ISA-R viewer"""
10+
11+
from anytree import Node
12+
13+
14+
class TreeGenContext:
15+
def __init__(self, parent=None) -> None:
16+
if parent:
17+
self.nodes = [parent]
18+
else:
19+
self.nodes = [Node("Tree")]
20+
self.parent_stack = [0]
21+
# self.layer = 0
22+
23+
@property
24+
def parent(self):
25+
return self.nodes[self.parent_stack[-1]]
26+
27+
@property
28+
def tree(self):
29+
return self.nodes[0]
30+
31+
def push(self, node):
32+
# self.layer += 1
33+
self.parent_stack.append(len(self.nodes))
34+
self.nodes.append(node)
35+
36+
def pop(self):
37+
# self.layer -= 1
38+
return self.parent_stack.pop()
39+
40+
def insert(self, text, values=None):
41+
self.push(self.insert2(text, values=values))
42+
43+
def insert2(self, text, values=None):
44+
raise NotImplementedError
45+
46+
47+
class TextTreeGenContext(TreeGenContext):
48+
def __init__(self, parent=None) -> None:
49+
super().__init__(parent=parent)
50+
51+
def insert2(self, text, values=None):
52+
if isinstance(values, (list, set, tuple)):
53+
if len(values) == 1:
54+
values = values[0]
55+
return Node(text, parent=self.parent, value=values)

0 commit comments

Comments
 (0)