m2isar.metamodel.behav
Deprecated module, only used for legacy reasons. Monkey patching can be avoided
by a custom ExprVisitor subclass and a custom generate function.
See m2isar.metamodel.utils.ExprVisitor for more details on how to do this.
This module contains classes for modeling the behavioral part
of an M2-ISA-R model, this means the functional behavior of functions
and instructions. Behavior is modeled as a tree of instances of the classes
in this module. This object tree can then be traversed with transformation
functions to generate code or transform the tree.
All classes in this module should inherit from BaseNode, but never implement
the generate method here. This method is dynamically overwritten during runtime depending
on which translation module is loaded using patch_model().
Classes
The base class for all behavior model classes. Only implements an |
|
The base class for all behavior model classes. Only implements an |
|
Class representing an operator (of either a |
|
Top-level collection class containing a list of actual operations. |
|
A separated code block with optional behavioral attributes. |
|
A binary operation with a left-hand and a right-hand operand as well |
|
A slicing operation for extracting bit runs from scalar values. |
|
A concatenating operation. |
|
The base class for all behavior model classes. Only implements an |
|
The base class for all behavior model classes. Only implements an |
|
An assignment statement. |
|
A conditional statement with multiple conditions and statement blocks. |
|
Common structural base for source and canonical loops. |
|
Canonical lowered loop representation. |
|
Source-level |
|
Source-level pre-tested while loop. |
|
Source-level post-tested do-while loop. |
|
A ternary expression. |
|
A var declaration without initialization. To initialize the var while |
|
A return expression. |
|
Continue the innermost loop. |
|
A break statement. |
|
An unary operation, whith an operator and a right hand operand. |
|
A named reference to a |
|
An indexed reference to a |
|
A type conversion. Size can be None, in this case only the signedness is affected. |
|
A generic invocation of a callable. |
|
A function (method with return value) call. |
|
A procedure (method without return value) call. |
|
A group of expressions, used e.g. for parenthesized expressions. |
Functions
|
Module Contents
- class BaseNode(line_info: m2isar.metamodel.code_info.LineInfo = None)[source]
The base class for all behavior model classes. Only implements an empty generate function which raises a
NotImplementedErrorif it is not overridden.
- class CodeLiteral(val, line_info=None)[source]
Bases:
BaseNodeThe base class for all behavior model classes. Only implements an empty generate function which raises a
NotImplementedErrorif it is not overridden.
- class Operator(op: str, line_info=None)[source]
Bases:
BaseNodeClass representing an operator (of either a
UnaryOperationor aBinaryOperation).
- class Operation(statements: list[BaseNode], line_info=None)[source]
Bases:
BaseNodeTop-level collection class containing a list of actual operations.
- class Block(statements: list[BaseNode], line_info=None, attributes=None, explicit_attributes=None)[source]
Bases:
OperationA separated code block with optional behavioral attributes.
- class BinaryOperation(left: BaseNode, op: Operator, right: BaseNode, line_info=None)[source]
Bases:
BaseNodeA binary operation with a left-hand and a right-hand operand as well as an operator.
- class SliceOperation(expr: BaseNode, left: BaseNode, right: BaseNode, line_info=None)[source]
Bases:
BaseNodeA slicing operation for extracting bit runs from scalar values.
- class ConcatOperation(left: BaseNode, right: BaseNode, line_info=None)[source]
Bases:
BaseNodeA concatenating operation.
- class Literal(value: int, ty=PrimitiveType(TypeKind.AUTO, None), base: int | None = 10, line_info=None)[source]
Bases:
BaseNodeThe base class for all behavior model classes. Only implements an empty generate function which raises a
NotImplementedErrorif it is not overridden.
- class Tensor(value: list[int], ty=ArrayType(PrimitiveType(TypeKind.NONE, None), None), line_info=None, initializer_elements=None)[source]
Bases:
BaseNodeThe base class for all behavior model classes. Only implements an empty generate function which raises a
NotImplementedErrorif it is not overridden.
- class Assignment(target: BaseNode, expr: BaseNode, line_info=None)[source]
Bases:
BaseNodeAn assignment statement.
- class Conditional(conds: list[BaseNode], stmts: list[BaseNode], line_info=None)[source]
Bases:
BaseNodeA conditional statement with multiple conditions and statement blocks.
Each statement block has a corresponding condition statement. The exception from this is the very last statement block, which when no corresponding condition is present is treated as an else statement.
- class LoopBase(cond: BaseNode, stmts: list[BaseNode], post_test: bool, line_info=None, init: list[BaseNode] = None, updates: list[BaseNode] = None)[source]
Bases:
BaseNodeCommon structural base for source and canonical loops.
initis executed once before the loop,updatesat the loop latch, andpost_testselects whether the condition is checked before or after the body. Source frontends should prefer one of the explicit loop classes.
- class Loop(cond: BaseNode, stmts: list[BaseNode], post_test: bool, line_info=None, init: list[BaseNode] = None, updates: list[BaseNode] = None)[source]
Bases:
LoopBaseCanonical lowered loop representation.
- class ForLoop(init: list[BaseNode], cond: BaseNode, updates: list[BaseNode], body: Block, line_info=None)[source]
Bases:
LoopBaseSource-level
for (init; cond; updates) bodyloop.
- class WhileLoop(cond: BaseNode, body: Block, line_info=None)[source]
Bases:
LoopBaseSource-level pre-tested while loop.
- class DoWhileLoop(body: Block, cond: BaseNode, line_info=None)[source]
Bases:
LoopBaseSource-level post-tested do-while loop.
- class Ternary(cond: BaseNode, then_expr: BaseNode, else_expr: BaseNode, line_info=None)[source]
Bases:
BaseNodeA ternary expression.
- class VarDefinition(var: m2isar.metamodel.arch.Variable, line_info=None)[source]
Bases:
BaseNodeA var declaration without initialization. To initialize the var while declaring it, use the var definition as LHS of an assignment statement.
- class Continue(line_info: m2isar.metamodel.code_info.LineInfo = None)[source]
Bases:
BaseNodeContinue the innermost loop.
- class Break(line_info: m2isar.metamodel.code_info.LineInfo = None)[source]
Bases:
BaseNodeA break statement.
- class UnaryOperation(op: Operator, right: BaseNode, line_info=None, *, postfix=False)[source]
Bases:
BaseNodeAn unary operation, whith an operator and a right hand operand.
- class NamedReference(reference: m2isar.metamodel.arch.Memory | m2isar.metamodel.arch.BitFieldDescr | m2isar.metamodel.arch.Variable | m2isar.metamodel.arch.Parameter | m2isar.metamodel.arch.FnParam | m2isar.metamodel.arch.Intrinsic, line_info=None)[source]
Bases:
BaseNodeA named reference to a
arch.Memory, BitFieldDescr, Variable, Parameter or FnParam.
- class IndexedReference(reference: Memory | RegisterBank, index: BaseNode, right: BaseNode = None, line_info=None, *, grouped_base=False)[source]
Bases:
BaseNodeAn indexed reference to a
arch.Memory/RegisterBank. Can optionally specify a range of indices using the right parameter.
- class TypeConv(data_type, size, expr: BaseNode, line_info=None)[source]
Bases:
BaseNodeA type conversion. Size can be None, in this case only the signedness is affected.
- class Callable(ref_or_name: str | m2isar.metamodel.arch.Function, args: list[BaseNode], line_info=None)[source]
Bases:
BaseNodeA generic invocation of a callable.
- class FunctionCall(ref_or_name: str | m2isar.metamodel.arch.Function, args: list[BaseNode], line_info=None)[source]
Bases:
CallableA function (method with return value) call.