From: jjasmine <tanghocle...@gmail.com> gcc/rust/ChangeLog:
* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): title. (parseAsmArg): title. * expand/rust-macro-builtins-asm.h (parse_clobber_abi): title. --- gcc/rust/expand/rust-macro-builtins-asm.cc | 76 +++++++++++++++++++++- gcc/rust/expand/rust-macro-builtins-asm.h | 7 +- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index f26c4610230..9d904d6223e 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -26,6 +26,80 @@ parseDirSpec (Parser<MacroInvocLexer> &parser, TokenId last_token_id) return tl::nullopt; } +int +parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + AsmArg &args) +{ + // clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")" + + // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA clobber_abi + // identifier keyword + + if (!parser.skip_token (LEFT_PAREN)) + { + // TODO: Raise error exactly like rustc if left parenthesis is not + // encountered. + return -1; + } + + if (parser.skip_token (RIGHT_PAREN)) + { + // TODO: We encountered a "clobber_abi()", which should be illegal? + // https://github.com/rust-lang/rust/blob/c00957a3e269219413041a4e3565f33b1f9d0779/compiler/rustc_builtin_macros/src/asm.rs#L381 + return -1; + } + + ClobberAbis new_abis; + + auto token = parser.peek_current_token (); + + while (token->get_id () != last_token_id && token->get_id () != RIGHT_PAREN) + { + // Check if it is a string literal or not, codename: <ABI> in ABNF + if (token->get_id () == STRING_LITERAL) + { + // TODO: Caring for span in here. + new_abis.push_back (token->as_string ()); + } + else + { + // TODO: We encountered something that is not string literal, which + // should be illegal, please emit the correct error + // https://github.com/rust-lang/rust/blob/b92758a9aef1cef7b79e2b72c3d8ba113e547f89/compiler/rustc_builtin_macros/src/asm.rs#L387 + } + + if (parser.skip_token (RIGHT_PAREN)) + { + break; + } + + if (!parser.skip_token (COMMA)) + { + // TODO: If the skip of comma is unsuccessful, which should be + // illegal, pleaes emit the correct error. + return -1; + } + + // Done processing the local clobber abis, push that to the main Args in + // argument + + for (auto abi : new_abis) + { + args.clobber_abis.push_back (abi); + } + + return 0; + } +} + +int +parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + AsmArg &args, bool is_global_asm) +{ + // Parse everything commitedly + if (!p.skip_token (LEFT_PAREN)) + {} +} bool check_identifier (Parser<MacroInvocLexer> &p, std::string ident) { @@ -115,7 +189,7 @@ parseAsmArg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // Ok after the left paren is good, we better be parsing correctly // everything in here, which is operand in ABNF - // TODO: Parse clobber abi + // TODO: Parse clobber abi, eat the identifier named "clobber_abi" if true if (check_identifier (parser, "clobber_abi")) { std::cout << "Clobber abi tee hee" << std::endl; diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h index 3a67c7e3152..ebb939a0548 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.h +++ b/gcc/rust/expand/rust-macro-builtins-asm.h @@ -37,7 +37,7 @@ typedef std::string symbol_name; typedef std::vector<AST::Expr> Templates; typedef std::vector<InlineAsmDirSpec> Operands; typedef std::map<std::string, int> RegisterArgs; -typedef std::map<symbol_name, int> ClobberAbis; +typedef std::vector<symbol_name> ClobberAbis; typedef std::map<symbol_name, int> NamedValues; struct AsmArg @@ -84,4 +84,9 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, tl::optional<InlineAsmRegOrRegClass> parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, AsmArg &args, bool is_explicit); + +int +parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + AsmArg &args); + } // namespace Rust \ No newline at end of file -- 2.45.2