Hi,
I’ve been hacking minic to try and add return types and variadic
arguments - https://github.com/DangerMouseB/minc. So far I quite
like it however I’m hitting some snags with QBE:
I’ve compiled this C program with clang:
char LF3() {return 10;}
And compiled this QBE IR program:
export function uh $LF() {
@start
%t =w mul 12, 256
%t =w add %t, 10
call $printf(l $gLF, ..., w %t, w %t, ub 10)
ret %t
}
export function w $LF2() {
@start
%t =w add 10, 0
ret %t
}
export function w $main(w %.0, l %.1) {
@start
# uh version
%pA =l call $LF()
call $printf(l $gpA, ..., l %pA, l %pA, ub 10)
%A =w loaduh %pA
call $printf(l $gA, ..., w %A, w %A, ub 10)
call $printf(l $gA, ..., uh %A, uh %A, ub 10)
call $printf(l $gA, ..., ub %A, ub %A, ub 10)
%B =w extub %A
call $printf(l $gB, ..., w %B, w %B, ub 10)
%C =w call $LF2()
call $printf(l $gC, ..., ub %C, ub %C, ub 10)
# C version
%D =ub call $LF3()
call $printf(l $gD, ..., ub %D, ub %D, ub 10)
ret 0
}
data $gLF = { b "LF: 0x%.8x %d %c", b 0 }
data $gpA = { b "pA: 0x%.16x %llu %c", b 0 }
data $gA = { b "A: 0x%.8x %d %c", b 0 }
data $gB = { b "B: 0x%.8x %d %c", b 0 }
data $gC = { b "C: 0x%.8x %d %c", b 0 }
data $gD = { b "D: 0x%.8x %d %c", b 0 }
If I make LF’s signature to be:
export function ub $LF
QBE gives me:
arm64/emit.c: dying: invalid class
So I can only get LF to work if I return a uh AND I treat
the result as a pointer to a uh. When I call LF3 (the C function) I can
treat the return value as a char rather than a char*.
1) is the error with ub a bug or my mistake?
2) is there a way to return a char from a QBE function as opposed to a
char*?
For reference current output is:
LF: 0x00000c0a 3082
pA: 0x00000000041e3fa8 4364058536
A: 0x00000c0a 3082
A: 0x00000c0a 3082
A: 0x0000000a 10
B: 0x0000000a 10
C: 0x0000000a 10
D: 0x0000000a 10
This is on macOS with an M1.
Thanks for your help.
-- David