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 seperated code block |
|
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. |
|
A loop statement, representing while and do .. while loops. post_test |
|
A ternary expression. |
|
A var declaration without initialization. To initialize the var while |
|
A return expression. |
|
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. |
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)[source]
Bases:
OperationA seperated code block
- 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.NONE, 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)[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 Loop(cond: BaseNode, stmts: list[BaseNode], post_test: bool, line_info=None)[source]
Bases:
BaseNodeA loop statement, representing while and do .. while loops. post_test differentiates between normal while (post_test = False) and do .. while (post_test=True) loops.
- 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 Break(line_info: m2isar.metamodel.code_info.LineInfo = None)[source]
Bases:
BaseNodeA break statement.
- class UnaryOperation(op: Operator, right: BaseNode, line_info=None)[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)[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.