Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- SystemZAsmParser.cpp - Parse SystemZ assembly instructions --------===// |
| 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 | |
| 10 | #include "MCTargetDesc/SystemZMCTargetDesc.h" |
Craig Topper | 690d8ea | 2013-07-24 07:33:14 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/STLExtras.h" |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCContext.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCExpr.h" |
| 14 | #include "llvm/MC/MCInst.h" |
| 15 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" |
Benjamin Kramer | b3e8a6d | 2016-01-27 10:01:28 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCParser/MCTargetAsmParser.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCStreamer.h" |
| 18 | #include "llvm/MC/MCSubtargetInfo.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 19 | #include "llvm/Support/TargetRegistry.h" |
| 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | // Return true if Expr is in the range [MinValue, MaxValue]. |
| 24 | static bool inRange(const MCExpr *Expr, int64_t MinValue, int64_t MaxValue) { |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 25 | if (auto *CE = dyn_cast<MCConstantExpr>(Expr)) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 26 | int64_t Value = CE->getValue(); |
| 27 | return Value >= MinValue && Value <= MaxValue; |
| 28 | } |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | namespace { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 33 | enum RegisterKind { |
| 34 | GR32Reg, |
Richard Sandiford | f949606 | 2013-09-30 10:45:16 +0000 | [diff] [blame] | 35 | GRH32Reg, |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 36 | GR64Reg, |
| 37 | GR128Reg, |
| 38 | ADDR32Reg, |
| 39 | ADDR64Reg, |
| 40 | FP32Reg, |
| 41 | FP64Reg, |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 42 | FP128Reg, |
| 43 | VR32Reg, |
| 44 | VR64Reg, |
| 45 | VR128Reg |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | enum MemoryKind { |
| 49 | BDMem, |
| 50 | BDXMem, |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 51 | BDLMem, |
| 52 | BDVMem |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 55 | class SystemZOperand : public MCParsedAsmOperand { |
| 56 | public: |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 57 | private: |
| 58 | enum OperandKind { |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 59 | KindInvalid, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 60 | KindToken, |
| 61 | KindReg, |
| 62 | KindAccessReg, |
| 63 | KindImm, |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 64 | KindImmTLS, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 65 | KindMem |
| 66 | }; |
| 67 | |
| 68 | OperandKind Kind; |
| 69 | SMLoc StartLoc, EndLoc; |
| 70 | |
| 71 | // A string of length Length, starting at Data. |
| 72 | struct TokenOp { |
| 73 | const char *Data; |
| 74 | unsigned Length; |
| 75 | }; |
| 76 | |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 77 | // LLVM register Num, which has kind Kind. In some ways it might be |
| 78 | // easier for this class to have a register bank (general, floating-point |
| 79 | // or access) and a raw register number (0-15). This would postpone the |
| 80 | // interpretation of the operand to the add*() methods and avoid the need |
| 81 | // for context-dependent parsing. However, we do things the current way |
| 82 | // because of the virtual getReg() method, which needs to distinguish |
| 83 | // between (say) %r0 used as a single register and %r0 used as a pair. |
| 84 | // Context-dependent parsing can also give us slightly better error |
| 85 | // messages when invalid pairs like %r1 are used. |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 86 | struct RegOp { |
| 87 | RegisterKind Kind; |
| 88 | unsigned Num; |
| 89 | }; |
| 90 | |
| 91 | // Base + Disp + Index, where Base and Index are LLVM registers or 0. |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 92 | // MemKind says what type of memory this is and RegKind says what type |
| 93 | // the base register has (ADDR32Reg or ADDR64Reg). Length is the operand |
| 94 | // length for D(L,B)-style operands, otherwise it is null. |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 95 | struct MemOp { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 96 | unsigned Base : 12; |
| 97 | unsigned Index : 12; |
| 98 | unsigned MemKind : 4; |
| 99 | unsigned RegKind : 4; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 100 | const MCExpr *Disp; |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 101 | const MCExpr *Length; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 104 | // Imm is an immediate operand, and Sym is an optional TLS symbol |
| 105 | // for use with a __tls_get_offset marker relocation. |
| 106 | struct ImmTLSOp { |
| 107 | const MCExpr *Imm; |
| 108 | const MCExpr *Sym; |
| 109 | }; |
| 110 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 111 | union { |
| 112 | TokenOp Token; |
| 113 | RegOp Reg; |
| 114 | unsigned AccessReg; |
| 115 | const MCExpr *Imm; |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 116 | ImmTLSOp ImmTLS; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 117 | MemOp Mem; |
| 118 | }; |
| 119 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 120 | void addExpr(MCInst &Inst, const MCExpr *Expr) const { |
| 121 | // Add as immediates when possible. Null MCExpr = 0. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 122 | if (!Expr) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 123 | Inst.addOperand(MCOperand::createImm(0)); |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 124 | else if (auto *CE = dyn_cast<MCConstantExpr>(Expr)) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 125 | Inst.addOperand(MCOperand::createImm(CE->getValue())); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 126 | else |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 127 | Inst.addOperand(MCOperand::createExpr(Expr)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | public: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 131 | SystemZOperand(OperandKind kind, SMLoc startLoc, SMLoc endLoc) |
| 132 | : Kind(kind), StartLoc(startLoc), EndLoc(endLoc) {} |
| 133 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 134 | // Create particular kinds of operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 135 | static std::unique_ptr<SystemZOperand> createInvalid(SMLoc StartLoc, |
| 136 | SMLoc EndLoc) { |
| 137 | return make_unique<SystemZOperand>(KindInvalid, StartLoc, EndLoc); |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 138 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 139 | static std::unique_ptr<SystemZOperand> createToken(StringRef Str, SMLoc Loc) { |
| 140 | auto Op = make_unique<SystemZOperand>(KindToken, Loc, Loc); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 141 | Op->Token.Data = Str.data(); |
| 142 | Op->Token.Length = Str.size(); |
| 143 | return Op; |
| 144 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 145 | static std::unique_ptr<SystemZOperand> |
| 146 | createReg(RegisterKind Kind, unsigned Num, SMLoc StartLoc, SMLoc EndLoc) { |
| 147 | auto Op = make_unique<SystemZOperand>(KindReg, StartLoc, EndLoc); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 148 | Op->Reg.Kind = Kind; |
| 149 | Op->Reg.Num = Num; |
| 150 | return Op; |
| 151 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 152 | static std::unique_ptr<SystemZOperand> |
| 153 | createAccessReg(unsigned Num, SMLoc StartLoc, SMLoc EndLoc) { |
| 154 | auto Op = make_unique<SystemZOperand>(KindAccessReg, StartLoc, EndLoc); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 155 | Op->AccessReg = Num; |
| 156 | return Op; |
| 157 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 158 | static std::unique_ptr<SystemZOperand> |
| 159 | createImm(const MCExpr *Expr, SMLoc StartLoc, SMLoc EndLoc) { |
| 160 | auto Op = make_unique<SystemZOperand>(KindImm, StartLoc, EndLoc); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 161 | Op->Imm = Expr; |
| 162 | return Op; |
| 163 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 164 | static std::unique_ptr<SystemZOperand> |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 165 | createMem(MemoryKind MemKind, RegisterKind RegKind, unsigned Base, |
| 166 | const MCExpr *Disp, unsigned Index, const MCExpr *Length, |
| 167 | SMLoc StartLoc, SMLoc EndLoc) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 168 | auto Op = make_unique<SystemZOperand>(KindMem, StartLoc, EndLoc); |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 169 | Op->Mem.MemKind = MemKind; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 170 | Op->Mem.RegKind = RegKind; |
| 171 | Op->Mem.Base = Base; |
| 172 | Op->Mem.Index = Index; |
| 173 | Op->Mem.Disp = Disp; |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 174 | Op->Mem.Length = Length; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 175 | return Op; |
| 176 | } |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 177 | static std::unique_ptr<SystemZOperand> |
| 178 | createImmTLS(const MCExpr *Imm, const MCExpr *Sym, |
| 179 | SMLoc StartLoc, SMLoc EndLoc) { |
| 180 | auto Op = make_unique<SystemZOperand>(KindImmTLS, StartLoc, EndLoc); |
| 181 | Op->ImmTLS.Imm = Imm; |
| 182 | Op->ImmTLS.Sym = Sym; |
| 183 | return Op; |
| 184 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 185 | |
| 186 | // Token operands |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 187 | bool isToken() const override { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 188 | return Kind == KindToken; |
| 189 | } |
| 190 | StringRef getToken() const { |
| 191 | assert(Kind == KindToken && "Not a token"); |
| 192 | return StringRef(Token.Data, Token.Length); |
| 193 | } |
| 194 | |
| 195 | // Register operands. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 196 | bool isReg() const override { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 197 | return Kind == KindReg; |
| 198 | } |
| 199 | bool isReg(RegisterKind RegKind) const { |
| 200 | return Kind == KindReg && Reg.Kind == RegKind; |
| 201 | } |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 202 | unsigned getReg() const override { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 203 | assert(Kind == KindReg && "Not a register"); |
| 204 | return Reg.Num; |
| 205 | } |
| 206 | |
| 207 | // Access register operands. Access registers aren't exposed to LLVM |
| 208 | // as registers. |
| 209 | bool isAccessReg() const { |
| 210 | return Kind == KindAccessReg; |
| 211 | } |
| 212 | |
| 213 | // Immediate operands. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 214 | bool isImm() const override { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 215 | return Kind == KindImm; |
| 216 | } |
| 217 | bool isImm(int64_t MinValue, int64_t MaxValue) const { |
| 218 | return Kind == KindImm && inRange(Imm, MinValue, MaxValue); |
| 219 | } |
| 220 | const MCExpr *getImm() const { |
| 221 | assert(Kind == KindImm && "Not an immediate"); |
| 222 | return Imm; |
| 223 | } |
| 224 | |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 225 | // Immediate operands with optional TLS symbol. |
| 226 | bool isImmTLS() const { |
| 227 | return Kind == KindImmTLS; |
| 228 | } |
| 229 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 230 | // Memory operands. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 231 | bool isMem() const override { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 232 | return Kind == KindMem; |
| 233 | } |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 234 | bool isMem(MemoryKind MemKind) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 235 | return (Kind == KindMem && |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 236 | (Mem.MemKind == MemKind || |
| 237 | // A BDMem can be treated as a BDXMem in which the index |
| 238 | // register field is 0. |
| 239 | (Mem.MemKind == BDMem && MemKind == BDXMem))); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 240 | } |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 241 | bool isMem(MemoryKind MemKind, RegisterKind RegKind) const { |
| 242 | return isMem(MemKind) && Mem.RegKind == RegKind; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 243 | } |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 244 | bool isMemDisp12(MemoryKind MemKind, RegisterKind RegKind) const { |
| 245 | return isMem(MemKind, RegKind) && inRange(Mem.Disp, 0, 0xfff); |
| 246 | } |
| 247 | bool isMemDisp20(MemoryKind MemKind, RegisterKind RegKind) const { |
| 248 | return isMem(MemKind, RegKind) && inRange(Mem.Disp, -524288, 524287); |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 249 | } |
| 250 | bool isMemDisp12Len8(RegisterKind RegKind) const { |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 251 | return isMemDisp12(BDLMem, RegKind) && inRange(Mem.Length, 1, 0x100); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 252 | } |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 253 | void addBDVAddrOperands(MCInst &Inst, unsigned N) const { |
| 254 | assert(N == 3 && "Invalid number of operands"); |
| 255 | assert(isMem(BDVMem) && "Invalid operand type"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 256 | Inst.addOperand(MCOperand::createReg(Mem.Base)); |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 257 | addExpr(Inst, Mem.Disp); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 258 | Inst.addOperand(MCOperand::createReg(Mem.Index)); |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 259 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 260 | |
| 261 | // Override MCParsedAsmOperand. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 262 | SMLoc getStartLoc() const override { return StartLoc; } |
| 263 | SMLoc getEndLoc() const override { return EndLoc; } |
| 264 | void print(raw_ostream &OS) const override; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 265 | |
| 266 | // Used by the TableGen code to add particular types of operand |
| 267 | // to an instruction. |
| 268 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 269 | assert(N == 1 && "Invalid number of operands"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 270 | Inst.addOperand(MCOperand::createReg(getReg())); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 271 | } |
| 272 | void addAccessRegOperands(MCInst &Inst, unsigned N) const { |
| 273 | assert(N == 1 && "Invalid number of operands"); |
| 274 | assert(Kind == KindAccessReg && "Invalid operand type"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 275 | Inst.addOperand(MCOperand::createImm(AccessReg)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 276 | } |
| 277 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 278 | assert(N == 1 && "Invalid number of operands"); |
| 279 | addExpr(Inst, getImm()); |
| 280 | } |
| 281 | void addBDAddrOperands(MCInst &Inst, unsigned N) const { |
| 282 | assert(N == 2 && "Invalid number of operands"); |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 283 | assert(isMem(BDMem) && "Invalid operand type"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 284 | Inst.addOperand(MCOperand::createReg(Mem.Base)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 285 | addExpr(Inst, Mem.Disp); |
| 286 | } |
| 287 | void addBDXAddrOperands(MCInst &Inst, unsigned N) const { |
| 288 | assert(N == 3 && "Invalid number of operands"); |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 289 | assert(isMem(BDXMem) && "Invalid operand type"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 290 | Inst.addOperand(MCOperand::createReg(Mem.Base)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 291 | addExpr(Inst, Mem.Disp); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 292 | Inst.addOperand(MCOperand::createReg(Mem.Index)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 293 | } |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 294 | void addBDLAddrOperands(MCInst &Inst, unsigned N) const { |
| 295 | assert(N == 3 && "Invalid number of operands"); |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 296 | assert(isMem(BDLMem) && "Invalid operand type"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 297 | Inst.addOperand(MCOperand::createReg(Mem.Base)); |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 298 | addExpr(Inst, Mem.Disp); |
| 299 | addExpr(Inst, Mem.Length); |
| 300 | } |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 301 | void addImmTLSOperands(MCInst &Inst, unsigned N) const { |
| 302 | assert(N == 2 && "Invalid number of operands"); |
| 303 | assert(Kind == KindImmTLS && "Invalid operand type"); |
| 304 | addExpr(Inst, ImmTLS.Imm); |
| 305 | if (ImmTLS.Sym) |
| 306 | addExpr(Inst, ImmTLS.Sym); |
| 307 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 308 | |
| 309 | // Used by the TableGen code to check for particular operand types. |
| 310 | bool isGR32() const { return isReg(GR32Reg); } |
Richard Sandiford | f949606 | 2013-09-30 10:45:16 +0000 | [diff] [blame] | 311 | bool isGRH32() const { return isReg(GRH32Reg); } |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 312 | bool isGRX32() const { return false; } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 313 | bool isGR64() const { return isReg(GR64Reg); } |
| 314 | bool isGR128() const { return isReg(GR128Reg); } |
| 315 | bool isADDR32() const { return isReg(ADDR32Reg); } |
| 316 | bool isADDR64() const { return isReg(ADDR64Reg); } |
| 317 | bool isADDR128() const { return false; } |
| 318 | bool isFP32() const { return isReg(FP32Reg); } |
| 319 | bool isFP64() const { return isReg(FP64Reg); } |
| 320 | bool isFP128() const { return isReg(FP128Reg); } |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 321 | bool isVR32() const { return isReg(VR32Reg); } |
| 322 | bool isVR64() const { return isReg(VR64Reg); } |
| 323 | bool isVF128() const { return false; } |
| 324 | bool isVR128() const { return isReg(VR128Reg); } |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 325 | bool isBDAddr32Disp12() const { return isMemDisp12(BDMem, ADDR32Reg); } |
| 326 | bool isBDAddr32Disp20() const { return isMemDisp20(BDMem, ADDR32Reg); } |
| 327 | bool isBDAddr64Disp12() const { return isMemDisp12(BDMem, ADDR64Reg); } |
| 328 | bool isBDAddr64Disp20() const { return isMemDisp20(BDMem, ADDR64Reg); } |
| 329 | bool isBDXAddr64Disp12() const { return isMemDisp12(BDXMem, ADDR64Reg); } |
| 330 | bool isBDXAddr64Disp20() const { return isMemDisp20(BDXMem, ADDR64Reg); } |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 331 | bool isBDLAddr64Disp12Len8() const { return isMemDisp12Len8(ADDR64Reg); } |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 332 | bool isBDVAddr64Disp12() const { return isMemDisp12(BDVMem, ADDR64Reg); } |
| 333 | bool isU1Imm() const { return isImm(0, 1); } |
| 334 | bool isU2Imm() const { return isImm(0, 3); } |
| 335 | bool isU3Imm() const { return isImm(0, 7); } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 336 | bool isU4Imm() const { return isImm(0, 15); } |
| 337 | bool isU6Imm() const { return isImm(0, 63); } |
| 338 | bool isU8Imm() const { return isImm(0, 255); } |
| 339 | bool isS8Imm() const { return isImm(-128, 127); } |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 340 | bool isU12Imm() const { return isImm(0, 4095); } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 341 | bool isU16Imm() const { return isImm(0, 65535); } |
| 342 | bool isS16Imm() const { return isImm(-32768, 32767); } |
| 343 | bool isU32Imm() const { return isImm(0, (1LL << 32) - 1); } |
| 344 | bool isS32Imm() const { return isImm(-(1LL << 31), (1LL << 31) - 1); } |
| 345 | }; |
| 346 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 347 | class SystemZAsmParser : public MCTargetAsmParser { |
| 348 | #define GET_ASSEMBLER_HEADER |
| 349 | #include "SystemZGenAsmMatcher.inc" |
| 350 | |
| 351 | private: |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 352 | MCAsmParser &Parser; |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 353 | enum RegisterGroup { |
| 354 | RegGR, |
| 355 | RegFP, |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 356 | RegV, |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 357 | RegAccess |
| 358 | }; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 359 | struct Register { |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 360 | RegisterGroup Group; |
| 361 | unsigned Num; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 362 | SMLoc StartLoc, EndLoc; |
| 363 | }; |
| 364 | |
| 365 | bool parseRegister(Register &Reg); |
| 366 | |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 367 | bool parseRegister(Register &Reg, RegisterGroup Group, const unsigned *Regs, |
| 368 | bool IsAddress = false); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 369 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 370 | OperandMatchResultTy parseRegister(OperandVector &Operands, |
| 371 | RegisterGroup Group, const unsigned *Regs, |
| 372 | RegisterKind Kind); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 373 | |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 374 | bool parseAddress(unsigned &Base, const MCExpr *&Disp, |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 375 | unsigned &Index, bool &IsVector, const MCExpr *&Length, |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 376 | const unsigned *Regs, RegisterKind RegKind); |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 377 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 378 | OperandMatchResultTy parseAddress(OperandVector &Operands, |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 379 | MemoryKind MemKind, const unsigned *Regs, |
| 380 | RegisterKind RegKind); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 381 | |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 382 | OperandMatchResultTy parsePCRel(OperandVector &Operands, int64_t MinVal, |
| 383 | int64_t MaxVal, bool AllowTLS); |
| 384 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 385 | bool parseOperand(OperandVector &Operands, StringRef Mnemonic); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 386 | |
| 387 | public: |
Akira Hatanaka | b11ef08 | 2015-11-14 06:35:56 +0000 | [diff] [blame] | 388 | SystemZAsmParser(const MCSubtargetInfo &sti, MCAsmParser &parser, |
Evgeniy Stepanov | 0a951b7 | 2014-04-23 11:16:03 +0000 | [diff] [blame] | 389 | const MCInstrInfo &MII, |
| 390 | const MCTargetOptions &Options) |
Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 391 | : MCTargetAsmParser(Options, sti), Parser(parser) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 392 | MCAsmParserExtension::Initialize(Parser); |
| 393 | |
| 394 | // Initialize the set of available features. |
Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 395 | setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits())); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // Override MCTargetAsmParser. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 399 | bool ParseDirective(AsmToken DirectiveID) override; |
| 400 | bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 401 | bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
| 402 | SMLoc NameLoc, OperandVector &Operands) override; |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 403 | bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 404 | OperandVector &Operands, MCStreamer &Out, |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 405 | uint64_t &ErrorInfo, |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 406 | bool MatchingInlineAsm) override; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 407 | |
| 408 | // Used by the TableGen code to parse particular operand types. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 409 | OperandMatchResultTy parseGR32(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 410 | return parseRegister(Operands, RegGR, SystemZMC::GR32Regs, GR32Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 411 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 412 | OperandMatchResultTy parseGRH32(OperandVector &Operands) { |
Richard Sandiford | f949606 | 2013-09-30 10:45:16 +0000 | [diff] [blame] | 413 | return parseRegister(Operands, RegGR, SystemZMC::GRH32Regs, GRH32Reg); |
| 414 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 415 | OperandMatchResultTy parseGRX32(OperandVector &Operands) { |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 416 | llvm_unreachable("GRX32 should only be used for pseudo instructions"); |
| 417 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 418 | OperandMatchResultTy parseGR64(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 419 | return parseRegister(Operands, RegGR, SystemZMC::GR64Regs, GR64Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 420 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 421 | OperandMatchResultTy parseGR128(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 422 | return parseRegister(Operands, RegGR, SystemZMC::GR128Regs, GR128Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 423 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 424 | OperandMatchResultTy parseADDR32(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 425 | return parseRegister(Operands, RegGR, SystemZMC::GR32Regs, ADDR32Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 426 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 427 | OperandMatchResultTy parseADDR64(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 428 | return parseRegister(Operands, RegGR, SystemZMC::GR64Regs, ADDR64Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 429 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 430 | OperandMatchResultTy parseADDR128(OperandVector &Operands) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 431 | llvm_unreachable("Shouldn't be used as an operand"); |
| 432 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 433 | OperandMatchResultTy parseFP32(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 434 | return parseRegister(Operands, RegFP, SystemZMC::FP32Regs, FP32Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 435 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 436 | OperandMatchResultTy parseFP64(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 437 | return parseRegister(Operands, RegFP, SystemZMC::FP64Regs, FP64Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 438 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 439 | OperandMatchResultTy parseFP128(OperandVector &Operands) { |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 440 | return parseRegister(Operands, RegFP, SystemZMC::FP128Regs, FP128Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 441 | } |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 442 | OperandMatchResultTy parseVR32(OperandVector &Operands) { |
| 443 | return parseRegister(Operands, RegV, SystemZMC::VR32Regs, VR32Reg); |
| 444 | } |
| 445 | OperandMatchResultTy parseVR64(OperandVector &Operands) { |
| 446 | return parseRegister(Operands, RegV, SystemZMC::VR64Regs, VR64Reg); |
| 447 | } |
| 448 | OperandMatchResultTy parseVF128(OperandVector &Operands) { |
| 449 | llvm_unreachable("Shouldn't be used as an operand"); |
| 450 | } |
| 451 | OperandMatchResultTy parseVR128(OperandVector &Operands) { |
| 452 | return parseRegister(Operands, RegV, SystemZMC::VR128Regs, VR128Reg); |
| 453 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 454 | OperandMatchResultTy parseBDAddr32(OperandVector &Operands) { |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 455 | return parseAddress(Operands, BDMem, SystemZMC::GR32Regs, ADDR32Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 456 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 457 | OperandMatchResultTy parseBDAddr64(OperandVector &Operands) { |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 458 | return parseAddress(Operands, BDMem, SystemZMC::GR64Regs, ADDR64Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 459 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 460 | OperandMatchResultTy parseBDXAddr64(OperandVector &Operands) { |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 461 | return parseAddress(Operands, BDXMem, SystemZMC::GR64Regs, ADDR64Reg); |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 462 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 463 | OperandMatchResultTy parseBDLAddr64(OperandVector &Operands) { |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 464 | return parseAddress(Operands, BDLMem, SystemZMC::GR64Regs, ADDR64Reg); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 465 | } |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 466 | OperandMatchResultTy parseBDVAddr64(OperandVector &Operands) { |
| 467 | return parseAddress(Operands, BDVMem, SystemZMC::GR64Regs, ADDR64Reg); |
| 468 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 469 | OperandMatchResultTy parseAccessReg(OperandVector &Operands); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 470 | OperandMatchResultTy parsePCRel16(OperandVector &Operands) { |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 471 | return parsePCRel(Operands, -(1LL << 16), (1LL << 16) - 1, false); |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 472 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 473 | OperandMatchResultTy parsePCRel32(OperandVector &Operands) { |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 474 | return parsePCRel(Operands, -(1LL << 32), (1LL << 32) - 1, false); |
| 475 | } |
| 476 | OperandMatchResultTy parsePCRelTLS16(OperandVector &Operands) { |
| 477 | return parsePCRel(Operands, -(1LL << 16), (1LL << 16) - 1, true); |
| 478 | } |
| 479 | OperandMatchResultTy parsePCRelTLS32(OperandVector &Operands) { |
| 480 | return parsePCRel(Operands, -(1LL << 32), (1LL << 32) - 1, true); |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 481 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 482 | }; |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 483 | } // end anonymous namespace |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 484 | |
| 485 | #define GET_REGISTER_MATCHER |
| 486 | #define GET_SUBTARGET_FEATURE_NAME |
| 487 | #define GET_MATCHER_IMPLEMENTATION |
| 488 | #include "SystemZGenAsmMatcher.inc" |
| 489 | |
| 490 | void SystemZOperand::print(raw_ostream &OS) const { |
| 491 | llvm_unreachable("Not implemented"); |
| 492 | } |
| 493 | |
| 494 | // Parse one register of the form %<prefix><number>. |
| 495 | bool SystemZAsmParser::parseRegister(Register &Reg) { |
| 496 | Reg.StartLoc = Parser.getTok().getLoc(); |
| 497 | |
| 498 | // Eat the % prefix. |
| 499 | if (Parser.getTok().isNot(AsmToken::Percent)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 500 | return Error(Parser.getTok().getLoc(), "register expected"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 501 | Parser.Lex(); |
| 502 | |
| 503 | // Expect a register name. |
| 504 | if (Parser.getTok().isNot(AsmToken::Identifier)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 505 | return Error(Reg.StartLoc, "invalid register"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 506 | |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 507 | // Check that there's a prefix. |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 508 | StringRef Name = Parser.getTok().getString(); |
| 509 | if (Name.size() < 2) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 510 | return Error(Reg.StartLoc, "invalid register"); |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 511 | char Prefix = Name[0]; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 512 | |
| 513 | // Treat the rest of the register name as a register number. |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 514 | if (Name.substr(1).getAsInteger(10, Reg.Num)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 515 | return Error(Reg.StartLoc, "invalid register"); |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 516 | |
| 517 | // Look for valid combinations of prefix and number. |
| 518 | if (Prefix == 'r' && Reg.Num < 16) |
| 519 | Reg.Group = RegGR; |
| 520 | else if (Prefix == 'f' && Reg.Num < 16) |
| 521 | Reg.Group = RegFP; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 522 | else if (Prefix == 'v' && Reg.Num < 32) |
| 523 | Reg.Group = RegV; |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 524 | else if (Prefix == 'a' && Reg.Num < 16) |
| 525 | Reg.Group = RegAccess; |
| 526 | else |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 527 | return Error(Reg.StartLoc, "invalid register"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 528 | |
| 529 | Reg.EndLoc = Parser.getTok().getLoc(); |
| 530 | Parser.Lex(); |
| 531 | return false; |
| 532 | } |
| 533 | |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 534 | // Parse a register of group Group. If Regs is nonnull, use it to map |
Jonas Paulsson | 0a9049b | 2015-10-09 07:19:12 +0000 | [diff] [blame] | 535 | // the raw register number to LLVM numbering, with zero entries |
| 536 | // indicating an invalid register. IsAddress says whether the |
| 537 | // register appears in an address context. Allow FP Group if expecting |
| 538 | // RegV Group, since the f-prefix yields the FP group even while used |
| 539 | // with vector instructions. |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 540 | bool SystemZAsmParser::parseRegister(Register &Reg, RegisterGroup Group, |
| 541 | const unsigned *Regs, bool IsAddress) { |
| 542 | if (parseRegister(Reg)) |
| 543 | return true; |
Jonas Paulsson | 0a9049b | 2015-10-09 07:19:12 +0000 | [diff] [blame] | 544 | if (Reg.Group != Group && !(Reg.Group == RegFP && Group == RegV)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 545 | return Error(Reg.StartLoc, "invalid operand for instruction"); |
| 546 | if (Regs && Regs[Reg.Num] == 0) |
| 547 | return Error(Reg.StartLoc, "invalid register pair"); |
| 548 | if (Reg.Num == 0 && IsAddress) |
| 549 | return Error(Reg.StartLoc, "%r0 used in an address"); |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 550 | if (Regs) |
| 551 | Reg.Num = Regs[Reg.Num]; |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 552 | return false; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 555 | // Parse a register and add it to Operands. The other arguments are as above. |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 556 | SystemZAsmParser::OperandMatchResultTy |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 557 | SystemZAsmParser::parseRegister(OperandVector &Operands, RegisterGroup Group, |
| 558 | const unsigned *Regs, RegisterKind Kind) { |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 559 | if (Parser.getTok().isNot(AsmToken::Percent)) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 560 | return MatchOperand_NoMatch; |
| 561 | |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 562 | Register Reg; |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 563 | bool IsAddress = (Kind == ADDR32Reg || Kind == ADDR64Reg); |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 564 | if (parseRegister(Reg, Group, Regs, IsAddress)) |
| 565 | return MatchOperand_ParseFail; |
| 566 | |
| 567 | Operands.push_back(SystemZOperand::createReg(Kind, Reg.Num, |
| 568 | Reg.StartLoc, Reg.EndLoc)); |
| 569 | return MatchOperand_Success; |
| 570 | } |
| 571 | |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 572 | // Parse a memory operand into Base, Disp, Index and Length. |
| 573 | // Regs maps asm register numbers to LLVM register numbers and RegKind |
| 574 | // says what kind of address register we're using (ADDR32Reg or ADDR64Reg). |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 575 | bool SystemZAsmParser::parseAddress(unsigned &Base, const MCExpr *&Disp, |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 576 | unsigned &Index, bool &IsVector, |
| 577 | const MCExpr *&Length, const unsigned *Regs, |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 578 | RegisterKind RegKind) { |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 579 | // Parse the displacement, which must always be present. |
| 580 | if (getParser().parseExpression(Disp)) |
| 581 | return true; |
| 582 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 583 | // Parse the optional base and index. |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 584 | Index = 0; |
| 585 | Base = 0; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 586 | IsVector = false; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 587 | Length = nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 588 | if (getLexer().is(AsmToken::LParen)) { |
| 589 | Parser.Lex(); |
| 590 | |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 591 | if (getLexer().is(AsmToken::Percent)) { |
| 592 | // Parse the first register and decide whether it's a base or an index. |
| 593 | Register Reg; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 594 | if (parseRegister(Reg)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 595 | return true; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 596 | if (Reg.Group == RegV) { |
| 597 | // A vector index register. The base register is optional. |
| 598 | IsVector = true; |
| 599 | Index = SystemZMC::VR128Regs[Reg.Num]; |
| 600 | } else if (Reg.Group == RegGR) { |
| 601 | if (Reg.Num == 0) |
| 602 | return Error(Reg.StartLoc, "%r0 used in an address"); |
| 603 | // If the are two registers, the first one is the index and the |
| 604 | // second is the base. |
| 605 | if (getLexer().is(AsmToken::Comma)) |
| 606 | Index = Regs[Reg.Num]; |
| 607 | else |
| 608 | Base = Regs[Reg.Num]; |
| 609 | } else |
| 610 | return Error(Reg.StartLoc, "invalid address register"); |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 611 | } else { |
| 612 | // Parse the length. |
| 613 | if (getParser().parseExpression(Length)) |
| 614 | return true; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 615 | } |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 616 | |
| 617 | // Check whether there's a second register. It's the base if so. |
| 618 | if (getLexer().is(AsmToken::Comma)) { |
| 619 | Parser.Lex(); |
| 620 | Register Reg; |
| 621 | if (parseRegister(Reg, RegGR, Regs, RegKind)) |
| 622 | return true; |
| 623 | Base = Reg.Num; |
| 624 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 625 | |
| 626 | // Consume the closing bracket. |
| 627 | if (getLexer().isNot(AsmToken::RParen)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 628 | return Error(Parser.getTok().getLoc(), "unexpected token in address"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 629 | Parser.Lex(); |
| 630 | } |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 631 | return false; |
| 632 | } |
| 633 | |
| 634 | // Parse a memory operand and add it to Operands. The other arguments |
| 635 | // are as above. |
| 636 | SystemZAsmParser::OperandMatchResultTy |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 637 | SystemZAsmParser::parseAddress(OperandVector &Operands, MemoryKind MemKind, |
| 638 | const unsigned *Regs, RegisterKind RegKind) { |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 639 | SMLoc StartLoc = Parser.getTok().getLoc(); |
| 640 | unsigned Base, Index; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 641 | bool IsVector; |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 642 | const MCExpr *Disp; |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 643 | const MCExpr *Length; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 644 | if (parseAddress(Base, Disp, Index, IsVector, Length, Regs, RegKind)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 645 | return MatchOperand_ParseFail; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 646 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 647 | if (IsVector && MemKind != BDVMem) { |
| 648 | Error(StartLoc, "invalid use of vector addressing"); |
| 649 | return MatchOperand_ParseFail; |
| 650 | } |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 651 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 652 | if (!IsVector && MemKind == BDVMem) { |
| 653 | Error(StartLoc, "vector index required in address"); |
| 654 | return MatchOperand_ParseFail; |
| 655 | } |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 656 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 657 | if (Index && MemKind != BDXMem && MemKind != BDVMem) { |
| 658 | Error(StartLoc, "invalid use of indexed addressing"); |
| 659 | return MatchOperand_ParseFail; |
| 660 | } |
| 661 | |
| 662 | if (Length && MemKind != BDLMem) { |
| 663 | Error(StartLoc, "invalid use of length addressing"); |
| 664 | return MatchOperand_ParseFail; |
| 665 | } |
| 666 | |
| 667 | if (!Length && MemKind == BDLMem) { |
| 668 | Error(StartLoc, "missing length in address"); |
| 669 | return MatchOperand_ParseFail; |
| 670 | } |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 671 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 672 | SMLoc EndLoc = |
| 673 | SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Ulrich Weigand | 1f698b0 | 2015-05-04 17:40:53 +0000 | [diff] [blame] | 674 | Operands.push_back(SystemZOperand::createMem(MemKind, RegKind, Base, Disp, |
| 675 | Index, Length, StartLoc, |
| 676 | EndLoc)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 677 | return MatchOperand_Success; |
| 678 | } |
| 679 | |
| 680 | bool SystemZAsmParser::ParseDirective(AsmToken DirectiveID) { |
| 681 | return true; |
| 682 | } |
| 683 | |
| 684 | bool SystemZAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc, |
| 685 | SMLoc &EndLoc) { |
| 686 | Register Reg; |
| 687 | if (parseRegister(Reg)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 688 | return true; |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 689 | if (Reg.Group == RegGR) |
| 690 | RegNo = SystemZMC::GR64Regs[Reg.Num]; |
| 691 | else if (Reg.Group == RegFP) |
| 692 | RegNo = SystemZMC::FP64Regs[Reg.Num]; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 693 | else if (Reg.Group == RegV) |
| 694 | RegNo = SystemZMC::VR128Regs[Reg.Num]; |
Richard Sandiford | 675f869 | 2013-05-24 14:14:38 +0000 | [diff] [blame] | 695 | else |
| 696 | // FIXME: Access registers aren't modelled as LLVM registers yet. |
| 697 | return Error(Reg.StartLoc, "invalid operand for instruction"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 698 | StartLoc = Reg.StartLoc; |
| 699 | EndLoc = Reg.EndLoc; |
| 700 | return false; |
| 701 | } |
| 702 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 703 | bool SystemZAsmParser::ParseInstruction(ParseInstructionInfo &Info, |
| 704 | StringRef Name, SMLoc NameLoc, |
| 705 | OperandVector &Operands) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 706 | Operands.push_back(SystemZOperand::createToken(Name, NameLoc)); |
| 707 | |
| 708 | // Read the remaining operands. |
| 709 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 710 | // Read the first operand. |
| 711 | if (parseOperand(Operands, Name)) { |
| 712 | Parser.eatToEndOfStatement(); |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | // Read any subsequent operands. |
| 717 | while (getLexer().is(AsmToken::Comma)) { |
| 718 | Parser.Lex(); |
| 719 | if (parseOperand(Operands, Name)) { |
| 720 | Parser.eatToEndOfStatement(); |
| 721 | return true; |
| 722 | } |
| 723 | } |
| 724 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 725 | SMLoc Loc = getLexer().getLoc(); |
| 726 | Parser.eatToEndOfStatement(); |
| 727 | return Error(Loc, "unexpected token in argument list"); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | // Consume the EndOfStatement. |
| 732 | Parser.Lex(); |
| 733 | return false; |
| 734 | } |
| 735 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 736 | bool SystemZAsmParser::parseOperand(OperandVector &Operands, |
| 737 | StringRef Mnemonic) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 738 | // Check if the current operand has a custom associated parser, if so, try to |
| 739 | // custom parse the operand, or fallback to the general approach. |
| 740 | OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic); |
| 741 | if (ResTy == MatchOperand_Success) |
| 742 | return false; |
| 743 | |
| 744 | // If there wasn't a custom match, try the generic matcher below. Otherwise, |
| 745 | // there was a match, but an error occurred, in which case, just return that |
| 746 | // the operand parsing failed. |
| 747 | if (ResTy == MatchOperand_ParseFail) |
| 748 | return true; |
| 749 | |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 750 | // Check for a register. All real register operands should have used |
| 751 | // a context-dependent parse routine, which gives the required register |
| 752 | // class. The code is here to mop up other cases, like those where |
| 753 | // the instruction isn't recognized. |
| 754 | if (Parser.getTok().is(AsmToken::Percent)) { |
| 755 | Register Reg; |
| 756 | if (parseRegister(Reg)) |
| 757 | return true; |
| 758 | Operands.push_back(SystemZOperand::createInvalid(Reg.StartLoc, Reg.EndLoc)); |
| 759 | return false; |
| 760 | } |
| 761 | |
| 762 | // The only other type of operand is an immediate or address. As above, |
| 763 | // real address operands should have used a context-dependent parse routine, |
| 764 | // so we treat any plain expression as an immediate. |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 765 | SMLoc StartLoc = Parser.getTok().getLoc(); |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 766 | unsigned Base, Index; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 767 | bool IsVector; |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 768 | const MCExpr *Expr, *Length; |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 769 | if (parseAddress(Base, Expr, Index, IsVector, Length, SystemZMC::GR64Regs, |
| 770 | ADDR64Reg)) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 771 | return true; |
| 772 | |
| 773 | SMLoc EndLoc = |
| 774 | SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 775 | if (Base || Index || Length) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 776 | Operands.push_back(SystemZOperand::createInvalid(StartLoc, EndLoc)); |
| 777 | else |
| 778 | Operands.push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 779 | return false; |
| 780 | } |
| 781 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 782 | bool SystemZAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
| 783 | OperandVector &Operands, |
| 784 | MCStreamer &Out, |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 785 | uint64_t &ErrorInfo, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 786 | bool MatchingInlineAsm) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 787 | MCInst Inst; |
| 788 | unsigned MatchResult; |
| 789 | |
| 790 | MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo, |
Ranjeet Singh | 86ecbb7 | 2015-06-30 12:32:53 +0000 | [diff] [blame] | 791 | MatchingInlineAsm); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 792 | switch (MatchResult) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 793 | case Match_Success: |
| 794 | Inst.setLoc(IDLoc); |
Akira Hatanaka | bd9fc28 | 2015-11-14 05:20:05 +0000 | [diff] [blame] | 795 | Out.EmitInstruction(Inst, getSTI()); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 796 | return false; |
| 797 | |
| 798 | case Match_MissingFeature: { |
Ranjeet Singh | 86ecbb7 | 2015-06-30 12:32:53 +0000 | [diff] [blame] | 799 | assert(ErrorInfo && "Unknown missing feature!"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 800 | // Special case the error message for the very common case where only |
| 801 | // a single subtarget feature is missing |
| 802 | std::string Msg = "instruction requires:"; |
Ranjeet Singh | 86ecbb7 | 2015-06-30 12:32:53 +0000 | [diff] [blame] | 803 | uint64_t Mask = 1; |
| 804 | for (unsigned I = 0; I < sizeof(ErrorInfo) * 8 - 1; ++I) { |
| 805 | if (ErrorInfo & Mask) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 806 | Msg += " "; |
Ranjeet Singh | 86ecbb7 | 2015-06-30 12:32:53 +0000 | [diff] [blame] | 807 | Msg += getSubtargetFeatureName(ErrorInfo & Mask); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 808 | } |
Ranjeet Singh | 86ecbb7 | 2015-06-30 12:32:53 +0000 | [diff] [blame] | 809 | Mask <<= 1; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 810 | } |
| 811 | return Error(IDLoc, Msg); |
| 812 | } |
| 813 | |
| 814 | case Match_InvalidOperand: { |
| 815 | SMLoc ErrorLoc = IDLoc; |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 816 | if (ErrorInfo != ~0ULL) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 817 | if (ErrorInfo >= Operands.size()) |
| 818 | return Error(IDLoc, "too few operands for instruction"); |
| 819 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 820 | ErrorLoc = ((SystemZOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 821 | if (ErrorLoc == SMLoc()) |
| 822 | ErrorLoc = IDLoc; |
| 823 | } |
| 824 | return Error(ErrorLoc, "invalid operand for instruction"); |
| 825 | } |
| 826 | |
| 827 | case Match_MnemonicFail: |
| 828 | return Error(IDLoc, "invalid instruction"); |
| 829 | } |
| 830 | |
| 831 | llvm_unreachable("Unexpected match type"); |
| 832 | } |
| 833 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 834 | SystemZAsmParser::OperandMatchResultTy |
| 835 | SystemZAsmParser::parseAccessReg(OperandVector &Operands) { |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 836 | if (Parser.getTok().isNot(AsmToken::Percent)) |
| 837 | return MatchOperand_NoMatch; |
| 838 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 839 | Register Reg; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 840 | if (parseRegister(Reg, RegAccess, nullptr)) |
Richard Sandiford | dc5ed71 | 2013-05-24 14:26:46 +0000 | [diff] [blame] | 841 | return MatchOperand_ParseFail; |
| 842 | |
| 843 | Operands.push_back(SystemZOperand::createAccessReg(Reg.Num, |
| 844 | Reg.StartLoc, |
| 845 | Reg.EndLoc)); |
| 846 | return MatchOperand_Success; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 847 | } |
| 848 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 849 | SystemZAsmParser::OperandMatchResultTy |
| 850 | SystemZAsmParser::parsePCRel(OperandVector &Operands, int64_t MinVal, |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 851 | int64_t MaxVal, bool AllowTLS) { |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 852 | MCContext &Ctx = getContext(); |
| 853 | MCStreamer &Out = getStreamer(); |
| 854 | const MCExpr *Expr; |
| 855 | SMLoc StartLoc = Parser.getTok().getLoc(); |
| 856 | if (getParser().parseExpression(Expr)) |
| 857 | return MatchOperand_NoMatch; |
| 858 | |
| 859 | // For consistency with the GNU assembler, treat immediates as offsets |
| 860 | // from ".". |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 861 | if (auto *CE = dyn_cast<MCConstantExpr>(Expr)) { |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 862 | int64_t Value = CE->getValue(); |
| 863 | if ((Value & 1) || Value < MinVal || Value > MaxVal) { |
| 864 | Error(StartLoc, "offset out of range"); |
| 865 | return MatchOperand_ParseFail; |
| 866 | } |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 867 | MCSymbol *Sym = Ctx.createTempSymbol(); |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 868 | Out.EmitLabel(Sym); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 869 | const MCExpr *Base = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 870 | Ctx); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 871 | Expr = Value == 0 ? Base : MCBinaryExpr::createAdd(Base, Expr, Ctx); |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 874 | // Optionally match :tls_gdcall: or :tls_ldcall: followed by a TLS symbol. |
| 875 | const MCExpr *Sym = nullptr; |
| 876 | if (AllowTLS && getLexer().is(AsmToken::Colon)) { |
| 877 | Parser.Lex(); |
| 878 | |
| 879 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
| 880 | Error(Parser.getTok().getLoc(), "unexpected token"); |
| 881 | return MatchOperand_ParseFail; |
| 882 | } |
| 883 | |
| 884 | MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None; |
| 885 | StringRef Name = Parser.getTok().getString(); |
| 886 | if (Name == "tls_gdcall") |
| 887 | Kind = MCSymbolRefExpr::VK_TLSGD; |
| 888 | else if (Name == "tls_ldcall") |
| 889 | Kind = MCSymbolRefExpr::VK_TLSLDM; |
| 890 | else { |
| 891 | Error(Parser.getTok().getLoc(), "unknown TLS tag"); |
| 892 | return MatchOperand_ParseFail; |
| 893 | } |
| 894 | Parser.Lex(); |
| 895 | |
| 896 | if (Parser.getTok().isNot(AsmToken::Colon)) { |
| 897 | Error(Parser.getTok().getLoc(), "unexpected token"); |
| 898 | return MatchOperand_ParseFail; |
| 899 | } |
| 900 | Parser.Lex(); |
| 901 | |
| 902 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
| 903 | Error(Parser.getTok().getLoc(), "unexpected token"); |
| 904 | return MatchOperand_ParseFail; |
| 905 | } |
| 906 | |
| 907 | StringRef Identifier = Parser.getTok().getString(); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 908 | Sym = MCSymbolRefExpr::create(Ctx.getOrCreateSymbol(Identifier), |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 909 | Kind, Ctx); |
| 910 | Parser.Lex(); |
| 911 | } |
| 912 | |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 913 | SMLoc EndLoc = |
| 914 | SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Ulrich Weigand | 7bdd7c2 | 2015-02-18 09:11:36 +0000 | [diff] [blame] | 915 | |
| 916 | if (AllowTLS) |
| 917 | Operands.push_back(SystemZOperand::createImmTLS(Expr, Sym, |
| 918 | StartLoc, EndLoc)); |
| 919 | else |
| 920 | Operands.push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc)); |
| 921 | |
Richard Sandiford | 1fb5883 | 2013-05-14 09:47:26 +0000 | [diff] [blame] | 922 | return MatchOperand_Success; |
| 923 | } |
| 924 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 925 | // Force static initialization. |
| 926 | extern "C" void LLVMInitializeSystemZAsmParser() { |
| 927 | RegisterMCAsmParser<SystemZAsmParser> X(TheSystemZTarget); |
| 928 | } |