From 314522210cf9d4ac750732a802687aae46c4c9ed Mon Sep 17 00:00:00 2001 From: Laborratte5 Date: Thu, 15 May 2025 17:50:53 +0200 Subject: [PATCH] test: Add "addition" codegen test --- test/simple_add.c0 | 3 +++ test/simple_add.c0.expected | 15 +++++++++++++++ test/var_add.c0 | 4 ++++ test/var_add.c0.expected | 16 ++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 test/simple_add.c0 create mode 100644 test/simple_add.c0.expected create mode 100644 test/var_add.c0 create mode 100644 test/var_add.c0.expected diff --git a/test/simple_add.c0 b/test/simple_add.c0 new file mode 100644 index 0000000..932f743 --- /dev/null +++ b/test/simple_add.c0 @@ -0,0 +1,3 @@ +int main() { + return 1 + 1; +} \ No newline at end of file diff --git a/test/simple_add.c0.expected b/test/simple_add.c0.expected new file mode 100644 index 0000000..19c78a0 --- /dev/null +++ b/test/simple_add.c0.expected @@ -0,0 +1,15 @@ +.global main +.global _main +.text +main: +call _main +# move the return value into the first argument for the syscall +movq %rax, %rdi +# move the exit syscall number into rax +movq $0x3C, %rax +syscall +_main: +# your generated code here + mov $1,%0 + add %0,%0 + ret diff --git a/test/var_add.c0 b/test/var_add.c0 new file mode 100644 index 0000000..959d0ec --- /dev/null +++ b/test/var_add.c0 @@ -0,0 +1,4 @@ +int main() { + int x = 1; + return x + 2; +} \ No newline at end of file diff --git a/test/var_add.c0.expected b/test/var_add.c0.expected new file mode 100644 index 0000000..4d57163 --- /dev/null +++ b/test/var_add.c0.expected @@ -0,0 +1,16 @@ +.global main +.global _main +.text +main: +call _main +# move the return value into the first argument for the syscall +movq %rax, %rdi +# move the exit syscall number into rax +movq $0x3C, %rax +syscall +_main: +# your generated code here + mov $1,%0 + mov $2,%1 + add %0,%1 + ret