From 74b4e47aa64c64069928884d35a5bc255bfcf41d Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Sun, 20 Mar 2016 01:36:16 -0400 Subject: [PATCH] tc-sparc.c: get rid of wierd usage of strchr () This lets us avoid assigning a literal to a char *, and perhaps more importantly makes it clearer what is going on here. gas/ChangeLog: 2016-03-22 Trevor Saunders * config/tc-sparc.c (sparc_regname_to_dw2regnum): Replace strchr () call with a switch. --- gas/ChangeLog | 5 +++++ gas/config/tc-sparc.c | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 0c5d973dc8e..a6960a22e3c 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,8 @@ +2016-03-22 Trevor Saunders + + * config/tc-sparc.c (sparc_regname_to_dw2regnum): Replace strchr () + call with a switch. + 2016-03-22 Trevor Saunders * config/tc-ia64.c (ia64_do_align): Remove. diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c index cac5d18bd6f..5d4e0d6631c 100644 --- a/gas/config/tc-sparc.c +++ b/gas/config/tc-sparc.c @@ -4829,18 +4829,25 @@ sparc_cfi_frame_initial_instructions (void) int sparc_regname_to_dw2regnum (char *regname) { - char *p, *q; + char *q; + int i; if (!regname[0]) return -1; - q = "goli"; - p = strchr (q, regname[0]); - if (p) + switch (regname[0]) + { + case 'g': i = 0; break; + case 'o': i = 1; break; + case 'l': i = 2; break; + case 'i': i = 3; break; + default: i = -1; break; + } + if (i != -1) { if (regname[1] < '0' || regname[1] > '8' || regname[2]) return -1; - return (p - q) * 8 + regname[1] - '0'; + return i * 8 + regname[1] - '0'; } if (regname[0] == 's' && regname[1] == 'p' && !regname[2]) return 14; @@ -4851,7 +4858,7 @@ sparc_regname_to_dw2regnum (char *regname) unsigned int regnum; regnum = strtoul (regname + 1, &q, 10); - if (p == q || *q) + if (q == NULL || *q) return -1; if (regnum >= ((regname[0] == 'f' && SPARC_OPCODE_ARCH_V9_P (max_architecture)) -- 2.30.2