All of lore.kernel.org
 help / color / mirror / Atom feed
From: Milica Lazarevic <milica.lazarevic@syrmia.com>
To: thuth@redhat.com
Cc: qemu-devel@nongnu.org, cfontana@suse.de, berrange@redhat.com,
	pbonzini@redhat.com, vince.delvecchio@mediatek.com,
	richard.henderson@linaro.org, peter.maydell@linaro.org,
	djordje.todorovic@syrmia.com, mips32r2@gmail.com,
	dragan.mladjenovic@syrmia.com,
	Milica Lazarevic <milica.lazarevic@syrmia.com>
Subject: [PATCH v3 09/24] disas/nanomips: Remove NMD class
Date: Mon, 12 Sep 2022 14:26:20 +0200	[thread overview]
Message-ID: <20220912122635.74032-10-milica.lazarevic@syrmia.com> (raw)
In-Reply-To: <20220912122635.74032-1-milica.lazarevic@syrmia.com>

NMD class has been deleted. The following methods are now declared as
static functions:
- public NMD::Disassemble method
- private NMD::Disassemble method
- private NMD::extract_op_code_value helper method

Also, the implementation of the print_insn_nanomips function and
nanomips_dis function is moved to the end of the nanomips.cpp file,
right after the implementation of the Disassemble function.

Signed-off-by: Milica Lazarevic <milica.lazarevic@syrmia.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas/nanomips.cpp | 202 ++++++++++++++++++++++-----------------------
 disas/nanomips.h   |  15 ----
 2 files changed, 100 insertions(+), 117 deletions(-)

diff --git a/disas/nanomips.cpp b/disas/nanomips.cpp
index fa2cf2204a..3b5e6d520f 100644
--- a/disas/nanomips.cpp
+++ b/disas/nanomips.cpp
@@ -41,105 +41,6 @@
 #define IMGASSERTONCE(test)
 
 
-static int nanomips_dis(char *buf,
-                 Dis_info *info,
-                 unsigned short one,
-                 unsigned short two,
-                 unsigned short three)
-{
-    std::string disasm;
-    uint16 bits[3] = {one, two, three};
-
-    TABLE_ENTRY_TYPE type;
-    NMD d;
-    int size = d.Disassemble(bits, disasm, type, info);
-
-    strcpy(buf, disasm.c_str());
-    return size;
-}
-
-int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info)
-{
-    int status;
-    bfd_byte buffer[2];
-    uint16_t insn1 = 0, insn2 = 0, insn3 = 0;
-    char buf[200];
-
-    info->bytes_per_chunk = 2;
-    info->display_endian = info->endian;
-    info->insn_info_valid = 1;
-    info->branch_delay_insns = 0;
-    info->data_size = 0;
-    info->insn_type = dis_nonbranch;
-    info->target = 0;
-    info->target2 = 0;
-
-    Dis_info disassm_info;
-    disassm_info.m_pc = memaddr;
-
-    status = (*info->read_memory_func)(memaddr, buffer, 2, info);
-    if (status != 0) {
-        (*info->memory_error_func)(status, memaddr, info);
-        return -1;
-    }
-
-    if (info->endian == BFD_ENDIAN_BIG) {
-        insn1 = bfd_getb16(buffer);
-    } else {
-        insn1 = bfd_getl16(buffer);
-    }
-    (*info->fprintf_func)(info->stream, "%04x ", insn1);
-
-    /* Handle 32-bit opcodes.  */
-    if ((insn1 & 0x1000) == 0) {
-        status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info);
-        if (status != 0) {
-            (*info->memory_error_func)(status, memaddr + 2, info);
-            return -1;
-        }
-
-        if (info->endian == BFD_ENDIAN_BIG) {
-            insn2 = bfd_getb16(buffer);
-        } else {
-            insn2 = bfd_getl16(buffer);
-        }
-        (*info->fprintf_func)(info->stream, "%04x ", insn2);
-    } else {
-        (*info->fprintf_func)(info->stream, "     ");
-    }
-    /* Handle 48-bit opcodes.  */
-    if ((insn1 >> 10) == 0x18) {
-        status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info);
-        if (status != 0) {
-            (*info->memory_error_func)(status, memaddr + 4, info);
-            return -1;
-        }
-
-        if (info->endian == BFD_ENDIAN_BIG) {
-            insn3 = bfd_getb16(buffer);
-        } else {
-            insn3 = bfd_getl16(buffer);
-        }
-        (*info->fprintf_func)(info->stream, "%04x ", insn3);
-    } else {
-        (*info->fprintf_func)(info->stream, "     ");
-    }
-
-    int length = nanomips_dis(buf, &disassm_info, insn1, insn2, insn3);
-
-    /* FIXME: Should probably use a hash table on the major opcode here.  */
-
-    (*info->fprintf_func) (info->stream, "%s", buf);
-    if (length > 0) {
-        return length / 8;
-    }
-
-    info->insn_type = dis_noninsn;
-
-    return insn3 ? 6 : insn2 ? 4 : 2;
-}
-
-
 std::string img_format(const char *format, ...)
 {
     char buffer[256];
@@ -739,7 +640,7 @@ static std::string ADDRESS(uint64 value, int instruction_size, Dis_info *info)
 }
 
 
