Teaching expression() to treat some operations specially

Dmitry Selyutin ghostmansd@gmail.com
Tue Jul 12 04:18:11 GMT 2022


On Tue, Jul 12, 2022 at 2:37 AM Alan Modra <amodra@gmail.com> wrote:
>
> You should not call expression like this without some syntactic
> element being consumed.

The expression() is not the culprit, it's the fact that operand() does
not set all the expression fields from the symbol.
The patch below "fixes" it, though I'm quite dubious regarding whether
this is a fix at all.

diff --git a/gas/expr.c b/gas/expr.c
index f4ea24717d..a46e220526 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -1350,8 +1350,7 @@ operand (expressionS *expressionP, enum expr_mode mode)
           }
         else if (mode != expr_defer && segment == reg_section)
           {
-             expressionP->X_op = O_register;
-             expressionP->X_add_number = S_GET_VALUE (symbolP);
+             *expressionP = *symbol_get_value_expression (symbolP);
           }
         else
           {

However, about using expression() in md_operand(), there's another question.
One of particular cases we're interested in is extending operands with
the vector notation.
For example, *%r3 would mean "vector register %r3, same as %r3, but
operating on a vector".
This is the code we're currently using; what'd be the safe way to
replace expression()?

void
md_operand (expressionS *exp)
{
  bool vector = false;

  if (*input_line_pointer == '*')
    {
      ++input_line_pointer;
      vector = true;
    }

  if (!register_name (exp))
    expression (exp);

  if (vector)
    {
      if (exp->X_op == O_register)
        exp->X_op = O_vector_register;
      else if (exp->X_op == O_constant)
        exp->X_op = O_vector_constant;
      else
        exp->X_op = O_absent;
    }
}

-- 
Best regards,
Dmitry Selyutin


More information about the Binutils mailing list