qbe/test/abi3.ssa
Scott Graham d166a61141 Implementation of Windows amd64_win target
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.
2026-02-12 09:17:17 +01:00

46 lines
875 B
Plaintext

type :four = {l, b, w}
data $z = { w 0 }
export
function $test() {
@start
%a =w loadw $z
%y =w add %a, %a
%yl =l extsw %y
%s =l alloc8 16 # allocate a :four struct
%s1 =l add %s, 12 # get address of the w
storel 4, %s # set the l
storew 5, %s1 # set the w
# only the last argument should be on the stack
%f =l add $F, %yl
%x =w call %f(w %y, w 1, w 2, w 3, :four %s, w 6)
# store the result in the
# global variable a
%x1 =w add %y, %x
storew %x1, $a
ret
}
# >>> driver
# #include <stdio.h>
# struct four { long long l; char c; int i; };
# extern void test(void);
# int F(int a0, int a1, int a2, int a3, struct four s, int a6) {
# printf("%d %d %d %d %d %d %d\n",
# a0, a1, a2, a3, (int)s.l, s.i, a6);
# return 42;
# }
# int a;
# int main() { test(); printf("%d\n", a); return 0; }
# <<<
# >>> output
# 0 1 2 3 4 5 6
# 42
# <<<