m2isar.transforms.encode_instructions.planner

Deterministic, non-mutating planning for 32-bit custom instruction encodings.

The prototype conservatively allocates one namespace across all model containers. It never widens logical operands or infers operand attributes from their names.

Exceptions

EncodingError

An encoding request cannot be satisfied without changing its contract.

Classes

EncodingPolicy

Field

Assignment

EncodingPlan

Functions

validate_pattern(code, mask)

overlaps(a, b)

operand_requirements(instruction)

candidates(instruction)

available_codes(mask, opcodes, occupied[, required])

Search discriminator bits, pruning subtrees covered by a reservation.

plan_encodings(instructions[, policy, existing, ...])

Plan an iterable of unencoded instructions. Optional manifest pins assignments.

apply_encoding_plan(instructions, plan[, copy])

Return encoded copies by default; validate everything before in-place updates.

model_instructions(model)

Collect shared instructions once, giving them stable qualified names.

plan_model(model[, policy, assignments])

apply_model_plan(model, plan)

Apply to a complete model copy, preserving aliases and updating containers.

Module Contents

exception EncodingError[source]

Bases: ValueError

An encoding request cannot be satisfied without changing its contract.

class EncodingPolicy[source]
opcodes: Tuple[int, ...] = (11, 43, 91, 123)[source]
reservations: Tuple[Tuple[int, int], ...] = ()[source]
fixed_bits: Tuple[Tuple[str, int, int], ...] = ()[source]
decode_mask: int = 4294967295[source]
__post_init__()[source]
validate_pattern(code, mask)[source]
overlaps(a, b)[source]
class Field[source]
name: str[source]
offset: int[source]
width: int[source]
signed: bool[source]
source_lower: int = 0[source]
class Assignment[source]
name: str[source]
layout: str[source]
code: int[source]
mask: int[source]
fields: Tuple[Field, ...][source]
encoding()[source]

Emit metamodel fields without changing operand descriptors or behavior.

to_dict()[source]
class EncodingPlan[source]
assignments: Tuple[Assignment, ...][source]
errors: Tuple[str, ...] = ()[source]
raise_for_errors()[source]
explain()[source]
to_dict()[source]
operand_requirements(instruction)[source]
candidates(instruction)[source]
available_codes(mask, opcodes, occupied, required=(0, 0))[source]

Search discriminator bits, pruning subtrees covered by a reservation.

plan_encodings(instructions, policy=None, existing=(), assignments=None)[source]

Plan an iterable of unencoded instructions. Optional manifest pins assignments.

Names must be unique. Existing encodings are (code, mask) pairs in this domain. Errors are collected and prevent application of the entire plan.

apply_encoding_plan(instructions, plan, copy=True)[source]

Return encoded copies by default; validate everything before in-place updates.

model_instructions(model)[source]

Collect shared instructions once, giving them stable qualified names.

plan_model(model, policy=None, assignments=None)[source]
apply_model_plan(model, plan)[source]

Apply to a complete model copy, preserving aliases and updating containers.