[llvm-dev] Having trouble getting started on writing a WDC 65816 backend

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 10 13:29:07 PDT 2019


Hi,

On Wed, 10 Jul 2019 at 20:44, via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> <srnb> I'm trying to write an LLVM backend for the WDC 65816 (for usage in compiling SNES code) but I have very little experience with how C++ works and LLVM's CMakeLists. I'm trying to follow the guide but I don't know how to check if the project builds after my changes or how to test a small amount of C with it once I get it working.

You might try searching the list for past discussions of 6502 since
many of the problems will be similar.

As I recall the big one is that LLVM isn't well adapted to instruction
sets without fungible registers. One idea is to use some of bank 0 as
a source of registers, maybe with a custom pass to promote things to
real registers where possible after the fact. The other main one was
to design a virtual machine runtime on top of the basic instructions
with a more friendly instruction set; LLVM would then generate VM
opcodes, and you'd always link in the runtime to actually execute it.

I'm afraid I haven't thought enough to decide which approach I'd take
(or why) if it was me.

> <srnb> - How do I handle ROM banks? ( https://stackoverflow.com/questions/56925635/equivalent-of-org-in-llvm-ir )
> <srnb> - Does it make sense to use `ENVIRONMENT` (where it's usually either `gnu` or `musl`) for the different ROM types? (`lorom`, `hirom`, `sa1`, etc)

I think it could be made to work, but the physical start address would
normally be handled by a linker. If you're trying to avoid a linker
entirely, many hacks are possible.

The wider issue of different ROM banks (how pointers must be defined
and accessed so that all possible values are in range) looks more like
a CodeModel on other targets to me (with existing values of tiny,
small, medium, ... but you could make your own if you don't like
those).

> <srnb> - The assembler I want to target is one that's not very known outside of the Super Mario World RomHacking community. Who's job is it to assemble what LLVM outputs, and how?

Most LLVM targets implement an assembler too so that they don't have
to call out to an external program. But you don't have to do that, and
if you want to start out using an external assembler then at some
point you'll probably want to teach Clang how to invoke it properly
(the alternative is telling your users they have to add lines to their
build system to do it, which is also fine to begin with). I believe
the key code is in clang/lib/Driver/ToolChains, for copy/paste
purposes.

> It got buried under join/leave messages and build alerts.

A perennial pain in the neck. I have join/leave suppressed and even
put  llvmbb on ignore most of the time. It's astonishing how much more
readable IRC becomes.

> I'm using CLion on Windows with Msys2-mingw64 (my VoidLinux-musl installation isn't that great for development yet). Importing the project works correctly, but I don't know how to build the project or test the project or test my backend.

That I can't help you with I'm afraid. I get the impression most of us
here use CMake/ninja directly to do builds (see
https://llvm.org/docs/GettingStarted.html), and maybe an IDE to edit
the source files. I certainly do.

Cheers.

Tim.


More information about the llvm-dev mailing list