ARMAsmParser.cpp revision ca9c42c4daa8f4ffd9411e11c05fb53ee1bfaf70
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" 11#include "llvm/ADT/SmallVector.h" 12#include "llvm/ADT/Twine.h" 13#include "llvm/MC/MCAsmLexer.h" 14#include "llvm/MC/MCAsmParser.h" 15#include "llvm/MC/MCStreamer.h" 16#include "llvm/MC/MCExpr.h" 17#include "llvm/MC/MCInst.h" 18#include "llvm/Support/SourceMgr.h" 19#include "llvm/Target/TargetRegistry.h" 20#include "llvm/Target/TargetAsmParser.h" 21using namespace llvm; 22 23namespace { 24struct ARMOperand; 25 26class ARMAsmParser : public TargetAsmParser { 27 MCAsmParser &Parser; 28 29private: 30 MCAsmParser &getParser() const { return Parser; } 31 32 MCAsmLexer &getLexer() const { return Parser.getLexer(); } 33 34 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); } 35 36 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } 37 38 bool ParseDirectiveWord(unsigned Size, SMLoc L); 39 40public: 41 ARMAsmParser(const Target &T, MCAsmParser &_Parser) 42 : TargetAsmParser(T), Parser(_Parser) {} 43 44 virtual bool ParseInstruction(const StringRef &Name, MCInst &Inst); 45 46 virtual bool ParseDirective(AsmToken DirectiveID); 47}; 48 49} // end anonymous namespace 50 51bool ARMAsmParser::ParseInstruction(const StringRef &Name, MCInst &Inst) { 52 SMLoc Loc = getLexer().getTok().getLoc(); 53 Error(Loc, "ARMAsmParser::ParseInstruction currently unimplemented"); 54 return true; 55} 56 57bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { 58 StringRef IDVal = DirectiveID.getIdentifier(); 59 if (IDVal == ".word") 60 return ParseDirectiveWord(4, DirectiveID.getLoc()); 61 return true; 62} 63 64/// ParseDirectiveWord 65/// ::= .word [ expression (, expression)* ] 66bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) { 67 if (getLexer().isNot(AsmToken::EndOfStatement)) { 68 for (;;) { 69 const MCExpr *Value; 70 if (getParser().ParseExpression(Value)) 71 return true; 72 73 getParser().getStreamer().EmitValue(Value, Size); 74 75 if (getLexer().is(AsmToken::EndOfStatement)) 76 break; 77 78 // FIXME: Improve diagnostic. 79 if (getLexer().isNot(AsmToken::Comma)) 80 return Error(L, "unexpected token in directive"); 81 getLexer().Lex(); 82 } 83 } 84 85 getLexer().Lex(); 86 return false; 87} 88 89// Force static initialization. 90extern "C" void LLVMInitializeARMAsmParser() { 91 RegisterAsmParser<ARMAsmParser> X(TheARMTarget); 92 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget); 93} 94