diff mbox series

[03/20] disas/nanomips: Delete NMD class fields

Message ID 20220815072629.12865-4-milica.lazarevic@syrmia.com (mailing list archive)
State New, archived
Headers show
Series Convert nanoMIPS disassembler from C++ to C | expand

Commit Message

Milica Lazarevic Aug. 15, 2022, 7:26 a.m. UTC
Class fields have been replaced with the public static variables.
Therefore, there is no more need for a constructor. The main goal is to
remove NMD class completely.

Signed-off-by: Milica Lazarevic <milica.lazarevic@syrmia.com>
---
 disas/nanomips.cpp | 6 +++++-
 disas/nanomips.h   | 9 ---------
 2 files changed, 5 insertions(+), 10 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 15, 2022, 10:59 a.m. UTC | #1
On 15/8/22 09:26, Milica Lazarevic wrote:
> Class fields have been replaced with the public static variables.
> Therefore, there is no more need for a constructor. The main goal is to
> remove NMD class completely.
> 
> Signed-off-by: Milica Lazarevic <milica.lazarevic@syrmia.com>
> ---
>   disas/nanomips.cpp | 6 +++++-
>   disas/nanomips.h   | 9 ---------
>   2 files changed, 5 insertions(+), 10 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Richard Henderson Aug. 15, 2022, 3:02 p.m. UTC | #2
On 8/15/22 02:26, Milica Lazarevic wrote:
> Class fields have been replaced with the public static variables.
> Therefore, there is no more need for a constructor. The main goal is to
> remove NMD class completely.
> 
> Signed-off-by: Milica Lazarevic <milica.lazarevic@syrmia.com>
> ---
>   disas/nanomips.cpp | 6 +++++-
>   disas/nanomips.h   | 9 ---------
>   2 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/disas/nanomips.cpp b/disas/nanomips.cpp
> index 00e489fd59..2cbaa122ae 100644
> --- a/disas/nanomips.cpp
> +++ b/disas/nanomips.cpp
> @@ -40,6 +40,8 @@
>   
>   #define IMGASSERTONCE(test)
>   
> +static img_address           m_pc;
> +static TABLE_ATTRIBUTE_TYPE   m_requested_instruction_categories;

This is not a viable solution, as it is not thread-safe.  You need to keep a struct and 
add it as an explicit argument where required.


r~
diff mbox series

Patch

diff --git a/disas/nanomips.cpp b/disas/nanomips.cpp
index 00e489fd59..2cbaa122ae 100644
--- a/disas/nanomips.cpp
+++ b/disas/nanomips.cpp
@@ -40,6 +40,8 @@ 
 
 #define IMGASSERTONCE(test)
 
+static img_address           m_pc;
+static TABLE_ATTRIBUTE_TYPE   m_requested_instruction_categories;
 
 int nanomips_dis(char *buf,
                  unsigned address,
@@ -51,7 +53,9 @@  int nanomips_dis(char *buf,
     uint16 bits[3] = {one, two, three};
 
     TABLE_ENTRY_TYPE type;
-    NMD d(address, ALL_ATTRIBUTES);
+    m_pc = address;
+    m_requested_instruction_categories = ALL_ATTRIBUTES;
+    NMD d;
     int size = d.Disassemble(bits, disasm, type);
 
     strcpy(buf, disasm.c_str());
diff --git a/disas/nanomips.h b/disas/nanomips.h
index f65a0957b8..9858740bf3 100644
--- a/disas/nanomips.h
+++ b/disas/nanomips.h
@@ -65,20 +65,11 @@  class NMD
 {
 public:
 
-    NMD(img_address pc, TABLE_ATTRIBUTE_TYPE requested_instruction_categories)
-        : m_pc(pc)
-        , m_requested_instruction_categories(requested_instruction_categories)
-    {
-    }
-
     int Disassemble(const uint16 *data, std::string & dis,
                     TABLE_ENTRY_TYPE & type);
 
 private:
 
-    img_address           m_pc;
-    TABLE_ATTRIBUTE_TYPE   m_requested_instruction_categories;
-
     typedef std::string(NMD:: *disassembly_function)(uint64 instruction);
     typedef bool(NMD:: *conditional_function)(uint64 instruction);