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>) [","] ")"
return -1;
}
- ClobberAbis new_abis;
+ std::vector<AST::TupleClobber> new_abis;
auto token = parser.peek_current_token ();
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
{
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
}
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))
{
{
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
{
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)
{
// 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>
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)
}
// operands stream, also handles the optional ","
- parseAsmArg (parser, last_token_id, is_global_asm);
+ parseAsmArg (parser, last_token_id, inlineAsm);
return tl::nullopt;
}
#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>
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