mgbdis icon indicating copy to clipboard operation
mgbdis copied to clipboard

Support scoped local labels

Open ISSOtm opened this issue 3 years ago • 0 comments

The following currently isn't disassembled correctly:

; @00:0000
    nop
    jr $0004
    nop
00:0000 Glob1
00:0001 .local
00:0003 Glob2
00:0004 .local

This will produce the following:

Glob1::
    nop

.local:
    jr .local

Glob2::
    nop

.local:

where the jr .local line should instead be Glob2.local. This is because mgbdis does not treat local labels specially: in RGBDS, they are always scoped. meaning the SYM file above is actually invalid. See below for what is actually produced.

00:0000 Glob1
00:0001 Glob1.local
00:0003 Glob2
00:0004 Glob2.local

mgbdis actually treats labels as local only if they begin with a dot, whereas the RGBDS rule is if they contain one at all.

This is actually linked to gbdev/rgbds#483 (and #12, by extension), though the currently drafted spec agrees on what has been outlined above.

Correct behavior

mgbdis should instead apply special meaning to local labels, trimming off their leading part if it's currently in scope. (Implementing that properly is a different problem.) Note that while Glob1.local: is actually valid syntax, it's a lot noisier, and nobody writes code like that.

ISSOtm avatar Feb 01 '21 17:02 ISSOtm