gbdev / gbdev/rgbds

Opt-in link-time lint warnings, e.g. when ld can be ldh, or jp can be jr

Open
#1,017 7 comments 3 reactions 0 assignees View on GitHub
enhancement rgbasm rgblink
Dominant language
C++
Stars
1.6k
Forks
193
Avg merge
22h 17m
Merged PRs (30d)
26

Description

These would be useful as opt-in link-time warnings:

- [ ] For every `ld`, check for and suggest using `ldh` instead if possible.

(This would be an improved substitute for the removed feature of `rgbasm -L`, which optimized known-constant `ld` to `ldh`.)

- [ ] For every `jp`, check for and suggest using `jr` instead if possible.

- [ ] For every `jp` and `jr`, check for redundant jumps to the location immediately after the instruction, and suggest `; fallthrough` instead.

- [ ] For every control flow instruction (`call`, `jp`, `jr`, `rst`) targeting a label in ROMX, do a lint equivalent of `assert BANK(@) == 0 || BANK() == 0 || BANK(@) == BANK()`.

(`rst` always targets ROM0, but if we add support for swappable ROM0, possibly via HDFs (#524), then this would be multi-banked.)

Do this only if PC is in a ROMX section, which also excludes `LOAD`. (In theory, `BANK(@) != 0` for ROMX, but `-t` maps ROMX to ROM0. The destination is then guaranteed to be in ROM0 as well, but that may not remain the case if we add some similar feature to HDFs, so a cheap stringent check for `BANK(@) == 0` is good for future-proofing.)

(Possibly make this a multi-level lint, where by default cross-SECTION jumps are not checked?)

Contributor guide

Open the contributing guide

Research direction

Start by locating the link-time diagnostics and control-flow analysis for ld, jp, jr, call, and rst; the issue names no source files or tests. Define the opt-in and possible multi-level lint behavior, then add checks for ldh/jr substitutions, redundant fallthrough jumps, and ROMX bank targets, with tests showing each warning and its suppression or non-warning cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.