Skip to content

Commit 58cef6b

Browse files
P-E-PCohenArthur
authored andcommitted
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 <[email protected]>
1 parent cdeec23 commit 58cef6b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

gcc/rust/expand/rust-macro-builtins-asm.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
384384
{
385385
auto &parser = inline_asm_ctx.parser;
386386
auto token = parser.peek_current_token ();
387+
location_t locus = token->get_locus ();
387388

388389
if (!inline_asm_ctx.is_global_asm () && check_identifier (parser, "inout"))
389390
{
@@ -401,10 +402,8 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
401402

402403
// TODO: Is error propogation our top priority, the ? in rust's asm.rs is
403404
// doing a lot of work.
404-
// TODO: Not sure how to use parse_expr
405-
if (!check_identifier (parser, ""))
406-
rust_unreachable ();
407-
// auto expr = parse_format_string (inline_asm_ctx);
405+
std::unique_ptr<AST::Expr> in_expr = parser.parse_expr ();
406+
rust_assert (in_expr != nullptr);
408407

409408
std::unique_ptr<AST::Expr> out_expr;
410409

@@ -414,11 +413,19 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
414413
{
415414
// auto result = parse_format_string (inline_asm_ctx);
416415

417-
if (!check_identifier (parser, ""))
418-
rust_unreachable ();
419-
// out_expr = parser.parse_expr();
416+
out_expr = parser.parse_expr ();
417+
418+
AST::InlineAsmOperand::SplitInOut splitinout (
419+
reg, false, std::move (in_expr), std::move (out_expr));
420+
421+
inline_asm_ctx.inline_asm.operands.emplace_back (splitinout,
422+
locus);
423+
424+
return inline_asm_ctx;
420425
}
421426

427+
rust_unreachable ();
428+
422429
// TODO: Rembmer to pass in clone_expr() instead of nullptr
423430
// https://github.com/rust-lang/rust/blob/a3167859f2fd8ff2241295469876a2b687280bdc/compiler/rustc_builtin_macros/src/asm.rs#L135
424431
// RUST VERSION: ast::InlineAsmOperand::SplitInOut { reg, in_expr:
@@ -432,6 +439,8 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
432439
}
433440
else
434441
{
442+
AST::InlineAsmOperand::InOut inout (reg, false, std::move (in_expr));
443+
inline_asm_ctx.inline_asm.operands.emplace_back (inout, locus);
435444
// https://github.com/rust-lang/rust/blob/a3167859f2fd8ff2241295469876a2b687280bdc/compiler/rustc_builtin_macros/src/asm.rs#L137
436445
// RUST VERSION: ast::InlineAsmOperand::InOut { reg, expr, late: false
437446
// }

0 commit comments

Comments
 (0)