33#define DEBUG_TYPE "xtensa-asm-parser"
40 enum XtensaRegisterType { Xtensa_Generic, Xtensa_SR, Xtensa_UR };
45 "do not have a target streamer");
54 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
57 bool MatchingInlineAsm)
override;
59 unsigned Kind)
override;
65#define GET_ASSEMBLER_HEADER
66#include "XtensaGenAsmMatcher.inc"
70 parseRegister(
OperandVector &Operands,
bool AllowParens =
false,
71 XtensaRegisterType SR = Xtensa_Generic,
76 XtensaRegisterType SR = Xtensa_Generic,
81 SMLoc &EndLoc)
override {
86 bool parseLiteralDirective(SMLoc L);
91#define GET_OPERAND_DIAGNOSTIC_TYPES
92#include "XtensaGenAsmMatcher.inc"
93#undef GET_OPERAND_DIAGNOSTIC_TYPES
109static bool inRange(
const MCExpr *Expr, int64_t MinValue, int64_t MaxValue) {
111 int64_t
Value = CE->getValue();
112 return Value >= MinValue &&
Value <= MaxValue;
163 bool isMem()
const override {
return false; }
165 bool isImm(int64_t MinValue, int64_t MaxValue)
const {
172 return isImm(-32768, 32512) &&
182 return isImm(0, 60) &&
189 return isImm(0, 510) &&
194 return isImm(0, 1020) &&
199 return isImm(0, 32760) &&
221 return isImm(-64, -4) &&
229 int64_t
Value = CE->getValue();
259 int64_t
Value = CE->getValue();
325 auto Op = std::make_unique<XtensaOperand>(
Token);
334 auto Op = std::make_unique<XtensaOperand>(
Register);
335 Op->Reg.RegNum = RegNo;
343 auto Op = std::make_unique<XtensaOperand>(
Immediate);
351 assert(Expr &&
"Expr shouldn't be null!");
353 bool IsConstant =
false;
357 Imm = CE->getValue();
368 assert(
N == 1 &&
"Invalid number of operands!");
373 assert(
N == 1 &&
"Invalid number of operands!");
378#define GET_REGISTER_MATCHER
379#define GET_MATCHER_IMPLEMENTATION
380#include "XtensaGenAsmMatcher.inc"
391 if (ErrorLoc ==
SMLoc())
398bool XtensaAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
402 const unsigned Opcode = Inst.
getOpcode();
405 const MCSymbolRefExpr *OpExpr =
411 XtensaTargetStreamer &TS = this->getTargetStreamer();
416 int32_t
Imm = ImmOp64;
418 XtensaTargetStreamer &TS = this->getTargetStreamer();
453bool XtensaAsmParser::matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
457 bool MatchingInlineAsm) {
460 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
466 processInstruction(Inst, IDLoc, Out,
STI);
471 return Error(IDLoc,
"instruction use requires an option to be enabled");
473 return Error(IDLoc,
"unrecognized instruction mnemonic");
475 SMLoc ErrorLoc = IDLoc;
476 if (ErrorInfo != ~0U) {
477 if (ErrorInfo >= Operands.
size())
478 return Error(ErrorLoc,
"too few operands for instruction");
480 ErrorLoc = ((XtensaOperand &)*Operands[ErrorInfo]).getStartLoc();
481 if (ErrorLoc == SMLoc())
484 return Error(ErrorLoc,
"invalid operand for instruction");
486 case Match_InvalidImm8:
488 "expected immediate in range [-128, 127]");
489 case Match_InvalidImm8_sh8:
491 "expected immediate in range [-32768, 32512], first 8 bits "
493 case Match_InvalidB4const:
495 "expected b4const immediate");
496 case Match_InvalidB4constu:
498 "expected b4constu immediate");
499 case Match_InvalidImm12:
501 "expected immediate in range [-2048, 2047]");
502 case Match_InvalidImm12m:
504 "expected immediate in range [-2048, 2047]");
505 case Match_InvalidImm1_16:
507 "expected immediate in range [1, 16]");
508 case Match_InvalidImm1n_15:
510 "expected immediate in range [-1, 15] except 0");
511 case Match_InvalidImm32n_95:
513 "expected immediate in range [-32, 95]");
514 case Match_InvalidImm64n_4n:
516 "expected immediate in range [-64, -4]");
517 case Match_InvalidImm8n_7:
519 "expected immediate in range [-8, 7]");
520 case Match_InvalidShimm1_31:
522 "expected immediate in range [1, 31]");
523 case Match_InvalidUimm4:
525 "expected immediate in range [0, 15]");
526 case Match_InvalidUimm5:
528 "expected immediate in range [0, 31]");
529 case Match_InvalidOffset8m8:
531 "expected immediate in range [0, 255]");
532 case Match_InvalidOffset8m16:
534 "expected immediate in range [0, 510], first bit "
536 case Match_InvalidOffset8m32:
538 "expected immediate in range [0, 1020], first 2 bits "
540 case Match_InvalidOffset4m32:
542 "expected immediate in range [0, 60], first 2 bits "
544 case Match_Invalidentry_imm12:
546 "expected immediate in range [0, 32760], first 3 bits "
548 case Match_Invalidimm7_22:
550 "expected immediate in range [7, 22]");
551 case Match_InvalidSelect_256:
553 "expected immediate in range [0, 255]");
566 const MCExpr *Expr =
nullptr;
567 if (Parser.parseExpression(Expr)) {
573 if (Expr->
getKind() == MCExpr::ExprKind::Constant)
574 return Error(getLoc(),
"unknown operand");
585 Reg = Xtensa::NoRegister;
593 return Error(StartLoc,
"invalid register name");
598 XtensaRegisterType RegType,
600 SMLoc FirstS = getLoc();
601 bool HadParens =
false;
616 MCRegister RegNo = 0;
622 if (RegType == Xtensa_Generic)
628 if (RegType == Xtensa_UR) {
691 return parseOperandWithModifier(Operands);
707 XtensaRegisterType RegType,
711 ParseStatus Res = MatchOperandParserImpl(Operands, Mnemonic);
722 if (parseRegister(Operands,
true, RegType, RAType).isSuccess())
726 if (parseImmediate(Operands).isSuccess())
730 return Error(getLoc(),
"unknown operand");
741 if ((
Name.size() > 4) && Name[3] ==
'.') {
755 return Error(NameLoc,
"invalid register name");
758 if (parseOperand(Operands, Name))
769 if (parseOperand(Operands, Name))
775 return Error(Loc,
"unexpected token");
779 if (parseOperand(Operands, Name, Name[1] ==
's' ? Xtensa_SR : Xtensa_UR,
787 return Error(Loc,
"unexpected token");
797 if (
Name.starts_with(
"wsr") ||
Name.starts_with(
"rsr") ||
798 Name.starts_with(
"xsr") ||
Name.starts_with(
"rur") ||
799 Name.starts_with(
"wur")) {
800 return ParseInstructionWithSR(Info, Name, NameLoc, Operands);
811 if (parseOperand(Operands, Name))
816 if (parseOperand(Operands, Name))
822 return Error(Loc,
"unexpected token");
829bool XtensaAsmParser::parseLiteralDirective(
SMLoc L) {
833 XtensaTargetStreamer &TS = this->getTargetStreamer();
835 if (Parser.parseExpression(
Value))
841 return Error(LiteralLoc,
"literal label must be a symbol");
843 if (Parser.parseComma())
848 return Error(OpcodeLoc,
"expected value");
850 if (Parser.parseExpression(
Value))
864 StringRef IDVal = DirectiveID.
getString();
867 if (IDVal ==
".literal_position") {
868 XtensaTargetStreamer &TS = this->getTargetStreamer();
873 if (IDVal ==
".literal") {
874 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")
#define LLVM_EXTERNAL_VISIBILITY
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
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)
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)
MCStreamer & getStreamer()
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(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
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
LLVM Value Representation.
virtual void emitLiteralPosition()
virtual void emitLiteral(MCSymbol *LblSym, const MCExpr *Value, bool SwitchLiteralSection, SMLoc L=SMLoc())
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.
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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 isSelect_256() const
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,...