flopz.arch package

Subpackages

Submodules

flopz.arch.architecture module

class Architecture(register_class=<class 'flopz.arch.register.Register'>)

Bases: object

An architecture is a combination of a set of registers and its compatible instructions.

One can sub-class architectures in order to refine. For example, it is legit to subclass an architecture for a particular MCU core

flopz.arch.auto_instruction module

class AutoInstruction(addr=0)

Bases: flopz.arch.instruction.Instruction

An AutoInstruction is a mini-module that expands into one or more architecture-specific instructions Each Auto*Type has to be implemented for each architecture individually For VLE, for example, AutoJmp could expand into se_b for short jumps or e_b for longer jumps Subclasses need to override expand() and (optionally) size_bytes() and length()

Parameters

addr (int) –

bytes()
Return type

bytes

Returns

this instruction, expanded and assembled to bytes

expand()
Return type

List[Instruction]

Returns

Regular instructions.

size_bits()
Return type

int

size_bytes()
Return type

int

flopz.arch.exceptions module

exception AutoInstructionFailure(message)

Bases: Exception

flopz.arch.instruction module

class ArbitraryBytesInstruction(bytes)

Bases: flopz.arch.instruction.Instruction

Parameters

bytes (bytes) –

bytes()
Return type

bytes

Returns

the encoded instruction as bytes

class Instruction(fmt, addr=0, bit_length=32)

Bases: flopz.core.addressable_object.AddressableObject

Parameters
  • fmt (str) –

  • addr (int) –

  • bit_length (int) –

bytes()
Return type

bytes

Returns

the encoded instruction as bytes

size_bits()
Return type

int

size_bytes()
Return type

int

flopz.arch.operands module

class BitsOperand(instruction, bitpos_start, bitpos_end, bits=None, signed=False, shift=0)

Bases: flopz.arch.operands.Operand

Class for instruction parameter setting and accessing.

Extends the basic Operand class with more capabilities and better error handling. The intended amount of bits assigned to the operand can be given to reduce implementation errors. Additionally it can be specified if the value to be encoded or read is shifted or if it is signed.

instruction

The instruction the operand is assigned to.

bitpos_start

The first bit of the instruction belonging to the operand.

bitpos_end

The first bit after the bits assigned to the operands (end of slice / exclusive).

bits

Amount of bits assigned to the operand.

signed

Is the value to be encoded signed.

shift

Is the encoded value shifted (right shift).

Parameters
  • instruction (Instruction) –

  • bitpos_start (int) –

  • bitpos_end (int) –

  • bits (Optional[int]) –

  • signed (bool) –

  • shift (int) –

class CombinedOperand(*args, signed=False, shift=0)

Bases: flopz.arch.operands.Operand

Used to combine multiple operand to represent a single value.

Many instructions have values encoded in multiple bitslices and bitpositions. A normal operand can only represent a continuous slice of bits, so this class is used to combine multiple operands to be able to represent more complex structures.

Parameters
  • *args – The operands that need to be combined. Ordered most significant operand first.

  • signed (bool) – Is the encoded value signed.

  • shift – Is the encoded value shifted.

  • args (Iterable[Any]) –

set_suboperands(full)

Sets the suboperands from msb to lsb.

class Operand(instruction, bitpos_start, bitpos_end)

Bases: object

Class for instruction parameter setting and accessing.

Operands are added to instruction classes to define how instructions encode certain parameters in their bit representation. They hold a reference to their assigned instruction and the bitpositions where they can access and set their value from/to the BitArray underlying the instruction. Bitpositions are inclusive for start, exclusive for end (like slicing etc.).

Parameters
  • instruction (Instruction) – The instruction the operand is assigned to.

  • bitpos_start (int) – The first bit of the instruction belonging to the operand.

  • bitpos_end (int) – The first bit after the bits assigned to the operands (end of slice / exclusive).

flopz.arch.register module

class Register(name, val, reg_type)

Bases: object

Parameters
  • name (str) –

  • val (int) –

  • reg_type (IntEnum) –

encode()
Return type

BitArray

Returns

this register, encoded to target architecture-specific encoding, as bitArray

static name()
value()

Module contents