#ifndef LLVM_MC_MCASMMACRO_H
#define LLVM_MC_MCASMMACRO_H
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/SMLoc.h"
#include <vector>
namespace llvm {
class AsmToken {
public:
enum TokenKind {
Eof, Error,
Identifier,
String,
Integer,
BigNum,
Real,
Comment,
HashDirective,
EndOfStatement,
Colon,
Space,
Plus, Minus, Tilde,
Slash, BackSlash, LParen, RParen, LBrac, RBrac, LCurly, RCurly,
Star, Dot, Comma, Dollar, Equal, EqualEqual,
Pipe, PipePipe, Caret,
Amp, AmpAmp, Exclaim, ExclaimEqual, Percent, Hash,
Less, LessEqual, LessLess, LessGreater,
Greater, GreaterEqual, GreaterGreater, At, MinusGreater,
PercentCall16, PercentCall_Hi, PercentCall_Lo, PercentDtprel_Hi,
PercentDtprel_Lo, PercentGot, PercentGot_Disp, PercentGot_Hi, PercentGot_Lo,
PercentGot_Ofst, PercentGot_Page, PercentGottprel, PercentGp_Rel, PercentHi,
PercentHigher, PercentHighest, PercentLo, PercentNeg, PercentPcrel_Hi,
PercentPcrel_Lo, PercentTlsgd, PercentTlsldm, PercentTprel_Hi,
PercentTprel_Lo
};
private:
TokenKind Kind;
StringRef Str;
APInt IntVal;
public:
AsmToken() = default;
AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
: Kind(Kind), Str(Str), IntVal(std::move(IntVal)) {}
AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal = 0)
: Kind(Kind), Str(Str), IntVal(64, IntVal, true) {}
TokenKind getKind() const { return Kind; }
bool is(TokenKind K) const { return Kind == K; }
bool isNot(TokenKind K) const { return Kind != K; }
SMLoc getLoc() const;
SMLoc getEndLoc() const;
SMRange getLocRange() const;
StringRef getStringContents() const {
assert(Kind == String && "This token isn't a string!");
return Str.slice(1, Str.size() - 1);
}
StringRef getIdentifier() const {
if (Kind == Identifier)
return getString();
return getStringContents();
}
StringRef getString() const { return Str; }
int64_t getIntVal() const {
assert(Kind == Integer && "This token isn't an integer!");
return IntVal.getZExtValue();
}
APInt getAPIntVal() const {
assert((Kind == Integer || Kind == BigNum) &&
"This token isn't an integer!");
return IntVal;
}
void dump(raw_ostream &OS) const;
};
struct MCAsmMacroParameter {
StringRef Name;
std::vector<AsmToken> Value;
bool Required = false;
bool Vararg = false;
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void dump() const { dump(dbgs()); }
LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
#endif
};
typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
struct MCAsmMacro {
StringRef Name;
StringRef Body;
MCAsmMacroParameters Parameters;
std::vector<std::string> Locals;
bool IsFunction = false;
public:
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
: Name(N), Body(B), Parameters(std::move(P)) {}
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P,
std::vector<std::string> L, bool F)
: Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)),
IsFunction(F) {}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void dump() const { dump(dbgs()); }
LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
#endif
};
}
#endif