mirror of
git://c9x.me/qbe.git
synced 2026-04-05 09:59:47 +00:00
This is an implementation of the Windows ABI. It supports most features (struct passing/returning, varargs, env). TLS is not yet supported. This patch does not actually port QBE to Windows, it only allows QBE to generate correct asm to target Windows. As a result, testing is accomplished on a Linux host, by using a cross-compiling toolchain, and running the resulting binaries by using wine. See: TARGET=amd64_win tools/test.sh all A few cross-platform tests were changed from 'long' to 'long long' in driver code because long in C does not match the size of a QBE 'l' on Windows.
76 lines
1.3 KiB
Plaintext
76 lines
1.3 KiB
Plaintext
# skip amd64_win (pthread and tls not implemented)
|
|
thread data $i = align 4 {w 42}
|
|
data $fmti = align 1 {b "i%d==%d\n", b 0}
|
|
|
|
thread data $x = {w 1, w 2, w 3, w 4}
|
|
data $fmtx = align 1 {b "*(x+%d)==%d\n", b 0}
|
|
|
|
export
|
|
function w $main() {
|
|
@start
|
|
%pthr =l alloc8 8
|
|
%rval =l alloc8 8
|
|
call $pthread_create(l %pthr, l 0, l $thread, l 0)
|
|
%t =l load %pthr
|
|
call $pthread_join(l %t, l %rval)
|
|
%i0 =w loadw thread $i
|
|
call $printf(l $fmti, ..., w 0, w %i0)
|
|
%i1 =w load %rval
|
|
call $printf(l $fmti, ..., w 1, w %i1)
|
|
|
|
%a0 =l call $xaddr()
|
|
%x0 =w load %a0
|
|
call $printf(l $fmtx, ..., w 0, w %x0)
|
|
%a4 =l call $xaddroff4()
|
|
%x4 =w load %a4
|
|
call $printf(l $fmtx, ..., w 4, w %x4)
|
|
%a8 =l call $xaddroff(l 8)
|
|
%x8 =w load %a8
|
|
call $printf(l $fmtx, ..., w 8, w %x8)
|
|
%xc =l call $xvalcnt(l 3)
|
|
call $printf(l $fmtx, ..., w 12, w %xc)
|
|
ret 0
|
|
}
|
|
|
|
function l $thread(l %arg) {
|
|
@start
|
|
%i3 =l add thread $i, 3
|
|
storeb 24, %i3
|
|
%ret =l loadsw thread $i
|
|
ret %ret
|
|
}
|
|
|
|
function l $xaddr() {
|
|
@start
|
|
ret thread $x
|
|
}
|
|
|
|
function l $xaddroff4() {
|
|
@start
|
|
%a =l add 4, thread $x
|
|
ret %a
|
|
}
|
|
|
|
function l $xaddroff(l %off) {
|
|
@start
|
|
%a =l add thread $x, %off
|
|
ret %a
|
|
}
|
|
|
|
function w $xvalcnt(l %cnt) {
|
|
@start
|
|
%o =l mul 4, %cnt
|
|
%a =l add thread $x, %o
|
|
%x =w load %a
|
|
ret %x
|
|
}
|
|
|
|
# >>> output
|
|
# i0==42
|
|
# i1==402653226
|
|
# *(x+0)==1
|
|
# *(x+4)==2
|
|
# *(x+8)==3
|
|
# *(x+12)==4
|
|
# <<<
|