1 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/ARMBaseInfo.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMMCExpr.h"
13 #include "llvm/MC/MCParser/MCAsmLexer.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrDesc.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCTargetAsmParser.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/TargetRegistry.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/ADT/BitVector.h"
30 #include "llvm/ADT/OwningPtr.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringExtras.h"
34 #include "llvm/ADT/StringSwitch.h"
35 #include "llvm/ADT/Twine.h"
43 class ARMAsmParser : public MCTargetAsmParser {
48 ARMCC::CondCodes Cond; // Condition for IT block.
49 unsigned Mask:4; // Condition mask for instructions.
50 // Starting at first 1 (from lsb).
51 // '1' condition as indicated in IT.
52 // '0' inverse of condition (else).
53 // Count of instructions in IT block is
54 // 4 - trailingzeroes(mask)
56 bool FirstCond; // Explicit flag for when we're parsing the
57 // First instruction in the IT block. It's
58 // implied in the mask, so needs special
61 unsigned CurPosition; // Current position in parsing of IT
62 // block. In range [0,3]. Initialized
63 // according to count of instructions in block.
64 // ~0U if no active IT block.
66 bool inITBlock() { return ITState.CurPosition != ~0U;}
67 void forwardITPosition() {
68 if (!inITBlock()) return;
69 // Move to the next instruction in the IT block, if there is one. If not,
70 // mark the block as done.
71 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
72 if (++ITState.CurPosition == 5 - TZ)
73 ITState.CurPosition = ~0U; // Done with the IT block after this.
77 MCAsmParser &getParser() const { return Parser; }
78 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
80 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
81 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
83 int tryParseRegister();
84 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
85 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
86 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
87 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
88 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
89 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
90 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
91 unsigned &ShiftAmount);
92 bool parseDirectiveWord(unsigned Size, SMLoc L);
93 bool parseDirectiveThumb(SMLoc L);
94 bool parseDirectiveThumbFunc(SMLoc L);
95 bool parseDirectiveCode(SMLoc L);
96 bool parseDirectiveSyntax(SMLoc L);
98 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
99 bool &CarrySetting, unsigned &ProcessorIMod,
101 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
102 bool &CanAcceptPredicationCode);
104 bool isThumb() const {
105 // FIXME: Can tablegen auto-generate this?
106 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
108 bool isThumbOne() const {
109 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
111 bool isThumbTwo() const {
112 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
114 bool hasV6Ops() const {
115 return STI.getFeatureBits() & ARM::HasV6Ops;
117 bool hasV7Ops() const {
118 return STI.getFeatureBits() & ARM::HasV7Ops;
121 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
122 setAvailableFeatures(FB);
124 bool isMClass() const {
125 return STI.getFeatureBits() & ARM::FeatureMClass;
128 /// @name Auto-generated Match Functions
131 #define GET_ASSEMBLER_HEADER
132 #include "ARMGenAsmMatcher.inc"
136 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
137 OperandMatchResultTy parseCoprocNumOperand(
138 SmallVectorImpl<MCParsedAsmOperand*>&);
139 OperandMatchResultTy parseCoprocRegOperand(
140 SmallVectorImpl<MCParsedAsmOperand*>&);
141 OperandMatchResultTy parseCoprocOptionOperand(
142 SmallVectorImpl<MCParsedAsmOperand*>&);
143 OperandMatchResultTy parseMemBarrierOptOperand(
144 SmallVectorImpl<MCParsedAsmOperand*>&);
145 OperandMatchResultTy parseProcIFlagsOperand(
146 SmallVectorImpl<MCParsedAsmOperand*>&);
147 OperandMatchResultTy parseMSRMaskOperand(
148 SmallVectorImpl<MCParsedAsmOperand*>&);
149 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
150 StringRef Op, int Low, int High);
151 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
152 return parsePKHImm(O, "lsl", 0, 31);
154 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
155 return parsePKHImm(O, "asr", 1, 32);
157 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
158 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
159 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
160 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
161 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
162 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
163 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
164 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
166 // Asm Match Converter Methods
167 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
168 const SmallVectorImpl<MCParsedAsmOperand*> &);
169 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
170 const SmallVectorImpl<MCParsedAsmOperand*> &);
171 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
172 const SmallVectorImpl<MCParsedAsmOperand*> &);
173 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
174 const SmallVectorImpl<MCParsedAsmOperand*> &);
175 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
176 const SmallVectorImpl<MCParsedAsmOperand*> &);
177 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
178 const SmallVectorImpl<MCParsedAsmOperand*> &);
179 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
180 const SmallVectorImpl<MCParsedAsmOperand*> &);
181 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
182 const SmallVectorImpl<MCParsedAsmOperand*> &);
183 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
184 const SmallVectorImpl<MCParsedAsmOperand*> &);
185 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
186 const SmallVectorImpl<MCParsedAsmOperand*> &);
187 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
188 const SmallVectorImpl<MCParsedAsmOperand*> &);
189 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
190 const SmallVectorImpl<MCParsedAsmOperand*> &);
191 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
192 const SmallVectorImpl<MCParsedAsmOperand*> &);
193 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
194 const SmallVectorImpl<MCParsedAsmOperand*> &);
195 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
196 const SmallVectorImpl<MCParsedAsmOperand*> &);
197 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
198 const SmallVectorImpl<MCParsedAsmOperand*> &);
199 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
200 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 bool validateInstruction(MCInst &Inst,
203 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
204 void processInstruction(MCInst &Inst,
205 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
206 bool shouldOmitCCOutOperand(StringRef Mnemonic,
207 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
210 enum ARMMatchResultTy {
211 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
212 Match_RequiresNotITBlock,
217 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
218 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
219 MCAsmParserExtension::Initialize(_Parser);
221 // Initialize the set of available features.
222 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
224 // Not in an ITBlock to start with.
225 ITState.CurPosition = ~0U;
228 // Implementation of the MCTargetAsmParser interface:
229 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
230 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
232 bool ParseDirective(AsmToken DirectiveID);
234 unsigned checkTargetMatchPredicate(MCInst &Inst);
236 bool MatchAndEmitInstruction(SMLoc IDLoc,
237 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
240 } // end anonymous namespace
244 /// ARMOperand - Instances of this class represent a parsed ARM machine
246 class ARMOperand : public MCParsedAsmOperand {
271 k_BitfieldDescriptor,
275 SMLoc StartLoc, EndLoc;
276 SmallVector<unsigned, 8> Registers;
280 ARMCC::CondCodes Val;
300 ARM_PROC::IFlags Val;
316 // A vector register list is a sequential list of 1 to 4 registers.
331 unsigned Val; // encoded 8-bit representation
334 /// Combined record for all forms of ARM address expressions.
337 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
339 const MCConstantExpr *OffsetImm; // Offset immediate value
340 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
341 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
342 unsigned ShiftImm; // shift for OffsetReg.
343 unsigned Alignment; // 0 = no alignment specified
344 // n = alignment in bytes (8, 16, or 32)
345 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
351 ARM_AM::ShiftOpc ShiftTy;
360 ARM_AM::ShiftOpc ShiftTy;
366 ARM_AM::ShiftOpc ShiftTy;
379 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
381 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
383 StartLoc = o.StartLoc;
400 case k_DPRRegisterList:
401 case k_SPRRegisterList:
402 Registers = o.Registers;
405 VectorList = o.VectorList;
412 CoprocOption = o.CoprocOption;
420 case k_MemBarrierOpt:
426 case k_PostIndexRegister:
427 PostIdxReg = o.PostIdxReg;
435 case k_ShifterImmediate:
436 ShifterImm = o.ShifterImm;
438 case k_ShiftedRegister:
439 RegShiftedReg = o.RegShiftedReg;
441 case k_ShiftedImmediate:
442 RegShiftedImm = o.RegShiftedImm;
444 case k_RotateImmediate:
447 case k_BitfieldDescriptor:
448 Bitfield = o.Bitfield;
451 VectorIndex = o.VectorIndex;
456 /// getStartLoc - Get the location of the first token of this operand.
457 SMLoc getStartLoc() const { return StartLoc; }
458 /// getEndLoc - Get the location of the last token of this operand.
459 SMLoc getEndLoc() const { return EndLoc; }
461 ARMCC::CondCodes getCondCode() const {
462 assert(Kind == k_CondCode && "Invalid access!");
466 unsigned getCoproc() const {
467 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
471 StringRef getToken() const {
472 assert(Kind == k_Token && "Invalid access!");
473 return StringRef(Tok.Data, Tok.Length);
476 unsigned getReg() const {
477 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
481 const SmallVectorImpl<unsigned> &getRegList() const {
482 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
483 Kind == k_SPRRegisterList) && "Invalid access!");
487 const MCExpr *getImm() const {
488 assert(Kind == k_Immediate && "Invalid access!");
492 unsigned getFPImm() const {
493 assert(Kind == k_FPImmediate && "Invalid access!");
497 unsigned getVectorIndex() const {
498 assert(Kind == k_VectorIndex && "Invalid access!");
499 return VectorIndex.Val;
502 ARM_MB::MemBOpt getMemBarrierOpt() const {
503 assert(Kind == k_MemBarrierOpt && "Invalid access!");
507 ARM_PROC::IFlags getProcIFlags() const {
508 assert(Kind == k_ProcIFlags && "Invalid access!");
512 unsigned getMSRMask() const {
513 assert(Kind == k_MSRMask && "Invalid access!");
517 bool isCoprocNum() const { return Kind == k_CoprocNum; }
518 bool isCoprocReg() const { return Kind == k_CoprocReg; }
519 bool isCoprocOption() const { return Kind == k_CoprocOption; }
520 bool isCondCode() const { return Kind == k_CondCode; }
521 bool isCCOut() const { return Kind == k_CCOut; }
522 bool isITMask() const { return Kind == k_ITCondMask; }
523 bool isITCondCode() const { return Kind == k_CondCode; }
524 bool isImm() const { return Kind == k_Immediate; }
525 bool isFPImm() const { return Kind == k_FPImmediate; }
526 bool isImm8s4() const {
527 if (Kind != k_Immediate)
529 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
530 if (!CE) return false;
531 int64_t Value = CE->getValue();
532 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
534 bool isImm0_1020s4() const {
535 if (Kind != k_Immediate)
537 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
538 if (!CE) return false;
539 int64_t Value = CE->getValue();
540 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
542 bool isImm0_508s4() const {
543 if (Kind != k_Immediate)
545 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
546 if (!CE) return false;
547 int64_t Value = CE->getValue();
548 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
550 bool isImm0_255() const {
551 if (Kind != k_Immediate)
553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
554 if (!CE) return false;
555 int64_t Value = CE->getValue();
556 return Value >= 0 && Value < 256;
558 bool isImm0_7() const {
559 if (Kind != k_Immediate)
561 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
562 if (!CE) return false;
563 int64_t Value = CE->getValue();
564 return Value >= 0 && Value < 8;
566 bool isImm0_15() const {
567 if (Kind != k_Immediate)
569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
570 if (!CE) return false;
571 int64_t Value = CE->getValue();
572 return Value >= 0 && Value < 16;
574 bool isImm0_31() const {
575 if (Kind != k_Immediate)
577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
578 if (!CE) return false;
579 int64_t Value = CE->getValue();
580 return Value >= 0 && Value < 32;
582 bool isImm1_16() const {
583 if (Kind != k_Immediate)
585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
586 if (!CE) return false;
587 int64_t Value = CE->getValue();
588 return Value > 0 && Value < 17;
590 bool isImm1_32() const {
591 if (Kind != k_Immediate)
593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
594 if (!CE) return false;
595 int64_t Value = CE->getValue();
596 return Value > 0 && Value < 33;
598 bool isImm0_65535() const {
599 if (Kind != k_Immediate)
601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
602 if (!CE) return false;
603 int64_t Value = CE->getValue();
604 return Value >= 0 && Value < 65536;
606 bool isImm0_65535Expr() const {
607 if (Kind != k_Immediate)
609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
610 // If it's not a constant expression, it'll generate a fixup and be
612 if (!CE) return true;
613 int64_t Value = CE->getValue();
614 return Value >= 0 && Value < 65536;
616 bool isImm24bit() const {
617 if (Kind != k_Immediate)
619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
620 if (!CE) return false;
621 int64_t Value = CE->getValue();
622 return Value >= 0 && Value <= 0xffffff;
624 bool isImmThumbSR() const {
625 if (Kind != k_Immediate)
627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
628 if (!CE) return false;
629 int64_t Value = CE->getValue();
630 return Value > 0 && Value < 33;
632 bool isPKHLSLImm() const {
633 if (Kind != k_Immediate)
635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int64_t Value = CE->getValue();
638 return Value >= 0 && Value < 32;
640 bool isPKHASRImm() const {
641 if (Kind != k_Immediate)
643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
644 if (!CE) return false;
645 int64_t Value = CE->getValue();
646 return Value > 0 && Value <= 32;
648 bool isARMSOImm() const {
649 if (Kind != k_Immediate)
651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
652 if (!CE) return false;
653 int64_t Value = CE->getValue();
654 return ARM_AM::getSOImmVal(Value) != -1;
656 bool isT2SOImm() const {
657 if (Kind != k_Immediate)
659 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
660 if (!CE) return false;
661 int64_t Value = CE->getValue();
662 return ARM_AM::getT2SOImmVal(Value) != -1;
664 bool isSetEndImm() const {
665 if (Kind != k_Immediate)
667 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
668 if (!CE) return false;
669 int64_t Value = CE->getValue();
670 return Value == 1 || Value == 0;
672 bool isReg() const { return Kind == k_Register; }
673 bool isRegList() const { return Kind == k_RegisterList; }
674 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
675 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
676 bool isToken() const { return Kind == k_Token; }
677 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
678 bool isMemory() const { return Kind == k_Memory; }
679 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
680 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
681 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
682 bool isRotImm() const { return Kind == k_RotateImmediate; }
683 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
684 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
685 bool isPostIdxReg() const {
686 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy == ARM_AM::no_shift;
688 bool isMemNoOffset(bool alignOK = false) const {
691 // No offset of any kind.
692 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
693 (alignOK || Memory.Alignment == 0);
695 bool isAlignedMemory() const {
696 return isMemNoOffset(true);
698 bool isAddrMode2() const {
699 if (!isMemory() || Memory.Alignment != 0) return false;
700 // Check for register offset.
701 if (Memory.OffsetRegNum) return true;
702 // Immediate offset in range [-4095, 4095].
703 if (!Memory.OffsetImm) return true;
704 int64_t Val = Memory.OffsetImm->getValue();
705 return Val > -4096 && Val < 4096;
707 bool isAM2OffsetImm() const {
708 if (Kind != k_Immediate)
710 // Immediate offset in range [-4095, 4095].
711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
712 if (!CE) return false;
713 int64_t Val = CE->getValue();
714 return Val > -4096 && Val < 4096;
716 bool isAddrMode3() const {
717 if (!isMemory() || Memory.Alignment != 0) return false;
718 // No shifts are legal for AM3.
719 if (Memory.ShiftType != ARM_AM::no_shift) return false;
720 // Check for register offset.
721 if (Memory.OffsetRegNum) return true;
722 // Immediate offset in range [-255, 255].
723 if (!Memory.OffsetImm) return true;
724 int64_t Val = Memory.OffsetImm->getValue();
725 return Val > -256 && Val < 256;
727 bool isAM3Offset() const {
728 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
730 if (Kind == k_PostIndexRegister)
731 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
732 // Immediate offset in range [-255, 255].
733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Val = CE->getValue();
736 // Special case, #-0 is INT32_MIN.
737 return (Val > -256 && Val < 256) || Val == INT32_MIN;
739 bool isAddrMode5() const {
740 if (!isMemory() || Memory.Alignment != 0) return false;
741 // Check for register offset.
742 if (Memory.OffsetRegNum) return false;
743 // Immediate offset in range [-1020, 1020] and a multiple of 4.
744 if (!Memory.OffsetImm) return true;
745 int64_t Val = Memory.OffsetImm->getValue();
746 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
749 bool isMemTBB() const {
750 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
751 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
755 bool isMemTBH() const {
756 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
757 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
758 Memory.Alignment != 0 )
762 bool isMemRegOffset() const {
763 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
767 bool isT2MemRegOffset() const {
768 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
769 Memory.Alignment != 0)
771 // Only lsl #{0, 1, 2, 3} allowed.
772 if (Memory.ShiftType == ARM_AM::no_shift)
774 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
778 bool isMemThumbRR() const {
779 // Thumb reg+reg addressing is simple. Just two registers, a base and
780 // an offset. No shifts, negations or any other complicating factors.
781 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
782 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
784 return isARMLowRegister(Memory.BaseRegNum) &&
785 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
787 bool isMemThumbRIs4() const {
788 if (!isMemory() || Memory.OffsetRegNum != 0 ||
789 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
791 // Immediate offset, multiple of 4 in range [0, 124].
792 if (!Memory.OffsetImm) return true;
793 int64_t Val = Memory.OffsetImm->getValue();
794 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
796 bool isMemThumbRIs2() const {
797 if (!isMemory() || Memory.OffsetRegNum != 0 ||
798 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
800 // Immediate offset, multiple of 4 in range [0, 62].
801 if (!Memory.OffsetImm) return true;
802 int64_t Val = Memory.OffsetImm->getValue();
803 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
805 bool isMemThumbRIs1() const {
806 if (!isMemory() || Memory.OffsetRegNum != 0 ||
807 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
809 // Immediate offset in range [0, 31].
810 if (!Memory.OffsetImm) return true;
811 int64_t Val = Memory.OffsetImm->getValue();
812 return Val >= 0 && Val <= 31;
814 bool isMemThumbSPI() const {
815 if (!isMemory() || Memory.OffsetRegNum != 0 ||
816 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
818 // Immediate offset, multiple of 4 in range [0, 1020].
819 if (!Memory.OffsetImm) return true;
820 int64_t Val = Memory.OffsetImm->getValue();
821 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
823 bool isMemImm8s4Offset() const {
824 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
826 // Immediate offset a multiple of 4 in range [-1020, 1020].
827 if (!Memory.OffsetImm) return true;
828 int64_t Val = Memory.OffsetImm->getValue();
829 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
831 bool isMemImm0_1020s4Offset() const {
832 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
834 // Immediate offset a multiple of 4 in range [0, 1020].
835 if (!Memory.OffsetImm) return true;
836 int64_t Val = Memory.OffsetImm->getValue();
837 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
839 bool isMemImm8Offset() const {
840 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
842 // Immediate offset in range [-255, 255].
843 if (!Memory.OffsetImm) return true;
844 int64_t Val = Memory.OffsetImm->getValue();
845 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
847 bool isMemPosImm8Offset() const {
848 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
850 // Immediate offset in range [0, 255].
851 if (!Memory.OffsetImm) return true;
852 int64_t Val = Memory.OffsetImm->getValue();
853 return Val >= 0 && Val < 256;
855 bool isMemNegImm8Offset() const {
856 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
858 // Immediate offset in range [-255, -1].
859 if (!Memory.OffsetImm) return true;
860 int64_t Val = Memory.OffsetImm->getValue();
861 return Val > -256 && Val < 0;
863 bool isMemUImm12Offset() const {
864 // If we have an immediate that's not a constant, treat it as a label
865 // reference needing a fixup. If it is a constant, it's something else
867 if (Kind == k_Immediate && !isa<MCConstantExpr>(getImm()))
870 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
872 // Immediate offset in range [0, 4095].
873 if (!Memory.OffsetImm) return true;
874 int64_t Val = Memory.OffsetImm->getValue();
875 return (Val >= 0 && Val < 4096);
877 bool isMemImm12Offset() const {
878 // If we have an immediate that's not a constant, treat it as a label
879 // reference needing a fixup. If it is a constant, it's something else
881 if (Kind == k_Immediate && !isa<MCConstantExpr>(getImm()))
884 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
886 // Immediate offset in range [-4095, 4095].
887 if (!Memory.OffsetImm) return true;
888 int64_t Val = Memory.OffsetImm->getValue();
889 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
891 bool isPostIdxImm8() const {
892 if (Kind != k_Immediate)
894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Val = CE->getValue();
897 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
899 bool isPostIdxImm8s4() const {
900 if (Kind != k_Immediate)
902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
903 if (!CE) return false;
904 int64_t Val = CE->getValue();
905 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
909 bool isMSRMask() const { return Kind == k_MSRMask; }
910 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
913 bool isVecListOneD() const {
914 if (Kind != k_VectorList) return false;
915 return VectorList.Count == 1;
918 bool isVecListTwoD() const {
919 if (Kind != k_VectorList) return false;
920 return VectorList.Count == 2;
923 bool isVecListThreeD() const {
924 if (Kind != k_VectorList) return false;
925 return VectorList.Count == 3;
928 bool isVecListFourD() const {
929 if (Kind != k_VectorList) return false;
930 return VectorList.Count == 4;
933 bool isVecListTwoQ() const {
934 if (Kind != k_VectorList) return false;
935 //FIXME: We haven't taught the parser to handle by-two register lists
936 // yet, so don't pretend to know one.
937 return VectorList.Count == 2 && false;
940 bool isVectorIndex8() const {
941 if (Kind != k_VectorIndex) return false;
942 return VectorIndex.Val < 8;
944 bool isVectorIndex16() const {
945 if (Kind != k_VectorIndex) return false;
946 return VectorIndex.Val < 4;
948 bool isVectorIndex32() const {
949 if (Kind != k_VectorIndex) return false;
950 return VectorIndex.Val < 2;
953 bool isNEONi8splat() const {
954 if (Kind != k_Immediate)
956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 // Must be a constant.
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
960 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
962 return Value >= 0 && Value < 256;
965 bool isNEONi16splat() const {
966 if (Kind != k_Immediate)
968 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
969 // Must be a constant.
970 if (!CE) return false;
971 int64_t Value = CE->getValue();
972 // i16 value in the range [0,255] or [0x0100, 0xff00]
973 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
976 bool isNEONi32splat() const {
977 if (Kind != k_Immediate)
979 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
980 // Must be a constant.
981 if (!CE) return false;
982 int64_t Value = CE->getValue();
983 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
984 return (Value >= 0 && Value < 256) ||
985 (Value >= 0x0100 && Value <= 0xff00) ||
986 (Value >= 0x010000 && Value <= 0xff0000) ||
987 (Value >= 0x01000000 && Value <= 0xff000000);
990 bool isNEONi32vmov() const {
991 if (Kind != k_Immediate)
993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
994 // Must be a constant.
995 if (!CE) return false;
996 int64_t Value = CE->getValue();
997 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
998 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
999 return (Value >= 0 && Value < 256) ||
1000 (Value >= 0x0100 && Value <= 0xff00) ||
1001 (Value >= 0x010000 && Value <= 0xff0000) ||
1002 (Value >= 0x01000000 && Value <= 0xff000000) ||
1003 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1004 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1007 bool isNEONi64splat() const {
1008 if (Kind != k_Immediate)
1010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1011 // Must be a constant.
1012 if (!CE) return false;
1013 uint64_t Value = CE->getValue();
1014 // i64 value with each byte being either 0 or 0xff.
1015 for (unsigned i = 0; i < 8; ++i)
1016 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1020 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1021 // Add as immediates when possible. Null MCExpr = 0.
1023 Inst.addOperand(MCOperand::CreateImm(0));
1024 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1025 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1027 Inst.addOperand(MCOperand::CreateExpr(Expr));
1030 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1031 assert(N == 2 && "Invalid number of operands!");
1032 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1033 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1034 Inst.addOperand(MCOperand::CreateReg(RegNum));
1037 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1038 assert(N == 1 && "Invalid number of operands!");
1039 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1042 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1043 assert(N == 1 && "Invalid number of operands!");
1044 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1047 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1048 assert(N == 1 && "Invalid number of operands!");
1049 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1052 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1053 assert(N == 1 && "Invalid number of operands!");
1054 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1057 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1058 assert(N == 1 && "Invalid number of operands!");
1059 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1062 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1063 assert(N == 1 && "Invalid number of operands!");
1064 Inst.addOperand(MCOperand::CreateReg(getReg()));
1067 void addRegOperands(MCInst &Inst, unsigned N) const {
1068 assert(N == 1 && "Invalid number of operands!");
1069 Inst.addOperand(MCOperand::CreateReg(getReg()));
1072 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1073 assert(N == 3 && "Invalid number of operands!");
1074 assert(isRegShiftedReg() && "addRegShiftedRegOperands() on non RegShiftedReg!");
1075 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1076 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1077 Inst.addOperand(MCOperand::CreateImm(
1078 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1081 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1082 assert(N == 2 && "Invalid number of operands!");
1083 assert(isRegShiftedImm() && "addRegShiftedImmOperands() on non RegShiftedImm!");
1084 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1085 Inst.addOperand(MCOperand::CreateImm(
1086 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, RegShiftedImm.ShiftImm)));
1089 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1090 assert(N == 1 && "Invalid number of operands!");
1091 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1095 void addRegListOperands(MCInst &Inst, unsigned N) const {
1096 assert(N == 1 && "Invalid number of operands!");
1097 const SmallVectorImpl<unsigned> &RegList = getRegList();
1098 for (SmallVectorImpl<unsigned>::const_iterator
1099 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1100 Inst.addOperand(MCOperand::CreateReg(*I));
1103 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1104 addRegListOperands(Inst, N);
1107 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1108 addRegListOperands(Inst, N);
1111 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1112 assert(N == 1 && "Invalid number of operands!");
1113 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1114 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1117 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1118 assert(N == 1 && "Invalid number of operands!");
1119 // Munge the lsb/width into a bitfield mask.
1120 unsigned lsb = Bitfield.LSB;
1121 unsigned width = Bitfield.Width;
1122 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1123 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1124 (32 - (lsb + width)));
1125 Inst.addOperand(MCOperand::CreateImm(Mask));
1128 void addImmOperands(MCInst &Inst, unsigned N) const {
1129 assert(N == 1 && "Invalid number of operands!");
1130 addExpr(Inst, getImm());
1133 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1134 assert(N == 1 && "Invalid number of operands!");
1135 Inst.addOperand(MCOperand::CreateImm(getFPImm()));
1138 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1139 assert(N == 1 && "Invalid number of operands!");
1140 // FIXME: We really want to scale the value here, but the LDRD/STRD
1141 // instruction don't encode operands that way yet.
1142 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1143 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1146 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1147 assert(N == 1 && "Invalid number of operands!");
1148 // The immediate is scaled by four in the encoding and is stored
1149 // in the MCInst as such. Lop off the low two bits here.
1150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1151 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1154 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1155 assert(N == 1 && "Invalid number of operands!");
1156 // The immediate is scaled by four in the encoding and is stored
1157 // in the MCInst as such. Lop off the low two bits here.
1158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1159 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1162 void addImm0_255Operands(MCInst &Inst, unsigned N) const {
1163 assert(N == 1 && "Invalid number of operands!");
1164 addExpr(Inst, getImm());
1167 void addImm0_7Operands(MCInst &Inst, unsigned N) const {
1168 assert(N == 1 && "Invalid number of operands!");
1169 addExpr(Inst, getImm());
1172 void addImm0_15Operands(MCInst &Inst, unsigned N) const {
1173 assert(N == 1 && "Invalid number of operands!");
1174 addExpr(Inst, getImm());
1177 void addImm0_31Operands(MCInst &Inst, unsigned N) const {
1178 assert(N == 1 && "Invalid number of operands!");
1179 addExpr(Inst, getImm());
1182 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1183 assert(N == 1 && "Invalid number of operands!");
1184 // The constant encodes as the immediate-1, and we store in the instruction
1185 // the bits as encoded, so subtract off one here.
1186 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1187 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1190 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1191 assert(N == 1 && "Invalid number of operands!");
1192 // The constant encodes as the immediate-1, and we store in the instruction
1193 // the bits as encoded, so subtract off one here.
1194 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1195 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1198 void addImm0_65535Operands(MCInst &Inst, unsigned N) const {
1199 assert(N == 1 && "Invalid number of operands!");
1200 addExpr(Inst, getImm());
1203 void addImm0_65535ExprOperands(MCInst &Inst, unsigned N) const {
1204 assert(N == 1 && "Invalid number of operands!");
1205 addExpr(Inst, getImm());
1208 void addImm24bitOperands(MCInst &Inst, unsigned N) const {
1209 assert(N == 1 && "Invalid number of operands!");
1210 addExpr(Inst, getImm());
1213 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1214 assert(N == 1 && "Invalid number of operands!");
1215 // The constant encodes as the immediate, except for 32, which encodes as
1217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1218 unsigned Imm = CE->getValue();
1219 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1222 void addPKHLSLImmOperands(MCInst &Inst, unsigned N) const {
1223 assert(N == 1 && "Invalid number of operands!");
1224 addExpr(Inst, getImm());
1227 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1228 assert(N == 1 && "Invalid number of operands!");
1229 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1230 // the instruction as well.
1231 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1232 int Val = CE->getValue();
1233 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1236 void addARMSOImmOperands(MCInst &Inst, unsigned N) const {
1237 assert(N == 1 && "Invalid number of operands!");
1238 addExpr(Inst, getImm());
1241 void addT2SOImmOperands(MCInst &Inst, unsigned N) const {
1242 assert(N == 1 && "Invalid number of operands!");
1243 addExpr(Inst, getImm());
1246 void addSetEndImmOperands(MCInst &Inst, unsigned N) const {
1247 assert(N == 1 && "Invalid number of operands!");
1248 addExpr(Inst, getImm());
1251 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1252 assert(N == 1 && "Invalid number of operands!");
1253 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1256 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1257 assert(N == 1 && "Invalid number of operands!");
1258 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1261 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1262 assert(N == 2 && "Invalid number of operands!");
1263 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1264 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1267 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1268 assert(N == 3 && "Invalid number of operands!");
1269 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1270 if (!Memory.OffsetRegNum) {
1271 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1272 // Special case for #-0
1273 if (Val == INT32_MIN) Val = 0;
1274 if (Val < 0) Val = -Val;
1275 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1277 // For register offset, we encode the shift type and negation flag
1279 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1280 Memory.ShiftImm, Memory.ShiftType);
1282 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1283 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1284 Inst.addOperand(MCOperand::CreateImm(Val));
1287 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1288 assert(N == 2 && "Invalid number of operands!");
1289 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1290 assert(CE && "non-constant AM2OffsetImm operand!");
1291 int32_t Val = CE->getValue();
1292 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1293 // Special case for #-0
1294 if (Val == INT32_MIN) Val = 0;
1295 if (Val < 0) Val = -Val;
1296 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1297 Inst.addOperand(MCOperand::CreateReg(0));
1298 Inst.addOperand(MCOperand::CreateImm(Val));
1301 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1302 assert(N == 3 && "Invalid number of operands!");
1303 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1304 if (!Memory.OffsetRegNum) {
1305 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1306 // Special case for #-0
1307 if (Val == INT32_MIN) Val = 0;
1308 if (Val < 0) Val = -Val;
1309 Val = ARM_AM::getAM3Opc(AddSub, Val);
1311 // For register offset, we encode the shift type and negation flag
1313 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1315 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1316 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1317 Inst.addOperand(MCOperand::CreateImm(Val));
1320 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1321 assert(N == 2 && "Invalid number of operands!");
1322 if (Kind == k_PostIndexRegister) {
1324 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1325 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1326 Inst.addOperand(MCOperand::CreateImm(Val));
1331 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1332 int32_t Val = CE->getValue();
1333 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1334 // Special case for #-0
1335 if (Val == INT32_MIN) Val = 0;
1336 if (Val < 0) Val = -Val;
1337 Val = ARM_AM::getAM3Opc(AddSub, Val);
1338 Inst.addOperand(MCOperand::CreateReg(0));
1339 Inst.addOperand(MCOperand::CreateImm(Val));
1342 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1343 assert(N == 2 && "Invalid number of operands!");
1344 // The lower two bits are always zero and as such are not encoded.
1345 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1346 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1347 // Special case for #-0
1348 if (Val == INT32_MIN) Val = 0;
1349 if (Val < 0) Val = -Val;
1350 Val = ARM_AM::getAM5Opc(AddSub, Val);
1351 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1352 Inst.addOperand(MCOperand::CreateImm(Val));
1355 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1356 assert(N == 2 && "Invalid number of operands!");
1357 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1358 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1359 Inst.addOperand(MCOperand::CreateImm(Val));
1362 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1363 assert(N == 2 && "Invalid number of operands!");
1364 // The lower two bits are always zero and as such are not encoded.
1365 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1366 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1367 Inst.addOperand(MCOperand::CreateImm(Val));
1370 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1371 assert(N == 2 && "Invalid number of operands!");
1372 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1373 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1374 Inst.addOperand(MCOperand::CreateImm(Val));
1377 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1378 addMemImm8OffsetOperands(Inst, N);
1381 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1382 addMemImm8OffsetOperands(Inst, N);
1385 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1386 assert(N == 2 && "Invalid number of operands!");
1387 // If this is an immediate, it's a label reference.
1388 if (Kind == k_Immediate) {
1389 addExpr(Inst, getImm());
1390 Inst.addOperand(MCOperand::CreateImm(0));
1394 // Otherwise, it's a normal memory reg+offset.
1395 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1396 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1397 Inst.addOperand(MCOperand::CreateImm(Val));
1400 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1401 assert(N == 2 && "Invalid number of operands!");
1402 // If this is an immediate, it's a label reference.
1403 if (Kind == k_Immediate) {
1404 addExpr(Inst, getImm());
1405 Inst.addOperand(MCOperand::CreateImm(0));
1409 // Otherwise, it's a normal memory reg+offset.
1410 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1411 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1412 Inst.addOperand(MCOperand::CreateImm(Val));
1415 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1416 assert(N == 2 && "Invalid number of operands!");
1417 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1418 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1421 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1422 assert(N == 2 && "Invalid number of operands!");
1423 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1424 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1427 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1428 assert(N == 3 && "Invalid number of operands!");
1429 unsigned Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1430 Memory.ShiftImm, Memory.ShiftType);
1431 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1432 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1433 Inst.addOperand(MCOperand::CreateImm(Val));
1436 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1437 assert(N == 3 && "Invalid number of operands!");
1438 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1439 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1440 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1443 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1444 assert(N == 2 && "Invalid number of operands!");
1445 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1446 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1449 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1450 assert(N == 2 && "Invalid number of operands!");
1451 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1452 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1453 Inst.addOperand(MCOperand::CreateImm(Val));
1456 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1457 assert(N == 2 && "Invalid number of operands!");
1458 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1459 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1460 Inst.addOperand(MCOperand::CreateImm(Val));
1463 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1464 assert(N == 2 && "Invalid number of operands!");
1465 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1466 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1467 Inst.addOperand(MCOperand::CreateImm(Val));
1470 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1471 assert(N == 2 && "Invalid number of operands!");
1472 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1473 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1474 Inst.addOperand(MCOperand::CreateImm(Val));
1477 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1478 assert(N == 1 && "Invalid number of operands!");
1479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1480 assert(CE && "non-constant post-idx-imm8 operand!");
1481 int Imm = CE->getValue();
1482 bool isAdd = Imm >= 0;
1483 if (Imm == INT32_MIN) Imm = 0;
1484 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1485 Inst.addOperand(MCOperand::CreateImm(Imm));
1488 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1489 assert(N == 1 && "Invalid number of operands!");
1490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 assert(CE && "non-constant post-idx-imm8s4 operand!");
1492 int Imm = CE->getValue();
1493 bool isAdd = Imm >= 0;
1494 if (Imm == INT32_MIN) Imm = 0;
1495 // Immediate is scaled by 4.
1496 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1497 Inst.addOperand(MCOperand::CreateImm(Imm));
1500 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1501 assert(N == 2 && "Invalid number of operands!");
1502 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1503 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1506 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 2 && "Invalid number of operands!");
1508 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1509 // The sign, shift type, and shift amount are encoded in a single operand
1510 // using the AM2 encoding helpers.
1511 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1512 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1513 PostIdxReg.ShiftTy);
1514 Inst.addOperand(MCOperand::CreateImm(Imm));
1517 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1518 assert(N == 1 && "Invalid number of operands!");
1519 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1522 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1527 void addVecListOneDOperands(MCInst &Inst, unsigned N) const {
1528 assert(N == 1 && "Invalid number of operands!");
1529 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1532 void addVecListTwoDOperands(MCInst &Inst, unsigned N) const {
1533 assert(N == 1 && "Invalid number of operands!");
1534 // Only the first register actually goes on the instruction. The rest
1535 // are implied by the opcode.
1536 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1539 void addVecListThreeDOperands(MCInst &Inst, unsigned N) const {
1540 assert(N == 1 && "Invalid number of operands!");
1541 // Only the first register actually goes on the instruction. The rest
1542 // are implied by the opcode.
1543 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1546 void addVecListFourDOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 1 && "Invalid number of operands!");
1548 // Only the first register actually goes on the instruction. The rest
1549 // are implied by the opcode.
1550 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1553 void addVecListTwoQOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 // Only the first register actually goes on the instruction. The rest
1556 // are implied by the opcode.
1557 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1560 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1565 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1570 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
1572 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1575 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 // The immediate encodes the type of constant as well as the value.
1578 // Mask in that this is an i8 splat.
1579 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1580 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1583 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1584 assert(N == 1 && "Invalid number of operands!");
1585 // The immediate encodes the type of constant as well as the value.
1586 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1587 unsigned Value = CE->getValue();
1589 Value = (Value >> 8) | 0xa00;
1592 Inst.addOperand(MCOperand::CreateImm(Value));
1595 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1596 assert(N == 1 && "Invalid number of operands!");
1597 // The immediate encodes the type of constant as well as the value.
1598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 unsigned Value = CE->getValue();
1600 if (Value >= 256 && Value <= 0xff00)
1601 Value = (Value >> 8) | 0x200;
1602 else if (Value > 0xffff && Value <= 0xff0000)
1603 Value = (Value >> 16) | 0x400;
1604 else if (Value > 0xffffff)
1605 Value = (Value >> 24) | 0x600;
1606 Inst.addOperand(MCOperand::CreateImm(Value));
1609 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1610 assert(N == 1 && "Invalid number of operands!");
1611 // The immediate encodes the type of constant as well as the value.
1612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 unsigned Value = CE->getValue();
1614 if (Value >= 256 && Value <= 0xffff)
1615 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1616 else if (Value > 0xffff && Value <= 0xffffff)
1617 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1618 else if (Value > 0xffffff)
1619 Value = (Value >> 24) | 0x600;
1620 Inst.addOperand(MCOperand::CreateImm(Value));
1623 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 // The immediate encodes the type of constant as well as the value.
1626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1627 uint64_t Value = CE->getValue();
1629 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
1630 Imm |= (Value & 1) << i;
1632 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
1635 virtual void print(raw_ostream &OS) const;
1637 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
1638 ARMOperand *Op = new ARMOperand(k_ITCondMask);
1639 Op->ITMask.Mask = Mask;
1645 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
1646 ARMOperand *Op = new ARMOperand(k_CondCode);
1653 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
1654 ARMOperand *Op = new ARMOperand(k_CoprocNum);
1655 Op->Cop.Val = CopVal;
1661 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
1662 ARMOperand *Op = new ARMOperand(k_CoprocReg);
1663 Op->Cop.Val = CopVal;
1669 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
1670 ARMOperand *Op = new ARMOperand(k_CoprocOption);
1677 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
1678 ARMOperand *Op = new ARMOperand(k_CCOut);
1679 Op->Reg.RegNum = RegNum;
1685 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
1686 ARMOperand *Op = new ARMOperand(k_Token);
1687 Op->Tok.Data = Str.data();
1688 Op->Tok.Length = Str.size();
1694 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
1695 ARMOperand *Op = new ARMOperand(k_Register);
1696 Op->Reg.RegNum = RegNum;
1702 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
1707 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
1708 Op->RegShiftedReg.ShiftTy = ShTy;
1709 Op->RegShiftedReg.SrcReg = SrcReg;
1710 Op->RegShiftedReg.ShiftReg = ShiftReg;
1711 Op->RegShiftedReg.ShiftImm = ShiftImm;
1717 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
1721 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
1722 Op->RegShiftedImm.ShiftTy = ShTy;
1723 Op->RegShiftedImm.SrcReg = SrcReg;
1724 Op->RegShiftedImm.ShiftImm = ShiftImm;
1730 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
1732 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
1733 Op->ShifterImm.isASR = isASR;
1734 Op->ShifterImm.Imm = Imm;
1740 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
1741 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
1742 Op->RotImm.Imm = Imm;
1748 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
1750 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
1751 Op->Bitfield.LSB = LSB;
1752 Op->Bitfield.Width = Width;
1759 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
1760 SMLoc StartLoc, SMLoc EndLoc) {
1761 KindTy Kind = k_RegisterList;
1763 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
1764 Kind = k_DPRRegisterList;
1765 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
1766 contains(Regs.front().first))
1767 Kind = k_SPRRegisterList;
1769 ARMOperand *Op = new ARMOperand(Kind);
1770 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
1771 I = Regs.begin(), E = Regs.end(); I != E; ++I)
1772 Op->Registers.push_back(I->first);
1773 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
1774 Op->StartLoc = StartLoc;
1775 Op->EndLoc = EndLoc;
1779 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
1781 ARMOperand *Op = new ARMOperand(k_VectorList);
1782 Op->VectorList.RegNum = RegNum;
1783 Op->VectorList.Count = Count;
1789 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
1791 ARMOperand *Op = new ARMOperand(k_VectorIndex);
1792 Op->VectorIndex.Val = Idx;
1798 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
1799 ARMOperand *Op = new ARMOperand(k_Immediate);
1806 static ARMOperand *CreateFPImm(unsigned Val, SMLoc S, MCContext &Ctx) {
1807 ARMOperand *Op = new ARMOperand(k_FPImmediate);
1808 Op->FPImm.Val = Val;
1814 static ARMOperand *CreateMem(unsigned BaseRegNum,
1815 const MCConstantExpr *OffsetImm,
1816 unsigned OffsetRegNum,
1817 ARM_AM::ShiftOpc ShiftType,
1822 ARMOperand *Op = new ARMOperand(k_Memory);
1823 Op->Memory.BaseRegNum = BaseRegNum;
1824 Op->Memory.OffsetImm = OffsetImm;
1825 Op->Memory.OffsetRegNum = OffsetRegNum;
1826 Op->Memory.ShiftType = ShiftType;
1827 Op->Memory.ShiftImm = ShiftImm;
1828 Op->Memory.Alignment = Alignment;
1829 Op->Memory.isNegative = isNegative;
1835 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
1836 ARM_AM::ShiftOpc ShiftTy,
1839 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
1840 Op->PostIdxReg.RegNum = RegNum;
1841 Op->PostIdxReg.isAdd = isAdd;
1842 Op->PostIdxReg.ShiftTy = ShiftTy;
1843 Op->PostIdxReg.ShiftImm = ShiftImm;
1849 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
1850 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
1851 Op->MBOpt.Val = Opt;
1857 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
1858 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
1859 Op->IFlags.Val = IFlags;
1865 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
1866 ARMOperand *Op = new ARMOperand(k_MSRMask);
1867 Op->MMask.Val = MMask;
1874 } // end anonymous namespace.
1876 void ARMOperand::print(raw_ostream &OS) const {
1879 OS << "<fpimm " << getFPImm() << "(" << ARM_AM::getFPImmFloat(getFPImm())
1883 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
1886 OS << "<ccout " << getReg() << ">";
1888 case k_ITCondMask: {
1889 static const char *MaskStr[] = {
1890 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
1891 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
1893 assert((ITMask.Mask & 0xf) == ITMask.Mask);
1894 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
1898 OS << "<coprocessor number: " << getCoproc() << ">";
1901 OS << "<coprocessor register: " << getCoproc() << ">";
1903 case k_CoprocOption:
1904 OS << "<coprocessor option: " << CoprocOption.Val << ">";
1907 OS << "<mask: " << getMSRMask() << ">";
1910 getImm()->print(OS);
1912 case k_MemBarrierOpt:
1913 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
1917 << " base:" << Memory.BaseRegNum;
1920 case k_PostIndexRegister:
1921 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
1922 << PostIdxReg.RegNum;
1923 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
1924 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
1925 << PostIdxReg.ShiftImm;
1928 case k_ProcIFlags: {
1929 OS << "<ARM_PROC::";
1930 unsigned IFlags = getProcIFlags();
1931 for (int i=2; i >= 0; --i)
1932 if (IFlags & (1 << i))
1933 OS << ARM_PROC::IFlagsToString(1 << i);
1938 OS << "<register " << getReg() << ">";
1940 case k_ShifterImmediate:
1941 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
1942 << " #" << ShifterImm.Imm << ">";
1944 case k_ShiftedRegister:
1945 OS << "<so_reg_reg "
1946 << RegShiftedReg.SrcReg
1947 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(RegShiftedReg.ShiftImm))
1948 << ", " << RegShiftedReg.ShiftReg << ", "
1949 << ARM_AM::getSORegOffset(RegShiftedReg.ShiftImm)
1952 case k_ShiftedImmediate:
1953 OS << "<so_reg_imm "
1954 << RegShiftedImm.SrcReg
1955 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(RegShiftedImm.ShiftImm))
1956 << ", " << ARM_AM::getSORegOffset(RegShiftedImm.ShiftImm)
1959 case k_RotateImmediate:
1960 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
1962 case k_BitfieldDescriptor:
1963 OS << "<bitfield " << "lsb: " << Bitfield.LSB
1964 << ", width: " << Bitfield.Width << ">";
1966 case k_RegisterList:
1967 case k_DPRRegisterList:
1968 case k_SPRRegisterList: {
1969 OS << "<register_list ";
1971 const SmallVectorImpl<unsigned> &RegList = getRegList();
1972 for (SmallVectorImpl<unsigned>::const_iterator
1973 I = RegList.begin(), E = RegList.end(); I != E; ) {
1975 if (++I < E) OS << ", ";
1982 OS << "<vector_list " << VectorList.Count << " * "
1983 << VectorList.RegNum << ">";
1986 OS << "'" << getToken() << "'";
1989 OS << "<vectorindex " << getVectorIndex() << ">";
1994 /// @name Auto-generated Match Functions
1997 static unsigned MatchRegisterName(StringRef Name);
2001 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2002 SMLoc &StartLoc, SMLoc &EndLoc) {
2003 RegNo = tryParseRegister();
2005 return (RegNo == (unsigned)-1);
2008 /// Try to parse a register name. The token must be an Identifier when called,
2009 /// and if it is a register name the token is eaten and the register number is
2010 /// returned. Otherwise return -1.
2012 int ARMAsmParser::tryParseRegister() {
2013 const AsmToken &Tok = Parser.getTok();
2014 if (Tok.isNot(AsmToken::Identifier)) return -1;
2016 // FIXME: Validate register for the current architecture; we have to do
2017 // validation later, so maybe there is no need for this here.
2018 std::string upperCase = Tok.getString().str();
2019 std::string lowerCase = LowercaseString(upperCase);
2020 unsigned RegNum = MatchRegisterName(lowerCase);
2022 RegNum = StringSwitch<unsigned>(lowerCase)
2023 .Case("r13", ARM::SP)
2024 .Case("r14", ARM::LR)
2025 .Case("r15", ARM::PC)
2026 .Case("ip", ARM::R12)
2029 if (!RegNum) return -1;
2031 Parser.Lex(); // Eat identifier token.
2036 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2037 // If a recoverable error occurs, return 1. If an irrecoverable error
2038 // occurs, return -1. An irrecoverable error is one where tokens have been
2039 // consumed in the process of trying to parse the shifter (i.e., when it is
2040 // indeed a shifter operand, but malformed).
2041 int ARMAsmParser::tryParseShiftRegister(
2042 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2043 SMLoc S = Parser.getTok().getLoc();
2044 const AsmToken &Tok = Parser.getTok();
2045 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2047 std::string upperCase = Tok.getString().str();
2048 std::string lowerCase = LowercaseString(upperCase);
2049 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2050 .Case("lsl", ARM_AM::lsl)
2051 .Case("lsr", ARM_AM::lsr)
2052 .Case("asr", ARM_AM::asr)
2053 .Case("ror", ARM_AM::ror)
2054 .Case("rrx", ARM_AM::rrx)
2055 .Default(ARM_AM::no_shift);
2057 if (ShiftTy == ARM_AM::no_shift)
2060 Parser.Lex(); // Eat the operator.
2062 // The source register for the shift has already been added to the
2063 // operand list, so we need to pop it off and combine it into the shifted
2064 // register operand instead.
2065 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2066 if (!PrevOp->isReg())
2067 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2068 int SrcReg = PrevOp->getReg();
2071 if (ShiftTy == ARM_AM::rrx) {
2072 // RRX Doesn't have an explicit shift amount. The encoder expects
2073 // the shift register to be the same as the source register. Seems odd,
2077 // Figure out if this is shifted by a constant or a register (for non-RRX).
2078 if (Parser.getTok().is(AsmToken::Hash)) {
2079 Parser.Lex(); // Eat hash.
2080 SMLoc ImmLoc = Parser.getTok().getLoc();
2081 const MCExpr *ShiftExpr = 0;
2082 if (getParser().ParseExpression(ShiftExpr)) {
2083 Error(ImmLoc, "invalid immediate shift value");
2086 // The expression must be evaluatable as an immediate.
2087 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2089 Error(ImmLoc, "invalid immediate shift value");
2092 // Range check the immediate.
2093 // lsl, ror: 0 <= imm <= 31
2094 // lsr, asr: 0 <= imm <= 32
2095 Imm = CE->getValue();
2097 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2098 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2099 Error(ImmLoc, "immediate shift value out of range");
2102 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2103 ShiftReg = tryParseRegister();
2104 SMLoc L = Parser.getTok().getLoc();
2105 if (ShiftReg == -1) {
2106 Error (L, "expected immediate or register in shift operand");
2110 Error (Parser.getTok().getLoc(),
2111 "expected immediate or register in shift operand");
2116 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2117 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2119 S, Parser.getTok().getLoc()));
2121 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2122 S, Parser.getTok().getLoc()));
2128 /// Try to parse a register name. The token must be an Identifier when called.
2129 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2130 /// if there is a "writeback". 'true' if it's not a register.
2132 /// TODO this is likely to change to allow different register types and or to
2133 /// parse for a specific register type.
2135 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2136 SMLoc S = Parser.getTok().getLoc();
2137 int RegNo = tryParseRegister();
2141 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2143 const AsmToken &ExclaimTok = Parser.getTok();
2144 if (ExclaimTok.is(AsmToken::Exclaim)) {
2145 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2146 ExclaimTok.getLoc()));
2147 Parser.Lex(); // Eat exclaim token
2151 // Also check for an index operand. This is only legal for vector registers,
2152 // but that'll get caught OK in operand matching, so we don't need to
2153 // explicitly filter everything else out here.
2154 if (Parser.getTok().is(AsmToken::LBrac)) {
2155 SMLoc SIdx = Parser.getTok().getLoc();
2156 Parser.Lex(); // Eat left bracket token.
2158 const MCExpr *ImmVal;
2159 if (getParser().ParseExpression(ImmVal))
2160 return MatchOperand_ParseFail;
2161 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2163 TokError("immediate value expected for vector index");
2164 return MatchOperand_ParseFail;
2167 SMLoc E = Parser.getTok().getLoc();
2168 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2169 Error(E, "']' expected");
2170 return MatchOperand_ParseFail;
2173 Parser.Lex(); // Eat right bracket token.
2175 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2183 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2184 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2186 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2187 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2189 switch (Name.size()) {
2192 if (Name[0] != CoprocOp)
2209 if (Name[0] != CoprocOp || Name[1] != '1')
2213 case '0': return 10;
2214 case '1': return 11;
2215 case '2': return 12;
2216 case '3': return 13;
2217 case '4': return 14;
2218 case '5': return 15;
2226 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2227 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2228 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2229 SMLoc S = Parser.getTok().getLoc();
2230 const AsmToken &Tok = Parser.getTok();
2231 if (!Tok.is(AsmToken::Identifier))
2232 return MatchOperand_NoMatch;
2233 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2234 .Case("eq", ARMCC::EQ)
2235 .Case("ne", ARMCC::NE)
2236 .Case("hs", ARMCC::HS)
2237 .Case("cs", ARMCC::HS)
2238 .Case("lo", ARMCC::LO)
2239 .Case("cc", ARMCC::LO)
2240 .Case("mi", ARMCC::MI)
2241 .Case("pl", ARMCC::PL)
2242 .Case("vs", ARMCC::VS)
2243 .Case("vc", ARMCC::VC)
2244 .Case("hi", ARMCC::HI)
2245 .Case("ls", ARMCC::LS)
2246 .Case("ge", ARMCC::GE)
2247 .Case("lt", ARMCC::LT)
2248 .Case("gt", ARMCC::GT)
2249 .Case("le", ARMCC::LE)
2250 .Case("al", ARMCC::AL)
2253 return MatchOperand_NoMatch;
2254 Parser.Lex(); // Eat the token.
2256 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2258 return MatchOperand_Success;
2261 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2262 /// token must be an Identifier when called, and if it is a coprocessor
2263 /// number, the token is eaten and the operand is added to the operand list.
2264 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2265 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2266 SMLoc S = Parser.getTok().getLoc();
2267 const AsmToken &Tok = Parser.getTok();
2268 if (Tok.isNot(AsmToken::Identifier))
2269 return MatchOperand_NoMatch;
2271 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2273 return MatchOperand_NoMatch;
2275 Parser.Lex(); // Eat identifier token.
2276 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2277 return MatchOperand_Success;
2280 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2281 /// token must be an Identifier when called, and if it is a coprocessor
2282 /// number, the token is eaten and the operand is added to the operand list.
2283 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2284 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2285 SMLoc S = Parser.getTok().getLoc();
2286 const AsmToken &Tok = Parser.getTok();
2287 if (Tok.isNot(AsmToken::Identifier))
2288 return MatchOperand_NoMatch;
2290 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2292 return MatchOperand_NoMatch;
2294 Parser.Lex(); // Eat identifier token.
2295 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2296 return MatchOperand_Success;
2299 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2300 /// coproc_option : '{' imm0_255 '}'
2301 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2302 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2303 SMLoc S = Parser.getTok().getLoc();
2305 // If this isn't a '{', this isn't a coprocessor immediate operand.
2306 if (Parser.getTok().isNot(AsmToken::LCurly))
2307 return MatchOperand_NoMatch;
2308 Parser.Lex(); // Eat the '{'
2311 SMLoc Loc = Parser.getTok().getLoc();
2312 if (getParser().ParseExpression(Expr)) {
2313 Error(Loc, "illegal expression");
2314 return MatchOperand_ParseFail;
2316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2317 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2318 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2319 return MatchOperand_ParseFail;
2321 int Val = CE->getValue();
2323 // Check for and consume the closing '}'
2324 if (Parser.getTok().isNot(AsmToken::RCurly))
2325 return MatchOperand_ParseFail;
2326 SMLoc E = Parser.getTok().getLoc();
2327 Parser.Lex(); // Eat the '}'
2329 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2330 return MatchOperand_Success;
2333 // For register list parsing, we need to map from raw GPR register numbering
2334 // to the enumeration values. The enumeration values aren't sorted by
2335 // register number due to our using "sp", "lr" and "pc" as canonical names.
2336 static unsigned getNextRegister(unsigned Reg) {
2337 // If this is a GPR, we need to do it manually, otherwise we can rely
2338 // on the sort ordering of the enumeration since the other reg-classes
2340 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2343 default: assert(0 && "Invalid GPR number!");
2344 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2345 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2346 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2347 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2348 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2349 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2350 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2351 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2355 /// Parse a register list.
2357 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2358 assert(Parser.getTok().is(AsmToken::LCurly) &&
2359 "Token is not a Left Curly Brace");
2360 SMLoc S = Parser.getTok().getLoc();
2361 Parser.Lex(); // Eat '{' token.
2362 SMLoc RegLoc = Parser.getTok().getLoc();
2364 // Check the first register in the list to see what register class
2365 // this is a list of.
2366 int Reg = tryParseRegister();
2368 return Error(RegLoc, "register expected");
2370 const MCRegisterClass *RC;
2371 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2372 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2373 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2374 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2375 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2376 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2378 return Error(RegLoc, "invalid register in register list");
2380 // The reglist instructions have at most 16 registers, so reserve
2381 // space for that many.
2382 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2383 // Store the first register.
2384 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2386 // This starts immediately after the first register token in the list,
2387 // so we can see either a comma or a minus (range separator) as a legal
2389 while (Parser.getTok().is(AsmToken::Comma) ||
2390 Parser.getTok().is(AsmToken::Minus)) {
2391 if (Parser.getTok().is(AsmToken::Minus)) {
2392 Parser.Lex(); // Eat the comma.
2393 SMLoc EndLoc = Parser.getTok().getLoc();
2394 int EndReg = tryParseRegister();
2396 return Error(EndLoc, "register expected");
2397 // If the register is the same as the start reg, there's nothing
2401 // The register must be in the same register class as the first.
2402 if (!RC->contains(EndReg))
2403 return Error(EndLoc, "invalid register in register list");
2404 // Ranges must go from low to high.
2405 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2406 return Error(EndLoc, "bad range in register list");
2408 // Add all the registers in the range to the register list.
2409 while (Reg != EndReg) {
2410 Reg = getNextRegister(Reg);
2411 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2415 Parser.Lex(); // Eat the comma.
2416 RegLoc = Parser.getTok().getLoc();
2418 Reg = tryParseRegister();
2420 return Error(RegLoc, "register expected");
2421 // The register must be in the same register class as the first.
2422 if (!RC->contains(Reg))
2423 return Error(RegLoc, "invalid register in register list");
2424 // List must be monotonically increasing.
2425 if (getARMRegisterNumbering(Reg) <= getARMRegisterNumbering(OldReg))
2426 return Error(RegLoc, "register list not in ascending order");
2427 // VFP register lists must also be contiguous.
2428 // It's OK to use the enumeration values directly here rather, as the
2429 // VFP register classes have the enum sorted properly.
2430 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2432 return Error(RegLoc, "non-contiguous register range");
2433 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2436 SMLoc E = Parser.getTok().getLoc();
2437 if (Parser.getTok().isNot(AsmToken::RCurly))
2438 return Error(E, "'}' expected");
2439 Parser.Lex(); // Eat '}' token.
2441 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2445 // parse a vector register list
2446 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2447 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2448 if(Parser.getTok().isNot(AsmToken::LCurly))
2449 return MatchOperand_NoMatch;
2451 SMLoc S = Parser.getTok().getLoc();
2452 Parser.Lex(); // Eat '{' token.
2453 SMLoc RegLoc = Parser.getTok().getLoc();
2455 int Reg = tryParseRegister();
2457 Error(RegLoc, "register expected");
2458 return MatchOperand_ParseFail;
2461 unsigned FirstReg = Reg;
2463 while (Parser.getTok().is(AsmToken::Comma)) {
2464 Parser.Lex(); // Eat the comma.
2465 RegLoc = Parser.getTok().getLoc();
2467 Reg = tryParseRegister();
2469 Error(RegLoc, "register expected");
2470 return MatchOperand_ParseFail;
2472 // vector register lists must also be contiguous.
2473 // It's OK to use the enumeration values directly here rather, as the
2474 // VFP register classes have the enum sorted properly.
2475 if (Reg != OldReg + 1) {
2476 Error(RegLoc, "non-contiguous register range");
2477 return MatchOperand_ParseFail;
2483 SMLoc E = Parser.getTok().getLoc();
2484 if (Parser.getTok().isNot(AsmToken::RCurly)) {
2485 Error(E, "'}' expected");
2486 return MatchOperand_ParseFail;
2488 Parser.Lex(); // Eat '}' token.
2490 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count, S, E));
2491 return MatchOperand_Success;
2494 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
2495 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2496 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2497 SMLoc S = Parser.getTok().getLoc();
2498 const AsmToken &Tok = Parser.getTok();
2499 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2500 StringRef OptStr = Tok.getString();
2502 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
2503 .Case("sy", ARM_MB::SY)
2504 .Case("st", ARM_MB::ST)
2505 .Case("sh", ARM_MB::ISH)
2506 .Case("ish", ARM_MB::ISH)
2507 .Case("shst", ARM_MB::ISHST)
2508 .Case("ishst", ARM_MB::ISHST)
2509 .Case("nsh", ARM_MB::NSH)
2510 .Case("un", ARM_MB::NSH)
2511 .Case("nshst", ARM_MB::NSHST)
2512 .Case("unst", ARM_MB::NSHST)
2513 .Case("osh", ARM_MB::OSH)
2514 .Case("oshst", ARM_MB::OSHST)
2518 return MatchOperand_NoMatch;
2520 Parser.Lex(); // Eat identifier token.
2521 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
2522 return MatchOperand_Success;
2525 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
2526 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2527 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2528 SMLoc S = Parser.getTok().getLoc();
2529 const AsmToken &Tok = Parser.getTok();
2530 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2531 StringRef IFlagsStr = Tok.getString();
2533 // An iflags string of "none" is interpreted to mean that none of the AIF
2534 // bits are set. Not a terribly useful instruction, but a valid encoding.
2535 unsigned IFlags = 0;
2536 if (IFlagsStr != "none") {
2537 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
2538 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
2539 .Case("a", ARM_PROC::A)
2540 .Case("i", ARM_PROC::I)
2541 .Case("f", ARM_PROC::F)
2544 // If some specific iflag is already set, it means that some letter is
2545 // present more than once, this is not acceptable.
2546 if (Flag == ~0U || (IFlags & Flag))
2547 return MatchOperand_NoMatch;
2553 Parser.Lex(); // Eat identifier token.
2554 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
2555 return MatchOperand_Success;
2558 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
2559 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2560 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2561 SMLoc S = Parser.getTok().getLoc();
2562 const AsmToken &Tok = Parser.getTok();
2563 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2564 StringRef Mask = Tok.getString();
2567 // See ARMv6-M 10.1.1
2568 unsigned FlagsVal = StringSwitch<unsigned>(Mask)
2578 .Case("primask", 16)
2579 .Case("basepri", 17)
2580 .Case("basepri_max", 18)
2581 .Case("faultmask", 19)
2582 .Case("control", 20)
2585 if (FlagsVal == ~0U)
2586 return MatchOperand_NoMatch;
2588 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
2589 // basepri, basepri_max and faultmask only valid for V7m.
2590 return MatchOperand_NoMatch;
2592 Parser.Lex(); // Eat identifier token.
2593 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
2594 return MatchOperand_Success;
2597 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
2598 size_t Start = 0, Next = Mask.find('_');
2599 StringRef Flags = "";
2600 std::string SpecReg = LowercaseString(Mask.slice(Start, Next));
2601 if (Next != StringRef::npos)
2602 Flags = Mask.slice(Next+1, Mask.size());
2604 // FlagsVal contains the complete mask:
2606 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
2607 unsigned FlagsVal = 0;
2609 if (SpecReg == "apsr") {
2610 FlagsVal = StringSwitch<unsigned>(Flags)
2611 .Case("nzcvq", 0x8) // same as CPSR_f
2612 .Case("g", 0x4) // same as CPSR_s
2613 .Case("nzcvqg", 0xc) // same as CPSR_fs
2616 if (FlagsVal == ~0U) {
2618 return MatchOperand_NoMatch;
2620 FlagsVal = 8; // No flag
2622 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
2623 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
2625 for (int i = 0, e = Flags.size(); i != e; ++i) {
2626 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
2633 // If some specific flag is already set, it means that some letter is
2634 // present more than once, this is not acceptable.
2635 if (FlagsVal == ~0U || (FlagsVal & Flag))
2636 return MatchOperand_NoMatch;
2639 } else // No match for special register.
2640 return MatchOperand_NoMatch;
2642 // Special register without flags is NOT equivalent to "fc" flags.
2643 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
2644 // two lines would enable gas compatibility at the expense of breaking
2650 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
2651 if (SpecReg == "spsr")
2654 Parser.Lex(); // Eat identifier token.
2655 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
2656 return MatchOperand_Success;
2659 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2660 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
2661 int Low, int High) {
2662 const AsmToken &Tok = Parser.getTok();
2663 if (Tok.isNot(AsmToken::Identifier)) {
2664 Error(Parser.getTok().getLoc(), Op + " operand expected.");
2665 return MatchOperand_ParseFail;
2667 StringRef ShiftName = Tok.getString();
2668 std::string LowerOp = LowercaseString(Op);
2669 std::string UpperOp = UppercaseString(Op);
2670 if (ShiftName != LowerOp && ShiftName != UpperOp) {
2671 Error(Parser.getTok().getLoc(), Op + " operand expected.");
2672 return MatchOperand_ParseFail;
2674 Parser.Lex(); // Eat shift type token.
2676 // There must be a '#' and a shift amount.
2677 if (Parser.getTok().isNot(AsmToken::Hash)) {
2678 Error(Parser.getTok().getLoc(), "'#' expected");
2679 return MatchOperand_ParseFail;
2681 Parser.Lex(); // Eat hash token.
2683 const MCExpr *ShiftAmount;
2684 SMLoc Loc = Parser.getTok().getLoc();
2685 if (getParser().ParseExpression(ShiftAmount)) {
2686 Error(Loc, "illegal expression");
2687 return MatchOperand_ParseFail;
2689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
2691 Error(Loc, "constant expression expected");
2692 return MatchOperand_ParseFail;
2694 int Val = CE->getValue();
2695 if (Val < Low || Val > High) {
2696 Error(Loc, "immediate value out of range");
2697 return MatchOperand_ParseFail;
2700 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
2702 return MatchOperand_Success;
2705 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2706 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2707 const AsmToken &Tok = Parser.getTok();
2708 SMLoc S = Tok.getLoc();
2709 if (Tok.isNot(AsmToken::Identifier)) {
2710 Error(Tok.getLoc(), "'be' or 'le' operand expected");
2711 return MatchOperand_ParseFail;
2713 int Val = StringSwitch<int>(Tok.getString())
2717 Parser.Lex(); // Eat the token.
2720 Error(Tok.getLoc(), "'be' or 'le' operand expected");
2721 return MatchOperand_ParseFail;
2723 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
2725 S, Parser.getTok().getLoc()));
2726 return MatchOperand_Success;
2729 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
2730 /// instructions. Legal values are:
2731 /// lsl #n 'n' in [0,31]
2732 /// asr #n 'n' in [1,32]
2733 /// n == 32 encoded as n == 0.
2734 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2735 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2736 const AsmToken &Tok = Parser.getTok();
2737 SMLoc S = Tok.getLoc();
2738 if (Tok.isNot(AsmToken::Identifier)) {
2739 Error(S, "shift operator 'asr' or 'lsl' expected");
2740 return MatchOperand_ParseFail;
2742 StringRef ShiftName = Tok.getString();
2744 if (ShiftName == "lsl" || ShiftName == "LSL")
2746 else if (ShiftName == "asr" || ShiftName == "ASR")
2749 Error(S, "shift operator 'asr' or 'lsl' expected");
2750 return MatchOperand_ParseFail;
2752 Parser.Lex(); // Eat the operator.
2754 // A '#' and a shift amount.
2755 if (Parser.getTok().isNot(AsmToken::Hash)) {
2756 Error(Parser.getTok().getLoc(), "'#' expected");
2757 return MatchOperand_ParseFail;
2759 Parser.Lex(); // Eat hash token.
2761 const MCExpr *ShiftAmount;
2762 SMLoc E = Parser.getTok().getLoc();
2763 if (getParser().ParseExpression(ShiftAmount)) {
2764 Error(E, "malformed shift expression");
2765 return MatchOperand_ParseFail;
2767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
2769 Error(E, "shift amount must be an immediate");
2770 return MatchOperand_ParseFail;
2773 int64_t Val = CE->getValue();
2775 // Shift amount must be in [1,32]
2776 if (Val < 1 || Val > 32) {
2777 Error(E, "'asr' shift amount must be in range [1,32]");
2778 return MatchOperand_ParseFail;
2780 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
2781 if (isThumb() && Val == 32) {
2782 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
2783 return MatchOperand_ParseFail;
2785 if (Val == 32) Val = 0;
2787 // Shift amount must be in [1,32]
2788 if (Val < 0 || Val > 31) {
2789 Error(E, "'lsr' shift amount must be in range [0,31]");
2790 return MatchOperand_ParseFail;
2794 E = Parser.getTok().getLoc();
2795 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
2797 return MatchOperand_Success;
2800 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
2801 /// of instructions. Legal values are:
2802 /// ror #n 'n' in {0, 8, 16, 24}
2803 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2804 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2805 const AsmToken &Tok = Parser.getTok();
2806 SMLoc S = Tok.getLoc();
2807 if (Tok.isNot(AsmToken::Identifier))
2808 return MatchOperand_NoMatch;
2809 StringRef ShiftName = Tok.getString();
2810 if (ShiftName != "ror" && ShiftName != "ROR")
2811 return MatchOperand_NoMatch;
2812 Parser.Lex(); // Eat the operator.
2814 // A '#' and a rotate amount.
2815 if (Parser.getTok().isNot(AsmToken::Hash)) {
2816 Error(Parser.getTok().getLoc(), "'#' expected");
2817 return MatchOperand_ParseFail;
2819 Parser.Lex(); // Eat hash token.
2821 const MCExpr *ShiftAmount;
2822 SMLoc E = Parser.getTok().getLoc();
2823 if (getParser().ParseExpression(ShiftAmount)) {
2824 Error(E, "malformed rotate expression");
2825 return MatchOperand_ParseFail;
2827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
2829 Error(E, "rotate amount must be an immediate");
2830 return MatchOperand_ParseFail;
2833 int64_t Val = CE->getValue();
2834 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
2835 // normally, zero is represented in asm by omitting the rotate operand
2837 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
2838 Error(E, "'ror' rotate amount must be 8, 16, or 24");
2839 return MatchOperand_ParseFail;
2842 E = Parser.getTok().getLoc();
2843 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
2845 return MatchOperand_Success;
2848 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2849 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2850 SMLoc S = Parser.getTok().getLoc();
2851 // The bitfield descriptor is really two operands, the LSB and the width.
2852 if (Parser.getTok().isNot(AsmToken::Hash)) {
2853 Error(Parser.getTok().getLoc(), "'#' expected");
2854 return MatchOperand_ParseFail;
2856 Parser.Lex(); // Eat hash token.
2858 const MCExpr *LSBExpr;
2859 SMLoc E = Parser.getTok().getLoc();
2860 if (getParser().ParseExpression(LSBExpr)) {
2861 Error(E, "malformed immediate expression");
2862 return MatchOperand_ParseFail;
2864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
2866 Error(E, "'lsb' operand must be an immediate");
2867 return MatchOperand_ParseFail;
2870 int64_t LSB = CE->getValue();
2871 // The LSB must be in the range [0,31]
2872 if (LSB < 0 || LSB > 31) {
2873 Error(E, "'lsb' operand must be in the range [0,31]");
2874 return MatchOperand_ParseFail;
2876 E = Parser.getTok().getLoc();
2878 // Expect another immediate operand.
2879 if (Parser.getTok().isNot(AsmToken::Comma)) {
2880 Error(Parser.getTok().getLoc(), "too few operands");
2881 return MatchOperand_ParseFail;
2883 Parser.Lex(); // Eat hash token.
2884 if (Parser.getTok().isNot(AsmToken::Hash)) {
2885 Error(Parser.getTok().getLoc(), "'#' expected");
2886 return MatchOperand_ParseFail;
2888 Parser.Lex(); // Eat hash token.
2890 const MCExpr *WidthExpr;
2891 if (getParser().ParseExpression(WidthExpr)) {
2892 Error(E, "malformed immediate expression");
2893 return MatchOperand_ParseFail;
2895 CE = dyn_cast<MCConstantExpr>(WidthExpr);
2897 Error(E, "'width' operand must be an immediate");
2898 return MatchOperand_ParseFail;
2901 int64_t Width = CE->getValue();
2902 // The LSB must be in the range [1,32-lsb]
2903 if (Width < 1 || Width > 32 - LSB) {
2904 Error(E, "'width' operand must be in the range [1,32-lsb]");
2905 return MatchOperand_ParseFail;
2907 E = Parser.getTok().getLoc();
2909 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
2911 return MatchOperand_Success;
2914 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2915 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2916 // Check for a post-index addressing register operand. Specifically:
2917 // postidx_reg := '+' register {, shift}
2918 // | '-' register {, shift}
2919 // | register {, shift}
2921 // This method must return MatchOperand_NoMatch without consuming any tokens
2922 // in the case where there is no match, as other alternatives take other
2924 AsmToken Tok = Parser.getTok();
2925 SMLoc S = Tok.getLoc();
2926 bool haveEaten = false;
2929 if (Tok.is(AsmToken::Plus)) {
2930 Parser.Lex(); // Eat the '+' token.
2932 } else if (Tok.is(AsmToken::Minus)) {
2933 Parser.Lex(); // Eat the '-' token.
2937 if (Parser.getTok().is(AsmToken::Identifier))
2938 Reg = tryParseRegister();
2941 return MatchOperand_NoMatch;
2942 Error(Parser.getTok().getLoc(), "register expected");
2943 return MatchOperand_ParseFail;
2945 SMLoc E = Parser.getTok().getLoc();
2947 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
2948 unsigned ShiftImm = 0;
2949 if (Parser.getTok().is(AsmToken::Comma)) {
2950 Parser.Lex(); // Eat the ','.
2951 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
2952 return MatchOperand_ParseFail;
2955 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
2958 return MatchOperand_Success;
2961 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2962 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2963 // Check for a post-index addressing register operand. Specifically:
2964 // am3offset := '+' register
2971 // This method must return MatchOperand_NoMatch without consuming any tokens
2972 // in the case where there is no match, as other alternatives take other
2974 AsmToken Tok = Parser.getTok();
2975 SMLoc S = Tok.getLoc();
2977 // Do immediates first, as we always parse those if we have a '#'.
2978 if (Parser.getTok().is(AsmToken::Hash)) {
2979 Parser.Lex(); // Eat the '#'.
2980 // Explicitly look for a '-', as we need to encode negative zero
2982 bool isNegative = Parser.getTok().is(AsmToken::Minus);
2983 const MCExpr *Offset;
2984 if (getParser().ParseExpression(Offset))
2985 return MatchOperand_ParseFail;
2986 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
2988 Error(S, "constant expression expected");
2989 return MatchOperand_ParseFail;
2991 SMLoc E = Tok.getLoc();
2992 // Negative zero is encoded as the flag value INT32_MIN.
2993 int32_t Val = CE->getValue();
2994 if (isNegative && Val == 0)
2998 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3000 return MatchOperand_Success;
3004 bool haveEaten = false;
3007 if (Tok.is(AsmToken::Plus)) {
3008 Parser.Lex(); // Eat the '+' token.
3010 } else if (Tok.is(AsmToken::Minus)) {
3011 Parser.Lex(); // Eat the '-' token.
3015 if (Parser.getTok().is(AsmToken::Identifier))
3016 Reg = tryParseRegister();
3019 return MatchOperand_NoMatch;
3020 Error(Parser.getTok().getLoc(), "register expected");
3021 return MatchOperand_ParseFail;
3023 SMLoc E = Parser.getTok().getLoc();
3025 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3028 return MatchOperand_Success;
3031 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3032 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3033 /// when they refer multiple MIOperands inside a single one.
3035 cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3036 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3038 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3039 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3040 // Create a writeback register dummy placeholder.
3041 Inst.addOperand(MCOperand::CreateReg(0));
3043 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3045 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3049 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3050 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3051 /// when they refer multiple MIOperands inside a single one.
3053 cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3054 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3055 // Create a writeback register dummy placeholder.
3056 Inst.addOperand(MCOperand::CreateReg(0));
3058 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3059 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3061 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3063 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3067 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3068 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3069 /// when they refer multiple MIOperands inside a single one.
3071 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3072 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3073 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3075 // Create a writeback register dummy placeholder.
3076 Inst.addOperand(MCOperand::CreateImm(0));
3078 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3079 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3083 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3084 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3085 /// when they refer multiple MIOperands inside a single one.
3087 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3088 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3089 // Create a writeback register dummy placeholder.
3090 Inst.addOperand(MCOperand::CreateImm(0));
3091 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3092 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3093 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3097 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3098 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3099 /// when they refer multiple MIOperands inside a single one.
3101 cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3102 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3103 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3105 // Create a writeback register dummy placeholder.
3106 Inst.addOperand(MCOperand::CreateImm(0));
3108 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3109 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3113 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3114 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3115 /// when they refer multiple MIOperands inside a single one.
3117 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3118 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3119 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3121 // Create a writeback register dummy placeholder.
3122 Inst.addOperand(MCOperand::CreateImm(0));
3124 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3125 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3130 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3131 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3132 /// when they refer multiple MIOperands inside a single one.
3134 cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3135 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3136 // Create a writeback register dummy placeholder.
3137 Inst.addOperand(MCOperand::CreateImm(0));
3138 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3139 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3140 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3144 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3145 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3146 /// when they refer multiple MIOperands inside a single one.
3148 cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3149 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3150 // Create a writeback register dummy placeholder.
3151 Inst.addOperand(MCOperand::CreateImm(0));
3152 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3153 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3154 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3158 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3159 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3160 /// when they refer multiple MIOperands inside a single one.
3162 cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3163 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3164 // Create a writeback register dummy placeholder.
3165 Inst.addOperand(MCOperand::CreateImm(0));
3166 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3167 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3168 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3172 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3173 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3174 /// when they refer multiple MIOperands inside a single one.
3176 cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3177 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3179 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3180 // Create a writeback register dummy placeholder.
3181 Inst.addOperand(MCOperand::CreateImm(0));
3183 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3185 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3187 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3191 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
3192 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3193 /// when they refer multiple MIOperands inside a single one.
3195 cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3196 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3198 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3199 // Create a writeback register dummy placeholder.
3200 Inst.addOperand(MCOperand::CreateImm(0));
3202 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3204 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3206 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3210 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
3211 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3212 /// when they refer multiple MIOperands inside a single one.
3214 cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3215 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3216 // Create a writeback register dummy placeholder.
3217 Inst.addOperand(MCOperand::CreateImm(0));
3219 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3221 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3223 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3225 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3229 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3230 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3231 /// when they refer multiple MIOperands inside a single one.
3233 cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3234 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3235 // Create a writeback register dummy placeholder.
3236 Inst.addOperand(MCOperand::CreateImm(0));
3238 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3240 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3242 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3244 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3248 /// cvtLdrdPre - Convert parsed operands to MCInst.
3249 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3250 /// when they refer multiple MIOperands inside a single one.
3252 cvtLdrdPre(MCInst &Inst, unsigned Opcode,
3253 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3255 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3256 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3257 // Create a writeback register dummy placeholder.
3258 Inst.addOperand(MCOperand::CreateImm(0));
3260 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3262 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3266 /// cvtStrdPre - Convert parsed operands to MCInst.
3267 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3268 /// when they refer multiple MIOperands inside a single one.
3270 cvtStrdPre(MCInst &Inst, unsigned Opcode,
3271 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3272 // Create a writeback register dummy placeholder.
3273 Inst.addOperand(MCOperand::CreateImm(0));
3275 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3276 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3278 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3280 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3284 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3285 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3286 /// when they refer multiple MIOperands inside a single one.
3288 cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3289 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3290 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3291 // Create a writeback register dummy placeholder.
3292 Inst.addOperand(MCOperand::CreateImm(0));
3293 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3294 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3298 /// cvtThumbMultiple- Convert parsed operands to MCInst.
3299 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3300 /// when they refer multiple MIOperands inside a single one.
3302 cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
3303 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3304 // The second source operand must be the same register as the destination
3306 if (Operands.size() == 6 &&
3307 (((ARMOperand*)Operands[3])->getReg() !=
3308 ((ARMOperand*)Operands[5])->getReg()) &&
3309 (((ARMOperand*)Operands[3])->getReg() !=
3310 ((ARMOperand*)Operands[4])->getReg())) {
3311 Error(Operands[3]->getStartLoc(),
3312 "destination register must match source register");
3315 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3316 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
3317 ((ARMOperand*)Operands[4])->addRegOperands(Inst, 1);
3318 // If we have a three-operand form, use that, else the second source operand
3319 // is just the destination operand again.
3320 if (Operands.size() == 6)
3321 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
3323 Inst.addOperand(Inst.getOperand(0));
3324 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
3329 /// Parse an ARM memory expression, return false if successful else return true
3330 /// or an error. The first token must be a '[' when called.
3332 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3334 assert(Parser.getTok().is(AsmToken::LBrac) &&
3335 "Token is not a Left Bracket");
3336 S = Parser.getTok().getLoc();
3337 Parser.Lex(); // Eat left bracket token.
3339 const AsmToken &BaseRegTok = Parser.getTok();
3340 int BaseRegNum = tryParseRegister();
3341 if (BaseRegNum == -1)
3342 return Error(BaseRegTok.getLoc(), "register expected");
3344 // The next token must either be a comma or a closing bracket.
3345 const AsmToken &Tok = Parser.getTok();
3346 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
3347 return Error(Tok.getLoc(), "malformed memory operand");
3349 if (Tok.is(AsmToken::RBrac)) {
3351 Parser.Lex(); // Eat right bracket token.
3353 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
3354 0, 0, false, S, E));
3356 // If there's a pre-indexing writeback marker, '!', just add it as a token
3357 // operand. It's rather odd, but syntactically valid.
3358 if (Parser.getTok().is(AsmToken::Exclaim)) {
3359 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
3360 Parser.Lex(); // Eat the '!'.
3366 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
3367 Parser.Lex(); // Eat the comma.
3369 // If we have a ':', it's an alignment specifier.
3370 if (Parser.getTok().is(AsmToken::Colon)) {
3371 Parser.Lex(); // Eat the ':'.
3372 E = Parser.getTok().getLoc();
3375 if (getParser().ParseExpression(Expr))
3378 // The expression has to be a constant. Memory references with relocations
3379 // don't come through here, as they use the <label> forms of the relevant
3381 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3383 return Error (E, "constant expression expected");
3386 switch (CE->getValue()) {
3388 return Error(E, "alignment specifier must be 64, 128, or 256 bits");
3389 case 64: Align = 8; break;
3390 case 128: Align = 16; break;
3391 case 256: Align = 32; break;
3394 // Now we should have the closing ']'
3395 E = Parser.getTok().getLoc();
3396 if (Parser.getTok().isNot(AsmToken::RBrac))
3397 return Error(E, "']' expected");
3398 Parser.Lex(); // Eat right bracket token.
3400 // Don't worry about range checking the value here. That's handled by
3401 // the is*() predicates.
3402 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
3403 ARM_AM::no_shift, 0, Align,
3406 // If there's a pre-indexing writeback marker, '!', just add it as a token
3408 if (Parser.getTok().is(AsmToken::Exclaim)) {
3409 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
3410 Parser.Lex(); // Eat the '!'.
3416 // If we have a '#', it's an immediate offset, else assume it's a register
3418 if (Parser.getTok().is(AsmToken::Hash)) {
3419 Parser.Lex(); // Eat the '#'.
3420 E = Parser.getTok().getLoc();
3422 bool isNegative = getParser().getTok().is(AsmToken::Minus);
3423 const MCExpr *Offset;
3424 if (getParser().ParseExpression(Offset))
3427 // The expression has to be a constant. Memory references with relocations
3428 // don't come through here, as they use the <label> forms of the relevant
3430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3432 return Error (E, "constant expression expected");
3434 // If the constant was #-0, represent it as INT32_MIN.
3435 int32_t Val = CE->getValue();
3436 if (isNegative && Val == 0)
3437 CE = MCConstantExpr::Create(INT32_MIN, getContext());
3439 // Now we should have the closing ']'
3440 E = Parser.getTok().getLoc();
3441 if (Parser.getTok().isNot(AsmToken::RBrac))
3442 return Error(E, "']' expected");
3443 Parser.Lex(); // Eat right bracket token.
3445 // Don't worry about range checking the value here. That's handled by
3446 // the is*() predicates.
3447 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
3448 ARM_AM::no_shift, 0, 0,
3451 // If there's a pre-indexing writeback marker, '!', just add it as a token
3453 if (Parser.getTok().is(AsmToken::Exclaim)) {
3454 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
3455 Parser.Lex(); // Eat the '!'.
3461 // The register offset is optionally preceded by a '+' or '-'
3462 bool isNegative = false;
3463 if (Parser.getTok().is(AsmToken::Minus)) {
3465 Parser.Lex(); // Eat the '-'.
3466 } else if (Parser.getTok().is(AsmToken::Plus)) {
3468 Parser.Lex(); // Eat the '+'.
3471 E = Parser.getTok().getLoc();
3472 int OffsetRegNum = tryParseRegister();
3473 if (OffsetRegNum == -1)
3474 return Error(E, "register expected");
3476 // If there's a shift operator, handle it.
3477 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
3478 unsigned ShiftImm = 0;
3479 if (Parser.getTok().is(AsmToken::Comma)) {
3480 Parser.Lex(); // Eat the ','.
3481 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
3485 // Now we should have the closing ']'
3486 E = Parser.getTok().getLoc();
3487 if (Parser.getTok().isNot(AsmToken::RBrac))
3488 return Error(E, "']' expected");
3489 Parser.Lex(); // Eat right bracket token.
3491 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
3492 ShiftType, ShiftImm, 0, isNegative,
3495 // If there's a pre-indexing writeback marker, '!', just add it as a token
3497 if (Parser.getTok().is(AsmToken::Exclaim)) {
3498 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
3499 Parser.Lex(); // Eat the '!'.
3505 /// parseMemRegOffsetShift - one of these two:
3506 /// ( lsl | lsr | asr | ror ) , # shift_amount
3508 /// return true if it parses a shift otherwise it returns false.
3509 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
3511 SMLoc Loc = Parser.getTok().getLoc();
3512 const AsmToken &Tok = Parser.getTok();
3513 if (Tok.isNot(AsmToken::Identifier))
3515 StringRef ShiftName = Tok.getString();
3516 if (ShiftName == "lsl" || ShiftName == "LSL")
3518 else if (ShiftName == "lsr" || ShiftName == "LSR")
3520 else if (ShiftName == "asr" || ShiftName == "ASR")
3522 else if (ShiftName == "ror" || ShiftName == "ROR")
3524 else if (ShiftName == "rrx" || ShiftName == "RRX")
3527 return Error(Loc, "illegal shift operator");
3528 Parser.Lex(); // Eat shift type token.
3530 // rrx stands alone.
3532 if (St != ARM_AM::rrx) {
3533 Loc = Parser.getTok().getLoc();
3534 // A '#' and a shift amount.
3535 const AsmToken &HashTok = Parser.getTok();
3536 if (HashTok.isNot(AsmToken::Hash))
3537 return Error(HashTok.getLoc(), "'#' expected");
3538 Parser.Lex(); // Eat hash token.
3541 if (getParser().ParseExpression(Expr))
3543 // Range check the immediate.
3544 // lsl, ror: 0 <= imm <= 31
3545 // lsr, asr: 0 <= imm <= 32
3546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3548 return Error(Loc, "shift amount must be an immediate");
3549 int64_t Imm = CE->getValue();
3551 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
3552 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
3553 return Error(Loc, "immediate shift value out of range");
3560 /// parseFPImm - A floating point immediate expression operand.
3561 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3562 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3563 SMLoc S = Parser.getTok().getLoc();
3565 if (Parser.getTok().isNot(AsmToken::Hash))
3566 return MatchOperand_NoMatch;
3568 // Disambiguate the VMOV forms that can accept an FP immediate.
3569 // vmov.f32 <sreg>, #imm
3570 // vmov.f64 <dreg>, #imm
3571 // vmov.f32 <dreg>, #imm @ vector f32x2
3572 // vmov.f32 <qreg>, #imm @ vector f32x4
3574 // There are also the NEON VMOV instructions which expect an
3575 // integer constant. Make sure we don't try to parse an FPImm
3577 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
3578 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
3579 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
3580 TyOp->getToken() != ".f64"))
3581 return MatchOperand_NoMatch;
3583 Parser.Lex(); // Eat the '#'.
3585 // Handle negation, as that still comes through as a separate token.
3586 bool isNegative = false;
3587 if (Parser.getTok().is(AsmToken::Minus)) {
3591 const AsmToken &Tok = Parser.getTok();
3592 if (Tok.is(AsmToken::Real)) {
3593 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
3594 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
3595 // If we had a '-' in front, toggle the sign bit.
3596 IntVal ^= (uint64_t)isNegative << 63;
3597 int Val = ARM_AM::getFP64Imm(APInt(64, IntVal));
3598 Parser.Lex(); // Eat the token.
3600 TokError("floating point value out of range");
3601 return MatchOperand_ParseFail;
3603 Operands.push_back(ARMOperand::CreateFPImm(Val, S, getContext()));
3604 return MatchOperand_Success;
3606 if (Tok.is(AsmToken::Integer)) {
3607 int64_t Val = Tok.getIntVal();
3608 Parser.Lex(); // Eat the token.
3609 if (Val > 255 || Val < 0) {
3610 TokError("encoded floating point value out of range");
3611 return MatchOperand_ParseFail;
3613 Operands.push_back(ARMOperand::CreateFPImm(Val, S, getContext()));
3614 return MatchOperand_Success;
3617 TokError("invalid floating point immediate");
3618 return MatchOperand_ParseFail;
3620 /// Parse a arm instruction operand. For now this parses the operand regardless
3621 /// of the mnemonic.
3622 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
3623 StringRef Mnemonic) {
3626 // Check if the current operand has a custom associated parser, if so, try to
3627 // custom parse the operand, or fallback to the general approach.
3628 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
3629 if (ResTy == MatchOperand_Success)
3631 // If there wasn't a custom match, try the generic matcher below. Otherwise,
3632 // there was a match, but an error occurred, in which case, just return that
3633 // the operand parsing failed.
3634 if (ResTy == MatchOperand_ParseFail)
3637 switch (getLexer().getKind()) {
3639 Error(Parser.getTok().getLoc(), "unexpected token in operand");
3641 case AsmToken::Identifier: {
3642 // If this is VMRS, check for the apsr_nzcv operand.
3643 if (!tryParseRegisterWithWriteBack(Operands))
3645 int Res = tryParseShiftRegister(Operands);
3646 if (Res == 0) // success
3648 else if (Res == -1) // irrecoverable error
3650 if (Mnemonic == "vmrs" && Parser.getTok().getString() == "apsr_nzcv") {
3651 S = Parser.getTok().getLoc();
3653 Operands.push_back(ARMOperand::CreateToken("apsr_nzcv", S));
3657 // Fall though for the Identifier case that is not a register or a
3660 case AsmToken::Integer: // things like 1f and 2b as a branch targets
3661 case AsmToken::Dot: { // . as a branch target
3662 // This was not a register so parse other operands that start with an
3663 // identifier (like labels) as expressions and create them as immediates.
3664 const MCExpr *IdVal;
3665 S = Parser.getTok().getLoc();
3666 if (getParser().ParseExpression(IdVal))
3668 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
3669 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
3672 case AsmToken::LBrac:
3673 return parseMemory(Operands);
3674 case AsmToken::LCurly:
3675 return parseRegisterList(Operands);
3676 case AsmToken::Hash: {
3677 // #42 -> immediate.
3678 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
3679 S = Parser.getTok().getLoc();
3681 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3682 const MCExpr *ImmVal;
3683 if (getParser().ParseExpression(ImmVal))
3685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
3687 Error(S, "constant expression expected");
3688 return MatchOperand_ParseFail;
3690 int32_t Val = CE->getValue();
3691 if (isNegative && Val == 0)
3692 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
3693 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
3694 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
3697 case AsmToken::Colon: {
3698 // ":lower16:" and ":upper16:" expression prefixes
3699 // FIXME: Check it's an expression prefix,
3700 // e.g. (FOO - :lower16:BAR) isn't legal.
3701 ARMMCExpr::VariantKind RefKind;
3702 if (parsePrefix(RefKind))
3705 const MCExpr *SubExprVal;
3706 if (getParser().ParseExpression(SubExprVal))
3709 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
3711 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
3712 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
3718 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
3719 // :lower16: and :upper16:.
3720 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
3721 RefKind = ARMMCExpr::VK_ARM_None;
3723 // :lower16: and :upper16: modifiers
3724 assert(getLexer().is(AsmToken::Colon) && "expected a :");
3725 Parser.Lex(); // Eat ':'
3727 if (getLexer().isNot(AsmToken::Identifier)) {
3728 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
3732 StringRef IDVal = Parser.getTok().getIdentifier();
3733 if (IDVal == "lower16") {
3734 RefKind = ARMMCExpr::VK_ARM_LO16;
3735 } else if (IDVal == "upper16") {
3736 RefKind = ARMMCExpr::VK_ARM_HI16;
3738 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
3743 if (getLexer().isNot(AsmToken::Colon)) {
3744 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
3747 Parser.Lex(); // Eat the last ':'
3751 /// \brief Given a mnemonic, split out possible predication code and carry
3752 /// setting letters to form a canonical mnemonic and flags.
3754 // FIXME: Would be nice to autogen this.
3755 // FIXME: This is a bit of a maze of special cases.
3756 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
3757 unsigned &PredicationCode,
3759 unsigned &ProcessorIMod,
3760 StringRef &ITMask) {
3761 PredicationCode = ARMCC::AL;
3762 CarrySetting = false;
3765 // Ignore some mnemonics we know aren't predicated forms.
3767 // FIXME: Would be nice to autogen this.
3768 if ((Mnemonic == "movs" && isThumb()) ||
3769 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
3770 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
3771 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
3772 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
3773 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
3774 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
3775 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal")
3778 // First, split out any predication code. Ignore mnemonics we know aren't
3779 // predicated but do have a carry-set and so weren't caught above.
3780 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
3781 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
3782 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
3783 Mnemonic != "sbcs" && Mnemonic != "rscs") {
3784 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
3785 .Case("eq", ARMCC::EQ)
3786 .Case("ne", ARMCC::NE)
3787 .Case("hs", ARMCC::HS)
3788 .Case("cs", ARMCC::HS)
3789 .Case("lo", ARMCC::LO)
3790 .Case("cc", ARMCC::LO)
3791 .Case("mi", ARMCC::MI)
3792 .Case("pl", ARMCC::PL)
3793 .Case("vs", ARMCC::VS)
3794 .Case("vc", ARMCC::VC)
3795 .Case("hi", ARMCC::HI)
3796 .Case("ls", ARMCC::LS)
3797 .Case("ge", ARMCC::GE)
3798 .Case("lt", ARMCC::LT)
3799 .Case("gt", ARMCC::GT)
3800 .Case("le", ARMCC::LE)
3801 .Case("al", ARMCC::AL)
3804 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
3805 PredicationCode = CC;
3809 // Next, determine if we have a carry setting bit. We explicitly ignore all
3810 // the instructions we know end in 's'.
3811 if (Mnemonic.endswith("s") &&
3812 !(Mnemonic == "cps" || Mnemonic == "mls" ||
3813 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
3814 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
3815 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
3816 Mnemonic == "vrsqrts" || Mnemonic == "srs" ||
3817 (Mnemonic == "movs" && isThumb()))) {
3818 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
3819 CarrySetting = true;
3822 // The "cps" instruction can have a interrupt mode operand which is glued into
3823 // the mnemonic. Check if this is the case, split it and parse the imod op
3824 if (Mnemonic.startswith("cps")) {
3825 // Split out any imod code.
3827 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
3828 .Case("ie", ARM_PROC::IE)
3829 .Case("id", ARM_PROC::ID)
3832 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
3833 ProcessorIMod = IMod;
3837 // The "it" instruction has the condition mask on the end of the mnemonic.
3838 if (Mnemonic.startswith("it")) {
3839 ITMask = Mnemonic.slice(2, Mnemonic.size());
3840 Mnemonic = Mnemonic.slice(0, 2);
3846 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
3847 /// inclusion of carry set or predication code operands.
3849 // FIXME: It would be nice to autogen this.
3851 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
3852 bool &CanAcceptPredicationCode) {
3853 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
3854 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
3855 Mnemonic == "add" || Mnemonic == "adc" ||
3856 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
3857 Mnemonic == "orr" || Mnemonic == "mvn" ||
3858 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
3859 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
3860 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
3861 Mnemonic == "mla" || Mnemonic == "smlal" ||
3862 Mnemonic == "umlal" || Mnemonic == "umull"))) {
3863 CanAcceptCarrySet = true;
3865 CanAcceptCarrySet = false;
3867 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
3868 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
3869 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
3870 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
3871 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
3872 (Mnemonic == "clrex" && !isThumb()) ||
3873 (Mnemonic == "nop" && isThumbOne()) ||
3874 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
3875 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
3876 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
3877 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
3879 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
3880 CanAcceptPredicationCode = false;
3882 CanAcceptPredicationCode = true;
3885 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
3886 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
3887 CanAcceptPredicationCode = false;
3891 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
3892 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3893 // FIXME: This is all horribly hacky. We really need a better way to deal
3894 // with optional operands like this in the matcher table.
3896 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
3897 // another does not. Specifically, the MOVW instruction does not. So we
3898 // special case it here and remove the defaulted (non-setting) cc_out
3899 // operand if that's the instruction we're trying to match.
3901 // We do this as post-processing of the explicit operands rather than just
3902 // conditionally adding the cc_out in the first place because we need
3903 // to check the type of the parsed immediate operand.
3904 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
3905 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
3906 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
3907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
3910 // Register-register 'add' for thumb does not have a cc_out operand
3911 // when there are only two register operands.
3912 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
3913 static_cast<ARMOperand*>(Operands[3])->isReg() &&
3914 static_cast<ARMOperand*>(Operands[4])->isReg() &&
3915 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
3917 // Register-register 'add' for thumb does not have a cc_out operand
3918 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
3919 // have to check the immediate range here since Thumb2 has a variant
3920 // that can handle a different range and has a cc_out operand.
3921 if (((isThumb() && Mnemonic == "add") ||
3922 (isThumbTwo() && Mnemonic == "sub")) &&
3923 Operands.size() == 6 &&
3924 static_cast<ARMOperand*>(Operands[3])->isReg() &&
3925 static_cast<ARMOperand*>(Operands[4])->isReg() &&
3926 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
3927 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
3928 (static_cast<ARMOperand*>(Operands[5])->isReg() ||
3929 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
3931 // For Thumb2, add/sub immediate does not have a cc_out operand for the
3932 // imm0_4095 variant. That's the least-preferred variant when
3933 // selecting via the generic "add" mnemonic, so to know that we
3934 // should remove the cc_out operand, we have to explicitly check that
3935 // it's not one of the other variants. Ugh.
3936 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
3937 Operands.size() == 6 &&
3938 static_cast<ARMOperand*>(Operands[3])->isReg() &&
3939 static_cast<ARMOperand*>(Operands[4])->isReg() &&
3940 static_cast<ARMOperand*>(Operands[5])->isImm()) {
3941 // Nest conditions rather than one big 'if' statement for readability.
3943 // If either register is a high reg, it's either one of the SP
3944 // variants (handled above) or a 32-bit encoding, so we just
3945 // check against T3.
3946 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
3947 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
3948 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
3950 // If both registers are low, we're in an IT block, and the immediate is
3951 // in range, we should use encoding T1 instead, which has a cc_out.
3953 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
3954 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
3955 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
3958 // Otherwise, we use encoding T4, which does not have a cc_out
3963 // The thumb2 multiply instruction doesn't have a CCOut register, so
3964 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
3965 // use the 16-bit encoding or not.
3966 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
3967 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
3968 static_cast<ARMOperand*>(Operands[3])->isReg() &&
3969 static_cast<ARMOperand*>(Operands[4])->isReg() &&
3970 static_cast<ARMOperand*>(Operands[5])->isReg() &&
3971 // If the registers aren't low regs, the destination reg isn't the
3972 // same as one of the source regs, or the cc_out operand is zero
3973 // outside of an IT block, we have to use the 32-bit encoding, so
3974 // remove the cc_out operand.
3975 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
3976 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
3978 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
3979 static_cast<ARMOperand*>(Operands[5])->getReg() &&
3980 static_cast<ARMOperand*>(Operands[3])->getReg() !=
3981 static_cast<ARMOperand*>(Operands[4])->getReg())))
3986 // Register-register 'add/sub' for thumb does not have a cc_out operand
3987 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
3988 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
3989 // right, this will result in better diagnostics (which operand is off)
3991 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
3992 (Operands.size() == 5 || Operands.size() == 6) &&
3993 static_cast<ARMOperand*>(Operands[3])->isReg() &&
3994 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
3995 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4001 /// Parse an arm instruction mnemonic followed by its operands.
4002 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4003 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4004 // Create the leading tokens for the mnemonic, split by '.' characters.
4005 size_t Start = 0, Next = Name.find('.');
4006 StringRef Mnemonic = Name.slice(Start, Next);
4008 // Split out the predication code and carry setting flag from the mnemonic.
4009 unsigned PredicationCode;
4010 unsigned ProcessorIMod;
4013 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4014 ProcessorIMod, ITMask);
4016 // In Thumb1, only the branch (B) instruction can be predicated.
4017 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4018 Parser.EatToEndOfStatement();
4019 return Error(NameLoc, "conditional execution not supported in Thumb1");
4022 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4024 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4025 // is the mask as it will be for the IT encoding if the conditional
4026 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4027 // where the conditional bit0 is zero, the instruction post-processing
4028 // will adjust the mask accordingly.
4029 if (Mnemonic == "it") {
4030 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4031 if (ITMask.size() > 3) {
4032 Parser.EatToEndOfStatement();
4033 return Error(Loc, "too many conditions on IT instruction");
4036 for (unsigned i = ITMask.size(); i != 0; --i) {
4037 char pos = ITMask[i - 1];
4038 if (pos != 't' && pos != 'e') {
4039 Parser.EatToEndOfStatement();
4040 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
4043 if (ITMask[i - 1] == 't')
4046 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
4049 // FIXME: This is all a pretty gross hack. We should automatically handle
4050 // optional operands like this via tblgen.
4052 // Next, add the CCOut and ConditionCode operands, if needed.
4054 // For mnemonics which can ever incorporate a carry setting bit or predication
4055 // code, our matching model involves us always generating CCOut and
4056 // ConditionCode operands to match the mnemonic "as written" and then we let
4057 // the matcher deal with finding the right instruction or generating an
4058 // appropriate error.
4059 bool CanAcceptCarrySet, CanAcceptPredicationCode;
4060 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
4062 // If we had a carry-set on an instruction that can't do that, issue an
4064 if (!CanAcceptCarrySet && CarrySetting) {
4065 Parser.EatToEndOfStatement();
4066 return Error(NameLoc, "instruction '" + Mnemonic +
4067 "' can not set flags, but 's' suffix specified");
4069 // If we had a predication code on an instruction that can't do that, issue an
4071 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4072 Parser.EatToEndOfStatement();
4073 return Error(NameLoc, "instruction '" + Mnemonic +
4074 "' is not predicable, but condition code specified");
4077 // Add the carry setting operand, if necessary.
4078 if (CanAcceptCarrySet) {
4079 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
4080 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
4084 // Add the predication code operand, if necessary.
4085 if (CanAcceptPredicationCode) {
4086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4088 Operands.push_back(ARMOperand::CreateCondCode(
4089 ARMCC::CondCodes(PredicationCode), Loc));
4092 // Add the processor imod operand, if necessary.
4093 if (ProcessorIMod) {
4094 Operands.push_back(ARMOperand::CreateImm(
4095 MCConstantExpr::Create(ProcessorIMod, getContext()),
4099 // Add the remaining tokens in the mnemonic.
4100 while (Next != StringRef::npos) {
4102 Next = Name.find('.', Start + 1);
4103 StringRef ExtraToken = Name.slice(Start, Next);
4105 // For now, we're only parsing Thumb1 (for the most part), so
4106 // just ignore ".n" qualifiers. We'll use them to restrict
4107 // matching when we do Thumb2.
4108 if (ExtraToken != ".n") {
4109 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4110 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4114 // Read the remaining operands.
4115 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4116 // Read the first operand.
4117 if (parseOperand(Operands, Mnemonic)) {
4118 Parser.EatToEndOfStatement();
4122 while (getLexer().is(AsmToken::Comma)) {
4123 Parser.Lex(); // Eat the comma.
4125 // Parse and remember the operand.
4126 if (parseOperand(Operands, Mnemonic)) {
4127 Parser.EatToEndOfStatement();
4133 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4134 SMLoc Loc = getLexer().getLoc();
4135 Parser.EatToEndOfStatement();
4136 return Error(Loc, "unexpected token in argument list");
4139 Parser.Lex(); // Consume the EndOfStatement
4141 // Some instructions, mostly Thumb, have forms for the same mnemonic that
4142 // do and don't have a cc_out optional-def operand. With some spot-checks
4143 // of the operand list, we can figure out which variant we're trying to
4144 // parse and adjust accordingly before actually matching. We shouldn't ever
4145 // try to remove a cc_out operand that was explicitly set on the the
4146 // mnemonic, of course (CarrySetting == true). Reason number #317 the
4147 // table driven matcher doesn't fit well with the ARM instruction set.
4148 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
4149 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4150 Operands.erase(Operands.begin() + 1);
4154 // ARM mode 'blx' need special handling, as the register operand version
4155 // is predicable, but the label operand version is not. So, we can't rely
4156 // on the Mnemonic based checking to correctly figure out when to put
4157 // a k_CondCode operand in the list. If we're trying to match the label
4158 // version, remove the k_CondCode operand here.
4159 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
4160 static_cast<ARMOperand*>(Operands[2])->isImm()) {
4161 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4162 Operands.erase(Operands.begin() + 1);
4166 // The vector-compare-to-zero instructions have a literal token "#0" at
4167 // the end that comes to here as an immediate operand. Convert it to a
4168 // token to play nicely with the matcher.
4169 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
4170 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
4171 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4172 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
4173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
4174 if (CE && CE->getValue() == 0) {
4175 Operands.erase(Operands.begin() + 5);
4176 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
4180 // VCMP{E} does the same thing, but with a different operand count.
4181 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
4182 static_cast<ARMOperand*>(Operands[4])->isImm()) {
4183 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
4184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
4185 if (CE && CE->getValue() == 0) {
4186 Operands.erase(Operands.begin() + 4);
4187 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
4191 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
4192 // end. Convert it to a token here.
4193 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
4194 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4195 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
4196 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
4197 if (CE && CE->getValue() == 0) {
4198 Operands.erase(Operands.begin() + 5);
4199 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
4207 // Validate context-sensitive operand constraints.
4209 // return 'true' if register list contains non-low GPR registers,
4210 // 'false' otherwise. If Reg is in the register list or is HiReg, set
4211 // 'containsReg' to true.
4212 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
4213 unsigned HiReg, bool &containsReg) {
4214 containsReg = false;
4215 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
4216 unsigned OpReg = Inst.getOperand(i).getReg();
4219 // Anything other than a low register isn't legal here.
4220 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
4226 // Check if the specified regisgter is in the register list of the inst,
4227 // starting at the indicated operand number.
4228 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
4229 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
4230 unsigned OpReg = Inst.getOperand(i).getReg();
4237 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
4238 // the ARMInsts array) instead. Getting that here requires awkward
4239 // API changes, though. Better way?
4241 extern const MCInstrDesc ARMInsts[];
4243 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
4244 return ARMInsts[Opcode];
4247 // FIXME: We would really like to be able to tablegen'erate this.
4249 validateInstruction(MCInst &Inst,
4250 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4251 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
4252 SMLoc Loc = Operands[0]->getStartLoc();
4253 // Check the IT block state first.
4254 // NOTE: In Thumb mode, the BKPT instruction has the interesting property of
4255 // being allowed in IT blocks, but not being predicable. It just always
4257 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT) {
4259 if (ITState.FirstCond)
4260 ITState.FirstCond = false;
4262 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
4263 // The instruction must be predicable.
4264 if (!MCID.isPredicable())
4265 return Error(Loc, "instructions in IT block must be predicable");
4266 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
4267 unsigned ITCond = bit ? ITState.Cond :
4268 ARMCC::getOppositeCondition(ITState.Cond);
4269 if (Cond != ITCond) {
4270 // Find the condition code Operand to get its SMLoc information.
4272 for (unsigned i = 1; i < Operands.size(); ++i)
4273 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
4274 CondLoc = Operands[i]->getStartLoc();
4275 return Error(CondLoc, "incorrect condition in IT block; got '" +
4276 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
4277 "', but expected '" +
4278 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
4280 // Check for non-'al' condition codes outside of the IT block.
4281 } else if (isThumbTwo() && MCID.isPredicable() &&
4282 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
4283 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
4284 Inst.getOpcode() != ARM::t2B)
4285 return Error(Loc, "predicated instructions must be in IT block");
4287 switch (Inst.getOpcode()) {
4290 case ARM::LDRD_POST:
4292 // Rt2 must be Rt + 1.
4293 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
4294 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
4296 return Error(Operands[3]->getStartLoc(),
4297 "destination operands must be sequential");
4301 // Rt2 must be Rt + 1.
4302 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
4303 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
4305 return Error(Operands[3]->getStartLoc(),
4306 "source operands must be sequential");
4310 case ARM::STRD_POST:
4312 // Rt2 must be Rt + 1.
4313 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
4314 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
4316 return Error(Operands[3]->getStartLoc(),
4317 "source operands must be sequential");
4322 // width must be in range [1, 32-lsb]
4323 unsigned lsb = Inst.getOperand(2).getImm();
4324 unsigned widthm1 = Inst.getOperand(3).getImm();
4325 if (widthm1 >= 32 - lsb)
4326 return Error(Operands[5]->getStartLoc(),
4327 "bitfield width must be in range [1,32-lsb]");
4331 // If we're parsing Thumb2, the .w variant is available and handles
4332 // most cases that are normally illegal for a Thumb1 LDM
4333 // instruction. We'll make the transformation in processInstruction()
4336 // Thumb LDM instructions are writeback iff the base register is not
4337 // in the register list.
4338 unsigned Rn = Inst.getOperand(0).getReg();
4339 bool hasWritebackToken =
4340 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
4341 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
4342 bool listContainsBase;
4343 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
4344 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
4345 "registers must be in range r0-r7");
4346 // If we should have writeback, then there should be a '!' token.
4347 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
4348 return Error(Operands[2]->getStartLoc(),
4349 "writeback operator '!' expected");
4350 // If we should not have writeback, there must not be a '!'. This is
4351 // true even for the 32-bit wide encodings.
4352 if (listContainsBase && hasWritebackToken)
4353 return Error(Operands[3]->getStartLoc(),
4354 "writeback operator '!' not allowed when base register "
4355 "in register list");
4359 case ARM::t2LDMIA_UPD: {
4360 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
4361 return Error(Operands[4]->getStartLoc(),
4362 "writeback operator '!' not allowed when base register "
4363 "in register list");
4367 bool listContainsBase;
4368 if (checkLowRegisterList(Inst, 3, 0, ARM::PC, listContainsBase))
4369 return Error(Operands[2]->getStartLoc(),
4370 "registers must be in range r0-r7 or pc");
4374 bool listContainsBase;
4375 if (checkLowRegisterList(Inst, 3, 0, ARM::LR, listContainsBase))
4376 return Error(Operands[2]->getStartLoc(),
4377 "registers must be in range r0-r7 or lr");
4380 case ARM::tSTMIA_UPD: {
4381 bool listContainsBase;
4382 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
4383 return Error(Operands[4]->getStartLoc(),
4384 "registers must be in range r0-r7");
4393 processInstruction(MCInst &Inst,
4394 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4395 switch (Inst.getOpcode()) {
4396 case ARM::LDMIA_UPD:
4397 // If this is a load of a single register via a 'pop', then we should use
4398 // a post-indexed LDR instruction instead, per the ARM ARM.
4399 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
4400 Inst.getNumOperands() == 5) {
4402 TmpInst.setOpcode(ARM::LDR_POST_IMM);
4403 TmpInst.addOperand(Inst.getOperand(4)); // Rt
4404 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
4405 TmpInst.addOperand(Inst.getOperand(1)); // Rn
4406 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
4407 TmpInst.addOperand(MCOperand::CreateImm(4));
4408 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
4409 TmpInst.addOperand(Inst.getOperand(3));
4413 case ARM::STMDB_UPD:
4414 // If this is a store of a single register via a 'push', then we should use
4415 // a pre-indexed STR instruction instead, per the ARM ARM.
4416 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
4417 Inst.getNumOperands() == 5) {
4419 TmpInst.setOpcode(ARM::STR_PRE_IMM);
4420 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
4421 TmpInst.addOperand(Inst.getOperand(4)); // Rt
4422 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
4423 TmpInst.addOperand(MCOperand::CreateImm(-4));
4424 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
4425 TmpInst.addOperand(Inst.getOperand(3));
4430 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
4431 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
4432 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
4433 // to encoding T1 if <Rd> is omitted."
4434 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6)
4435 Inst.setOpcode(ARM::tADDi3);
4438 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
4439 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
4440 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
4441 // to encoding T1 if <Rd> is omitted."
4442 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6)
4443 Inst.setOpcode(ARM::tSUBi3);
4446 // A Thumb conditional branch outside of an IT block is a tBcc.
4447 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock())
4448 Inst.setOpcode(ARM::tBcc);
4451 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
4452 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock())
4453 Inst.setOpcode(ARM::t2Bcc);
4456 // If the conditional is AL or we're in an IT block, we really want t2B.
4457 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock())
4458 Inst.setOpcode(ARM::t2B);
4461 // If the conditional is AL, we really want tB.
4462 if (Inst.getOperand(1).getImm() == ARMCC::AL)
4463 Inst.setOpcode(ARM::tB);
4466 // If the register list contains any high registers, or if the writeback
4467 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
4468 // instead if we're in Thumb2. Otherwise, this should have generated
4469 // an error in validateInstruction().
4470 unsigned Rn = Inst.getOperand(0).getReg();
4471 bool hasWritebackToken =
4472 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
4473 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
4474 bool listContainsBase;
4475 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
4476 (!listContainsBase && !hasWritebackToken) ||
4477 (listContainsBase && hasWritebackToken)) {
4478 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
4479 assert (isThumbTwo());
4480 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
4481 // If we're switching to the updating version, we need to insert
4482 // the writeback tied operand.
4483 if (hasWritebackToken)
4484 Inst.insert(Inst.begin(),
4485 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
4489 case ARM::tSTMIA_UPD: {
4490 // If the register list contains any high registers, we need to use
4491 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
4492 // should have generated an error in validateInstruction().
4493 unsigned Rn = Inst.getOperand(0).getReg();
4494 bool listContainsBase;
4495 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
4496 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
4497 assert (isThumbTwo());
4498 Inst.setOpcode(ARM::t2STMIA_UPD);
4503 // If we can use the 16-bit encoding and the user didn't explicitly
4504 // request the 32-bit variant, transform it here.
4505 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
4506 Inst.getOperand(1).getImm() <= 255 &&
4507 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
4508 Inst.getOperand(4).getReg() == ARM::CPSR) ||
4509 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
4510 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
4511 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
4512 // The operands aren't in the same order for tMOVi8...
4514 TmpInst.setOpcode(ARM::tMOVi8);
4515 TmpInst.addOperand(Inst.getOperand(0));
4516 TmpInst.addOperand(Inst.getOperand(4));
4517 TmpInst.addOperand(Inst.getOperand(1));
4518 TmpInst.addOperand(Inst.getOperand(2));
4519 TmpInst.addOperand(Inst.getOperand(3));
4525 // If we can use the 16-bit encoding and the user didn't explicitly
4526 // request the 32-bit variant, transform it here.
4527 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
4528 isARMLowRegister(Inst.getOperand(1).getReg()) &&
4529 Inst.getOperand(2).getImm() == ARMCC::AL &&
4530 Inst.getOperand(4).getReg() == ARM::CPSR &&
4531 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
4532 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
4533 // The operands aren't the same for tMOV[S]r... (no cc_out)
4535 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
4536 TmpInst.addOperand(Inst.getOperand(0));
4537 TmpInst.addOperand(Inst.getOperand(1));
4538 TmpInst.addOperand(Inst.getOperand(2));
4539 TmpInst.addOperand(Inst.getOperand(3));
4548 // If we can use the 16-bit encoding and the user didn't explicitly
4549 // request the 32-bit variant, transform it here.
4550 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
4551 isARMLowRegister(Inst.getOperand(1).getReg()) &&
4552 Inst.getOperand(2).getImm() == 0 &&
4553 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
4554 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
4556 switch (Inst.getOpcode()) {
4557 default: llvm_unreachable("Illegal opcode!");
4558 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
4559 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
4560 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
4561 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
4563 // The operands aren't the same for thumb1 (no rotate operand).
4565 TmpInst.setOpcode(NewOpc);
4566 TmpInst.addOperand(Inst.getOperand(0));
4567 TmpInst.addOperand(Inst.getOperand(1));
4568 TmpInst.addOperand(Inst.getOperand(3));
4569 TmpInst.addOperand(Inst.getOperand(4));
4575 // The mask bits for all but the first condition are represented as
4576 // the low bit of the condition code value implies 't'. We currently
4577 // always have 1 implies 't', so XOR toggle the bits if the low bit
4578 // of the condition code is zero. The encoding also expects the low
4579 // bit of the condition to be encoded as bit 4 of the mask operand,
4580 // so mask that in if needed
4581 MCOperand &MO = Inst.getOperand(1);
4582 unsigned Mask = MO.getImm();
4583 unsigned OrigMask = Mask;
4584 unsigned TZ = CountTrailingZeros_32(Mask);
4585 if ((Inst.getOperand(0).getImm() & 1) == 0) {
4586 assert(Mask && TZ <= 3 && "illegal IT mask value!");
4587 for (unsigned i = 3; i != TZ; --i)
4593 // Set up the IT block state according to the IT instruction we just
4595 assert(!inITBlock() && "nested IT blocks?!");
4596 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
4597 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
4598 ITState.CurPosition = 0;
4599 ITState.FirstCond = true;
4605 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
4606 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
4607 // suffix depending on whether they're in an IT block or not.
4608 unsigned Opc = Inst.getOpcode();
4609 const MCInstrDesc &MCID = getInstDesc(Opc);
4610 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
4611 assert(MCID.hasOptionalDef() &&
4612 "optionally flag setting instruction missing optional def operand");
4613 assert(MCID.NumOperands == Inst.getNumOperands() &&
4614 "operand count mismatch!");
4615 // Find the optional-def operand (cc_out).
4618 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
4621 // If we're parsing Thumb1, reject it completely.
4622 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
4623 return Match_MnemonicFail;
4624 // If we're parsing Thumb2, which form is legal depends on whether we're
4626 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
4628 return Match_RequiresITBlock;
4629 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
4631 return Match_RequiresNotITBlock;
4633 // Some high-register supporting Thumb1 encodings only allow both registers
4634 // to be from r0-r7 when in Thumb2.
4635 else if (Opc == ARM::tADDhirr && isThumbOne() &&
4636 isARMLowRegister(Inst.getOperand(1).getReg()) &&
4637 isARMLowRegister(Inst.getOperand(2).getReg()))
4638 return Match_RequiresThumb2;
4639 // Others only require ARMv6 or later.
4640 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
4641 isARMLowRegister(Inst.getOperand(0).getReg()) &&
4642 isARMLowRegister(Inst.getOperand(1).getReg()))
4643 return Match_RequiresV6;
4644 return Match_Success;
4648 MatchAndEmitInstruction(SMLoc IDLoc,
4649 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4653 unsigned MatchResult;
4654 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
4655 switch (MatchResult) {
4658 // Context sensitive operand constraints aren't handled by the matcher,
4659 // so check them here.
4660 if (validateInstruction(Inst, Operands)) {
4661 // Still progress the IT block, otherwise one wrong condition causes
4662 // nasty cascading errors.
4663 forwardITPosition();
4667 // Some instructions need post-processing to, for example, tweak which
4668 // encoding is selected.
4669 processInstruction(Inst, Operands);
4671 // Only move forward at the very end so that everything in validate
4672 // and process gets a consistent answer about whether we're in an IT
4674 forwardITPosition();
4676 Out.EmitInstruction(Inst);
4678 case Match_MissingFeature:
4679 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
4681 case Match_InvalidOperand: {
4682 SMLoc ErrorLoc = IDLoc;
4683 if (ErrorInfo != ~0U) {
4684 if (ErrorInfo >= Operands.size())
4685 return Error(IDLoc, "too few operands for instruction");
4687 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
4688 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
4691 return Error(ErrorLoc, "invalid operand for instruction");
4693 case Match_MnemonicFail:
4694 return Error(IDLoc, "invalid instruction");
4695 case Match_ConversionFail:
4696 // The converter function will have already emited a diagnostic.
4698 case Match_RequiresNotITBlock:
4699 return Error(IDLoc, "flag setting instruction only valid outside IT block");
4700 case Match_RequiresITBlock:
4701 return Error(IDLoc, "instruction only valid inside IT block");
4702 case Match_RequiresV6:
4703 return Error(IDLoc, "instruction variant requires ARMv6 or later");
4704 case Match_RequiresThumb2:
4705 return Error(IDLoc, "instruction variant requires Thumb2");
4708 llvm_unreachable("Implement any new match types added!");
4712 /// parseDirective parses the arm specific directives
4713 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
4714 StringRef IDVal = DirectiveID.getIdentifier();
4715 if (IDVal == ".word")
4716 return parseDirectiveWord(4, DirectiveID.getLoc());
4717 else if (IDVal == ".thumb")
4718 return parseDirectiveThumb(DirectiveID.getLoc());
4719 else if (IDVal == ".thumb_func")
4720 return parseDirectiveThumbFunc(DirectiveID.getLoc());
4721 else if (IDVal == ".code")
4722 return parseDirectiveCode(DirectiveID.getLoc());
4723 else if (IDVal == ".syntax")
4724 return parseDirectiveSyntax(DirectiveID.getLoc());
4728 /// parseDirectiveWord
4729 /// ::= .word [ expression (, expression)* ]
4730 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
4731 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4733 const MCExpr *Value;
4734 if (getParser().ParseExpression(Value))
4737 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
4739 if (getLexer().is(AsmToken::EndOfStatement))
4742 // FIXME: Improve diagnostic.
4743 if (getLexer().isNot(AsmToken::Comma))
4744 return Error(L, "unexpected token in directive");
4753 /// parseDirectiveThumb
4755 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
4756 if (getLexer().isNot(AsmToken::EndOfStatement))
4757 return Error(L, "unexpected token in directive");
4760 // TODO: set thumb mode
4761 // TODO: tell the MC streamer the mode
4762 // getParser().getStreamer().Emit???();
4766 /// parseDirectiveThumbFunc
4767 /// ::= .thumbfunc symbol_name
4768 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
4769 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
4770 bool isMachO = MAI.hasSubsectionsViaSymbols();
4773 // Darwin asm has function name after .thumb_func direction
4776 const AsmToken &Tok = Parser.getTok();
4777 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
4778 return Error(L, "unexpected token in .thumb_func directive");
4779 Name = Tok.getString();
4780 Parser.Lex(); // Consume the identifier token.
4783 if (getLexer().isNot(AsmToken::EndOfStatement))
4784 return Error(L, "unexpected token in directive");
4787 // FIXME: assuming function name will be the line following .thumb_func
4789 Name = Parser.getTok().getString();
4792 // Mark symbol as a thumb symbol.
4793 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
4794 getParser().getStreamer().EmitThumbFunc(Func);
4798 /// parseDirectiveSyntax
4799 /// ::= .syntax unified | divided
4800 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
4801 const AsmToken &Tok = Parser.getTok();
4802 if (Tok.isNot(AsmToken::Identifier))
4803 return Error(L, "unexpected token in .syntax directive");
4804 StringRef Mode = Tok.getString();
4805 if (Mode == "unified" || Mode == "UNIFIED")
4807 else if (Mode == "divided" || Mode == "DIVIDED")
4808 return Error(L, "'.syntax divided' arm asssembly not supported");
4810 return Error(L, "unrecognized syntax mode in .syntax directive");
4812 if (getLexer().isNot(AsmToken::EndOfStatement))
4813 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
4816 // TODO tell the MC streamer the mode
4817 // getParser().getStreamer().Emit???();
4821 /// parseDirectiveCode
4822 /// ::= .code 16 | 32
4823 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
4824 const AsmToken &Tok = Parser.getTok();
4825 if (Tok.isNot(AsmToken::Integer))
4826 return Error(L, "unexpected token in .code directive");
4827 int64_t Val = Parser.getTok().getIntVal();
4833 return Error(L, "invalid operand to .code directive");
4835 if (getLexer().isNot(AsmToken::EndOfStatement))
4836 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
4842 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
4846 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
4852 extern "C" void LLVMInitializeARMAsmLexer();
4854 /// Force static initialization.
4855 extern "C" void LLVMInitializeARMAsmParser() {
4856 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
4857 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
4858 LLVMInitializeARMAsmLexer();
4861 #define GET_REGISTER_MATCHER
4862 #define GET_MATCHER_IMPLEMENTATION
4863 #include "ARMGenAsmMatcher.inc"