From 0c993d4a0e50b0064bfa70591bb02e216efaf1c9 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Sun, 31 Jul 2022 14:09:37 +0900 Subject: [PATCH] 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. --- opcodes/riscv-dis.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 65f8212e455..bda48eac847 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -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. */ @@ -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; }