Skip to content

Commit 22b0d5a

Browse files
committed
RISC-V: Split riscv_get_map_state into two steps
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.
1 parent 251b52d commit 22b0d5a

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

opcodes/riscv-dis.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,24 @@ riscv_disassemble_insn (bfd_vma memaddr,
846846
return insnlen;
847847
}
848848

849+
/* Return new mapping state if a given symbol name is of mapping symbols',
850+
MAP_NONE otherwise. If arch is not NULL and name denotes a mapping symbol
851+
with ISA string, *arch is updated to the ISA string. */
852+
853+
static enum riscv_seg_mstate
854+
riscv_get_map_state_by_name (const char *name, const char** arch)
855+
{
856+
if (startswith (name, "$x"))
857+
{
858+
if (arch && startswith (name + 2, "rv"))
859+
*arch = name + 2;
860+
return MAP_INSN;
861+
}
862+
else if (startswith (name, "$d"))
863+
return MAP_DATA;
864+
return MAP_NONE;
865+
}
866+
849867
/* Return true if we find the suitable mapping symbol,
850868
and also update the STATE. Otherwise, return false. */
851869

@@ -854,28 +872,23 @@ riscv_get_map_state (int n,
854872
enum riscv_seg_mstate *state,
855873
struct disassemble_info *info)
856874
{
857-
const char *name;
875+
const char *name, *arch = NULL;
858876

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

864-
name = bfd_asymbol_name(info->symtab[n]);
865-
if (startswith (name, "$x"))
882+
name = bfd_asymbol_name (info->symtab[n]);
883+
enum riscv_seg_mstate newstate = riscv_get_map_state_by_name (name, &arch);
884+
if (newstate == MAP_NONE)
885+
return false;
886+
*state = newstate;
887+
if (arch)
866888
{
867-
if (startswith (name + 2, "rv"))
868-
{
869-
riscv_release_subset_list (&riscv_subsets);
870-
riscv_parse_subset (&riscv_rps_dis, name + 2);
871-
}
872-
*state = MAP_INSN;
889+
riscv_release_subset_list (&riscv_subsets);
890+
riscv_parse_subset (&riscv_rps_dis, arch);
873891
}
874-
else if (startswith (name, "$d"))
875-
*state = MAP_DATA;
876-
else
877-
return false;
878-
879892
return true;
880893
}
881894

0 commit comments

Comments
 (0)