diff options
author | jjasmine <tanghocle456@gmail.com> | 2024-05-18 21:24:10 -0700 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:35 +0100 |
commit | 2695feddfdad99c66b73d6b0ba903f5f58115a09 (patch) | |
tree | 4bd5daaab1af8d8ccb35177eb77bb60a7c59b6a1 /gcc | |
parent | ab988c156f9a1a7eed1684b8bb40d05aa757c0f8 (diff) | |
download | gcc-2695feddfdad99c66b73d6b0ba903f5f58115a09.zip gcc-2695feddfdad99c66b73d6b0ba903f5f58115a09.tar.gz gcc-2695feddfdad99c66b73d6b0ba903f5f58115a09.tar.bz2 |
gccrs: Working on parseAsmArg
gcc/rust/ChangeLog:
* expand/rust-macro-builtins-asm.cc (enum InlineAsmRegOrRegClass): title.
(parseAsmArg): title.
(check_identifier): title.
(parse_operand): title.
(parse_options): title.
(parse_reg): title.
(parseDirSpec): title.
(parse_asm): title.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.cc | 151 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.h | 87 |
2 files changed, 159 insertions, 79 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index 7958d91..f26c461 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -16,74 +16,32 @@ // along with GCC; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -#include "rust-macro-builtins.h" -#include "rust-macro-builtins-helpers.h" -#include "rust-macro-invoc-lexer.h" +#include "rust-macro-builtins-asm.h" namespace Rust { -struct AsmParseError -{ -}; - -// This is just an enum to hold some operands right now. -enum InlineAsmDirSpec -{ - In, - Out, - InOut, - SplitInOut, - Const, - Sym, - Label, -}; - -enum InlineAsmOptions -{ - -}; - -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::map<symbol_name, int> NamedValues; - -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 -}; - -tl::optional<AsmArg> -parseAsmArg (Parser<MacroInvocLexer> &p, bool is_global_asm); -static tl::optional<AST::Fragment> -parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc); -static tl::optional<AST::Fragment> -parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc); -static tl::optional<AST::Fragment> -parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, - bool is_global_asm); - tl::optional<InlineAsmDirSpec> -parseDirSpec (Parser<MacroInvocLexer> &p, TokenId last_token_id) +parseDirSpec (Parser<MacroInvocLexer> &parser, TokenId last_token_id) { return tl::nullopt; } -tl::optional<AsmArg> -parseAsmArg (Parser<MacroInvocLexer> &p, bool is_global_asm) + +bool +check_identifier (Parser<MacroInvocLexer> &p, std::string ident) { - return tl::nullopt; -} + auto token = p.peek_current_token (); + if (token->get_id () == IDENTIFIER + && (token->as_string () == ident || ident == "")) + { + p.skip_token (); + return true; + } + else + { + return false; + } +} tl::optional<std::string> parse_format_string (Parser<MacroInvocLexer> &parser, TokenId last_token_id) { @@ -125,6 +83,59 @@ MacroBuiltin::nonglobal_asm_handler (location_t invoc_locus, return parse_asm (invoc_locus, invoc, is_global_asm); } +tl::optional<AsmArg> +parseAsmArg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + bool is_global_asm) +{ + auto token = parser.peek_current_token (); + AsmArg arg; + tl::optional<std::string> fm_string; + while (token->get_id () != last_token_id) + { + std::cout << token->get_token_description () << std::endl; + + token = parser.peek_current_token (); + + // We accept a comma token here. + if (token->get_id () != COMMA) + { + break; + } + parser.skip_token (); + + // And if that token comma is also the trailing comma, we break + // TODO: Check with mentor see what last_token_id means + token = parser.peek_current_token (); + if (token->get_id () == COMMA && token->get_id () == last_token_id) + { + parser.skip_token (); + break; + } + + // Ok after the left paren is good, we better be parsing correctly + // everything in here, which is operand in ABNF + + // TODO: Parse clobber abi + if (check_identifier (parser, "clobber_abi")) + { + std::cout << "Clobber abi tee hee" << std::endl; + continue; + } + + // TODO: Parse options + if (check_identifier (parser, "options")) + { + std::cout << "Parse optoins" << std::endl; + continue; + } + + // Ok after we have check that neither clobber_abi nor options works, the + // only other logical choice is reg_operand + fm_string = parse_format_string (parser, last_token_id); + } + return tl::nullopt; +} + static tl::optional<AST::Fragment> parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, bool is_global_asm) @@ -171,26 +182,8 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, fm_string = parse_format_string (parser, last_token_id); } - // operands stream - token = parser.peek_current_token (); - while (token->get_id () != last_token_id) - { - std::cout << token->get_token_description () << std::endl; - - token = parser.peek_current_token (); - if (token->get_id () != COMMA) - { - break; - } - parser.skip_token (); - // Ok after the left paren is good, we better be parsing correctly - // everything in here, which is operand in ABNF - - // TODO: Work on parsing operands - fm_string = parse_format_string (parser, last_token_id); - } - - // TODO: Handle the optional "," + // operands stream, also handles the optional "," + parseAsmArg (parser, last_token_id, is_global_asm); return tl::nullopt; } diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h new file mode 100644 index 0000000..3a67c7e --- /dev/null +++ b/gcc/rust/expand/rust-macro-builtins-asm.h @@ -0,0 +1,87 @@ + +#include "rust-macro-builtins.h" +#include "rust-macro-builtins-helpers.h" +#include "rust-macro-invoc-lexer.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 +}; + +enum InlineAsmOptions +{ + +}; + +// 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::map<symbol_name, int> ClobberAbis; +typedef std::map<symbol_name, int> NamedValues; + +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> +parseAsmArg (Parser<MacroInvocLexer> &p, TokenId last_token_id, + bool is_global_asm); +static tl::optional<AST::Fragment> +parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc); +static tl::optional<AST::Fragment> +parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc); +static tl::optional<AST::Fragment> +parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, + bool is_global_asm); + +bool +check_identifier (Parser<MacroInvocLexer> &p, std::string ident); + +// From rustc +int +parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + AsmArg &args); + +// From rustc +int +parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + AsmArg &args, bool is_global_asm); + +// From rustc +tl::optional<InlineAsmRegOrRegClass> +parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, AsmArg &args, + bool is_explicit); +} // namespace Rust
\ No newline at end of file |