33#define DEBUG_TYPE "xtensa-asm-parser"
40 enum XtensaRegisterType { Xtensa_Generic, Xtensa_SR, Xtensa_UR };
52 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
55 bool MatchingInlineAsm)
override;
57 unsigned Kind)
override;
63#define GET_ASSEMBLER_HEADER
64#include "XtensaGenAsmMatcher.inc"
69 XtensaRegisterType SR = Xtensa_Generic,
74 XtensaRegisterType SR = Xtensa_Generic,
79 SMLoc &EndLoc)
override {
84 bool parseLiteralDirective(SMLoc L);
89#define GET_OPERAND_DIAGNOSTIC_TYPES
90#include "XtensaGenAsmMatcher.inc"
91#undef GET_OPERAND_DIAGNOSTIC_TYPES
107static bool inRange(
const MCExpr *Expr, int64_t MinValue, int64_t MaxValue) {
109 int64_t
Value = CE->getValue();
110 return Value >= MinValue &&
Value <= MaxValue;
161 bool isMem()
const override {
return false; }
163 bool isImm(int64_t MinValue, int64_t MaxValue)
const {
170 return isImm(-32768, 32512) &&
180 return isImm(0, 60) &&
187 return isImm(0, 510) &&
192 return isImm(0, 1020) &&
197 return isImm(0, 32760) &&
219 return isImm(-64, -4) &&
227 int64_t
Value = CE->getValue();
257 int64_t
Value = CE->getValue();
321 auto Op = std::make_unique<XtensaOperand>(
Token);
330 auto Op = std::make_unique<XtensaOperand>(
Register);
331 Op->Reg.RegNum = RegNo;
339 auto Op = std::make_unique<XtensaOperand>(
Immediate);
347 assert(Expr &&
"Expr shouldn't be null!");
349 bool IsConstant =
false;
353 Imm = CE->getValue();
364 assert(
N == 1 &&
"Invalid number of operands!");
369 assert(
N == 1 &&
"Invalid number of operands!");
374#define GET_REGISTER_MATCHER
375#define GET_MATCHER_IMPLEMENTATION
376#include "XtensaGenAsmMatcher.inc"
387 if (ErrorLoc ==
SMLoc())
394bool XtensaAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
398 const unsigned Opcode = Inst.
getOpcode();
401 const MCSymbolRefExpr *OpExpr =
407 XtensaTargetStreamer &TS = this->getTargetStreamer();
412 int32_t
Imm = ImmOp64;
414 XtensaTargetStreamer &TS = this->getTargetStreamer();
449bool XtensaAsmParser::matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
453 bool MatchingInlineAsm) {
456 MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm);
462 processInstruction(Inst, IDLoc, Out,
STI);
467 return Error(IDLoc,
"instruction use requires an option to be enabled");
469 return Error(IDLoc,
"unrecognized instruction mnemonic");
471 SMLoc ErrorLoc = IDLoc;
472 if (ErrorInfo != ~0U) {
474 return Error(ErrorLoc,
"too few operands for instruction");
476 ErrorLoc = ((XtensaOperand &)*
Operands[ErrorInfo]).getStartLoc();
477 if (ErrorLoc == SMLoc())
480 return Error(ErrorLoc,
"invalid operand for instruction");
482 case Match_InvalidImm8:
484 "expected immediate in range [-128, 127]");
485 case Match_InvalidImm8_sh8:
487 "expected immediate in range [-32768, 32512], first 8 bits "
489 case Match_InvalidB4const:
491 "expected b4const immediate");
492 case Match_InvalidB4constu:
494 "expected b4constu immediate");
495 case Match_InvalidImm12:
497 "expected immediate in range [-2048, 2047]");
498 case Match_InvalidImm12m:
500 "expected immediate in range [-2048, 2047]");
501 case Match_InvalidImm1_16:
503 "expected immediate in range [1, 16]");
504 case Match_InvalidImm1n_15:
506 "expected immediate in range [-1, 15] except 0");
507 case Match_InvalidImm32n_95:
509 "expected immediate in range [-32, 95]");
510 case Match_InvalidImm64n_4n:
512 "expected immediate in range [-64, -4]");
513 case Match_InvalidImm8n_7:
515 "expected immediate in range [-8, 7]");
516 case Match_InvalidShimm1_31:
518 "expected immediate in range [1, 31]");
519 case Match_InvalidUimm4:
521 "expected immediate in range [0, 15]");
522 case Match_InvalidUimm5:
524 "expected immediate in range [0, 31]");
525 case Match_InvalidOffset8m8:
527 "expected immediate in range [0, 255]");
528 case Match_InvalidOffset8m16:
530 "expected immediate in range [0, 510], first bit "
532 case Match_InvalidOffset8m32:
534 "expected immediate in range [0, 1020], first 2 bits "
536 case Match_InvalidOffset4m32:
538 "expected immediate in range [0, 60], first 2 bits "
540 case Match_Invalidentry_imm12:
542 "expected immediate in range [0, 32760], first 3 bits "
544 case Match_Invalidimm7_22:
546 "expected immediate in range [7, 22]");
559 const MCExpr *Expr =
nullptr;
560 if (Parser.parseExpression(Expr)) {
566 if (Expr->
getKind() == MCExpr::ExprKind::Constant)
567 return Error(getLoc(),
"unknown operand");
578 Reg = Xtensa::NoRegister;
586 return Error(StartLoc,
"invalid register name");
591 XtensaRegisterType RegType,
593 SMLoc FirstS = getLoc();
594 bool HadParens =
false;
609 MCRegister RegNo = 0;
615 if (RegType == Xtensa_Generic)
621 if (RegType == Xtensa_UR) {
680 if (
getParser().parseIdentifier(Identifier))
688 return parseOperandWithModifier(
Operands);
704 XtensaRegisterType RegType,
708 ParseStatus Res = MatchOperandParserImpl(
Operands, Mnemonic);
719 if (parseRegister(
Operands,
true, RegType, RAType).isSuccess())
723 if (parseImmediate(
Operands).isSuccess())
727 return Error(getLoc(),
"unknown operand");
738 if ((
Name.size() > 4) && Name[3] ==
'.') {
752 return Error(NameLoc,
"invalid register name");
772 return Error(Loc,
"unexpected token");
776 if (parseOperand(
Operands, Name, Name[1] ==
's' ? Xtensa_SR : Xtensa_UR,
784 return Error(Loc,
"unexpected token");
794 if (
Name.starts_with(
"wsr") ||
Name.starts_with(
"rsr") ||
795 Name.starts_with(
"xsr") ||
Name.starts_with(
"rur") ||
796 Name.starts_with(
"wur")) {
797 return ParseInstructionWithSR(
Info, Name, NameLoc,
Operands);
819 return Error(Loc,
"unexpected token");
826bool XtensaAsmParser::parseLiteralDirective(
SMLoc L) {
830 XtensaTargetStreamer &TS = this->getTargetStreamer();
832 if (Parser.parseExpression(
Value))
838 return Error(LiteralLoc,
"literal label must be a symbol");
840 if (Parser.parseComma())
845 return Error(OpcodeLoc,
"expected value");
847 if (Parser.parseExpression(
Value))
861 StringRef IDVal = DirectiveID.
getString();
864 if (IDVal ==
".literal_position") {
865 XtensaTargetStreamer &TS = this->getTargetStreamer();
870 if (IDVal ==
".literal") {
871 return parseLiteralDirective(Loc);
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static MCRegister MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
#define LLVM_EXTERNAL_VISIBILITY
mir Rename Register Operands
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
static bool inRange(const MCExpr *Expr, int64_t MinValue, int64_t MaxValue)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXtensaAsmParser()
static SMLoc RefineErrorLoc(const SMLoc Loc, const OperandVector &Operands, uint64_t ErrorInfo)
XtensaAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options)
SMLoc getLoc() const
Get the current source location.
void UnLex(AsmToken const &Token)
const AsmToken & getTok() const
Get the current (last) lexed token.
const AsmToken & Lex()
Consume the next token from the input stream and return it.
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
int64_t getIntVal() const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Base class for user error types.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void printExpr(raw_ostream &, const MCExpr &) const
bool parseOptionalToken(AsmToken::TokenKind T)
MCAsmParser & getParser()
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
MCStreamer & getStreamer()
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Interface to description of machine instruction set.
static MCOperand createExpr(const MCExpr *Val)
void setExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
MCParsedAsmOperand()=default
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Streaming machine code generation interface.
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
MCTargetStreamer * getTargetStreamer()
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
StringRef getName() const
getName - Get the symbol name.
@ FIRST_TARGET_MATCH_RESULT_TY
MCTargetAsmParser(MCTargetOptions const &, const MCSubtargetInfo &STI, const MCInstrInfo &MII)
void setAvailableFeatures(const FeatureBitset &Value)
const MCSubtargetInfo & getSTI() const
const MCSubtargetInfo * STI
Current STI.
Target specific streamer interface.
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
virtual void emitLiteralPosition()=0
virtual void emitLiteral(MCSymbol *LblSym, const MCExpr *Value, bool SwitchLiteralSection, SMLoc L=SMLoc())=0
This class implements an extremely fast bulk output stream that can only output to a stream.
MCExpr const & getExpr(MCExpr const &Expr)
bool checkRegister(MCRegister RegNo, const FeatureBitset &FeatureBits, RegisterAccessType RA)
MCRegister getUserRegister(unsigned Code, const MCRegisterInfo &MRI)
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Target & getTheXtensaTarget()
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool isOffset4m32() const
bool isOffset8m16() const
static std::unique_ptr< XtensaOperand > createToken(StringRef Str, SMLoc S)
void addRegOperands(MCInst &Inst, unsigned N) const
void addExpr(MCInst &Inst, const MCExpr *Expr) const
void addImmOperands(MCInst &Inst, unsigned N) const
StringRef getToken() const
enum XtensaOperand::KindTy Kind
bool isMem() const override
isMem - Is this a memory operand?
bool isToken() const override
isToken - Is this a token operand?
MCRegister getReg() const override
SMLoc getStartLoc() const override
getStartLoc - Gets location of the first token of this operand
bool isImm(int64_t MinValue, int64_t MaxValue) const
bool isReg() const override
isReg - Is this a register operand?
bool isImm() const override
isImm - Is this an immediate operand?
bool isentry_imm12() const
static std::unique_ptr< XtensaOperand > createReg(unsigned RegNo, SMLoc S, SMLoc E)
SMLoc getEndLoc() const override
getEndLoc - Gets location of the last token of this operand
const MCExpr * getImm() const
void print(raw_ostream &OS, const MCAsmInfo &MAI) const override
print - Print a debug representation of the operand to the given stream.
XtensaOperand(const XtensaOperand &o)
static std::unique_ptr< XtensaOperand > createImm(const MCExpr *Val, SMLoc S, SMLoc E)
bool isOffset8m32() const
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...