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 * start.zig should support pub export fn main with -ofmt=c
12 * get stage2 tests passing
23 * modify stage2 tests so that only 1 uses _start and the rest use
34 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
58 * use a hash map for instructions because the array is too big
69 - 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 {
1515 // Regular old hello world
1616 case.addCompareOutput(
1717 \\extern fn puts(s: [*:0]const u8) c_int;
18 \\export fn main() c_int {
18 \\pub export fn main() c_int {
1919 \\ _ = puts("hello world!");
2020 \\ return 0;
2121 \\}
......@@ -24,7 +24,7 @@ pub fn addCases(ctx: *TestContext) !void {
2424 // Now change the message only
2525 case.addCompareOutput(
2626 \\extern fn puts(s: [*:0]const u8) c_int;
27 \\export fn main() c_int {
27 \\pub export fn main() c_int {
2828 \\ _ = puts("yo");
2929 \\ return 0;
3030 \\}
......@@ -33,7 +33,7 @@ pub fn addCases(ctx: *TestContext) !void {
3333 // Add an unused Decl
3434 case.addCompareOutput(
3535 \\extern fn puts(s: [*:0]const u8) c_int;
36 \\export fn main() c_int {
36 \\pub export fn main() c_int {
3737 \\ _ = puts("yo!");
3838 \\ return 0;
3939 \\}
......@@ -43,7 +43,7 @@ pub fn addCases(ctx: *TestContext) !void {
4343 // Comptime return type and calling convention expected.
4444 case.addError(
4545 \\var x: i32 = 1234;
46 \\export fn main() x {
46 \\pub export fn main() x {
4747 \\ return 0;
4848 \\}
4949 \\export fn foo() callconv(y) c_int {
......@@ -62,7 +62,7 @@ pub fn addCases(ctx: *TestContext) !void {
6262 case.addCompareOutput(
6363 \\extern fn printf(format: [*:0]const u8, ...) c_int;
6464 \\
65 \\export fn main() c_int {
65 \\pub export fn main() c_int {
6666 \\ _ = printf("Hello, %s!\n", "world");
6767 \\ return 0;
6868 \\}
......@@ -119,14 +119,14 @@ pub fn addCases(ctx: *TestContext) !void {
119119 \\ unreachable;
120120 \\}
121121 \\
122 \\export fn main() c_int {
122 \\pub export fn main() c_int {
123123 \\ exitGood();
124124 \\}
125125 , "");
126126
127127 // Pass a usize parameter to exit
128128 case.addCompareOutput(
129 \\export fn main() c_int {
129 \\pub export fn main() c_int {
130130 \\ exit(0);
131131 \\}
132132 \\
......@@ -142,7 +142,7 @@ pub fn addCases(ctx: *TestContext) !void {
142142
143143 // Change the parameter to u8
144144 case.addCompareOutput(
145 \\export fn main() c_int {
145 \\pub export fn main() c_int {
146146 \\ exit(0);
147147 \\}
148148 \\
......@@ -158,7 +158,7 @@ pub fn addCases(ctx: *TestContext) !void {
158158
159159 // Do some arithmetic at the exit callsite
160160 case.addCompareOutput(
161 \\export fn main() c_int {
161 \\pub export fn main() c_int {
162162 \\ exitMath(1);
163163 \\}
164164 \\
......@@ -179,7 +179,7 @@ pub fn addCases(ctx: *TestContext) !void {
179179
180180 // Invert the arithmetic
181181 case.addCompareOutput(
182 \\export fn main() c_int {
182 \\pub export fn main() c_int {
183183 \\ exitMath(1);
184184 \\}
185185 \\
......@@ -211,7 +211,7 @@ pub fn addCases(ctx: *TestContext) !void {
211211 \\ return add(a, b);
212212 \\}
213213 \\
214 \\export fn main() c_int {
214 \\pub export fn main() c_int {
215215 \\ return addIndirect(1, 2) - 3;
216216 \\}
217217 , "");
......@@ -225,7 +225,7 @@ pub fn addCases(ctx: *TestContext) !void {
225225 \\ return a + b;
226226 \\}
227227 \\
228 \\export fn main() c_int {
228 \\pub export fn main() c_int {
229229 \\ const x = add(1, 2);
230230 \\ var y = add(3, 0);
231231 \\ y -= x;
......@@ -237,7 +237,7 @@ pub fn addCases(ctx: *TestContext) !void {
237237 var case = ctx.exeFromCompiledC("@setEvalBranchQuota", .{});
238238
239239 case.addCompareOutput(
240 \\export fn main() i32 {
240 \\pub export fn main() i32 {
241241 \\ @setEvalBranchQuota(1001);
242242 \\ const y = rec(1001);
243243 \\ return y - 1;
......@@ -254,14 +254,14 @@ pub fn addCases(ctx: *TestContext) !void {
254254
255255 // Simple while loop
256256 case.addCompareOutput(
257 \\export fn main() c_int {
257 \\pub export fn main() c_int {
258258 \\ var a: c_int = 0;
259259 \\ while (a < 5) : (a+=1) {}
260260 \\ return a - 5;
261261 \\}
262262 , "");
263263 case.addCompareOutput(
264 \\export fn main() c_int {
264 \\pub export fn main() c_int {
265265 \\ var a = true;
266266 \\ while (!a) {}
267267 \\ return 0;
......@@ -270,7 +270,7 @@ pub fn addCases(ctx: *TestContext) !void {
270270
271271 // If expression
272272 case.addCompareOutput(
273 \\export fn main() c_int {
273 \\pub export fn main() c_int {
274274 \\ var cond: c_int = 0;
275275 \\ var a: c_int = @as(c_int, if (cond == 0)
276276 \\ 2
......@@ -282,7 +282,7 @@ pub fn addCases(ctx: *TestContext) !void {
282282
283283 // If expression with breakpoint that does not get hit
284284 case.addCompareOutput(
285 \\export fn main() c_int {
285 \\pub export fn main() c_int {
286286 \\ var x: i32 = 1;
287287 \\ if (x != 1) @breakpoint();
288288 \\ return 0;
......@@ -291,7 +291,7 @@ pub fn addCases(ctx: *TestContext) !void {
291291
292292 // Switch expression
293293 case.addCompareOutput(
294 \\export fn main() c_int {
294 \\pub export fn main() c_int {
295295 \\ var cond: c_int = 0;
296296 \\ var a: c_int = switch (cond) {
297297 \\ 1 => 1,
......@@ -306,7 +306,7 @@ pub fn addCases(ctx: *TestContext) !void {
306306
307307 // Switch expression missing else case.
308308 case.addError(
309 \\export fn main() c_int {
309 \\pub export fn main() c_int {
310310 \\ var cond: c_int = 0;
311311 \\ const a: c_int = switch (cond) {
312312 \\ 1 => 1,
......@@ -320,7 +320,7 @@ pub fn addCases(ctx: *TestContext) !void {
320320
321321 // Switch expression, has an unreachable prong.
322322 case.addCompareOutput(
323 \\export fn main() c_int {
323 \\pub export fn main() c_int {
324324 \\ var cond: c_int = 0;
325325 \\ const a: c_int = switch (cond) {
326326 \\ 1 => 1,
......@@ -337,7 +337,7 @@ pub fn addCases(ctx: *TestContext) !void {
337337 // Switch expression, has an unreachable prong and prongs write
338338 // to result locations.
339339 case.addCompareOutput(
340 \\export fn main() c_int {
340 \\pub export fn main() c_int {
341341 \\ var cond: c_int = 0;
342342 \\ var a: c_int = switch (cond) {
343343 \\ 1 => 1,
......@@ -353,7 +353,7 @@ pub fn addCases(ctx: *TestContext) !void {
353353
354354 // Integer switch expression has duplicate case value.
355355 case.addError(
356 \\export fn main() c_int {
356 \\pub export fn main() c_int {
357357 \\ var cond: c_int = 0;
358358 \\ const a: c_int = switch (cond) {
359359 \\ 1 => 1,
......@@ -372,7 +372,7 @@ pub fn addCases(ctx: *TestContext) !void {
372372
373373 // Boolean switch expression has duplicate case value.
374374 case.addError(
375 \\export fn main() c_int {
375 \\pub export fn main() c_int {
376376 \\ var a: bool = false;
377377 \\ const b: c_int = switch (a) {
378378 \\ false => 1,
......@@ -386,7 +386,7 @@ pub fn addCases(ctx: *TestContext) !void {
386386
387387 // Sparse (no range capable) switch expression has duplicate case value.
388388 case.addError(
389 \\export fn main() c_int {
389 \\pub export fn main() c_int {
390390 \\ const A: type = i32;
391391 \\ const b: c_int = switch (A) {
392392 \\ i32 => 1,
......@@ -402,7 +402,7 @@ pub fn addCases(ctx: *TestContext) !void {
402402
403403 // Ranges not allowed for some kinds of switches.
404404 case.addError(
405 \\export fn main() c_int {
405 \\pub export fn main() c_int {
406406 \\ const A: type = i32;
407407 \\ const b: c_int = switch (A) {
408408 \\ i32 => 1,
......@@ -418,7 +418,7 @@ pub fn addCases(ctx: *TestContext) !void {
418418
419419 // Switch expression has unreachable else prong.
420420 case.addError(
421 \\export fn main() c_int {
421 \\pub export fn main() c_int {
422422 \\ var a: u2 = 0;
423423 \\ const b: i32 = switch (a) {
424424 \\ 0 => 10,
......@@ -437,7 +437,7 @@ pub fn addCases(ctx: *TestContext) !void {
437437
438438 // // Simple while loop
439439 // case.addCompareOutput(
440 // \\export fn main() c_int {
440 // \\pub export fn main() c_int {
441441 // \\ var count: c_int = 0;
442442 // \\ var opt_ptr: ?*c_int = &count;
443443 // \\ while (opt_ptr) |_| : (count += 1) {
......@@ -449,7 +449,7 @@ pub fn addCases(ctx: *TestContext) !void {
449449
450450 // // Same with non pointer optionals
451451 // case.addCompareOutput(
452 // \\export fn main() c_int {
452 // \\pub export fn main() c_int {
453453 // \\ var count: c_int = 0;
454454 // \\ var opt_ptr: ?c_int = count;
455455 // \\ while (opt_ptr) |_| : (count += 1) {
......@@ -463,7 +463,7 @@ pub fn addCases(ctx: *TestContext) !void {
463463 {
464464 var case = ctx.exeFromCompiledC("errors", .{});
465465 case.addCompareOutput(
466 \\export fn main() c_int {
466 \\pub export fn main() c_int {
467467 \\ var e1 = error.Foo;
468468 \\ var e2 = error.Bar;
469469 \\ assert(e1 != e2);
......@@ -476,14 +476,14 @@ pub fn addCases(ctx: *TestContext) !void {
476476 \\}
477477 , "");
478478 case.addCompareOutput(
479 \\export fn main() c_int {
479 \\pub export fn main() c_int {
480480 \\ var e: anyerror!c_int = 0;
481481 \\ const i = e catch 69;
482482 \\ return i;
483483 \\}
484484 , "");
485485 case.addCompareOutput(
486 \\export fn main() c_int {
486 \\pub export fn main() c_int {
487487 \\ var e: anyerror!c_int = error.Foo;
488488 \\ const i = e catch 69;
489489 \\ return 69 - i;
......@@ -495,7 +495,7 @@ pub fn addCases(ctx: *TestContext) !void {
495495 var case = ctx.exeFromCompiledC("structs", .{});
496496 case.addError(
497497 \\const Point = struct { x: i32, y: i32 };
498 \\export fn main() c_int {
498 \\pub export fn main() c_int {
499499 \\ var p: Point = .{
500500 \\ .y = 24,
501501 \\ .x = 12,
......@@ -509,7 +509,7 @@ pub fn addCases(ctx: *TestContext) !void {
509509 });
510510 case.addError(
511511 \\const Point = struct { x: i32, y: i32 };
512 \\export fn main() c_int {
512 \\pub export fn main() c_int {
513513 \\ var p: Point = .{
514514 \\ .y = 24,
515515 \\ };
......@@ -521,7 +521,7 @@ pub fn addCases(ctx: *TestContext) !void {
521521 });
522522 case.addError(
523523 \\const Point = struct { x: i32, y: i32 };
524 \\export fn main() c_int {
524 \\pub export fn main() c_int {
525525 \\ var p: Point = .{
526526 \\ .x = 12,
527527 \\ .y = 24,
......@@ -535,7 +535,7 @@ pub fn addCases(ctx: *TestContext) !void {
535535 });
536536 case.addCompareOutput(
537537 \\const Point = struct { x: i32, y: i32 };
538 \\export fn main() c_int {
538 \\pub export fn main() c_int {
539539 \\ var p: Point = .{
540540 \\ .x = 12,
541541 \\ .y = 24,
......@@ -589,7 +589,7 @@ pub fn addCases(ctx: *TestContext) !void {
589589 case.addCompareOutput(
590590 \\const Number = enum { One, Two, Three };
591591 \\
592 \\export fn main() c_int {
592 \\pub export fn main() c_int {
593593 \\ var number1 = Number.One;
594594 \\ var number2: Number = .Two;
595595 \\ const number3 = @intToEnum(Number, 2);