m2isar.metamodel.behav
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. |
|
A class holding a generic number literal. |
|
A more precise class holding only integer literals. |
|
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 scalar declaration without initialization. To initialize the scalar 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
NotImplementedError
if it is not overridden.
- class CodeLiteral(val, line_info=None)[source]
Bases:
BaseNode
The base class for all behavior model classes. Only implements an empty generate function which raises a
NotImplementedError
if it is not overridden.
- class Operator(op: str, line_info=None)[source]
Bases:
BaseNode
Class representing an operator (of either a
UnaryOperation
or aBinaryOperation
).
- class Operation(statements: list[BaseNode], line_info=None)[source]
Bases:
BaseNode
Top-level collection class containing a list of actual operations.
- class Block(statements: list[BaseNode], line_info=None)[source]
Bases:
Operation
A seperated code block
- class BinaryOperation(left: BaseNode, op: Operator, right: BaseNode, line_info=None)[source]
Bases:
BaseNode
A 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:
BaseNode
A slicing operation for extracting bit runs from scalar values.
- class ConcatOperation(left: BaseNode, right: BaseNode, line_info=None)[source]
Bases:
BaseNode
A concatenating operation.
- class NumberLiteral(value, line_info=None)[source]
Bases:
BaseNode
A class holding a generic number literal.
- class IntLiteral(value: int, bit_size: int = None, signed: bool = None, line_info=None)[source]
Bases:
NumberLiteral
A more precise class holding only integer literals.
- class Assignment(target: BaseNode, expr: BaseNode, line_info=None)[source]
Bases:
BaseNode
An assignment statement.
- class Conditional(conds: list[BaseNode], stmts: list[BaseNode], line_info=None)[source]
Bases:
BaseNode
A 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:
BaseNode
A 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:
BaseNode
A ternary expression.
- class ScalarDefinition(scalar: m2isar.metamodel.arch.Scalar, line_info=None)[source]
Bases:
BaseNode
A scalar declaration without initialization. To initialize the scalar while declaring it, use the scalar definition as LHS of an assignment statement.
- class Break(line_info: m2isar.metamodel.code_info.LineInfo = None)[source]
Bases:
BaseNode
A break statement.
- class UnaryOperation(op: Operator, right: BaseNode, line_info=None)[source]
Bases:
BaseNode
An unary operation, whith an operator and a right hand operand.
- class NamedReference(reference: m2isar.metamodel.arch.Memory | m2isar.metamodel.arch.BitFieldDescr | m2isar.metamodel.arch.Scalar | m2isar.metamodel.arch.Constant | m2isar.metamodel.arch.FnParam | m2isar.metamodel.arch.Intrinsic, line_info=None)[source]
Bases:
BaseNode
A named reference to a
arch.Memory
, BitFieldDescr, Scalar, Constant or FnParam.
- class IndexedReference(reference: m2isar.metamodel.arch.Memory, index: BaseNode, right: BaseNode = None, line_info=None)[source]
Bases:
BaseNode
An indexed reference to a
arch.Memory
. Can optionally specify a range of indices using the right parameter.
- class TypeConv(data_type, size, expr: BaseNode, line_info=None)[source]
Bases:
BaseNode
A 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:
BaseNode
A generic invocation of a callable.
- class FunctionCall(ref_or_name: str | m2isar.metamodel.arch.Function, args: list[BaseNode], line_info=None)[source]
Bases:
Callable
A function (method with return value) call.