aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjjasmine <tanghocle456@gmail.com>2024-05-20 17:01:43 -0700
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:36 +0100
commit2ea6a697d743d8a374711cad751b931891aac1c6 (patch)
treee282061c566ebd6801e8f960ef46f1be3aed4458
parent2695feddfdad99c66b73d6b0ba903f5f58115a09 (diff)
downloadgcc-2ea6a697d743d8a374711cad751b931891aac1c6.zip
gcc-2ea6a697d743d8a374711cad751b931891aac1c6.tar.gz
gcc-2ea6a697d743d8a374711cad751b931891aac1c6.tar.bz2
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.
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.cc76
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.h7
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 f26c461..9d904d6 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 3a67c7e..ebb939a 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