https://gcc.gnu.org/g:e780a09bd810c85936d52799d1af4f0cc0070dce
commit r15-8214-ge780a09bd810c85936d52799d1af4f0cc0070dce Author: jjasmine <tanghocle...@gmail.com> Date: Sun Jun 16 11:03:23 2024 -0700 gccrs: Scaffold expected on parse_options and asm_arg gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (check_and_set): Scaffold expected on parse_options and asm_arg (parse_options): Likewise (parse_asm_arg): Likewise * expand/rust-macro-builtins-asm.h (check_and_set): Likewise (parse_label): Likewise Signed-off-by: badumbatish <tanghocle...@gmail.com> Diff: --- gcc/rust/expand/rust-macro-builtins-asm.cc | 39 +++++++++++++++++++++--------- gcc/rust/expand/rust-macro-builtins-asm.h | 5 +--- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index 304edb1b936f..7e484713ef7d 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -35,6 +35,8 @@ std::map<AST::InlineAsmOption, std::string> InlineAsmOptionMap{ {AST::InlineAsmOption::RAW, "raw"}, }; +std::set<std::string> potentially_nonpromoted_keywords + = {"in", "out", "lateout", "inout", "inlateout", "const", "sym", "label"}; tl::expected<InlineAsmContext, InlineAsmParseError> parse_clobber_abi (InlineAsmContext inline_asm_ctx) { @@ -426,11 +428,10 @@ check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option) inline_asm.options.insert (option); } } -int +tl::expected<InlineAsmContext, InlineAsmParseError> parse_options (InlineAsmContext &inline_asm_ctx) { auto &parser = inline_asm_ctx.parser; - auto last_token_id = inline_asm_ctx.last_token_id; bool is_global_asm = inline_asm_ctx.inline_asm.is_global_asm; // Parse everything commitedly if (!parser.skip_token (LEFT_PAREN)) @@ -438,11 +439,11 @@ parse_options (InlineAsmContext &inline_asm_ctx) // We have shifted `options` to search for the left parenthesis next, we // should error out if this is not possible. // TODO: report some error. - return -1; + return tl::unexpected<InlineAsmParseError> (COMMITTED); } auto token = parser.peek_current_token (); - while (token->get_id () != last_token_id && token->get_id () != RIGHT_PAREN) + while (!parser.skip_token (RIGHT_PAREN)) { if (!is_global_asm && check_identifier (parser, "pure")) { @@ -489,7 +490,7 @@ parse_options (InlineAsmContext &inline_asm_ctx) ")", "att_syntax", "may_unwind", "nomem", "noreturn", "nostack", "preserves_flags", "pure", "raw", "readonly", token->as_string ().c_str ()); - return -1; + return tl::unexpected<InlineAsmParseError> (COMMITTED); } if (parser.skip_token (RIGHT_PAREN)) { @@ -505,7 +506,8 @@ parse_options (InlineAsmContext &inline_asm_ctx) { rust_unreachable (); token = parser.peek_current_token (); - return -1; + return tl::unexpected<InlineAsmParseError> (COMMITTED); + ; } } @@ -514,7 +516,7 @@ parse_options (InlineAsmContext &inline_asm_ctx) // let new_span = span_start.to(p.prev_token.span); // args.options_spans.push(new_span); - return 0; + return inline_asm_ctx; } bool @@ -599,10 +601,14 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx) inline_asm_ctx.consumed_comma_without_formatted_string = false; parser.skip_token (); } - else + else if (token->get_id () == COMMA + && inline_asm_ctx.consumed_comma_without_formatted_string) { - // TODO: we consumed comma, and there happens to also be a comma + // We consumed comma, and there happens to also be a comma // error should be: expected expression, found `,` + rust_error_at (token->get_locus (), "expected expression, found %qs", + ","); + return tl::unexpected<InlineAsmParseError> (COMMITTED); break; } @@ -620,14 +626,20 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx) // TODO: Parse clobber abi, eat the identifier named "clobber_abi" if true if (check_identifier (parser, "clobber_abi")) { - parse_clobber_abi (inline_asm_ctx); + auto expected = parse_clobber_abi (inline_asm_ctx); + if (expected || expected.error () == COMMITTED) + return expected; + continue; } // TODO: Parse options if (check_identifier (parser, "options")) { - parse_options (inline_asm_ctx); + auto expected = parse_options (inline_asm_ctx); + if (expected || expected.error () == COMMITTED) + return expected; + continue; } @@ -636,7 +648,10 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx) // std::cout << "reg_operand" << std::endl; // TODO: BUBBLE UP THIS EXPECTED(...) - auto operand = parse_reg_operand (inline_asm_ctx); + auto expected = parse_reg_operand (inline_asm_ctx); + if (expected || expected.error () == COMMITTED) + return expected; + continue; } return tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx); } diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h index d03adf004ca3..a0bfd782e9b0 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.h +++ b/gcc/rust/expand/rust-macro-builtins-asm.h @@ -119,7 +119,7 @@ void check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option); // From rustc -int +tl::expected<InlineAsmContext, InlineAsmParseError> parse_options (InlineAsmContext &inline_asm_ctx); // From rustc @@ -133,7 +133,4 @@ tl::optional<std::string> parse_label (Parser<MacroInvocLexer> &parser, TokenId last_token_id, InlineAsmContext &inline_asm_ctx); -std::set<std::string> potentially_nonpromoted_keywords - = {"in", "out", "lateout", "inout", "inlateout", "const", "sym", "label"}; - } // namespace Rust \ No newline at end of file