[PATCH 1/1] ppc: support register names in macros

Dmitry Selyutin ghostmansd@gmail.com
Tue Jul 12 14:13:11 GMT 2022


On Tue, Jul 12, 2022 at 4:51 PM Dmitry Selyutin <ghostmansd@gmail.com> wrote:
> @@ -7752,23 +7714,15 @@ tc_ppc_regname_to_dw2regnum (char *regname)
>      if (strcmp (regnames[i].name, regname) == 0)
>        return regnames[i].dw2regnum;
>
> -  if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
> -    {
> -      p = regname + 1 + (regname[1] == '.');
> -      regnum = strtoul (p, &q, 10);
> -      if (p == q || *q || regnum >= 32)
> -       return -1;
> -      if (regname[0] == 'f')
> -       regnum += 32;
> -      else if (regname[0] == 'v')
> -       regnum += 77;
> -    }
> -  else if (regname[0] == 'c' && regname[1] == 'r')
> -    {
> -      p = regname + 2 + (regname[2] == '.');
> -      if (p[0] < '0' || p[0] > '7' || p[1])
> -       return -1;
> -      regnum = p[0] - '0' + 68;
> -    }
> -  return regnum;
> +  if (regname[0] == '%' && ISALPHA (regname[1]))
> +    ++regname;
> +
> +  reg = reg_name_search (reg_names, REG_NAME_CNT, regname);
> +  if (reg == NULL)
> +    reg = reg_name_search (cr_names, CR_NAME_CNT, regname);
> +
> +  if (reg != NULL)
> +    return reg->value;
> +
> +  return -1;
>  }

I'm by no means a CFI expert, so I'm not sure whether we should be
able to accept all registers here.
Judging from the original (overly simplified) code, we should only
consider a register with one of these flags:

    PPC_OPERAND_GPR
    PPC_OPERAND_FPR
    PPC_OPERAND_VR
    PPC_OPERAND_CR_REG

I'm inclined to add this check for reg->flags. Any objections?

-- 
Best regards,
Dmitry Selyutin


More information about the Binutils mailing list