Skip to content

Commit 47bba10

Browse files
committed
Put filename in asm context
ASM contexts now puts the filename in #line directives for better error reporting.
1 parent f23728d commit 47bba10

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/arch/zx48k/backend/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,7 @@ def _inline(ins):
18031803

18041804
ASMLABEL = new_ASMID()
18051805
ASMS[ASMLABEL] = tmp
1806-
output.append('#line %s' % ins.quad[2])
18071806
output.append(ASMLABEL)
1808-
output.append('#line %i' % (int(ins.quad[2]) + len(tmp)))
18091807

18101808
return output
18111809

@@ -2095,7 +2093,7 @@ def __str__(self):
20952093
'out': [2, _out], # Defines a OUT instruction OUT x, y
20962094
'in': [1, _in], # Defines an IN instruction IN x, y
20972095

2098-
'inline': [2, _inline], # Defines an inline asm instruction
2096+
'inline': [1, _inline], # Defines an inline asm instruction
20992097

21002098
'cast': [4, _cast],
21012099
# TYPECAST: X = cast(from Type1, to Type2, Y) Ej. Converts Y 16bit to X 8bit: (cast, x, u16, u8, y)

src/arch/zx48k/translator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def visit_ON_GOSUB(self, node):
626626

627627
def visit_CHKBREAK(self, node):
628628
if self.PREV_TOKEN != node.token:
629-
self.ic_inline('push hl', node.children[0].t)
629+
self.ic_inline('push hl')
630630
self.ic_fparam(gl.PTR_TYPE, node.children[0].t)
631631
self.ic_call('CHECK_BREAK', 0)
632632
backend.REQUIRES.add('break.asm')
@@ -906,7 +906,10 @@ def visit_ITALIC(self, node):
906906
# Other Sentences, like ASM, etc..
907907
# -----------------------------------------------------------------------------------------------------
908908
def visit_ASM(self, node):
909-
self.ic_inline(node.asm, node.lineno)
909+
EOL = '\n'
910+
self.ic_inline(f'#line {node.lineno} "{node.filename}"')
911+
self.ic_inline(node.asm)
912+
self.ic_inline(f'#line {node.lineno + 1 + len(node.asm.split(EOL))} "{node.filename}"')
910913

911914
# endregion
912915

src/arch/zx48k/translatorinstvisitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def ic_gt(self, type_, t, t1, t2):
109109
def ic_in(self, t):
110110
return self.emit('in', t)
111111

112-
def ic_inline(self, asm_code: str, t):
113-
return self.emit('inline', asm_code, t)
112+
def ic_inline(self, asm_code: str):
113+
return self.emit('inline', asm_code)
114114

115115
def ic_jgezero(self, type_, t, label: str):
116116
return self.emit('jgezero' + self.TSUFFIX(type_), t, label)

src/libzxbc/zxbc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def main(args=None, emitter=None):
252252
# Emits jump tables
253253
translator.emit_jump_tables()
254254
# Signals end of user code
255-
translator.ic_inline(';; --- end of user code ---', zxblex.lexer.lineno)
255+
translator.ic_inline(';; --- end of user code ---')
256256

257257
if OPTIONS.emitBackend:
258258
with open_file(OPTIONS.outputFileName, 'wt', 'utf-8') as output_file:

0 commit comments

Comments
 (0)