]> git.sesse.net Git - interpreter_trials/commitdiff
stopped using exceptions for exiting
authorRune Holm <rune.holm@arm.com>
Thu, 17 Jun 2021 11:36:08 +0000 (13:36 +0200)
committerRune Holm <rune.holm@arm.com>
Thu, 17 Jun 2021 11:36:08 +0000 (13:36 +0200)
interpreter10.cpp
interpreter7.cpp
interpreter8.cpp
interpreter9.cpp

index f396efe2d84eb40c753bc0f68ea3512d9f7edf9d..9bb5580ea9df27098da05889357124a87b8a42cd 100644 (file)
@@ -14,11 +14,6 @@ namespace interpreter10
     };
 
 
-    struct ReturnException
-    {
-    };
-
-
 
 #define PARAMS CpuState *state, uint8_t *pc, uint32_t cycle_count, void *dispatch_table_void
 #define ARGS state, pc, cycle_count, dispatch_table_void
@@ -29,7 +24,7 @@ namespace interpreter10
     {
         cycle_count += 1;
         state->final_cycle_count = cycle_count;
-        throw ReturnException();
+        return;
     }
 
     void op_add(PARAMS)
@@ -141,19 +136,11 @@ namespace interpreter10
         state->regs[X0] = param;
         uint32_t cycle_count = 0;
         void *dispatch_table_void = (void*)&dispatch_table[0];
-        try
-        {
-            while(true)
-            {
-                uint8_t opcode = *pc++;
-                dispatch_table[opcode](ARGS);
-            }
 
+        uint8_t opcode = *pc++;
+        dispatch_table[opcode](ARGS);
 
-        } catch(ReturnException ex)
-        {
-            return std::make_pair(state->regs[X0], state->final_cycle_count);
-        }
+        return std::make_pair(state->regs[X0], state->final_cycle_count);
 
     }
 
index c68ba02fa23b640a6bb598879f25796f12ac4e6f..1b4c5ee6bae8c331bb0cf524e6b84688127b1485 100644 (file)
@@ -18,11 +18,6 @@ namespace interpreter7
     };
 
 
-    struct ReturnException
-    {
-    };
-
-
 
 #define PARAMS CpuState *state, uint8_t *pc, Flags flags, uint32_t cycle_count
 #define ARGS state, pc, flags, cycle_count
@@ -33,7 +28,7 @@ namespace interpreter7
     {
         cycle_count += 1;
         state->final_cycle_count = cycle_count;
-        throw ReturnException();
+        return;
     }
 
     void op_add(PARAMS)
@@ -139,20 +134,11 @@ namespace interpreter7
         state->regs[X0] = param;
         uint32_t cycle_count = 0;
         Flags flags = {0, 0};
-        try
-        {
-            while(true)
-            {
-                uint8_t opcode = *pc++;
-                dispatch_table[opcode](ARGS);
-            }
 
+        uint8_t opcode = *pc++;
+        dispatch_table[opcode](ARGS);
 
-        } catch(ReturnException ex)
-        {
-            return std::make_pair(state->regs[X0], state->final_cycle_count);
-        }
-
+        return std::make_pair(state->regs[X0], state->final_cycle_count);
     }
 
 
index aae565f979f35f652a9b0347cb1b7b32be518f38..0747c18d49eccea142e2214b3217349afbb6af88 100644 (file)
@@ -18,11 +18,6 @@ namespace interpreter8
     };
 
 
-    struct ReturnException
-    {
-    };
-
-
 
 #define PARAMS CpuState *state, uint8_t *pc, Flags flags, uint32_t cycle_count, void *dispatch_table_void
 #define ARGS state, pc, flags, cycle_count, dispatch_table_void
@@ -33,7 +28,6 @@ namespace interpreter8
     {
         cycle_count += 1;
         state->final_cycle_count = cycle_count;
-        throw ReturnException();
     }
 
     void op_add(PARAMS)
@@ -146,20 +140,12 @@ namespace interpreter8
         uint32_t cycle_count = 0;
         Flags flags = {0, 0};
         void *dispatch_table_void = (void*)&dispatch_table[0];
-        try
-        {
-            while(true)
-            {
-                uint8_t opcode = *pc++;
-                dispatch_table[opcode](ARGS);
-            }
 
 
-        } catch(ReturnException ex)
-        {
-            return std::make_pair(state->regs[X0], state->final_cycle_count);
-        }
+        uint8_t opcode = *pc++;
+        dispatch_table[opcode](ARGS);
 
+        return std::make_pair(state->regs[X0], state->final_cycle_count);
     }
 
 
index 5a80fda1a404aeb42be6d1ec9e83707748a20d69..52feddbac5ef4b943f83f1d834f9c8220c3d198b 100644 (file)
@@ -12,10 +12,6 @@ namespace interpreter9
     };
 
 
-    struct ReturnException
-    {
-    };
-
 
 
 #define PARAMS CpuState *state, uint8_t *pc, bool flags_zero, bool flags_negative, uint32_t cycle_count, void *dispatch_table_void
@@ -27,7 +23,7 @@ namespace interpreter9
     {
         cycle_count += 1;
         state->final_cycle_count = cycle_count;
-        throw ReturnException();
+        return;
     }
 
     void op_add(PARAMS)
@@ -141,19 +137,10 @@ namespace interpreter9
         bool flags_zero = false;
         bool flags_negative = false;
         void *dispatch_table_void = (void*)&dispatch_table[0];
-        try
-        {
-            while(true)
-            {
-                uint8_t opcode = *pc++;
-                dispatch_table[opcode](ARGS);
-            }
-
 
-        } catch(ReturnException ex)
-        {
-            return std::make_pair(state->regs[X0], state->final_cycle_count);
-        }
+        uint8_t opcode = *pc++;
+        dispatch_table[opcode](ARGS);
+        return std::make_pair(state->regs[X0], state->final_cycle_count);
 
     }