Skip to content

Commit 537ca14

Browse files
committed
RISC-V: Move disassembler private data initialization
The original intent of this commit was to move disassembler's private data initialization. Since Nelson did the same in the commit 26e9197 ("RISC-V: Minor improvements for dis-assembler."), this commit only moves the initialization function (to fit much larger reorganization of the disassembler). Nelson's commit also allows storing mapping symbol and/or section-related information to riscv_private_data. In performance perspective, it also has a penalty. However, it can be easily paid back by other optimizations and it makes implementing some optimizations easier. Also, because xcalloc cannot fail (exit(1) occurs if the memory allocation fails), the author temporarily removed the error handling here. opcodes/ChangeLog: * riscv-dis.c (init_riscv_dis_private_data): Moved from riscv_init_disasm_info. (riscv_disassemble_insn): Move private data initialization to init_riscv_dis_private_data. Remove unnecessary error handling. (riscv_init_disasm_info): Move to init_riscv_dis_private_data. (print_insn_riscv): Call init_riscv_dis_private_data.
1 parent 14b8e87 commit 537ca14

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

opcodes/riscv-dis.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,29 @@ init_riscv_dis_state_for_arch_and_options (void)
238238
is_arch_changed = false;
239239
}
240240

241+
/* Initialize private data of the disassemble_info. */
242+
243+
static void
244+
init_riscv_dis_private_data (struct disassemble_info *info)
245+
{
246+
struct riscv_private_data *pd;
247+
248+
pd = info->private_data = xcalloc (1, sizeof (struct riscv_private_data));
249+
pd->gp = 0;
250+
pd->print_addr = 0;
251+
for (int i = 0; i < (int)ARRAY_SIZE (pd->hi_addr); i++)
252+
pd->hi_addr[i] = -1;
253+
pd->to_print_addr = false;
254+
pd->has_gp = false;
255+
256+
for (int i = 0; i < info->symtab_size; i++)
257+
if (strcmp (bfd_asymbol_name (info->symtab[i]), RISCV_GP_SYMBOL) == 0)
258+
{
259+
pd->gp = bfd_asymbol_value (info->symtab[i]);
260+
pd->has_gp = true;
261+
}
262+
}
263+
241264
/* Update architecture for disassembler with its context.
242265
Call initialization functions if either:
243266
- the architecture for current context is changed or
@@ -1290,34 +1313,6 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
12901313
return info->bytes_per_chunk;
12911314
}
12921315

1293-
static bool
1294-
riscv_init_disasm_info (struct disassemble_info *info)
1295-
{
1296-
int i;
1297-
1298-
struct riscv_private_data *pd =
1299-
xcalloc (1, sizeof (struct riscv_private_data));
1300-
pd->gp = 0;
1301-
pd->print_addr = 0;
1302-
for (i = 0; i < (int) ARRAY_SIZE (pd->hi_addr); i++)
1303-
pd->hi_addr[i] = -1;
1304-
pd->to_print_addr = false;
1305-
pd->has_gp = false;
1306-
1307-
for (i = 0; i < info->symtab_size; i++)
1308-
{
1309-
asymbol *sym = info->symtab[i];
1310-
if (strcmp (bfd_asymbol_name (sym), RISCV_GP_SYMBOL) == 0)
1311-
{
1312-
pd->gp = bfd_asymbol_value (sym);
1313-
pd->has_gp = true;
1314-
}
1315-
}
1316-
1317-
info->private_data = pd;
1318-
return true;
1319-
}
1320-
13211316
int
13221317
print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
13231318
{
@@ -1329,13 +1324,14 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
13291324
int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte *,
13301325
struct disassemble_info *);
13311326

1327+
/* Initialize the private data. */
1328+
if (info->private_data == NULL)
1329+
init_riscv_dis_private_data (info);
1330+
13321331
/* Guess and update XLEN if we haven't determined it yet. */
13331332
if (xlen == 0)
13341333
update_riscv_dis_xlen (info);
13351334

1336-
if (info->private_data == NULL && !riscv_init_disasm_info (info))
1337-
return -1;
1338-
13391335
mstate = riscv_search_mapping_symbol (memaddr, info);
13401336
/* Save the last mapping state. */
13411337
last_map_state = mstate;

0 commit comments

Comments
 (0)