m2isar.metamodel.arch

This module contains classes for modeling the architectural part of an M2-ISA-R model. The architectural part is anything but the functional behavior of functions and instructions.

Attributes

ValOrConst

Classes

Named

A simple base class for a named object.

SizedRefOrConst

A simple base class for an object with a name and a size.

Constant

An object holding a constant value. Should have a value at some point, also holds attributes

RangeSpec

A class holding a range to denote a range of indices or width of a memory bank.

MemoryAttribute

Generic enumeration.

ConstAttribute

Generic enumeration.

InstrAttribute

Generic enumeration.

FunctionAttribute

Generic enumeration.

FunctionThrows

Enum where members are also (and must be) ints

DataType

Generic enumeration.

DataType2

A datatype base class, only holds information on whether it is a pointer.

VoidType

A void datatype, automatically assumes native size.

IntegerType

An integer datatype with width and sign information.

FnParam

A function parameter.

Scalar

A scalar variable object, used mainly in behavior descriptions.

Intrinsic

A simple base class for an object with a name and a size.

Memory

A generic memory object. Can have children, which alias to specific indices

BitVal

A class representing a fixed bit sequence in an instruction encoding.

BitField

A class representing an operand in an instruction encoding. Can be split

BitFieldDescr

A class representing a full instruction operand. Has no information about

Instruction

A class representing an instruction.

Function

A class representing a function.

AlwaysBlock

A simple base class for a named object.

InstructionSet

A class representing an InstructionSet collection. Bundles constants, memories, functions

CoreDef

A class representing an entire CPU core. Contains the collected attributes of multiple InstructionSets.

Functions

get_const_or_val(→ int)

extract_memory_alias(memories)

Extract and separate parent and children memories from the given list

Module Contents

get_const_or_val(arg) int[source]
class Named(name: str)[source]

A simple base class for a named object.

name: str[source]

The name of the object.

__str__() str[source]
__repr__() str[source]
ValOrConst[source]
class SizedRefOrConst(name, size: ValOrConst)[source]

Bases: Named

Inheritance diagram of m2isar.metamodel.arch.SizedRefOrConst

A simple base class for an object with a name and a size. Size can be either an int, a Constant or a statically resolvable expression, expressed by a BaseNode.

_size: int | Constant | m2isar.metamodel.behav.BaseNode[source]

The size of the object

property size: int[source]

Returns the resolved size, by calling get_const_or_val on _size.

property actual_size[source]
Returns the bits needed in multiples of eight to represent the
resolved size of the object.
__str__() str[source]
class Constant(name, value: int | Constant | m2isar.metamodel.behav.BaseNode, attributes: dict[ConstAttribute, list[BaseNode]], size=None, signed=False)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.Constant

An object holding a constant value. Should have a value at some point, also holds attributes and signedness information.

_value: int | Constant | m2isar.metamodel.behav.BaseNode[source]

The value this object holds. Can be an int, another constant or a statically resolvable BaseNode.

attributes: dict[ConstAttribute, list[BaseNode]][source]

A dictionary of attributes, mapping attribute type to a list of attribute arguments.

signed: bool[source]

The signedness of this constant.

property value[source]
Returns the resolved value this constant holds.
__str__() str[source]
__repr__() str[source]
class RangeSpec(upper_base: ValOrConst, lower_base: ValOrConst = None, upper_power: ValOrConst = 1, lower_power: ValOrConst = 1)[source]

A class holding a range to denote a range of indices or width of a memory bank.

_upper_base: int | Constant | m2isar.metamodel.behav.BaseNode[source]

The upper bound of the range. Can be an int, a constant or a statically resolvable BaseNode.

_lower_base: int | Constant | m2isar.metamodel.behav.BaseNode[source]

The lower bound of the range. Can be an int, a constant or a statically resolvable BaseNode.

_upper_power: int | Constant | m2isar.metamodel.behav.BaseNode[source]

Obsolete, do not use

_lower_power: int | Constant | m2isar.metamodel.behav.BaseNode[source]

Obsolete, do not use

property upper_power[source]
Returns the resolved upper bound power.
property lower_power[source]
Returns the resolved lower bound power.
property upper_base[source]
Returns the resolved upper bound base.
property lower_base[source]
Returns the resolved lower bound base.
property upper: int | None[source]

Returns the resolved upper power.

property lower: int[source]

