|
| 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() |
0 commit comments