diff options
| author | s-ol <s+removethis@s-ol.nu> | 2021-05-23 09:15:25 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2021-05-23 09:15:25 +0000 |
| commit | f89982437be8154a9c77527faee2459f0957a450 (patch) | |
| tree | e977ecdfc81f96d36a5432e5430cfc405e4ce02b /pack.py | |
| parent | log offending line when errors occur, across all stages (diff) | |
| download | subv-f89982437be8154a9c77527faee2459f0957a450.tar.gz subv-f89982437be8154a9c77527faee2459f0957a450.zip | |
revert to code detection by segment
Diffstat (limited to 'pack.py')
| -rwxr-xr-x | pack.py | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -64,8 +64,6 @@ def byteify(word): @subv.with_parsed_lines def pack(iter): - segment = None - out = [] buf = bits.empty @@ -73,31 +71,34 @@ def pack(iter): tmp = out[:] out.clear() return { - 'type': 'data', - 'data': tmp, + 'type': 'instr', + 'instr': tmp, 'comment': None, } - for line in iter: - if line['type'] == 'data': - for part in line['data']: - buf = bits.concat(buf, bits.from_part(part)) - while buf[1] >= 8: - byte = bits.slice(buf, 7, 0) - buf = bits.slice(buf, buf[1] - 1, 8, allow_empty=True) - out.append(byte[:1]) - - if len(out) == 4: - yield subv.format(flush_bytes()) - else: + last_segment = None + for segment, line in iter: + if last_segment != segment: assert buf[1] == 0, "segment '{}' end isn't byte-aligned".format(segment) if out: yield subv.format(flush_bytes()) - if line['type'] == 'segment': - segment = line['segment'][0] + if line['type'] == 'instr': + for part in line['instr']: + buf = bits.concat(buf, bits.from_part(part)) + else: yield line['raw'] + while buf[1] >= 8: + byte = bits.slice(buf, 7, 0) + buf = bits.slice(buf, buf[1] - 1, 8, allow_empty=True) + out.append(byte[:1]) + + if len(out) == 4: + yield subv.format(flush_bytes()) + + last_segment = segment + assert buf[1] == 0, "segment '{}' end isn't byte-aligned".format(segment) if __name__ == '__main__': |
