authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-06 17:51:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-06 17:51:09-07:00
log3acd98fa3423d67cdce7118bc6abe736309e71df
treea9791f09581cae82771820205e778cffd70c5724
parent7dd33d431612cd8511eaea8dcabdca44b354e14b

stage2: CBE tests `pub export` instead of `export` main

This is needed so that start code can avoid redundantly trying to export a main function for libc to call.

2 files changed, 39 insertions(+), 36 deletions(-)

BRANCH_TODO+3
...@@ -1,6 +1,9 @@...@@ -1,6 +1,9 @@
1 * start.zig should support pub export fn main with -ofmt=c
1 * get stage2 tests passing2 * get stage2 tests passing
2 * modify stage2 tests so that only 1 uses _start and the rest use3 * modify stage2 tests so that only 1 uses _start and the rest use
3 pub fn main4 pub fn main
5 * modify stage2 CBE tests so that only 1 uses pub export main and the
6 rest use pub fn main
47
5 * use a hash map for instructions because the array is too big8 * use a hash map for instructions because the array is too big
6 - no, actually modify the Zir.Inst.Ref strategy so that each decl gets9 - no, actually modify the Zir.Inst.Ref strategy so that each decl gets
test/stage2/cbe.zig+36-36
...@@ -15,7 +15,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -15,7 +15,7 @@ pub fn addCases(ctx: *TestContext) !void {
15 // Regular old hello world15 // Regular old hello world
16 case.addCompareOutput(16 case.addCompareOutput(
17 \\extern fn puts(s: [*:0]const u8) c_int;17 \\extern fn puts(s: [*:0]const u8) c_int;
18 \\export fn main() c_int {18 \\pub export fn main() c_int {
19 \\ _ = puts("hello world!");19 \\ _ = puts("hello world!");
20 \\ return 0;20 \\ return 0;
21 \\}21 \\}
...@@ -24,7 +24,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -24,7 +24,7 @@ pub fn addCases(ctx: *TestContext) !void {
24 // Now change the message only24 // Now change the message only
25 case.addCompareOutput(25 case.addCompareOutput(
26 \\extern fn puts(s: [*:0]const u8) c_int;26 \\extern fn puts(s: [*:0]const u8) c_int;
27 \\export fn main() c_int {27 \\pub export fn main() c_int {
28 \\ _ = puts("yo");28 \\ _ = puts("yo");
29 \\ return 0;29 \\ return 0;
30 \\}30 \\}
...@@ -33,7 +33,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -33,7 +33,7 @@ pub fn addCases(ctx: *TestContext) !void {
33 // Add an unused Decl33 // Add an unused Decl
34 case.addCompareOutput(34 case.addCompareOutput(
35 \\extern fn puts(s: [*:0]const u8) c_int;35 \\extern fn puts(s: [*:0]const u8) c_int;
36 \\export fn main() c_int {36 \\pub export fn main() c_int {
37 \\ _ = puts("yo!");37 \\ _ = puts("yo!");
38 \\ return 0;38 \\ return 0;
39 \\}39 \\}
...@@ -43,7 +43,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -43,7 +43,7 @@ pub fn addCases(ctx: *TestContext) !void {
43 // Comptime return type and calling convention expected.43 // Comptime return type and calling convention expected.
44 case.addError(44 case.addError(
45 \\var x: i32 = 1234;45 \\var x: i32 = 1234;
46 \\export fn main() x {46 \\pub export fn main() x {
47 \\ return 0;47 \\ return 0;
48 \\}48 \\}
49 \\export fn foo() callconv(y) c_int {49 \\export fn foo() callconv(y) c_int {
...@@ -62,7 +62,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -62,7 +62,7 @@ pub fn addCases(ctx: *TestContext) !void {
62 case.addCompareOutput(62 case.addCompareOutput(
63 \\extern fn printf(format: [*:0]const u8, ...) c_int;63 \\extern fn printf(format: [*:0]const u8, ...) c_int;
64 \\64 \\
65 \\export fn main() c_int {65 \\pub export fn main() c_int {
66 \\ _ = printf("Hello, %s!\n", "world");66 \\ _ = printf("Hello, %s!\n", "world");
67 \\ return 0;67 \\ return 0;
68 \\}68 \\}
...@@ -119,14 +119,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -119,14 +119,14 @@ pub fn addCases(ctx: *TestContext) !void {
119 \\ unreachable;119 \\ unreachable;
120 \\}120 \\}
121 \\121 \\
122 \\export fn main() c_int {122 \\pub export fn main() c_int {
123 \\ exitGood();123 \\ exitGood();
124 \\}124 \\}
125 , "");125 , "");
126126
127 // Pass a usize parameter to exit127 // Pass a usize parameter to exit
128 case.addCompareOutput(128 case.addCompareOutput(
129 \\export fn main() c_int {129 \\pub export fn main() c_int {
130 \\ exit(0);130 \\ exit(0);
131 \\}131 \\}
132 \\132 \\
...@@ -142,7 +142,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -142,7 +142,7 @@ pub fn addCases(ctx: *TestContext) !void {
142142
143 // Change the parameter to u8143 // Change the parameter to u8
144 case.addCompareOutput(144 case.addCompareOutput(
145 \\export fn main() c_int {145 \\pub export fn main() c_int {
146 \\ exit(0);146 \\ exit(0);
147 \\}147 \\}
148 \\148 \\
...@@ -158,7 +158,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -158,7 +158,7 @@ pub fn addCases(ctx: *TestContext) !void {
158158
159 // Do some arithmetic at the exit callsite159 // Do some arithmetic at the exit callsite
160 case.addCompareOutput(160 case.addCompareOutput(
161 \\export fn main() c_int {161 \\pub export fn main() c_int {
162 \\ exitMath(1);162 \\ exitMath(1);
163 \\}163 \\}
164 \\164 \\
...@@ -179,7 +179,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -179,7 +179,7 @@ pub fn addCases(ctx: *TestContext) !void {
179179
180 // Invert the arithmetic180 // Invert the arithmetic
181 case.addCompareOutput(181 case.addCompareOutput(
182 \\export fn main() c_int {182 \\pub export fn main() c_int {
183 \\ exitMath(1);183 \\ exitMath(1);
184 \\}184 \\}
185 \\185 \\
...@@ -211,7 +211,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -211,7 +211,7 @@ pub fn addCases(ctx: *TestContext) !void {
211 \\ return add(a, b);211 \\ return add(a, b);
212 \\}212 \\}
213 \\213 \\
214 \\export fn main() c_int {214 \\pub export fn main() c_int {
215 \\ return addIndirect(1, 2) - 3;215 \\ return addIndirect(1, 2) - 3;
216 \\}216 \\}
217 , "");217 , "");
...@@ -225,7 +225,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -225,7 +225,7 @@ pub fn addCases(ctx: *TestContext) !void {
225 \\ return a + b;225 \\ return a + b;
226 \\}226 \\}
227 \\227 \\
228 \\export fn main() c_int {228 \\pub export fn main() c_int {
229 \\ const x = add(1, 2);229 \\ const x = add(1, 2);
230 \\ var y = add(3, 0);230 \\ var y = add(3, 0);
231 \\ y -= x;231 \\ y -= x;
...@@ -237,7 +237,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -237,7 +237,7 @@ pub fn addCases(ctx: *TestContext) !void {
237 var case = ctx.exeFromCompiledC("@setEvalBranchQuota", .{});237 var case = ctx.exeFromCompiledC("@setEvalBranchQuota", .{});
238238
239 case.addCompareOutput(239 case.addCompareOutput(
240 \\export fn main() i32 {240 \\pub export fn main() i32 {
241 \\ @setEvalBranchQuota(1001);241 \\ @setEvalBranchQuota(1001);
242 \\ const y = rec(1001);242 \\ const y = rec(1001);
243 \\ return y - 1;243 \\ return y - 1;
...@@ -254,14 +254,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -254,14 +254,14 @@ pub fn addCases(ctx: *TestContext) !void {
254254
255 // Simple while loop255 // Simple while loop
256 case.addCompareOutput(256 case.addCompareOutput(
257 \\export fn main() c_int {257 \\pub export fn main() c_int {
258 \\ var a: c_int = 0;258 \\ var a: c_int = 0;
259 \\ while (a < 5) : (a+=1) {}259 \\ while (a < 5) : (a+=1) {}
260 \\ return a - 5;260 \\ return a - 5;
261 \\}261 \\}
262 , "");262 , "");
263 case.addCompareOutput(263 case.addCompareOutput(
264 \\export fn main() c_int {264 \\pub export fn main() c_int {
265 \\ var a = true;265 \\ var a = true;
266 \\ while (!a) {}266 \\ while (!a) {}
267 \\ return 0;267 \\ return 0;
...@@ -270,7 +270,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -270,7 +270,7 @@ pub fn addCases(ctx: *TestContext) !void {
270270
271 // If expression271 // If expression
272 case.addCompareOutput(272 case.addCompareOutput(
273 \\export fn main() c_int {273 \\pub export fn main() c_int {
274 \\ var cond: c_int = 0;274 \\ var cond: c_int = 0;
275 \\ var a: c_int = @as(c_int, if (cond == 0)275 \\ var a: c_int = @as(c_int, if (cond == 0)
276 \\ 2276 \\ 2
...@@ -282,7 +282,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -282,7 +282,7 @@ pub fn addCases(ctx: *TestContext) !void {
282282
283 // If expression with breakpoint that does not get hit283 // If expression with breakpoint that does not get hit
284 case.addCompareOutput(284 case.addCompareOutput(
285 \\export fn main() c_int {285 \\pub export fn main() c_int {
286 \\ var x: i32 = 1;286 \\ var x: i32 = 1;
287 \\ if (x != 1) @breakpoint();287 \\ if (x != 1) @breakpoint();
288 \\ return 0;288 \\ return 0;
...@@ -291,7 +291,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -291,7 +291,7 @@ pub fn addCases(ctx: *TestContext) !void {
291291
292 // Switch expression292 // Switch expression
293 case.addCompareOutput(293 case.addCompareOutput(
294 \\export fn main() c_int {294 \\pub export fn main() c_int {
295 \\ var cond: c_int = 0;295 \\ var cond: c_int = 0;
296 \\ var a: c_int = switch (cond) {296 \\ var a: c_int = switch (cond) {
297 \\ 1 => 1,297 \\ 1 => 1,
...@@ -306,7 +306,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -306,7 +306,7 @@ pub fn addCases(ctx: *TestContext) !void {
306306
307 // Switch expression missing else case.307 // Switch expression missing else case.
308 case.addError(308 case.addError(
309 \\export fn main() c_int {309 \\pub export fn main() c_int {
310 \\ var cond: c_int = 0;310 \\ var cond: c_int = 0;
311 \\ const a: c_int = switch (cond) {311 \\ const a: c_int = switch (cond) {
312 \\ 1 => 1,312 \\ 1 => 1,
...@@ -320,7 +320,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -320,7 +320,7 @@ pub fn addCases(ctx: *TestContext) !void {
320320
321 // Switch expression, has an unreachable prong.321 // Switch expression, has an unreachable prong.
322 case.addCompareOutput(322 case.addCompareOutput(
323 \\export fn main() c_int {323 \\pub export fn main() c_int {
324 \\ var cond: c_int = 0;324 \\ var cond: c_int = 0;
325 \\ const a: c_int = switch (cond) {325 \\ const a: c_int = switch (cond) {
326 \\ 1 => 1,326 \\ 1 => 1,
...@@ -337,7 +337,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -337,7 +337,7 @@ pub fn addCases(ctx: *TestContext) !void {
337 // Switch expression, has an unreachable prong and prongs write337 // Switch expression, has an unreachable prong and prongs write
338 // to result locations.338 // to result locations.
339 case.addCompareOutput(339 case.addCompareOutput(
340 \\export fn main() c_int {340 \\pub export fn main() c_int {
341 \\ var cond: c_int = 0;341 \\ var cond: c_int = 0;
342 \\ var a: c_int = switch (cond) {342 \\ var a: c_int = switch (cond) {
343 \\ 1 => 1,343 \\ 1 => 1,
...@@ -353,7 +353,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -353,7 +353,7 @@ pub fn addCases(ctx: *TestContext) !void {
353353
354 // Integer switch expression has duplicate case value.354 // Integer switch expression has duplicate case value.
355 case.addError(355 case.addError(
356 \\export fn main() c_int {356 \\pub export fn main() c_int {
357 \\ var cond: c_int = 0;357 \\ var cond: c_int = 0;
358 \\ const a: c_int = switch (cond) {358 \\ const a: c_int = switch (cond) {
359 \\ 1 => 1,359 \\ 1 => 1,
...@@ -372,7 +372,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -372,7 +372,7 @@ pub fn addCases(ctx: *TestContext) !void {
372372
373 // Boolean switch expression has duplicate case value.373 // Boolean switch expression has duplicate case value.
374 case.addError(374 case.addError(
375 \\export fn main() c_int {375 \\pub export fn main() c_int {
376 \\ var a: bool = false;376 \\ var a: bool = false;
377 \\ const b: c_int = switch (a) {377 \\ const b: c_int = switch (a) {
378 \\ false => 1,378 \\ false => 1,
...@@ -386,7 +386,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -386,7 +386,7 @@ pub fn addCases(ctx: *TestContext) !void {
386386
387 // Sparse (no range capable) switch expression has duplicate case value.387 // Sparse (no range capable) switch expression has duplicate case value.
388 case.addError(388 case.addError(
389 \\export fn main() c_int {389 \\pub export fn main() c_int {
390 \\ const A: type = i32;390 \\ const A: type = i32;
391 \\ const b: c_int = switch (A) {391 \\ const b: c_int = switch (A) {
392 \\ i32 => 1,392 \\ i32 => 1,
...@@ -402,7 +402,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -402,7 +402,7 @@ pub fn addCases(ctx: *TestContext) !void {
402402
403 // Ranges not allowed for some kinds of switches.403 // Ranges not allowed for some kinds of switches.
404 case.addError(404 case.addError(
405 \\export fn main() c_int {405 \\pub export fn main() c_int {
406 \\ const A: type = i32;406 \\ const A: type = i32;
407 \\ const b: c_int = switch (A) {407 \\ const b: c_int = switch (A) {
408 \\ i32 => 1,408 \\ i32 => 1,
...@@ -418,7 +418,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -418,7 +418,7 @@ pub fn addCases(ctx: *TestContext) !void {
418418
419 // Switch expression has unreachable else prong.419 // Switch expression has unreachable else prong.
420 case.addError(420 case.addError(
421 \\export fn main() c_int {421 \\pub export fn main() c_int {
422 \\ var a: u2 = 0;422 \\ var a: u2 = 0;
423 \\ const b: i32 = switch (a) {423 \\ const b: i32 = switch (a) {
424 \\ 0 => 10,424 \\ 0 => 10,
...@@ -437,7 +437,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -437,7 +437,7 @@ pub fn addCases(ctx: *TestContext) !void {
437437
438 // // Simple while loop438 // // Simple while loop
439 // case.addCompareOutput(439 // case.addCompareOutput(
440 // \\export fn main() c_int {440 // \\pub export fn main() c_int {
441 // \\ var count: c_int = 0;441 // \\ var count: c_int = 0;
442 // \\ var opt_ptr: ?*c_int = &count;442 // \\ var opt_ptr: ?*c_int = &count;
443 // \\ while (opt_ptr) |_| : (count += 1) {443 // \\ while (opt_ptr) |_| : (count += 1) {
...@@ -449,7 +449,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -449,7 +449,7 @@ pub fn addCases(ctx: *TestContext) !void {
449449
450 // // Same with non pointer optionals450 // // Same with non pointer optionals
451 // case.addCompareOutput(451 // case.addCompareOutput(
452 // \\export fn main() c_int {452 // \\pub export fn main() c_int {
453 // \\ var count: c_int = 0;453 // \\ var count: c_int = 0;
454 // \\ var opt_ptr: ?c_int = count;454 // \\ var opt_ptr: ?c_int = count;
455 // \\ while (opt_ptr) |_| : (count += 1) {455 // \\ while (opt_ptr) |_| : (count += 1) {
...@@ -463,7 +463,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -463,7 +463,7 @@ pub fn addCases(ctx: *TestContext) !void {
463 {463 {
464 var case = ctx.exeFromCompiledC("errors", .{});464 var case = ctx.exeFromCompiledC("errors", .{});
465 case.addCompareOutput(465 case.addCompareOutput(
466 \\export fn main() c_int {466 \\pub export fn main() c_int {
467 \\ var e1 = error.Foo;467 \\ var e1 = error.Foo;
468 \\ var e2 = error.Bar;468 \\ var e2 = error.Bar;
469 \\ assert(e1 != e2);469 \\ assert(e1 != e2);
...@@ -476,14 +476,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -476,14 +476,14 @@ pub fn addCases(ctx: *TestContext) !void {
476 \\}476 \\}
477 , "");477 , "");
478 case.addCompareOutput(478 case.addCompareOutput(
479 \\export fn main() c_int {479 \\pub export fn main() c_int {
480 \\ var e: anyerror!c_int = 0;480 \\ var e: anyerror!c_int = 0;
481 \\ const i = e catch 69;481 \\ const i = e catch 69;
482 \\ return i;482 \\ return i;
483 \\}483 \\}
484 , "");484 , "");
485 case.addCompareOutput(485 case.addCompareOutput(
486 \\export fn main() c_int {486 \\pub export fn main() c_int {
487 \\ var e: anyerror!c_int = error.Foo;487 \\ var e: anyerror!c_int = error.Foo;
488 \\ const i = e catch 69;488 \\ const i = e catch 69;
489 \\ return 69 - i;489 \\ return 69 - i;
...@@ -495,7 +495,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -495,7 +495,7 @@ pub fn addCases(ctx: *TestContext) !void {
495 var case = ctx.exeFromCompiledC("structs", .{});495 var case = ctx.exeFromCompiledC("structs", .{});
496 case.addError(496 case.addError(
497 \\const Point = struct { x: i32, y: i32 };497 \\const Point = struct { x: i32, y: i32 };
498 \\export fn main() c_int {498 \\pub export fn main() c_int {
499 \\ var p: Point = .{499 \\ var p: Point = .{
500 \\ .y = 24,500 \\ .y = 24,
501 \\ .x = 12,501 \\ .x = 12,
...@@ -509,7 +509,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -509,7 +509,7 @@ pub fn addCases(ctx: *TestContext) !void {
509 });509 });
510 case.addError(510 case.addError(
511 \\const Point = struct { x: i32, y: i32 };511 \\const Point = struct { x: i32, y: i32 };
512 \\export fn main() c_int {512 \\pub export fn main() c_int {
513 \\ var p: Point = .{513 \\ var p: Point = .{
514 \\ .y = 24,514 \\ .y = 24,
515 \\ };515 \\ };
...@@ -521,7 +521,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -521,7 +521,7 @@ pub fn addCases(ctx: *TestContext) !void {
521 });521 });
522 case.addError(522 case.addError(
523 \\const Point = struct { x: i32, y: i32 };523 \\const Point = struct { x: i32, y: i32 };
524 \\export fn main() c_int {524 \\pub export fn main() c_int {
525 \\ var p: Point = .{525 \\ var p: Point = .{
526 \\ .x = 12,526 \\ .x = 12,
527 \\ .y = 24,527 \\ .y = 24,
...@@ -535,7 +535,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -535,7 +535,7 @@ pub fn addCases(ctx: *TestContext) !void {
535 });535 });
536 case.addCompareOutput(536 case.addCompareOutput(
537 \\const Point = struct { x: i32, y: i32 };537 \\const Point = struct { x: i32, y: i32 };
538 \\export fn main() c_int {538 \\pub export fn main() c_int {
539 \\ var p: Point = .{539 \\ var p: Point = .{
540 \\ .x = 12,540 \\ .x = 12,
541 \\ .y = 24,541 \\ .y = 24,
...@@ -589,7 +589,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -589,7 +589,7 @@ pub fn addCases(ctx: *TestContext) !void {
589 case.addCompareOutput(589 case.addCompareOutput(
590 \\const Number = enum { One, Two, Three };590 \\const Number = enum { One, Two, Three };
591 \\591 \\
592 \\export fn main() c_int {592 \\pub export fn main() c_int {
593 \\ var number1 = Number.One;593 \\ var number1 = Number.One;
594 \\ var number2: Number = .Two;594 \\ var number2: Number = .Two;
595 \\ const number3 = @intToEnum(Number, 2);595 \\ const number3 = @intToEnum(Number, 2);