Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 1 | //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst 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 "ARM.h" |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 11 | #include "ARMSubtarget.h" |
Chris Lattner | c6ef277 | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 13 | #include "llvm/MC/MCParser/MCAsmParser.h" |
| 14 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCStreamer.h" |
| 16 | #include "llvm/MC/MCExpr.h" |
| 17 | #include "llvm/MC/MCInst.h" |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetRegistry.h" |
| 19 | #include "llvm/Target/TargetAsmParser.h" |
Chris Lattner | c6ef277 | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Compiler.h" |
| 21 | #include "llvm/Support/SourceMgr.h" |
Daniel Dunbar | fa315de | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/OwningPtr.h" |
Chris Lattner | c6ef277 | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | 345a9a6 | 2010-08-11 06:37:20 +0000 | [diff] [blame^] | 25 | #include "llvm/ADT/StringSwitch.h" |
Chris Lattner | c6ef277 | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Twine.h" |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
| 29 | namespace { |
| 30 | struct ARMOperand; |
| 31 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 32 | // The shift types for register controlled shifts in arm memory addressing |
| 33 | enum ShiftType { |
| 34 | Lsl, |
| 35 | Lsr, |
| 36 | Asr, |
| 37 | Ror, |
| 38 | Rrx |
| 39 | }; |
| 40 | |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 41 | class ARMAsmParser : public TargetAsmParser { |
| 42 | MCAsmParser &Parser; |
Daniel Dunbar | d73ada7 | 2010-07-19 00:33:49 +0000 | [diff] [blame] | 43 | TargetMachine &TM; |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | MCAsmParser &getParser() const { return Parser; } |
| 47 | |
| 48 | MCAsmLexer &getLexer() const { return Parser.getLexer(); } |
| 49 | |
| 50 | void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); } |
| 51 | |
| 52 | bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } |
| 53 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 54 | bool MaybeParseRegister(OwningPtr<ARMOperand> &Op, bool ParseWriteBack); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 55 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 56 | bool ParseRegisterList(OwningPtr<ARMOperand> &Op); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 57 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 58 | bool ParseMemory(OwningPtr<ARMOperand> &Op); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 59 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 60 | bool ParseMemoryOffsetReg(bool &Negative, |
| 61 | bool &OffsetRegShifted, |
| 62 | enum ShiftType &ShiftType, |
| 63 | const MCExpr *&ShiftAmount, |
| 64 | const MCExpr *&Offset, |
| 65 | bool &OffsetIsReg, |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 66 | int &OffsetRegNum, |
| 67 | SMLoc &E); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 68 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 69 | bool ParseShift(enum ShiftType &St, const MCExpr *&ShiftAmount, SMLoc &E); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 70 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 71 | bool ParseOperand(OwningPtr<ARMOperand> &Op); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 72 | |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 73 | bool ParseDirectiveWord(unsigned Size, SMLoc L); |
| 74 | |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 75 | bool ParseDirectiveThumb(SMLoc L); |
| 76 | |
| 77 | bool ParseDirectiveThumbFunc(SMLoc L); |
| 78 | |
| 79 | bool ParseDirectiveCode(SMLoc L); |
| 80 | |
| 81 | bool ParseDirectiveSyntax(SMLoc L); |
| 82 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 83 | /// @name Auto-generated Match Functions |
| 84 | /// { |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 85 | |
| 86 | unsigned ComputeAvailableFeatures(const ARMSubtarget *Subtarget) const; |
| 87 | |
Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 88 | bool MatchInstruction(const SmallVectorImpl<MCParsedAsmOperand*> &Operands, |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 89 | MCInst &Inst); |
| 90 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 91 | /// } |
| 92 | |
| 93 | |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 94 | public: |
Daniel Dunbar | d73ada7 | 2010-07-19 00:33:49 +0000 | [diff] [blame] | 95 | ARMAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &_TM) |
| 96 | : TargetAsmParser(T), Parser(_Parser), TM(_TM) {} |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 97 | |
Benjamin Kramer | 38e5989 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 98 | virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, |
Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 99 | SmallVectorImpl<MCParsedAsmOperand*> &Operands); |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 100 | |
| 101 | virtual bool ParseDirective(AsmToken DirectiveID); |
| 102 | }; |
| 103 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 104 | /// ARMOperand - Instances of this class represent a parsed ARM machine |
| 105 | /// instruction. |
Chris Lattner | 7659389 | 2010-01-14 21:21:40 +0000 | [diff] [blame] | 106 | struct ARMOperand : public MCParsedAsmOperand { |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 107 | private: |
| 108 | ARMOperand() {} |
| 109 | public: |
| 110 | enum KindTy { |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 111 | CondCode, |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 112 | Immediate, |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 113 | Memory, |
| 114 | Register, |
| 115 | Token |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 116 | } Kind; |
| 117 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 118 | SMLoc StartLoc, EndLoc; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 119 | |
| 120 | union { |
| 121 | struct { |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 122 | ARMCC::CondCodes Val; |
| 123 | } CC; |
| 124 | |
| 125 | struct { |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 126 | const char *Data; |
| 127 | unsigned Length; |
| 128 | } Tok; |
| 129 | |
| 130 | struct { |
| 131 | unsigned RegNum; |
Kevin Enderby | 99e6d4e | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 132 | bool Writeback; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 133 | } Reg; |
| 134 | |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 135 | struct { |
| 136 | const MCExpr *Val; |
| 137 | } Imm; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 138 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 139 | // This is for all forms of ARM address expressions |
| 140 | struct { |
| 141 | unsigned BaseRegNum; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 142 | unsigned OffsetRegNum; // used when OffsetIsReg is true |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 143 | const MCExpr *Offset; // used when OffsetIsReg is false |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 144 | const MCExpr *ShiftAmount; // used when OffsetRegShifted is true |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 145 | enum ShiftType ShiftType; // used when OffsetRegShifted is true |
| 146 | unsigned |
| 147 | OffsetRegShifted : 1, // only used when OffsetIsReg is true |
| 148 | Preindexed : 1, |
| 149 | Postindexed : 1, |
| 150 | OffsetIsReg : 1, |
| 151 | Negative : 1, // only used when OffsetIsReg is true |
| 152 | Writeback : 1; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 153 | } Mem; |
| 154 | |
| 155 | }; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 156 | |
| 157 | ARMOperand(KindTy K, SMLoc S, SMLoc E) |
| 158 | : Kind(K), StartLoc(S), EndLoc(E) {} |
| 159 | |
| 160 | ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() { |
| 161 | Kind = o.Kind; |
| 162 | StartLoc = o.StartLoc; |
| 163 | EndLoc = o.EndLoc; |
| 164 | switch (Kind) { |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 165 | case CondCode: |
| 166 | CC = o.CC; |
| 167 | break; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 168 | case Token: |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 169 | Tok = o.Tok; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 170 | break; |
| 171 | case Register: |
| 172 | Reg = o.Reg; |
| 173 | break; |
| 174 | case Immediate: |
| 175 | Imm = o.Imm; |
| 176 | break; |
| 177 | case Memory: |
| 178 | Mem = o.Mem; |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /// getStartLoc - Get the location of the first token of this operand. |
| 184 | SMLoc getStartLoc() const { return StartLoc; } |
| 185 | /// getEndLoc - Get the location of the last token of this operand. |
| 186 | SMLoc getEndLoc() const { return EndLoc; } |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 187 | |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 188 | ARMCC::CondCodes getCondCode() const { |
| 189 | assert(Kind == CondCode && "Invalid access!"); |
| 190 | return CC.Val; |
| 191 | } |
| 192 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 193 | StringRef getToken() const { |
| 194 | assert(Kind == Token && "Invalid access!"); |
| 195 | return StringRef(Tok.Data, Tok.Length); |
| 196 | } |
| 197 | |
| 198 | unsigned getReg() const { |
| 199 | assert(Kind == Register && "Invalid access!"); |
| 200 | return Reg.RegNum; |
| 201 | } |
| 202 | |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 203 | const MCExpr *getImm() const { |
| 204 | assert(Kind == Immediate && "Invalid access!"); |
| 205 | return Imm.Val; |
| 206 | } |
| 207 | |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 208 | bool isCondCode() const { return Kind == CondCode; } |
| 209 | |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 210 | bool isImm() const { return Kind == Immediate; } |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 211 | |
| 212 | bool isReg() const { return Kind == Register; } |
| 213 | |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 214 | bool isToken() const {return Kind == Token; } |
| 215 | |
| 216 | void addExpr(MCInst &Inst, const MCExpr *Expr) const { |
| 217 | // Add as immediates when possible. |
| 218 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) |
| 219 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 220 | else |
| 221 | Inst.addOperand(MCOperand::CreateExpr(Expr)); |
| 222 | } |
| 223 | |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 224 | void addCondCodeOperands(MCInst &Inst, unsigned N) const { |
Daniel Dunbar | 345a9a6 | 2010-08-11 06:37:20 +0000 | [diff] [blame^] | 225 | assert(N == 2 && "Invalid number of operands!"); |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 226 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
Daniel Dunbar | 345a9a6 | 2010-08-11 06:37:20 +0000 | [diff] [blame^] | 227 | // FIXME: What belongs here? |
| 228 | Inst.addOperand(MCOperand::CreateReg(0)); |
Daniel Dunbar | 8462b30 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 231 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 232 | assert(N == 1 && "Invalid number of operands!"); |
| 233 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 234 | } |
| 235 | |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 236 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 237 | assert(N == 1 && "Invalid number of operands!"); |
| 238 | addExpr(Inst, getImm()); |
| 239 | } |
| 240 | |
Daniel Dunbar | fa315de | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 241 | virtual void dump(raw_ostream &OS) const; |
Daniel Dunbar | b3cb696 | 2010-08-11 06:37:04 +0000 | [diff] [blame] | 242 | |
Daniel Dunbar | 345a9a6 | 2010-08-11 06:37:20 +0000 | [diff] [blame^] | 243 | static void CreateCondCode(OwningPtr<ARMOperand> &Op, ARMCC::CondCodes CC, |
| 244 | SMLoc S) { |
| 245 | Op.reset(new ARMOperand); |
| 246 | Op->Kind = CondCode; |
| 247 | Op->CC.Val = CC; |
| 248 | Op->StartLoc = S; |
| 249 | Op->EndLoc = S; |
| 250 | } |
| 251 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 252 | static void CreateToken(OwningPtr<ARMOperand> &Op, StringRef Str, |
| 253 | SMLoc S) { |
| 254 | Op.reset(new ARMOperand); |
| 255 | Op->Kind = Token; |
| 256 | Op->Tok.Data = Str.data(); |
| 257 | Op->Tok.Length = Str.size(); |
| 258 | Op->StartLoc = S; |
| 259 | Op->EndLoc = S; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 262 | static void CreateReg(OwningPtr<ARMOperand> &Op, unsigned RegNum, |
| 263 | bool Writeback, SMLoc S, SMLoc E) { |
| 264 | Op.reset(new ARMOperand); |
| 265 | Op->Kind = Register; |
| 266 | Op->Reg.RegNum = RegNum; |
| 267 | Op->Reg.Writeback = Writeback; |
| 268 | |
| 269 | Op->StartLoc = S; |
| 270 | Op->EndLoc = E; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 273 | static void CreateImm(OwningPtr<ARMOperand> &Op, const MCExpr *Val, |
| 274 | SMLoc S, SMLoc E) { |
| 275 | Op.reset(new ARMOperand); |
| 276 | Op->Kind = Immediate; |
| 277 | Op->Imm.Val = Val; |
| 278 | |
| 279 | Op->StartLoc = S; |
| 280 | Op->EndLoc = E; |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 283 | static void CreateMem(OwningPtr<ARMOperand> &Op, |
| 284 | unsigned BaseRegNum, bool OffsetIsReg, |
| 285 | const MCExpr *Offset, unsigned OffsetRegNum, |
| 286 | bool OffsetRegShifted, enum ShiftType ShiftType, |
| 287 | const MCExpr *ShiftAmount, bool Preindexed, |
| 288 | bool Postindexed, bool Negative, bool Writeback, |
| 289 | SMLoc S, SMLoc E) { |
| 290 | Op.reset(new ARMOperand); |
| 291 | Op->Kind = Memory; |
| 292 | Op->Mem.BaseRegNum = BaseRegNum; |
| 293 | Op->Mem.OffsetIsReg = OffsetIsReg; |
| 294 | Op->Mem.Offset = Offset; |
| 295 | Op->Mem.OffsetRegNum = OffsetRegNum; |
| 296 | Op->Mem.OffsetRegShifted = OffsetRegShifted; |
| 297 | Op->Mem.ShiftType = ShiftType; |
| 298 | Op->Mem.ShiftAmount = ShiftAmount; |
| 299 | Op->Mem.Preindexed = Preindexed; |
| 300 | Op->Mem.Postindexed = Postindexed; |
| 301 | Op->Mem.Negative = Negative; |
| 302 | Op->Mem.Writeback = Writeback; |
| 303 | |
| 304 | Op->StartLoc = S; |
| 305 | Op->EndLoc = E; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 306 | } |
| 307 | }; |
| 308 | |
| 309 | } // end anonymous namespace. |
| 310 | |
Daniel Dunbar | fa315de | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 311 | void ARMOperand::dump(raw_ostream &OS) const { |
| 312 | switch (Kind) { |
| 313 | case CondCode: |
| 314 | OS << ARMCondCodeToString(getCondCode()); |
| 315 | break; |
| 316 | case Immediate: |
| 317 | getImm()->print(OS); |
| 318 | break; |
| 319 | case Memory: |
| 320 | OS << "<memory>"; |
| 321 | break; |
| 322 | case Register: |
| 323 | OS << "<register " << getReg() << ">"; |
| 324 | break; |
| 325 | case Token: |
| 326 | OS << "'" << getToken() << "'"; |
| 327 | break; |
| 328 | } |
| 329 | } |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 330 | |
| 331 | /// @name Auto-generated Match Functions |
| 332 | /// { |
| 333 | |
| 334 | static unsigned MatchRegisterName(StringRef Name); |
| 335 | |
| 336 | /// } |
| 337 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 338 | /// Try to parse a register name. The token must be an Identifier when called, |
| 339 | /// and if it is a register name a Reg operand is created, the token is eaten |
| 340 | /// and false is returned. Else true is returned and no token is eaten. |
| 341 | /// TODO this is likely to change to allow different register types and or to |
| 342 | /// parse for a specific register type. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 343 | bool ARMAsmParser::MaybeParseRegister |
| 344 | (OwningPtr<ARMOperand> &Op, bool ParseWriteBack) { |
| 345 | SMLoc S, E; |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 346 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 347 | assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier"); |
| 348 | |
| 349 | // FIXME: Validate register for the current architecture; we have to do |
| 350 | // validation later, so maybe there is no need for this here. |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 351 | int RegNum; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 352 | |
| 353 | RegNum = MatchRegisterName(Tok.getString()); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 354 | if (RegNum == -1) |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 355 | return true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 356 | |
| 357 | S = Tok.getLoc(); |
| 358 | |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 359 | Parser.Lex(); // Eat identifier token. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 360 | |
| 361 | E = Parser.getTok().getLoc(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 362 | |
Kevin Enderby | 99e6d4e | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 363 | bool Writeback = false; |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 364 | if (ParseWriteBack) { |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 365 | const AsmToken &ExclaimTok = Parser.getTok(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 366 | if (ExclaimTok.is(AsmToken::Exclaim)) { |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 367 | E = ExclaimTok.getLoc(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 368 | Writeback = true; |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 369 | Parser.Lex(); // Eat exclaim token |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 370 | } |
Kevin Enderby | 99e6d4e | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 373 | ARMOperand::CreateReg(Op, RegNum, Writeback, S, E); |
Kevin Enderby | 99e6d4e | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 374 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 378 | /// Parse a register list, return false if successful else return true or an |
| 379 | /// error. The first token must be a '{' when called. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 380 | bool ARMAsmParser::ParseRegisterList(OwningPtr<ARMOperand> &Op) { |
| 381 | SMLoc S, E; |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 382 | assert(Parser.getTok().is(AsmToken::LCurly) && |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 383 | "Token is not an Left Curly Brace"); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 384 | S = Parser.getTok().getLoc(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 385 | Parser.Lex(); // Eat left curly brace token. |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 386 | |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 387 | const AsmToken &RegTok = Parser.getTok(); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 388 | SMLoc RegLoc = RegTok.getLoc(); |
| 389 | if (RegTok.isNot(AsmToken::Identifier)) |
| 390 | return Error(RegLoc, "register expected"); |
| 391 | int RegNum = MatchRegisterName(RegTok.getString()); |
| 392 | if (RegNum == -1) |
| 393 | return Error(RegLoc, "register expected"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 394 | Parser.Lex(); // Eat identifier token. |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 395 | unsigned RegList = 1 << RegNum; |
| 396 | |
| 397 | int HighRegNum = RegNum; |
| 398 | // TODO ranges like "{Rn-Rm}" |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 399 | while (Parser.getTok().is(AsmToken::Comma)) { |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 400 | Parser.Lex(); // Eat comma token. |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 401 | |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 402 | const AsmToken &RegTok = Parser.getTok(); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 403 | SMLoc RegLoc = RegTok.getLoc(); |
| 404 | if (RegTok.isNot(AsmToken::Identifier)) |
| 405 | return Error(RegLoc, "register expected"); |
| 406 | int RegNum = MatchRegisterName(RegTok.getString()); |
| 407 | if (RegNum == -1) |
| 408 | return Error(RegLoc, "register expected"); |
| 409 | |
| 410 | if (RegList & (1 << RegNum)) |
| 411 | Warning(RegLoc, "register duplicated in register list"); |
| 412 | else if (RegNum <= HighRegNum) |
| 413 | Warning(RegLoc, "register not in ascending order in register list"); |
| 414 | RegList |= 1 << RegNum; |
| 415 | HighRegNum = RegNum; |
| 416 | |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 417 | Parser.Lex(); // Eat identifier token. |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 418 | } |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 419 | const AsmToken &RCurlyTok = Parser.getTok(); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 420 | if (RCurlyTok.isNot(AsmToken::RCurly)) |
| 421 | return Error(RCurlyTok.getLoc(), "'}' expected"); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 422 | E = RCurlyTok.getLoc(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 423 | Parser.Lex(); // Eat left curly brace token. |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 424 | |
| 425 | return false; |
| 426 | } |
| 427 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 428 | /// Parse an arm memory expression, return false if successful else return true |
| 429 | /// or an error. The first token must be a '[' when called. |
| 430 | /// TODO Only preindexing and postindexing addressing are started, unindexed |
| 431 | /// with option, etc are still to do. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 432 | bool ARMAsmParser::ParseMemory(OwningPtr<ARMOperand> &Op) { |
| 433 | SMLoc S, E; |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 434 | assert(Parser.getTok().is(AsmToken::LBrac) && |
Kevin Enderby | 6bd266e | 2009-10-12 22:51:49 +0000 | [diff] [blame] | 435 | "Token is not an Left Bracket"); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 436 | S = Parser.getTok().getLoc(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 437 | Parser.Lex(); // Eat left bracket token. |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 438 | |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 439 | const AsmToken &BaseRegTok = Parser.getTok(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 440 | if (BaseRegTok.isNot(AsmToken::Identifier)) |
| 441 | return Error(BaseRegTok.getLoc(), "register expected"); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 442 | if (MaybeParseRegister(Op, false)) |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 443 | return Error(BaseRegTok.getLoc(), "register expected"); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 444 | int BaseRegNum = Op->getReg(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 445 | |
| 446 | bool Preindexed = false; |
| 447 | bool Postindexed = false; |
| 448 | bool OffsetIsReg = false; |
| 449 | bool Negative = false; |
| 450 | bool Writeback = false; |
| 451 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 452 | // First look for preindexed address forms, that is after the "[Rn" we now |
| 453 | // have to see if the next token is a comma. |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 454 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 455 | if (Tok.is(AsmToken::Comma)) { |
| 456 | Preindexed = true; |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 457 | Parser.Lex(); // Eat comma token. |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 458 | int OffsetRegNum; |
| 459 | bool OffsetRegShifted; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 460 | enum ShiftType ShiftType; |
| 461 | const MCExpr *ShiftAmount; |
| 462 | const MCExpr *Offset; |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 463 | if(ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount, |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 464 | Offset, OffsetIsReg, OffsetRegNum, E)) |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 465 | return true; |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 466 | const AsmToken &RBracTok = Parser.getTok(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 467 | if (RBracTok.isNot(AsmToken::RBrac)) |
| 468 | return Error(RBracTok.getLoc(), "']' expected"); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 469 | E = RBracTok.getLoc(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 470 | Parser.Lex(); // Eat right bracket token. |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 471 | |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 472 | const AsmToken &ExclaimTok = Parser.getTok(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 473 | if (ExclaimTok.is(AsmToken::Exclaim)) { |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 474 | E = ExclaimTok.getLoc(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 475 | Writeback = true; |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 476 | Parser.Lex(); // Eat exclaim token |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 477 | } |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 478 | ARMOperand::CreateMem(Op, BaseRegNum, OffsetIsReg, Offset, OffsetRegNum, |
| 479 | OffsetRegShifted, ShiftType, ShiftAmount, |
| 480 | Preindexed, Postindexed, Negative, Writeback, S, E); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | // The "[Rn" we have so far was not followed by a comma. |
| 484 | else if (Tok.is(AsmToken::RBrac)) { |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 485 | // This is a post indexing addressing forms, that is a ']' follows after |
| 486 | // the "[Rn". |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 487 | Postindexed = true; |
| 488 | Writeback = true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 489 | E = Tok.getLoc(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 490 | Parser.Lex(); // Eat right bracket token. |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 491 | |
Kevin Enderby | e2a98dd | 2009-10-15 21:42:45 +0000 | [diff] [blame] | 492 | int OffsetRegNum = 0; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 493 | bool OffsetRegShifted = false; |
| 494 | enum ShiftType ShiftType; |
| 495 | const MCExpr *ShiftAmount; |
| 496 | const MCExpr *Offset; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 497 | |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 498 | const AsmToken &NextTok = Parser.getTok(); |
Kevin Enderby | e2a98dd | 2009-10-15 21:42:45 +0000 | [diff] [blame] | 499 | if (NextTok.isNot(AsmToken::EndOfStatement)) { |
| 500 | if (NextTok.isNot(AsmToken::Comma)) |
Duncan Sands | 3472766 | 2010-07-12 08:16:59 +0000 | [diff] [blame] | 501 | return Error(NextTok.getLoc(), "',' expected"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 502 | Parser.Lex(); // Eat comma token. |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 503 | if(ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 504 | ShiftAmount, Offset, OffsetIsReg, OffsetRegNum, |
| 505 | E)) |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 506 | return true; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 507 | } |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 508 | |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 509 | ARMOperand::CreateMem(Op, BaseRegNum, OffsetIsReg, Offset, OffsetRegNum, |
| 510 | OffsetRegShifted, ShiftType, ShiftAmount, |
| 511 | Preindexed, Postindexed, Negative, Writeback, S, E); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 512 | return false; |
| 513 | } |
| 514 | |
| 515 | return true; |
| 516 | } |
| 517 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 518 | /// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn]," |
| 519 | /// we will parse the following (were +/- means that a plus or minus is |
| 520 | /// optional): |
| 521 | /// +/-Rm |
| 522 | /// +/-Rm, shift |
| 523 | /// #offset |
| 524 | /// we return false on success or an error otherwise. |
| 525 | bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative, |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 526 | bool &OffsetRegShifted, |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 527 | enum ShiftType &ShiftType, |
| 528 | const MCExpr *&ShiftAmount, |
| 529 | const MCExpr *&Offset, |
| 530 | bool &OffsetIsReg, |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 531 | int &OffsetRegNum, |
| 532 | SMLoc &E) { |
| 533 | OwningPtr<ARMOperand> Op; |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 534 | Negative = false; |
| 535 | OffsetRegShifted = false; |
| 536 | OffsetIsReg = false; |
| 537 | OffsetRegNum = -1; |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 538 | const AsmToken &NextTok = Parser.getTok(); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 539 | E = NextTok.getLoc(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 540 | if (NextTok.is(AsmToken::Plus)) |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 541 | Parser.Lex(); // Eat plus token. |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 542 | else if (NextTok.is(AsmToken::Minus)) { |
| 543 | Negative = true; |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 544 | Parser.Lex(); // Eat minus token |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 545 | } |
| 546 | // See if there is a register following the "[Rn," or "[Rn]," we have so far. |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 547 | const AsmToken &OffsetRegTok = Parser.getTok(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 548 | if (OffsetRegTok.is(AsmToken::Identifier)) { |
| 549 | OffsetIsReg = !MaybeParseRegister(Op, false); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 550 | if (OffsetIsReg) { |
| 551 | E = Op->getEndLoc(); |
| 552 | OffsetRegNum = Op->getReg(); |
| 553 | } |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 554 | } |
| 555 | // If we parsed a register as the offset then their can be a shift after that |
| 556 | if (OffsetRegNum != -1) { |
| 557 | // Look for a comma then a shift |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 558 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 559 | if (Tok.is(AsmToken::Comma)) { |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 560 | Parser.Lex(); // Eat comma token. |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 561 | |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 562 | const AsmToken &Tok = Parser.getTok(); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 563 | if (ParseShift(ShiftType, ShiftAmount, E)) |
Duncan Sands | 3472766 | 2010-07-12 08:16:59 +0000 | [diff] [blame] | 564 | return Error(Tok.getLoc(), "shift expected"); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 565 | OffsetRegShifted = true; |
| 566 | } |
| 567 | } |
| 568 | else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm" |
| 569 | // Look for #offset following the "[Rn," or "[Rn]," |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 570 | const AsmToken &HashTok = Parser.getTok(); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 571 | if (HashTok.isNot(AsmToken::Hash)) |
| 572 | return Error(HashTok.getLoc(), "'#' expected"); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 573 | |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 574 | Parser.Lex(); // Eat hash token. |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 575 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 576 | if (getParser().ParseExpression(Offset)) |
| 577 | return true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 578 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 579 | } |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 580 | return false; |
| 581 | } |
| 582 | |
| 583 | /// ParseShift as one of these two: |
| 584 | /// ( lsl | lsr | asr | ror ) , # shift_amount |
| 585 | /// rrx |
| 586 | /// and returns true if it parses a shift otherwise it returns false. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 587 | bool ARMAsmParser::ParseShift(ShiftType &St, |
| 588 | const MCExpr *&ShiftAmount, |
| 589 | SMLoc &E) { |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 590 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 591 | if (Tok.isNot(AsmToken::Identifier)) |
| 592 | return true; |
Benjamin Kramer | 38e5989 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 593 | StringRef ShiftName = Tok.getString(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 594 | if (ShiftName == "lsl" || ShiftName == "LSL") |
| 595 | St = Lsl; |
| 596 | else if (ShiftName == "lsr" || ShiftName == "LSR") |
| 597 | St = Lsr; |
| 598 | else if (ShiftName == "asr" || ShiftName == "ASR") |
| 599 | St = Asr; |
| 600 | else if (ShiftName == "ror" || ShiftName == "ROR") |
| 601 | St = Ror; |
| 602 | else if (ShiftName == "rrx" || ShiftName == "RRX") |
| 603 | St = Rrx; |
| 604 | else |
| 605 | return true; |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 606 | Parser.Lex(); // Eat shift type token. |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 607 | |
| 608 | // Rrx stands alone. |
| 609 | if (St == Rrx) |
| 610 | return false; |
| 611 | |
| 612 | // Otherwise, there must be a '#' and a shift amount. |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 613 | const AsmToken &HashTok = Parser.getTok(); |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 614 | if (HashTok.isNot(AsmToken::Hash)) |
| 615 | return Error(HashTok.getLoc(), "'#' expected"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 616 | Parser.Lex(); // Eat hash token. |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 617 | |
| 618 | if (getParser().ParseExpression(ShiftAmount)) |
| 619 | return true; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 620 | |
| 621 | return false; |
| 622 | } |
| 623 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 624 | /// Parse a arm instruction operand. For now this parses the operand regardless |
| 625 | /// of the mnemonic. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 626 | bool ARMAsmParser::ParseOperand(OwningPtr<ARMOperand> &Op) { |
| 627 | SMLoc S, E; |
| 628 | |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 629 | switch (getLexer().getKind()) { |
| 630 | case AsmToken::Identifier: |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 631 | if (!MaybeParseRegister(Op, true)) |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 632 | return false; |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 633 | // This was not a register so parse other operands that start with an |
| 634 | // identifier (like labels) as expressions and create them as immediates. |
| 635 | const MCExpr *IdVal; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 636 | S = Parser.getTok().getLoc(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 637 | if (getParser().ParseExpression(IdVal)) |
| 638 | return true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 639 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 640 | ARMOperand::CreateImm(Op, IdVal, S, E); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 641 | return false; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 642 | case AsmToken::LBrac: |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 643 | return ParseMemory(Op); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 644 | case AsmToken::LCurly: |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 645 | return ParseRegisterList(Op); |
Kevin Enderby | d7894f1 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 646 | case AsmToken::Hash: |
Kevin Enderby | 079469f | 2009-10-13 23:33:38 +0000 | [diff] [blame] | 647 | // #42 -> immediate. |
| 648 | // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 649 | S = Parser.getTok().getLoc(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 650 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 651 | const MCExpr *ImmVal; |
| 652 | if (getParser().ParseExpression(ImmVal)) |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 653 | return true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 654 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 655 | ARMOperand::CreateImm(Op, ImmVal, S, E); |
Kevin Enderby | cfe0724 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 656 | return false; |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 657 | default: |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 658 | return Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 662 | /// Parse an arm instruction mnemonic followed by its operands. |
Benjamin Kramer | 38e5989 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 663 | bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc, |
Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 664 | SmallVectorImpl<MCParsedAsmOperand*> &Operands) { |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 665 | OwningPtr<ARMOperand> Op; |
Daniel Dunbar | 5747b13 | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 666 | |
| 667 | // Create the leading tokens for the mnemonic, split by '.' characters. |
| 668 | size_t Start = 0, Next = Name.find('.'); |
| 669 | StringRef Head = Name.slice(Start, Next); |
| 670 | |
Daniel Dunbar | 345a9a6 | 2010-08-11 06:37:20 +0000 | [diff] [blame^] | 671 | // Determine the predicate, if any. |
| 672 | // |
| 673 | // FIXME: We need a way to check whether a prefix supports predication, |
| 674 | // otherwise we will end up with an ambiguity for instructions that happen to |
| 675 | // end with a predicate name. |
| 676 | unsigned CC = StringSwitch<unsigned>(Head.substr(Head.size()-2)) |
| 677 | .Case("eq", ARMCC::EQ) |
| 678 | .Case("ne", ARMCC::NE) |
| 679 | .Case("hs", ARMCC::HS) |
| 680 | .Case("lo", ARMCC::LO) |
| 681 | .Case("mi", ARMCC::MI) |
| 682 | .Case("pl", ARMCC::PL) |
| 683 | .Case("vs", ARMCC::VS) |
| 684 | .Case("vc", ARMCC::VC) |
| 685 | .Case("hi", ARMCC::HI) |
| 686 | .Case("ls", ARMCC::LS) |
| 687 | .Case("ge", ARMCC::GE) |
| 688 | .Case("lt", ARMCC::LT) |
| 689 | .Case("gt", ARMCC::GT) |
| 690 | .Case("le", ARMCC::LE) |
| 691 | .Case("al", ARMCC::AL) |
| 692 | .Default(~0U); |
| 693 | if (CC != ~0U) { |
| 694 | Head = Head.slice(0, Head.size() - 2); |
| 695 | } else |
| 696 | CC = ARMCC::AL; |
| 697 | |
Daniel Dunbar | 5747b13 | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 698 | ARMOperand::CreateToken(Op, Head, NameLoc); |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 699 | Operands.push_back(Op.take()); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 700 | |
Daniel Dunbar | 345a9a6 | 2010-08-11 06:37:20 +0000 | [diff] [blame^] | 701 | ARMOperand::CreateCondCode(Op, ARMCC::CondCodes(CC), NameLoc); |
| 702 | Operands.push_back(Op.take()); |
| 703 | |
| 704 | // Add the remaining tokens in the mnemonic. |
Daniel Dunbar | 5747b13 | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 705 | while (Next != StringRef::npos) { |
| 706 | Start = Next; |
| 707 | Next = Name.find('.', Start + 1); |
| 708 | Head = Name.slice(Start, Next); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 709 | |
Daniel Dunbar | 5747b13 | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 710 | ARMOperand::CreateToken(Op, Head, NameLoc); |
| 711 | Operands.push_back(Op.take()); |
| 712 | } |
| 713 | |
| 714 | // Read the remaining operands. |
| 715 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 716 | // Read the first operand. |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 717 | OwningPtr<ARMOperand> Op; |
Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 718 | if (ParseOperand(Op)) return true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 719 | Operands.push_back(Op.take()); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 720 | |
| 721 | while (getLexer().is(AsmToken::Comma)) { |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 722 | Parser.Lex(); // Eat the comma. |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 723 | |
| 724 | // Parse and remember the operand. |
Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 725 | if (ParseOperand(Op)) return true; |
Sean Callanan | 7626476 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 726 | Operands.push_back(Op.take()); |
Kevin Enderby | a7ba3a8 | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 729 | return false; |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 732 | /// ParseDirective parses the arm specific directives |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 733 | bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { |
| 734 | StringRef IDVal = DirectiveID.getIdentifier(); |
| 735 | if (IDVal == ".word") |
| 736 | return ParseDirectiveWord(4, DirectiveID.getLoc()); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 737 | else if (IDVal == ".thumb") |
| 738 | return ParseDirectiveThumb(DirectiveID.getLoc()); |
| 739 | else if (IDVal == ".thumb_func") |
| 740 | return ParseDirectiveThumbFunc(DirectiveID.getLoc()); |
| 741 | else if (IDVal == ".code") |
| 742 | return ParseDirectiveCode(DirectiveID.getLoc()); |
| 743 | else if (IDVal == ".syntax") |
| 744 | return ParseDirectiveSyntax(DirectiveID.getLoc()); |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 745 | return true; |
| 746 | } |
| 747 | |
| 748 | /// ParseDirectiveWord |
| 749 | /// ::= .word [ expression (, expression)* ] |
| 750 | bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) { |
| 751 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 752 | for (;;) { |
| 753 | const MCExpr *Value; |
| 754 | if (getParser().ParseExpression(Value)) |
| 755 | return true; |
| 756 | |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 757 | getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/); |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 758 | |
| 759 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 760 | break; |
| 761 | |
| 762 | // FIXME: Improve diagnostic. |
| 763 | if (getLexer().isNot(AsmToken::Comma)) |
| 764 | return Error(L, "unexpected token in directive"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 765 | Parser.Lex(); |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 769 | Parser.Lex(); |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 770 | return false; |
| 771 | } |
| 772 | |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 773 | /// ParseDirectiveThumb |
| 774 | /// ::= .thumb |
| 775 | bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) { |
| 776 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 777 | return Error(L, "unexpected token in directive"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 778 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 779 | |
| 780 | // TODO: set thumb mode |
| 781 | // TODO: tell the MC streamer the mode |
| 782 | // getParser().getStreamer().Emit???(); |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | /// ParseDirectiveThumbFunc |
| 787 | /// ::= .thumbfunc symbol_name |
| 788 | bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) { |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 789 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 790 | if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) |
| 791 | return Error(L, "unexpected token in .syntax directive"); |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 792 | StringRef ATTRIBUTE_UNUSED SymbolName = Parser.getTok().getIdentifier(); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 793 | Parser.Lex(); // Consume the identifier token. |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 794 | |
| 795 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 796 | return Error(L, "unexpected token in directive"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 797 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 798 | |
| 799 | // TODO: mark symbol as a thumb symbol |
| 800 | // getParser().getStreamer().Emit???(); |
| 801 | return false; |
| 802 | } |
| 803 | |
| 804 | /// ParseDirectiveSyntax |
| 805 | /// ::= .syntax unified | divided |
| 806 | bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) { |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 807 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 808 | if (Tok.isNot(AsmToken::Identifier)) |
| 809 | return Error(L, "unexpected token in .syntax directive"); |
Benjamin Kramer | 38e5989 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 810 | StringRef Mode = Tok.getString(); |
Duncan Sands | 58c8691 | 2010-06-29 13:04:35 +0000 | [diff] [blame] | 811 | if (Mode == "unified" || Mode == "UNIFIED") |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 812 | Parser.Lex(); |
Duncan Sands | 58c8691 | 2010-06-29 13:04:35 +0000 | [diff] [blame] | 813 | else if (Mode == "divided" || Mode == "DIVIDED") |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 814 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 815 | else |
| 816 | return Error(L, "unrecognized syntax mode in .syntax directive"); |
| 817 | |
| 818 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 819 | return Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 820 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 821 | |
| 822 | // TODO tell the MC streamer the mode |
| 823 | // getParser().getStreamer().Emit???(); |
| 824 | return false; |
| 825 | } |
| 826 | |
| 827 | /// ParseDirectiveCode |
| 828 | /// ::= .code 16 | 32 |
| 829 | bool ARMAsmParser::ParseDirectiveCode(SMLoc L) { |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 830 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 831 | if (Tok.isNot(AsmToken::Integer)) |
| 832 | return Error(L, "unexpected token in .code directive"); |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 833 | int64_t Val = Parser.getTok().getIntVal(); |
Duncan Sands | 58c8691 | 2010-06-29 13:04:35 +0000 | [diff] [blame] | 834 | if (Val == 16) |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 835 | Parser.Lex(); |
Duncan Sands | 58c8691 | 2010-06-29 13:04:35 +0000 | [diff] [blame] | 836 | else if (Val == 32) |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 837 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 838 | else |
| 839 | return Error(L, "invalid operand to .code directive"); |
| 840 | |
| 841 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 842 | return Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
Sean Callanan | b9a25b7 | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 843 | Parser.Lex(); |
Kevin Enderby | 515d509 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 844 | |
| 845 | // TODO tell the MC streamer the mode |
| 846 | // getParser().getStreamer().Emit???(); |
| 847 | return false; |
| 848 | } |
| 849 | |
Sean Callanan | 90b7097 | 2010-04-07 20:29:34 +0000 | [diff] [blame] | 850 | extern "C" void LLVMInitializeARMAsmLexer(); |
| 851 | |
Kevin Enderby | 9c41fa8 | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 852 | /// Force static initialization. |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 853 | extern "C" void LLVMInitializeARMAsmParser() { |
| 854 | RegisterAsmParser<ARMAsmParser> X(TheARMTarget); |
| 855 | RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget); |
Sean Callanan | 90b7097 | 2010-04-07 20:29:34 +0000 | [diff] [blame] | 856 | LLVMInitializeARMAsmLexer(); |
Kevin Enderby | ca9c42c | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 857 | } |
Daniel Dunbar | 3483aca | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 858 | |
| 859 | #include "ARMGenAsmMatcher.inc" |