From 7e329dda8e3b973203ae9efe17c49d64a407cd26 Mon Sep 17 00:00:00 2001 From: Keyvan Kambakhsh Date: Sun, 8 Dec 2024 02:28:44 +0330 Subject: [PATCH] test: Update run outputs on examples --- Makefile | 2 +- scripts/test.py | 16 +- tests/output/inp.c_output.txt | 65 -- tests/output/inp3.c_output.txt | 617 ------------------- tests/output/inp3.c_run_output.txt | 3 +- tests/output/inp4.c_output.txt | 21 - tests/output/inp4.c_run_output.txt | 2 + tests/output/inp_arg_macro.c_asm_output.txt | 76 --- tests/output/inp_bin_op.c_run_output.txt | 3 + tests/output/inp_break.c_run_output.txt | 70 +++ tests/output/inp_extern.c_run_output.txt | 3 + tests/output/inp_preprocess.c_run_output.txt | 7 +- tests/output/inp_vararg.c_lex_output.txt | 170 ----- tests/output/inp_vararg.c_prep_output.txt | 128 ---- tests/output/inp_vararg.c_tree_output.txt | 110 ---- tests/output/switch.c_asm_output.txt | 178 ------ 16 files changed, 93 insertions(+), 1378 deletions(-) delete mode 100644 tests/output/inp.c_output.txt delete mode 100644 tests/output/inp3.c_output.txt delete mode 100644 tests/output/inp4.c_output.txt delete mode 100644 tests/output/inp_arg_macro.c_asm_output.txt create mode 100644 tests/output/inp_extern.c_run_output.txt delete mode 100644 tests/output/inp_vararg.c_lex_output.txt delete mode 100644 tests/output/inp_vararg.c_prep_output.txt delete mode 100644 tests/output/inp_vararg.c_tree_output.txt delete mode 100644 tests/output/switch.c_asm_output.txt diff --git a/Makefile b/Makefile index 8fdc30d..16a5f53 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ $(STAGE3_BIN): $(STAGE2_BIN) **/*.h **/*.c rm -rf target2 run: $(BIN) - @./a.out $(program) --asm > out.asm + @./30cc $(program) --asm > out.asm @nasm -f elf64 out.asm -o out.o @ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc -o out out.o @echo "$ ./out \"$(arguments)\"" diff --git a/scripts/test.py b/scripts/test.py index 887fd0a..0ea155b 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -93,7 +93,7 @@ def git_add_and_diff(file_path): def main(): mode = None - if len(sys.argv) > 2: + if len(sys.argv) >= 2: mode = sys.argv[1] if mode not in ["update", "revert", "run"]: print("Invalid mode. Use 'update' or 'revert' or 'run'.") @@ -120,20 +120,20 @@ def main(): diff_count = 0 failed = False for test_file in TEST_FILES.keys(): - for mode in ['lex', 'prep', 'tree', 'asm']: + for md in ['lex', 'prep', 'tree', 'asm']: extension = "txt" - if mode == "asm": + if md == "asm": extension = "asm" output_file = os.path.join( OUTPUT_FOLDER, - f"{os.path.basename(test_file)}_{mode}_output.{extension}", + f"{os.path.basename(test_file)}_{md}_output.{extension}", ) - print(test_file, mode) - output = run(test_file, mode) + print(test_file, md) + output = run(test_file, md) if output is None: failed = True - if mode == "revert": + if md == "revert": revert_snapshot(output_file) continue @@ -147,7 +147,7 @@ def main(): update_output(output_file, output, True) else: update_output(output_file, output) - + if mode == "run": for test_file, inputs in TEST_FILES.items(): if len(inputs) == 0: diff --git a/tests/output/inp.c_output.txt b/tests/output/inp.c_output.txt deleted file mode 100644 index dc1fa92..0000000 --- a/tests/output/inp.c_output.txt +++ /dev/null @@ -1,65 +0,0 @@ -section .data -__printf_size: equ 16 -__temp_str_1 db `%u `, 0 -__temp_str_2 db `%u `, 0 -__main_size: equ 96 -section .text -extern printf -global main -main: -push rbp -mov rbp, rsp -sub rsp, __main_size -mov rax, 10 -mov [rsp+0], rax -mov rax, 0 -mov [rsp+8], rax -__tmp_label_0: -mov rax, [rsp + 8] -mov rbx, 5 -cmp rax, rbx -jl __tmp_label_2 -mov rax, 0 -jmp __tmp_label_3 -__tmp_label_2: -mov rax, 1 -__tmp_label_3: -mov [rsp + 16], rax -mov rax, [rsp + 16] -cmp rax, 0 -je __tmp_label_1 -mov rax, 2 -mov [rsp+24], rax -mov rax, __temp_str_1 -mov [rsp + 32], rax -mov rax, [rsp + 24] -mov [rsp + 40], rax -mov rdi, [rsp + 32] -mov rsi, [rsp + 40] -call printf -mov [rsp + 48], rax -mov rax, [rsp + 8] -mov rbx, 1 -add rax, rbx -mov [rsp + 24], rax -mov rax, [rsp + 24] -mov [rsp+8], rax -jmp __tmp_label_0 -__tmp_label_1: -mov rax, __temp_str_2 -mov [rsp + 8], rax -mov rax, [rsp + 0] -mov [rsp + 16], rax -mov rdi, [rsp + 8] -mov rsi, [rsp + 16] -call printf -mov [rsp + 24], rax -mov rsp, rbp -pop rbp -ret -extern exit -global _start -_start: -call main -mov rdi, 0 -call exit diff --git a/tests/output/inp3.c_output.txt b/tests/output/inp3.c_output.txt deleted file mode 100644 index 8802ae7..0000000 --- a/tests/output/inp3.c_output.txt +++ /dev/null @@ -1,617 +0,0 @@ -section .data -__printf_size: equ 16 -__doub_size: equ 32 -__temp_str_2 db `Fact: %u\n`, 0 -__fact_size: equ 80 -__fibo_size: equ 96 -__temp_str_5 db `I: %u\n`, 0 -__temp_str_6 db `%c %c %u`, 0 -__temp_str_7 db `\n`, 0 -__temp_str_8 db `Result: %u\n`, 0 -__temp_str_9 db `Addr of a: %u\n`, 0 -__temp_str_10 db `Value of b: %u\n`, 0 -__temp_str_11 db `Addr of c: %u\n`, 0 -__temp_str_12 db `Double of 123: %u\n`, 0 -__temp_str_13 db `Factorial 5: %u\n`, 0 -__temp_str_14 db `TRUE\n`, 0 -__temp_str_15 db `FALSE\n`, 0 -__temp_str_16 db `TRUE\n`, 0 -__temp_str_17 db `FALSE\n`, 0 -__temp_str_18 db `%u\n`, 0 -__temp_str_19 db `%u `, 0 -__temp_str_20 db `%u `, 0 -__temp_str_21 db `%u `, 0 -__temp_str_22 db `%u `, 0 -__temp_str_23 db `%u `, 0 -__temp_str_24 db `%u `, 0 -__temp_str_25 db `%u `, 0 -__temp_str_26 db `%u `, 0 -__temp_str_27 db `%u\n`, 0 -__temp_str_28 db `%u `, 0 -__temp_str_29 db `\nDONE!\n`, 0 -__temp_str_30 db `%u\n`, 0 -__main_size: equ 1040 -section .text -extern printf -global doub -doub: -push rbp -mov rbp, rsp -sub rsp, __doub_size -mov [rsp+0], rdi -mov rax, [rsp + 0] -mov rbx, 2 -mul rbx -mov [rsp + 8], rax -mov rax, [rsp + 8] -mov rsp, rbp -pop rbp -ret -mov rsp, rbp -pop rbp -ret -global fact -fact: -push rbp -mov rbp, rsp -sub rsp, __fact_size -mov [rsp+0], rdi -mov rax, __temp_str_2 -mov [rsp + 8], rax -mov rax, [rsp + 0] -mov [rsp + 16], rax -mov rdi, [rsp + 8] -mov rsi, [rsp + 16] -call printf -mov [rsp + 24], rax -mov rax, 0 -cmp rax, [rsp + 0] -je __tmp_label_0 -mov rax, [rsp + 0] -mov rbx, 1 -sub rax, rbx -mov [rsp + 32], rax -mov rax, [rsp + 32] -mov [rsp + 40], rax -mov rdi, [rsp + 40] -call fact -mov [rsp + 48], rax -mov rax, [rsp + 0] -mov rbx, [rsp + 48] -mul rbx -mov [rsp + 56], rax -mov rax, [rsp + 56] -mov rsp, rbp -pop rbp -ret -jmp __tmp_label_1 -__tmp_label_0: -mov rax, 1 -mov rsp, rbp -pop rbp -ret -__tmp_label_1: -mov rsp, rbp -pop rbp -ret -global fibo -fibo: -push rbp -mov rbp, rsp -sub rsp, __fibo_size -mov [rsp+0], rdi -mov rax, [rsp + 0] -mov rbx, 0 -cmp rax, rbx -je __tmp_label_2 -mov rax, 0 -jmp __tmp_label_3 -__tmp_label_2: -mov rax, 1 -__tmp_label_3: -mov [rsp + 8], rax -mov rax, 0 -cmp rax, [rsp + 8] -je __tmp_label_4 -mov rax, 1 -mov rsp, rbp -pop rbp -ret -jmp __tmp_label_5 -__tmp_label_4: -mov rax, [rsp + 0] -mov rbx, 1 -cmp rax, rbx -je __tmp_label_6 -mov rax, 0 -jmp __tmp_label_7 -__tmp_label_6: -mov rax, 1 -__tmp_label_7: -mov [rsp + 16], rax -mov rax, 0 -cmp rax, [rsp + 16] -je __tmp_label_8 -mov rax, 1 -mov rsp, rbp -pop rbp -ret -jmp __tmp_label_9 -__tmp_label_8: -mov rax, [rsp + 0] -mov rbx, 1 -sub rax, rbx -mov [rsp + 24], rax -mov rax, [rsp + 24] -mov [rsp + 32], rax -mov rdi, [rsp + 32] -call fibo -mov [rsp + 40], rax -mov rax, [rsp + 0] -mov rbx, 2 -sub rax, rbx -mov [rsp + 48], rax -mov rax, [rsp + 48] -mov [rsp + 56], rax -mov rdi, [rsp + 56] -call fibo -mov [rsp + 64], rax -mov rax, [rsp + 40] -mov rbx, [rsp + 64] -add rax, rbx -mov [rsp + 72], rax -mov rax, [rsp + 72] -mov rsp, rbp -pop rbp -ret -__tmp_label_9: -__tmp_label_5: -mov rsp, rbp -pop rbp -ret -global main -main: -push rbp -mov rbp, rsp -sub rsp, __main_size -mov rax, 0 -mov [rsp+0], rax -__tmp_label_10: -mov rax, [rsp + 0] -mov rbx, 10 -cmp rax, rbx -jl __tmp_label_12 -mov rax, 0 -jmp __tmp_label_13 -__tmp_label_12: -mov rax, 1 -__tmp_label_13: -mov [rsp + 8], rax -mov rax, [rsp + 8] -cmp rax, 0 -je __tmp_label_11 -mov rax, __temp_str_5 -mov [rsp + 16], rax -mov rax, [rsp + 0] -mov [rsp + 24], rax -mov rdi, [rsp + 16] -mov rsi, [rsp + 24] -call printf -mov [rsp + 32], rax -mov rax, [rsp + 0] -mov rbx, 1 -add rax, rbx -mov [rsp + 40], rax -mov rax, [rsp + 40] -mov [rsp+0], rax -jmp __tmp_label_10 -__tmp_label_11: -mov rax, __temp_str_6 -mov [rsp + 16], rax -mov rax, 97 -mov [rsp + 24], rax -mov rax, 110 -mov [rsp + 32], rax -mov rax, 99 -mov [rsp + 40], rax -mov rdi, [rsp + 16] -mov rsi, [rsp + 24] -mov rdx, [rsp + 32] -mov rcx, [rsp + 40] -call printf -mov [rsp + 48], rax -mov rax, __temp_str_7 -mov [rsp + 56], rax -mov rdi, [rsp + 56] -call printf -mov [rsp + 64], rax -mov rax, 10 -mov [rsp+72], rax -mov rax, 20 -mov [rsp+80], rax -mov rax, [rsp + 72] -mov rbx, [rsp + 80] -mul rbx -mov [rsp + 96], rax -mov rax, [rsp + 96] -mov [rsp+88], rax -mov rax, [rsp + 88] -mov rbx, [rsp + 72] -add rax, rbx -mov [rsp + 112], rax -mov rax, [rsp + 88] -mov rbx, [rsp + 112] -mul rbx -mov [rsp + 120], rax -mov rax, [rsp + 120] -mov [rsp+104], rax -mov rax, __temp_str_8 -mov [rsp + 128], rax -mov rax, [rsp + 80] -mov rbx, [rsp + 72] -add rax, rbx -mov [rsp + 136], rax -mov rax, [rsp + 136] -mov rbx, [rsp + 72] -mul rbx -mov [rsp + 144], rax -mov rax, [rsp + 104] -mov rbx, [rsp + 144] -add rax, rbx -mov [rsp + 152], rax -mov rax, [rsp + 88] -mov rbx, [rsp + 152] -add rax, rbx -mov [rsp + 160], rax -mov rax, [rsp + 88] -mov rbx, [rsp + 160] -add rax, rbx -mov [rsp + 168], rax -mov rax, [rsp + 168] -mov [rsp + 176], rax -mov rdi, [rsp + 128] -mov rsi, [rsp + 176] -call printf -mov [rsp + 184], rax -mov rax, rsp -add rax, 88 -mov rax, rax -mov [rsp+192], rax -mov rax, __temp_str_9 -mov [rsp + 200], rax -mov rax, rsp -add rax, 72 -mov rax, rax -mov [rsp + 208], rax -mov rdi, [rsp + 200] -mov rsi, [rsp + 208] -call printf -mov [rsp + 216], rax -mov rax, __temp_str_10 -mov [rsp + 224], rax -mov rax, rsp -add rax, 72 -mov rax, rax -mov rbx, 8 -add rax, rbx -mov [rsp + 232], rax -mov rax, [rsp + 232] -mov rax, [rax] -mov rax, rax -mov [rsp + 240], rax -mov rdi, [rsp + 224] -mov rsi, [rsp + 240] -call printf -mov [rsp + 248], rax -mov rax, __temp_str_11 -mov [rsp + 256], rax -mov rax, [rsp + 192] -mov [rsp + 264], rax -mov rdi, [rsp + 256] -mov rsi, [rsp + 264] -call printf -mov [rsp + 272], rax -mov rax, __temp_str_12 -mov [rsp + 280], rax -mov rax, 123 -mov [rsp + 288], rax -mov rdi, [rsp + 288] -call doub -mov [rsp + 296], rax -mov rax, 123 -mov rbx, [rsp + 296] -mul rbx -mov [rsp + 304], rax -mov rax, [rsp + 304] -mov [rsp + 312], rax -mov rdi, [rsp + 312] -call doub -mov [rsp + 320], rax -mov rax, [rsp + 320] -mov rbx, 2 -mul rbx -mov [rsp + 328], rax -mov rax, [rsp + 328] -mov [rsp + 336], rax -mov rdi, [rsp + 336] -call doub -mov [rsp + 344], rax -mov rax, [rsp + 344] -mov rbx, 10 -add rax, rbx -mov [rsp + 352], rax -mov rax, [rsp + 352] -mov [rsp + 360], rax -mov rdi, [rsp + 280] -mov rsi, [rsp + 360] -call printf -mov [rsp + 368], rax -mov rax, __temp_str_13 -mov [rsp + 376], rax -mov rax, 5 -mov [rsp + 384], rax -mov rdi, [rsp + 384] -call fact -mov [rsp + 392], rax -mov rax, [rsp + 392] -mov [rsp + 400], rax -mov rdi, [rsp + 376] -mov rsi, [rsp + 400] -call printf -mov [rsp + 408], rax -mov rax, 0 -cmp rax, 1 -je __tmp_label_14 -mov rax, __temp_str_14 -mov [rsp + 416], rax -mov rdi, [rsp + 416] -call printf -mov [rsp + 424], rax -jmp __tmp_label_15 -__tmp_label_14: -mov rax, __temp_str_15 -mov [rsp + 416], rax -mov rdi, [rsp + 416] -call printf -mov [rsp + 424], rax -__tmp_label_15: -mov rax, 0 -cmp rax, 1 -je __tmp_label_16 -mov rax, __temp_str_16 -mov [rsp + 416], rax -mov rdi, [rsp + 416] -call printf -mov [rsp + 424], rax -jmp __tmp_label_17 -__tmp_label_16: -mov rax, __temp_str_17 -mov [rsp + 416], rax -mov rdi, [rsp + 416] -call printf -mov [rsp + 424], rax -__tmp_label_17: -mov rax, __temp_str_18 -mov [rsp + 416], rax -mov rax, 5 -mov rbx, 1 -cmp rax, rbx -jne __tmp_label_18 -mov rax, 0 -jmp __tmp_label_19 -__tmp_label_18: -mov rax, 1 -__tmp_label_19: -mov [rsp + 424], rax -mov rax, [rsp + 424] -mov [rsp + 432], rax -mov rdi, [rsp + 416] -mov rsi, [rsp + 432] -call printf -mov [rsp + 440], rax -mov rax, __temp_str_19 -mov [rsp + 448], rax -mov rax, 0 -mov [rsp + 456], rax -mov rdi, [rsp + 456] -call fibo -mov [rsp + 464], rax -mov rax, [rsp + 464] -mov [rsp + 472], rax -mov rdi, [rsp + 448] -mov rsi, [rsp + 472] -call printf -mov [rsp + 480], rax -mov rax, __temp_str_20 -mov [rsp + 488], rax -mov rax, 1 -mov [rsp + 496], rax -mov rdi, [rsp + 496] -call fibo -mov [rsp + 504], rax -mov rax, [rsp + 504] -mov [rsp + 512], rax -mov rdi, [rsp + 488] -mov rsi, [rsp + 512] -call printf -mov [rsp + 520], rax -mov rax, __temp_str_21 -mov [rsp + 528], rax -mov rax, 2 -mov [rsp + 536], rax -mov rdi, [rsp + 536] -call fibo -mov [rsp + 544], rax -mov rax, [rsp + 544] -mov [rsp + 552], rax -mov rdi, [rsp + 528] -mov rsi, [rsp + 552] -call printf -mov [rsp + 560], rax -mov rax, __temp_str_22 -mov [rsp + 568], rax -mov rax, 3 -mov [rsp + 576], rax -mov rdi, [rsp + 576] -call fibo -mov [rsp + 584], rax -mov rax, [rsp + 584] -mov [rsp + 592], rax -mov rdi, [rsp + 568] -mov rsi, [rsp + 592] -call printf -mov [rsp + 600], rax -mov rax, __temp_str_23 -mov [rsp + 608], rax -mov rax, 4 -mov [rsp + 616], rax -mov rdi, [rsp + 616] -call fibo -mov [rsp + 624], rax -mov rax, [rsp + 624] -mov [rsp + 632], rax -mov rdi, [rsp + 608] -mov rsi, [rsp + 632] -call printf -mov [rsp + 640], rax -mov rax, __temp_str_24 -mov [rsp + 648], rax -mov rax, 5 -mov [rsp + 656], rax -mov rdi, [rsp + 656] -call fibo -mov [rsp + 664], rax -mov rax, [rsp + 664] -mov [rsp + 672], rax -mov rdi, [rsp + 648] -mov rsi, [rsp + 672] -call printf -mov [rsp + 680], rax -mov rax, __temp_str_25 -mov [rsp + 688], rax -mov rax, 6 -mov [rsp + 696], rax -mov rdi, [rsp + 696] -call fibo -mov [rsp + 704], rax -mov rax, [rsp + 704] -mov [rsp + 712], rax -mov rdi, [rsp + 688] -mov rsi, [rsp + 712] -call printf -mov [rsp + 720], rax -mov rax, __temp_str_26 -mov [rsp + 728], rax -mov rax, 7 -mov [rsp + 736], rax -mov rdi, [rsp + 736] -call fibo -mov [rsp + 744], rax -mov rax, [rsp + 744] -mov [rsp + 752], rax -mov rdi, [rsp + 728] -mov rsi, [rsp + 752] -call printf -mov [rsp + 760], rax -mov rax, __temp_str_27 -mov [rsp + 768], rax -mov rax, 8 -mov [rsp + 776], rax -mov rdi, [rsp + 776] -call fibo -mov [rsp + 784], rax -mov rax, [rsp + 784] -mov [rsp + 792], rax -mov rdi, [rsp + 768] -mov rsi, [rsp + 792] -call printf -mov [rsp + 800], rax -mov rax, 0 -mov [rsp+808], rax -__tmp_label_20: -mov rax, [rsp + 808] -mov rbx, 20 -cmp rax, rbx -jl __tmp_label_22 -mov rax, 0 -jmp __tmp_label_23 -__tmp_label_22: -mov rax, 1 -__tmp_label_23: -mov [rsp + 816], rax -mov rax, [rsp + 816] -cmp rax, 0 -je __tmp_label_21 -mov rax, __temp_str_28 -mov [rsp + 824], rax -mov rax, [rsp + 808] -mov [rsp + 832], rax -mov rdi, [rsp + 832] -call fibo -mov [rsp + 840], rax -mov rax, [rsp + 840] -mov [rsp + 848], rax -mov rdi, [rsp + 824] -mov rsi, [rsp + 848] -call printf -mov [rsp + 856], rax -mov rax, [rsp + 808] -mov rbx, 1 -add rax, rbx -mov [rsp + 824], rax -mov rax, [rsp + 824] -mov [rsp+808], rax -jmp __tmp_label_20 -__tmp_label_21: -mov rax, __temp_str_29 -mov [rsp + 808], rax -mov rdi, [rsp + 808] -call printf -mov [rsp + 816], rax -mov rax, __temp_str_30 -mov [rsp + 824], rax -mov rax, 1 -mov rbx, 1 -cmp rax, 0 -je __tmp_label_24 -mov rax, rbx -jmp __tmp_label_25 -__tmp_label_24: -mov rax, 0 -__tmp_label_25: -mov [rsp + 832], rax -mov rax, 1 -mov rbx, 1 -cmp rax, 0 -je __tmp_label_26 -mov rax, rbx -jmp __tmp_label_27 -__tmp_label_26: -mov rax, 0 -__tmp_label_27: -mov [rsp + 840], rax -mov rax, [rsp + 832] -mov rbx, [rsp + 840] -cmp rax, 0 -je __tmp_label_28 -mov rax, rbx -jmp __tmp_label_29 -__tmp_label_28: -mov rax, 0 -__tmp_label_29: -mov [rsp + 848], rax -mov rax, [rsp + 848] -mov [rsp + 856], rax -mov rdi, [rsp + 824] -mov rsi, [rsp + 856] -call printf -mov [rsp + 864], rax -mov rsp, rbp -pop rbp -ret -extern exit -global _start -_start: -call main -mov rdi, 0 -call exit diff --git a/tests/output/inp3.c_run_output.txt b/tests/output/inp3.c_run_output.txt index cee05b9..5e2b4e2 100644 --- a/tests/output/inp3.c_run_output.txt +++ b/tests/output/inp3.c_run_output.txt @@ -12,8 +12,7 @@ I: 8 I: 9 a n 99 Result: 42700 -Addr of a: 662392626 -Addr of c: 662392642 +Addr of c - Addr of a: 4294967280 Double of 123: 242074 Fact: 5 Fact: 4 diff --git a/tests/output/inp4.c_output.txt b/tests/output/inp4.c_output.txt deleted file mode 100644 index 8b7a06f..0000000 --- a/tests/output/inp4.c_output.txt +++ /dev/null @@ -1,21 +0,0 @@ -section .data -__main_size: equ 16 -section .text -global main -main: -push rbp -mov rbp, rsp -sub rsp, __main_size -mov rax, 0 -mov rsp, rbp -pop rbp -ret -mov rsp, rbp -pop rbp -ret -extern exit -global _start -_start: -call main -mov rdi, 0 -call exit diff --git a/tests/output/inp4.c_run_output.txt b/tests/output/inp4.c_run_output.txt index 4b1a76f..7431a09 100644 --- a/tests/output/inp4.c_run_output.txt +++ b/tests/output/inp4.c_run_output.txt @@ -2,3 +2,5 @@ ------------- 5 10 19 123 251 987 +123 +234 diff --git a/tests/output/inp_arg_macro.c_asm_output.txt b/tests/output/inp_arg_macro.c_asm_output.txt deleted file mode 100644 index 353113f..0000000 --- a/tests/output/inp_arg_macro.c_asm_output.txt +++ /dev/null @@ -1,76 +0,0 @@ -section .data -__printf_size: equ 16 -__temp_str_1 db `cde`, 0 -__temp_str_2 db `%s: %d\n`, 0 -__main_size: equ 128 -section .text -extern printf -global main -main: -push rbp -mov rbp, rsp -sub rsp, __main_size -;define variable a -mov rax, 10 -mov [rsp+0], rax -;end define variable a -mov rax, rsp -add rax, 0 -mov [rsp+16], rax -mov rax, 2 -mov rbx, [rsp+0] -mul rbx -mov [rsp+24], rax -mov rax, 20 -mov rbx, [rsp+24] -add rax, rbx -mov [rsp+32], rax -mov rax, 3 -mov rbx, 20 -mul rbx -mov [rsp+40], rax -mov rax, [rsp+32] -mov rbx, [rsp+40] -add rax, rbx -mov [rsp+48], rax -;define variable cde -mov rax, [rsp+48] -mov [rsp+8], rax -;end define variable cde -;define variable s -mov rax, __temp_str_1 -mov [rsp+56], rax -;end define variable s -mov rax, __temp_str_2 -mov [rsp+64], rax -mov rax, rsp -add rax, 56 -mov [rsp+72], rax -mov rax, [rsp+56] -mov [rsp+80], rax -mov rax, rsp -add rax, 8 -mov [rsp+88], rax -mov rax, [rsp+8] -mov [rsp+96], rax -mov rdi, [rsp+64] -mov rsi, [rsp+80] -mov rdx, [rsp+96] -mov rax, rsp -add rax, 0 -mov [rsp+104], rax -call printf -mov [rsp+112], rax -mov rsp, rbp -pop rbp -ret -extern exit -global _start -_start: -; Pass argc and argv -mov rdi, [rsp] -mov rsi, rsp -add rsi, 8 -call main -mov rdi, 0 -call exit diff --git a/tests/output/inp_bin_op.c_run_output.txt b/tests/output/inp_bin_op.c_run_output.txt index f2c9d1a..911d40f 100644 --- a/tests/output/inp_bin_op.c_run_output.txt +++ b/tests/output/inp_bin_op.c_run_output.txt @@ -1,2 +1,5 @@ ./out "" ------------- +7 +3 +0 diff --git a/tests/output/inp_break.c_run_output.txt b/tests/output/inp_break.c_run_output.txt index 5ae8da9..d8d591c 100644 --- a/tests/output/inp_break.c_run_output.txt +++ b/tests/output/inp_break.c_run_output.txt @@ -9,3 +9,73 @@ j is 2 j is 3 j is 4 j is 5 +i is 1 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 2 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 3 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 4 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 5 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 6 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 7 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 8 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 9 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 +i is 10 +j is 0 +j is 1 +j is 2 +j is 3 +j is 4 +j is 5 diff --git a/tests/output/inp_extern.c_run_output.txt b/tests/output/inp_extern.c_run_output.txt new file mode 100644 index 0000000..7fa621c --- /dev/null +++ b/tests/output/inp_extern.c_run_output.txt @@ -0,0 +1,3 @@ +./out "" +------------- +This is stdout! diff --git a/tests/output/inp_preprocess.c_run_output.txt b/tests/output/inp_preprocess.c_run_output.txt index 0cc1ebf..888a963 100644 --- a/tests/output/inp_preprocess.c_run_output.txt +++ b/tests/output/inp_preprocess.c_run_output.txt @@ -1,4 +1,7 @@ ./out "" ------------- -function(): 69 -function2(): 99 +30CC is compiling this! +ABC defined! +AB defined! +A defined! +D not defined! diff --git a/tests/output/inp_vararg.c_lex_output.txt b/tests/output/inp_vararg.c_lex_output.txt deleted file mode 100644 index 8f4b549..0000000 --- a/tests/output/inp_vararg.c_lex_output.txt +++ /dev/null @@ -1,170 +0,0 @@ -TKN_VOID -TKN_STAR -TKN_ID(malloc) -TKN_L_PAREN -TKN_INT -TKN_R_PAREN -TKN_SEMICOLON -TKN_VOID -TKN_ID(printf) -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_COMMA -TKN_DOTS -TKN_R_PAREN -TKN_SEMICOLON -TKN_VOID -TKN_ID(sprintf) -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_COMMA -TKN_CHAR -TKN_STAR -TKN_COMMA -TKN_DOTS -TKN_R_PAREN -TKN_SEMICOLON -TKN_DIRECTIVE: - TKN_ID(define) - TKN_ID(PUSHARGS) - TKN_L_PAREN - TKN_R_PAREN - TKN_ASM - TKN_L_PAREN - TKN_LIT_STR(push rdi) - TKN_LIT_STR(push rsi) - TKN_LIT_STR(push rdx) - TKN_LIT_STR(push rcx) - TKN_LIT_STR(push r8) - TKN_LIT_STR(push r9) - TKN_R_PAREN - TKN_EOF -TKN_DIRECTIVE: - TKN_ID(define) - TKN_ID(SLARGS) - TKN_L_PAREN - TKN_R_PAREN - TKN_ASM - TKN_L_PAREN - TKN_LIT_STR(mov rdi, rsi) - TKN_LIT_STR(mov rsi, rdx) - TKN_LIT_STR(mov rdx, rcx) - TKN_LIT_STR(mov rcx, r8) - TKN_LIT_STR(mov r8, r9) - TKN_LIT_STR(mov r9, 0) - TKN_R_PAREN - TKN_EOF -TKN_DIRECTIVE: - TKN_ID(define) - TKN_ID(SRARGS) - TKN_L_PAREN - TKN_R_PAREN - TKN_ASM - TKN_L_PAREN - TKN_LIT_STR(mov r9, r8) - TKN_LIT_STR(mov r8, rcx) - TKN_LIT_STR(mov rcx, rdx) - TKN_LIT_STR(mov rdx, rsi) - TKN_LIT_STR(mov rsi, rdi) - TKN_LIT_STR(mov rdi, 0) - TKN_R_PAREN - TKN_EOF -TKN_DIRECTIVE: - TKN_ID(define) - TKN_ID(POPARGS) - TKN_L_PAREN - TKN_R_PAREN - TKN_ASM - TKN_L_PAREN - TKN_LIT_STR(pop r9) - TKN_LIT_STR(pop r8) - TKN_LIT_STR(pop rcx) - TKN_LIT_STR(pop rdx) - TKN_LIT_STR(pop rsi) - TKN_LIT_STR(pop rdi) - TKN_R_PAREN - TKN_EOF -TKN_CHAR -TKN_STAR -TKN_ID(cc_asprintf) -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_ID(inp) -TKN_COMMA -TKN_DOTS -TKN_R_PAREN -TKN_L_BRACE -TKN_ID(SRARGS) -TKN_L_PAREN -TKN_R_PAREN -TKN_SEMICOLON -TKN_ID(PUSHARGS) -TKN_L_PAREN -TKN_R_PAREN -TKN_SEMICOLON -TKN_CHAR -TKN_STAR -TKN_ID(ret) -TKN_ASSIGN -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_R_PAREN -TKN_ID(malloc) -TKN_L_PAREN -TKN_LIT_INT(128) -TKN_R_PAREN -TKN_SEMICOLON -TKN_ID(POPARGS) -TKN_L_PAREN -TKN_R_PAREN -TKN_SEMICOLON -TKN_ID(sprintf) -TKN_L_PAREN -TKN_ID(ret) -TKN_COMMA -TKN_ID(inp) -TKN_R_PAREN -TKN_SEMICOLON -TKN_RETURN -TKN_ID(ret) -TKN_SEMICOLON -TKN_R_BRACE -TKN_INT -TKN_ID(main) -TKN_L_PAREN -TKN_R_PAREN -TKN_L_BRACE -TKN_CHAR -TKN_STAR -TKN_ID(ret) -TKN_ASSIGN -TKN_ID(cc_asprintf) -TKN_L_PAREN -TKN_LIT_STR(salam %s %u%c) -TKN_COMMA -TKN_LIT_STR(donya) -TKN_COMMA -TKN_LIT_INT(123) -TKN_COMMA -TKN_LIT_CHAR(!) -TKN_R_PAREN -TKN_SEMICOLON -TKN_ID(printf) -TKN_L_PAREN -TKN_LIT_STR(%s %s -) -TKN_COMMA -TKN_LIT_STR(haha) -TKN_COMMA -TKN_ID(ret) -TKN_R_PAREN -TKN_SEMICOLON -TKN_RETURN -TKN_LIT_INT(0) -TKN_SEMICOLON -TKN_R_BRACE -TKN_EOF diff --git a/tests/output/inp_vararg.c_prep_output.txt b/tests/output/inp_vararg.c_prep_output.txt deleted file mode 100644 index c455d04..0000000 --- a/tests/output/inp_vararg.c_prep_output.txt +++ /dev/null @@ -1,128 +0,0 @@ -TKN_VOID -TKN_STAR -TKN_ID(malloc) -TKN_L_PAREN -TKN_INT -TKN_R_PAREN -TKN_SEMICOLON -TKN_VOID -TKN_ID(printf) -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_COMMA -TKN_DOTS -TKN_R_PAREN -TKN_SEMICOLON -TKN_VOID -TKN_ID(sprintf) -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_COMMA -TKN_CHAR -TKN_STAR -TKN_COMMA -TKN_DOTS -TKN_R_PAREN -TKN_SEMICOLON -TKN_CHAR -TKN_STAR -TKN_ID(cc_asprintf) -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_ID(inp) -TKN_COMMA -TKN_DOTS -TKN_R_PAREN -TKN_L_BRACE -TKN_ASM -TKN_L_PAREN -TKN_LIT_STR(mov r9, r8) -TKN_LIT_STR(mov r8, rcx) -TKN_LIT_STR(mov rcx, rdx) -TKN_LIT_STR(mov rdx, rsi) -TKN_LIT_STR(mov rsi, rdi) -TKN_LIT_STR(mov rdi, 0) -TKN_R_PAREN -TKN_SEMICOLON -TKN_ASM -TKN_L_PAREN -TKN_LIT_STR(push rdi) -TKN_LIT_STR(push rsi) -TKN_LIT_STR(push rdx) -TKN_LIT_STR(push rcx) -TKN_LIT_STR(push r8) -TKN_LIT_STR(push r9) -TKN_R_PAREN -TKN_SEMICOLON -TKN_CHAR -TKN_STAR -TKN_ID(ret) -TKN_ASSIGN -TKN_L_PAREN -TKN_CHAR -TKN_STAR -TKN_R_PAREN -TKN_ID(malloc) -TKN_L_PAREN -TKN_LIT_INT(128) -TKN_R_PAREN -TKN_SEMICOLON -TKN_ASM -TKN_L_PAREN -TKN_LIT_STR(pop r9) -TKN_LIT_STR(pop r8) -TKN_LIT_STR(pop rcx) -TKN_LIT_STR(pop rdx) -TKN_LIT_STR(pop rsi) -TKN_LIT_STR(pop rdi) -TKN_R_PAREN -TKN_SEMICOLON -TKN_ID(sprintf) -TKN_L_PAREN -TKN_ID(ret) -TKN_COMMA -TKN_ID(inp) -TKN_R_PAREN -TKN_SEMICOLON -TKN_RETURN -TKN_ID(ret) -TKN_SEMICOLON -TKN_R_BRACE -TKN_INT -TKN_ID(main) -TKN_L_PAREN -TKN_R_PAREN -TKN_L_BRACE -TKN_CHAR -TKN_STAR -TKN_ID(ret) -TKN_ASSIGN -TKN_ID(cc_asprintf) -TKN_L_PAREN -TKN_LIT_STR(salam %s %u%c) -TKN_COMMA -TKN_LIT_STR(donya) -TKN_COMMA -TKN_LIT_INT(123) -TKN_COMMA -TKN_LIT_CHAR(!) -TKN_R_PAREN -TKN_SEMICOLON -TKN_ID(printf) -TKN_L_PAREN -TKN_LIT_STR(%s %s -) -TKN_COMMA -TKN_LIT_STR(haha) -TKN_COMMA -TKN_ID(ret) -TKN_R_PAREN -TKN_SEMICOLON -TKN_RETURN -TKN_LIT_INT(0) -TKN_SEMICOLON -TKN_R_BRACE -TKN_EOF diff --git a/tests/output/inp_vararg.c_tree_output.txt b/tests/output/inp_vararg.c_tree_output.txt deleted file mode 100644 index 6ad9c35..0000000 --- a/tests/output/inp_vararg.c_tree_output.txt +++ /dev/null @@ -1,110 +0,0 @@ -Program( - FunctionDecl( - Name: - malloc - Returns: - Type(Name: (null)): - Pointer of: - TKN_VOID - Params: - Type(Name: (null)): - TKN_INT - ) - FunctionDecl( - Name: - printf - Returns: - Type(Name: (null)): - TKN_VOID - Params: - Type(Name: (null)): - Pointer of: - TKN_CHAR - ) - FunctionDecl( - Name: - sprintf - Returns: - Type(Name: (null)): - TKN_VOID - Params: - Type(Name: (null)): - Pointer of: - TKN_CHAR - Type(Name: (null)): - Pointer of: - TKN_CHAR - ) - Function( - Name: - cc_asprintf - Returns: - Type(Name: (null)): - Pointer of: - TKN_CHAR - Params: - Type(Name: inp): - Pointer of: - TKN_CHAR - Statements: - Asm: - "mov r9, r8" "mov r8, rcx" "mov rcx, rdx" "mov rdx, rsi" "mov rsi, rdi" "mov rdi, 0" Asm: - "push rdi" "push rsi" "push rdx" "push rcx" "push r8" "push r9" VarDecl(ret): - Type(Name: ret): - Pointer of: - TKN_CHAR - Value: - Cast: - Val: - FunctionCall: - Function: - Variable(malloc) - Args: - Literal(Type: 34, Value: 128) - Type: - Type(Name: (null)): - Pointer of: - TKN_CHAR - Asm: - "pop r9" "pop r8" "pop rcx" "pop rdx" "pop rsi" "pop rdi" FunctionCall: - Function: - Variable(sprintf) - Args: - Variable(ret) - Variable(inp) - Return: - Variable(ret) - ) - Function( - Name: - main - Returns: - Type(Name: (null)): - TKN_INT - Params: - Statements: - VarDecl(ret): - Type(Name: ret): - Pointer of: - TKN_CHAR - Value: - FunctionCall: - Function: - Variable(cc_asprintf) - Args: - Literal(Type: 33, Value: salam %s %u%c) - Literal(Type: 33, Value: donya) - Literal(Type: 34, Value: 123) - Literal(Type: 35) - FunctionCall: - Function: - Variable(printf) - Args: - Literal(Type: 33, Value: %s %s -) - Literal(Type: 33, Value: haha) - Variable(ret) - Return: - Literal(Type: 34, Value: 0) - ) -) diff --git a/tests/output/switch.c_asm_output.txt b/tests/output/switch.c_asm_output.txt deleted file mode 100644 index fae9449..0000000 --- a/tests/output/switch.c_asm_output.txt +++ /dev/null @@ -1,178 +0,0 @@ -section .data -__printf_size: equ 16 -__temp_str_1 db `1`, 0 -__temp_str_2 db `Excellent!\n`, 0 -__temp_str_3 db `Well done\n`, 0 -__temp_str_4 db `You passed\n`, 0 -__temp_str_5 db `Better try again\n`, 0 -__temp_str_6 db `Invalid grade\n`, 0 -__temp_str_7 db `default case\n`, 0 -__temp_str_8 db `is two\n`, 0 -__temp_str_9 db `%s\n`, 0 -__main_size: equ 176 -section .text -extern printf -global main -main: -push rbp -mov rbp, rsp -sub rsp, __main_size -;define variable grade -mov rax, 66 -mov [rsp+0], rax -;end define variable grade -;start switch -mov rax, rsp -add rax, 0 -mov [rsp+9], rax -mov rax, [rsp+0] -cmp rax, 65 -je case___tmp_label_0_1 -cmp rax, 66 -je case___tmp_label_0_3 -cmp rax, 67 -je case___tmp_label_0_3 -cmp rax, 68 -je case___tmp_label_0_5 -cmp rax, 70 -je case___tmp_label_0_7 -jmp case___tmp_label_0_9 -; stmt loc 0 -mov rax, __temp_str_1 -mov [rsp+10], rax -mov rdi, [rsp+10] -mov rax, rsp -add rax, 0 -mov [rsp+18], rax -call printf -mov [rsp+26], rax -; stmt loc 1 -case___tmp_label_0_1: -mov rax, rsp -add rax, 1 -mov [rsp+26], rax -mov rax, [rsp+1] -mov rbx, __temp_str_2 -mov rax, __temp_str_2 -mov rbx, [rsp+26] -mov [rbx], rax -mov [rsp+34], rax -; stmt loc 2 -jmp __tmp_label_0 -; stmt loc 3 -case___tmp_label_0_3: -case___tmp_label_0_3: -mov rax, rsp -add rax, 1 -mov [rsp+42], rax -mov rax, [rsp+1] -mov rbx, __temp_str_3 -mov rax, __temp_str_3 -mov rbx, [rsp+42] -mov [rbx], rax -mov [rsp+50], rax -; stmt loc 4 -jmp __tmp_label_0 -; stmt loc 5 -case___tmp_label_0_5: -mov rax, rsp -add rax, 1 -mov [rsp+58], rax -mov rax, [rsp+1] -mov rbx, __temp_str_4 -mov rax, __temp_str_4 -mov rbx, [rsp+58] -mov [rbx], rax -mov [rsp+66], rax -; stmt loc 6 -jmp __tmp_label_0 -; stmt loc 7 -case___tmp_label_0_7: -mov rax, rsp -add rax, 1 -mov [rsp+74], rax -mov rax, [rsp+1] -mov rbx, __temp_str_5 -mov rax, __temp_str_5 -mov rbx, [rsp+74] -mov [rbx], rax -mov [rsp+82], rax -; stmt loc 8 -jmp __tmp_label_0 -; stmt loc 9 -case___tmp_label_0_9: -mov rax, rsp -add rax, 1 -mov [rsp+90], rax -mov rax, [rsp+1] -mov rbx, __temp_str_6 -mov rax, __temp_str_6 -mov rbx, [rsp+90] -mov [rbx], rax -mov [rsp+98], rax -; end switch -__tmp_label_0: -;start switch -mov rax, 1 -jmp case___tmp_label_1_0 -; stmt loc 0 -case___tmp_label_1_0: -mov rax, __temp_str_7 -mov [rsp+106], rax -mov rdi, [rsp+106] -mov rax, rsp -add rax, 0 -mov [rsp+114], rax -call printf -mov [rsp+122], rax -; end switch -__tmp_label_1: -;start switch -mov rax, 2 -cmp rax, 2 -je case___tmp_label_2_0 -jmp case___tmp_label_2_0 -; stmt loc 0 -case___tmp_label_2_0: -case___tmp_label_2_0: -mov rax, __temp_str_8 -mov [rsp+122], rax -mov rdi, [rsp+122] -mov rax, rsp -add rax, 0 -mov [rsp+130], rax -call printf -mov [rsp+138], rax -; end switch -__tmp_label_2: -mov rax, __temp_str_9 -mov [rsp+138], rax -mov rax, rsp -add rax, 1 -mov [rsp+146], rax -mov rax, [rsp+1] -mov [rsp+154], rax -mov rdi, [rsp+138] -mov rsi, [rsp+154] -mov rax, rsp -add rax, 0 -mov [rsp+162], rax -call printf -mov [rsp+170], rax -mov rax, 0 -mov rsp, rbp -pop rbp -ret -mov rsp, rbp -pop rbp -ret -extern exit -global _start -_start: -; Pass argc and argv -mov rdi, [rsp] -mov rsi, rsp -add rsi, 8 -call main -mov rdi, rax -call exit