mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
cbe: fix extern
This commit is contained in:
parent
b40fc70188
commit
fa46f9a3d7
68
lib/include/zig.h
vendored
68
lib/include/zig.h
vendored
@ -66,9 +66,9 @@
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define zig_extern_c extern "C"
|
||||
#define zig_extern extern "C"
|
||||
#else
|
||||
#define zig_extern_c
|
||||
#define zig_extern extern
|
||||
#endif
|
||||
|
||||
#if zig_has_builtin(debugtrap)
|
||||
@ -265,8 +265,8 @@ typedef int64_t zig_i64;
|
||||
#define zig_compiler_rt_abbrev_f80 xf
|
||||
#define zig_compiler_rt_abbrev_f128 tf
|
||||
|
||||
zig_extern_c void *memcpy (void *zig_restrict, void const *zig_restrict, zig_usize);
|
||||
zig_extern_c void *memset (void *, int, zig_usize);
|
||||
zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, zig_usize);
|
||||
zig_extern void *memset (void *, int, zig_usize);
|
||||
|
||||
/* ==================== 8/16/32/64-bit Integer Routines ===================== */
|
||||
|
||||
@ -345,7 +345,7 @@ static inline zig_bool zig_addo_u32(zig_u32 *res, zig_u32 lhs, zig_u32 rhs, zig_
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i32 __addosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i32 __addosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_addo_i32(zig_i32 *res, zig_i32 lhs, zig_i32 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(add_overflow)
|
||||
zig_i32 full_res;
|
||||
@ -371,7 +371,7 @@ static inline zig_bool zig_addo_u64(zig_u64 *res, zig_u64 lhs, zig_u64 rhs, zig_
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i64 __addodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i64 __addodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_addo_i64(zig_i64 *res, zig_i64 lhs, zig_i64 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(add_overflow)
|
||||
zig_i64 full_res;
|
||||
@ -441,7 +441,7 @@ static inline zig_bool zig_subo_u32(zig_u32 *res, zig_u32 lhs, zig_u32 rhs, zig_
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i32 __subosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i32 __subosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_subo_i32(zig_i32 *res, zig_i32 lhs, zig_i32 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(sub_overflow)
|
||||
zig_i32 full_res;
|
||||
@ -467,7 +467,7 @@ static inline zig_bool zig_subo_u64(zig_u64 *res, zig_u64 lhs, zig_u64 rhs, zig_
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i64 __subodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i64 __subodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_subo_i64(zig_i64 *res, zig_i64 lhs, zig_i64 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(sub_overflow)
|
||||
zig_i64 full_res;
|
||||
@ -537,7 +537,7 @@ static inline zig_bool zig_mulo_u32(zig_u32 *res, zig_u32 lhs, zig_u32 rhs, zig_
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i32 __mulosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i32 __mulosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_mulo_i32(zig_i32 *res, zig_i32 lhs, zig_i32 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(mul_overflow)
|
||||
zig_i32 full_res;
|
||||
@ -563,7 +563,7 @@ static inline zig_bool zig_mulo_u64(zig_u64 *res, zig_u64 lhs, zig_u64 rhs, zig_
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i64 __mulodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i64 __mulodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_mulo_i64(zig_i64 *res, zig_i64 lhs, zig_i64 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(mul_overflow)
|
||||
zig_i64 full_res;
|
||||
@ -1210,7 +1210,7 @@ static inline zig_bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs,
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(add_overflow)
|
||||
zig_i128 full_res;
|
||||
@ -1236,7 +1236,7 @@ static inline zig_bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs,
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(sub_overflow)
|
||||
zig_i128 full_res;
|
||||
@ -1262,7 +1262,7 @@ static inline zig_bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs,
|
||||
#endif
|
||||
}
|
||||
|
||||
zig_extern_c zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow);
|
||||
zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow);
|
||||
static inline zig_bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) {
|
||||
#if zig_has_builtin(mul_overflow)
|
||||
zig_i128 full_res;
|
||||
@ -1552,7 +1552,7 @@ typedef long double zig_c_longdouble;
|
||||
#define zig_as_special_c_longdouble(sign, name, arg, repr) sign __builtin_##name##l(arg)
|
||||
|
||||
#define zig_convert_builtin(ResType, operation, ArgType, version) \
|
||||
zig_extern_c zig_##ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \
|
||||
zig_extern zig_##ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \
|
||||
zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(zig_##ArgType);
|
||||
zig_convert_builtin(f16, trunc, f32, 2)
|
||||
zig_convert_builtin(f16, trunc, f64, 2)
|
||||
@ -1585,7 +1585,7 @@ zig_convert_builtin(f128, extend, f80, 2)
|
||||
}
|
||||
|
||||
#define zig_float_less_builtin_0(Type, operation) \
|
||||
zig_extern_c zig_i8 zig_expand_concat(zig_expand_concat(__##operation, \
|
||||
zig_extern zig_i8 zig_expand_concat(zig_expand_concat(__##operation, \
|
||||
zig_compiler_rt_abbrev_##Type), 2)(zig_##Type, zig_##Type); \
|
||||
static inline zig_i8 zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \
|
||||
return (zig_i8)zig_expand_concat(zig_expand_concat(__##operation, zig_compiler_rt_abbrev_##Type), 2)(lhs, rhs); \
|
||||
@ -1603,7 +1603,7 @@ zig_convert_builtin(f128, extend, f80, 2)
|
||||
}
|
||||
|
||||
#define zig_float_binary_builtin_0(Type, operation, operator) \
|
||||
zig_extern_c zig_##Type zig_expand_concat(zig_expand_concat(__##operation, \
|
||||
zig_extern zig_##Type zig_expand_concat(zig_expand_concat(__##operation, \
|
||||
zig_compiler_rt_abbrev_##Type), 3)(zig_##Type, zig_##Type); \
|
||||
static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \
|
||||
return zig_expand_concat(zig_expand_concat(__##operation, zig_compiler_rt_abbrev_##Type), 3)(lhs, rhs); \
|
||||
@ -1638,24 +1638,24 @@ zig_convert_builtin(f128, extend, f80, 2)
|
||||
zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, sub, -) \
|
||||
zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, mul, *) \
|
||||
zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, div, /) \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(sqrt)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(sin)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(cos)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(tan)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(exp)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(exp2)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(log)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(log2)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(log10)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(fabs)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(floor)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(ceil)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(round)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(trunc)(zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(fmod)(zig_##Type, zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(fmin)(zig_##Type, zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(fmax)(zig_##Type, zig_##Type); \
|
||||
zig_extern_c zig_##Type zig_libc_name_##Type(fma)(zig_##Type, zig_##Type, zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(sqrt)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(sin)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(cos)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(tan)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(exp)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(exp2)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(log)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(log2)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(log10)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(fabs)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(floor)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(ceil)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(round)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(trunc)(zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(fmod)(zig_##Type, zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(fmin)(zig_##Type, zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(fmax)(zig_##Type, zig_##Type); \
|
||||
zig_extern zig_##Type zig_libc_name_##Type(fma)(zig_##Type, zig_##Type, zig_##Type); \
|
||||
\
|
||||
static inline zig_##Type zig_div_trunc_##Type(zig_##Type lhs, zig_##Type rhs) { \
|
||||
return zig_libc_name_##Type(trunc)(zig_div_##Type(lhs, rhs)); \
|
||||
|
@ -2215,7 +2215,7 @@ pub fn genFunc(f: *Function) !void {
|
||||
|
||||
const is_global = o.dg.module.decl_exports.contains(f.func.owner_decl);
|
||||
const fwd_decl_writer = o.dg.fwd_decl.writer();
|
||||
try fwd_decl_writer.writeAll(if (is_global) "zig_extern_c " else "static ");
|
||||
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
try o.dg.renderFunctionSignature(fwd_decl_writer, .Forward);
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
|
||||
@ -2252,9 +2252,10 @@ pub fn genDecl(o: *Object) !void {
|
||||
.ty = o.dg.decl.ty,
|
||||
.val = o.dg.decl.val,
|
||||
};
|
||||
if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime()) return;
|
||||
if (tv.val.tag() == .extern_fn) {
|
||||
const fwd_decl_writer = o.dg.fwd_decl.writer();
|
||||
try fwd_decl_writer.writeAll("zig_extern_c ");
|
||||
try fwd_decl_writer.writeAll("zig_extern ");
|
||||
try o.dg.renderFunctionSignature(fwd_decl_writer, .Forward);
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
} else if (tv.val.castTag(.variable)) |var_payload| {
|
||||
@ -2268,22 +2269,19 @@ pub fn genDecl(o: *Object) !void {
|
||||
.decl = o.dg.decl_index,
|
||||
};
|
||||
|
||||
if (is_global) try fwd_decl_writer.writeAll("zig_extern_c ");
|
||||
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
if (variable.is_threadlocal) try fwd_decl_writer.writeAll("zig_threadlocal ");
|
||||
try o.dg.renderTypeAndName(fwd_decl_writer, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align", .Complete);
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
|
||||
if (variable.is_extern or variable.init.isUndefDeep()) {
|
||||
return;
|
||||
}
|
||||
if (variable.is_extern) return;
|
||||
|
||||
const w = o.writer();
|
||||
if (!is_global) try w.writeAll("static ");
|
||||
if (variable.is_threadlocal) try w.writeAll("zig_threadlocal ");
|
||||
try o.dg.renderTypeAndName(w, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align", .Complete);
|
||||
try w.writeAll(" = ");
|
||||
if (variable.init.tag() != .unreachable_value) {
|
||||
try o.dg.renderValue(w, tv.ty, variable.init, .Initializer);
|
||||
}
|
||||
try o.dg.renderValue(w, tv.ty, variable.init, .Initializer);
|
||||
try w.writeByte(';');
|
||||
try o.indent_writer.insertNewline();
|
||||
} else {
|
||||
@ -2319,7 +2317,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
|
||||
.Fn => {
|
||||
const is_global = dg.declIsGlobal(tv);
|
||||
if (is_global) {
|
||||
try writer.writeAll("zig_extern_c ");
|
||||
try writer.writeAll("zig_extern ");
|
||||
try dg.renderFunctionSignature(writer, .Complete);
|
||||
try dg.fwd_decl.appendSlice(";\n");
|
||||
}
|
||||
|
@ -435,6 +435,7 @@ test "global union with single field is correctly initialized" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
|
||||
glbl = Foo1{
|
||||
.f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
|
||||
|
@ -951,7 +951,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
ctx.h("simple header", linux_x64,
|
||||
\\export fn start() void{}
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_void);
|
||||
\\zig_extern zig_void start(zig_void);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with single param function", linux_x64,
|
||||
@ -959,7 +959,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
\\ _ = a;
|
||||
\\}
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_u8 const a0);
|
||||
\\zig_extern zig_void start(zig_u8 const a0);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with multiple param function", linux_x64,
|
||||
@ -967,25 +967,25 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
\\ _ = a; _ = b; _ = c;
|
||||
\\}
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2);
|
||||
\\zig_extern zig_void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with u32 param function", linux_x64,
|
||||
\\export fn start(a: u32) void{ _ = a; }
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_u32 const a0);
|
||||
\\zig_extern zig_void start(zig_u32 const a0);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with usize param function", linux_x64,
|
||||
\\export fn start(a: usize) void{ _ = a; }
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_usize const a0);
|
||||
\\zig_extern zig_void start(zig_usize const a0);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with bool param function", linux_x64,
|
||||
\\export fn start(a: bool) void{_ = a;}
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_bool const a0);
|
||||
\\zig_extern zig_void start(zig_bool const a0);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with noreturn function", linux_x64,
|
||||
@ -993,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
\\ unreachable;
|
||||
\\}
|
||||
,
|
||||
\\zig_extern_c zig_noreturn start(zig_void);
|
||||
\\zig_extern zig_noreturn start(zig_void);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with multiple functions", linux_x64,
|
||||
@ -1001,15 +1001,15 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
\\export fn b() void{}
|
||||
\\export fn c() void{}
|
||||
,
|
||||
\\zig_extern_c zig_void a(zig_void);
|
||||
\\zig_extern_c zig_void b(zig_void);
|
||||
\\zig_extern_c zig_void c(zig_void);
|
||||
\\zig_extern zig_void a(zig_void);
|
||||
\\zig_extern zig_void b(zig_void);
|
||||
\\zig_extern zig_void c(zig_void);
|
||||
\\
|
||||
);
|
||||
ctx.h("header with multiple includes", linux_x64,
|
||||
\\export fn start(a: u32, b: usize) void{ _ = a; _ = b; }
|
||||
,
|
||||
\\zig_extern_c zig_void start(zig_u32 const a0, zig_usize const a1);
|
||||
\\zig_extern zig_void start(zig_u32 const a0, zig_usize const a1);
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user