diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/asm_ops.py | 4 | ||||
| -rw-r--r-- | src/asm_pass3.py | 19 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/asm_ops.py b/src/asm_ops.py index 78ec356..a2631e3 100644 --- a/src/asm_ops.py +++ b/src/asm_ops.py @@ -76,8 +76,8 @@ def make_jpi(meta: Meta, symbols: Symbols, imm: str) -> int: imm_e = eval_expr(symbols, imm, bits=9) imm_e = imm_e - meta.address - 1 imm_e = imm_e & (0b111111111) - print("symbols:", symbols) - print(meta, imm, f"0x{imm_e:>0x}") + #print("symbols:", symbols) + #print(meta, imm, f"0x{imm_e:>0x}") word = (0b0110 << 12) + \ imm_e return word diff --git a/src/asm_pass3.py b/src/asm_pass3.py index 5221f6d..edfd79f 100644 --- a/src/asm_pass3.py +++ b/src/asm_pass3.py @@ -50,7 +50,7 @@ def pass_3(result2: Result2) -> Result3: rows_with_same_addr = list(filter(lambda l: l.address == result_line.address, result_lines)) n = len(rows_with_same_addr) if n > 1: - formatted = "\n".join(map(lambda l: " ".join(l.parts), rows_with_same_addr)) + formatted = format_overlapping_rows(rows_with_same_addr) raise Exception(f"Overlapping segments: address 0x{result_line.address:>04x} has conflicting definitions:\n{formatted}") return Result3( operations=result2.operations, @@ -58,3 +58,20 @@ def pass_3(result2: Result2) -> Result3: lines=result_lines, symbols=symbols, ) + +def format_overlapping_rows(rows: list[Result3Line]) -> str: + longest_val = 0 + for row in rows: + joined = " ".join(row.parts) + if len(joined) > longest_val: + longest_val = len(joined) + + first_col_width = longest_val + 4 + + results: list[str] = [] + for row in rows: + joined = " ".join(row.parts) + result = joined + (first_col_width - len(joined)) * " " + f" ({row.src_file}:{row.line_num})" + results.append(result) + + return "\n".join(results) |
