From: jjasmine Date: Tue, 21 May 2024 00:01:43 +0000 (-0700) Subject: gccrs: Introduce first implementation of parse_clobber_abi X-Git-Tag: basepoints/gcc-16~1388 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ea6a697d743d8a374711cad751b931891aac1c6;p=thirdparty%2Fgcc.git gccrs: Introduce first implementation of parse_clobber_abi 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. --- 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 &parser, TokenId last_token_id) return tl::nullopt; } +int +parse_clobber_abi (Parser &parser, TokenId last_token_id, + AsmArg &args) +{ + // clobber_abi := "clobber_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: 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 &parser, TokenId last_token_id, + AsmArg &args, bool is_global_asm) +{ + // Parse everything commitedly + if (!p.skip_token (LEFT_PAREN)) + {} +} bool check_identifier (Parser &p, std::string ident) { @@ -115,7 +189,7 @@ parseAsmArg (Parser &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 Templates; typedef std::vector Operands; typedef std::map RegisterArgs; -typedef std::map ClobberAbis; +typedef std::vector ClobberAbis; typedef std::map NamedValues; struct AsmArg @@ -84,4 +84,9 @@ parse_options (Parser &parser, TokenId last_token_id, tl::optional parse_reg (Parser &parser, TokenId last_token_id, AsmArg &args, bool is_explicit); + +int +parse_clobber_abi (Parser &parser, TokenId last_token_id, + AsmArg &args); + } // namespace Rust \ No newline at end of file