Skip to content

Commit ce839d4

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 af5b30c commit ce839d4

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
@@ -233,6 +233,29 @@ init_riscv_dis_state_for_arch_and_options (void)
233233
is_arch_changed = false;
234234
}
235235

236+
/* Initialize private data of the disassemble_info. */
237+
238+
static void
239+
init_riscv_dis_private_data (struct disassemble_info *info)
240+
{
241+
struct riscv_private_data *pd;
242+
243+
pd = info->private_data = xcalloc (1, sizeof (struct riscv_private_data));
244+
pd->gp = 0;
245+
pd->print_addr = 0;
246+
for (int i = 0; i < (int)ARRAY_SIZE (pd->hi_addr); i++)
247+
pd->hi_addr[i] = -1;
248+
pd->to_print_addr = false;
249+
pd->has_gp = false;
250+
251+
for (int i = 0; i < info->symtab_size; i++)
252+
if (strcmp (bfd_asymbol_name (info->symtab[i]), RISCV_GP_SYMBOL) == 0)
253+
{
254+
pd->gp = bfd_asymbol_value (info->symtab[i]);
255+
pd->has_gp = true;
256+
}
257+
}
258+
236259
/* Update architecture for disassembler with its context.
237260
Call initialization functions if either:
238261
- the architecture for current context is changed or
@@ -1280,34 +1303,6 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
12801303
return info->bytes_per_chunk;
12811304
}
12821305

1283-
static bool
1284-
riscv_init_disasm_info (struct disassemble_info *info)
1285-
{
1286-
int i;
1287-
1288-
struct riscv_private_data *pd =
1289-
xcalloc (1, sizeof (struct riscv_private_data));
1290-
pd->gp = 0;
1291-
pd->print_addr = 0;
1292-
for (i = 0; i < (int) ARRAY_SIZE (pd->hi_addr); i++)
1293-
pd->hi_addr[i] = -1;
1294-
pd->to_print_addr = false;
1295-
pd->has_gp = false;
1296-
1297-
for (i = 0; i < info->symtab_size; i++)
1298-
{
1299-
asymbol *sym = info->symtab[i];
1300-
if (strcmp (bfd_asymbol_name (sym), RISCV_GP_SYMBOL) == 0)
1301-
{
1302-
pd->gp = bfd_asymbol_value (sym);
1303-
pd->has_gp = true;
1304-
}
1305-
}
1306-
1307-
info->private_data = pd;
1308-
return true;
1309-
}
1310-
13111306
int
13121307
print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
13131308
{
@@ -1319,13 +1314,14 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
13191314
int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte *,
13201315
struct disassemble_info *);
13211316

1317+
/* Initialize the private data. */
1318+
if (info->private_data == NULL)
1319+
init_riscv_dis_private_data (info);
1320+
13221321
/* Guess and update XLEN if we haven't determined it yet. */
13231322
if (xlen == 0)
13241323
update_riscv_dis_xlen (info);
13251324

1326-
if (info->private_data == NULL && !riscv_init_disasm_info (info))
1327-
return -1;
1328-
13291325
mstate = riscv_search_mapping_symbol (memaddr, info);
13301326
/* Save the last mapping state. */
13311327
last_map_state = mstate;

0 commit comments

Comments
 (0)