aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjjasmine <tanghocle456@gmail.com>2024-05-21 16:50:36 -0700
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:37 +0100
commit7f6fd8db4879f93680d2611cbd9e5f26bb4bcfb7 (patch)
treedd1f923a15481cbd006cb25a86253ab1fb9aea70
parentca10fe5f2a66060a7ab01cc2b3bd68154e385742 (diff)
downloadgcc-7f6fd8db4879f93680d2611cbd9e5f26bb4bcfb7.zip
gcc-7f6fd8db4879f93680d2611cbd9e5f26bb4bcfb7.tar.gz
gcc-7f6fd8db4879f93680d2611cbd9e5f26bb4bcfb7.tar.bz2
gccrs: Replace scaffolded InlineAsm with real InlineAsm.
Replace scaffolded InlineAsm with real InlineAsm node in rust-expr.h gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parseDirSpec): replace scaffolded InlineAsm with real InlineAsm. (parse_clobber_abi): likewise. (check_and_set): likewise. (parse_options): likewise. (parseAsmArg): likewise. (parse_asm): likewise. * expand/rust-macro-builtins-asm.h (struct AsmParseError): likewise. (enum InlineAsmDirSpec): likewise. (enum InlineAsmRegOrRegClass): likewise. (struct AsmArg): likewise. (parseAsmArg): likewise. (check_and_set): likewise. (parse_operand): likewise. (parse_options): likewise. (parse_reg): likewise. (parse_clobber_abi): likewise.
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.cc54
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.h66
2 files changed, 40 insertions, 80 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 971dd7b..6e602c4 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -20,15 +20,15 @@
namespace Rust {
-tl::optional<InlineAsmDirSpec>
+int
parseDirSpec (Parser<MacroInvocLexer> &parser, TokenId last_token_id)
{
- return tl::nullopt;
+ return 0;
}
int
parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
- AsmArg &args)
+ AST::InlineAsm &inlineAsm)
{
// clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
@@ -49,7 +49,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
return -1;
}
- ClobberAbis new_abis;
+ std::vector<AST::TupleClobber> new_abis;
auto token = parser.peek_current_token ();
@@ -59,7 +59,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
if (token->get_id () == STRING_LITERAL)
{
// TODO: Caring for span in here.
- new_abis.push_back (token->as_string ());
+ new_abis.push_back ({token->as_string (), token->get_locus ()});
}
else
{
@@ -88,16 +88,17 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
for (auto abi : new_abis)
{
- args.clobber_abis.push_back (abi);
+ inlineAsm.clobber_abi.push_back (abi);
}
return 0;
}
void
-check_and_set (Parser<MacroInvocLexer> &p, AsmArg &args, std::string option)
+check_and_set (Parser<MacroInvocLexer> &p, AST::InlineAsm &inlineAsm,
+ std::string option)
{
- if (args.options.count (option) == 1)
+ if (inlineAsm.options.count (option) == 1)
{
// TODO: report an error of duplication
@@ -105,13 +106,14 @@ check_and_set (Parser<MacroInvocLexer> &p, AsmArg &args, std::string option)
}
else
{
- args.options.insert (option);
+ inlineAsm.options.insert (option);
}
}
int
parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
- AsmArg &args, bool is_global_asm)
+ AST::InlineAsm &inlineAsm)
{
+ bool is_global_asm = inlineAsm.is_global_asm;
// Parse everything commitedly
if (!parser.skip_token (LEFT_PAREN))
{
@@ -126,43 +128,43 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
{
if (!is_global_asm && check_identifier (parser, "pure"))
{
- check_and_set (parser, args, "pure");
+ check_and_set (parser, inlineAsm, "pure");
}
else if (!is_global_asm && check_identifier (parser, "nomem"))
{
- check_and_set (parser, args, "nomem");
+ check_and_set (parser, inlineAsm, "nomem");
}
else if (!is_global_asm && check_identifier (parser, "readonly"))
{
- check_and_set (parser, args, "readonly");
+ check_and_set (parser, inlineAsm, "readonly");
}
else if (!is_global_asm && check_identifier (parser, "preserves_flags"))
{
- check_and_set (parser, args, "preserves_flags");
+ check_and_set (parser, inlineAsm, "preserves_flags");
}
else if (!is_global_asm && check_identifier (parser, "noreturn"))
{
- check_and_set (parser, args, "noreturn");
+ check_and_set (parser, inlineAsm, "noreturn");
}
else if (!is_global_asm && check_identifier (parser, "noreturn"))
{
- check_and_set (parser, args, "noreturn");
+ check_and_set (parser, inlineAsm, "noreturn");
}
else if (!is_global_asm && check_identifier (parser, "nostack"))
{
- check_and_set (parser, args, "nostack");
+ check_and_set (parser, inlineAsm, "nostack");
}
else if (!is_global_asm && check_identifier (parser, "may_unwind"))
{
- check_and_set (parser, args, "may_unwind");
+ check_and_set (parser, inlineAsm, "may_unwind");
}
else if (check_identifier (parser, "att_syntax"))
{
- check_and_set (parser, args, "att_syntax");
+ check_and_set (parser, inlineAsm, "att_syntax");
}
else if (check_identifier (parser, "raw"))
{
- check_and_set (parser, args, "raw");
+ check_and_set (parser, inlineAsm, "raw");
}
else
{
@@ -249,12 +251,11 @@ MacroBuiltin::nonglobal_asm_handler (location_t invoc_locus,
return parse_asm (invoc_locus, invoc, is_global_asm);
}
-tl::optional<AsmArg>
+int
parseAsmArg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
- bool is_global_asm)
+ AST::InlineAsm &inlineAsm)
{
auto token = parser.peek_current_token ();
- AsmArg arg;
tl::optional<std::string> fm_string;
while (token->get_id () != last_token_id)
{
@@ -299,7 +300,7 @@ parseAsmArg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
// only other logical choice is reg_operand
fm_string = parse_format_string (parser, last_token_id);
}
- return tl::nullopt;
+ return 0;
}
static tl::optional<AST::Fragment>
@@ -326,6 +327,9 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
Parser<MacroInvocLexer> parser (lex);
auto last_token_id = macro_end_token (invoc.get_delim_tok_tree (), parser);
+ AST::InlineAsm inlineAsm (invoc_locus, is_global_asm);
+ inlineAsm.is_global_asm = is_global_asm;
+
// Parse the first ever formatted string, success or not, will skip 1 token
auto fm_string = parse_format_string (parser, last_token_id);
if (fm_string == tl::nullopt)
@@ -349,7 +353,7 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
}
// operands stream, also handles the optional ","
- parseAsmArg (parser, last_token_id, is_global_asm);
+ parseAsmArg (parser, last_token_id, inlineAsm);
return tl::nullopt;
}
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h
index fd86c309..204ac0e 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -2,59 +2,14 @@
#include "rust-macro-builtins.h"
#include "rust-macro-builtins-helpers.h"
#include "rust-macro-invoc-lexer.h"
-
+#include "rust/ast/rust-expr.h"
namespace Rust {
-struct AsmParseError
-{
-};
-
-// This is just an enum to hold some operands right now.
-enum InlineAsmDirSpec
-{
- In,
- Out,
- InOut,
- SplitInOut,
- InLateOut, // TODO: This is not present in rust's asm.rs
- Const, // TODO: This is not present in ABNF
- Sym, // TODO: This is not present in ABNF
- Label, // TODO: This is not present in ABNF
-};
-
-// Place holder for classes
-enum InlineAsmRegOrRegClass
-{
- InlineAsmReg,
- Reg,
-};
-
-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::vector<symbol_name> ClobberAbis;
-typedef std::map<symbol_name, int> NamedValues;
-typedef std::set<std::string> InlineAsmOptions;
-
-struct AsmArg
-{
- Templates templates;
- Operands operands;
- std::map<symbol_name, int> named_values;
- RegisterArgs register_arguments;
- ClobberAbis clobber_abis;
- InlineAsmOptions options;
- std::vector<InlineAsmOptions>
- options_span; // TODO: @badumbatish @jjasmine I have no idea what span do, i
- // copied it out of rustc_builtin_macros/src/asm.rs
-};
-
// All the operands are called asm_args in rustc asm.rs, we create a struct that
// can store all of these AsmArgs This replaces the phase where we have to parse
// all operands.
-tl::optional<AsmArg>
+int
parseAsmArg (Parser<MacroInvocLexer> &p, TokenId last_token_id,
- bool is_global_asm);
+ AST::InlineAsm &inlineAsm);
static tl::optional<AST::Fragment>
parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
static tl::optional<AST::Fragment>
@@ -67,24 +22,25 @@ bool
check_identifier (Parser<MacroInvocLexer> &p, std::string ident);
void
-check_and_set (Parser<MacroInvocLexer> &p, AsmArg &args, std::string option);
+check_and_set (Parser<MacroInvocLexer> &p, AST::InlineAsm &inlineAsm,
+ std::string option);
// From rustc
int
parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
- AsmArg &args);
+ AST::InlineAsm &inlineAsm);
// From rustc
int
parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
- AsmArg &args, bool is_global_asm);
+ AST::InlineAsm &inlineAsm);
// From rustc
-tl::optional<InlineAsmRegOrRegClass>
-parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, AsmArg &args,
- bool is_explicit);
+int
+parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
+ AST::InlineAsm &inlineAsm, bool is_explicit);
int
parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
- AsmArg &args);
+ AST::InlineAsm &inlineAsm);
} // namespace Rust \ No newline at end of file