activate start code when pub main exists
and rename LinkType->LinkMode, OutType->OutputMode
This commit is contained in:
parent
ffd21c586d
commit
6a046c1bcd
@ -350,8 +350,7 @@ pub const Endian = enum {
|
|||||||
|
|
||||||
/// This data structure is used by the Zig language code generation and
|
/// This data structure is used by the Zig language code generation and
|
||||||
/// therefore must be kept in sync with the compiler implementation.
|
/// therefore must be kept in sync with the compiler implementation.
|
||||||
pub const OutType = enum {
|
pub const OutputMode = enum {
|
||||||
Unknown,
|
|
||||||
Exe,
|
Exe,
|
||||||
Lib,
|
Lib,
|
||||||
Obj,
|
Obj,
|
||||||
@ -359,7 +358,7 @@ pub const OutType = enum {
|
|||||||
|
|
||||||
/// This data structure is used by the Zig language code generation and
|
/// This data structure is used by the Zig language code generation and
|
||||||
/// therefore must be kept in sync with the compiler implementation.
|
/// therefore must be kept in sync with the compiler implementation.
|
||||||
pub const LinkType = enum {
|
pub const LinkMode = enum {
|
||||||
Static,
|
Static,
|
||||||
Dynamic,
|
Dynamic,
|
||||||
};
|
};
|
||||||
|
@ -19,37 +19,28 @@ const is_mips = switch (builtin.arch) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
switch (builtin.output_type) {
|
if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
|
||||||
.Unknown => unreachable,
|
if (builtin.os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
|
||||||
.Exe => {
|
@export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong);
|
||||||
if (builtin.link_libc) {
|
}
|
||||||
if (@hasDecl(root, "main") and
|
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
|
||||||
@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C)
|
if (builtin.link_libc and @hasDecl(root, "main") and
|
||||||
{
|
@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C)
|
||||||
@export("main", main, .Weak);
|
{
|
||||||
}
|
@export("main", main, .Weak);
|
||||||
} else if (builtin.os == .windows) {
|
} else if (builtin.os == .windows) {
|
||||||
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
|
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
|
||||||
@export("WinMainCRTStartup", WinMainCRTStartup, .Strong);
|
@export("WinMainCRTStartup", WinMainCRTStartup, .Strong);
|
||||||
}
|
|
||||||
} else if (is_wasm and builtin.os == .freestanding) {
|
|
||||||
if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
|
|
||||||
} else if (builtin.os == .uefi) {
|
|
||||||
if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
|
|
||||||
} else if (is_mips) {
|
|
||||||
if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
|
|
||||||
} else {
|
|
||||||
if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
|
|
||||||
}
|
}
|
||||||
},
|
} else if (is_wasm and builtin.os == .freestanding) {
|
||||||
.Lib => {
|
if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
|
||||||
if (builtin.os == .windows and builtin.link_type == .Dynamic and
|
} else if (builtin.os == .uefi) {
|
||||||
!@hasDecl(root, "_DllMainCRTStartup"))
|
if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
|
||||||
{
|
} else if (is_mips) {
|
||||||
@export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong);
|
if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
|
||||||
}
|
} else {
|
||||||
},
|
if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
|
||||||
.Obj => {},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8378,8 +8378,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
|||||||
const char *out_type = nullptr;
|
const char *out_type = nullptr;
|
||||||
switch (g->out_type) {
|
switch (g->out_type) {
|
||||||
case OutTypeUnknown:
|
case OutTypeUnknown:
|
||||||
out_type = "Unknown";
|
zig_unreachable();
|
||||||
break;
|
|
||||||
case OutTypeExe:
|
case OutTypeExe:
|
||||||
out_type = "Exe";
|
out_type = "Exe";
|
||||||
break;
|
break;
|
||||||
@ -8390,9 +8389,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
|||||||
out_type = "Obj";
|
out_type = "Obj";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf_appendf(contents, "pub const output_type = OutType.%s;\n", out_type);
|
buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type);
|
||||||
const char *link_type = g->is_dynamic ? "Dynamic" : "Static";
|
const char *link_type = g->is_dynamic ? "Dynamic" : "Static";
|
||||||
buf_appendf(contents, "pub const link_type = LinkType.%s;\n", link_type);
|
buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type);
|
||||||
buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
|
buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
|
||||||
buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
|
buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
|
||||||
buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
|
buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
|
||||||
|
@ -156,7 +156,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
|
"tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"disallow coercion from non-null-terminated pointer to null-terminated pointer",
|
"disallow coercion from non-null-terminated pointer to null-terminated pointer",
|
||||||
\\extern fn puts(s: [*:0]const u8) c_int;
|
\\extern fn puts(s: [*:0]const u8) c_int;
|
||||||
\\pub fn main() void {
|
\\pub fn main() void {
|
||||||
@ -876,7 +876,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:3:32: note: cast discards const qualifier",
|
"tmp.zig:3:32: note: cast discards const qualifier",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"overflow in enum value allocation",
|
"overflow in enum value allocation",
|
||||||
\\const Moo = enum(u8) {
|
\\const Moo = enum(u8) {
|
||||||
\\ Last = 255,
|
\\ Last = 255,
|
||||||
@ -3000,14 +3000,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:3:9: error: encountered @panic at compile-time",
|
"tmp.zig:3:9: error: encountered @panic at compile-time",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"wrong return type for main",
|
"wrong return type for main",
|
||||||
\\pub fn main() f32 { }
|
\\pub fn main() f32 { }
|
||||||
,
|
,
|
||||||
"error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
|
"error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"double ?? on main return value",
|
"double ?? on main return value",
|
||||||
\\pub fn main() ??void {
|
\\pub fn main() ??void {
|
||||||
\\}
|
\\}
|
||||||
@ -4900,7 +4900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:3:13: error: cannot assign to constant",
|
"tmp.zig:3:13: error: cannot assign to constant",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"main function with bogus args type",
|
"main function with bogus args type",
|
||||||
\\pub fn main(args: [][]bogus) !void {}
|
\\pub fn main(args: [][]bogus) !void {}
|
||||||
,
|
,
|
||||||
@ -5718,7 +5718,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:4:13: error: cannot continue out of defer expression",
|
"tmp.zig:4:13: error: cannot continue out of defer expression",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"calling a var args function only known at runtime",
|
"calling a var args function only known at runtime",
|
||||||
\\var foos = [_]fn(...) void { foo1, foo2 };
|
\\var foos = [_]fn(...) void { foo1, foo2 };
|
||||||
\\
|
\\
|
||||||
@ -5732,7 +5732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
|
"tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe(
|
cases.add(
|
||||||
"calling a generic function only known at runtime",
|
"calling a generic function only known at runtime",
|
||||||
\\var foos = [_]fn(var) void { foo1, foo2 };
|
\\var foos = [_]fn(var) void { foo1, foo2 };
|
||||||
\\
|
\\
|
||||||
@ -6850,7 +6850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||||||
"tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
|
"tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.addExe("compileLog of tagged enum doesn't crash the compiler",
|
cases.add("compileLog of tagged enum doesn't crash the compiler",
|
||||||
\\const Bar = union(enum(u32)) {
|
\\const Bar = union(enum(u32)) {
|
||||||
\\ X: i32 = 1
|
\\ X: i32 = 1
|
||||||
\\};
|
\\};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user