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)
241 .Case(
"ld_pseudo",
true)
242 .Case(
"store_release",
true)
247 static bool isValidIdInMiddle(StringRef Name) {
248 return StringSwitch<bool>(
Name.lower())
262 .Case(
"bswap16",
true)
263 .Case(
"bswap32",
true)
264 .Case(
"bswap64",
true)
269 .Case(
"atomic_fetch_add",
true)
270 .Case(
"atomic_fetch_and",
true)
271 .Case(
"atomic_fetch_or",
true)
272 .Case(
"atomic_fetch_xor",
true)
273 .Case(
"xchg_64",
true)
274 .Case(
"xchg32_32",
true)
275 .Case(
"cmpxchg_64",
true)
276 .Case(
"cmpxchg32_32",
true)
277 .Case(
"addr_space_cast",
true)
278 .Case(
"load_acquire",
true)
284#define GET_REGISTER_MATCHER
285#define GET_MATCHER_IMPLEMENTATION
286#include "BPFGenAsmMatcher.inc"
293 BPFOperand &Op0 = (BPFOperand &)*
Operands[0];
294 BPFOperand &Op1 = (BPFOperand &)*
Operands[1];
295 BPFOperand &Op2 = (BPFOperand &)*
Operands[2];
296 BPFOperand &Op3 = (BPFOperand &)*
Operands[3];
297 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
298 && Op1.getToken() ==
"="
299 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16"
300 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64"
301 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32"
302 || Op2.getToken() ==
"le64")
303 && Op0.getReg() != Op3.getReg())
310bool BPFAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
312 MCStreamer &Out,
uint64_t &ErrorInfo,
313 bool MatchingInlineAsm) {
318 return Error(IDLoc,
"additional inst constraint not met");
320 switch (MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
327 case Match_MissingFeature:
328 return Error(IDLoc,
"instruction use requires an option to be enabled");
329 case Match_MnemonicFail:
330 return Error(IDLoc,
"unrecognized instruction mnemonic");
331 case Match_InvalidOperand:
334 if (ErrorInfo != ~0U) {
336 return Error(ErrorLoc,
"too few operands for instruction");
338 ErrorLoc = ((BPFOperand &)*
Operands[ErrorInfo]).getStartLoc();
340 if (ErrorLoc == SMLoc())
344 return Error(ErrorLoc,
"invalid operand for instruction");
345 case Match_InvalidBrTarget:
347 "operand is not an identifier or 16-bit signed integer");
348 case Match_InvalidSImm16:
350 "operand is not a 16-bit signed integer");
351 case Match_InvalidTiedOperand:
353 "operand is not the same as the dst register");
359bool BPFAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
361 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
362 return Error(StartLoc,
"invalid register name");
366ParseStatus BPFAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
368 const AsmToken &Tok = getParser().getTok();
371 Reg = BPF::NoRegister;
372 StringRef
Name = getLexer().getTok().getIdentifier();
386 StringRef
Name = getLexer().getTok().getIdentifier();
388 if (BPFOperand::isValidIdInMiddle(Name)) {
390 Operands.push_back(BPFOperand::createToken(Name, S));
397 switch (getLexer().getKind()) {
418 StringRef
Name = getLexer().getTok().getString();
420 Operands.push_back(BPFOperand::createToken(Name, S));
431 Operands.push_back(BPFOperand::createToken(
432 getLexer().getTok().getString().
substr(0, 1), S));
433 Operands.push_back(BPFOperand::createToken(
434 getLexer().getTok().getString().
substr(1, 1), S));
451 switch (getLexer().getKind()) {
455 StringRef
Name = getLexer().getTok().getIdentifier();
468 switch (getLexer().getKind()) {
483 if (getParser().parseExpression(IdVal))
487 Operands.push_back(BPFOperand::createImm(IdVal, S,
E));
493bool BPFAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
500 Operands.push_back(BPFOperand::createReg(
Reg, NameLoc,
E));
501 }
else if (BPFOperand::isValidIdAtStart(Name))
502 Operands.push_back(BPFOperand::createToken(Name, NameLoc));
504 return Error(NameLoc,
"invalid register/token name");
508 if (parseOperandAsOperator(
Operands).isSuccess())
512 if (parseRegister(
Operands).isSuccess())
522 SMLoc Loc = getLexer().getLoc();
523 return Error(Loc,
"unexpected token");
528 SMLoc Loc = getLexer().getLoc();
530 getParser().eatToEndOfStatement();
532 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,...