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

BaseNode

The base class for all behavior model classes. Only implements an

CodeLiteral

The base class for all behavior model classes. Only implements an

Operator

Class representing an operator (of either a UnaryOperation or a

Operation

Top-level collection class containing a list of actual operations.

Block

A separated code block with optional behavioral attributes.

BinaryOperation

A binary operation with a left-hand and a right-hand operand as well

SliceOperation

A slicing operation for extracting bit runs from scalar values.

ConcatOperation

A concatenating operation.

Literal

The base class for all behavior model classes. Only implements an

Tensor

The base class for all behavior model classes. Only implements an

Assignment

An assignment statement.

Conditional

A conditional statement with multiple conditions and statement blocks.

LoopBase

Common structural base for source and canonical loops.

Loop

Canonical lowered loop representation.

ForLoop

Source-level for (init; cond; updates) body loop.

WhileLoop

Source-level pre-tested while loop.

DoWhileLoop

Source-level post-tested do-while loop.

Ternary

A ternary expression.

VarDefinition

A var declaration without initialization. To initialize the var while

Return

A return expression.

Continue

Continue the innermost loop.

Break

A break statement.

UnaryOperation

An unary operation, whith an operator and a right hand operand.

NamedReference

A named reference to a arch.Memory, BitFieldDescr, Variable, Parameter or FnParam.

IndexedReference

An indexed reference to a arch.Memory/RegisterBank. Can optionally specify a range of indices

TypeConv

A type conversion. Size can be None, in this case only the signedness is affected.

Callable

A generic invocation of a callable.

FunctionCall

A function (method with return value) call.

ProcedureCall

A procedure (method without return value) call.

Group

A group of expressions, used e.g. for parenthesized expressions.

Functions

required_bits(n[, signed]) → int

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.

line_info = None[source]
ty = None[source]
abstract generate(context)[source]
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.

val[source]
class Operator(op: str, line_info=None)[source]

Bases: BaseNode

Class representing an operator (of either a UnaryOperation or a BinaryOperation).

value[source]
class Operation(statements: list[BaseNode], line_info=None)[source]

Bases: BaseNode

Top-level collection class containing a list of actual operations.

statements[source]
class Block(statements: list[BaseNode], line_info=None, attributes=None, explicit_attributes=None)[source]

Bases: Operation

A separated code block with optional behavioral attributes.

attributes[source]
explicit_attributes[source]
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.

left[source]
op[source]
right[source]
class SliceOperation(expr: BaseNode, left: BaseNode, right: BaseNode, line_info=None)[source]

Bases: BaseNode

A slicing operation for extracting bit runs from scalar values.

expr[source]
left[source]
right[source]
class ConcatOperation(left: BaseNode, right: BaseNode, line_info=None)[source]

Bases: BaseNode

A concatenating operation.

left[source]
right[source]
required_bits(n: int, signed: bool = False) → int[source]
class Literal(value: int, ty=PrimitiveType(TypeKind.AUTO, None), base: int | None = 10, 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.

_value: int | str[source]
ty[source]
base: int | None = 10[source]
__repr__()[source]
__int__()[source]
property value: int[source]

Returns the resolved value.

class Tensor(value: list[int], ty=ArrayType(PrimitiveType(TypeKind.NONE, None), None), line_info=None, initializer_elements=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.

_value: numpy.ndarray[source]
ty[source]
initializer_elements = None[source]
__repr__()[source]
property value: numpy.ndarray[source]

Returns the resolved array.

class Assignment(target: BaseNode, expr: BaseNode, line_info=None)[source]

Bases: BaseNode

An assignment statement.

target[source]
expr[source]
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.

conds[source]
stmts[source]
class LoopBase(cond: BaseNode, stmts: list[BaseNode], post_test: bool, line_info=None, init: list[BaseNode] = None, updates: list[BaseNode] = None)[source]

Bases: BaseNode

Common structural base for source and canonical loops.

init is executed once before the loop, updates at the loop latch, and post_test selects whether the condition is checked before or after the body. Source frontends should prefer one of the explicit loop classes.

cond[source]
stmts[source]
post_test[source]
init[source]
updates[source]
property body[source]

Return the loop body block.

class Loop(cond: BaseNode, stmts: list[BaseNode], post_test: bool, line_info=None, init: list[BaseNode] = None, updates: list[BaseNode] = None)[source]

Bases: LoopBase

Canonical lowered loop representation.

class ForLoop(init: list[BaseNode], cond: BaseNode, updates: list[BaseNode], body: Block, line_info=None)[source]

Bases: LoopBase

Source-level for (init; cond; updates) body loop.

class WhileLoop(cond: BaseNode, body: Block, line_info=None)[source]

Bases: LoopBase

Source-level pre-tested while loop.

class DoWhileLoop(body: Block, cond: BaseNode, line_info=None)[source]

Bases: LoopBase

Source-level post-tested do-while loop.

class Ternary(cond: BaseNode, then_expr: BaseNode, else_expr: BaseNode, line_info=None)[source]

Bases: BaseNode

A ternary expression.

cond[source]
then_expr[source]
else_expr[source]
class VarDefinition(var: m2isar.metamodel.arch.Variable, line_info=None)[source]

Bases: BaseNode

A var declaration without initialization. To initialize the var while declaring it, use the var definition as LHS of an assignment statement.

var[source]
class Return(expr: BaseNode, line_info=None)[source]

Bases: BaseNode

A return expression.

expr[source]
class Continue(line_info: m2isar.metamodel.code_info.LineInfo = None)[source]

Bases: BaseNode

Continue the innermost loop.

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, *, postfix=False)[source]

Bases: BaseNode

An unary operation, whith an operator and a right hand operand.

op[source]
right[source]
postfix = False[source]
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: BaseNode

A named reference to a arch.Memory, BitFieldDescr, Variable, Parameter or FnParam.

reference[source]
class IndexedReference(reference: Memory | RegisterBank, index: BaseNode, right: BaseNode = None, line_info=None, *, grouped_base=False)[source]

Bases: BaseNode

An indexed reference to a arch.Memory/RegisterBank. Can optionally specify a range of indices using the right parameter.

reference[source]
index[source]
right = None[source]
grouped_base = False[source]
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.

data_type[source]
_size[source]
expr[source]
property size: int[source]

Returns the resolved size.

property actual_size: int[source]

Returns the actual size.

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.

ref_or_name[source]
args[source]
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.

class ProcedureCall(ref_or_name: str | m2isar.metamodel.arch.Function, args: list[BaseNode], line_info=None)[source]

Bases: Callable

A procedure (method without return value) call.

class Group(expr: BaseNode, line_info=None)[source]

Bases: BaseNode

A group of expressions, used e.g. for parenthesized expressions.

expr[source]