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) {
402402 return Instruction{
403403 .DataProcessing = .{
404404 .cond = @enumToInt(cond),
405 .i = if (op2 == .Immediate) 1 else 0,
405 .i = @boolToInt(op2 == .Immediate),
406406 .opcode = @enumToInt(opcode),
407407 .s = s,
408408 .rn = rn.id(),
......@@ -430,11 +430,11 @@ pub const Instruction = union(enum) {
430430 .rd = rd.id(),
431431 .offset = offset.toU12(),
432432 .load_store = load_store,
433 .write_back = if (write_back) 1 else 0,
433 .write_back = @boolToInt(write_back),
434434 .byte_word = byte_word,
435 .up_down = if (positive) 1 else 0,
436 .pre_post = if (pre_index) 1 else 0,
437 .imm = if (offset == .Immediate) 0 else 1,
435 .up_down = @boolToInt(positive),
436 .pre_post = @boolToInt(pre_index),
437 .imm = @boolToInt(offset != .Immediate),
438438 },
439439 };
440440 }
......@@ -454,7 +454,7 @@ pub const Instruction = union(enum) {
454454 .register_list = @bitCast(u16, reg_list),
455455 .rn = rn.id(),
456456 .load_store = load_store,
457 .write_back = if (write_back) 1 else 0,
457 .write_back = @boolToInt(write_back),
458458 .psr_or_user = psr_or_user,
459459 .up_down = up_down,
460460 .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{
2121 .os_tag = .linux,
2222};
2323
24const linux_arm = std.zig.CrossTarget{
25 .cpu_arch = .arm,
26 .os_tag = .linux,
27};
28
2924const wasi = std.zig.CrossTarget{
3025 .cpu_arch = .wasm32,
3126 .os_tag = .wasi,
......@@ -35,6 +30,7 @@ pub fn addCases(ctx: *TestContext) !void {
3530 try @import("zir.zig").addCases(ctx);
3631 try @import("cbe.zig").addCases(ctx);
3732 try @import("spu-ii.zig").addCases(ctx);
33 try @import("arm.zig").addCases(ctx);
3834
3935 {
4036 var case = ctx.exe("hello world with updates", linux_x64);
......@@ -76,7 +72,7 @@ pub fn addCases(ctx: *TestContext) !void {
7672 \\ );
7773 \\ unreachable;
7874 \\}
79 ,
75 ,
8076 "Hello, World!\n",
8177 );
8278 // Now change the message only
......@@ -108,7 +104,7 @@ pub fn addCases(ctx: *TestContext) !void {
108104 \\ );
109105 \\ unreachable;
110106 \\}
111 ,
107 ,
112108 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
113109 );
114110 // Now we print it twice.
......@@ -184,42 +180,7 @@ pub fn addCases(ctx: *TestContext) !void {
184180 \\ );
185181 \\ unreachable;
186182 \\}
187 ,
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 ,
183 ,
223184 "Hello, World!\n",
224185 );
225186 }
......@@ -244,7 +205,7 @@ pub fn addCases(ctx: *TestContext) !void {
244205 \\ );
245206 \\ unreachable;
246207 \\}
247 ,
208 ,
248209 "Hello, World!\n",
249210 );
250211 }
......@@ -271,7 +232,7 @@ pub fn addCases(ctx: *TestContext) !void {
271232 \\ );
272233 \\ unreachable;
273234 \\}
274 ,
235 ,
275236 "",
276237 );
277238 }
......@@ -298,7 +259,7 @@ pub fn addCases(ctx: *TestContext) !void {
298259 \\ );
299260 \\ unreachable;
300261 \\}
301 ,
262 ,
302263 "",
303264 );
304265 }
......@@ -329,7 +290,7 @@ pub fn addCases(ctx: *TestContext) !void {
329290 \\ );
330291 \\ unreachable;
331292 \\}
332 ,
293 ,
333294 "",
334295 );
335296
......@@ -362,7 +323,7 @@ pub fn addCases(ctx: *TestContext) !void {
362323 \\ );
363324 \\ unreachable;
364325 \\}
365 ,
326 ,
366327 "",
367328 );
368329
......@@ -398,7 +359,7 @@ pub fn addCases(ctx: *TestContext) !void {
398359 \\ );
399360 \\ unreachable;
400361 \\}
401 ,
362 ,
402363 "",
403364 );
404365
......@@ -435,7 +396,7 @@ pub fn addCases(ctx: *TestContext) !void {
435396 \\ );
436397 \\ unreachable;
437398 \\}
438 ,
399 ,
439400 "",
440401 );
441402
......@@ -465,7 +426,7 @@ pub fn addCases(ctx: *TestContext) !void {
465426 \\ );
466427 \\ unreachable;
467428 \\}
468 ,
429 ,
469430 "",
470431 );
471432
......@@ -499,7 +460,7 @@ pub fn addCases(ctx: *TestContext) !void {
499460 \\ );
500461 \\ unreachable;
501462 \\}
502 ,
463 ,
503464 "",
504465 );
505466
......@@ -523,7 +484,7 @@ pub fn addCases(ctx: *TestContext) !void {
523484 \\ );
524485 \\ unreachable;
525486 \\}
526 ,
487 ,
527488 "",
528489 );
529490
......@@ -562,7 +523,7 @@ pub fn addCases(ctx: *TestContext) !void {
562523 \\ );
563524 \\ unreachable;
564525 \\}
565 ,
526 ,
566527 "hello\nhello\nhello\nhello\n",
567528 );
568529
......@@ -599,7 +560,7 @@ pub fn addCases(ctx: *TestContext) !void {
599560 \\ );
600561 \\ unreachable;
601562 \\}
602 ,
563 ,
603564 "",
604565 );
605566
......@@ -641,7 +602,7 @@ pub fn addCases(ctx: *TestContext) !void {
641602 \\ );
642603 \\ unreachable;
643604 \\}
644 ,
605 ,
645606 "",
646607 );
647608
......@@ -693,7 +654,7 @@ pub fn addCases(ctx: *TestContext) !void {
693654 \\ );
694655 \\ unreachable;
695656 \\}
696 ,
657 ,
697658 "",
698659 );
699660
......@@ -755,7 +716,7 @@ pub fn addCases(ctx: *TestContext) !void {
755716 \\ );
756717 \\ unreachable;
757718 \\}
758 ,
719 ,
759720 "",
760721 );
761722
......@@ -788,7 +749,7 @@ pub fn addCases(ctx: *TestContext) !void {
788749 \\ );
789750 \\ unreachable;
790751 \\}
791 ,
752 ,
792753 "",
793754 );
794755
......@@ -820,7 +781,7 @@ pub fn addCases(ctx: *TestContext) !void {
820781 \\ );
821782 \\ unreachable;
822783 \\}
823 ,
784 ,
824785 "",
825786 );
826787
......@@ -845,7 +806,7 @@ pub fn addCases(ctx: *TestContext) !void {
845806 \\ );
846807 \\ unreachable;
847808 \\}
848 ,
809 ,
849810 "",
850811 );
851812
......@@ -871,7 +832,7 @@ pub fn addCases(ctx: *TestContext) !void {
871832 \\ );
872833 \\ unreachable;
873834 \\}
874 ,
835 ,
875836 "",
876837 );
877838
......@@ -904,7 +865,7 @@ pub fn addCases(ctx: *TestContext) !void {
904865 \\ );
905866 \\ unreachable;
906867 \\}
907 ,
868 ,
908869 "hello\nhello\nhello\nhello\nhello\n",
909870 );
910871 }
......@@ -923,7 +884,7 @@ pub fn addCases(ctx: *TestContext) !void {
923884 \\ bar();
924885 \\}
925886 \\fn bar() void {}
926 ,
887 ,
927888 "42\n",
928889 );
929890
......@@ -941,7 +902,7 @@ pub fn addCases(ctx: *TestContext) !void {
941902 \\ bar();
942903 \\}
943904 \\fn bar() void {}
944 ,
905 ,
945906 "42\n",
946907 );
947908
......@@ -957,10 +918,10 @@ pub fn addCases(ctx: *TestContext) !void {
957918 \\ bar();
958919 \\}
959920 \\fn bar() void {}
960 ,
961 // This is what you get when you take the bits of the IEE-754
962 // representation of 42.0 and reinterpret them as an unsigned
963 // integer. Guess that's a bug in wasmtime.
921 ,
922 // This is what you get when you take the bits of the IEE-754
923 // representation of 42.0 and reinterpret them as an unsigned
924 // integer. Guess that's a bug in wasmtime.
964925 "1109917696\n",
965926 );
966927 }