authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-09-27 11:27:40+02:00
committergravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-10-03 12:52:04+02:00
logfb58fb2d8dfa49b01594f341f262cb45958c5e23
tree24c569fef4136e334ca486ae74785a5f84dde2a2
parentcfe486e3887ee5ea622234439fc7bd41fb2774bc

stage2 ARM: add testcases for non-leaf fns, parameters, return values


3 files changed, 152 insertions(+), 75 deletions(-)

src/codegen/arm.zig+6-6
...@@ -402,7 +402,7 @@ pub const Instruction = union(enum) {...@@ -402,7 +402,7 @@ pub const Instruction = union(enum) {
402 return Instruction{402 return Instruction{
403 .DataProcessing = .{403 .DataProcessing = .{
404 .cond = @enumToInt(cond),404 .cond = @enumToInt(cond),
405 .i = if (op2 == .Immediate) 1 else 0,405 .i = @boolToInt(op2 == .Immediate),
406 .opcode = @enumToInt(opcode),406 .opcode = @enumToInt(opcode),
407 .s = s,407 .s = s,
408 .rn = rn.id(),408 .rn = rn.id(),
...@@ -430,11 +430,11 @@ pub const Instruction = union(enum) {...@@ -430,11 +430,11 @@ pub const Instruction = union(enum) {
430 .rd = rd.id(),430 .rd = rd.id(),
431 .offset = offset.toU12(),431 .offset = offset.toU12(),
432 .load_store = load_store,432 .load_store = load_store,
433 .write_back = if (write_back) 1 else 0,433 .write_back = @boolToInt(write_back),
434 .byte_word = byte_word,434 .byte_word = byte_word,
435 .up_down = if (positive) 1 else 0,435 .up_down = @boolToInt(positive),
436 .pre_post = if (pre_index) 1 else 0,436 .pre_post = @boolToInt(pre_index),
437 .imm = if (offset == .Immediate) 0 else 1,437 .imm = @boolToInt(offset != .Immediate),
438 },438 },
439 };439 };
440 }440 }
...@@ -454,7 +454,7 @@ pub const Instruction = union(enum) {...@@ -454,7 +454,7 @@ pub const Instruction = union(enum) {
454 .register_list = @bitCast(u16, reg_list),454 .register_list = @bitCast(u16, reg_list),
455 .rn = rn.id(),455 .rn = rn.id(),
456 .load_store = load_store,456 .load_store = load_store,
457 .write_back = if (write_back) 1 else 0,457 .write_back = @boolToInt(write_back),
458 .psr_or_user = psr_or_user,458 .psr_or_user = psr_or_user,
459 .up_down = up_down,459 .up_down = up_down,
460 .pre_post = pre_post,460 .pre_post = pre_post,
test/stage2/arm.zig created+116
...@@ -0,0 +1,116 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3
4const linux_arm = std.zig.CrossTarget{
5 .cpu_arch = .arm,
6 .os_tag = .linux,
7};
8
9pub fn addCases(ctx: *TestContext) !void {
10 {
11 var case = ctx.exe("hello world", linux_arm);
12 // Regular old hello world
13 case.addCompareOutput(
14 \\export fn _start() noreturn {
15 \\ print();
16 \\ exit();
17 \\}
18 \\
19 \\fn print() void {
20 \\ asm volatile ("svc #0"
21 \\ :
22 \\ : [number] "{r7}" (4),
23 \\ [arg1] "{r0}" (1),
24 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
25 \\ [arg3] "{r2}" (14)
26 \\ : "memory"
27 \\ );
28 \\ return;
29 \\}
30 \\
31 \\fn exit() noreturn {
32 \\ asm volatile ("svc #0"
33 \\ :
34 \\ : [number] "{r7}" (1),
35 \\ [arg1] "{r0}" (0)
36 \\ : "memory"
37 \\ );
38 \\ unreachable;
39 \\}
40 ,
41 "Hello, World!\n",
42 );
43 }
44
45 {
46 var case = ctx.exe("parameters and return values", linux_arm);
47 // Testing simple parameters and return values
48 //
49 // TODO: The parameters to the asm statement in print() had to
50 // be in a specific order because otherwise the write to r0
51 // would overwrite the len parameter which resides in r0
52 case.addCompareOutput(
53 \\export fn _start() noreturn {
54 \\ print(id(14));
55 \\ exit();
56 \\}
57 \\
58 \\fn id(x: u32) u32 {
59 \\ return x;
60 \\}
61 \\
62 \\fn print(len: u32) void {
63 \\ asm volatile ("svc #0"
64 \\ :
65 \\ : [number] "{r7}" (4),
66 \\ [arg3] "{r2}" (len),
67 \\ [arg1] "{r0}" (1),
68 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n"))
69 \\ : "memory"
70 \\ );
71 \\ return;
72 \\}
73 \\
74 \\fn exit() noreturn {
75 \\ asm volatile ("svc #0"
76 \\ :
77 \\ : [number] "{r7}" (1),
78 \\ [arg1] "{r0}" (0)
79 \\ : "memory"
80 \\ );
81 \\ unreachable;
82 \\}
83 ,
84 "Hello, World!\n",
85 );
86 }
87
88 {
89 var case = ctx.exe("non-leaf functions", linux_arm);
90 // Testing non-leaf functions
91 case.addCompareOutput(
92 \\export fn _start() noreturn {
93 \\ foo();
94 \\ exit();
95 \\}
96 \\
97 \\fn foo() void {
98 \\ bar();
99 \\}
100 \\
101 \\fn bar() void {}
102 \\
103 \\fn exit() noreturn {
104 \\ asm volatile ("svc #0"
105 \\ :
106 \\ : [number] "{r7}" (1),
107 \\ [arg1] "{r0}" (0)
108 \\ : "memory"
109 \\ );
110 \\ unreachable;
111 \\}
112 ,
113 "",
114 );
115 }
116}
test/stage2/test.zig+30-69
...@@ -21,11 +21,6 @@ const linux_riscv64 = std.zig.CrossTarget{...@@ -21,11 +21,6 @@ const linux_riscv64 = std.zig.CrossTarget{
21 .os_tag = .linux,21 .os_tag = .linux,
22};22};
2323
24const linux_arm = std.zig.CrossTarget{
25 .cpu_arch = .arm,
26 .os_tag = .linux,
27};
28
29const wasi = std.zig.CrossTarget{24const wasi = std.zig.CrossTarget{
30 .cpu_arch = .wasm32,25 .cpu_arch = .wasm32,
31 .os_tag = .wasi,26 .os_tag = .wasi,
...@@ -35,6 +30,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -35,6 +30,7 @@ pub fn addCases(ctx: *TestContext) !void {
35 try @import("zir.zig").addCases(ctx);30 try @import("zir.zig").addCases(ctx);
36 try @import("cbe.zig").addCases(ctx);31 try @import("cbe.zig").addCases(ctx);
37 try @import("spu-ii.zig").addCases(ctx);32 try @import("spu-ii.zig").addCases(ctx);
33 try @import("arm.zig").addCases(ctx);
3834
39 {35 {
40 var case = ctx.exe("hello world with updates", linux_x64);36 var case = ctx.exe("hello world with updates", linux_x64);
...@@ -76,7 +72,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -76,7 +72,7 @@ pub fn addCases(ctx: *TestContext) !void {
76 \\ );72 \\ );
77 \\ unreachable;73 \\ unreachable;
78 \\}74 \\}
79 ,75 ,
80 "Hello, World!\n",76 "Hello, World!\n",
81 );77 );
82 // Now change the message only78 // Now change the message only
...@@ -108,7 +104,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -108,7 +104,7 @@ pub fn addCases(ctx: *TestContext) !void {
108 \\ );104 \\ );
109 \\ unreachable;105 \\ unreachable;
110 \\}106 \\}
111 ,107 ,
112 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",108 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
113 );109 );
114 // Now we print it twice.110 // Now we print it twice.
...@@ -184,42 +180,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -184,42 +180,7 @@ pub fn addCases(ctx: *TestContext) !void {
184 \\ );180 \\ );
185 \\ unreachable;181 \\ unreachable;
186 \\}182 \\}
187 ,183 ,
188 "Hello, World!\n",
189 );
190 }
191
192 {
193 var case = ctx.exe("hello world", linux_arm);
194 // Regular old hello world
195 case.addCompareOutput(
196 \\export fn _start() noreturn {
197 \\ print();
198 \\ exit();
199 \\}
200 \\
201 \\fn print() void {
202 \\ asm volatile ("svc #0"
203 \\ :
204 \\ : [number] "{r7}" (4),
205 \\ [arg1] "{r0}" (1),
206 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
207 \\ [arg3] "{r2}" (14)
208 \\ : "memory"
209 \\ );
210 \\ return;
211 \\}
212 \\
213 \\fn exit() noreturn {
214 \\ asm volatile ("svc #0"
215 \\ :
216 \\ : [number] "{r7}" (1),
217 \\ [arg1] "{r0}" (0)
218 \\ : "memory"
219 \\ );
220 \\ unreachable;
221 \\}
222 ,
223 "Hello, World!\n",184 "Hello, World!\n",
224 );185 );
225 }186 }
...@@ -244,7 +205,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -244,7 +205,7 @@ pub fn addCases(ctx: *TestContext) !void {
244 \\ );205 \\ );
245 \\ unreachable;206 \\ unreachable;
246 \\}207 \\}
247 ,208 ,
248 "Hello, World!\n",209 "Hello, World!\n",
249 );210 );
250 }211 }
...@@ -271,7 +232,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -271,7 +232,7 @@ pub fn addCases(ctx: *TestContext) !void {
271 \\ );232 \\ );
272 \\ unreachable;233 \\ unreachable;
273 \\}234 \\}
274 ,235 ,
275 "",236 "",
276 );237 );
277 }238 }
...@@ -298,7 +259,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -298,7 +259,7 @@ pub fn addCases(ctx: *TestContext) !void {
298 \\ );259 \\ );
299 \\ unreachable;260 \\ unreachable;
300 \\}261 \\}
301 ,262 ,
302 "",263 "",
303 );264 );
304 }265 }
...@@ -329,7 +290,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -329,7 +290,7 @@ pub fn addCases(ctx: *TestContext) !void {
329 \\ );290 \\ );
330 \\ unreachable;291 \\ unreachable;
331 \\}292 \\}
332 ,293 ,
333 "",294 "",
334 );295 );
335296
...@@ -362,7 +323,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -362,7 +323,7 @@ pub fn addCases(ctx: *TestContext) !void {
362 \\ );323 \\ );
363 \\ unreachable;324 \\ unreachable;
364 \\}325 \\}
365 ,326 ,
366 "",327 "",
367 );328 );
368329
...@@ -398,7 +359,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -398,7 +359,7 @@ pub fn addCases(ctx: *TestContext) !void {
398 \\ );359 \\ );
399 \\ unreachable;360 \\ unreachable;
400 \\}361 \\}
401 ,362 ,
402 "",363 "",
403 );364 );
404365
...@@ -435,7 +396,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -435,7 +396,7 @@ pub fn addCases(ctx: *TestContext) !void {
435 \\ );396 \\ );
436 \\ unreachable;397 \\ unreachable;
437 \\}398 \\}
438 ,399 ,
439 "",400 "",
440 );401 );
441402
...@@ -465,7 +426,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -465,7 +426,7 @@ pub fn addCases(ctx: *TestContext) !void {
465 \\ );426 \\ );
466 \\ unreachable;427 \\ unreachable;
467 \\}428 \\}
468 ,429 ,
469 "",430 "",
470 );431 );
471432
...@@ -499,7 +460,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -499,7 +460,7 @@ pub fn addCases(ctx: *TestContext) !void {
499 \\ );460 \\ );
500 \\ unreachable;461 \\ unreachable;
501 \\}462 \\}
502 ,463 ,
503 "",464 "",
504 );465 );
505466
...@@ -523,7 +484,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -523,7 +484,7 @@ pub fn addCases(ctx: *TestContext) !void {
523 \\ );484 \\ );
524 \\ unreachable;485 \\ unreachable;
525 \\}486 \\}
526 ,487 ,
527 "",488 "",
528 );489 );
529490
...@@ -562,7 +523,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -562,7 +523,7 @@ pub fn addCases(ctx: *TestContext) !void {
562 \\ );523 \\ );
563 \\ unreachable;524 \\ unreachable;
564 \\}525 \\}
565 ,526 ,
566 "hello\nhello\nhello\nhello\n",527 "hello\nhello\nhello\nhello\n",
567 );528 );
568529
...@@ -599,7 +560,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -599,7 +560,7 @@ pub fn addCases(ctx: *TestContext) !void {
599 \\ );560 \\ );
600 \\ unreachable;561 \\ unreachable;
601 \\}562 \\}
602 ,563 ,
603 "",564 "",
604 );565 );
605566
...@@ -641,7 +602,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -641,7 +602,7 @@ pub fn addCases(ctx: *TestContext) !void {
641 \\ );602 \\ );
642 \\ unreachable;603 \\ unreachable;
643 \\}604 \\}
644 ,605 ,
645 "",606 "",
646 );607 );
647608
...@@ -693,7 +654,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -693,7 +654,7 @@ pub fn addCases(ctx: *TestContext) !void {
693 \\ );654 \\ );
694 \\ unreachable;655 \\ unreachable;
695 \\}656 \\}
696 ,657 ,
697 "",658 "",
698 );659 );
699660
...@@ -755,7 +716,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -755,7 +716,7 @@ pub fn addCases(ctx: *TestContext) !void {
755 \\ );716 \\ );
756 \\ unreachable;717 \\ unreachable;
757 \\}718 \\}
758 ,719 ,
759 "",720 "",
760 );721 );
761722
...@@ -788,7 +749,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -788,7 +749,7 @@ pub fn addCases(ctx: *TestContext) !void {
788 \\ );749 \\ );
789 \\ unreachable;750 \\ unreachable;
790 \\}751 \\}
791 ,752 ,
792 "",753 "",
793 );754 );
794755
...@@ -820,7 +781,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -820,7 +781,7 @@ pub fn addCases(ctx: *TestContext) !void {
820 \\ );781 \\ );
821 \\ unreachable;782 \\ unreachable;
822 \\}783 \\}
823 ,784 ,
824 "",785 "",
825 );786 );
826787
...@@ -845,7 +806,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -845,7 +806,7 @@ pub fn addCases(ctx: *TestContext) !void {
845 \\ );806 \\ );
846 \\ unreachable;807 \\ unreachable;
847 \\}808 \\}
848 ,809 ,
849 "",810 "",
850 );811 );
851812
...@@ -871,7 +832,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -871,7 +832,7 @@ pub fn addCases(ctx: *TestContext) !void {
871 \\ );832 \\ );
872 \\ unreachable;833 \\ unreachable;
873 \\}834 \\}
874 ,835 ,
875 "",836 "",
876 );837 );
877838
...@@ -904,7 +865,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -904,7 +865,7 @@ pub fn addCases(ctx: *TestContext) !void {
904 \\ );865 \\ );
905 \\ unreachable;866 \\ unreachable;
906 \\}867 \\}
907 ,868 ,
908 "hello\nhello\nhello\nhello\nhello\n",869 "hello\nhello\nhello\nhello\nhello\n",
909 );870 );
910 }871 }
...@@ -923,7 +884,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -923,7 +884,7 @@ pub fn addCases(ctx: *TestContext) !void {
923 \\ bar();884 \\ bar();
924 \\}885 \\}
925 \\fn bar() void {}886 \\fn bar() void {}
926 ,887 ,
927 "42\n",888 "42\n",
928 );889 );
929890
...@@ -941,7 +902,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -941,7 +902,7 @@ pub fn addCases(ctx: *TestContext) !void {
941 \\ bar();902 \\ bar();
942 \\}903 \\}
943 \\fn bar() void {}904 \\fn bar() void {}
944 ,905 ,
945 "42\n",906 "42\n",
946 );907 );
947908
...@@ -957,10 +918,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -957,10 +918,10 @@ pub fn addCases(ctx: *TestContext) !void {
957 \\ bar();918 \\ bar();
958 \\}919 \\}
959 \\fn bar() void {}920 \\fn bar() void {}
960 ,921 ,
961 // This is what you get when you take the bits of the IEE-754922 // This is what you get when you take the bits of the IEE-754
962 // representation of 42.0 and reinterpret them as an unsigned923 // representation of 42.0 and reinterpret them as an unsigned
963 // integer. Guess that's a bug in wasmtime.924 // integer. Guess that's a bug in wasmtime.
964 "1109917696\n",925 "1109917696\n",
965 );926 );
966 }927 }