-uint64 NMD::extract_op_code_value(const uint16 * data, int size)
+static uint64 extract_op_code_value(const uint16 *data, int size)
 {
     switch (size) {
     case 16:
@@ -765,7 +666,7 @@ uint64 NMD::extract_op_code_value(const uint16 * data, int size)
  *      instruction size    - negative is error
  *      disassembly string  - on error will constain error string
  */
-int NMD::Disassemble(const uint16 * data, std::string & dis,
+static int Disassemble(const uint16 * data, std::string & dis,
                      TABLE_ENTRY_TYPE & type, const Pool *table,
                      int table_size, Dis_info *info)
 {
@@ -22348,8 +22249,105 @@ static const Pool MAJOR[2] = {
        0x0                 },        /* P16 */
 };
 
-int NMD::Disassemble(const uint16 * data, std::string & dis,
+static int Disassemble(const uint16 *data, std::string & dis,
                      TABLE_ENTRY_TYPE & type, Dis_info *info)
 {
     return Disassemble(data, dis, type, MAJOR, 2, info);
 }
+
+static int nanomips_dis(char *buf,
+                 Dis_info *info,
+                 unsigned short one,
+                 unsigned short two,
+                 unsigned short three)
+{
+    std::string disasm;
+    uint16 bits[3] = {one, two, three};
+
+    TABLE_ENTRY_TYPE type;
+    int size = Disassemble(bits, disasm, type, info);
+
+    strcpy(buf, disasm.c_str());
+    return size;
+}
+
+int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info)
+{
+    int status;
+    bfd_byte buffer[2];
+    uint16_t insn1 = 0, insn2 = 0, insn3 = 0;
+    char buf[200];
+
+    info->bytes_per_chunk = 2;
+    info->display_endian = info->endian;
+    info->insn_info_valid = 1;
+    info->branch_delay_insns = 0;
+    info->data_size = 0;
+    info->insn_type = dis_nonbranch;
+    info->target = 0;
+    info->target2 = 0;
+
+    Dis_info disassm_info;
+    disassm_info.m_pc = memaddr;
+
+    status = (*info->read_memory_func)(memaddr, buffer, 2, info);
+    if (status != 0) {
+        (*info->memory_error_func)(status, memaddr, info);
+        return -1;
+    }
+
+    if (info->endian == BFD_ENDIAN_BIG) {
+        insn1 = bfd_getb16(buffer);
+    } else {
+        insn1 = bfd_getl16(buffer);
+    }
+    (*info->fprintf_func)(info->stream, "%04x ", insn1);
+
+    /* Handle 32-bit opcodes.  */
+    if ((insn1 & 0x1000) == 0) {
+        status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info);
+        if (status != 0) {
+            (*info->memory_error_func)(status, memaddr + 2, info);
+            return -1;
+        }
+
+        if (info->endian == BFD_ENDIAN_BIG) {
+            insn2 = bfd_getb16(buffer);
+        } else {
+            insn2 = bfd_getl16(buffer);
+        }
+        (*info->fprintf_func)(info->stream, "%04x ", insn2);
+    } else {
+        (*info->fprintf_func)(info->stream, "     ");
+    }
+    /* Handle 48-bit opcodes.  */
+    if ((insn1 >> 10) == 0x18) {
+        status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info);
+        if (status != 0) {
+            (*info->memory_error_func)(status, memaddr + 4, info);
+            return -1;
+        }
+
+        if (info->endian == BFD_ENDIAN_BIG) {
+            insn3 = bfd_getb16(buffer);
+        } else {
+            insn3 = bfd_getl16(buffer);
+        }
+        (*info->fprintf_func)(info->stream, "%04x ", insn3);
+    } else {
+        (*info->fprintf_func)(info->stream, "     ");
+    }
+
+    int length = nanomips_dis(buf, &disassm_info, insn1, insn2, insn3);
+
+    /* FIXME: Should probably use a hash table on the major opcode here.  */
+
+    (*info->fprintf_func) (info->stream, "%s", buf);
+    if (length > 0) {
+        return length / 8;
+    }
+
+    info->insn_type = dis_noninsn;
+
+    return insn3 ? 6 : insn2 ? 4 : 2;
+}
diff --git a/disas/nanomips.h b/disas/nanomips.h
index 82deff1094..75abe03bba 100644
--- a/disas/nanomips.h
+++ b/disas/nanomips.h
@@ -80,19 +80,4 @@ typedef struct Pool {
     uint64               attributes;
 } Pool;
 
-class NMD
-{
-public:
-
-    int Disassemble(const uint16 *data, std::string & dis,
-                    TABLE_ENTRY_TYPE & type, Dis_info *info);
-
-private:
-
-    uint64 extract_op_code_value(const uint16 *data, int size);
-    int Disassemble(const uint16 *data, std::string & dis,
-                    TABLE_ENTRY_TYPE & type, const Pool *table, int table_size,
-                    Dis_info *info);
-};
-
 #endif
-- 
2.25.1



  parent reply	other threads:[~2022-09-12 12:59 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 12:26 [PATCH v3 0/24] Convert nanoMIPS disassembler from C++ to C Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 01/24] disas/nanomips: Remove namespace img Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 02/24] disas/nanomips: Extract enums out of the NMD class Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 03/24] disas/nanomips: Delete NMD class field Milica Lazarevic
