1. 13
  1. 3

    On a related note, the equivalent m68k was recently merged to llvm.

    Next llvm release will thus have proper m68k support. AIUI only unix targets for now, but getting other ABIs implemented (AmigaOS, Atari TOS, Sinclair QL and so on) should be easy to do, relative to getting the m68k support done.

    1. 2

      The 6502 is notoriously hostile to being a target for C compilers. The 658c16 tweaks it enough that it could theoretically have one, but so far the best one is ORCA/C.

      1. 2

        Yeah, Forth seems a better fit. I used FIG-Forth a lot on my Apple ][ back in the day. I think it was under 8KB of code for a fairly complete environment.

        1. 1

          Is there a good explanation somewhere of “why?” it’s notoriously hostile for C compilers, for someone like myself who is not super familiar with the 6502?

          1. 2
            • C heavily uses stack for local variables and function parameters. 6502 does not have stack-relative addressing. Probably use of stack is not required by C specification and it’s just an implementation detail, but you have to store local variables somewhere at dynamic addresses and there’s no base + offset addressing in 6502. Some languages designed for such 8-bit CPUs allocate fixed memory addresses for local variables but this requires dropping support for recursion (and other things like function pointers).
            • Default type is int, which has, by specification, minimum size of 16 bits. 6502 does not have 16-bit operations. Signed 16-bit arithmetic is even more tricky and int is signed. (However you can use unsigned char in your code where possible).

            See also: Why do C to Z80 compilers produce poor code?. Z80 is slightly more powerful than 6502: it has IX and IY registers for relative addressing, but offsets are fixed and these operations are slow (compilers tend to use these registers to access stack-based variables); it has 16-bit arithmetic, but it’s limited. So mostly the same problems as for 6502.

              1. 1

                There was some discussion of how to support the 6502 on the LLVM list a few years ago. The suggestion was to not target the 6502 directly, but instead target SWEET16, which is a virtual ISA and emulator that Woz wrote as the target for Apple BASIC. SWEET16 has 16 16-bit registers and a full suite of 16-bit operations, implemented in about 300 bytes of 6502 assembly. It’s a lot slower to use than raw 6502 machine code, but it’s vaguely plausible as a target for something with a C-like abstract machine such as LLVM IR.