File indexing completed on 2026-05-10 08:44:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_MC_MCASMMACRO_H
0010 #define LLVM_MC_MCASMMACRO_H
0011
0012 #include "llvm/ADT/APInt.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/Support/Debug.h"
0015 #include "llvm/Support/SMLoc.h"
0016 #include <vector>
0017
0018 namespace llvm {
0019
0020
0021 class AsmToken {
0022 public:
0023 enum TokenKind {
0024
0025 Eof, Error,
0026
0027
0028 Identifier,
0029 String,
0030
0031
0032 Integer,
0033 BigNum,
0034
0035
0036 Real,
0037
0038
0039 Comment,
0040 HashDirective,
0041
0042 EndOfStatement,
0043 Colon,
0044 Space,
0045 Plus, Minus, Tilde,
0046 Slash,
0047 BackSlash,
0048 LParen, RParen, LBrac, RBrac, LCurly, RCurly,
0049 Question, Star, Dot, Comma, Dollar, Equal, EqualEqual,
0050
0051 Pipe, PipePipe, Caret,
0052 Amp, AmpAmp, Exclaim, ExclaimEqual, Percent, Hash,
0053 Less, LessEqual, LessLess, LessGreater,
0054 Greater, GreaterEqual, GreaterGreater, At, MinusGreater,
0055
0056
0057 PercentCall16, PercentCall_Hi, PercentCall_Lo, PercentDtprel_Hi,
0058 PercentDtprel_Lo, PercentGot, PercentGot_Disp, PercentGot_Hi, PercentGot_Lo,
0059 PercentGot_Ofst, PercentGot_Page, PercentGottprel, PercentGp_Rel, PercentHi,
0060 PercentHigher, PercentHighest, PercentLo, PercentNeg, PercentPcrel_Hi,
0061 PercentPcrel_Lo, PercentTlsgd, PercentTlsldm, PercentTprel_Hi,
0062 PercentTprel_Lo
0063 };
0064
0065 private:
0066 TokenKind Kind = TokenKind::Eof;
0067
0068
0069
0070 StringRef Str;
0071
0072 APInt IntVal;
0073
0074 public:
0075 AsmToken() = default;
0076 AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
0077 : Kind(Kind), Str(Str), IntVal(std::move(IntVal)) {}
0078 AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal = 0)
0079 : Kind(Kind), Str(Str), IntVal(64, IntVal, true) {}
0080
0081 TokenKind getKind() const { return Kind; }
0082 bool is(TokenKind K) const { return Kind == K; }
0083 bool isNot(TokenKind K) const { return Kind != K; }
0084
0085 SMLoc getLoc() const;
0086 SMLoc getEndLoc() const;
0087 SMRange getLocRange() const;
0088
0089
0090 StringRef getStringContents() const {
0091 assert(Kind == String && "This token isn't a string!");
0092 return Str.slice(1, Str.size() - 1);
0093 }
0094
0095
0096
0097
0098
0099 StringRef getIdentifier() const {
0100 if (Kind == Identifier)
0101 return getString();
0102 return getStringContents();
0103 }
0104
0105
0106
0107
0108
0109
0110 StringRef getString() const { return Str; }
0111
0112
0113
0114
0115 int64_t getIntVal() const {
0116 assert(Kind == Integer && "This token isn't an integer!");
0117 return IntVal.getZExtValue();
0118 }
0119
0120 APInt getAPIntVal() const {
0121 assert((Kind == Integer || Kind == BigNum) &&
0122 "This token isn't an integer!");
0123 return IntVal;
0124 }
0125
0126 void dump(raw_ostream &OS) const;
0127 };
0128
0129 struct MCAsmMacroParameter {
0130 StringRef Name;
0131 std::vector<AsmToken> Value;
0132 bool Required = false;
0133 bool Vararg = false;
0134
0135 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0136 void dump() const { dump(dbgs()); }
0137 LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
0138 #endif
0139 };
0140
0141 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
0142 struct MCAsmMacro {
0143 StringRef Name;
0144 StringRef Body;
0145 MCAsmMacroParameters Parameters;
0146 std::vector<std::string> Locals;
0147 bool IsFunction = false;
0148 unsigned Count = 0;
0149
0150 public:
0151 MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
0152 : Name(N), Body(B), Parameters(std::move(P)) {}
0153 MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P,
0154 std::vector<std::string> L, bool F)
0155 : Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)),
0156 IsFunction(F) {}
0157
0158 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0159 void dump() const { dump(dbgs()); }
0160 LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
0161 #endif
0162 };
0163 }
0164
0165 #endif