diff options
author | jjasmine <tanghocle456@gmail.com> | 2024-06-15 22:18:22 -0700 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-06-28 09:59:34 +0000 |
commit | c37eb03de6b316cf5654b7d7ff86d38022aca2d8 (patch) | |
tree | 5b85b9867e19a335146a2dd825b5081b90463fde /gcc/rust/expand/rust-macro-builtins-asm.cc | |
parent | 79a2eaa693525d4d753ff5096b99fe43ef6b3bc1 (diff) | |
download | gcc-c37eb03de6b316cf5654b7d7ff86d38022aca2d8.zip gcc-c37eb03de6b316cf5654b7d7ff86d38022aca2d8.tar.gz gcc-c37eb03de6b316cf5654b7d7ff86d38022aca2d8.tar.bz2 |
Finish expected parse_reg_operand
gcc/rust/ChangeLog:
* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
Finish expected parse_reg_operand
(parse_reg_operand_unexpected): Likewise
* expand/rust-macro-builtins-asm.h (parse_reg_operand_unexpected): Likewise
Signed-off-by: badumbatish <tanghocle456@gmail.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins-asm.cc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.cc | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index 8dd7238..2c59e8e 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -208,52 +208,34 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx) } } - // For the keyword IN, currently we count it as a seperate keyword called - // Rust::IN search for #define RS_TOKEN_LIST in code base. tl::expected<InlineAsmContext, InlineAsmParseError> parsing_operand = tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx); - // PARSING WITH IN - parsing_operand.map (parse_reg_operand_in); - if (parsing_operand || parsing_operand.error () == COMMITTED) - return parsing_operand; - - // KEEP ON PARSING WITH OUT - parsing_operand.emplace (inline_asm_ctx); - parsing_operand.map (parse_reg_operand_out); - if (parsing_operand || parsing_operand.error () == COMMITTED) - return parsing_operand; - - // KEEP ON PARSING WITH LATEOUT - parsing_operand.emplace (inline_asm_ctx); - parsing_operand.map (parse_reg_operand_lateout); - if (parsing_operand || parsing_operand.error () == COMMITTED) - return parsing_operand; - - // KEEP ON PARSING WITH INOUT - parsing_operand.emplace (inline_asm_ctx); - parsing_operand.map (parse_reg_operand_inout); - if (parsing_operand || parsing_operand.error () == COMMITTED) - return parsing_operand; - - // KEEP ON PARSING WITH INOUT - parsing_operand.emplace (inline_asm_ctx); - parsing_operand.map (parse_reg_operand_const); - if (parsing_operand || parsing_operand.error () == COMMITTED) - return parsing_operand; + // Here is all parse_reg_operand functions we're using in a for loop + auto parse_funcs = {parse_reg_operand_in, parse_reg_operand_out, + parse_reg_operand_lateout, parse_reg_operand_inout, + parse_reg_operand_const, parse_reg_operand_sym, + parse_reg_operand_unexpected}; - // TODO: It is weird that we can't seem to match any identifier, - // something must be wrong. consult compiler code in asm.rs or rust online - // compiler. - rust_unreachable (); + // Loop over and execute the parsing functions, if the parser successfullly + // parses or if the parser fails to parse while it has committed to a token, + // we propogate the result. + for (auto &parse_func : parse_funcs) + { + parsing_operand.emplace (inline_asm_ctx); + parsing_operand.map (parse_func); + if (parsing_operand || parsing_operand.error () == COMMITTED) + return parsing_operand; + } - rust_error_at (token->get_locus (), "ERROR RIGHT HERE"); - return tl::unexpected<InlineAsmParseError> (COMMITTED); + return parsing_operand; } tl::expected<InlineAsmContext, InlineAsmParseError> parse_reg_operand_in (InlineAsmContext inline_asm_ctx) { + // For the keyword IN, currently we count it as a seperate keyword called + // Rust::IN search for #define RS_TOKEN_LIST in code base. AST::InlineAsmOperand reg_operand; auto &parser = inline_asm_ctx.parser; if (!inline_asm_ctx.is_global_asm () && parser.skip_token (IN)) @@ -412,6 +394,20 @@ parse_reg_operand_sym (InlineAsmContext inline_asm_ctx) } return tl::unexpected<InlineAsmParseError> (NONCOMMITED); } + +tl::expected<InlineAsmContext, InlineAsmParseError> +parse_reg_operand_unexpected (InlineAsmContext inline_asm_ctx) +{ + auto token = inline_asm_ctx.parser.peek_current_token (); + // TODO: It is weird that we can't seem to match any identifier, + // something must be wrong. consult compiler code in asm.rs or rust online + // compiler. + rust_unreachable (); + + rust_error_at (token->get_locus (), "ERROR RIGHT HERE"); + return tl::unexpected<InlineAsmParseError> (COMMITTED); +} + void check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option) { |