Returns the resolved lower power.

property length[source]
Returns the length of the range using following algorithm:
if self.upper is None: return None
elif self.lower is None: return self.upper
else return self.upper - self.lower + 1
__str__() str[source]
class MemoryAttribute[source]

Bases: enum.Enum

Inheritance diagram of m2isar.metamodel.arch.MemoryAttribute

Generic enumeration.

Derive from this class to define new enumerations.

IS_PC[source]
IS_MAIN_MEM[source]
IS_MAIN_REG[source]
DELETE[source]
ETISS_CAN_FAIL[source]
ETISS_IS_GLOBAL_IRQ_EN[source]
ETISS_IS_IRQ_EN[source]
ETISS_IS_IRQ_PENDING[source]
ETISS_IS_PROCNO[source]
class ConstAttribute[source]

Bases: enum.Enum

Inheritance diagram of m2isar.metamodel.arch.ConstAttribute

Generic enumeration.

Derive from this class to define new enumerations.

IS_REG_WIDTH[source]
IS_ADDR_WIDTH[source]
class InstrAttribute[source]

Bases: enum.Enum

Inheritance diagram of m2isar.metamodel.arch.InstrAttribute

Generic enumeration.

Derive from this class to define new enumerations.

NO_CONT[source]
COND[source]
FLUSH[source]
SIM_EXIT[source]
ENABLE[source]
ETISS_ERROR_INSTRUCTION[source]
class FunctionAttribute[source]

Bases: enum.Enum

Inheritance diagram of m2isar.metamodel.arch.FunctionAttribute

Generic enumeration.

Derive from this class to define new enumerations.

ETISS_STATICFN[source]
ETISS_NEEDS_ARCH[source]
ETISS_TRAP_ENTRY_FN[source]
ETISS_TRAP_TRANSLATE_FN[source]
class FunctionThrows[source]

Bases: enum.IntEnum

Inheritance diagram of m2isar.metamodel.arch.FunctionThrows

Enum where members are also (and must be) ints

NO = 0[source]
YES = 1[source]
MAYBE = 2[source]
class DataType[source]

Bases: enum.Enum

Inheritance diagram of m2isar.metamodel.arch.DataType

Generic enumeration.

Derive from this class to define new enumerations.

NONE[source]
U[source]
S[source]
F[source]
D[source]
Q[source]
B[source]
class DataType2(ptr)[source]

A datatype base class, only holds information on whether it is a pointer.

ptr: Any[source]
class VoidType(ptr)[source]

Bases: DataType2

Inheritance diagram of m2isar.metamodel.arch.VoidType

A void datatype, automatically assumes native size.

class IntegerType(width: int | Constant | m2isar.metamodel.behav.BaseNode, signed: bool, ptr)[source]

Bases: DataType2

Inheritance diagram of m2isar.metamodel.arch.IntegerType

An integer datatype with width and sign information.

_width: int | Constant | m2isar.metamodel.behav.BaseNode[source]
signed: bool[source]
property width[source]
Returns the resolved width value.
property actual_width[source]
Returns the resolved width value rounded to the nearest multiple of 8.
class FnParam(name, size, data_type: DataType, width=1)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.FnParam

A function parameter.

data_type: DataType[source]
_width: int | Constant | m2isar.metamodel.behav.BaseNode[source]

The array width of this parameter.

property width[source]
Returns the resolved array width value.
__str__() str[source]
class Scalar(name, value: int, static: bool, size, data_type: DataType)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.Scalar

A scalar variable object, used mainly in behavior descriptions.

value: int[source]
static: bool[source]
data_type: DataType[source]
class Intrinsic(name, size: ValOrConst, data_type: DataType, value: int = None)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.Intrinsic

A simple base class for an object with a name and a size. Size can be either an int, a Constant or a statically resolvable expression, expressed by a BaseNode.

