LLVM API Documentation

MCAsmParserExtension.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
00011 #define LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
00012 
00013 #include "llvm/ADT/StringRef.h"
00014 #include "llvm/MC/MCParser/MCAsmParser.h"
00015 #include "llvm/Support/SMLoc.h"
00016 
00017 namespace llvm {
00018 class Twine;
00019 
00020 /// \brief Generic interface for extending the MCAsmParser,
00021 /// which is implemented by target and object file assembly parser
00022 /// implementations.
00023 class MCAsmParserExtension {
00024   MCAsmParserExtension(const MCAsmParserExtension &) LLVM_DELETED_FUNCTION;
00025   void operator=(const MCAsmParserExtension &) LLVM_DELETED_FUNCTION;
00026 
00027   MCAsmParser *Parser;
00028 
00029 protected:
00030   MCAsmParserExtension();
00031 
00032   // Helper template for implementing static dispatch functions.
00033   template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
00034   static bool HandleDirective(MCAsmParserExtension *Target,
00035                               StringRef Directive,
00036                               SMLoc DirectiveLoc) {
00037     T *Obj = static_cast<T*>(Target);
00038     return (Obj->*Handler)(Directive, DirectiveLoc);
00039   }
00040 
00041   bool BracketExpressionsSupported;
00042 
00043 public:
00044   virtual ~MCAsmParserExtension();
00045 
00046   /// \brief Initialize the extension for parsing using the given \p Parser.
00047   /// The extension should use the AsmParser interfaces to register its
00048   /// parsing routines.
00049   virtual void Initialize(MCAsmParser &Parser);
00050 
00051   /// @name MCAsmParser Proxy Interfaces
00052   /// @{
00053 
00054   MCContext &getContext() { return getParser().getContext(); }
00055   MCAsmLexer &getLexer() { return getParser().getLexer(); }
00056   MCAsmParser &getParser() { return *Parser; }
00057   SourceMgr &getSourceManager() { return getParser().getSourceManager(); }
00058   MCStreamer &getStreamer() { return getParser().getStreamer(); }
00059   bool Warning(SMLoc L, const Twine &Msg) {
00060     return getParser().Warning(L, Msg);
00061   }
00062   bool Error(SMLoc L, const Twine &Msg) {
00063     return getParser().Error(L, Msg);
00064   }
00065   bool TokError(const Twine &Msg) {
00066     return getParser().TokError(Msg);
00067   }
00068 
00069   const AsmToken &Lex() { return getParser().Lex(); }
00070 
00071   const AsmToken &getTok() { return getParser().getTok(); }
00072 
00073   bool HasBracketExpressions() const { return BracketExpressionsSupported; }
00074 
00075   /// @}
00076 };
00077 
00078 } // End llvm namespace
00079 
00080 #endif