| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 1 | //===-- PPCAsmParser.cpp - Parse PowerPC asm to MCInst instructions -------===// |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 10 | #include "MCTargetDesc/PPCMCExpr.h" |
| Benjamin Kramer | b3e8a6d | 2016-01-27 10:01:28 +0000 | [diff] [blame] | 11 | #include "MCTargetDesc/PPCMCTargetDesc.h" |
| Rafael Espindola | 6b9ee9b | 2014-01-25 02:35:56 +0000 | [diff] [blame] | 12 | #include "PPCTargetStreamer.h" |
| Craig Topper | 690d8ea | 2013-07-24 07:33:14 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/STLExtras.h" |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringSwitch.h" |
| 15 | #include "llvm/ADT/Twine.h" |
| Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCContext.h" |
| Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
| 18 | #include "llvm/MC/MCInst.h" |
| 19 | #include "llvm/MC/MCInstrInfo.h" |
| 20 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 21 | #include "llvm/MC/MCParser/MCAsmParser.h" |
| 22 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" |
| Benjamin Kramer | b3e8a6d | 2016-01-27 10:01:28 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCParser/MCTargetAsmParser.h" |
| Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCRegisterInfo.h" |
| 25 | #include "llvm/MC/MCStreamer.h" |
| 26 | #include "llvm/MC/MCSubtargetInfo.h" |
| Benjamin Kramer | b3e8a6d | 2016-01-27 10:01:28 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCSymbolELF.h" |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 28 | #include "llvm/Support/SourceMgr.h" |
| 29 | #include "llvm/Support/TargetRegistry.h" |
| 30 | #include "llvm/Support/raw_ostream.h" |
| 31 | |
| 32 | using namespace llvm; |
| 33 | |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 34 | static const MCPhysReg RRegs[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 35 | PPC::R0, PPC::R1, PPC::R2, PPC::R3, |
| 36 | PPC::R4, PPC::R5, PPC::R6, PPC::R7, |
| 37 | PPC::R8, PPC::R9, PPC::R10, PPC::R11, |
| 38 | PPC::R12, PPC::R13, PPC::R14, PPC::R15, |
| 39 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 40 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 41 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 42 | PPC::R28, PPC::R29, PPC::R30, PPC::R31 |
| 43 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 44 | static const MCPhysReg RRegsNoR0[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 45 | PPC::ZERO, |
| 46 | PPC::R1, PPC::R2, PPC::R3, |
| 47 | PPC::R4, PPC::R5, PPC::R6, PPC::R7, |
| 48 | PPC::R8, PPC::R9, PPC::R10, PPC::R11, |
| 49 | PPC::R12, PPC::R13, PPC::R14, PPC::R15, |
| 50 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 51 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 52 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 53 | PPC::R28, PPC::R29, PPC::R30, PPC::R31 |
| 54 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 55 | static const MCPhysReg XRegs[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 56 | PPC::X0, PPC::X1, PPC::X2, PPC::X3, |
| 57 | PPC::X4, PPC::X5, PPC::X6, PPC::X7, |
| 58 | PPC::X8, PPC::X9, PPC::X10, PPC::X11, |
| 59 | PPC::X12, PPC::X13, PPC::X14, PPC::X15, |
| 60 | PPC::X16, PPC::X17, PPC::X18, PPC::X19, |
| 61 | PPC::X20, PPC::X21, PPC::X22, PPC::X23, |
| 62 | PPC::X24, PPC::X25, PPC::X26, PPC::X27, |
| 63 | PPC::X28, PPC::X29, PPC::X30, PPC::X31 |
| 64 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 65 | static const MCPhysReg XRegsNoX0[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 66 | PPC::ZERO8, |
| 67 | PPC::X1, PPC::X2, PPC::X3, |
| 68 | PPC::X4, PPC::X5, PPC::X6, PPC::X7, |
| 69 | PPC::X8, PPC::X9, PPC::X10, PPC::X11, |
| 70 | PPC::X12, PPC::X13, PPC::X14, PPC::X15, |
| 71 | PPC::X16, PPC::X17, PPC::X18, PPC::X19, |
| 72 | PPC::X20, PPC::X21, PPC::X22, PPC::X23, |
| 73 | PPC::X24, PPC::X25, PPC::X26, PPC::X27, |
| 74 | PPC::X28, PPC::X29, PPC::X30, PPC::X31 |
| 75 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 76 | static const MCPhysReg FRegs[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 77 | PPC::F0, PPC::F1, PPC::F2, PPC::F3, |
| 78 | PPC::F4, PPC::F5, PPC::F6, PPC::F7, |
| 79 | PPC::F8, PPC::F9, PPC::F10, PPC::F11, |
| 80 | PPC::F12, PPC::F13, PPC::F14, PPC::F15, |
| 81 | PPC::F16, PPC::F17, PPC::F18, PPC::F19, |
| 82 | PPC::F20, PPC::F21, PPC::F22, PPC::F23, |
| 83 | PPC::F24, PPC::F25, PPC::F26, PPC::F27, |
| 84 | PPC::F28, PPC::F29, PPC::F30, PPC::F31 |
| 85 | }; |
| Nemanja Ivanovic | 11049f8 | 2016-10-04 06:59:23 +0000 | [diff] [blame] | 86 | static const MCPhysReg VFRegs[32] = { |
| 87 | PPC::VF0, PPC::VF1, PPC::VF2, PPC::VF3, |
| 88 | PPC::VF4, PPC::VF5, PPC::VF6, PPC::VF7, |
| 89 | PPC::VF8, PPC::VF9, PPC::VF10, PPC::VF11, |
| 90 | PPC::VF12, PPC::VF13, PPC::VF14, PPC::VF15, |
| 91 | PPC::VF16, PPC::VF17, PPC::VF18, PPC::VF19, |
| 92 | PPC::VF20, PPC::VF21, PPC::VF22, PPC::VF23, |
| 93 | PPC::VF24, PPC::VF25, PPC::VF26, PPC::VF27, |
| 94 | PPC::VF28, PPC::VF29, PPC::VF30, PPC::VF31 |
| 95 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 96 | static const MCPhysReg VRegs[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 97 | PPC::V0, PPC::V1, PPC::V2, PPC::V3, |
| 98 | PPC::V4, PPC::V5, PPC::V6, PPC::V7, |
| 99 | PPC::V8, PPC::V9, PPC::V10, PPC::V11, |
| 100 | PPC::V12, PPC::V13, PPC::V14, PPC::V15, |
| 101 | PPC::V16, PPC::V17, PPC::V18, PPC::V19, |
| 102 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 103 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 104 | PPC::V28, PPC::V29, PPC::V30, PPC::V31 |
| 105 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 106 | static const MCPhysReg VSRegs[64] = { |
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 107 | PPC::VSL0, PPC::VSL1, PPC::VSL2, PPC::VSL3, |
| 108 | PPC::VSL4, PPC::VSL5, PPC::VSL6, PPC::VSL7, |
| 109 | PPC::VSL8, PPC::VSL9, PPC::VSL10, PPC::VSL11, |
| 110 | PPC::VSL12, PPC::VSL13, PPC::VSL14, PPC::VSL15, |
| 111 | PPC::VSL16, PPC::VSL17, PPC::VSL18, PPC::VSL19, |
| 112 | PPC::VSL20, PPC::VSL21, PPC::VSL22, PPC::VSL23, |
| 113 | PPC::VSL24, PPC::VSL25, PPC::VSL26, PPC::VSL27, |
| 114 | PPC::VSL28, PPC::VSL29, PPC::VSL30, PPC::VSL31, |
| 115 | |
| Nemanja Ivanovic | 11049f8 | 2016-10-04 06:59:23 +0000 | [diff] [blame] | 116 | PPC::V0, PPC::V1, PPC::V2, PPC::V3, |
| 117 | PPC::V4, PPC::V5, PPC::V6, PPC::V7, |
| 118 | PPC::V8, PPC::V9, PPC::V10, PPC::V11, |
| 119 | PPC::V12, PPC::V13, PPC::V14, PPC::V15, |
| 120 | PPC::V16, PPC::V17, PPC::V18, PPC::V19, |
| 121 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 122 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 123 | PPC::V28, PPC::V29, PPC::V30, PPC::V31 |
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 124 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 125 | static const MCPhysReg VSFRegs[64] = { |
| Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 126 | PPC::F0, PPC::F1, PPC::F2, PPC::F3, |
| 127 | PPC::F4, PPC::F5, PPC::F6, PPC::F7, |
| 128 | PPC::F8, PPC::F9, PPC::F10, PPC::F11, |
| 129 | PPC::F12, PPC::F13, PPC::F14, PPC::F15, |
| 130 | PPC::F16, PPC::F17, PPC::F18, PPC::F19, |
| 131 | PPC::F20, PPC::F21, PPC::F22, PPC::F23, |
| 132 | PPC::F24, PPC::F25, PPC::F26, PPC::F27, |
| 133 | PPC::F28, PPC::F29, PPC::F30, PPC::F31, |
| 134 | |
| 135 | PPC::VF0, PPC::VF1, PPC::VF2, PPC::VF3, |
| 136 | PPC::VF4, PPC::VF5, PPC::VF6, PPC::VF7, |
| 137 | PPC::VF8, PPC::VF9, PPC::VF10, PPC::VF11, |
| 138 | PPC::VF12, PPC::VF13, PPC::VF14, PPC::VF15, |
| 139 | PPC::VF16, PPC::VF17, PPC::VF18, PPC::VF19, |
| 140 | PPC::VF20, PPC::VF21, PPC::VF22, PPC::VF23, |
| 141 | PPC::VF24, PPC::VF25, PPC::VF26, PPC::VF27, |
| 142 | PPC::VF28, PPC::VF29, PPC::VF30, PPC::VF31 |
| 143 | }; |
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 144 | static const MCPhysReg VSSRegs[64] = { |
| 145 | PPC::F0, PPC::F1, PPC::F2, PPC::F3, |
| 146 | PPC::F4, PPC::F5, PPC::F6, PPC::F7, |
| 147 | PPC::F8, PPC::F9, PPC::F10, PPC::F11, |
| 148 | PPC::F12, PPC::F13, PPC::F14, PPC::F15, |
| 149 | PPC::F16, PPC::F17, PPC::F18, PPC::F19, |
| 150 | PPC::F20, PPC::F21, PPC::F22, PPC::F23, |
| 151 | PPC::F24, PPC::F25, PPC::F26, PPC::F27, |
| 152 | PPC::F28, PPC::F29, PPC::F30, PPC::F31, |
| 153 | |
| 154 | PPC::VF0, PPC::VF1, PPC::VF2, PPC::VF3, |
| 155 | PPC::VF4, PPC::VF5, PPC::VF6, PPC::VF7, |
| 156 | PPC::VF8, PPC::VF9, PPC::VF10, PPC::VF11, |
| 157 | PPC::VF12, PPC::VF13, PPC::VF14, PPC::VF15, |
| 158 | PPC::VF16, PPC::VF17, PPC::VF18, PPC::VF19, |
| 159 | PPC::VF20, PPC::VF21, PPC::VF22, PPC::VF23, |
| 160 | PPC::VF24, PPC::VF25, PPC::VF26, PPC::VF27, |
| 161 | PPC::VF28, PPC::VF29, PPC::VF30, PPC::VF31 |
| 162 | }; |
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 163 | static unsigned QFRegs[32] = { |
| 164 | PPC::QF0, PPC::QF1, PPC::QF2, PPC::QF3, |
| 165 | PPC::QF4, PPC::QF5, PPC::QF6, PPC::QF7, |
| 166 | PPC::QF8, PPC::QF9, PPC::QF10, PPC::QF11, |
| 167 | PPC::QF12, PPC::QF13, PPC::QF14, PPC::QF15, |
| 168 | PPC::QF16, PPC::QF17, PPC::QF18, PPC::QF19, |
| 169 | PPC::QF20, PPC::QF21, PPC::QF22, PPC::QF23, |
| 170 | PPC::QF24, PPC::QF25, PPC::QF26, PPC::QF27, |
| 171 | PPC::QF28, PPC::QF29, PPC::QF30, PPC::QF31 |
| 172 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 173 | static const MCPhysReg CRBITRegs[32] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 174 | PPC::CR0LT, PPC::CR0GT, PPC::CR0EQ, PPC::CR0UN, |
| 175 | PPC::CR1LT, PPC::CR1GT, PPC::CR1EQ, PPC::CR1UN, |
| 176 | PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, |
| 177 | PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, |
| 178 | PPC::CR4LT, PPC::CR4GT, PPC::CR4EQ, PPC::CR4UN, |
| 179 | PPC::CR5LT, PPC::CR5GT, PPC::CR5EQ, PPC::CR5UN, |
| 180 | PPC::CR6LT, PPC::CR6GT, PPC::CR6EQ, PPC::CR6UN, |
| 181 | PPC::CR7LT, PPC::CR7GT, PPC::CR7EQ, PPC::CR7UN |
| 182 | }; |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 183 | static const MCPhysReg CRRegs[8] = { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 184 | PPC::CR0, PPC::CR1, PPC::CR2, PPC::CR3, |
| 185 | PPC::CR4, PPC::CR5, PPC::CR6, PPC::CR7 |
| 186 | }; |
| 187 | |
| Ulrich Weigand | b86cb7d | 2013-07-04 14:24:00 +0000 | [diff] [blame] | 188 | // Evaluate an expression containing condition register |
| 189 | // or condition register field symbols. Returns positive |
| 190 | // value on success, or -1 on error. |
| 191 | static int64_t |
| 192 | EvaluateCRExpr(const MCExpr *E) { |
| 193 | switch (E->getKind()) { |
| 194 | case MCExpr::Target: |
| 195 | return -1; |
| 196 | |
| 197 | case MCExpr::Constant: { |
| 198 | int64_t Res = cast<MCConstantExpr>(E)->getValue(); |
| 199 | return Res < 0 ? -1 : Res; |
| 200 | } |
| 201 | |
| 202 | case MCExpr::SymbolRef: { |
| 203 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E); |
| 204 | StringRef Name = SRE->getSymbol().getName(); |
| 205 | |
| 206 | if (Name == "lt") return 0; |
| 207 | if (Name == "gt") return 1; |
| 208 | if (Name == "eq") return 2; |
| 209 | if (Name == "so") return 3; |
| 210 | if (Name == "un") return 3; |
| 211 | |
| 212 | if (Name == "cr0") return 0; |
| 213 | if (Name == "cr1") return 1; |
| 214 | if (Name == "cr2") return 2; |
| 215 | if (Name == "cr3") return 3; |
| 216 | if (Name == "cr4") return 4; |
| 217 | if (Name == "cr5") return 5; |
| 218 | if (Name == "cr6") return 6; |
| 219 | if (Name == "cr7") return 7; |
| 220 | |
| 221 | return -1; |
| 222 | } |
| 223 | |
| 224 | case MCExpr::Unary: |
| 225 | return -1; |
| 226 | |
| 227 | case MCExpr::Binary: { |
| 228 | const MCBinaryExpr *BE = cast<MCBinaryExpr>(E); |
| 229 | int64_t LHSVal = EvaluateCRExpr(BE->getLHS()); |
| 230 | int64_t RHSVal = EvaluateCRExpr(BE->getRHS()); |
| 231 | int64_t Res; |
| 232 | |
| 233 | if (LHSVal < 0 || RHSVal < 0) |
| 234 | return -1; |
| 235 | |
| 236 | switch (BE->getOpcode()) { |
| 237 | default: return -1; |
| 238 | case MCBinaryExpr::Add: Res = LHSVal + RHSVal; break; |
| 239 | case MCBinaryExpr::Mul: Res = LHSVal * RHSVal; break; |
| 240 | } |
| 241 | |
| 242 | return Res < 0 ? -1 : Res; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | llvm_unreachable("Invalid expression kind!"); |
| 247 | } |
| 248 | |
| Craig Topper | f7df722 | 2014-12-18 05:02:14 +0000 | [diff] [blame] | 249 | namespace { |
| 250 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 251 | struct PPCOperand; |
| 252 | |
| 253 | class PPCAsmParser : public MCTargetAsmParser { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 254 | bool IsPPC64; |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 255 | bool IsDarwin; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 256 | |
| Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 257 | void Warning(SMLoc L, const Twine &Msg) { getParser().Warning(L, Msg); } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 258 | |
| 259 | bool isPPC64() const { return IsPPC64; } |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 260 | bool isDarwin() const { return IsDarwin; } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 261 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 262 | bool MatchRegisterName(unsigned &RegNo, int64_t &IntVal); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 263 | |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 264 | bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 265 | |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 266 | const MCExpr *ExtractModifierFromExpr(const MCExpr *E, |
| 267 | PPCMCExpr::VariantKind &Variant); |
| Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 268 | const MCExpr *FixupVariantKind(const MCExpr *E); |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 269 | bool ParseExpression(const MCExpr *&EVal); |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 270 | bool ParseDarwinExpression(const MCExpr *&EVal); |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 271 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 272 | bool ParseOperand(OperandVector &Operands); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 273 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 274 | bool ParseDirectiveWord(unsigned Size, AsmToken ID); |
| 275 | bool ParseDirectiveTC(unsigned Size, AsmToken ID); |
| Ulrich Weigand | 55daa77 | 2013-07-09 10:00:34 +0000 | [diff] [blame] | 276 | bool ParseDirectiveMachine(SMLoc L); |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 277 | bool ParseDarwinDirectiveMachine(SMLoc L); |
| Ulrich Weigand | 0daa516 | 2014-07-20 22:56:57 +0000 | [diff] [blame] | 278 | bool ParseDirectiveAbiVersion(SMLoc L); |
| Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 279 | bool ParseDirectiveLocalEntry(SMLoc L); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 280 | |
| 281 | bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 282 | OperandVector &Operands, MCStreamer &Out, |
| Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 283 | uint64_t &ErrorInfo, |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 284 | bool MatchingInlineAsm) override; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 285 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 286 | void ProcessInstruction(MCInst &Inst, const OperandVector &Ops); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 287 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 288 | /// @name Auto-generated Match Functions |
| 289 | /// { |
| 290 | |
| 291 | #define GET_ASSEMBLER_HEADER |
| 292 | #include "PPCGenAsmMatcher.inc" |
| 293 | |
| 294 | /// } |
| 295 | |
| 296 | |
| 297 | public: |
| Akira Hatanaka | b11ef08 | 2015-11-14 06:35:56 +0000 | [diff] [blame] | 298 | PPCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &, |
| Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 299 | const MCInstrInfo &MII, const MCTargetOptions &Options) |
| Oliver Stannard | 4191b9e | 2017-10-11 09:17:43 +0000 | [diff] [blame] | 300 | : MCTargetAsmParser(Options, STI, MII) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 301 | // Check for 64-bit vs. 32-bit pointer mode. |
| Benjamin Kramer | 4fed928 | 2016-05-27 12:30:51 +0000 | [diff] [blame] | 302 | const Triple &TheTriple = STI.getTargetTriple(); |
| Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 303 | IsPPC64 = (TheTriple.getArch() == Triple::ppc64 || |
| 304 | TheTriple.getArch() == Triple::ppc64le); |
| 305 | IsDarwin = TheTriple.isMacOSX(); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 306 | // Initialize the set of available features. |
| 307 | setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); |
| 308 | } |
| 309 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 310 | bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
| 311 | SMLoc NameLoc, OperandVector &Operands) override; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 312 | |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 313 | bool ParseDirective(AsmToken DirectiveID) override; |
| Ulrich Weigand | c0944b5 | 2013-07-08 14:49:37 +0000 | [diff] [blame] | 314 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 315 | unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 316 | unsigned Kind) override; |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 317 | |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 318 | const MCExpr *applyModifierToExpr(const MCExpr *E, |
| 319 | MCSymbolRefExpr::VariantKind, |
| 320 | MCContext &Ctx) override; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | /// PPCOperand - Instances of this class represent a parsed PowerPC machine |
| 324 | /// instruction. |
| 325 | struct PPCOperand : public MCParsedAsmOperand { |
| 326 | enum KindTy { |
| 327 | Token, |
| 328 | Immediate, |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 329 | ContextImmediate, |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 330 | Expression, |
| 331 | TLSRegister |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 332 | } Kind; |
| 333 | |
| 334 | SMLoc StartLoc, EndLoc; |
| 335 | bool IsPPC64; |
| 336 | |
| 337 | struct TokOp { |
| 338 | const char *Data; |
| 339 | unsigned Length; |
| 340 | }; |
| 341 | |
| 342 | struct ImmOp { |
| 343 | int64_t Val; |
| 344 | }; |
| 345 | |
| 346 | struct ExprOp { |
| 347 | const MCExpr *Val; |
| Ulrich Weigand | b86cb7d | 2013-07-04 14:24:00 +0000 | [diff] [blame] | 348 | int64_t CRVal; // Cached result of EvaluateCRExpr(Val) |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 349 | }; |
| 350 | |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 351 | struct TLSRegOp { |
| 352 | const MCSymbolRefExpr *Sym; |
| 353 | }; |
| 354 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 355 | union { |
| 356 | struct TokOp Tok; |
| 357 | struct ImmOp Imm; |
| 358 | struct ExprOp Expr; |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 359 | struct TLSRegOp TLSReg; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | PPCOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {} |
| 363 | public: |
| 364 | PPCOperand(const PPCOperand &o) : MCParsedAsmOperand() { |
| 365 | Kind = o.Kind; |
| 366 | StartLoc = o.StartLoc; |
| 367 | EndLoc = o.EndLoc; |
| 368 | IsPPC64 = o.IsPPC64; |
| 369 | switch (Kind) { |
| 370 | case Token: |
| 371 | Tok = o.Tok; |
| 372 | break; |
| 373 | case Immediate: |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 374 | case ContextImmediate: |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 375 | Imm = o.Imm; |
| 376 | break; |
| 377 | case Expression: |
| 378 | Expr = o.Expr; |
| 379 | break; |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 380 | case TLSRegister: |
| 381 | TLSReg = o.TLSReg; |
| 382 | break; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| Richard Smith | c2a2830 | 2016-03-08 00:59:44 +0000 | [diff] [blame] | 386 | // Disable use of sized deallocation due to overallocation of PPCOperand |
| 387 | // objects in CreateTokenWithStringCopy. |
| 388 | void operator delete(void *p) { ::operator delete(p); } |
| 389 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 390 | /// getStartLoc - Get the location of the first token of this operand. |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 391 | SMLoc getStartLoc() const override { return StartLoc; } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 392 | |
| 393 | /// getEndLoc - Get the location of the last token of this operand. |
| Peter Collingbourne | 0da8630 | 2016-10-10 22:49:37 +0000 | [diff] [blame] | 394 | SMLoc getEndLoc() const override { return EndLoc; } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 395 | |
| Hal Finkel | e86a8b7 | 2017-12-16 02:42:18 +0000 | [diff] [blame] | 396 | /// getLocRange - Get the range between the first and last token of this |
| 397 | /// operand. |
| 398 | SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } |
| 399 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 400 | /// isPPC64 - True if this operand is for an instruction in 64-bit mode. |
| 401 | bool isPPC64() const { return IsPPC64; } |
| 402 | |
| 403 | int64_t getImm() const { |
| 404 | assert(Kind == Immediate && "Invalid access!"); |
| 405 | return Imm.Val; |
| 406 | } |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 407 | int64_t getImmS16Context() const { |
| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 408 | assert((Kind == Immediate || Kind == ContextImmediate) && |
| 409 | "Invalid access!"); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 410 | if (Kind == Immediate) |
| 411 | return Imm.Val; |
| 412 | return static_cast<int16_t>(Imm.Val); |
| 413 | } |
| 414 | int64_t getImmU16Context() const { |
| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 415 | assert((Kind == Immediate || Kind == ContextImmediate) && |
| 416 | "Invalid access!"); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 417 | return Imm.Val; |
| 418 | } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 419 | |
| 420 | const MCExpr *getExpr() const { |
| 421 | assert(Kind == Expression && "Invalid access!"); |
| 422 | return Expr.Val; |
| 423 | } |
| 424 | |
| Ulrich Weigand | b86cb7d | 2013-07-04 14:24:00 +0000 | [diff] [blame] | 425 | int64_t getExprCRVal() const { |
| 426 | assert(Kind == Expression && "Invalid access!"); |
| 427 | return Expr.CRVal; |
| 428 | } |
| 429 | |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 430 | const MCExpr *getTLSReg() const { |
| 431 | assert(Kind == TLSRegister && "Invalid access!"); |
| 432 | return TLSReg.Sym; |
| 433 | } |
| 434 | |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 435 | unsigned getReg() const override { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 436 | assert(isRegNumber() && "Invalid access!"); |
| 437 | return (unsigned) Imm.Val; |
| 438 | } |
| 439 | |
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 440 | unsigned getVSReg() const { |
| 441 | assert(isVSRegNumber() && "Invalid access!"); |
| 442 | return (unsigned) Imm.Val; |
| 443 | } |
| 444 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 445 | unsigned getCCReg() const { |
| 446 | assert(isCCRegNumber() && "Invalid access!"); |
| Ulrich Weigand | b86cb7d | 2013-07-04 14:24:00 +0000 | [diff] [blame] | 447 | return (unsigned) (Kind == Immediate ? Imm.Val : Expr.CRVal); |
| 448 | } |
| 449 | |
| 450 | unsigned getCRBit() const { |
| 451 | assert(isCRBitNumber() && "Invalid access!"); |
| 452 | return (unsigned) (Kind == Immediate ? Imm.Val : Expr.CRVal); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | unsigned getCRBitMask() const { |
| 456 | assert(isCRBitMask() && "Invalid access!"); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 457 | return 7 - countTrailingZeros<uint64_t>(Imm.Val); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 460 | bool isToken() const override { return Kind == Token; } |
| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 461 | bool isImm() const override { |
| 462 | return Kind == Immediate || Kind == Expression; |
| 463 | } |
| Nemanja Ivanovic | e8effe1 | 2015-03-04 20:44:33 +0000 | [diff] [blame] | 464 | bool isU1Imm() const { return Kind == Immediate && isUInt<1>(getImm()); } |
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 465 | bool isU2Imm() const { return Kind == Immediate && isUInt<2>(getImm()); } |
| Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 466 | bool isU3Imm() const { return Kind == Immediate && isUInt<3>(getImm()); } |
| Joerg Sonnenberger | 9e9623c | 2014-07-29 22:21:57 +0000 | [diff] [blame] | 467 | bool isU4Imm() const { return Kind == Immediate && isUInt<4>(getImm()); } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 468 | bool isU5Imm() const { return Kind == Immediate && isUInt<5>(getImm()); } |
| 469 | bool isS5Imm() const { return Kind == Immediate && isInt<5>(getImm()); } |
| 470 | bool isU6Imm() const { return Kind == Immediate && isUInt<6>(getImm()); } |
| Joerg Sonnenberger | 0013b92 | 2014-08-08 16:43:49 +0000 | [diff] [blame] | 471 | bool isU6ImmX2() const { return Kind == Immediate && |
| 472 | isUInt<6>(getImm()) && |
| 473 | (getImm() & 1) == 0; } |
| Chuang-Yu Cheng | 8072271 | 2016-03-28 08:34:28 +0000 | [diff] [blame] | 474 | bool isU7Imm() const { return Kind == Immediate && isUInt<7>(getImm()); } |
| Joerg Sonnenberger | 0013b92 | 2014-08-08 16:43:49 +0000 | [diff] [blame] | 475 | bool isU7ImmX4() const { return Kind == Immediate && |
| 476 | isUInt<7>(getImm()) && |
| 477 | (getImm() & 3) == 0; } |
| Chuang-Yu Cheng | 8072271 | 2016-03-28 08:34:28 +0000 | [diff] [blame] | 478 | bool isU8Imm() const { return Kind == Immediate && isUInt<8>(getImm()); } |
| Joerg Sonnenberger | 0013b92 | 2014-08-08 16:43:49 +0000 | [diff] [blame] | 479 | bool isU8ImmX8() const { return Kind == Immediate && |
| 480 | isUInt<8>(getImm()) && |
| 481 | (getImm() & 7) == 0; } |
| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 482 | |
| Bill Schmidt | e26236e | 2015-05-22 16:44:10 +0000 | [diff] [blame] | 483 | bool isU10Imm() const { return Kind == Immediate && isUInt<10>(getImm()); } |
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 484 | bool isU12Imm() const { return Kind == Immediate && isUInt<12>(getImm()); } |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 485 | bool isU16Imm() const { |
| 486 | switch (Kind) { |
| 487 | case Expression: |
| 488 | return true; |
| 489 | case Immediate: |
| 490 | case ContextImmediate: |
| 491 | return isUInt<16>(getImmU16Context()); |
| 492 | default: |
| 493 | return false; |
| 494 | } |
| 495 | } |
| 496 | bool isS16Imm() const { |
| 497 | switch (Kind) { |
| 498 | case Expression: |
| 499 | return true; |
| 500 | case Immediate: |
| 501 | case ContextImmediate: |
| 502 | return isInt<16>(getImmS16Context()); |
| 503 | default: |
| 504 | return false; |
| 505 | } |
| 506 | } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 507 | bool isS16ImmX4() const { return Kind == Expression || |
| 508 | (Kind == Immediate && isInt<16>(getImm()) && |
| 509 | (getImm() & 3) == 0); } |
| Kit Barton | ba532dc | 2016-03-08 03:49:13 +0000 | [diff] [blame] | 510 | bool isS16ImmX16() const { return Kind == Expression || |
| 511 | (Kind == Immediate && isInt<16>(getImm()) && |
| 512 | (getImm() & 15) == 0); } |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 513 | bool isS17Imm() const { |
| 514 | switch (Kind) { |
| 515 | case Expression: |
| 516 | return true; |
| 517 | case Immediate: |
| 518 | case ContextImmediate: |
| 519 | return isInt<17>(getImmS16Context()); |
| 520 | default: |
| 521 | return false; |
| 522 | } |
| 523 | } |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 524 | bool isTLSReg() const { return Kind == TLSRegister; } |
| Joerg Sonnenberger | eb9d13f | 2014-08-08 20:57:58 +0000 | [diff] [blame] | 525 | bool isDirectBr() const { |
| 526 | if (Kind == Expression) |
| 527 | return true; |
| 528 | if (Kind != Immediate) |
| 529 | return false; |
| 530 | // Operand must be 64-bit aligned, signed 27-bit immediate. |
| 531 | if ((getImm() & 3) != 0) |
| 532 | return false; |
| 533 | if (isInt<26>(getImm())) |
| 534 | return true; |
| 535 | if (!IsPPC64) { |
| 536 | // In 32-bit mode, large 32-bit quantities wrap around. |
| 537 | if (isUInt<32>(getImm()) && isInt<26>(static_cast<int32_t>(getImm()))) |
| 538 | return true; |
| 539 | } |
| 540 | return false; |
| 541 | } |
| Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 542 | bool isCondBr() const { return Kind == Expression || |
| 543 | (Kind == Immediate && isInt<16>(getImm()) && |
| 544 | (getImm() & 3) == 0); } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 545 | bool isRegNumber() const { return Kind == Immediate && isUInt<5>(getImm()); } |
| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 546 | bool isVSRegNumber() const { |
| 547 | return Kind == Immediate && isUInt<6>(getImm()); |
| 548 | } |
| Ulrich Weigand | b86cb7d | 2013-07-04 14:24:00 +0000 | [diff] [blame] | 549 | bool isCCRegNumber() const { return (Kind == Expression |
| 550 | && isUInt<3>(getExprCRVal())) || |
| 551 | (Kind == Immediate |
| 552 | && isUInt<3>(getImm())); } |
| 553 | bool isCRBitNumber() const { return (Kind == Expression |
| 554 | && isUInt<5>(getExprCRVal())) || |
| 555 | (Kind == Immediate |
| 556 | && isUInt<5>(getImm())); } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 557 | bool isCRBitMask() const { return Kind == Immediate && isUInt<8>(getImm()) && |
| 558 | isPowerOf2_32(getImm()); } |
| Hal Finkel | 522e4d9 | 2016-09-03 02:31:44 +0000 | [diff] [blame] | 559 | bool isATBitsAsHint() const { return false; } |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 560 | bool isMem() const override { return false; } |
| 561 | bool isReg() const override { return false; } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 562 | |
| 563 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 564 | llvm_unreachable("addRegOperands"); |
| 565 | } |
| 566 | |
| 567 | void addRegGPRCOperands(MCInst &Inst, unsigned N) const { |
| 568 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 569 | Inst.addOperand(MCOperand::createReg(RRegs[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void addRegGPRCNoR0Operands(MCInst &Inst, unsigned N) const { |
| 573 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 574 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | void addRegG8RCOperands(MCInst &Inst, unsigned N) const { |
| 578 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 579 | Inst.addOperand(MCOperand::createReg(XRegs[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | void addRegG8RCNoX0Operands(MCInst &Inst, unsigned N) const { |
| 583 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 584 | Inst.addOperand(MCOperand::createReg(XRegsNoX0[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | void addRegGxRCOperands(MCInst &Inst, unsigned N) const { |
| 588 | if (isPPC64()) |
| 589 | addRegG8RCOperands(Inst, N); |
| 590 | else |
| 591 | addRegGPRCOperands(Inst, N); |
| 592 | } |
| 593 | |
| 594 | void addRegGxRCNoR0Operands(MCInst &Inst, unsigned N) const { |
| 595 | if (isPPC64()) |
| 596 | addRegG8RCNoX0Operands(Inst, N); |
| 597 | else |
| 598 | addRegGPRCNoR0Operands(Inst, N); |
| 599 | } |
| 600 | |
| 601 | void addRegF4RCOperands(MCInst &Inst, unsigned N) const { |
| 602 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 603 | Inst.addOperand(MCOperand::createReg(FRegs[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | void addRegF8RCOperands(MCInst &Inst, unsigned N) const { |
| 607 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 608 | Inst.addOperand(MCOperand::createReg(FRegs[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| Nemanja Ivanovic | 11049f8 | 2016-10-04 06:59:23 +0000 | [diff] [blame] | 611 | void addRegVFRCOperands(MCInst &Inst, unsigned N) const { |
| 612 | assert(N == 1 && "Invalid number of operands!"); |
| 613 | Inst.addOperand(MCOperand::createReg(VFRegs[getReg()])); |
| 614 | } |
| 615 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 616 | void addRegVRRCOperands(MCInst &Inst, unsigned N) const { |
| 617 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 618 | Inst.addOperand(MCOperand::createReg(VRegs[getReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 621 | void addRegVSRCOperands(MCInst &Inst, unsigned N) const { |
| 622 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 623 | Inst.addOperand(MCOperand::createReg(VSRegs[getVSReg()])); |
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 626 | void addRegVSFRCOperands(MCInst &Inst, unsigned N) const { |
| 627 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 628 | Inst.addOperand(MCOperand::createReg(VSFRegs[getVSReg()])); |
| Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 631 | void addRegVSSRCOperands(MCInst &Inst, unsigned N) const { |
| 632 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 633 | Inst.addOperand(MCOperand::createReg(VSSRegs[getVSReg()])); |
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 636 | void addRegQFRCOperands(MCInst &Inst, unsigned N) const { |
| 637 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 638 | Inst.addOperand(MCOperand::createReg(QFRegs[getReg()])); |
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | void addRegQSRCOperands(MCInst &Inst, unsigned N) const { |
| 642 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 643 | Inst.addOperand(MCOperand::createReg(QFRegs[getReg()])); |
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | void addRegQBRCOperands(MCInst &Inst, unsigned N) const { |
| 647 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 648 | Inst.addOperand(MCOperand::createReg(QFRegs[getReg()])); |
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 651 | void addRegCRBITRCOperands(MCInst &Inst, unsigned N) const { |
| 652 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 653 | Inst.addOperand(MCOperand::createReg(CRBITRegs[getCRBit()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void addRegCRRCOperands(MCInst &Inst, unsigned N) const { |
| 657 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 658 | Inst.addOperand(MCOperand::createReg(CRRegs[getCCReg()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | void addCRBitMaskOperands(MCInst &Inst, unsigned N) const { |
| 662 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 663 | Inst.addOperand(MCOperand::createReg(CRRegs[getCRBitMask()])); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 667 | assert(N == 1 && "Invalid number of operands!"); |
| 668 | if (Kind == Immediate) |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 669 | Inst.addOperand(MCOperand::createImm(getImm())); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 670 | else |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 671 | Inst.addOperand(MCOperand::createExpr(getExpr())); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 674 | void addS16ImmOperands(MCInst &Inst, unsigned N) const { |
| 675 | assert(N == 1 && "Invalid number of operands!"); |
| 676 | switch (Kind) { |
| 677 | case Immediate: |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 678 | Inst.addOperand(MCOperand::createImm(getImm())); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 679 | break; |
| 680 | case ContextImmediate: |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 681 | Inst.addOperand(MCOperand::createImm(getImmS16Context())); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 682 | break; |
| 683 | default: |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 684 | Inst.addOperand(MCOperand::createExpr(getExpr())); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 685 | break; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | void addU16ImmOperands(MCInst &Inst, unsigned N) const { |
| 690 | assert(N == 1 && "Invalid number of operands!"); |
| 691 | switch (Kind) { |
| 692 | case Immediate: |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 693 | Inst.addOperand(MCOperand::createImm(getImm())); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 694 | break; |
| 695 | case ContextImmediate: |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 696 | Inst.addOperand(MCOperand::createImm(getImmU16Context())); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 697 | break; |
| 698 | default: |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 699 | Inst.addOperand(MCOperand::createExpr(getExpr())); |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
| Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 704 | void addBranchTargetOperands(MCInst &Inst, unsigned N) const { |
| 705 | assert(N == 1 && "Invalid number of operands!"); |
| 706 | if (Kind == Immediate) |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 707 | Inst.addOperand(MCOperand::createImm(getImm() / 4)); |
| Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 708 | else |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 709 | Inst.addOperand(MCOperand::createExpr(getExpr())); |
| Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 712 | void addTLSRegOperands(MCInst &Inst, unsigned N) const { |
| 713 | assert(N == 1 && "Invalid number of operands!"); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 714 | Inst.addOperand(MCOperand::createExpr(getTLSReg())); |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 717 | StringRef getToken() const { |
| 718 | assert(Kind == Token && "Invalid access!"); |
| 719 | return StringRef(Tok.Data, Tok.Length); |
| 720 | } |
| 721 | |
| Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 722 | void print(raw_ostream &OS) const override; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 723 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 724 | static std::unique_ptr<PPCOperand> CreateToken(StringRef Str, SMLoc S, |
| 725 | bool IsPPC64) { |
| 726 | auto Op = make_unique<PPCOperand>(Token); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 727 | Op->Tok.Data = Str.data(); |
| 728 | Op->Tok.Length = Str.size(); |
| 729 | Op->StartLoc = S; |
| 730 | Op->EndLoc = S; |
| 731 | Op->IsPPC64 = IsPPC64; |
| 732 | return Op; |
| 733 | } |
| 734 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 735 | static std::unique_ptr<PPCOperand> |
| 736 | CreateTokenWithStringCopy(StringRef Str, SMLoc S, bool IsPPC64) { |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 737 | // Allocate extra memory for the string and copy it. |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 738 | // FIXME: This is incorrect, Operands are owned by unique_ptr with a default |
| 739 | // deleter which will destroy them by simply using "delete", not correctly |
| 740 | // calling operator delete on this extra memory after calling the dtor |
| 741 | // explicitly. |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 742 | void *Mem = ::operator new(sizeof(PPCOperand) + Str.size()); |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 743 | std::unique_ptr<PPCOperand> Op(new (Mem) PPCOperand(Token)); |
| Benjamin Kramer | 769989c | 2014-08-15 11:05:45 +0000 | [diff] [blame] | 744 | Op->Tok.Data = reinterpret_cast<const char *>(Op.get() + 1); |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 745 | Op->Tok.Length = Str.size(); |
| Benjamin Kramer | 769989c | 2014-08-15 11:05:45 +0000 | [diff] [blame] | 746 | std::memcpy(const_cast<char *>(Op->Tok.Data), Str.data(), Str.size()); |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 747 | Op->StartLoc = S; |
| 748 | Op->EndLoc = S; |
| 749 | Op->IsPPC64 = IsPPC64; |
| 750 | return Op; |
| 751 | } |
| 752 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 753 | static std::unique_ptr<PPCOperand> CreateImm(int64_t Val, SMLoc S, SMLoc E, |
| 754 | bool IsPPC64) { |
| 755 | auto Op = make_unique<PPCOperand>(Immediate); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 756 | Op->Imm.Val = Val; |
| 757 | Op->StartLoc = S; |
| 758 | Op->EndLoc = E; |
| 759 | Op->IsPPC64 = IsPPC64; |
| 760 | return Op; |
| 761 | } |
| 762 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 763 | static std::unique_ptr<PPCOperand> CreateExpr(const MCExpr *Val, SMLoc S, |
| 764 | SMLoc E, bool IsPPC64) { |
| 765 | auto Op = make_unique<PPCOperand>(Expression); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 766 | Op->Expr.Val = Val; |
| Ulrich Weigand | b86cb7d | 2013-07-04 14:24:00 +0000 | [diff] [blame] | 767 | Op->Expr.CRVal = EvaluateCRExpr(Val); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 768 | Op->StartLoc = S; |
| 769 | Op->EndLoc = E; |
| 770 | Op->IsPPC64 = IsPPC64; |
| 771 | return Op; |
| 772 | } |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 773 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 774 | static std::unique_ptr<PPCOperand> |
| 775 | CreateTLSReg(const MCSymbolRefExpr *Sym, SMLoc S, SMLoc E, bool IsPPC64) { |
| 776 | auto Op = make_unique<PPCOperand>(TLSRegister); |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 777 | Op->TLSReg.Sym = Sym; |
| 778 | Op->StartLoc = S; |
| 779 | Op->EndLoc = E; |
| 780 | Op->IsPPC64 = IsPPC64; |
| 781 | return Op; |
| 782 | } |
| 783 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 784 | static std::unique_ptr<PPCOperand> |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 785 | CreateContextImm(int64_t Val, SMLoc S, SMLoc E, bool IsPPC64) { |
| 786 | auto Op = make_unique<PPCOperand>(ContextImmediate); |
| 787 | Op->Imm.Val = Val; |
| 788 | Op->StartLoc = S; |
| 789 | Op->EndLoc = E; |
| 790 | Op->IsPPC64 = IsPPC64; |
| 791 | return Op; |
| 792 | } |
| 793 | |
| 794 | static std::unique_ptr<PPCOperand> |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 795 | CreateFromMCExpr(const MCExpr *Val, SMLoc S, SMLoc E, bool IsPPC64) { |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 796 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Val)) |
| 797 | return CreateImm(CE->getValue(), S, E, IsPPC64); |
| 798 | |
| 799 | if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Val)) |
| 800 | if (SRE->getKind() == MCSymbolRefExpr::VK_PPC_TLS) |
| 801 | return CreateTLSReg(SRE, S, E, IsPPC64); |
| 802 | |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 803 | if (const PPCMCExpr *TE = dyn_cast<PPCMCExpr>(Val)) { |
| 804 | int64_t Res; |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 805 | if (TE->evaluateAsConstant(Res)) |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 806 | return CreateContextImm(Res, S, E, IsPPC64); |
| 807 | } |
| 808 | |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 809 | return CreateExpr(Val, S, E, IsPPC64); |
| 810 | } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 811 | }; |
| 812 | |
| 813 | } // end anonymous namespace. |
| 814 | |
| 815 | void PPCOperand::print(raw_ostream &OS) const { |
| 816 | switch (Kind) { |
| 817 | case Token: |
| 818 | OS << "'" << getToken() << "'"; |
| 819 | break; |
| 820 | case Immediate: |
| Joerg Sonnenberger | bfef1dd | 2014-08-10 12:41:50 +0000 | [diff] [blame] | 821 | case ContextImmediate: |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 822 | OS << getImm(); |
| 823 | break; |
| 824 | case Expression: |
| Rafael Espindola | f4a1365 | 2015-05-27 13:05:42 +0000 | [diff] [blame] | 825 | OS << *getExpr(); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 826 | break; |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 827 | case TLSRegister: |
| Rafael Espindola | f4a1365 | 2015-05-27 13:05:42 +0000 | [diff] [blame] | 828 | OS << *getTLSReg(); |
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 829 | break; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 833 | static void |
| 834 | addNegOperand(MCInst &Inst, MCOperand &Op, MCContext &Ctx) { |
| 835 | if (Op.isImm()) { |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 836 | Inst.addOperand(MCOperand::createImm(-Op.getImm())); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 837 | return; |
| 838 | } |
| 839 | const MCExpr *Expr = Op.getExpr(); |
| 840 | if (const MCUnaryExpr *UnExpr = dyn_cast<MCUnaryExpr>(Expr)) { |
| 841 | if (UnExpr->getOpcode() == MCUnaryExpr::Minus) { |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 842 | Inst.addOperand(MCOperand::createExpr(UnExpr->getSubExpr())); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | } else if (const MCBinaryExpr *BinExpr = dyn_cast<MCBinaryExpr>(Expr)) { |
| 846 | if (BinExpr->getOpcode() == MCBinaryExpr::Sub) { |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 847 | const MCExpr *NE = MCBinaryExpr::createSub(BinExpr->getRHS(), |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 848 | BinExpr->getLHS(), Ctx); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 849 | Inst.addOperand(MCOperand::createExpr(NE)); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 850 | return; |
| 851 | } |
| 852 | } |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 853 | Inst.addOperand(MCOperand::createExpr(MCUnaryExpr::createMinus(Expr, Ctx))); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 856 | void PPCAsmParser::ProcessInstruction(MCInst &Inst, |
| 857 | const OperandVector &Operands) { |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 858 | int Opcode = Inst.getOpcode(); |
| 859 | switch (Opcode) { |
| Hal Finkel | fefcfff | 2015-04-23 22:47:57 +0000 | [diff] [blame] | 860 | case PPC::DCBTx: |
| 861 | case PPC::DCBTT: |
| 862 | case PPC::DCBTSTx: |
| 863 | case PPC::DCBTSTT: { |
| 864 | MCInst TmpInst; |
| 865 | TmpInst.setOpcode((Opcode == PPC::DCBTx || Opcode == PPC::DCBTT) ? |
| 866 | PPC::DCBT : PPC::DCBTST); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 867 | TmpInst.addOperand(MCOperand::createImm( |
| Hal Finkel | fefcfff | 2015-04-23 22:47:57 +0000 | [diff] [blame] | 868 | (Opcode == PPC::DCBTx || Opcode == PPC::DCBTSTx) ? 0 : 16)); |
| 869 | TmpInst.addOperand(Inst.getOperand(0)); |
| 870 | TmpInst.addOperand(Inst.getOperand(1)); |
| 871 | Inst = TmpInst; |
| 872 | break; |
| 873 | } |
| 874 | case PPC::DCBTCT: |
| 875 | case PPC::DCBTDS: { |
| 876 | MCInst TmpInst; |
| 877 | TmpInst.setOpcode(PPC::DCBT); |
| 878 | TmpInst.addOperand(Inst.getOperand(2)); |
| 879 | TmpInst.addOperand(Inst.getOperand(0)); |
| 880 | TmpInst.addOperand(Inst.getOperand(1)); |
| 881 | Inst = TmpInst; |
| 882 | break; |
| 883 | } |
| 884 | case PPC::DCBTSTCT: |
| 885 | case PPC::DCBTSTDS: { |
| 886 | MCInst TmpInst; |
| 887 | TmpInst.setOpcode(PPC::DCBTST); |
| 888 | TmpInst.addOperand(Inst.getOperand(2)); |
| 889 | TmpInst.addOperand(Inst.getOperand(0)); |
| 890 | TmpInst.addOperand(Inst.getOperand(1)); |
| 891 | Inst = TmpInst; |
| 892 | break; |
| 893 | } |
| Hal Finkel | 277736e | 2016-09-02 23:41:54 +0000 | [diff] [blame] | 894 | case PPC::DCBFx: |
| 895 | case PPC::DCBFL: |
| 896 | case PPC::DCBFLP: { |
| 897 | int L = 0; |
| 898 | if (Opcode == PPC::DCBFL) |
| 899 | L = 1; |
| 900 | else if (Opcode == PPC::DCBFLP) |
| 901 | L = 3; |
| 902 | |
| 903 | MCInst TmpInst; |
| 904 | TmpInst.setOpcode(PPC::DCBF); |
| 905 | TmpInst.addOperand(MCOperand::createImm(L)); |
| 906 | TmpInst.addOperand(Inst.getOperand(0)); |
| 907 | TmpInst.addOperand(Inst.getOperand(1)); |
| 908 | Inst = TmpInst; |
| 909 | break; |
| 910 | } |
| Ulrich Weigand | 6ca7157 | 2013-06-24 18:08:03 +0000 | [diff] [blame] | 911 | case PPC::LAx: { |
| 912 | MCInst TmpInst; |
| 913 | TmpInst.setOpcode(PPC::LA); |
| 914 | TmpInst.addOperand(Inst.getOperand(0)); |
| 915 | TmpInst.addOperand(Inst.getOperand(2)); |
| 916 | TmpInst.addOperand(Inst.getOperand(1)); |
| 917 | Inst = TmpInst; |
| 918 | break; |
| 919 | } |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 920 | case PPC::SUBI: { |
| 921 | MCInst TmpInst; |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 922 | TmpInst.setOpcode(PPC::ADDI); |
| 923 | TmpInst.addOperand(Inst.getOperand(0)); |
| 924 | TmpInst.addOperand(Inst.getOperand(1)); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 925 | addNegOperand(TmpInst, Inst.getOperand(2), getContext()); |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 926 | Inst = TmpInst; |
| 927 | break; |
| 928 | } |
| 929 | case PPC::SUBIS: { |
| 930 | MCInst TmpInst; |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 931 | TmpInst.setOpcode(PPC::ADDIS); |
| 932 | TmpInst.addOperand(Inst.getOperand(0)); |
| 933 | TmpInst.addOperand(Inst.getOperand(1)); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 934 | addNegOperand(TmpInst, Inst.getOperand(2), getContext()); |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 935 | Inst = TmpInst; |
| 936 | break; |
| 937 | } |
| 938 | case PPC::SUBIC: { |
| 939 | MCInst TmpInst; |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 940 | TmpInst.setOpcode(PPC::ADDIC); |
| 941 | TmpInst.addOperand(Inst.getOperand(0)); |
| 942 | TmpInst.addOperand(Inst.getOperand(1)); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 943 | addNegOperand(TmpInst, Inst.getOperand(2), getContext()); |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 944 | Inst = TmpInst; |
| 945 | break; |
| 946 | } |
| 947 | case PPC::SUBICo: { |
| 948 | MCInst TmpInst; |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 949 | TmpInst.setOpcode(PPC::ADDICo); |
| 950 | TmpInst.addOperand(Inst.getOperand(0)); |
| 951 | TmpInst.addOperand(Inst.getOperand(1)); |
| Joerg Sonnenberger | 5aab5af | 2014-08-09 17:10:26 +0000 | [diff] [blame] | 952 | addNegOperand(TmpInst, Inst.getOperand(2), getContext()); |
| Ulrich Weigand | 4069e24 | 2013-06-25 13:16:48 +0000 | [diff] [blame] | 953 | Inst = TmpInst; |
| 954 | break; |
| 955 | } |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 956 | case PPC::EXTLWI: |
| 957 | case PPC::EXTLWIo: { |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 958 | MCInst TmpInst; |
| 959 | int64_t N = Inst.getOperand(2).getImm(); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 960 | int64_t B = Inst.getOperand(3).getImm(); |
| 961 | TmpInst.setOpcode(Opcode == PPC::EXTLWI? PPC::RLWINM : PPC::RLWINMo); |
| 962 | TmpInst.addOperand(Inst.getOperand(0)); |
| 963 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 964 | TmpInst.addOperand(MCOperand::createImm(B)); |
| 965 | TmpInst.addOperand(MCOperand::createImm(0)); |
| 966 | TmpInst.addOperand(MCOperand::createImm(N - 1)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 967 | Inst = TmpInst; |
| 968 | break; |
| 969 | } |
| 970 | case PPC::EXTRWI: |
| 971 | case PPC::EXTRWIo: { |
| 972 | MCInst TmpInst; |
| 973 | int64_t N = Inst.getOperand(2).getImm(); |
| 974 | int64_t B = Inst.getOperand(3).getImm(); |
| 975 | TmpInst.setOpcode(Opcode == PPC::EXTRWI? PPC::RLWINM : PPC::RLWINMo); |
| 976 | TmpInst.addOperand(Inst.getOperand(0)); |
| 977 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 978 | TmpInst.addOperand(MCOperand::createImm(B + N)); |
| 979 | TmpInst.addOperand(MCOperand::createImm(32 - N)); |
| 980 | TmpInst.addOperand(MCOperand::createImm(31)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 981 | Inst = TmpInst; |
| 982 | break; |
| 983 | } |
| 984 | case PPC::INSLWI: |
| 985 | case PPC::INSLWIo: { |
| 986 | MCInst TmpInst; |
| 987 | int64_t N = Inst.getOperand(2).getImm(); |
| 988 | int64_t B = Inst.getOperand(3).getImm(); |
| 989 | TmpInst.setOpcode(Opcode == PPC::INSLWI? PPC::RLWIMI : PPC::RLWIMIo); |
| 990 | TmpInst.addOperand(Inst.getOperand(0)); |
| 991 | TmpInst.addOperand(Inst.getOperand(0)); |
| 992 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 993 | TmpInst.addOperand(MCOperand::createImm(32 - B)); |
| 994 | TmpInst.addOperand(MCOperand::createImm(B)); |
| 995 | TmpInst.addOperand(MCOperand::createImm((B + N) - 1)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 996 | Inst = TmpInst; |
| 997 | break; |
| 998 | } |
| 999 | case PPC::INSRWI: |
| 1000 | case PPC::INSRWIo: { |
| 1001 | MCInst TmpInst; |
| 1002 | int64_t N = Inst.getOperand(2).getImm(); |
| 1003 | int64_t B = Inst.getOperand(3).getImm(); |
| 1004 | TmpInst.setOpcode(Opcode == PPC::INSRWI? PPC::RLWIMI : PPC::RLWIMIo); |
| 1005 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1006 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1007 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1008 | TmpInst.addOperand(MCOperand::createImm(32 - (B + N))); |
| 1009 | TmpInst.addOperand(MCOperand::createImm(B)); |
| 1010 | TmpInst.addOperand(MCOperand::createImm((B + N) - 1)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1011 | Inst = TmpInst; |
| 1012 | break; |
| 1013 | } |
| 1014 | case PPC::ROTRWI: |
| 1015 | case PPC::ROTRWIo: { |
| 1016 | MCInst TmpInst; |
| 1017 | int64_t N = Inst.getOperand(2).getImm(); |
| 1018 | TmpInst.setOpcode(Opcode == PPC::ROTRWI? PPC::RLWINM : PPC::RLWINMo); |
| 1019 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1020 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1021 | TmpInst.addOperand(MCOperand::createImm(32 - N)); |
| 1022 | TmpInst.addOperand(MCOperand::createImm(0)); |
| 1023 | TmpInst.addOperand(MCOperand::createImm(31)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1024 | Inst = TmpInst; |
| 1025 | break; |
| 1026 | } |
| 1027 | case PPC::SLWI: |
| 1028 | case PPC::SLWIo: { |
| 1029 | MCInst TmpInst; |
| 1030 | int64_t N = Inst.getOperand(2).getImm(); |
| 1031 | TmpInst.setOpcode(Opcode == PPC::SLWI? PPC::RLWINM : PPC::RLWINMo); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1032 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1033 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1034 | TmpInst.addOperand(MCOperand::createImm(N)); |
| 1035 | TmpInst.addOperand(MCOperand::createImm(0)); |
| 1036 | TmpInst.addOperand(MCOperand::createImm(31 - N)); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1037 | Inst = TmpInst; |
| 1038 | break; |
| 1039 | } |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1040 | case PPC::SRWI: |
| 1041 | case PPC::SRWIo: { |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1042 | MCInst TmpInst; |
| 1043 | int64_t N = Inst.getOperand(2).getImm(); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1044 | TmpInst.setOpcode(Opcode == PPC::SRWI? PPC::RLWINM : PPC::RLWINMo); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1045 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1046 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1047 | TmpInst.addOperand(MCOperand::createImm(32 - N)); |
| 1048 | TmpInst.addOperand(MCOperand::createImm(N)); |
| 1049 | TmpInst.addOperand(MCOperand::createImm(31)); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1050 | Inst = TmpInst; |
| 1051 | break; |
| 1052 | } |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1053 | case PPC::CLRRWI: |
| 1054 | case PPC::CLRRWIo: { |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1055 | MCInst TmpInst; |
| 1056 | int64_t N = Inst.getOperand(2).getImm(); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1057 | TmpInst.setOpcode(Opcode == PPC::CLRRWI? PPC::RLWINM : PPC::RLWINMo); |
| 1058 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1059 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1060 | TmpInst.addOperand(MCOperand::createImm(0)); |
| 1061 | TmpInst.addOperand(MCOperand::createImm(0)); |
| 1062 | TmpInst.addOperand(MCOperand::createImm(31 - N)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1063 | Inst = TmpInst; |
| 1064 | break; |
| 1065 | } |
| 1066 | case PPC::CLRLSLWI: |
| 1067 | case PPC::CLRLSLWIo: { |
| 1068 | MCInst TmpInst; |
| 1069 | int64_t B = Inst.getOperand(2).getImm(); |
| 1070 | int64_t N = Inst.getOperand(3).getImm(); |
| 1071 | TmpInst.setOpcode(Opcode == PPC::CLRLSLWI? PPC::RLWINM : PPC::RLWINMo); |
| 1072 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1073 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1074 | TmpInst.addOperand(MCOperand::createImm(N)); |
| 1075 | TmpInst.addOperand(MCOperand::createImm(B - N)); |
| 1076 | TmpInst.addOperand(MCOperand::createImm(31 - N)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1077 | Inst = TmpInst; |
| 1078 | break; |
| 1079 | } |
| 1080 | case PPC::EXTLDI: |
| 1081 | case PPC::EXTLDIo: { |
| 1082 | MCInst TmpInst; |
| 1083 | int64_t N = Inst.getOperand(2).getImm(); |
| 1084 | int64_t B = Inst.getOperand(3).getImm(); |
| 1085 | TmpInst.setOpcode(Opcode == PPC::EXTLDI? PPC::RLDICR : PPC::RLDICRo); |
| 1086 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1087 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1088 | TmpInst.addOperand(MCOperand::createImm(B)); |
| 1089 | TmpInst.addOperand(MCOperand::createImm(N - 1)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1090 | Inst = TmpInst; |
| 1091 | break; |
| 1092 | } |
| 1093 | case PPC::EXTRDI: |
| 1094 | case PPC::EXTRDIo: { |
| 1095 | MCInst TmpInst; |
| 1096 | int64_t N = Inst.getOperand(2).getImm(); |
| 1097 | int64_t B = Inst.getOperand(3).getImm(); |
| 1098 | TmpInst.setOpcode(Opcode == PPC::EXTRDI? PPC::RLDICL : PPC::RLDICLo); |
| 1099 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1100 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1101 | TmpInst.addOperand(MCOperand::createImm(B + N)); |
| 1102 | TmpInst.addOperand(MCOperand::createImm(64 - N)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1103 | Inst = TmpInst; |
| 1104 | break; |
| 1105 | } |
| 1106 | case PPC::INSRDI: |
| 1107 | case PPC::INSRDIo: { |
| 1108 | MCInst TmpInst; |
| 1109 | int64_t N = Inst.getOperand(2).getImm(); |
| 1110 | int64_t B = Inst.getOperand(3).getImm(); |
| 1111 | TmpInst.setOpcode(Opcode == PPC::INSRDI? PPC::RLDIMI : PPC::RLDIMIo); |
| 1112 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1113 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1114 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1115 | TmpInst.addOperand(MCOperand::createImm(64 - (B + N))); |
| 1116 | TmpInst.addOperand(MCOperand::createImm(B)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1117 | Inst = TmpInst; |
| 1118 | break; |
| 1119 | } |
| 1120 | case PPC::ROTRDI: |
| 1121 | case PPC::ROTRDIo: { |
| 1122 | MCInst TmpInst; |
| 1123 | int64_t N = Inst.getOperand(2).getImm(); |
| 1124 | TmpInst.setOpcode(Opcode == PPC::ROTRDI? PPC::RLDICL : PPC::RLDICLo); |
| 1125 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1126 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1127 | TmpInst.addOperand(MCOperand::createImm(64 - N)); |
| 1128 | TmpInst.addOperand(MCOperand::createImm(0)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1129 | Inst = TmpInst; |
| 1130 | break; |
| 1131 | } |
| 1132 | case PPC::SLDI: |
| 1133 | case PPC::SLDIo: { |
| 1134 | MCInst TmpInst; |
| 1135 | int64_t N = Inst.getOperand(2).getImm(); |
| 1136 | TmpInst.setOpcode(Opcode == PPC::SLDI? PPC::RLDICR : PPC::RLDICRo); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1137 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1138 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1139 | TmpInst.addOperand(MCOperand::createImm(N)); |
| 1140 | TmpInst.addOperand(MCOperand::createImm(63 - N)); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1141 | Inst = TmpInst; |
| 1142 | break; |
| 1143 | } |
| Tony Jiang | 425071e | 2017-09-19 15:22:36 +0000 | [diff] [blame] | 1144 | case PPC::SUBPCIS: { |
| 1145 | MCInst TmpInst; |
| 1146 | int64_t N = Inst.getOperand(1).getImm(); |
| 1147 | TmpInst.setOpcode(PPC::ADDPCIS); |
| 1148 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1149 | TmpInst.addOperand(MCOperand::createImm(-N)); |
| 1150 | Inst = TmpInst; |
| 1151 | break; |
| 1152 | } |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1153 | case PPC::SRDI: |
| 1154 | case PPC::SRDIo: { |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1155 | MCInst TmpInst; |
| 1156 | int64_t N = Inst.getOperand(2).getImm(); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1157 | TmpInst.setOpcode(Opcode == PPC::SRDI? PPC::RLDICL : PPC::RLDICLo); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1158 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1159 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1160 | TmpInst.addOperand(MCOperand::createImm(64 - N)); |
| 1161 | TmpInst.addOperand(MCOperand::createImm(N)); |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1162 | Inst = TmpInst; |
| 1163 | break; |
| 1164 | } |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1165 | case PPC::CLRRDI: |
| 1166 | case PPC::CLRRDIo: { |
| 1167 | MCInst TmpInst; |
| 1168 | int64_t N = Inst.getOperand(2).getImm(); |
| 1169 | TmpInst.setOpcode(Opcode == PPC::CLRRDI? PPC::RLDICR : PPC::RLDICRo); |
| 1170 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1171 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1172 | TmpInst.addOperand(MCOperand::createImm(0)); |
| 1173 | TmpInst.addOperand(MCOperand::createImm(63 - N)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1174 | Inst = TmpInst; |
| 1175 | break; |
| 1176 | } |
| 1177 | case PPC::CLRLSLDI: |
| 1178 | case PPC::CLRLSLDIo: { |
| 1179 | MCInst TmpInst; |
| 1180 | int64_t B = Inst.getOperand(2).getImm(); |
| 1181 | int64_t N = Inst.getOperand(3).getImm(); |
| 1182 | TmpInst.setOpcode(Opcode == PPC::CLRLSLDI? PPC::RLDIC : PPC::RLDICo); |
| 1183 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1184 | TmpInst.addOperand(Inst.getOperand(1)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1185 | TmpInst.addOperand(MCOperand::createImm(N)); |
| 1186 | TmpInst.addOperand(MCOperand::createImm(B - N)); |
| Ulrich Weigand | ad873cd | 2013-06-25 13:17:41 +0000 | [diff] [blame] | 1187 | Inst = TmpInst; |
| 1188 | break; |
| 1189 | } |
| Hal Finkel | 6e9110a | 2015-03-28 19:42:41 +0000 | [diff] [blame] | 1190 | case PPC::RLWINMbm: |
| 1191 | case PPC::RLWINMobm: { |
| 1192 | unsigned MB, ME; |
| 1193 | int64_t BM = Inst.getOperand(3).getImm(); |
| 1194 | if (!isRunOfOnes(BM, MB, ME)) |
| 1195 | break; |
| 1196 | |
| 1197 | MCInst TmpInst; |
| 1198 | TmpInst.setOpcode(Opcode == PPC::RLWINMbm ? PPC::RLWINM : PPC::RLWINMo); |
| 1199 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1200 | TmpInst.addOperand(Inst.getOperand(1)); |
| 1201 | TmpInst.addOperand(Inst.getOperand(2)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1202 | TmpInst.addOperand(MCOperand::createImm(MB)); |
| 1203 | TmpInst.addOperand(MCOperand::createImm(ME)); |
| Hal Finkel | 6e9110a | 2015-03-28 19:42:41 +0000 | [diff] [blame] | 1204 | Inst = TmpInst; |
| 1205 | break; |
| 1206 | } |
| 1207 | case PPC::RLWIMIbm: |
| 1208 | case PPC::RLWIMIobm: { |
| 1209 | unsigned MB, ME; |
| 1210 | int64_t BM = Inst.getOperand(3).getImm(); |
| 1211 | if (!isRunOfOnes(BM, MB, ME)) |
| 1212 | break; |
| 1213 | |
| 1214 | MCInst TmpInst; |
| 1215 | TmpInst.setOpcode(Opcode == PPC::RLWIMIbm ? PPC::RLWIMI : PPC::RLWIMIo); |
| 1216 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1217 | TmpInst.addOperand(Inst.getOperand(0)); // The tied operand. |
| 1218 | TmpInst.addOperand(Inst.getOperand(1)); |
| 1219 | TmpInst.addOperand(Inst.getOperand(2)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1220 | TmpInst.addOperand(MCOperand::createImm(MB)); |
| 1221 | TmpInst.addOperand(MCOperand::createImm(ME)); |
| Hal Finkel | 6e9110a | 2015-03-28 19:42:41 +0000 | [diff] [blame] | 1222 | Inst = TmpInst; |
| 1223 | break; |
| 1224 | } |
| 1225 | case PPC::RLWNMbm: |
| 1226 | case PPC::RLWNMobm: { |
| 1227 | unsigned MB, ME; |
| 1228 | int64_t BM = Inst.getOperand(3).getImm(); |
| 1229 | if (!isRunOfOnes(BM, MB, ME)) |
| 1230 | break; |
| 1231 | |
| 1232 | MCInst TmpInst; |
| 1233 | TmpInst.setOpcode(Opcode == PPC::RLWNMbm ? PPC::RLWNM : PPC::RLWNMo); |
| 1234 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1235 | TmpInst.addOperand(Inst.getOperand(1)); |
| 1236 | TmpInst.addOperand(Inst.getOperand(2)); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1237 | TmpInst.addOperand(MCOperand::createImm(MB)); |
| 1238 | TmpInst.addOperand(MCOperand::createImm(ME)); |
| Hal Finkel | 6e9110a | 2015-03-28 19:42:41 +0000 | [diff] [blame] | 1239 | Inst = TmpInst; |
| 1240 | break; |
| 1241 | } |
| Kit Barton | 4f79f96 | 2015-06-16 16:01:15 +0000 | [diff] [blame] | 1242 | case PPC::MFTB: { |
| Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 1243 | if (getSTI().getFeatureBits()[PPC::FeatureMFTB]) { |
| Kit Barton | 4f79f96 | 2015-06-16 16:01:15 +0000 | [diff] [blame] | 1244 | assert(Inst.getNumOperands() == 2 && "Expecting two operands"); |
| 1245 | Inst.setOpcode(PPC::MFSPR); |
| 1246 | } |
| 1247 | break; |
| 1248 | } |
| Chuang-Yu Cheng | eaf4b3d | 2016-04-06 01:46:45 +0000 | [diff] [blame] | 1249 | case PPC::CP_COPYx: |
| 1250 | case PPC::CP_COPY_FIRST: { |
| 1251 | MCInst TmpInst; |
| 1252 | TmpInst.setOpcode(PPC::CP_COPY); |
| 1253 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1254 | TmpInst.addOperand(Inst.getOperand(1)); |
| 1255 | TmpInst.addOperand(MCOperand::createImm(Opcode == PPC::CP_COPYx ? 0 : 1)); |
| 1256 | |
| 1257 | Inst = TmpInst; |
| 1258 | break; |
| 1259 | } |
| 1260 | case PPC::CP_PASTEx : |
| 1261 | case PPC::CP_PASTE_LAST: { |
| 1262 | MCInst TmpInst; |
| 1263 | TmpInst.setOpcode(Opcode == PPC::CP_PASTEx ? |
| 1264 | PPC::CP_PASTE : PPC::CP_PASTEo); |
| 1265 | TmpInst.addOperand(Inst.getOperand(0)); |
| 1266 | TmpInst.addOperand(Inst.getOperand(1)); |
| 1267 | TmpInst.addOperand(MCOperand::createImm(Opcode == PPC::CP_PASTEx ? 0 : 1)); |
| 1268 | |
| 1269 | Inst = TmpInst; |
| 1270 | break; |
| 1271 | } |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | |
| Hal Finkel | e86a8b7 | 2017-12-16 02:42:18 +0000 | [diff] [blame] | 1275 | static std::string PPCMnemonicSpellCheck(StringRef S, uint64_t FBS, |
| 1276 | unsigned VariantID = 0); |
| 1277 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1278 | bool PPCAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
| 1279 | OperandVector &Operands, |
| Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 1280 | MCStreamer &Out, uint64_t &ErrorInfo, |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1281 | bool MatchingInlineAsm) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1282 | MCInst Inst; |
| 1283 | |
| Ranjeet Singh | 86ecbb7 | 2015-06-30 12:32:53 +0000 | [diff] [blame] | 1284 | switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm)) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1285 | case Match_Success: |
| Ulrich Weigand | d839490 | 2013-05-03 19:50:27 +0000 | [diff] [blame] | 1286 | // Post-process instructions (typically extended mnemonics) |
| 1287 | ProcessInstruction(Inst, Operands); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1288 | Inst.setLoc(IDLoc); |
| Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 1289 | Out.EmitInstruction(Inst, getSTI()); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1290 | return false; |
| 1291 | case Match_MissingFeature: |
| 1292 | return Error(IDLoc, "instruction use requires an option to be enabled"); |
| Hal Finkel | e86a8b7 | 2017-12-16 02:42:18 +0000 | [diff] [blame] | 1293 | case Match_MnemonicFail: { |
| 1294 | uint64_t FBS = ComputeAvailableFeatures(getSTI().getFeatureBits()); |
| 1295 | std::string Suggestion = PPCMnemonicSpellCheck( |
| 1296 | ((PPCOperand &)*Operands[0]).getToken(), FBS); |
| 1297 | return Error(IDLoc, "invalid instruction" + Suggestion, |
| 1298 | ((PPCOperand &)*Operands[0]).getLocRange()); |
| 1299 | } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1300 | case Match_InvalidOperand: { |
| 1301 | SMLoc ErrorLoc = IDLoc; |
| Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 1302 | if (ErrorInfo != ~0ULL) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1303 | if (ErrorInfo >= Operands.size()) |
| 1304 | return Error(IDLoc, "too few operands for instruction"); |
| 1305 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1306 | ErrorLoc = ((PPCOperand &)*Operands[ErrorInfo]).getStartLoc(); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1307 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 1308 | } |
| 1309 | |
| 1310 | return Error(ErrorLoc, "invalid operand for instruction"); |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | llvm_unreachable("Implement any new match types added!"); |
| 1315 | } |
| 1316 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1317 | bool PPCAsmParser::MatchRegisterName(unsigned &RegNo, int64_t &IntVal) { |
| 1318 | if (getParser().getTok().is(AsmToken::Identifier)) { |
| 1319 | StringRef Name = getParser().getTok().getString(); |
| Ulrich Weigand | 509c240 | 2013-05-06 11:16:57 +0000 | [diff] [blame] | 1320 | if (Name.equals_lower("lr")) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1321 | RegNo = isPPC64()? PPC::LR8 : PPC::LR; |
| 1322 | IntVal = 8; |
| Ulrich Weigand | 509c240 | 2013-05-06 11:16:57 +0000 | [diff] [blame] | 1323 | } else if (Name.equals_lower("ctr")) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1324 | RegNo = isPPC64()? PPC::CTR8 : PPC::CTR; |
| 1325 | IntVal = 9; |
| Hal Finkel | 52727c6 | 2013-07-02 03:39:34 +0000 | [diff] [blame] | 1326 | } else if (Name.equals_lower("vrsave")) { |
| 1327 | RegNo = PPC::VRSAVE; |
| 1328 | IntVal = 256; |
| Rui Ueyama | 29d2910 | 2013-10-31 19:59:55 +0000 | [diff] [blame] | 1329 | } else if (Name.startswith_lower("r") && |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1330 | !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { |
| 1331 | RegNo = isPPC64()? XRegs[IntVal] : RRegs[IntVal]; |
| Rui Ueyama | 29d2910 | 2013-10-31 19:59:55 +0000 | [diff] [blame] | 1332 | } else if (Name.startswith_lower("f") && |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1333 | !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { |
| 1334 | RegNo = FRegs[IntVal]; |
| Hal Finkel | 4dc8fcc | 2015-04-23 23:16:22 +0000 | [diff] [blame] | 1335 | } else if (Name.startswith_lower("vs") && |
| 1336 | !Name.substr(2).getAsInteger(10, IntVal) && IntVal < 64) { |
| 1337 | RegNo = VSRegs[IntVal]; |
| Rui Ueyama | 29d2910 | 2013-10-31 19:59:55 +0000 | [diff] [blame] | 1338 | } else if (Name.startswith_lower("v") && |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1339 | !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { |
| 1340 | RegNo = VRegs[IntVal]; |
| Hal Finkel | 4dc8fcc | 2015-04-23 23:16:22 +0000 | [diff] [blame] | 1341 | } else if (Name.startswith_lower("q") && |
| 1342 | !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { |
| 1343 | RegNo = QFRegs[IntVal]; |
| Rui Ueyama | 29d2910 | 2013-10-31 19:59:55 +0000 | [diff] [blame] | 1344 | } else if (Name.startswith_lower("cr") && |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1345 | !Name.substr(2).getAsInteger(10, IntVal) && IntVal < 8) { |
| 1346 | RegNo = CRRegs[IntVal]; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1347 | } else |
| 1348 | return true; |
| 1349 | getParser().Lex(); |
| 1350 | return false; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1351 | } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1352 | return true; |
| 1353 | } |
| 1354 | |
| 1355 | bool PPCAsmParser:: |
| 1356 | ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) { |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1357 | const AsmToken &Tok = getParser().getTok(); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1358 | StartLoc = Tok.getLoc(); |
| 1359 | EndLoc = Tok.getEndLoc(); |
| 1360 | RegNo = 0; |
| 1361 | int64_t IntVal; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1362 | if (MatchRegisterName(RegNo, IntVal)) |
| 1363 | return TokError("invalid register name"); |
| 1364 | return false; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| NAKAMURA Takumi | 36c17ee | 2013-06-25 01:14:20 +0000 | [diff] [blame] | 1367 | /// Extract \code @l/@ha \endcode modifier from expression. Recursively scan |
| Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 1368 | /// the expression and check for VK_PPC_LO/HI/HA |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1369 | /// symbol variants. If all symbols with modifier use the same |
| 1370 | /// variant, return the corresponding PPCMCExpr::VariantKind, |
| 1371 | /// and a modified expression using the default symbol variant. |
| 1372 | /// Otherwise, return NULL. |
| 1373 | const MCExpr *PPCAsmParser:: |
| 1374 | ExtractModifierFromExpr(const MCExpr *E, |
| 1375 | PPCMCExpr::VariantKind &Variant) { |
| 1376 | MCContext &Context = getParser().getContext(); |
| 1377 | Variant = PPCMCExpr::VK_PPC_None; |
| 1378 | |
| 1379 | switch (E->getKind()) { |
| 1380 | case MCExpr::Target: |
| 1381 | case MCExpr::Constant: |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1382 | return nullptr; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1383 | |
| 1384 | case MCExpr::SymbolRef: { |
| 1385 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E); |
| 1386 | |
| 1387 | switch (SRE->getKind()) { |
| Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 1388 | case MCSymbolRefExpr::VK_PPC_LO: |
| 1389 | Variant = PPCMCExpr::VK_PPC_LO; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1390 | break; |
| Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 1391 | case MCSymbolRefExpr::VK_PPC_HI: |
| 1392 | Variant = PPCMCExpr::VK_PPC_HI; |
| 1393 | break; |
| Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 1394 | case MCSymbolRefExpr::VK_PPC_HA: |
| 1395 | Variant = PPCMCExpr::VK_PPC_HA; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1396 | break; |
| Sean Fertile | 80b8f82 | 2018-06-15 19:47:11 +0000 | [diff] [blame^] | 1397 | case MCSymbolRefExpr::VK_PPC_HIGH: |
| 1398 | Variant = PPCMCExpr::VK_PPC_HIGH; |
| 1399 | break; |
| 1400 | case MCSymbolRefExpr::VK_PPC_HIGHA: |
| 1401 | Variant = PPCMCExpr::VK_PPC_HIGHA; |
| 1402 | break; |
| Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 1403 | case MCSymbolRefExpr::VK_PPC_HIGHER: |
| 1404 | Variant = PPCMCExpr::VK_PPC_HIGHER; |
| 1405 | break; |
| 1406 | case MCSymbolRefExpr::VK_PPC_HIGHERA: |
| 1407 | Variant = PPCMCExpr::VK_PPC_HIGHERA; |
| 1408 | break; |
| 1409 | case MCSymbolRefExpr::VK_PPC_HIGHEST: |
| 1410 | Variant = PPCMCExpr::VK_PPC_HIGHEST; |
| 1411 | break; |
| 1412 | case MCSymbolRefExpr::VK_PPC_HIGHESTA: |
| 1413 | Variant = PPCMCExpr::VK_PPC_HIGHESTA; |
| 1414 | break; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1415 | default: |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1416 | return nullptr; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1419 | return MCSymbolRefExpr::create(&SRE->getSymbol(), Context); |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | case MCExpr::Unary: { |
| 1423 | const MCUnaryExpr *UE = cast<MCUnaryExpr>(E); |
| 1424 | const MCExpr *Sub = ExtractModifierFromExpr(UE->getSubExpr(), Variant); |
| 1425 | if (!Sub) |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1426 | return nullptr; |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1427 | return MCUnaryExpr::create(UE->getOpcode(), Sub, Context); |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | case MCExpr::Binary: { |
| 1431 | const MCBinaryExpr *BE = cast<MCBinaryExpr>(E); |
| 1432 | PPCMCExpr::VariantKind LHSVariant, RHSVariant; |
| 1433 | const MCExpr *LHS = ExtractModifierFromExpr(BE->getLHS(), LHSVariant); |
| 1434 | const MCExpr *RHS = ExtractModifierFromExpr(BE->getRHS(), RHSVariant); |
| 1435 | |
| 1436 | if (!LHS && !RHS) |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1437 | return nullptr; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1438 | |
| 1439 | if (!LHS) LHS = BE->getLHS(); |
| 1440 | if (!RHS) RHS = BE->getRHS(); |
| 1441 | |
| 1442 | if (LHSVariant == PPCMCExpr::VK_PPC_None) |
| 1443 | Variant = RHSVariant; |
| 1444 | else if (RHSVariant == PPCMCExpr::VK_PPC_None) |
| 1445 | Variant = LHSVariant; |
| 1446 | else if (LHSVariant == RHSVariant) |
| 1447 | Variant = LHSVariant; |
| 1448 | else |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1449 | return nullptr; |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1450 | |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1451 | return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, Context); |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | llvm_unreachable("Invalid expression kind!"); |
| 1456 | } |
| 1457 | |
| Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 1458 | /// Find all VK_TLSGD/VK_TLSLD symbol references in expression and replace |
| 1459 | /// them by VK_PPC_TLSGD/VK_PPC_TLSLD. This is necessary to avoid having |
| 1460 | /// _GLOBAL_OFFSET_TABLE_ created via ELFObjectWriter::RelocNeedsGOT. |
| 1461 | /// FIXME: This is a hack. |
| 1462 | const MCExpr *PPCAsmParser:: |
| 1463 | FixupVariantKind(const MCExpr *E) { |
| 1464 | MCContext &Context = getParser().getContext(); |
| 1465 | |
| 1466 | switch (E->getKind()) { |
| 1467 | case MCExpr::Target: |
| 1468 | case MCExpr::Constant: |
| 1469 | return E; |
| 1470 | |
| 1471 | case MCExpr::SymbolRef: { |
| 1472 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E); |
| 1473 | MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; |
| 1474 | |
| 1475 | switch (SRE->getKind()) { |
| 1476 | case MCSymbolRefExpr::VK_TLSGD: |
| 1477 | Variant = MCSymbolRefExpr::VK_PPC_TLSGD; |
| 1478 | break; |
| 1479 | case MCSymbolRefExpr::VK_TLSLD: |
| 1480 | Variant = MCSymbolRefExpr::VK_PPC_TLSLD; |
| 1481 | break; |
| 1482 | default: |
| 1483 | return E; |
| 1484 | } |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1485 | return MCSymbolRefExpr::create(&SRE->getSymbol(), Variant, Context); |
| Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | case MCExpr::Unary: { |
| 1489 | const MCUnaryExpr *UE = cast<MCUnaryExpr>(E); |
| 1490 | const MCExpr *Sub = FixupVariantKind(UE->getSubExpr()); |
| 1491 | if (Sub == UE->getSubExpr()) |
| 1492 | return E; |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1493 | return MCUnaryExpr::create(UE->getOpcode(), Sub, Context); |
| Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | case MCExpr::Binary: { |
| 1497 | const MCBinaryExpr *BE = cast<MCBinaryExpr>(E); |
| 1498 | const MCExpr *LHS = FixupVariantKind(BE->getLHS()); |
| 1499 | const MCExpr *RHS = FixupVariantKind(BE->getRHS()); |
| 1500 | if (LHS == BE->getLHS() && RHS == BE->getRHS()) |
| 1501 | return E; |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1502 | return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, Context); |
| Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | llvm_unreachable("Invalid expression kind!"); |
| 1507 | } |
| 1508 | |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1509 | /// ParseExpression. This differs from the default "parseExpression" in that |
| 1510 | /// it handles modifiers. |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1511 | bool PPCAsmParser:: |
| 1512 | ParseExpression(const MCExpr *&EVal) { |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1513 | |
| 1514 | if (isDarwin()) |
| 1515 | return ParseDarwinExpression(EVal); |
| 1516 | |
| 1517 | // (ELF Platforms) |
| 1518 | // Handle \code @l/@ha \endcode |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1519 | if (getParser().parseExpression(EVal)) |
| 1520 | return true; |
| 1521 | |
| Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 1522 | EVal = FixupVariantKind(EVal); |
| 1523 | |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1524 | PPCMCExpr::VariantKind Variant; |
| 1525 | const MCExpr *E = ExtractModifierFromExpr(EVal, Variant); |
| 1526 | if (E) |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1527 | EVal = PPCMCExpr::create(Variant, E, false, getParser().getContext()); |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1528 | |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1532 | /// ParseDarwinExpression. (MachO Platforms) |
| 1533 | /// This differs from the default "parseExpression" in that it handles detection |
| 1534 | /// of the \code hi16(), ha16() and lo16() \endcode modifiers. At present, |
| 1535 | /// parseExpression() doesn't recognise the modifiers when in the Darwin/MachO |
| Eric Christopher | 87590fa | 2016-06-16 01:00:53 +0000 | [diff] [blame] | 1536 | /// syntax form so it is done here. TODO: Determine if there is merit in |
| 1537 | /// arranging for this to be done at a higher level. |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1538 | bool PPCAsmParser:: |
| 1539 | ParseDarwinExpression(const MCExpr *&EVal) { |
| Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 1540 | MCAsmParser &Parser = getParser(); |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1541 | PPCMCExpr::VariantKind Variant = PPCMCExpr::VK_PPC_None; |
| 1542 | switch (getLexer().getKind()) { |
| 1543 | default: |
| 1544 | break; |
| 1545 | case AsmToken::Identifier: |
| 1546 | // Compiler-generated Darwin identifiers begin with L,l,_ or "; thus |
| 1547 | // something starting with any other char should be part of the |
| 1548 | // asm syntax. If handwritten asm includes an identifier like lo16, |
| 1549 | // then all bets are off - but no-one would do that, right? |
| 1550 | StringRef poss = Parser.getTok().getString(); |
| 1551 | if (poss.equals_lower("lo16")) { |
| 1552 | Variant = PPCMCExpr::VK_PPC_LO; |
| 1553 | } else if (poss.equals_lower("hi16")) { |
| 1554 | Variant = PPCMCExpr::VK_PPC_HI; |
| 1555 | } else if (poss.equals_lower("ha16")) { |
| 1556 | Variant = PPCMCExpr::VK_PPC_HA; |
| 1557 | } |
| 1558 | if (Variant != PPCMCExpr::VK_PPC_None) { |
| 1559 | Parser.Lex(); // Eat the xx16 |
| 1560 | if (getLexer().isNot(AsmToken::LParen)) |
| 1561 | return Error(Parser.getTok().getLoc(), "expected '('"); |
| 1562 | Parser.Lex(); // Eat the '(' |
| 1563 | } |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | if (getParser().parseExpression(EVal)) |
| 1568 | return true; |
| 1569 | |
| 1570 | if (Variant != PPCMCExpr::VK_PPC_None) { |
| 1571 | if (getLexer().isNot(AsmToken::RParen)) |
| 1572 | return Error(Parser.getTok().getLoc(), "expected ')'"); |
| 1573 | Parser.Lex(); // Eat the ')' |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1574 | EVal = PPCMCExpr::create(Variant, EVal, false, getParser().getContext()); |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1575 | } |
| 1576 | return false; |
| 1577 | } |
| 1578 | |
| 1579 | /// ParseOperand |
| 1580 | /// This handles registers in the form 'NN', '%rNN' for ELF platforms and |
| 1581 | /// rNN for MachO. |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1582 | bool PPCAsmParser::ParseOperand(OperandVector &Operands) { |
| Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 1583 | MCAsmParser &Parser = getParser(); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1584 | SMLoc S = Parser.getTok().getLoc(); |
| 1585 | SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 1586 | const MCExpr *EVal; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1587 | |
| 1588 | // Attempt to parse the next token as an immediate |
| 1589 | switch (getLexer().getKind()) { |
| 1590 | // Special handling for register names. These are interpreted |
| 1591 | // as immediates corresponding to the register number. |
| 1592 | case AsmToken::Percent: |
| 1593 | Parser.Lex(); // Eat the '%'. |
| 1594 | unsigned RegNo; |
| 1595 | int64_t IntVal; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1596 | if (MatchRegisterName(RegNo, IntVal)) |
| 1597 | return Error(S, "invalid register name"); |
| 1598 | |
| 1599 | Operands.push_back(PPCOperand::CreateImm(IntVal, S, E, isPPC64())); |
| 1600 | return false; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1601 | |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1602 | case AsmToken::Identifier: |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1603 | case AsmToken::LParen: |
| 1604 | case AsmToken::Plus: |
| 1605 | case AsmToken::Minus: |
| 1606 | case AsmToken::Integer: |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1607 | case AsmToken::Dot: |
| 1608 | case AsmToken::Dollar: |
| Roman Divacky | a26f9a6 | 2014-03-12 19:25:57 +0000 | [diff] [blame] | 1609 | case AsmToken::Exclaim: |
| 1610 | case AsmToken::Tilde: |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1611 | // Note that non-register-name identifiers from the compiler will begin |
| 1612 | // with '_', 'L'/'l' or '"'. Of course, handwritten asm could include |
| 1613 | // identifiers like r31foo - so we fall through in the event that parsing |
| 1614 | // a register name fails. |
| 1615 | if (isDarwin()) { |
| 1616 | unsigned RegNo; |
| 1617 | int64_t IntVal; |
| 1618 | if (!MatchRegisterName(RegNo, IntVal)) { |
| 1619 | Operands.push_back(PPCOperand::CreateImm(IntVal, S, E, isPPC64())); |
| 1620 | return false; |
| 1621 | } |
| 1622 | } |
| 1623 | // All other expressions |
| 1624 | |
| Ulrich Weigand | 96e6578 | 2013-06-20 16:23:52 +0000 | [diff] [blame] | 1625 | if (!ParseExpression(EVal)) |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1626 | break; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1627 | // Fall-through |
| 1628 | LLVM_FALLTHROUGH; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1629 | default: |
| 1630 | return Error(S, "unknown operand"); |
| 1631 | } |
| 1632 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1633 | // Push the parsed operand into the list of operands |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1634 | Operands.push_back(PPCOperand::CreateFromMCExpr(EVal, S, E, isPPC64())); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1635 | |
| Ulrich Weigand | 42a09dc | 2013-07-02 21:31:59 +0000 | [diff] [blame] | 1636 | // Check whether this is a TLS call expression |
| 1637 | bool TLSCall = false; |
| 1638 | if (const MCSymbolRefExpr *Ref = dyn_cast<MCSymbolRefExpr>(EVal)) |
| 1639 | TLSCall = Ref->getSymbol().getName() == "__tls_get_addr"; |
| 1640 | |
| 1641 | if (TLSCall && getLexer().is(AsmToken::LParen)) { |
| 1642 | const MCExpr *TLSSym; |
| 1643 | |
| 1644 | Parser.Lex(); // Eat the '('. |
| 1645 | S = Parser.getTok().getLoc(); |
| 1646 | if (ParseExpression(TLSSym)) |
| 1647 | return Error(S, "invalid TLS call expression"); |
| 1648 | if (getLexer().isNot(AsmToken::RParen)) |
| 1649 | return Error(Parser.getTok().getLoc(), "missing ')'"); |
| 1650 | E = Parser.getTok().getLoc(); |
| 1651 | Parser.Lex(); // Eat the ')'. |
| 1652 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1653 | Operands.push_back(PPCOperand::CreateFromMCExpr(TLSSym, S, E, isPPC64())); |
| Ulrich Weigand | 42a09dc | 2013-07-02 21:31:59 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | // Otherwise, check for D-form memory operands |
| 1657 | if (!TLSCall && getLexer().is(AsmToken::LParen)) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1658 | Parser.Lex(); // Eat the '('. |
| 1659 | S = Parser.getTok().getLoc(); |
| 1660 | |
| 1661 | int64_t IntVal; |
| 1662 | switch (getLexer().getKind()) { |
| 1663 | case AsmToken::Percent: |
| 1664 | Parser.Lex(); // Eat the '%'. |
| 1665 | unsigned RegNo; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1666 | if (MatchRegisterName(RegNo, IntVal)) |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1667 | return Error(S, "invalid register name"); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1668 | break; |
| 1669 | |
| 1670 | case AsmToken::Integer: |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1671 | if (isDarwin()) |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1672 | return Error(S, "unexpected integer value"); |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1673 | else if (getParser().parseAbsoluteExpression(IntVal) || IntVal < 0 || |
| 1674 | IntVal > 31) |
| 1675 | return Error(S, "invalid register number"); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1676 | break; |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1677 | case AsmToken::Identifier: |
| 1678 | if (isDarwin()) { |
| 1679 | unsigned RegNo; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1680 | if (!MatchRegisterName(RegNo, IntVal)) { |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | } |
| 1683 | } |
| Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 1684 | LLVM_FALLTHROUGH; |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1685 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1686 | default: |
| 1687 | return Error(S, "invalid memory operand"); |
| 1688 | } |
| 1689 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1690 | E = Parser.getTok().getLoc(); |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1691 | if (parseToken(AsmToken::RParen, "missing ')'")) |
| 1692 | return true; |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1693 | Operands.push_back(PPCOperand::CreateImm(IntVal, S, E, isPPC64())); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | return false; |
| 1697 | } |
| 1698 | |
| 1699 | /// Parse an instruction mnemonic followed by its operands. |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1700 | bool PPCAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
| 1701 | SMLoc NameLoc, OperandVector &Operands) { |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1702 | // The first operand is the token for the instruction name. |
| Ulrich Weigand | 86247b6 | 2013-06-24 16:52:04 +0000 | [diff] [blame] | 1703 | // If the next character is a '+' or '-', we need to add it to the |
| 1704 | // instruction name, to match what TableGen is doing. |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 1705 | std::string NewOpcode; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1706 | if (parseOptionalToken(AsmToken::Plus)) { |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 1707 | NewOpcode = Name; |
| 1708 | NewOpcode += '+'; |
| 1709 | Name = NewOpcode; |
| Ulrich Weigand | 86247b6 | 2013-06-24 16:52:04 +0000 | [diff] [blame] | 1710 | } |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1711 | if (parseOptionalToken(AsmToken::Minus)) { |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 1712 | NewOpcode = Name; |
| 1713 | NewOpcode += '-'; |
| 1714 | Name = NewOpcode; |
| Ulrich Weigand | 86247b6 | 2013-06-24 16:52:04 +0000 | [diff] [blame] | 1715 | } |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1716 | // If the instruction ends in a '.', we need to create a separate |
| 1717 | // token for it, to match what TableGen is doing. |
| 1718 | size_t Dot = Name.find('.'); |
| 1719 | StringRef Mnemonic = Name.slice(0, Dot); |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 1720 | if (!NewOpcode.empty()) // Underlying memory for Name is volatile. |
| 1721 | Operands.push_back( |
| 1722 | PPCOperand::CreateTokenWithStringCopy(Mnemonic, NameLoc, isPPC64())); |
| 1723 | else |
| 1724 | Operands.push_back(PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64())); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1725 | if (Dot != StringRef::npos) { |
| 1726 | SMLoc DotLoc = SMLoc::getFromPointer(NameLoc.getPointer() + Dot); |
| 1727 | StringRef DotStr = Name.slice(Dot, StringRef::npos); |
| Benjamin Kramer | 72d45cc | 2013-08-03 22:43:29 +0000 | [diff] [blame] | 1728 | if (!NewOpcode.empty()) // Underlying memory for Name is volatile. |
| 1729 | Operands.push_back( |
| 1730 | PPCOperand::CreateTokenWithStringCopy(DotStr, DotLoc, isPPC64())); |
| 1731 | else |
| 1732 | Operands.push_back(PPCOperand::CreateToken(DotStr, DotLoc, isPPC64())); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | // If there are no more operands then finish |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1736 | if (parseOptionalToken(AsmToken::EndOfStatement)) |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1737 | return false; |
| 1738 | |
| 1739 | // Parse the first operand |
| 1740 | if (ParseOperand(Operands)) |
| 1741 | return true; |
| 1742 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1743 | while (!parseOptionalToken(AsmToken::EndOfStatement)) { |
| 1744 | if (parseToken(AsmToken::Comma) || ParseOperand(Operands)) |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1745 | return true; |
| 1746 | } |
| 1747 | |
| Hal Finkel | fefcfff | 2015-04-23 22:47:57 +0000 | [diff] [blame] | 1748 | // We'll now deal with an unfortunate special case: the syntax for the dcbt |
| 1749 | // and dcbtst instructions differs for server vs. embedded cores. |
| 1750 | // The syntax for dcbt is: |
| 1751 | // dcbt ra, rb, th [server] |
| 1752 | // dcbt th, ra, rb [embedded] |
| 1753 | // where th can be omitted when it is 0. dcbtst is the same. We take the |
| 1754 | // server form to be the default, so swap the operands if we're parsing for |
| 1755 | // an embedded core (they'll be swapped again upon printing). |
| Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 1756 | if (getSTI().getFeatureBits()[PPC::FeatureBookE] && |
| Hal Finkel | fefcfff | 2015-04-23 22:47:57 +0000 | [diff] [blame] | 1757 | Operands.size() == 4 && |
| 1758 | (Name == "dcbt" || Name == "dcbtst")) { |
| 1759 | std::swap(Operands[1], Operands[3]); |
| 1760 | std::swap(Operands[2], Operands[1]); |
| 1761 | } |
| 1762 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1763 | return false; |
| 1764 | } |
| 1765 | |
| 1766 | /// ParseDirective parses the PPC specific directives |
| 1767 | bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) { |
| 1768 | StringRef IDVal = DirectiveID.getIdentifier(); |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1769 | if (isDarwin()) { |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1770 | if (IDVal == ".machine") |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1771 | ParseDarwinDirectiveMachine(DirectiveID.getLoc()); |
| 1772 | else |
| 1773 | return true; |
| 1774 | } else if (IDVal == ".word") |
| 1775 | ParseDirectiveWord(2, DirectiveID); |
| 1776 | else if (IDVal == ".llong") |
| 1777 | ParseDirectiveWord(8, DirectiveID); |
| 1778 | else if (IDVal == ".tc") |
| 1779 | ParseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID); |
| 1780 | else if (IDVal == ".machine") |
| 1781 | ParseDirectiveMachine(DirectiveID.getLoc()); |
| 1782 | else if (IDVal == ".abiversion") |
| 1783 | ParseDirectiveAbiVersion(DirectiveID.getLoc()); |
| 1784 | else if (IDVal == ".localentry") |
| 1785 | ParseDirectiveLocalEntry(DirectiveID.getLoc()); |
| 1786 | else |
| 1787 | return true; |
| 1788 | return false; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | /// ParseDirectiveWord |
| 1792 | /// ::= .word [ expression (, expression)* ] |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1793 | bool PPCAsmParser::ParseDirectiveWord(unsigned Size, AsmToken ID) { |
| 1794 | auto parseOp = [&]() -> bool { |
| 1795 | const MCExpr *Value; |
| 1796 | SMLoc ExprLoc = getParser().getTok().getLoc(); |
| 1797 | if (getParser().parseExpression(Value)) |
| 1798 | return true; |
| 1799 | if (const auto *MCE = dyn_cast<MCConstantExpr>(Value)) { |
| 1800 | assert(Size <= 8 && "Invalid size"); |
| 1801 | uint64_t IntValue = MCE->getValue(); |
| 1802 | if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue)) |
| 1803 | return Error(ExprLoc, "literal value out of range for '" + |
| 1804 | ID.getIdentifier() + "' directive"); |
| 1805 | getStreamer().EmitIntValue(IntValue, Size); |
| 1806 | } else |
| 1807 | getStreamer().EmitValue(Value, Size, ExprLoc); |
| 1808 | return false; |
| 1809 | }; |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1810 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1811 | if (parseMany(parseOp)) |
| 1812 | return addErrorSuffix(" in '" + ID.getIdentifier() + "' directive"); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1813 | return false; |
| 1814 | } |
| 1815 | |
| 1816 | /// ParseDirectiveTC |
| 1817 | /// ::= .tc [ symbol (, expression)* ] |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1818 | bool PPCAsmParser::ParseDirectiveTC(unsigned Size, AsmToken ID) { |
| Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 1819 | MCAsmParser &Parser = getParser(); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1820 | // Skip TC symbol, which is only used with XCOFF. |
| 1821 | while (getLexer().isNot(AsmToken::EndOfStatement) |
| 1822 | && getLexer().isNot(AsmToken::Comma)) |
| 1823 | Parser.Lex(); |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1824 | if (parseToken(AsmToken::Comma)) |
| 1825 | return addErrorSuffix(" in '.tc' directive"); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Align to word size. |
| 1828 | getParser().getStreamer().EmitValueToAlignment(Size); |
| 1829 | |
| 1830 | // Emit expressions. |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1831 | return ParseDirectiveWord(Size, ID); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1834 | /// ParseDirectiveMachine (ELF platforms) |
| Ulrich Weigand | 55daa77 | 2013-07-09 10:00:34 +0000 | [diff] [blame] | 1835 | /// ::= .machine [ cpu | "push" | "pop" ] |
| 1836 | bool PPCAsmParser::ParseDirectiveMachine(SMLoc L) { |
| Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 1837 | MCAsmParser &Parser = getParser(); |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1838 | if (Parser.getTok().isNot(AsmToken::Identifier) && |
| 1839 | Parser.getTok().isNot(AsmToken::String)) |
| 1840 | return Error(L, "unexpected token in '.machine' directive"); |
| Ulrich Weigand | 55daa77 | 2013-07-09 10:00:34 +0000 | [diff] [blame] | 1841 | |
| 1842 | StringRef CPU = Parser.getTok().getIdentifier(); |
| Ulrich Weigand | 55daa77 | 2013-07-09 10:00:34 +0000 | [diff] [blame] | 1843 | |
| 1844 | // FIXME: Right now, the parser always allows any available |
| 1845 | // instruction, so the .machine directive is not useful. |
| 1846 | // Implement ".machine any" (by doing nothing) for the benefit |
| 1847 | // of existing assembler code. Likewise, we can then implement |
| 1848 | // ".machine push" and ".machine pop" as no-op. |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1849 | if (CPU != "any" && CPU != "push" && CPU != "pop") |
| 1850 | return TokError("unrecognized machine type"); |
| Ulrich Weigand | 55daa77 | 2013-07-09 10:00:34 +0000 | [diff] [blame] | 1851 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1852 | Parser.Lex(); |
| 1853 | |
| 1854 | if (parseToken(AsmToken::EndOfStatement)) |
| 1855 | return addErrorSuffix(" in '.machine' directive"); |
| 1856 | |
| Rafael Espindola | 6b9ee9b | 2014-01-25 02:35:56 +0000 | [diff] [blame] | 1857 | PPCTargetStreamer &TStreamer = |
| 1858 | *static_cast<PPCTargetStreamer *>( |
| 1859 | getParser().getStreamer().getTargetStreamer()); |
| 1860 | TStreamer.emitMachine(CPU); |
| Ulrich Weigand | 55daa77 | 2013-07-09 10:00:34 +0000 | [diff] [blame] | 1861 | |
| 1862 | return false; |
| 1863 | } |
| 1864 | |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1865 | /// ParseDarwinDirectiveMachine (Mach-o platforms) |
| 1866 | /// ::= .machine cpu-identifier |
| 1867 | bool PPCAsmParser::ParseDarwinDirectiveMachine(SMLoc L) { |
| Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 1868 | MCAsmParser &Parser = getParser(); |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1869 | if (Parser.getTok().isNot(AsmToken::Identifier) && |
| 1870 | Parser.getTok().isNot(AsmToken::String)) |
| 1871 | return Error(L, "unexpected token in directive"); |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1872 | |
| 1873 | StringRef CPU = Parser.getTok().getIdentifier(); |
| 1874 | Parser.Lex(); |
| 1875 | |
| 1876 | // FIXME: this is only the 'default' set of cpu variants. |
| 1877 | // However we don't act on this information at present, this is simply |
| 1878 | // allowing parsing to proceed with minimal sanity checking. |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1879 | if (check(CPU != "ppc7400" && CPU != "ppc" && CPU != "ppc64", L, |
| 1880 | "unrecognized cpu type") || |
| 1881 | check(isPPC64() && (CPU == "ppc7400" || CPU == "ppc"), L, |
| 1882 | "wrong cpu type specified for 64bit") || |
| 1883 | check(!isPPC64() && CPU == "ppc64", L, |
| 1884 | "wrong cpu type specified for 32bit") || |
| 1885 | parseToken(AsmToken::EndOfStatement)) |
| 1886 | return addErrorSuffix(" in '.machine' directive"); |
| Iain Sandoe | e0b4cb6 | 2013-12-14 13:34:02 +0000 | [diff] [blame] | 1887 | return false; |
| 1888 | } |
| 1889 | |
| Ulrich Weigand | 0daa516 | 2014-07-20 22:56:57 +0000 | [diff] [blame] | 1890 | /// ParseDirectiveAbiVersion |
| 1891 | /// ::= .abiversion constant-expression |
| 1892 | bool PPCAsmParser::ParseDirectiveAbiVersion(SMLoc L) { |
| 1893 | int64_t AbiVersion; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1894 | if (check(getParser().parseAbsoluteExpression(AbiVersion), L, |
| 1895 | "expected constant expression") || |
| 1896 | parseToken(AsmToken::EndOfStatement)) |
| 1897 | return addErrorSuffix(" in '.abiversion' directive"); |
| Ulrich Weigand | 0daa516 | 2014-07-20 22:56:57 +0000 | [diff] [blame] | 1898 | |
| 1899 | PPCTargetStreamer &TStreamer = |
| 1900 | *static_cast<PPCTargetStreamer *>( |
| 1901 | getParser().getStreamer().getTargetStreamer()); |
| 1902 | TStreamer.emitAbiVersion(AbiVersion); |
| 1903 | |
| 1904 | return false; |
| 1905 | } |
| 1906 | |
| Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 1907 | /// ParseDirectiveLocalEntry |
| 1908 | /// ::= .localentry symbol, expression |
| 1909 | bool PPCAsmParser::ParseDirectiveLocalEntry(SMLoc L) { |
| 1910 | StringRef Name; |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1911 | if (getParser().parseIdentifier(Name)) |
| 1912 | return Error(L, "expected identifier in '.localentry' directive"); |
| 1913 | |
| Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 1914 | MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name)); |
| Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 1915 | const MCExpr *Expr; |
| Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 1916 | |
| Nirav Dave | d6642c1 | 2016-12-05 14:11:03 +0000 | [diff] [blame] | 1917 | if (parseToken(AsmToken::Comma) || |
| 1918 | check(getParser().parseExpression(Expr), L, "expected expression") || |
| 1919 | parseToken(AsmToken::EndOfStatement)) |
| 1920 | return addErrorSuffix(" in '.localentry' directive"); |
| Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 1921 | |
| 1922 | PPCTargetStreamer &TStreamer = |
| 1923 | *static_cast<PPCTargetStreamer *>( |
| 1924 | getParser().getStreamer().getTargetStreamer()); |
| 1925 | TStreamer.emitLocalEntry(Sym, Expr); |
| 1926 | |
| 1927 | return false; |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1932 | /// Force static initialization. |
| 1933 | extern "C" void LLVMInitializePowerPCAsmParser() { |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 1934 | RegisterMCAsmParser<PPCAsmParser> A(getThePPC32Target()); |
| 1935 | RegisterMCAsmParser<PPCAsmParser> B(getThePPC64Target()); |
| 1936 | RegisterMCAsmParser<PPCAsmParser> C(getThePPC64LETarget()); |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | #define GET_REGISTER_MATCHER |
| 1940 | #define GET_MATCHER_IMPLEMENTATION |
| Hal Finkel | e86a8b7 | 2017-12-16 02:42:18 +0000 | [diff] [blame] | 1941 | #define GET_MNEMONIC_SPELL_CHECKER |
| Ulrich Weigand | 640192d | 2013-05-03 19:49:39 +0000 | [diff] [blame] | 1942 | #include "PPCGenAsmMatcher.inc" |
| Ulrich Weigand | c0944b5 | 2013-07-08 14:49:37 +0000 | [diff] [blame] | 1943 | |
| 1944 | // Define this matcher function after the auto-generated include so we |
| 1945 | // have the match class enum definitions. |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1946 | unsigned PPCAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp, |
| Ulrich Weigand | c0944b5 | 2013-07-08 14:49:37 +0000 | [diff] [blame] | 1947 | unsigned Kind) { |
| 1948 | // If the kind is a token for a literal immediate, check if our asm |
| 1949 | // operand matches. This is for InstAliases which have a fixed-value |
| 1950 | // immediate in the syntax. |
| 1951 | int64_t ImmVal; |
| 1952 | switch (Kind) { |
| 1953 | case MCK_0: ImmVal = 0; break; |
| 1954 | case MCK_1: ImmVal = 1; break; |
| Roman Divacky | 62cb635 | 2013-09-12 17:50:54 +0000 | [diff] [blame] | 1955 | case MCK_2: ImmVal = 2; break; |
| 1956 | case MCK_3: ImmVal = 3; break; |
| Joerg Sonnenberger | dda8e78 | 2014-07-30 09:24:37 +0000 | [diff] [blame] | 1957 | case MCK_4: ImmVal = 4; break; |
| 1958 | case MCK_5: ImmVal = 5; break; |
| 1959 | case MCK_6: ImmVal = 6; break; |
| 1960 | case MCK_7: ImmVal = 7; break; |
| Ulrich Weigand | c0944b5 | 2013-07-08 14:49:37 +0000 | [diff] [blame] | 1961 | default: return Match_InvalidOperand; |
| 1962 | } |
| 1963 | |
| David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 1964 | PPCOperand &Op = static_cast<PPCOperand &>(AsmOp); |
| 1965 | if (Op.isImm() && Op.getImm() == ImmVal) |
| Ulrich Weigand | c0944b5 | 2013-07-08 14:49:37 +0000 | [diff] [blame] | 1966 | return Match_Success; |
| 1967 | |
| 1968 | return Match_InvalidOperand; |
| 1969 | } |
| 1970 | |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1971 | const MCExpr * |
| 1972 | PPCAsmParser::applyModifierToExpr(const MCExpr *E, |
| 1973 | MCSymbolRefExpr::VariantKind Variant, |
| 1974 | MCContext &Ctx) { |
| 1975 | switch (Variant) { |
| 1976 | case MCSymbolRefExpr::VK_PPC_LO: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1977 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_LO, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1978 | case MCSymbolRefExpr::VK_PPC_HI: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1979 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HI, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1980 | case MCSymbolRefExpr::VK_PPC_HA: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1981 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HA, E, false, Ctx); |
| Sean Fertile | 80b8f82 | 2018-06-15 19:47:11 +0000 | [diff] [blame^] | 1982 | case MCSymbolRefExpr::VK_PPC_HIGH: |
| 1983 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGH, E, false, Ctx); |
| 1984 | case MCSymbolRefExpr::VK_PPC_HIGHA: |
| 1985 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHA, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1986 | case MCSymbolRefExpr::VK_PPC_HIGHER: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1987 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHER, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1988 | case MCSymbolRefExpr::VK_PPC_HIGHERA: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1989 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHERA, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1990 | case MCSymbolRefExpr::VK_PPC_HIGHEST: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1991 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHEST, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1992 | case MCSymbolRefExpr::VK_PPC_HIGHESTA: |
| Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 1993 | return PPCMCExpr::create(PPCMCExpr::VK_PPC_HIGHESTA, E, false, Ctx); |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1994 | default: |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1995 | return nullptr; |
| Joerg Sonnenberger | b822af4 | 2013-08-27 20:23:19 +0000 | [diff] [blame] | 1996 | } |
| 1997 | } |