https://gcc.gnu.org/g:a527e317a067cc1ee9902dbeaadf3d77f306f614

commit r16-2963-ga527e317a067cc1ee9902dbeaadf3d77f306f614
Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
Date:   Tue Jul 29 13:53:58 2025 +0200

    gccrs: Parse input and output expression
    
    Previously inline assembly expected identifiers instead of expression.
    
    gcc/rust/ChangeLog:
    
            * expand/rust-macro-builtins-asm.cc (parse_reg_operand_inout): Parse
            expressions and build split in out.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 7b2cf7084457..9dc234cf850c 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -384,6 +384,7 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
 {
   auto &parser = inline_asm_ctx.parser;
   auto token = parser.peek_current_token ();
+  location_t locus = token->get_locus ();
 
   if (!inline_asm_ctx.is_global_asm () && check_identifier (parser, "inout"))
     {
@@ -401,10 +402,8 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
 
       // TODO: Is error propogation our top priority, the ? in rust's asm.rs is
       // doing a lot of work.
-      // TODO: Not sure how to use parse_expr
-      if (!check_identifier (parser, ""))
-       rust_unreachable ();
-      // auto expr = parse_format_string (inline_asm_ctx);
+      std::unique_ptr<AST::Expr> in_expr = parser.parse_expr ();
+      rust_assert (in_expr != nullptr);
 
       std::unique_ptr<AST::Expr> out_expr;
 
@@ -414,11 +413,19 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
            {
              // auto result = parse_format_string (inline_asm_ctx);
 
-             if (!check_identifier (parser, ""))
-               rust_unreachable ();
-             // out_expr = parser.parse_expr();
+             out_expr = parser.parse_expr ();
+
+             AST::InlineAsmOperand::SplitInOut splitinout (
+               reg, false, std::move (in_expr), std::move (out_expr));
+
+             inline_asm_ctx.inline_asm.operands.emplace_back (splitinout,
+                                                              locus);
+
+             return inline_asm_ctx;
            }
 
+         rust_unreachable ();
+
          // TODO: Rembmer to pass in clone_expr() instead of nullptr
          // 
https://github.com/rust-lang/rust/blob/a3167859f2fd8ff2241295469876a2b687280bdc/compiler/rustc_builtin_macros/src/asm.rs#L135
          // RUST VERSION: ast::InlineAsmOperand::SplitInOut { reg, in_expr:
@@ -432,6 +439,8 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
        }
       else
        {
+         AST::InlineAsmOperand::InOut inout (reg, false, std::move (in_expr));
+         inline_asm_ctx.inline_asm.operands.emplace_back (inout, locus);
          // 
https://github.com/rust-lang/rust/blob/a3167859f2fd8ff2241295469876a2b687280bdc/compiler/rustc_builtin_macros/src/asm.rs#L137
          // RUST VERSION: ast::InlineAsmOperand::InOut { reg, expr, late: false
          // }

Reply via email to