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"
68 parseRegister(
OperandVector &Operands,
bool AllowParens =
false,
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();
323 auto Op = std::make_unique<XtensaOperand>(
Token);
332 auto Op = std::make_unique<XtensaOperand>(
Register);
333 Op->Reg.RegNum = RegNo;
341 auto Op = std::make_unique<XtensaOperand>(
Immediate);
349 assert(Expr &&
"Expr shouldn't be null!");
351 bool IsConstant =
false;
355 Imm = CE->getValue();
366 assert(
N == 1 &&
"Invalid number of operands!");
371 assert(
N == 1 &&
"Invalid number of operands!");
376#define GET_REGISTER_MATCHER
377#define GET_MATCHER_IMPLEMENTATION
378#include "XtensaGenAsmMatcher.inc"
389 if (ErrorLoc ==
SMLoc())
396bool XtensaAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
400 const unsigned Opcode = Inst.
getOpcode();
403 const MCSymbolRefExpr *OpExpr =
409 XtensaTargetStreamer &TS = this->getTargetStreamer();
414 int32_t
Imm = ImmOp64;
416 XtensaTargetStreamer &TS = this->getTargetStreamer();
451bool XtensaAsmParser::matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
455 bool MatchingInlineAsm) {
458 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
464 processInstruction(Inst, IDLoc, Out,
STI);
469 return Error(IDLoc,
"instruction use requires an option to be enabled");
471 return Error(IDLoc,
"unrecognized instruction mnemonic");
473 SMLoc ErrorLoc = IDLoc;
474 if (ErrorInfo != ~0U) {
475 if (ErrorInfo >= Operands.
size())
476 return Error(ErrorLoc,
"too few operands for instruction");
478 ErrorLoc = ((XtensaOperand &)*Operands[ErrorInfo]).getStartLoc();
479 if (ErrorLoc == SMLoc())
482 return Error(ErrorLoc,
"invalid operand for instruction");
484 case Match_InvalidImm8:
486 "expected immediate in range [-128, 127]");
487 case Match_InvalidImm8_sh8:
489 "expected immediate in range [-32768, 32512], first 8 bits "
491 case Match_InvalidB4const:
493 "expected b4const immediate");
494 case Match_InvalidB4constu:
496 "expected b4constu immediate");
497 case Match_InvalidImm12:
499 "expected immediate in range [-2048, 2047]");
500 case Match_InvalidImm12m:
502 "expected immediate in range [-2048, 2047]");
503 case Match_InvalidImm1_16:
505 "expected immediate in range [1, 16]");
506 case Match_InvalidImm1n_15:
508 "expected immediate in range [-1, 15] except 0");
509 case Match_InvalidImm32n_95:
511 "expected immediate in range [-32, 95]");
512 case Match_InvalidImm64n_4n:
514 "expected immediate in range [-64, -4]");
515 case Match_InvalidImm8n_7:
517 "expected immediate in range [-8, 7]");
518 case Match_InvalidShimm1_31:
520 "expected immediate in range [1, 31]");
521 case Match_InvalidUimm4:
523 "expected immediate in range [0, 15]");
524 case Match_InvalidUimm5:
526 "expected immediate in range [0, 31]");
527 case Match_InvalidOffset8m8:
529 "expected immediate in range [0, 255]");
530 case Match_InvalidOffset8m16:
532 "expected immediate in range [0, 510], first bit "
534 case Match_InvalidOffset8m32:
536 "expected immediate in range [0, 1020], first 2 bits "
538 case Match_InvalidOffset4m32:
540 "expected immediate in range [0, 60], first 2 bits "
542 case Match_Invalidentry_imm12:
544 "expected immediate in range [0, 32760], first 3 bits "
546 case Match_Invalidimm7_22:
548 "expected immediate in range [7, 22]");
549 case Match_InvalidSelect_256:
551 "expected immediate in range [0, 255]");
564 const MCExpr *Expr =
nullptr;
565 if (Parser.parseExpression(Expr)) {
571 if (Expr->
getKind() == MCExpr::ExprKind::Constant)
572 return Error(getLoc(),
"unknown operand");
583 Reg = Xtensa::NoRegister;
591 return Error(StartLoc,
"invalid register name");
596 XtensaRegisterType RegType,
598 SMLoc FirstS = getLoc();
599 bool HadParens =
false;
614 MCRegister RegNo = 0;
620 if (RegType == Xtensa_Generic)
626 if (RegType == Xtensa_UR) {
689 return parseOperandWithModifier(Operands);
705 XtensaRegisterType RegType,
709 ParseStatus Res = MatchOperandParserImpl(Operands, Mnemonic);
720 if (parseRegister(Operands,
true, RegType, RAType).isSuccess())
724 if (parseImmediate(Operands).isSuccess())
728 return Error(getLoc(),
"unknown operand");
739 if ((
Name.size() > 4) && Name[3] ==
'.') {
753 return Error(NameLoc,
"invalid register name");
756 if (parseOperand(Operands, Name))
767 if (parseOperand(Operands, Name))
773 return Error(Loc,
"unexpected token");
777 if (parseOperand(Operands, Name, Name[1] ==
's' ? Xtensa_SR : Xtensa_UR,
785 return Error(Loc,
"unexpected token");
795 if (
Name.starts_with(
"wsr") ||
Name.starts_with(
"rsr") ||
796 Name.starts_with(
"xsr") ||
Name.starts_with(
"rur") ||
797 Name.starts_with(
"wur")) {
798 return ParseInstructionWithSR(Info, Name, NameLoc, Operands);
809 if (parseOperand(Operands, Name))
814 if (parseOperand(Operands, Name))
820 return Error(Loc,
"unexpected token");
827bool XtensaAsmParser::parseLiteralDirective(
SMLoc L) {
831 XtensaTargetStreamer &TS = this->getTargetStreamer();
833 if (Parser.parseExpression(
Value))
839 return Error(LiteralLoc,
"literal label must be a symbol");
841 if (Parser.parseComma())
846 return Error(OpcodeLoc,
"expected value");
848 if (Parser.parseExpression(
Value))
862 StringRef IDVal = DirectiveID.
getString();
865 if (IDVal ==
".literal_position") {
866 XtensaTargetStreamer &TS = this->getTargetStreamer();
871 if (IDVal ==
".literal") {
872 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)
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()=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 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,...