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

exprInterpretVisitor

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.

Parameter

An object holding a ("Parameter") Parameter value.

RangeSpec

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

FnParam

A function parameter.

Symbol

A simple base class for a symbol, which is a named object that

Variable

A variable is only defined in the functional behavior of a function, but not in the architectural part.

Intrinsic

A simple base class for a symbol, which is a named object that

RegisterBank

A class representing a register bank. A register bank combines structured registers,

Register

A class representing a register. A register is a single defined Symbols. Dont mix it up

Memory

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

Alias

A class representing an (potentially ranged) alias to a Register/Memory/RegisterBank entity,

BitField

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

BitVal

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

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 parameters, memories, functions

InstructionSetGroup

A group of InstructionSet instances.

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

extract_register_alias(register_banks)

Extract and separate parent and children register banks from the given list

Module Contents

exprInterpretVisitor[source]
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

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

_size: int | Parameter | 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.

__str__() str[source]
class Parameter(name, value: int | Parameter | m2isar.metamodel.behav.BaseNode, attributes: dict[attribute_info.ConstAttribute, list[BaseNode]], size=None, signed=False)[source]

Bases: SizedRefOrConst

An object holding a (“Parameter”) Parameter value. Should have a value at some point, also holds attributes and signedness information.

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

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

attributes: dict[attribute_info.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 | Parameter | 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 | Parameter | 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 | Parameter | m2isar.metamodel.behav.BaseNode[source]

Obsolete, do not use

_lower_power: int | Parameter | 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 FnParam(name, size, kind: m2isar.metamodel.type_info.TypeKind, width=1)[source]

Bases: Named

A function parameter.

ty: m2isar.metamodel.type_info.PrimitiveType[source]
_width: int | Parameter | m2isar.metamodel.behav.BaseNode[source]

The array width of this parameter.

property width[source]

Returns the resolved array width value.

__str__() str[source]
class Symbol(name: str, ty: m2isar.metamodel.type_info.PrimitiveType | m2isar.metamodel.type_info.FloatType | m2isar.metamodel.type_info.ArrayType | m2isar.metamodel.type_info.BitFieldType | m2isar.metamodel.type_info.PointerType, attributes: dict = {})[source]

Bases: Named

A simple base class for a symbol, which is a named object that can be used as an operand in an instruction or function.

ty[source]
attributes[source]
class Variable(name: str, ty: m2isar.metamodel.type_info.PrimitiveType | m2isar.metamodel.type_info.FloatType | m2isar.metamodel.type_info.ArrayType, attributes: dict = {'static': attribute_info.AccessAttribute.RW}, value=None, children=[])[source]

Bases: Symbol

A variable is only defined in the functional behavior of a function, but not in the architectural part. Archtiectural Parts are depicted as Register Banks or Memories, but not as variables. However, we need to define variables for intermediate results, …

value = None[source]
children = [][source]
class Intrinsic(name, size: ValOrConst, kind: m2isar.metamodel.type_info.TypeKind, value: int = None)[source]

Bases: Symbol

A simple base class for a symbol, which is a named object that can be used as an operand in an instruction or function.

value: int[source]
class RegisterBank(name, nr_ele: int | Parameter, kind: m2isar.metamodel.type_info.TypeKind, size, attributes: dict[attribute_info.MemoryAttribute, list[BaseNode]])[source]

Bases: Symbol

A class representing a register bank. A register bank combines structured registers, which is used to represent registers in the architectural part of an M2-ISA-R model.

children: list[Memory][source]
_initval: dict[int, int | Parameter | BaseNode][source]
initval(idx=None)[source]

Return the initial value for the given index.

property is_main_reg[source]

Return true if this memory is tagged as being a general-purpose register.

property is_float_reg: bool[source]

Return true if this memory is tagged as being a float register array or named F.

property is_vector_reg: bool[source]

Return true if this memory is tagged as being a vector register array or named V.

_is_specific_register(register_type: m2isar.metamodel.attribute_info.RegisterAttribute, expected_name: str = '') bool[source]

This is a helper function to ensure, that all checks are performed always the same. :param register_type: The register attribute qualifying for this check :param expected_name: The fixed name for this specific type of register :return: True if the register matches the constraints, False otherwise

class Register(name, kind: m2isar.metamodel.type_info.TypeKind, size, attributes: dict[attribute_info.RegisterAttribute, list[BaseNode]])[source]

Bases: Symbol

A class representing a register. A register is a single defined Symbols. Dont mix it up bit alias that are IndexedReference of already declared Symbols. This class should simplify different handling to register bank. And is used to represent registers in the architectural part of an M2-ISA-R model.

children: list[Memory][source]
_initval: dict[int | Parameter | BaseNode][source]
initval()[source]

Return the initial value for the given index.

property is_pc[source]

Return true if this memory is tagged as being the program counter.

_is_specific_register(register_type: m2isar.metamodel.attribute_info.RegisterAttribute, expected_name: str = '') bool[source]

This is a helper function to ensure, that all checks are performed always the same. :param register_type: The register attribute qualifying for this check :param expected_name: The fixed name for this specific type of memory :return: True if the memory matches the constraints, False otherwise

class Memory(name, kind: m2isar.metamodel.type_info.TypeKind, size, length, attributes: dict[attribute_info.MemoryAttribute, list[BaseNode]])[source]

Bases: Symbol

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.

range: RangeSpec[source]
children: list[Memory][source]
parent: 'Memory' | None[source]
_initval: dict[int, int | Parameter | 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_csr_reg: bool[source]

Return true if this memory is tagged as being a csr register array or named CSR.

property is_main_mem[source]

Return true if this memory is tagged as being the main memory array.

_is_specific_memory(memory_type: m2isar.metamodel.attribute_info.MemoryAttribute, expected_name: str = '') bool[source]

This is a helper function to ensure, that all checks are performed always the same. :param memory_type: The memory attribute qualifying for this check :param expected_name: The fixed name for this specific type of memory :return: True if the memory matches the constraints, False otherwise

class Alias(name, parent: Memory | RegisterBank, range: RangeSpec, type: m2isar.metamodel.type_info.PointerType, attributes: dict = {})[source]

Bases: Symbol

A class representing an (potentially ranged) alias to a Register/Memory/RegisterBank entity, which refer to the architectural part of an M2-ISA-R model. This access might be ranged

parent: Memory | RegisterBank[source]
_initval = 0[source]
range[source]
ty[source]
property data_range[source]

Returns a RangeSpec object with upper=range.upper-range.lower, lower=0.

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

class BitField(name, _range: RangeSpec, kind: m2isar.metamodel.type_info.TypeKind)[source]

Bases: Symbol

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]
kind: m2isar.metamodel.type_info.TypeKind[source]
__str__() str[source]
__repr__()[source]
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 BitFieldDescr(name, size: ValOrConst, kind: m2isar.metamodel.type_info.TypeKind)[source]

Bases: Named

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

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

Bases: SizedRefOrConst

A class representing an instruction.

attributes: dict[attribute_info.InstrAttribute, list[BaseNode]][source]
encoding: list[BitField | BitVal][source]
mnemonic: str[source]
assembly: str[source]
operation: m2isar.metamodel.behav.Operation[source]
ext_name: str[source]
fields: dict[str, BitFieldDescr][source]
vars: dict[str, Symbol][source]
throws: bool[source]
mask: int[source]
code: int[source]
function_info[source]
__str__() str[source]
class Function(name, attributes: dict[attribute_info.FunctionAttribute, list[BaseNode]], return_len, kind: m2isar.metamodel.type_info.TypeKind, args: list[FnParam], operation: m2isar.metamodel.behav.Operation, extern: bool = False, function_info: m2isar.metamodel.code_info.FunctionInfo = None)[source]

Bases: Named

A class representing a function.

attributes: dict[attribute_info.FunctionAttribute, list[BaseNode]][source]
ty: m2isar.metamodel.type_info.FunctionType[source]
args: list[FnParam][source]
operation: m2isar.metamodel.behav.Operation[source]
extern: bool[source]
ext_name: str[source]
vars: dict[str, Symbol][source]
throws: bool[source]
static: m2isar.metamodel.attribute_info.AccessAttribute[source]
function_info = None[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.

extract_register_alias(register_banks: list[RegisterBank])[source]

Extract and separate parent and children register banks from the given list of register bank objects.

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

Bases: Named

A simple base class for a named object.

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

Bases: Named

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

extension[source]
combines = [][source]
parameters[source]
functions[source]
instructions[source]
class InstructionSetGroup(name, combines: list[str])[source]

Bases: InstructionSet

A group of InstructionSet instances.

combines[source]
class CoreDef(name, contributing_types: list[str], template: str, parameters: dict[str, Parameter], memories: dict[str, Memory], memory_aliases: dict[str, Alias], register_banks: dict[str, RegisterBank | Register], register_aliases: dict[str, Alias], functions: dict[str, Function], instructions: dict[tuple[int, int], Instruction] | list[Instruction], instr_classes: set[int], intrinsics: dict[str, Intrinsic])[source]

Bases: Named

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

contributing_types[source]
template[source]
parameters[source]
memories[source]
memory_aliases[source]
register_banks[source]
register_aliases[source]
functions[source]
instructions[source]
instr_classes[source]
main_reg_file = None[source]
float_reg_file = None[source]
vector_reg_file = None[source]
csr_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 = None[source]
functions_by_ext[source]
_instructions_by_class = None[source]
property instructions_by_ext[source]
property instructions_by_class[source]