diff options
| author | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-10-11 16:21:21 +0200 |
|---|---|---|
| committer | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-10-11 16:21:21 +0200 |
| commit | 69c55d68d68c00007afa1af76a1d06f74ee72fe6 (patch) | |
| tree | 991b92b4a5ba447b9fb5f77db4377bd9d14fbdf9 /snapshot.py | |
| parent | b9c08cadc158b18d7cab14a830a9e11f590ec7bd (diff) | |
| download | focaccia-69c55d68d68c00007afa1af76a1d06f74ee72fe6.tar.gz focaccia-69c55d68d68c00007afa1af76a1d06f74ee72fe6.zip | |
Refactor file structure
- main.py: focaccia user-interface - snapshot.py: state trace snapshots handling - compare.py: snapshot comparison algorithms - run.py: native execution tracer - arancini.py: Arancini log handling - arch/: per-architecture abstractions Co-authored-by: Theofilos Augoustis <theofilos.augoustis@gmail.com> Co-authored-by: Nicola Crivellin <nicola.crivellin98@gmail.com>
Diffstat (limited to 'snapshot.py')
| -rw-r--r-- | snapshot.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/snapshot.py b/snapshot.py new file mode 100644 index 0000000..d5136ad --- /dev/null +++ b/snapshot.py @@ -0,0 +1,38 @@ +from arch.arch import Arch + +class ProgramState(): + """A snapshot of the program's state.""" + def __init__(self, arch: Arch): + self.arch = arch + + dict_t = dict[str, int] + self.regs = dict_t({ reg: None for reg in arch.regnames }) + self.has_backwards = False + self.matched = False + + def set_backwards(self): + self.has_backwards = True + + def set(self, reg: str, value: int): + """Assign a value to a register. + + :raises RuntimeError: if the register already has a value. + """ + assert(reg in self.arch.regnames) + + if self.regs[reg] != None: + raise RuntimeError("Reassigning register") + self.regs[reg] = value + + def as_repr(self, reg: str): + """Get a representational string of a register's value.""" + assert(reg in self.arch.regnames) + + value = self.regs[reg] + if value is not None: + return hex(value) + else: + return "<none>" + + def __repr__(self): + return self.regs.__repr__() |