Skip to content

Commit

Permalink
RISC-V: Split riscv_get_map_state into two steps
Browse files Browse the repository at this point in the history
Because mapping symbol optimization would remove riscv_get_map_state
function, this commit splits symbol name checking step into a separate
function riscv_get_map_state_by_name.

Let alone the optimization, splitting the code improves readability.

opcodes/ChangeLog:

	* riscv-dis.c (riscv_get_map_state): Split symbol name checking
	into a separate function.  (riscv_get_map_state_by_name): New.
  • Loading branch information
a4lg authored and ouuleilei-bot committed Nov 15, 2022
1 parent d9fb0b9 commit 9c3e2d6
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,24 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info)
return insnlen;
}

/* Return new mapping state if a given symbol name is of mapping symbols',
MAP_NONE otherwise. If arch is not NULL and name denotes a mapping symbol
with ISA string, *arch is updated to the ISA string. */

static enum riscv_seg_mstate
riscv_get_map_state_by_name (const char *name, const char** arch)
{
if (startswith (name, "$x"))
{
if (arch && startswith (name + 2, "rv"))
*arch = name + 2;
return MAP_INSN;
}
else if (startswith (name, "$d"))
return MAP_DATA;
return MAP_NONE;
}

/* Return true if we find the suitable mapping symbol,
and also update the STATE. Otherwise, return false. */

Expand All @@ -824,28 +842,23 @@ riscv_get_map_state (int n,
enum riscv_seg_mstate *state,
struct disassemble_info *info)
{
const char *name;
const char *name, *arch = NULL;

/* If the symbol is in a different section, ignore it. */
if (info->section != NULL
&& info->section != info->symtab[n]->section)
return false;

name = bfd_asymbol_name(info->symtab[n]);
if (startswith (name, "$x"))
name = bfd_asymbol_name (info->symtab[n]);
enum riscv_seg_mstate newstate = riscv_get_map_state_by_name (name, &arch);
if (newstate == MAP_NONE)
return false;
*state = newstate;
if (arch)
{
if (startswith (name + 2, "rv"))
{
riscv_release_subset_list (&riscv_subsets);
riscv_parse_subset (&riscv_rps_dis, name + 2);
}
*state = MAP_INSN;
riscv_release_subset_list (&riscv_subsets);
riscv_parse_subset (&riscv_rps_dis, arch);
}
else if (startswith (name, "$d"))
*state = MAP_DATA;
else
return false;

return true;
}

Expand Down

0 comments on commit 9c3e2d6

Please sign in to comment.