32 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
36 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
39 bool MatchingInlineAsm)
override;
41 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
46 bool ParseDirective(
AsmToken DirectiveID)
override;
50 bool equalIsAsmAssignment()
override {
return false; }
53 bool starIsStartOfStatement()
override {
return true; }
55 #define GET_ASSEMBLER_HEADER 56 #include "BPFGenAsmMatcher.inc" 63 enum BPFMatchResultTy {
64 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
65 #define GET_OPERAND_DIAGNOSTIC_TYPES 66 #include "BPFGenAsmMatcher.inc" 67 #undef GET_OPERAND_DIAGNOSTIC_TYPES 73 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
95 SMLoc StartLoc, EndLoc;
107 StartLoc = o.StartLoc;
123 bool isToken()
const override {
return Kind == Token; }
125 bool isImm()
const override {
return Kind == Immediate; }
126 bool isMem()
const override {
return false; }
128 bool isConstantImm()
const {
132 int64_t getConstantImm()
const {
133 const MCExpr *Val = getImm();
137 bool isSImm12()
const {
138 return (isConstantImm() && isInt<12>(getConstantImm()));
142 SMLoc getStartLoc()
const override {
return StartLoc; }
144 SMLoc getEndLoc()
const override {
return EndLoc; }
146 unsigned getReg()
const override {
151 const MCExpr *getImm()
const {
152 assert(Kind == Immediate &&
"Invalid type access!");
157 assert(Kind == Token &&
"Invalid type access!");
177 assert(Expr &&
"Expr shouldn't be null!");
179 if (
auto *CE = dyn_cast<MCConstantExpr>(Expr))
186 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
187 assert(N == 1 &&
"Invalid number of operands!");
191 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
192 assert(N == 1 &&
"Invalid number of operands!");
193 addExpr(Inst, getImm());
196 static std::unique_ptr<BPFOperand> createToken(
StringRef Str,
SMLoc S) {
197 auto Op = make_unique<BPFOperand>(Token);
204 static std::unique_ptr<BPFOperand> createReg(
unsigned RegNo,
SMLoc S,
207 Op->Reg.RegNum = RegNo;
213 static std::unique_ptr<BPFOperand> createImm(
const MCExpr *Val,
SMLoc S,
215 auto Op = make_unique<BPFOperand>(Immediate);
231 .
Case(
"ld_pseudo",
true)
236 static bool isValidIdInMiddle(
StringRef Name) {
257 #define GET_REGISTER_MATCHER 258 #define GET_MATCHER_IMPLEMENTATION 259 #include "BPFGenAsmMatcher.inc" 263 if (Operands.
size() == 4) {
266 BPFOperand &Op0 = (BPFOperand &)*Operands[0];
267 BPFOperand &Op1 = (BPFOperand &)*Operands[1];
268 BPFOperand &Op2 = (BPFOperand &)*Operands[2];
269 BPFOperand &Op3 = (BPFOperand &)*Operands[3];
270 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
271 && Op1.getToken() ==
"=" 272 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16" 273 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64" 274 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32" 275 || Op2.getToken() ==
"le64")
276 && Op0.getReg() != Op3.getReg())
283 bool BPFAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
286 bool MatchingInlineAsm) {
290 if (PreMatchCheck(Operands))
291 return Error(IDLoc,
"additional inst constraint not met");
293 switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
300 case Match_MissingFeature:
301 return Error(IDLoc,
"instruction use requires an option to be enabled");
302 case Match_MnemonicFail:
303 return Error(IDLoc,
"unrecognized instruction mnemonic");
304 case Match_InvalidOperand:
307 if (ErrorInfo != ~0U) {
308 if (ErrorInfo >= Operands.
size())
309 return Error(ErrorLoc,
"too few operands for instruction");
311 ErrorLoc = ((BPFOperand &)*Operands[ErrorInfo]).getStartLoc();
313 if (ErrorLoc ==
SMLoc())
317 return Error(ErrorLoc,
"invalid operand for instruction");
323 bool BPFAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
325 const AsmToken &Tok = getParser().getTok();
336 return Error(StartLoc,
"invalid register name");
340 BPFAsmParser::parseOperandAsOperator(
OperandVector &Operands) {
346 if (BPFOperand::isValidIdInMiddle(Name)) {
348 Operands.
push_back(BPFOperand::createToken(Name, S));
355 switch (getLexer().getKind()) {
378 Operands.
push_back(BPFOperand::createToken(Name, S));
389 Operands.
push_back(BPFOperand::createToken(
390 getLexer().getTok().getString().substr(0, 1), S));
391 Operands.
push_back(BPFOperand::createToken(
392 getLexer().getTok().getString().substr(1, 1), S));
409 switch (getLexer().getKind()) {
420 Operands.
push_back(BPFOperand::createReg(RegNo, S, E));
426 switch (getLexer().getKind()) {
441 if (getParser().parseExpression(IdVal))
445 Operands.
push_back(BPFOperand::createImm(IdVal, S, E));
459 Operands.
push_back(BPFOperand::createReg(RegNo, NameLoc, E));
460 }
else if (BPFOperand::isValidIdAtStart (Name))
461 Operands.
push_back(BPFOperand::createToken(Name, NameLoc));
463 return Error(NameLoc,
"invalid register/token name");
476 SMLoc Loc = getLexer().getLoc();
477 return Error(Loc,
"unexpected token");
482 SMLoc Loc = getLexer().getLoc();
484 getParser().eatToEndOfStatement();
486 return Error(Loc,
"unexpected token");
494 bool BPFAsmParser::ParseDirective(
AsmToken DirectiveID) {
return true; }
static bool isReg(const MCInst &MI, unsigned OpNo)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
static unsigned MatchRegisterName(StringRef Name)
Generic assembler parser interface, for use by target specific assembly parsers.
static MCOperand createExpr(const MCExpr *Val)
MCTargetAsmParser - Generic interface to target specific assembly parsers.
void push_back(const T &Elt)
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static MCOperand createReg(unsigned Reg)
const FeatureBitset & getFeatureBits() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
Target independent representation for an assembler token.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
static bool isMem(const MachineInstr &MI, unsigned Op)
zlib-gnu style compression
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
Instances of this class represent a single low-level machine instruction.
Analysis containing CSE Info
const char * getPointer() const
A switch()-like statement whose cases are string literals.
Streaming machine code generation interface.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Interface to description of machine instruction set.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void LLVMInitializeBPFAsmParser()
Promote Memory to Register
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Base class for user error types.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
static SMLoc getFromPointer(const char *Ptr)
Generic base class for all target subtargets.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
LLVM_NODISCARD std::string lower() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Target & getTheBPFleTarget()
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
Target & getTheBPFbeTarget()
Represents a location in source code.
static MCOperand createImm(int64_t Val)
Target & getTheBPFTarget()
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)