3 ms·
I'm porting LLVM/Clang to the 6502. Notoriously difficult project, attempted dozens of times by as many folks. https://github.com/mysterymath/clang6502 https:/
by mysterymath 6y ago
I'm porting LLVM/Clang to the 6502. Notoriously difficult project, attempted dozens of times by as many folks.
https://github.com/mysterymath/clang6502 https://github.com/mysterymath/clang6502
My take generates pretty darn good assembly for the cases it handles, but it's absurdly incomplete. Still, a huge amount of risk factors have already been addressed, and there's only a few big known unknowns left.
Example input:
void print_int(char x) {
if (x < 10) {
x += '0';
asm volatile ("JSR\t$FFD2" : "+a"(x));
return;
}
print_int(x / 10);
print_int(x % 10);
}
Example output:
.code
.global print__int ; -- Begin function print_int
print__int: ; @print_int
; %bb.0: ; %entry
CMP #10
BMI LBB0__2
; %bb.1: ; %if.end.preheader
LDX #10
PHA ; 1-byte Folded Spill
JSR ____udivqi3
JSR print__int
PLA ; 1-byte Folded Reload
LDX #10
JSR ____umodqi3
LBB0__2: ; %if.then
CLC
ADC #48
;APP
JSR $FFD2
;NO_APP
RTS
; -- End function
.global ____udivqi3
.global ____umodqi3
- rzzzt 6y agoOMF:2097 profile picture spotted! Loved the game as a child. Will the compiler support 65C02 instructions?
- mysterymath 6y agoShouldn't be too hard to add later, since they're mostly just swizzles onto the existing instructions, and LLVM already has good support for registering slightly different versions of a target (subtargeting). For now, I'm targeting the plain-jane MOS chip, since it's the buggiest and least capable, and thus the most difficult.