From b1c8e24e01d730c61a55cbd7163de45eadd274d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 20 Jun 2022 10:42:35 +0200
Subject: [PATCH] Bytecode: store instruction opcode (Tags enum) directly
 inside instruction classes

This makes the code simpler. Incidentally, since Tags are no longer stored as
uint8_t, this makes the .cod files larger, but there is no clear performance impact.
---
 src/Bytecode.hh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Bytecode.hh b/src/Bytecode.hh
index 0df4a2c9..c04e9102 100644
--- a/src/Bytecode.hh
+++ b/src/Bytecode.hh
@@ -107,9 +107,9 @@ struct Block_contain_type
 class BytecodeInstruction
 {
 protected:
-  uint8_t op_code;
+  Tags op_code;
 public:
-  explicit BytecodeInstruction(Tags op_code_arg) : op_code{static_cast<uint8_t>(op_code_arg)}
+  explicit BytecodeInstruction(Tags op_code_arg) : op_code{op_code_arg}
   {
   };
   void
@@ -868,7 +868,7 @@ public:
   uint8_t *
   load(uint8_t *code)
   {
-    op_code = static_cast<uint8_t>(Tags::FCALL); code += sizeof(op_code);
+    op_code = Tags::FCALL; code += sizeof(op_code);
     memcpy(&nb_output_arguments, code, sizeof(nb_output_arguments)); code += sizeof(nb_output_arguments);
     memcpy(&nb_input_arguments, code, sizeof(nb_input_arguments)); code += sizeof(nb_input_arguments);
     memcpy(&indx, code, sizeof(indx)); code += sizeof(indx);
@@ -1155,7 +1155,7 @@ public:
   uint8_t *
   load(uint8_t *code)
   {
-    op_code = static_cast<uint8_t>(Tags::FBEGINBLOCK); code += sizeof(op_code);
+    op_code = Tags::FBEGINBLOCK; code += sizeof(op_code);
     memcpy(&size, code, sizeof(size)); code += sizeof(size);
     memcpy(&type, code, sizeof(type)); code += sizeof(type);
     for (int i = 0; i < size; i++)
@@ -1253,7 +1253,7 @@ public:
     int instruction = 0;
     while (!done)
       {
-        switch (static_cast<Tags>(*code))
+        switch (*reinterpret_cast<Tags *>(code))
           {
           case Tags::FLDZ:
 # ifdef DEBUGL
-- 
GitLab