opcodes: constify & scope microblaze opcodes

Message ID 20210627055900.15624-1-vapier@gentoo.org
State New
Headers show
Series
  • opcodes: constify & scope microblaze opcodes
Related show

Commit Message

Luis Machado via Binutils June 27, 2021, 5:59 a.m.
This is exporting the variable "opcodes" as a large writable blob.
This is not a namespace friendly name, so add a "microblaze" prefix,
and then sprinkle const over its definition & use.
---
 gas/config/tc-microblaze.c |  4 ++--
 opcodes/microblaze-dis.c   | 18 +++++++++---------
 opcodes/microblaze-opc.h   |  4 ++--
 3 files changed, 13 insertions(+), 13 deletions(-)

-- 
2.31.1

Comments

Luis Machado via Binutils July 1, 2021, 10:08 a.m. | #1
Hi Mike,

> This is exporting the variable "opcodes" as a large writable blob.

> This is not a namespace friendly name, so add a "microblaze" prefix,

> and then sprinkle const over its definition & use.


Approved - please apply - with ChangeLogs...

Cheers
   Nick

Patch

diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
index 9893bc47cfd7..881172d52748 100644
--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -411,12 +411,12 @@  const pseudo_typeS md_pseudo_table[] =
 void
 md_begin (void)
 {
-  struct op_code_struct * opcode;
+  const struct op_code_struct * opcode;
 
   opcode_hash_control = str_htab_create ();
 
   /* Insert unique names into hash table.  */
-  for (opcode = opcodes; opcode->name; opcode ++)
+  for (opcode = microblaze_opcodes; opcode->name; opcode ++)
     str_hash_insert (opcode_hash_control, opcode->name, opcode, 0);
 }
 
diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
index aa75c4cc1fd1..1696f559a0b7 100644
--- a/opcodes/microblaze-dis.c
+++ b/opcodes/microblaze-dis.c
@@ -111,7 +111,7 @@  get_field_imm15 (struct string_buf *buf, long instr)
 
 static char *
 get_field_special (struct string_buf *buf, long instr,
-		   struct op_code_struct *op)
+		   const struct op_code_struct *op)
 {
   char *p = strbuf (buf);
   char *spr;
@@ -184,11 +184,11 @@  get_field_special (struct string_buf *buf, long instr,
 static unsigned long
 read_insn_microblaze (bfd_vma memaddr,
 		      struct disassemble_info *info,
-		      struct op_code_struct **opr)
+		      const struct op_code_struct **opr)
 {
   unsigned char       ibytes[4];
   int                 status;
-  struct op_code_struct * op;
+  const struct op_code_struct *op;
   unsigned long inst;
 
   status = info->read_memory_func (memaddr, ibytes, 4, info);
@@ -209,7 +209,7 @@  read_insn_microblaze (bfd_vma memaddr,
     abort ();
 
   /* Just a linear search of the table.  */
-  for (op = opcodes; op->name != 0; op ++)
+  for (op = microblaze_opcodes; op->name != 0; op ++)
     if (op->bit_sequence == (inst & op->opcode_mask))
       break;
 
@@ -224,7 +224,7 @@  print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
   fprintf_ftype print_func = info->fprintf_func;
   void *stream = info->stream;
   unsigned long inst, prev_inst;
-  struct op_code_struct *op, *pop;
+  const struct op_code_struct *op, *pop;
   int immval = 0;
   bool immfound = false;
   static bfd_vma prev_insn_addr = -1;	/* Init the prev insn addr.  */
@@ -452,11 +452,11 @@  get_insn_microblaze (long inst,
   		     enum microblaze_instr_type *insn_type,
   		     short *delay_slots)
 {
-  struct op_code_struct * op;
+  const struct op_code_struct *op;
   *isunsignedimm = false;
 
   /* Just a linear search of the table.  */
-  for (op = opcodes; op->name != 0; op ++)
+  for (op = microblaze_opcodes; op->name != 0; op ++)
     if (op->bit_sequence == (inst & op->opcode_mask))
       break;
 
@@ -494,12 +494,12 @@  microblaze_get_target_address (long inst, bool immfound, int immval,
 			       bool *targetvalid,
 			       bool *unconditionalbranch)
 {
-  struct op_code_struct * op;
+  const struct op_code_struct *op;
   long targetaddr = 0;
 
   *unconditionalbranch = false;
   /* Just a linear search of the table.  */
-  for (op = opcodes; op->name != 0; op ++)
+  for (op = microblaze_opcodes; op->name != 0; op ++)
     if (op->bit_sequence == (inst & op->opcode_mask))
       break;
 
diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
index 3182d9489568..080d238bd2b7 100644
--- a/opcodes/microblaze-opc.h
+++ b/opcodes/microblaze-opc.h
@@ -103,7 +103,7 @@ 
 
 #define MAX_OPCODES 289
 
-struct op_code_struct
+const struct op_code_struct
 {
   const char * name;
   short inst_type;            /* Registers and immediate values involved.  */
@@ -117,7 +117,7 @@  struct op_code_struct
   enum microblaze_instr instr;
   enum microblaze_instr_type instr_type;
   /* More info about output format here.  */
-} opcodes[MAX_OPCODES] =
+} microblaze_opcodes[MAX_OPCODES] =
 {
   {"add",   INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x00000000, OPCODE_MASK_H4, add, arithmetic_inst },
   {"rsub",  INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H4, rsub, arithmetic_inst },