value: int[source]
data_type: DataType[source]
class Memory(name, range_: RangeSpec, size, attributes: dict[MemoryAttribute, list[BaseNode]])[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.Memory

A generic memory object. Can have children, which alias to specific indices of their parent memory. Has a variable array size, can therefore represent both scalar and array registers and/or memories.

attributes: dict[MemoryAttribute, list[BaseNode]][source]
range: RangeSpec[source]
children: list[Memory][source]
parent: Memory | None[source]
_initval: dict[int, int | Constant | BaseNode][source]
initval(idx=None)[source]

Return the initial value for the given index.

property data_range[source]
Returns a RangeSpec object with upper=range.upper-range.lower, lower=0.
property is_pc[source]
Return true if this memory is tagged as being the program counter.
property is_main_mem[source]
Return true if this memory is tagged as being the main memory array.
class BitVal[source]

A class representing a fixed bit sequence in an instruction encoding. Modeled as length and integral value.

length: int[source]
value: int[source]
class BitField(name, _range: RangeSpec, data_type: DataType)[source]

Bases: Named

Inheritance diagram of m2isar.metamodel.arch.BitField

A class representing an operand in an instruction encoding. Can be split into multiple parts, if the operand is split over two or more bit ranges.

range: RangeSpec[source]
data_type: DataType[source]
__str__() str[source]
__repr__()[source]
class BitFieldDescr(name, size: ValOrConst, data_type: DataType)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.BitFieldDescr

A class representing a full instruction operand. Has no information about the actual bits it is composed of, for that use BitField.

data_type[source]
class Instruction(name, attributes: dict[InstrAttribute, list[BaseNode]], encoding: list[BitField | BitVal], disass: str, operation: m2isar.metamodel.behav.Operation, function_info: m2isar.metamodel.code_info.FunctionInfo)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.Instruction

A class representing an instruction.

attributes: dict[InstrAttribute, list[BaseNode]][source]
encoding: list[BitField | BitVal][source]
disass: str[source]
operation: m2isar.metamodel.behav.Operation[source]
ext_name: str[source]
fields: dict[str, BitFieldDescr][source]
scalars: dict[str, Scalar][source]
throws: bool[source]
mask: int[source]
code: int[source]
function_info[source]
__str__() str[source]
class Function(name, attributes: dict[FunctionAttribute, list[BaseNode]], return_len, data_type: DataType, args: list[FnParam], operation: m2isar.metamodel.behav.Operation, extern: bool = False, function_info: m2isar.metamodel.code_info.FunctionInfo = None)[source]

Bases: SizedRefOrConst

Inheritance diagram of m2isar.metamodel.arch.Function

A class representing a function.

attributes: dict[FunctionAttribute, list[BaseNode]][source]
data_type: DataType[source]
args: list[FnParam][source]
operation: m2isar.metamodel.behav.Operation[source]
extern: bool[source]
ext_name: str[source]
scalars: dict[str, Scalar][source]
throws: bool[source]
static: bool[source]
function_info[source]
__str__() str[source]
extract_memory_alias(memories: list[Memory])[source]

Extract and separate parent and children memories from the given list of memory objects.

class AlwaysBlock(name: str, attributes, operation)[source]

Bases: Named

Inheritance diagram of m2isar.metamodel.arch.AlwaysBlock

A simple base class for a named object.

attributes: dict[FunctionAttribute, list[BaseNode]][source]
operation: m2isar.metamodel.behav.Operation[source]
class InstructionSet(name, extension: list[str], constants: dict[str, Constant], memories: dict[str, Memory], functions: dict[str, Function], instructions: dict[tuple[int, int], Instruction])[source]

Bases: Named

Inheritance diagram of m2isar.metamodel.arch.InstructionSet

A class representing an InstructionSet collection. Bundles constants, memories, functions and instructions under a common name.

extension[source]
constants[source]
functions[source]
instructions[source]
class CoreDef(name, contributing_types: list[str], template: str, constants: dict[str, Constant], memories: dict[str, Memory], memory_aliases: dict[str, Memory], functions: dict[str, Function], instructions: dict[tuple[int, int], Instruction], instr_classes: set[int], intrinsics: dict[str, Intrinsic])[source]

Bases: Named

Inheritance diagram of m2isar.metamodel.arch.CoreDef

A class representing an entire CPU core. Contains the collected attributes of multiple InstructionSets.

contributing_types[source]
template[source]
constants[source]
memories[source]
memory_aliases[source]
functions[source]
instructions[source]
instr_classes[source]
main_reg_file = None[source]
main_memory = None[source]
pc_memory = None[source]
global_irq_en_memory = None[source]
global_irq_en_mask = None[source]
procno_memory = None[source]
irq_en_memory = None[source]
irq_pending_memory = None[source]
intrinsics[source]
instructions_by_ext[source]
functions_by_ext[source]
instructions_by_class[source]