Assembly File Handling¶
The asm.py
module contains utilities to handle file I/O operations on arbitrary assembly files.
The purpose is to remove and to restore lines from the associated assembly file accurately.
ISA¶
This class, which implements the Singleton pattern, is used to parse a user-defined language file and offers utilities to check whether an arbitrary string is a valid instruction according to the language file.
Codeline¶
This is a dataclass to represent a single line of assembly code. Note that the lineno
attribute
which corresponds to the line number of the code line in the assembly file uses 0-based indexing!
AssemblyHandler¶
This class, utilises ISA
and Codeline
to parse a single assembly file and store its code
in chunks (lists) of Codeline
objects. It offers utilities for removing and restoring arbitrary
lines of code from the file while keeping track of the changes performed and accurately updating the
lineno
attributes of the stored code lines when needed.
- class asm.AssemblyHandler(isa: ISA, assembly_source: Path, chunksize: int = 1)[source]¶
Bases:
object
Manages one assembly file.
It operates on the file by removing/restoring lines of code.
- get_asm_source() Path [source]¶
Returns the assembly source file
pathlib.Path
.- Returns:
The assembly source
pathlib.Path
.- Return type:
pathlib.Path
- get_candidate(lineno: int) Codeline [source]¶
Returns the Codeline in candidates with the specified lineno
- Parameters:
lineno (int) – the line number of the candidate to be found.
- Returns:
the
Codeline
withCodeline.lineno == lineno
if found.- Return type:
- Raises:
LookUpError – If the requested Codeline does not exist
- get_code() list[Codeline] [source]¶
Returns the parsed code as a list of
Codelines
.- Returns:
A list of
Codeline
entries.- Return type:
list
- get_random_candidate(pop_candidate: bool = True) Codeline [source]¶
In a uniform random manner selects one
Codeline
and returns it while also optionally removing it from thecandidate
collection.- Parameters:
pop_candidate (bool) – When True, deletes the
Codeline
from the collection after identifying it.- Returns:
A random
Codeline
from a randomself.candidates
chunk.- Return type:
- remove(codeline: Codeline) None [source]¶
Removes the codeline from the assembly file.
Creates a new assembly file by using the current
self.asm_code
as a source and skips the the line which corresponds tocodeline
’slineno
attribute. Theself.candidates
lineno fields are updated (-1) if >= than the entry which is being restored.- Parameters:
codeline (Codeline) – The
Codeline
to be removed from the assembly file.- Returns:
None