34 SMLoc getLoc()
const {
return getParser().
getTok().
getLoc(); }
38 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
41 bool MatchingInlineAsm)
override;
43 bool parseRegister(MCRegister &Reo, SMLoc &StartLoc, SMLoc &EndLoc)
override;
44 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
45 SMLoc &EndLoc)
override;
47 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
52 bool equalIsAsmAssignment()
override {
return false; }
59#define GET_ASSEMBLER_HEADER
60#include "BPFGenAsmMatcher.inc"
67 enum BPFMatchResultTy {
68 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
69#define GET_OPERAND_DIAGNOSTIC_TYPES
70#include "BPFGenAsmMatcher.inc"
71#undef GET_OPERAND_DIAGNOSTIC_TYPES
74 BPFAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
75 const MCInstrInfo &MII)
76 : MCTargetAsmParser(STI, MII) {
77 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
99 SMLoc StartLoc, EndLoc;
106 BPFOperand(KindTy K) : Kind(
K) {}
109 BPFOperand(
const BPFOperand &o) : MCParsedAsmOperand() {
111 StartLoc =
o.StartLoc;
127 bool isToken()
const override {
return Kind == Token; }
128 bool isReg()
const override {
return Kind == Register; }
129 bool isImm()
const override {
return Kind == Immediate; }
130 bool isMem()
const override {
return false; }
132 bool isConstantImm()
const {
136 int64_t getConstantImm()
const {
137 const MCExpr *Val =
getImm();
138 return static_cast<const MCConstantExpr *
>(Val)->
getValue();
141 bool isSImm16()
const {
142 return (isConstantImm() &&
isInt<16>(getConstantImm()));
147 bool isBrTarget()
const {
return isSymbolRef() || isSImm16(); }
150 SMLoc getStartLoc()
const override {
return StartLoc; }
152 SMLoc getEndLoc()
const override {
return EndLoc; }
154 MCRegister
getReg()
const override {
155 assert(Kind == Register &&
"Invalid type access!");
159 const MCExpr *
getImm()
const {
160 assert(Kind == Immediate &&
"Invalid type access!");
165 assert(Kind == Token &&
"Invalid type access!");
169 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
184 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
185 assert(Expr &&
"Expr shouldn't be null!");
194 void addRegOperands(MCInst &Inst,
unsigned N)
const {
195 assert(
N == 1 &&
"Invalid number of operands!");
199 void addImmOperands(MCInst &Inst,
unsigned N)
const {
200 assert(
N == 1 &&
"Invalid number of operands!");
204 static std::unique_ptr<BPFOperand> createToken(StringRef Str, SMLoc S) {
205 auto Op = std::make_unique<BPFOperand>(Token);
212 static std::unique_ptr<BPFOperand> createReg(MCRegister
Reg, SMLoc S,
214 auto Op = std::make_unique<BPFOperand>(Register);
215 Op->Reg.RegNum =
Reg;
221 static std::unique_ptr<BPFOperand> createImm(
const MCExpr *Val, SMLoc S,
223 auto Op = std::make_unique<BPFOperand>(Immediate);
231 static bool isValidIdAtStart(StringRef Name) {
232 return StringSwitch<bool>(
Name.lower())
239 .Case(
"may_goto",
true)
243 .Case(
"ld_pseudo",
true)
244 .Case(
"store_release",
true)
249 static bool isValidIdInMiddle(StringRef Name) {
250 return StringSwitch<bool>(
Name.lower())
264 .Case(
"bswap16",
true)
265 .Case(
"bswap32",
true)
266 .Case(
"bswap64",
true)
271 .Case(
"atomic_fetch_add",
true)
272 .Case(
"atomic_fetch_and",
true)
273 .Case(
"atomic_fetch_or",
true)
274 .Case(
"atomic_fetch_xor",
true)
275 .Case(
"xchg_64",
true)
276 .Case(
"xchg32_32",
true)
277 .Case(
"cmpxchg_64",
true)
278 .Case(
"cmpxchg32_32",
true)
279 .Case(
"addr_space_cast",
true)
280 .Case(
"load_acquire",
true)
286#define GET_REGISTER_MATCHER
287#define GET_MATCHER_IMPLEMENTATION
288#include "BPFGenAsmMatcher.inc"
295 BPFOperand &Op0 = (BPFOperand &)*
Operands[0];
296 BPFOperand &Op1 = (BPFOperand &)*
Operands[1];
297 BPFOperand &Op2 = (BPFOperand &)*
Operands[2];
298 BPFOperand &Op3 = (BPFOperand &)*
Operands[3];
299 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
300 && Op1.getToken() ==
"="
301 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16"
302 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64"
303 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32"
304 || Op2.getToken() ==
"le64")
305 && Op0.getReg() != Op3.getReg())
312bool BPFAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
314 MCStreamer &Out, uint64_t &ErrorInfo,
315 bool MatchingInlineAsm) {
320 return Error(IDLoc,
"additional inst constraint not met");
322 switch (MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
329 case Match_MissingFeature:
330 return Error(IDLoc,
"instruction use requires an option to be enabled");
331 case Match_MnemonicFail:
332 return Error(IDLoc,
"unrecognized instruction mnemonic");
333 case Match_InvalidOperand:
336 if (ErrorInfo != ~0U) {
338 return Error(ErrorLoc,
"too few operands for instruction");
340 ErrorLoc = ((BPFOperand &)*
Operands[ErrorInfo]).getStartLoc();
342 if (ErrorLoc == SMLoc())
346 return Error(ErrorLoc,
"invalid operand for instruction");
347 case Match_InvalidBrTarget:
349 "operand is not an identifier or 16-bit signed integer");
350 case Match_InvalidSImm16:
352 "operand is not a 16-bit signed integer");
353 case Match_InvalidTiedOperand:
355 "operand is not the same as the dst register");
361bool BPFAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
363 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
364 return Error(StartLoc,
"invalid register name");
368ParseStatus BPFAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
370 const AsmToken &Tok = getParser().getTok();
373 Reg = BPF::NoRegister;
374 StringRef
Name = getLexer().getTok().getIdentifier();
388 StringRef
Name = getLexer().getTok().getIdentifier();
390 if (BPFOperand::isValidIdInMiddle(Name)) {
392 Operands.push_back(BPFOperand::createToken(Name, S));
399 switch (getLexer().getKind()) {
420 StringRef
Name = getLexer().getTok().getString();
422 Operands.push_back(BPFOperand::createToken(Name, S));
433 Operands.push_back(BPFOperand::createToken(
434 getLexer().getTok().getString().
substr(0, 1), S));
435 Operands.push_back(BPFOperand::createToken(
436 getLexer().getTok().getString().
substr(1, 1), S));
453 switch (getLexer().getKind()) {
457 StringRef
Name = getLexer().getTok().getIdentifier();
470 switch (getLexer().getKind()) {
485 if (getParser().parseExpression(IdVal))
489 Operands.push_back(BPFOperand::createImm(IdVal, S,
E));
495bool BPFAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
502 Operands.push_back(BPFOperand::createReg(
Reg, NameLoc,
E));
503 }
else if (BPFOperand::isValidIdAtStart(Name))
504 Operands.push_back(BPFOperand::createToken(Name, NameLoc));
506 return Error(NameLoc,
"invalid register/token name");
510 if (parseOperandAsOperator(
Operands).isSuccess())
514 if (parseRegister(
Operands).isSuccess())
524 SMLoc Loc = getLexer().getLoc();
525 return Error(Loc,
"unexpected token");
530 SMLoc Loc = getLexer().getLoc();
532 getParser().eatToEndOfStatement();
534 return Error(Loc,
"unexpected token");
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFAsmParser()
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
static constexpr Value * getValue(Ty &ValueOrUse)
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static StringRef substr(StringRef Str, uint64_t Len)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
LLVM_ABI SMLoc getLoc() const
LLVM_ABI SMLoc getEndLoc() const
void printExpr(raw_ostream &, const MCExpr &) const
const AsmToken & getTok()
void addOperand(const MCOperand Op)
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
constexpr unsigned id() const
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
const FeatureBitset & getFeatureBits() const
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Ternary parse status returned by various parse* methods.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CE
Windows NT (Windows on ARM)
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Target & getTheBPFleTarget()
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
Target & getTheBPFbeTarget()
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Target & getTheBPFTarget()
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...