authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-03 12:29:55-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-03 12:50:42-05:00
log6a046c1bcda1d02d4f9a05ea125ef56b50cf6e7c
tree7a92c39cf94ac84b9a9ff8a48b91a214f1ca806f
parentffd21c586dbed40b991c5578b2b2ba7d12c72a8e
signature Commit is signed but in an unrecognized format.

activate start code when pub main exists

and rename LinkType->LinkMode, OutType->OutputMode

4 files changed, 34 insertions(+), 45 deletions(-)

lib/std/builtin.zig+2-3
......@@ -350,8 +350,7 @@ pub const Endian = enum {
350350
351351/// This data structure is used by the Zig language code generation and
352352/// therefore must be kept in sync with the compiler implementation.
353pub const OutType = enum {
354 Unknown,
353pub const OutputMode = enum {
355354 Exe,
356355 Lib,
357356 Obj,
......@@ -359,7 +358,7 @@ pub const OutType = enum {
359358
360359/// This data structure is used by the Zig language code generation and
361360/// therefore must be kept in sync with the compiler implementation.
362pub const LinkType = enum {
361pub const LinkMode = enum {
363362 Static,
364363 Dynamic,
365364};
lib/std/special/start.zig+21-30
......@@ -19,37 +19,28 @@ const is_mips = switch (builtin.arch) {
1919};
2020
2121comptime {
22 switch (builtin.output_type) {
23 .Unknown => unreachable,
24 .Exe => {
25 if (builtin.link_libc) {
26 if (@hasDecl(root, "main") and
27 @typeInfo(@typeOf(root.main)).Fn.calling_convention != .C)
28 {
29 @export("main", main, .Weak);
30 }
31 } else if (builtin.os == .windows) {
32 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
33 @export("WinMainCRTStartup", WinMainCRTStartup, .Strong);
34 }
35 } else if (is_wasm and builtin.os == .freestanding) {
36 if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
37 } else if (builtin.os == .uefi) {
38 if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
39 } else if (is_mips) {
40 if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
41 } else {
42 if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
43 }
44 },
45 .Lib => {
46 if (builtin.os == .windows and builtin.link_type == .Dynamic and
47 !@hasDecl(root, "_DllMainCRTStartup"))
48 {
49 @export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong);
22 if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
23 if (builtin.os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
24 @export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong);
25 }
26 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
27 if (builtin.link_libc and @hasDecl(root, "main") and
28 @typeInfo(@typeOf(root.main)).Fn.calling_convention != .C)
29 {
30 @export("main", main, .Weak);
31 } else if (builtin.os == .windows) {
32 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
33 @export("WinMainCRTStartup", WinMainCRTStartup, .Strong);
5034 }
51 },
52 .Obj => {},
35 } else if (is_wasm and builtin.os == .freestanding) {
36 if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
37 } else if (builtin.os == .uefi) {
38 if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
39 } else if (is_mips) {
40 if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
41 } else {
42 if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
43 }
5344 }
5445}
5546
src/codegen.cpp+3-4
......@@ -8378,8 +8378,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
83788378 const char *out_type = nullptr;
83798379 switch (g->out_type) {
83808380 case OutTypeUnknown:
8381 out_type = "Unknown";
8382 break;
8381 zig_unreachable();
83838382 case OutTypeExe:
83848383 out_type = "Exe";
83858384 break;
......@@ -8390,9 +8389,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
83908389 out_type = "Obj";
83918390 break;
83928391 }
8393 buf_appendf(contents, "pub const output_type = OutType.%s;\n", out_type);
8392 buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type);
83948393 const char *link_type = g->is_dynamic ? "Dynamic" : "Static";
8395 buf_appendf(contents, "pub const link_type = LinkType.%s;\n", link_type);
8394 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type);
83968395 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
83978396 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
83988397 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
test/compile_errors.zig+8-8
......@@ -156,7 +156,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
156156 "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
157157 );
158158
159 cases.addExe(
159 cases.add(
160160 "disallow coercion from non-null-terminated pointer to null-terminated pointer",
161161 \\extern fn puts(s: [*:0]const u8) c_int;
162162 \\pub fn main() void {
......@@ -876,7 +876,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
876876 "tmp.zig:3:32: note: cast discards const qualifier",
877877 );
878878
879 cases.addExe(
879 cases.add(
880880 "overflow in enum value allocation",
881881 \\const Moo = enum(u8) {
882882 \\ Last = 255,
......@@ -3000,14 +3000,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30003000 "tmp.zig:3:9: error: encountered @panic at compile-time",
30013001 );
30023002
3003 cases.addExe(
3003 cases.add(
30043004 "wrong return type for main",
30053005 \\pub fn main() f32 { }
30063006 ,
30073007 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
30083008 );
30093009
3010 cases.addExe(
3010 cases.add(
30113011 "double ?? on main return value",
30123012 \\pub fn main() ??void {
30133013 \\}
......@@ -4900,7 +4900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49004900 "tmp.zig:3:13: error: cannot assign to constant",
49014901 );
49024902
4903 cases.addExe(
4903 cases.add(
49044904 "main function with bogus args type",
49054905 \\pub fn main(args: [][]bogus) !void {}
49064906 ,
......@@ -5718,7 +5718,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57185718 "tmp.zig:4:13: error: cannot continue out of defer expression",
57195719 );
57205720
5721 cases.addExe(
5721 cases.add(
57225722 "calling a var args function only known at runtime",
57235723 \\var foos = [_]fn(...) void { foo1, foo2 };
57245724 \\
......@@ -5732,7 +5732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57325732 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
57335733 );
57345734
5735 cases.addExe(
5735 cases.add(
57365736 "calling a generic function only known at runtime",
57375737 \\var foos = [_]fn(var) void { foo1, foo2 };
57385738 \\
......@@ -6850,7 +6850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68506850 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
68516851 );
68526852
6853 cases.addExe("compileLog of tagged enum doesn't crash the compiler",
6853 cases.add("compileLog of tagged enum doesn't crash the compiler",
68546854 \\const Bar = union(enum(u32)) {
68556855 \\ X: i32 = 1
68566856 \\};