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 committed Aug 30, 2022
1 parent 7a07317 commit 94a6666
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,19 @@ 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. */

static enum riscv_seg_mstate
riscv_get_map_state_by_name (const char *name)
{
if (startswith (name, "$x"))
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 @@ -879,14 +892,11 @@ riscv_get_map_state (int n,
&& info->section != info->symtab[n]->section)
return false;

name = bfd_asymbol_name(info->symtab[n]);
if (startswith (name, "$x"))
*state = MAP_INSN;
else if (startswith (name, "$d"))
*state = MAP_DATA;
else
name = bfd_asymbol_name (info->symtab[n]);
enum riscv_seg_mstate newstate = riscv_get_map_state_by_name (name);
if (newstate == MAP_NONE)
return false;

*state = newstate;
return true;
}

Expand Down

0 comments on commit 94a6666

Please sign in to comment.