mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
delete all the translate-c tests
the ziglang/translate-c package has its own test suite, so these are redundant
This commit is contained in:
parent
f49a54745b
commit
1bdcdbd996
55 changed files with 21 additions and 6900 deletions
48
build.zig
48
build.zig
|
|
@ -90,8 +90,6 @@ pub fn build(b: *std.Build) !void {
|
|||
const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
|
||||
const skip_single_threaded = b.option(bool, "skip-single-threaded", "Main test suite skips tests that are single-threaded") orelse false;
|
||||
const skip_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") orelse false;
|
||||
const skip_translate_c = b.option(bool, "skip-translate-c", "Main test suite skips translate-c tests") orelse false;
|
||||
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse skip_translate_c;
|
||||
const skip_freebsd = b.option(bool, "skip-freebsd", "Main test suite skips targets with freebsd OS") orelse false;
|
||||
const skip_netbsd = b.option(bool, "skip-netbsd", "Main test suite skips targets with netbsd OS") orelse false;
|
||||
const skip_windows = b.option(bool, "skip-windows", "Main test suite skips targets with windows OS") orelse false;
|
||||
|
|
@ -416,7 +414,7 @@ pub fn build(b: *std.Build) !void {
|
|||
test_step.dependOn(check_fmt);
|
||||
|
||||
const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
|
||||
try tests.addCases(b, test_cases_step, target, .{
|
||||
try tests.addCases(b, test_cases_step, .{
|
||||
.test_filters = test_filters,
|
||||
.test_target_filters = test_target_filters,
|
||||
.skip_compile_errors = skip_compile_errors,
|
||||
|
|
@ -428,9 +426,6 @@ pub fn build(b: *std.Build) !void {
|
|||
.skip_linux = skip_linux,
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = skip_libc,
|
||||
}, .{
|
||||
.skip_translate_c = skip_translate_c,
|
||||
.skip_run_translated_c = skip_run_translated_c,
|
||||
}, .{
|
||||
.enable_llvm = enable_llvm,
|
||||
.llvm_has_m68k = llvm_has_m68k,
|
||||
|
|
@ -465,27 +460,25 @@ pub fn build(b: *std.Build) !void {
|
|||
.max_rss = 4000000000,
|
||||
}));
|
||||
|
||||
if (!skip_translate_c) {
|
||||
test_modules_step.dependOn(tests.addModuleTests(b, .{
|
||||
.test_filters = test_filters,
|
||||
.test_target_filters = test_target_filters,
|
||||
.test_extra_targets = test_extra_targets,
|
||||
.root_src = "test/c_import.zig",
|
||||
.name = "c-import",
|
||||
.desc = "Run the @cImport tests",
|
||||
.optimize_modes = optimization_modes,
|
||||
.include_paths = &.{"test/c_import"},
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
.skip_netbsd = skip_netbsd,
|
||||
.skip_windows = skip_windows,
|
||||
.skip_macos = skip_macos,
|
||||
.skip_linux = skip_linux,
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = skip_libc,
|
||||
}));
|
||||
}
|
||||
test_modules_step.dependOn(tests.addModuleTests(b, .{
|
||||
.test_filters = test_filters,
|
||||
.test_target_filters = test_target_filters,
|
||||
.test_extra_targets = test_extra_targets,
|
||||
.root_src = "test/c_import.zig",
|
||||
.name = "c-import",
|
||||
.desc = "Run the @cImport tests",
|
||||
.optimize_modes = optimization_modes,
|
||||
.include_paths = &.{"test/c_import"},
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
.skip_netbsd = skip_netbsd,
|
||||
.skip_windows = skip_windows,
|
||||
.skip_macos = skip_macos,
|
||||
.skip_linux = skip_linux,
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = skip_libc,
|
||||
}));
|
||||
|
||||
test_modules_step.dependOn(tests.addModuleTests(b, .{
|
||||
.test_filters = test_filters,
|
||||
|
|
@ -577,7 +570,6 @@ pub fn build(b: *std.Build) !void {
|
|||
enable_macos_sdk,
|
||||
enable_ios_sdk,
|
||||
enable_symlinks_windows,
|
||||
skip_translate_c,
|
||||
));
|
||||
test_step.dependOn(tests.addCAbiTests(b, .{
|
||||
.test_target_filters = test_target_filters,
|
||||
|
|
|
|||
|
|
@ -22,33 +22,6 @@ This will do `zig run` on the code and expect exit code 0.
|
|||
// run
|
||||
```
|
||||
|
||||
## Translate-c
|
||||
|
||||
If you want to test translating C code to Zig use `translate-c`:
|
||||
|
||||
```c
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// pub const foo = 1;
|
||||
// pub const immediately_after_foo = 2;
|
||||
//
|
||||
// pub const somewhere_else_in_the_file = 3:
|
||||
```
|
||||
|
||||
## Run Translated C
|
||||
|
||||
If you want to test translating C code to Zig and then executing it use `run-translated-c`:
|
||||
|
||||
```c
|
||||
// run-translated-c
|
||||
// c_frontend=aro,clang
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// Hello world!
|
||||
```
|
||||
|
||||
## Incremental Compilation
|
||||
|
||||
Make multiple files that have ".", and then an integer, before the ".zig"
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
int main() {
|
||||
int i = 2;
|
||||
float f = 3.2f;
|
||||
|
||||
i += 1.7;
|
||||
if (i != 3) return 1;
|
||||
i += f;
|
||||
if (i != 6) return 2;
|
||||
|
||||
|
||||
f += 2UL;
|
||||
if (f <= 5.1999 || f >= 5.2001) return 3;
|
||||
f += i;
|
||||
if (f <= 11.1999 || f >= 11.2001) return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
int main() {
|
||||
const char *s = "forgreatjustice";
|
||||
unsigned int add = 1;
|
||||
|
||||
s += add;
|
||||
if (*s != 'o') return 1;
|
||||
|
||||
s += 1UL;
|
||||
if (*s != 'r') return 2;
|
||||
|
||||
const char *s2 = (s += add);
|
||||
if (*s2 != 'g') return 3;
|
||||
|
||||
s2 -= add;
|
||||
if (*s2 != 'r') return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
int main(void) {
|
||||
int i = 0;
|
||||
*&i = 42;
|
||||
if (i != 42) abort();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
// link_libc=true
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
int main() {
|
||||
float f = 2.0f;
|
||||
bool b = (bool) f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
const int ev = 40;
|
||||
|
||||
static int func(void)
|
||||
{
|
||||
typedef int test_type_t;
|
||||
extern const test_type_t ev;
|
||||
// Ensure mangled name is also being used for conditions and loops, see #20828
|
||||
if (ev == 0);
|
||||
while (ev == 0);
|
||||
do; while (ev == 0);
|
||||
return ev + 2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (func() != 42)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
int main() {
|
||||
float f = (float)(10.0f > 1.0f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
int a = 42;
|
||||
int foo(int bar) {
|
||||
extern int a;
|
||||
if (bar) {
|
||||
return a;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int main() {
|
||||
int result1 = foo(0);
|
||||
if (result1 != 0) abort();
|
||||
int result2 = foo(1);
|
||||
if (result2 != 42) abort();
|
||||
a = 100;
|
||||
int result3 = foo(1);
|
||||
if (result3 != 100) abort();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// run-translated-c
|
||||
// c_frontend=clang
|
||||
// link_libc=true
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
_Static_assert(1 == 1, "");
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=aro
|
||||
//
|
||||
// tmp.c:1:1: warning: ignoring _Static_assert declaration
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
__attribute__ ((aligned(128)))
|
||||
extern char my_array[16];
|
||||
__attribute__ ((aligned(128)))
|
||||
void my_fn(void) { }
|
||||
void other_fn(void) {
|
||||
char ARR[16] __attribute__ ((aligned (16)));
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub extern var my_array: [16]u8 align(128);
|
||||
// pub export fn my_fn() align(128) void {}
|
||||
// pub export fn other_fn() void {
|
||||
// var ARR: [16]u8 align(16) = undefined;
|
||||
// _ = &ARR;
|
||||
// }
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
void assert(int x) {}
|
||||
#define FOO assert(0 && "error message")
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const FOO = assert((@as(c_int, 0) != 0) and (@intFromPtr("error message") != 0));
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
typedef _Atomic(int) AtomicInt;
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=aro
|
||||
//
|
||||
// tmp.c:1:22: warning: unsupported type: '_Atomic(int)'
|
||||
// pub const AtomicInt = @compileError("unable to resolve typedef child type");
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
#define GUARDED_INT_ADDITION(int) ((int) + 1)
|
||||
|
||||
#define UNGUARDED_INT_SUBTRACTION(int) (int - 2)
|
||||
|
||||
#define GUARDED_INT_MULTIPLY(int) ((int) * 3)
|
||||
|
||||
#define UNGUARDED_INT_DIVIDE(int) (int / 4)
|
||||
|
||||
#define WRAPPED_RETURN(return) ((return) % 2)
|
||||
|
||||
#define UNWRAPPED_RETURN(return) (return ^ 0x7F)
|
||||
|
||||
#define WITH_TWO_PARAMETERS(signed, x) ((signed) + (x) + 9)
|
||||
|
||||
#define GUARDED_ALIGNOF(_Alignof) ((_Alignof) & 0x55)
|
||||
|
||||
#define UNGUARDED_ALIGNOF(_Alignof) (_Alignof | 0x80)
|
||||
|
||||
#define GUARDED_SIZEOF(sizeof) ((sizeof) == 64)
|
||||
|
||||
#define UNGUARDED_SIZEOF(sizeof) (sizeof < 64)
|
||||
|
||||
#define SIZEOF(x) ((int)sizeof(x))
|
||||
|
||||
#define SIZEOF2(x) ((int)sizeof x)
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub inline fn GUARDED_INT_ADDITION(int: anytype) @TypeOf(int + @as(c_int, 1)) {
|
||||
// _ = ∫
|
||||
// return int + @as(c_int, 1);
|
||||
// }
|
||||
// pub inline fn UNGUARDED_INT_SUBTRACTION(int: anytype) @TypeOf(int - @as(c_int, 2)) {
|
||||
// _ = ∫
|
||||
// return int - @as(c_int, 2);
|
||||
// }
|
||||
// pub inline fn GUARDED_INT_MULTIPLY(int: anytype) @TypeOf(int * @as(c_int, 3)) {
|
||||
// _ = ∫
|
||||
// return int * @as(c_int, 3);
|
||||
// }
|
||||
// pub inline fn UNGUARDED_INT_DIVIDE(int: anytype) @TypeOf(@import("std").zig.c_translation.MacroArithmetic.div(int, @as(c_int, 4))) {
|
||||
// _ = ∫
|
||||
// return @import("std").zig.c_translation.MacroArithmetic.div(int, @as(c_int, 4));
|
||||
// }
|
||||
// pub inline fn WRAPPED_RETURN(@"return": anytype) @TypeOf(@import("std").zig.c_translation.MacroArithmetic.rem(@"return", @as(c_int, 2))) {
|
||||
// _ = &@"return";
|
||||
// return @import("std").zig.c_translation.MacroArithmetic.rem(@"return", @as(c_int, 2));
|
||||
// }
|
||||
// pub inline fn UNWRAPPED_RETURN(@"return": anytype) @TypeOf(@"return" ^ @as(c_int, 0x7F)) {
|
||||
// _ = &@"return";
|
||||
// return @"return" ^ @as(c_int, 0x7F);
|
||||
// }
|
||||
// pub inline fn WITH_TWO_PARAMETERS(signed: anytype, x: anytype) @TypeOf((signed + x) + @as(c_int, 9)) {
|
||||
// _ = &signed;
|
||||
// _ = &x;
|
||||
// return (signed + x) + @as(c_int, 9);
|
||||
// }
|
||||
// pub inline fn GUARDED_ALIGNOF(_Alignof: anytype) @TypeOf(_Alignof & @as(c_int, 0x55)) {
|
||||
// _ = &_Alignof;
|
||||
// return _Alignof & @as(c_int, 0x55);
|
||||
// }
|
||||
// pub inline fn UNGUARDED_ALIGNOF(_Alignof: anytype) @TypeOf(_Alignof | @as(c_int, 0x80)) {
|
||||
// _ = &_Alignof;
|
||||
// return _Alignof | @as(c_int, 0x80);
|
||||
// }
|
||||
// pub inline fn GUARDED_SIZEOF(sizeof: anytype) @TypeOf(sizeof == @as(c_int, 64)) {
|
||||
// _ = &sizeof;
|
||||
// return sizeof == @as(c_int, 64);
|
||||
// }
|
||||
// pub inline fn UNGUARDED_SIZEOF(sizeof: anytype) @TypeOf(sizeof < @as(c_int, 64)) {
|
||||
// _ = &sizeof;
|
||||
// return sizeof < @as(c_int, 64);
|
||||
// }
|
||||
// pub inline fn SIZEOF(x: anytype) c_int {
|
||||
// _ = &x;
|
||||
// return @import("std").zig.c_translation.cast(c_int, @import("std").zig.c_translation.sizeof(x));
|
||||
// }
|
||||
// pub inline fn SIZEOF2(x: anytype) c_int {
|
||||
// _ = &x;
|
||||
// return @import("std").zig.c_translation.cast(c_int, @import("std").zig.c_translation.sizeof(x));
|
||||
// }
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
struct Bar;
|
||||
|
||||
struct Foo {
|
||||
struct Bar *next;
|
||||
};
|
||||
|
||||
struct Bar {
|
||||
struct Foo *next;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_Bar = extern struct {
|
||||
// next: [*c]struct_Foo = @import("std").mem.zeroes([*c]struct_Foo),
|
||||
// };
|
||||
//
|
||||
// pub const struct_Foo = extern struct {
|
||||
// next: [*c]struct_Bar = @import("std").mem.zeroes([*c]struct_Bar),
|
||||
// };
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
void foo() {
|
||||
for (;;) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub export fn foo() void {
|
||||
// while (true) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
typedef struct Bar Bar;
|
||||
typedef struct Foo Foo;
|
||||
|
||||
struct Foo {
|
||||
Foo *a;
|
||||
};
|
||||
|
||||
struct Bar {
|
||||
Foo *a;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_Foo = extern struct {
|
||||
// a: [*c]Foo = @import("std").mem.zeroes([*c]Foo),
|
||||
// };
|
||||
//
|
||||
// pub const Foo = struct_Foo;
|
||||
//
|
||||
// pub const struct_Bar = extern struct {
|
||||
// a: [*c]Foo = @import("std").mem.zeroes([*c]Foo),
|
||||
// };
|
||||
//
|
||||
// pub const Bar = struct_Bar;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
;
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang,aro
|
||||
//
|
||||
//
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
union U {
|
||||
int x;
|
||||
long y;
|
||||
};
|
||||
|
||||
void foo(void) {
|
||||
union U u = {};
|
||||
}
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const union_U = extern union {
|
||||
// x: c_int,
|
||||
// y: c_long,
|
||||
// };
|
||||
// pub export fn foo() void {
|
||||
// var u: union_U = @import("std").mem.zeroes(union_U);
|
||||
// _ = &u;
|
||||
// }
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
enum Foo {
|
||||
FooA = 2,
|
||||
FooB = 5,
|
||||
Foo1,
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-windows-msvc
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const FooA: c_int = 2;
|
||||
// pub const FooB: c_int = 5;
|
||||
// pub const Foo1: c_int = 6;
|
||||
// pub const enum_Foo = c_int;
|
||||
//
|
||||
// pub const Foo = enum_Foo;
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
enum Foo {
|
||||
FooA = 2,
|
||||
FooB = 5,
|
||||
Foo1,
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=clang,aro
|
||||
//
|
||||
// pub const FooA: c_int = 2;
|
||||
// pub const FooB: c_int = 5;
|
||||
// pub const Foo1: c_int = 6;
|
||||
// pub const enum_Foo = c_uint;
|
||||
//
|
||||
// pub const Foo = enum_Foo;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
unsigned long foo(unsigned long x) {
|
||||
return ((union{unsigned long _x}){x})._x;
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub export fn foo(arg_x: c_ulong) c_ulong {
|
||||
// var x = arg_x;
|
||||
// _ = &x;
|
||||
// const union_unnamed_1 = extern union {
|
||||
// _x: c_ulong,
|
||||
// };
|
||||
// _ = &union_unnamed_1;
|
||||
// return (union_unnamed_1{
|
||||
// ._x = x,
|
||||
// })._x;
|
||||
// }
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
void (f0) (void *L);
|
||||
void ((f1)) (void *L);
|
||||
void (((f2))) (void *L);
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang,aro
|
||||
//
|
||||
// pub extern fn f0(L: ?*anyopaque) void;
|
||||
// pub extern fn f1(L: ?*anyopaque) void;
|
||||
// pub extern fn f2(L: ?*anyopaque) void;
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
struct foo {
|
||||
int x;
|
||||
};
|
||||
const char *struct_foo = "hello world";
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_foo_1 = extern struct {
|
||||
// x: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
//
|
||||
// pub const foo = struct_foo_1;
|
||||
//
|
||||
// pub export var struct_foo: [*c]const u8 = "hello world";
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
struct __attribute__((packed)) bar {
|
||||
short a;
|
||||
float b;
|
||||
double c;
|
||||
short x;
|
||||
float y;
|
||||
double z;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub const struct_bar = extern struct {
|
||||
// a: c_short align(1) = @import("std").mem.zeroes(c_short),
|
||||
// b: f32 align(1) = @import("std").mem.zeroes(f32),
|
||||
// c: f64 align(1) = @import("std").mem.zeroes(f64),
|
||||
// x: c_short align(1) = @import("std").mem.zeroes(c_short),
|
||||
// y: f32 align(1) = @import("std").mem.zeroes(f32),
|
||||
// z: f64 align(1) = @import("std").mem.zeroes(f64),
|
||||
// };
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#define SYSV_ABI __attribute__((sysv_abi))
|
||||
void SYSV_ABI foo(void);
|
||||
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
// target=x86_64-windows
|
||||
//
|
||||
// pub extern fn foo() callconv(.{ .x86_64_sysv = .{} }) void;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#define bar() ""
|
||||
#define FOO bar() "," bar()
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub inline fn bar() @TypeOf("") {
|
||||
// return "";
|
||||
// }
|
||||
// pub const FOO = bar() ++ "," ++ bar();
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
extern float foo;
|
||||
#define FOO_TWICE foo * 2.0f
|
||||
#define FOO_NEGATIVE -foo
|
||||
|
||||
#define BAR 10.0f
|
||||
#define BAR_TWICE BAR * 2.0f
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub extern var foo: f32;
|
||||
//
|
||||
// pub inline fn FOO_TWICE() @TypeOf(foo * @as(f32, 2.0)) {
|
||||
// return foo * @as(f32, 2.0);
|
||||
// }
|
||||
//
|
||||
// pub inline fn FOO_NEGATIVE() @TypeOf(-foo) {
|
||||
// return -foo;
|
||||
// }
|
||||
// pub const BAR = @as(f32, 10.0);
|
||||
// pub const BAR_TWICE = BAR * @as(f32, 2.0);
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
void foo(void) __attribute__((noreturn));
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub extern fn foo() noreturn;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// NOTE: The nested struct is *not* packed/aligned,
|
||||
// even though the parent struct is
|
||||
// this is consistent with GCC docs
|
||||
union Foo{
|
||||
short x;
|
||||
double y;
|
||||
struct {
|
||||
int b;
|
||||
} z;
|
||||
} __attribute__((packed));
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// const struct_unnamed_1 = extern struct {
|
||||
// b: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
//
|
||||
// pub const union_Foo = extern union {
|
||||
// x: c_short align(1),
|
||||
// y: f64 align(1),
|
||||
// z: struct_unnamed_1 align(1),
|
||||
// };
|
||||
//
|
||||
// pub const Foo = union_Foo;
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
union Foo {
|
||||
short x;
|
||||
double y;
|
||||
} __attribute__((packed));
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub const union_Foo = extern union {
|
||||
// x: c_short align(1),
|
||||
// y: f64 align(1),
|
||||
// };
|
||||
//
|
||||
// pub const Foo = union_Foo;
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
struct Foo {
|
||||
unsigned int: 1;
|
||||
};
|
||||
struct Bar {
|
||||
struct Foo *foo;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_Foo = opaque {};
|
||||
//
|
||||
// pub const struct_Bar = extern struct {
|
||||
// foo: ?*struct_Foo = @import("std").mem.zeroes(?*struct_Foo),
|
||||
// };
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
struct Foo {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
enum Bar {
|
||||
BarA,
|
||||
BarB,
|
||||
};
|
||||
void func(struct Foo *a, enum Bar **b);
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// pub const struct_Foo = extern struct {
|
||||
// x: c_int = @import("std").mem.zeroes(c_int),
|
||||
// y: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// pub const BarA: c_int = 0;
|
||||
// pub const BarB: c_int = 1;
|
||||
// pub const enum_Bar = c_uint;
|
||||
// pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void;
|
||||
//
|
||||
// pub const Foo = struct_Foo;
|
||||
// pub const Bar = enum_Bar;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
struct Foo {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
enum Bar {
|
||||
BarA,
|
||||
BarB,
|
||||
};
|
||||
void func(struct Foo *a, enum Bar **b);
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
// target=x86_64-windows-msvc
|
||||
//
|
||||
// pub const struct_Foo = extern struct {
|
||||
// x: c_int = @import("std").mem.zeroes(c_int),
|
||||
// y: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// pub const BarA: c_int = 0;
|
||||
// pub const BarB: c_int = 1;
|
||||
// pub const enum_Bar = c_int;
|
||||
// pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void;
|
||||
//
|
||||
// pub const Foo = struct_Foo;
|
||||
// pub const Bar = enum_Bar;
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
void foo() {
|
||||
struct Foo {
|
||||
int A;
|
||||
int B;
|
||||
int C;
|
||||
};
|
||||
struct Foo a = {0};
|
||||
{
|
||||
struct Foo {
|
||||
int A;
|
||||
int B;
|
||||
int C;
|
||||
};
|
||||
struct Foo a = {0};
|
||||
}
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub export fn foo() void {
|
||||
// const struct_Foo = extern struct {
|
||||
// A: c_int = @import("std").mem.zeroes(c_int),
|
||||
// B: c_int = @import("std").mem.zeroes(c_int),
|
||||
// C: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// _ = &struct_Foo;
|
||||
// var a: struct_Foo = struct_Foo{
|
||||
// .A = @as(c_int, 0),
|
||||
// .B = 0,
|
||||
// .C = 0,
|
||||
// };
|
||||
// _ = &a;
|
||||
// {
|
||||
// const struct_Foo_1 = extern struct {
|
||||
// A: c_int = @import("std").mem.zeroes(c_int),
|
||||
// B: c_int = @import("std").mem.zeroes(c_int),
|
||||
// C: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// _ = &struct_Foo_1;
|
||||
// var a_2: struct_Foo_1 = struct_Foo_1{
|
||||
// .A = @as(c_int, 0),
|
||||
// .B = 0,
|
||||
// .C = 0,
|
||||
// };
|
||||
// _ = &a_2;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
void __attribute__((noreturn)) foo(void);
|
||||
int bar(void);
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang,aro
|
||||
//
|
||||
// pub extern fn foo() noreturn;
|
||||
// pub extern fn bar() c_int;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
struct Foo {
|
||||
int x;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// const struct_Foo = extern struct {
|
||||
// x: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
//
|
||||
// pub const Foo = struct_Foo;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
union Foo {
|
||||
int x;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub const union_Foo = extern union {
|
||||
// x: c_int,
|
||||
// };
|
||||
//
|
||||
// pub const Foo = union_Foo;
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
struct empty_struct {};
|
||||
|
||||
static inline void foo() {
|
||||
static struct empty_struct bar = {};
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_empty_struct = extern struct {};
|
||||
// pub fn foo() callconv(.c) void {
|
||||
// const bar = struct {
|
||||
// var static: struct_empty_struct = @import("std").mem.zeroes(struct_empty_struct);
|
||||
// };
|
||||
// _ = &bar;
|
||||
// }
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
void foo() { if(0 && "error message") {} }
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub export fn foo() void {
|
||||
// if (false and (@intFromPtr("error message") != 0)) {}
|
||||
// }
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
struct Foo;
|
||||
struct Foo *some_func(struct Foo *foo, int x);
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang,aro
|
||||
//
|
||||
// pub const struct_Foo = opaque {};
|
||||
// pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
|
||||
//
|
||||
// pub const Foo = struct_Foo;
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
struct Foo {
|
||||
int a;
|
||||
struct Bar {
|
||||
int a;
|
||||
} b;
|
||||
} a = {};
|
||||
#define PTR void *
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_Bar_1 = extern struct {
|
||||
// a: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// pub const struct_Foo = extern struct {
|
||||
// a: c_int = @import("std").mem.zeroes(c_int),
|
||||
// b: struct_Bar_1 = @import("std").mem.zeroes(struct_Bar_1),
|
||||
// };
|
||||
// pub export var a: struct_Foo = struct_Foo{
|
||||
// .a = 0,
|
||||
// .b = @import("std").mem.zeroes(struct_Bar_1),
|
||||
// };
|
||||
//
|
||||
// pub const PTR = ?*anyopaque;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
struct foo {
|
||||
__attribute__((aligned(4))) short bar;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub const struct_foo = extern struct {
|
||||
// bar: c_short align(4) = @import("std").mem.zeroes(c_short),
|
||||
// };
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// The aligned attribute cannot decrease the alignment of a field. The packed attribute is required
|
||||
// for decreasing the alignment. gcc and clang will compile these structs without error
|
||||
// (and possibly without warning), but checking the alignment will reveal a different value than
|
||||
// what was requested. This is consistent with the gcc documentation on type attributes.
|
||||
//
|
||||
// This test is currently broken for the clang frontend. See issue #19307.
|
||||
|
||||
struct foo {
|
||||
__attribute__((aligned(1)))int x;
|
||||
};
|
||||
|
||||
struct bar {
|
||||
__attribute__((aligned(2)))float y;
|
||||
};
|
||||
|
||||
struct baz {
|
||||
__attribute__((aligned(4)))double z;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// pub const struct_foo = extern struct {
|
||||
// x: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
//
|
||||
// pub const struct_bar = extern struct {
|
||||
// y: f32 = @import("std").mem.zeroes(f32),
|
||||
// };
|
||||
//
|
||||
// pub const struct_baz = extern struct {
|
||||
// z: f64 = @import("std").mem.zeroes(f64),
|
||||
// };
|
||||
//
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// When clang uses the <arch>-windows-none, triple it behaves as MSVC and
|
||||
// interprets the inner `struct Bar` as an anonymous structure
|
||||
struct Foo {
|
||||
struct Bar{
|
||||
int b;
|
||||
};
|
||||
struct Bar c;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
// target=x86_64-linux-gnu
|
||||
//
|
||||
// pub const struct_Bar_1 = extern struct {
|
||||
// b: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// pub const struct_Foo = extern struct {
|
||||
// c: struct_Bar_1 = @import("std").mem.zeroes(struct_Bar_1),
|
||||
// };
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
union { int x; char c[4]; }
|
||||
ua = {1},
|
||||
ub = {.c={'a','b','b','a'}};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
//
|
||||
// const union_unnamed_1 = extern union {
|
||||
// x: c_int,
|
||||
// c: [4]u8,
|
||||
// };
|
||||
// pub export var ua: union_unnamed_1 = union_unnamed_1{
|
||||
// .x = @as(c_int, 1),
|
||||
// };
|
||||
// pub export var ub: union_unnamed_1 = union_unnamed_1{
|
||||
// .c = [4]u8{
|
||||
// 'a',
|
||||
// 'b',
|
||||
// 'b',
|
||||
// 'a',
|
||||
// },
|
||||
// };
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
struct A;
|
||||
union B;
|
||||
enum C;
|
||||
|
||||
struct A {
|
||||
short x;
|
||||
double y;
|
||||
};
|
||||
|
||||
union B {
|
||||
short x;
|
||||
double y;
|
||||
};
|
||||
|
||||
struct Foo {
|
||||
struct A a;
|
||||
union B b;
|
||||
};
|
||||
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub const struct_A = extern struct {
|
||||
// x: c_short = @import("std").mem.zeroes(c_short),
|
||||
// y: f64 = @import("std").mem.zeroes(f64),
|
||||
// };
|
||||
//
|
||||
// pub const union_B = extern union {
|
||||
// x: c_short,
|
||||
// y: f64,
|
||||
// };
|
||||
//
|
||||
// pub const struct_Foo = extern struct {
|
||||
// a: struct_A = @import("std").mem.zeroes(struct_A),
|
||||
// b: union_B = @import("std").mem.zeroes(union_B),
|
||||
// };
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
struct a {
|
||||
struct { int x; };
|
||||
};
|
||||
struct b {
|
||||
struct { int y; };
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// const struct_unnamed_1 = extern struct {
|
||||
// x: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// pub const struct_a = extern struct {
|
||||
// unnamed_0: struct_unnamed_1 = @import("std").mem.zeroes(struct_unnamed_1),
|
||||
// };
|
||||
// const struct_unnamed_2 = extern struct {
|
||||
// y: c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
// pub const struct_b = extern struct {
|
||||
// unnamed_0: struct_unnamed_2 = @import("std").mem.zeroes(struct_unnamed_2),
|
||||
// };
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include <stddef.h>
|
||||
ptrdiff_t sub_ptr(void *a, void *b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// c_frontend=clang
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// pub export fn sub_ptr(arg_a: ?*anyopaque, arg_b: ?*anyopaque) ptrdiff_t {
|
||||
// var a = arg_a;
|
||||
// _ = &a;
|
||||
// var b = arg_b;
|
||||
// _ = &b;
|
||||
// return @as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b)));
|
||||
// }
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
struct __attribute__((packed)) foo {
|
||||
int x;
|
||||
struct {};
|
||||
float y;
|
||||
union {};
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro
|
||||
//
|
||||
// const struct_unnamed_1 = extern struct {};
|
||||
// const union_unnamed_2 = extern union {};
|
||||
// pub const struct_foo = extern struct {
|
||||
// x: c_int align(1) = @import("std").mem.zeroes(c_int),
|
||||
// unnamed_0: struct_unnamed_1 align(1) = @import("std").mem.zeroes(struct_unnamed_1),
|
||||
// y: f32 align(1) = @import("std").mem.zeroes(f32),
|
||||
// unnamed_1: union_unnamed_2 align(1) = @import("std").mem.zeroes(union_unnamed_2),
|
||||
// };
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
struct comptime {
|
||||
int defer;
|
||||
};
|
||||
|
||||
// translate-c
|
||||
// c_frontend=aro,clang
|
||||
//
|
||||
// pub const struct_comptime = extern struct {
|
||||
// @"defer": c_int = @import("std").mem.zeroes(c_int),
|
||||
// };
|
||||
//
|
||||
// pub const @"comptime" = struct_comptime;
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;
|
|||
gpa: Allocator,
|
||||
arena: Allocator,
|
||||
cases: std.array_list.Managed(Case),
|
||||
translate: std.array_list.Managed(Translate),
|
||||
|
||||
pub const IncrementalCase = struct {
|
||||
base_path: []const u8,
|
||||
|
|
@ -127,25 +126,6 @@ pub const Case = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub const Translate = struct {
|
||||
/// The name of the test case. This is shown if a test fails, and
|
||||
/// otherwise ignored.
|
||||
name: []const u8,
|
||||
|
||||
input: [:0]const u8,
|
||||
target: std.Build.ResolvedTarget,
|
||||
link_libc: bool,
|
||||
c_frontend: CFrontend,
|
||||
kind: union(enum) {
|
||||
/// Translate the input, run it and check that it
|
||||
/// outputs the expected text.
|
||||
run: []const u8,
|
||||
/// Translate the input and check that it contains
|
||||
/// the expected lines of code.
|
||||
translate: []const []const u8,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn addExe(
|
||||
ctx: *Cases,
|
||||
name: []const u8,
|
||||
|
|
@ -374,7 +354,6 @@ fn addFromDirInner(
|
|||
|
||||
const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend);
|
||||
const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", std.Target.Query);
|
||||
const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend);
|
||||
const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool);
|
||||
const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool);
|
||||
const output_mode = try manifest.getConfigForKeyAssertSingle("output_mode", std.builtin.OutputMode);
|
||||
|
|
@ -384,39 +363,6 @@ fn addFromDirInner(
|
|||
const emit_bin = try manifest.getConfigForKeyAssertSingle("emit_bin", bool);
|
||||
const imports = try manifest.getConfigForKeyAlloc(ctx.arena, "imports", []const u8);
|
||||
|
||||
if (manifest.type == .translate_c) {
|
||||
for (c_frontends) |c_frontend| {
|
||||
for (targets) |target_query| {
|
||||
const output = try manifest.trailingLinesSplit(ctx.arena);
|
||||
try ctx.translate.append(.{
|
||||
.name = try caseNameFromPath(ctx.arena, filename),
|
||||
.c_frontend = c_frontend,
|
||||
.target = b.resolveTargetQuery(target_query),
|
||||
.link_libc = link_libc,
|
||||
.input = src,
|
||||
.kind = .{ .translate = output },
|
||||
});
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (manifest.type == .run_translated_c) {
|
||||
for (c_frontends) |c_frontend| {
|
||||
for (targets) |target_query| {
|
||||
const output = try manifest.trailingSplit(ctx.arena);
|
||||
try ctx.translate.append(.{
|
||||
.name = try caseNameFromPath(ctx.arena, filename),
|
||||
.c_frontend = c_frontend,
|
||||
.target = b.resolveTargetQuery(target_query),
|
||||
.link_libc = link_libc,
|
||||
.input = src,
|
||||
.kind = .{ .run = output },
|
||||
});
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
var cases = std.array_list.Managed(usize).init(ctx.arena);
|
||||
|
||||
// Cross-product to get all possible test combinations
|
||||
|
|
@ -484,101 +430,11 @@ fn addFromDirInner(
|
|||
pub fn init(gpa: Allocator, arena: Allocator) Cases {
|
||||
return .{
|
||||
.gpa = gpa,
|
||||
.cases = std.array_list.Managed(Case).init(gpa),
|
||||
.translate = std.array_list.Managed(Translate).init(gpa),
|
||||
.cases = .init(gpa),
|
||||
.arena = arena,
|
||||
};
|
||||
}
|
||||
|
||||
pub const TranslateCOptions = struct {
|
||||
skip_translate_c: bool = false,
|
||||
skip_run_translated_c: bool = false,
|
||||
};
|
||||
pub fn lowerToTranslateCSteps(
|
||||
self: *Cases,
|
||||
b: *std.Build,
|
||||
parent_step: *std.Build.Step,
|
||||
test_filters: []const []const u8,
|
||||
test_target_filters: []const []const u8,
|
||||
target: std.Build.ResolvedTarget,
|
||||
translate_c_options: TranslateCOptions,
|
||||
) void {
|
||||
const tests = @import("../tests.zig");
|
||||
const test_translate_c_step = b.step("test-translate-c", "Run the C translation tests");
|
||||
if (!translate_c_options.skip_translate_c) {
|
||||
tests.addTranslateCTests(b, test_translate_c_step, test_filters, test_target_filters);
|
||||
parent_step.dependOn(test_translate_c_step);
|
||||
}
|
||||
|
||||
const test_run_translated_c_step = b.step("test-run-translated-c", "Run the Run-Translated-C tests");
|
||||
if (!translate_c_options.skip_run_translated_c) {
|
||||
tests.addRunTranslatedCTests(b, test_run_translated_c_step, test_filters, target);
|
||||
parent_step.dependOn(test_run_translated_c_step);
|
||||
}
|
||||
|
||||
for (self.translate.items) |case| switch (case.kind) {
|
||||
.run => |output| {
|
||||
if (translate_c_options.skip_run_translated_c) continue;
|
||||
const annotated_case_name = b.fmt("run-translated-c {s}", .{case.name});
|
||||
for (test_filters) |test_filter| {
|
||||
if (std.mem.indexOf(u8, annotated_case_name, test_filter)) |_| break;
|
||||
} else if (test_filters.len > 0) continue;
|
||||
if (!std.process.can_spawn) {
|
||||
std.debug.print("Unable to spawn child processes on {s}, skipping test.\n", .{@tagName(builtin.os.tag)});
|
||||
continue; // Pass test.
|
||||
}
|
||||
|
||||
const write_src = b.addWriteFiles();
|
||||
const file_source = write_src.add("tmp.c", case.input);
|
||||
|
||||
const translate_c = b.addTranslateC(.{
|
||||
.root_source_file = file_source,
|
||||
.optimize = .Debug,
|
||||
.target = case.target,
|
||||
.link_libc = case.link_libc,
|
||||
.use_clang = case.c_frontend == .clang,
|
||||
});
|
||||
translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name});
|
||||
|
||||
const run_exe = b.addExecutable(.{
|
||||
.name = "translated_c",
|
||||
.root_module = translate_c.createModule(),
|
||||
});
|
||||
run_exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name});
|
||||
run_exe.root_module.link_libc = true;
|
||||
const run = b.addRunArtifact(run_exe);
|
||||
run.step.name = b.fmt("{s} run", .{annotated_case_name});
|
||||
run.expectStdOutEqual(output);
|
||||
run.skip_foreign_checks = true;
|
||||
|
||||
test_run_translated_c_step.dependOn(&run.step);
|
||||
},
|
||||
.translate => |output| {
|
||||
if (translate_c_options.skip_translate_c) continue;
|
||||
const annotated_case_name = b.fmt("zig translate-c {s}", .{case.name});
|
||||
for (test_filters) |test_filter| {
|
||||
if (std.mem.indexOf(u8, annotated_case_name, test_filter)) |_| break;
|
||||
} else if (test_filters.len > 0) continue;
|
||||
|
||||
const write_src = b.addWriteFiles();
|
||||
const file_source = write_src.add("tmp.c", case.input);
|
||||
|
||||
const translate_c = b.addTranslateC(.{
|
||||
.root_source_file = file_source,
|
||||
.optimize = .Debug,
|
||||
.target = case.target,
|
||||
.link_libc = case.link_libc,
|
||||
.use_clang = case.c_frontend == .clang,
|
||||
});
|
||||
translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name});
|
||||
|
||||
const check_file = translate_c.addCheckFile(output);
|
||||
check_file.step.name = b.fmt("{s} CheckFile", .{annotated_case_name});
|
||||
test_translate_c_step.dependOn(&check_file.step);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub const CaseTestOptions = struct {
|
||||
test_filters: []const []const u8,
|
||||
test_target_filters: []const []const u8,
|
||||
|
|
|
|||
|
|
@ -7,14 +7,10 @@ const Step = std.Build.Step;
|
|||
|
||||
// Cases
|
||||
const stack_traces = @import("stack_traces.zig");
|
||||
const translate_c = @import("translate_c.zig");
|
||||
const run_translated_c = @import("run_translated_c.zig");
|
||||
const llvm_ir = @import("llvm_ir.zig");
|
||||
const libc = @import("libc.zig");
|
||||
|
||||
// Implementations
|
||||
pub const TranslateCContext = @import("src/TranslateC.zig");
|
||||
pub const RunTranslatedCContext = @import("src/RunTranslatedC.zig");
|
||||
pub const StackTracesContext = @import("src/StackTrace.zig");
|
||||
pub const DebuggerContext = @import("src/Debugger.zig");
|
||||
pub const LlvmIrContext = @import("src/LlvmIr.zig");
|
||||
|
|
@ -1901,7 +1897,6 @@ pub fn addStandaloneTests(
|
|||
enable_macos_sdk: bool,
|
||||
enable_ios_sdk: bool,
|
||||
enable_symlinks_windows: bool,
|
||||
skip_translate_c: bool,
|
||||
) *Step {
|
||||
const step = b.step("test-standalone", "Run the standalone tests");
|
||||
if (compilerHasPackageManager(b)) {
|
||||
|
|
@ -1914,7 +1909,6 @@ pub fn addStandaloneTests(
|
|||
.simple_skip_release_safe = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSafe) == null,
|
||||
.simple_skip_release_fast = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseFast) == null,
|
||||
.simple_skip_release_small = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSmall) == null,
|
||||
.skip_translate_c = skip_translate_c,
|
||||
});
|
||||
const test_cases_dep_step = test_cases_dep.builder.default_step;
|
||||
test_cases_dep_step.name = b.dupe(test_cases_dep_name);
|
||||
|
|
@ -2155,42 +2149,6 @@ pub fn addCliTests(b: *std.Build) *Step {
|
|||
return step;
|
||||
}
|
||||
|
||||
pub fn addTranslateCTests(
|
||||
b: *std.Build,
|
||||
parent_step: *std.Build.Step,
|
||||
test_filters: []const []const u8,
|
||||
test_target_filters: []const []const u8,
|
||||
) void {
|
||||
const cases = b.allocator.create(TranslateCContext) catch @panic("OOM");
|
||||
cases.* = TranslateCContext{
|
||||
.b = b,
|
||||
.step = parent_step,
|
||||
.test_index = 0,
|
||||
.test_filters = test_filters,
|
||||
.test_target_filters = test_target_filters,
|
||||
};
|
||||
|
||||
translate_c.addCases(cases);
|
||||
}
|
||||
|
||||
pub fn addRunTranslatedCTests(
|
||||
b: *std.Build,
|
||||
parent_step: *std.Build.Step,
|
||||
test_filters: []const []const u8,
|
||||
target: std.Build.ResolvedTarget,
|
||||
) void {
|
||||
const cases = b.allocator.create(RunTranslatedCContext) catch @panic("OOM");
|
||||
cases.* = .{
|
||||
.b = b,
|
||||
.step = parent_step,
|
||||
.test_index = 0,
|
||||
.test_filters = test_filters,
|
||||
.target = target,
|
||||
};
|
||||
|
||||
run_translated_c.addCases(cases);
|
||||
}
|
||||
|
||||
const ModuleTestOptions = struct {
|
||||
test_filters: []const []const u8,
|
||||
test_target_filters: []const []const u8,
|
||||
|
|
@ -2558,9 +2516,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
|
|||
pub fn addCases(
|
||||
b: *std.Build,
|
||||
parent_step: *Step,
|
||||
target: std.Build.ResolvedTarget,
|
||||
case_test_options: @import("src/Cases.zig").CaseTestOptions,
|
||||
translate_c_options: @import("src/Cases.zig").TranslateCOptions,
|
||||
build_options: @import("cases.zig").BuildOptions,
|
||||
) !void {
|
||||
const arena = b.allocator;
|
||||
|
|
@ -2574,15 +2530,6 @@ pub fn addCases(
|
|||
cases.addFromDir(dir, b);
|
||||
try @import("cases.zig").addCases(&cases, build_options, b);
|
||||
|
||||
cases.lowerToTranslateCSteps(
|
||||
b,
|
||||
parent_step,
|
||||
case_test_options.test_filters,
|
||||
case_test_options.test_target_filters,
|
||||
target,
|
||||
translate_c_options,
|
||||
);
|
||||
|
||||
cases.lowerToBuildSteps(
|
||||
b,
|
||||
parent_step,
|
||||
|
|
|
|||
3923
test/translate_c.zig
3923
test/translate_c.zig
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue