aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-builtins-asm.h
blob: 1ed3148e5720fafa2a3cc7b76b0e9090661f3379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

#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 {
// 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.

class InlineAsmContext
{
public:
  bool allow_templates;
  bool is_explicit;
  bool consumed_comma_without_formatted_string;
  AST::InlineAsm &inline_asm;
  InlineAsmContext (AST::InlineAsm &inline_asm)
    : allow_templates (true), is_explicit (false),
      consumed_comma_without_formatted_string (false), inline_asm (inline_asm)
  {}

  bool is_global_asm () { return inline_asm.is_global_asm; }

  bool allows_templates () { return allow_templates; }

  void set_allow_templates (bool allow_templates)
  {
    this->allow_templates = allow_templates;
  }
};

int
parse_asm_arg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
	       InlineAsmContext &inline_asm_ctx);

tl::optional<AST::Fragment>
parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
	   bool is_global_asm);

bool
check_identifier (Parser<MacroInvocLexer> &parser, std::string ident);

void
check_and_set (Parser<MacroInvocLexer> &parser,
	       InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option);
// From rustc
int
parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
	       InlineAsmContext &inline_asm_ctx);

// From rustc
tl::optional<AST::InlineAsmOperand>
parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
		   InlineAsmContext &inline_asm_ctx);

// From rustc
int
parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
	       InlineAsmContext &inline_asm_ctx);

// From rustc
tl::optional<AST::InlineAsmRegOrRegClass>
parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
	   InlineAsmContext &inline_asm_ctx);

int
parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
		   InlineAsmContext &inline_asm_ctx);

tl::optional<std::string>
parse_format_string (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
		     InlineAsmContext &inline_asm_ctx);

std::set<std::string> potentially_nonpromoted_keywords
  = {"in", "out", "lateout", "inout", "inlateout", "const", "sym", "label"};

} // namespace Rust