stage2: implement RISCV C ABI
This commit is contained in:
@@ -16,6 +16,10 @@ static void assert_or_panic(bool ok) {
|
||||
# define ZIG_PPC32
|
||||
#endif
|
||||
|
||||
#if defined __riscv && defined _ILP32
|
||||
# define ZIG_RISCV32
|
||||
#endif
|
||||
|
||||
#ifdef __i386__
|
||||
# define ZIG_NO_I128
|
||||
#endif
|
||||
@@ -32,6 +36,10 @@ static void assert_or_panic(bool ok) {
|
||||
# define ZIG_NO_I128
|
||||
#endif
|
||||
|
||||
#ifdef ZIG_RISCV32
|
||||
# define ZIG_NO_I128
|
||||
#endif
|
||||
|
||||
#ifdef __i386__
|
||||
# define ZIG_NO_COMPLEX
|
||||
#endif
|
||||
@@ -48,6 +56,10 @@ static void assert_or_panic(bool ok) {
|
||||
# define ZIG_NO_COMPLEX
|
||||
#endif
|
||||
|
||||
#ifdef __riscv
|
||||
# define ZIG_NO_COMPLEX
|
||||
#endif
|
||||
|
||||
#ifndef ZIG_NO_I128
|
||||
struct i128 {
|
||||
__int128 value;
|
||||
@@ -265,7 +277,7 @@ void run_c_tests(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
|
||||
#if !defined __mips__ && !defined ZIG_PPC32
|
||||
{
|
||||
struct BigStruct s = {1, 2, 3, 4, 5};
|
||||
zig_big_struct(s);
|
||||
@@ -273,7 +285,7 @@ void run_c_tests(void) {
|
||||
#endif
|
||||
|
||||
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
|
||||
!defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
!defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
{
|
||||
struct SmallStructInts s = {1, 2, 3, 4};
|
||||
zig_small_struct_ints(s);
|
||||
@@ -299,14 +311,14 @@ void run_c_tests(void) {
|
||||
}
|
||||
|
||||
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
|
||||
!defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
!defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
{
|
||||
struct SplitStructInts s = {1234, 100, 1337};
|
||||
zig_split_struct_ints(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __arm__ && !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
#if !defined __arm__ && !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
{
|
||||
struct MedStructMixed s = {1234, 100.0f, 1337.0f};
|
||||
zig_med_struct_mixed(s);
|
||||
@@ -314,14 +326,14 @@ void run_c_tests(void) {
|
||||
#endif
|
||||
|
||||
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
|
||||
!defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
!defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
{
|
||||
struct SplitStructMixed s = {1234, 100, 1337.0f};
|
||||
zig_split_struct_mixed(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
|
||||
#if !defined __mips__ && !defined ZIG_PPC32
|
||||
{
|
||||
struct BigStruct s = {30, 31, 32, 33, 34};
|
||||
struct BigStruct res = zig_big_struct_both(s);
|
||||
@@ -333,7 +345,7 @@ void run_c_tests(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __riscv && !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
#if !defined ZIG_PPC32 && !defined _ARCH_PPC64
|
||||
{
|
||||
struct Rect r1 = {1, 21, 16, 4};
|
||||
struct Rect r2 = {178, 189, 21, 15};
|
||||
@@ -341,7 +353,7 @@ void run_c_tests(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __mips__ && !defined __riscv && !defined ZIG_PPC32
|
||||
#if !defined __mips__ && !defined ZIG_PPC32
|
||||
{
|
||||
struct FloatRect r1 = {1, 21, 16, 4};
|
||||
struct FloatRect r2 = {178, 189, 21, 15};
|
||||
@@ -354,9 +366,7 @@ void run_c_tests(void) {
|
||||
|
||||
assert_or_panic(zig_ret_u8() == 0xff);
|
||||
assert_or_panic(zig_ret_u16() == 0xffff);
|
||||
#ifndef __riscv
|
||||
assert_or_panic(zig_ret_u32() == 0xffffffff);
|
||||
#endif
|
||||
assert_or_panic(zig_ret_u64() == 0xffffffffffffffff);
|
||||
|
||||
assert_or_panic(zig_ret_i8() == -1);
|
||||
|
||||
@@ -171,7 +171,7 @@ extern fn c_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat;
|
||||
extern fn c_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble;
|
||||
|
||||
const complex_abi_compatible = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isMIPS() and
|
||||
!builtin.cpu.arch.isARM() and !builtin.cpu.arch.isPPC();
|
||||
!builtin.cpu.arch.isARM() and !builtin.cpu.arch.isPPC() and !builtin.cpu.arch.isRISCV();
|
||||
|
||||
test "C ABI complex float" {
|
||||
if (!complex_abi_compatible) return error.SkipZigTest;
|
||||
@@ -265,7 +265,6 @@ extern fn c_big_struct(BigStruct) void;
|
||||
|
||||
test "C ABI big struct" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
|
||||
var s = BigStruct{
|
||||
@@ -292,7 +291,6 @@ const BigUnion = extern union {
|
||||
extern fn c_big_union(BigUnion) void;
|
||||
|
||||
test "C ABI big union" {
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
|
||||
var x = BigUnion{
|
||||
@@ -327,7 +325,6 @@ extern fn c_ret_med_struct_mixed() MedStructMixed;
|
||||
test "C ABI medium struct of ints and floats" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -361,7 +358,6 @@ extern fn c_ret_small_struct_ints() SmallStructInts;
|
||||
test "C ABI small struct of ints" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -444,7 +440,6 @@ extern fn c_split_struct_ints(SplitStructInt) void;
|
||||
test "C ABI split struct of ints" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -473,7 +468,6 @@ extern fn c_ret_split_struct_mixed() SplitStructMixed;
|
||||
test "C ABI split struct of ints and floats" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -502,7 +496,6 @@ extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;
|
||||
|
||||
test "C ABI sret and byval together" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
|
||||
var s = BigStruct{
|
||||
@@ -555,7 +548,6 @@ extern fn c_big_struct_floats(Vector5) void;
|
||||
|
||||
test "C ABI structs of floats as parameter" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -596,7 +588,6 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {
|
||||
}
|
||||
|
||||
test "C ABI structs of ints as multiple parameters" {
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -635,7 +626,6 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
|
||||
|
||||
test "C ABI structs of floats as multiple parameters" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
|
||||
var r1 = FloatRect{
|
||||
@@ -741,7 +731,6 @@ extern fn c_ret_struct_with_array() StructWithArray;
|
||||
test "Struct with array as padding." {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
@@ -768,7 +757,6 @@ extern fn c_ret_float_array_struct() FloatArrayStruct;
|
||||
|
||||
test "Float array like struct" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
|
||||
c_float_array_struct(.{
|
||||
@@ -796,7 +784,6 @@ extern fn c_ret_small_vec() SmallVec;
|
||||
|
||||
test "small simd vector" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
|
||||
|
||||
c_small_vec(.{ 1, 2 });
|
||||
|
||||
Reference in New Issue
Block a user