1 //===-- llvm/MC/MCTargetAsmLexer.h - Target Assembly Lexer ------*- C++ -*-===// 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 #ifndef LLVM_MC_MCTARGETASMLEXER_H 11 #define LLVM_MC_MCTARGETASMLEXER_H 12 13 #include "llvm/MC/MCParser/MCAsmLexer.h" 14 15 namespace llvm { 16 class Target; 17 18 /// MCTargetAsmLexer - Generic interface to target specific assembly lexers. 19 class MCTargetAsmLexer { 20 /// The current token 21 AsmToken CurTok; 22 23 /// The location and description of the current error 24 SMLoc ErrLoc; 25 std::string Err; 26 27 MCTargetAsmLexer(const MCTargetAsmLexer &); // DO NOT IMPLEMENT 28 void operator=(const MCTargetAsmLexer &); // DO NOT IMPLEMENT 29 protected: // Can only create subclasses. 30 MCTargetAsmLexer(const Target &); 31 32 virtual AsmToken LexToken() = 0; 33 34 void SetError(const SMLoc &errLoc, const std::string &err) { 35 ErrLoc = errLoc; 36 Err = err; 37 } 38 39 /// TheTarget - The Target that this machine was created for. 40 const Target &TheTarget; 41 MCAsmLexer *Lexer; 42 43 public: 44 virtual ~MCTargetAsmLexer(); 45 46 const Target &getTarget() const { return TheTarget; } 47 48 /// InstallLexer - Set the lexer to get tokens from lower-level lexer \arg L. 49 void InstallLexer(MCAsmLexer &L) { 50 Lexer = &L; 51 } 52 53 MCAsmLexer *getLexer() { 54 return Lexer; 55 } 56 57 /// Lex - Consume the next token from the input stream and return it. 58 const AsmToken &Lex() { 59 return CurTok = LexToken(); 60 } 61 62 /// getTok - Get the current (last) lexed token. 63 const AsmToken &getTok() { 64 return CurTok; 65 } 66 67 /// getErrLoc - Get the current error location 68 const SMLoc &getErrLoc() { 69 return ErrLoc; 70 } 71 72 /// getErr - Get the current error string 73 const std::string &getErr() { 74 return Err; 75 } 76 77 /// getKind - Get the kind of current token. 78 AsmToken::TokenKind getKind() const { return CurTok.getKind(); } 79 80 /// is - Check if the current token has kind \arg K. 81 bool is(AsmToken::TokenKind K) const { return CurTok.is(K); } 82 83 /// isNot - Check if the current token has kind \arg K. 84 bool isNot(AsmToken::TokenKind K) const { return CurTok.isNot(K); } 85 }; 86 87 } // End llvm namespace 88 89 #endif 90