From f2204df7d77c1013b0202d2ea7c12ec70f839fc9 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sun, 5 May 2024 21:35:37 +0200 Subject: [PATCH] auto remove unreachable instructions when executing ram machine --- src/ram.y | 2 +- src/test.asm | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ram.y b/src/ram.y index 130471c..f356dc5 100644 --- a/src/ram.y +++ b/src/ram.y @@ -128,7 +128,7 @@ int main() { fprintf(stderr, "Error creating file machine.py\n"); return 1; } else { - fprintf(file, "from ram import *\n\n%s\nram = Ram(instructions, input_registers)\nram.execute()\nprint(\"Result:\", ram.output_registers)\n", result); + fprintf(file, "from ram import *\n\n%s\nram = Ram(instructions, input_registers)\nram.remove_unreachable_instr()\nram.execute()\nprint(\"Result:\", ram.output_registers)\n", result); fclose(file); } return 0; diff --git a/src/test.asm b/src/test.asm index 8e85802..a403cfa 100644 --- a/src/test.asm +++ b/src/test.asm @@ -2,5 +2,10 @@ ADD(i0 ,1 ,r0) SUB(i1,3,r1) +JUMP(2) +DIV(10,2,r1) // unreachable + MULT(r1,r0,o1) ADD(5, i@i2, o2) +JUMP(2) +JUMP(-5) // unreachable