diff options
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins-asm.cc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.cc | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index 850c8dd..61222db 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 // } @@ -819,6 +828,11 @@ expand_inline_asm_strings (InlineAsmContext inline_asm_ctx) } break; case Fmt::ffi::Position::Tag::ArgumentIs: + { + auto idx = next_argument.position.argument_is._0; + transformed_template_str += "%" + std::to_string (idx); + break; + } case Fmt::ffi::Position::Tag::ArgumentNamed: rust_sorry_at (inline_asm.get_locus (), "unhandled argument position specifier"); @@ -923,7 +937,9 @@ parse_format_strings (InlineAsmContext inline_asm_ctx) { if (!parser.skip_token (COMMA)) { - break; + rust_error_at (parser.peek_current_token ()->get_locus (), + "expected token %qs", ";"); + return tl::unexpected<InlineAsmParseError> (COMMITTED); } // Ok after the comma is good, we better be parsing correctly // everything in here, which is formatted string in ABNF |