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

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 seperated code block

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.

NumberLiteral

A class holding a generic number literal.

IntLiteral

A more precise class holding only integer literals.

Assignment

An assignment statement.

Conditional

A conditional statement with multiple conditions and statement blocks.

Loop

A loop statement, representing while and do .. while loops. post_test

Ternary

A ternary expression.

ScalarDefinition

A scalar declaration without initialization. To initialize the scalar while

Return

A return expression.

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, Scalar, Constant or FnParam.

IndexedReference

An indexed reference to a arch.Memory. 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.

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[source]
abstract generate(context)[source]
class CodeLiteral(val, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.CodeLiteral

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

Inheritance diagram of m2isar.metamodel.behav.Operator

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

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Operation

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

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

Bases: Operation

Inheritance diagram of m2isar.metamodel.behav.Block

A seperated code block

class BinaryOperation(left: BaseNode, op: Operator, right: BaseNode, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.BinaryOperation

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

Inheritance diagram of m2isar.metamodel.behav.SliceOperation

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

Inheritance diagram of m2isar.metamodel.behav.ConcatOperation

A concatenating operation.

left[source]
right[source]
class NumberLiteral(value, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.NumberLiteral

A class holding a generic number literal.

value[source]
class IntLiteral(value: int, bit_size: int = None, signed: bool = None, line_info=None)[source]

Bases: NumberLiteral

Inheritance diagram of m2isar.metamodel.behav.IntLiteral

A more precise class holding only integer literals.

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Assignment

An assignment statement.

target[source]
expr[source]
class Conditional(conds: list[BaseNode], stmts: list[BaseNode], line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Conditional

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 Loop(cond: BaseNode, stmts: list[BaseNode], post_test: bool, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Loop

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.

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Ternary

A ternary expression.

cond[source]
then_expr[source]
else_expr[source]
class ScalarDefinition(scalar: m2isar.metamodel.arch.Scalar, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.ScalarDefinition

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

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Return

A return expression.

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Break

A break statement.

class UnaryOperation(op: Operator, right: BaseNode, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.UnaryOperation

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

op[source]
right[source]
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

Inheritance diagram of m2isar.metamodel.behav.NamedReference

A named reference to a arch.Memory, BitFieldDescr, Scalar, Constant or FnParam.

reference[source]
class IndexedReference(reference: m2isar.metamodel.arch.Memory, index: BaseNode, right: BaseNode = None, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.IndexedReference

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

reference[source]
index[source]
right[source]
class TypeConv(data_type, size, expr: BaseNode, line_info=None)[source]

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.TypeConv

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

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Callable

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

Inheritance diagram of m2isar.metamodel.behav.FunctionCall

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

Inheritance diagram of m2isar.metamodel.behav.ProcedureCall

A procedure (method without return value) call.

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

Bases: BaseNode

Inheritance diagram of m2isar.metamodel.behav.Group

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

expr[source]