32 SMLoc getLoc()
const {
return getParser().
getTok().
getLoc(); }
36 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
39 bool MatchingInlineAsm)
override;
41 bool parseRegister(MCRegister &Reo, SMLoc &StartLoc, SMLoc &EndLoc)
override;
42 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
43 SMLoc &EndLoc)
override;
45 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
50 bool equalIsAsmAssignment()
override {
return false; }
57#define GET_ASSEMBLER_HEADER
58#include "BPFGenAsmMatcher.inc"
65 enum BPFMatchResultTy {
66 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
67#define GET_OPERAND_DIAGNOSTIC_TYPES
68#include "BPFGenAsmMatcher.inc"
69#undef GET_OPERAND_DIAGNOSTIC_TYPES
72 BPFAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
73 const MCInstrInfo &MII)
74 : MCTargetAsmParser(STI, MII) {
75 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
97 SMLoc StartLoc, EndLoc;
104 BPFOperand(KindTy K) : Kind(
K) {}
107 BPFOperand(
const BPFOperand &o) : MCParsedAsmOperand() {
109 StartLoc =
o.StartLoc;
125 bool isToken()
const override {
return Kind == Token; }
126 bool isReg()
const override {
return Kind == Register; }
127 bool isImm()
const override {
return Kind == Immediate; }
128 bool isMem()
const override {
return false; }
130 bool isConstantImm()
const {
134 int64_t getConstantImm()
const {
135 const MCExpr *Val =
getImm();
136 return static_cast<const MCConstantExpr *
>(Val)->
getValue();
139 bool isSImm16()
const {
140 return (isConstantImm() &&
isInt<16>(getConstantImm()));
145 bool isBrTarget()
const {
return isSymbolRef() || isSImm16(); }
148 SMLoc getStartLoc()
const override {
return StartLoc; }
150 SMLoc getEndLoc()
const override {
return EndLoc; }
152 MCRegister
getReg()
const override {
153 assert(Kind == Register &&
"Invalid type access!");
157 const MCExpr *
getImm()
const {
158 assert(Kind == Immediate &&
"Invalid type access!");
163 assert(Kind == Token &&
"Invalid type access!");
167 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
182 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
183 assert(Expr &&
"Expr shouldn't be null!");
192 void addRegOperands(MCInst &Inst,
unsigned N)
const {
193 assert(
N == 1 &&
"Invalid number of operands!");
197 void addImmOperands(MCInst &Inst,
unsigned N)
const {
198 assert(
N == 1 &&
"Invalid number of operands!");
202 static std::unique_ptr<BPFOperand> createToken(StringRef Str, SMLoc S) {
203 auto Op = std::make_unique<BPFOperand>(Token);
210 static std::unique_ptr<BPFOperand> createReg(MCRegister
Reg, SMLoc S,
212 auto Op = std::make_unique<BPFOperand>(Register);
213 Op->Reg.RegNum =
Reg;
219 static std::unique_ptr<BPFOperand> createImm(
const MCExpr *Val, SMLoc S,
221 auto Op = std::make_unique<BPFOperand>(Immediate);
229 static bool isValidIdAtStart(StringRef Name) {
230 return StringSwitch<bool>(
Name.lower())
237 .Case(
"may_goto",
true)
238 .Case(
"unwind_goto",
true)
241 .Case(
"unwind_exit",
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)
273 .Case(
"atomic_fetch_add",
true)
274 .Case(
"atomic_fetch_and",
true)
275 .Case(
"atomic_fetch_or",
true)
276 .Case(
"atomic_fetch_xor",
true)
277 .Case(
"xchg_64",
true)
278 .Case(
"xchg32_32",
true)
279 .Case(
"cmpxchg_64",
true)
280 .Case(
"cmpxchg32_32",
true)
281 .Case(
"addr_space_cast",
true)
282 .Case(
"load_acquire",
true)
288#define GET_REGISTER_MATCHER
289#define GET_MATCHER_IMPLEMENTATION
290#include "BPFGenAsmMatcher.inc"
297 BPFOperand &Op0 = (BPFOperand &)*
Operands[0];
298 BPFOperand &Op1 = (BPFOperand &)*
Operands[1];
299 BPFOperand &Op2 = (BPFOperand &)*
Operands[2];
300 BPFOperand &Op3 = (BPFOperand &)*
Operands[3];
301 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
302 && Op1.getToken() ==
"="
303 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16"
304 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64"
305 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32"
306 || Op2.getToken() ==
"le64")
307 && Op0.getReg() != Op3.getReg())
314bool BPFAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
316 MCStreamer &Out,
uint64_t &ErrorInfo,
317 bool MatchingInlineAsm) {
322 return Error(IDLoc,
"additional inst constraint not met");
324 switch (MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
329 Out.emitInstruction(Inst, getSTI());
331 case Match_MissingFeature:
332 return Error(IDLoc,
"instruction use requires an option to be enabled");
333 case Match_MnemonicFail:
334 return Error(IDLoc,
"unrecognized instruction mnemonic");
335 case Match_InvalidOperand:
338 if (ErrorInfo != ~0U) {
340 return Error(ErrorLoc,
"too few operands for instruction");
342 ErrorLoc = ((BPFOperand &)*
Operands[ErrorInfo]).getStartLoc();
344 if (ErrorLoc == SMLoc())
348 return Error(ErrorLoc,
"invalid operand for instruction");
349 case Match_InvalidBrTarget:
351 "operand is not an identifier or 16-bit signed integer");
352 case Match_InvalidSImm16:
354 "operand is not a 16-bit signed integer");
355 case Match_InvalidTiedOperand:
357 "operand is not the same as the dst register");
363bool BPFAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
365 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
366 return Error(StartLoc,
"invalid register name");
370ParseStatus BPFAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
372 const AsmToken &Tok = getParser().getTok();
375 Reg = BPF::NoRegister;
376 StringRef
Name = getLexer().getTok().getIdentifier();
390 StringRef
Name = getLexer().getTok().getIdentifier();
392 if (BPFOperand::isValidIdInMiddle(Name)) {
394 Operands.push_back(BPFOperand::createToken(Name, S));
401 switch (getLexer().getKind()) {
422 StringRef
Name = getLexer().getTok().getString();
424 Operands.push_back(BPFOperand::createToken(Name, S));
435 Operands.push_back(BPFOperand::createToken(
436 getLexer().getTok().getString().
substr(0, 1), S));
437 Operands.push_back(BPFOperand::createToken(
438 getLexer().getTok().getString().
substr(1, 1), S));
455 switch (getLexer().getKind()) {
459 StringRef
Name = getLexer().getTok().getIdentifier();
472 switch (getLexer().getKind()) {
487 if (getParser().parseExpression(IdVal))
491 Operands.push_back(BPFOperand::createImm(IdVal, S,
E));
497bool BPFAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
504 Operands.push_back(BPFOperand::createReg(
Reg, NameLoc,
E));
505 }
else if (BPFOperand::isValidIdAtStart(Name))
506 Operands.push_back(BPFOperand::createToken(Name, NameLoc));
508 return Error(NameLoc,
"invalid register/token name");
512 if (parseOperandAsOperator(
Operands).isSuccess())
516 if (parseRegister(
Operands).isSuccess())
526 SMLoc Loc = getLexer().getLoc();
527 return Error(Loc,
"unexpected token");
532 SMLoc Loc = getLexer().getLoc();
534 getParser().eatToEndOfStatement();
536 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
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,...