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:
objectManages 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
CodelinewithCodeline.lineno == linenoif 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
Codelineentries.- Return type:
list
- get_random_candidate(pop_candidate: bool = True) Codeline[source]¶
In a uniform random manner selects one
Codelineand returns it while also optionally removing it from thecandidatecollection.- Parameters:
pop_candidate (bool) – When True, deletes the
Codelinefrom the collection after identifying it.- Returns:
A random
Codelinefrom a randomself.candidateschunk.- 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_codeas a source and skips the the line which corresponds tocodeline’slinenoattribute. Theself.candidateslineno fields are updated (-1) if >= than the entry which is being restored.- Parameters:
codeline (Codeline) – The
Codelineto be removed from the assembly file.- Returns:
None