aboutsummaryrefslogtreecommitdiffstats
path: root/format.py
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-05-22 16:23:57 +0000
committers-ol <s+removethis@s-ol.nu>2021-05-22 16:24:36 +0000
commit0658187afb830fbcf082950b30f0be6cea4455a0 (patch)
treebc174c1d648951157ff7957f1bdf8f34e9e2ae72 /format.py
parentsupport non-byte aligned data lines (diff)
downloadsubv-0658187afb830fbcf082950b30f0be6cea4455a0.tar.gz
subv-0658187afb830fbcf082950b30f0be6cea4455a0.zip
log offending line when errors occur, across all stages
Diffstat (limited to 'format.py')
-rwxr-xr-xformat.py57
1 files changed, 20 insertions, 37 deletions
diff --git a/format.py b/format.py
index 419f6df..aa6c8ba 100755
--- a/format.py
+++ b/format.py
@@ -282,44 +282,27 @@ instr_map = {
'jal': (pack_j, 0x6f),
}
+@subv.with_parsed_lines
def format(iter):
- for line_no, raw_line in enumerate(iter, start=1):
- try:
- line = subv.parse(raw_line)
- except AssertionError as e:
- message = '''
-failed to format line:
-<input>:{} {}
-parsed as {}
- '''.strip().format(line_no, raw_line.strip())
- raise Exception(message) from e
-
- try:
- if line['type'] == 'instr':
- op = line['instr'][0]
- assert len(op) == 2, 'instruction without op label: {}'.format(op)
-
- (op, label) = op
- if label not in instr_map:
- raise ValueError("unknown instruction label: {}".format(label))
- (formatter, expected) = instr_map[label]
- if op != expected:
- raise ValueError("opcode {} doesn't match label {} (expected {})"
- .format(op, label, expected))
-
- formatted = formatter(line['instr'])
- formatted[0] = (*formatted[0], label)
- line['instr'] = formatted
- yield subv.format(line)
- else:
- yield line['raw']
- except AssertionError as e:
- message = '''
-failed to format line:
-<input>:{} {}
-parsed as {}
- '''.strip().format(line_no, raw_line.strip(), subv.dump(line))
- raise Exception(message) from e
+ for line in iter:
+ if line['type'] == 'instr':
+ op = line['instr'][0]
+ assert len(op) == 2, 'instruction without op label: {}'.format(op)
+
+ (op, label) = op
+ if label not in instr_map:
+ raise ValueError("unknown instruction label: {}".format(label))
+ (formatter, expected) = instr_map[label]
+ if op != expected:
+ raise ValueError("opcode {} doesn't match label {} (expected {})"
+ .format(op, label, expected))
+
+ formatted = formatter(line['instr'])
+ formatted[0] = (*formatted[0], label)
+ line['instr'] = formatted
+ line = yield subv.format(line)
+ else:
+ line = yield line['raw']
if __name__ == '__main__':
import sys