2022-09-13  7:50   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 04/24] disas/nanomips: Delete NMD class second field Milica Lazarevic
2022-09-13  7:51   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 05/24] disas/nanomips: Remove helper methods from class Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 06/24] disas/nanomips: Remove __cond " Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 07/24] disas/nanomips: Remove disasm " Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 08/24] disas/nanomips: Remove Pool tables from the class Milica Lazarevic
2022-09-12 12:26 ` Milica Lazarevic [this message]
2022-09-12 12:26 ` [PATCH v3 10/24] disas/nanomips: Move typedefs etc to nanomips.cpp Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 11/24] disas/nanomips: Delete nanomips.h Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 12/24] disas/nanomips: Remove #inlcude <sstream> Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 13/24] disas/nanomips: Delete copy functions Milica Lazarevic
2022-09-13  7:53   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 14/24] disas/nanomips: Delete wrapper functions Milica Lazarevic
2022-09-13  7:54   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 15/24] disas/nanomips: Replace std::string type Milica Lazarevic
2022-09-13  8:00   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 16/24] disas/nanomips: Remove IMMEDIATE functions Milica Lazarevic
2022-09-13  8:03   ` Richard Henderson
2022-11-01  8:28   ` Stefan Weil via
2022-11-01  9:27     ` Philippe Mathieu-Daudé
2022-11-01 11:28       ` Stefan Weil via
2022-11-01 11:32         ` Philippe Mathieu-Daudé
2022-09-12 12:26 ` [PATCH v3 17/24] disas/nanomips: Remove CPR function Milica Lazarevic
2022-09-13  8:05   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 18/24] disas/nanomips: Prevent memory leaking Milica Lazarevic
2022-09-13  8:06   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 19/24] disas/nanomips: Remove function overloading Milica Lazarevic
2022-09-13  8:07   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 20/24] disas/nanomips: Expand Dis_info struct Milica Lazarevic
2022-09-13  8:09   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 21/24] disas/nanomips: Replace exception handling Milica Lazarevic
2022-09-13  8:12   ` Richard Henderson
2022-09-12 12:26 ` [PATCH v3 22/24] disas/nanomips: Replace Cpp enums for C enums Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 23/24] disas/nanomips: Remove argument passing by ref Milica Lazarevic
2022-09-12 12:26 ` [PATCH v3 24/24] disas/nanomips: Rename nanomips.cpp to nanomips.c Milica Lazarevic
2022-09-13  8:12   ` Richard Henderson
2022-10-27  7:25 ` [PATCH v3 0/24] Convert nanoMIPS disassembler from C++ to C Thomas Huth
2022-10-27 10:55   ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220912122635.74032-10-milica.lazarevic@syrmia.com \
    --to=milica.lazarevic@syrmia.com \
    --cc=berrange@redhat.com \
    --cc=cfontana@suse.de \
    --cc=djordje.todorovic@syrmia.com \
    --cc=dragan.mladjenovic@syrmia.com \
    --cc=mips32r2@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=vince.delvecchio@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.