aboutsummaryrefslogtreecommitdiffstats
path: root/pack.py
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-05-23 09:15:25 +0000
committers-ol <s+removethis@s-ol.nu>2021-05-23 09:15:25 +0000
commitf89982437be8154a9c77527faee2459f0957a450 (patch)
treee977ecdfc81f96d36a5432e5430cfc405e4ce02b /pack.py
parentlog offending line when errors occur, across all stages (diff)
downloadsubv-f89982437be8154a9c77527faee2459f0957a450.tar.gz
subv-f89982437be8154a9c77527faee2459f0957a450.zip
revert to code detection by segment
Diffstat (limited to 'pack.py')
-rwxr-xr-xpack.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/pack.py b/pack.py
index 29949b4..f717df4 100755
--- a/pack.py
+++ b/pack.py
@@ -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__':