diff options
| author | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-08-20 17:04:24 +0200 |
|---|---|---|
| committer | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-08-20 17:04:24 +0200 |
| commit | 96094b79c8e3cc2583272a9daf06a19189c67176 (patch) | |
| tree | 181b371c7a603f3663385933474c3337ed88cb05 | |
| parent | 3731d78bb21601936141c037405c36d0cffa2385 (diff) | |
| download | focaccia-96094b79c8e3cc2583272a9daf06a19189c67176.tar.gz focaccia-96094b79c8e3cc2583272a9daf06a19189c67176.zip | |
Add initial support for diffs between snapshots
| -rwxr-xr-x | compare.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/compare.py b/compare.py index 36cc9c7..b5bc87e 100755 --- a/compare.py +++ b/compare.py @@ -3,6 +3,7 @@ import re import sys import shutil import argparse +from typing import List from functools import partial as bind from utils import check_version @@ -71,6 +72,15 @@ class Constructor: self.cblocks[-1].regs[key] = value +class Transformations: + def __init__(self, previous: ContextBlock, current: ContextBlock): + self.transformation = ContextBlock() + for el1 in current.regs.keys(): + for el2 in previous.regs.keys(): + if el1 != el2: + continue + self.transformation.regs[el1] = current.regs[el1] - previous.regs[el2] + def parse(lines: list, labels: list): ctor = Constructor(labels) @@ -115,10 +125,15 @@ def get_labels(): 'flag DF': split_second} return labels -def equivalent(val1, val2): - return val1 == val2 +def equivalent(val1, val2, transformation, previous_translation): + if val1 == val2: + return True + + # TODO: maybe incorrect + return val1 - previous_translation == transformation -def verify(translation: ContextBlock, reference: ContextBlock): +def verify(translation: ContextBlock, reference: ContextBlock, + transformation: Transformations, previous_translation: ContextBlock): if translation.regs["PC"] != reference.regs["PC"]: return 1 @@ -138,11 +153,12 @@ def verify(translation: ContextBlock, reference: ContextBlock): print(f'Element not available in reference: {el2}') continue - if not equivalent(translation.regs[el1], reference.regs[el2]): + if not equivalent(translation.regs[el1], reference.regs[el2], + transformation.regs[el1], previous_translation.regs[el1]): print(f'Difference for {el1}: {hex(translation.regs[el1])} != {hex(reference.regs[el2])}') return 0 -def compare(txl: list, native: list, stats: bool = False): +def compare(txl: List[ContextBlock], native: List[ContextBlock], stats: bool = False): txl = parse(txl, get_labels()) native = parse(native, get_labels()) @@ -150,9 +166,13 @@ def compare(txl: list, native: list, stats: bool = False): print(f'Different number of blocks discovered translation: {len(txl)} vs. ' f'reference: {len(native)}', file=sys.stderr) + previous_reference = native[0] + previous_translation = txl[0] + unmatched_pcs = {} for translation, reference in zip(txl, native): - if verify(translation, reference) == 1: + transformations = Transformations(previous_reference, reference) + if verify(translation, reference, transformations.transformation, previous_translation) == 1: # TODO: add verbose output print_separator(stream=sys.stderr) print(f'No match for PC {hex(translation.regs["PC"])}', file=sys.stderr) @@ -160,6 +180,9 @@ def compare(txl: list, native: list, stats: bool = False): unmatched_pcs[translation.regs['PC']] = 0 unmatched_pcs[translation.regs['PC']] += 1 + previous_reference = reference + previous_translation = translation + if stats: print_separator() print('Statistics:') |