• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks -------*- 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_MCASMPARSEREXTENSION_H
11 #define LLVM_MC_MCASMPARSEREXTENSION_H
12 
13 #include "llvm/MC/MCParser/MCAsmParser.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/SMLoc.h"
16 
17 namespace llvm {
18 class Twine;
19 
20 /// \brief Generic interface for extending the MCAsmParser,
21 /// which is implemented by target and object file assembly parser
22 /// implementations.
23 class MCAsmParserExtension {
24   MCAsmParserExtension(const MCAsmParserExtension &);   // DO NOT IMPLEMENT
25   void operator=(const MCAsmParserExtension &);  // DO NOT IMPLEMENT
26 
27   MCAsmParser *Parser;
28 
29 protected:
30   MCAsmParserExtension();
31 
32   // Helper template for implementing static dispatch functions.
33   template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
HandleDirective(MCAsmParserExtension * Target,StringRef Directive,SMLoc DirectiveLoc)34   static bool HandleDirective(MCAsmParserExtension *Target,
35                               StringRef Directive,
36                               SMLoc DirectiveLoc) {
37     T *Obj = static_cast<T*>(Target);
38     return (Obj->*Handler)(Directive, DirectiveLoc);
39   }
40 
41   bool BracketExpressionsSupported;
42 
43 public:
44   virtual ~MCAsmParserExtension();
45 
46   /// \brief Initialize the extension for parsing using the given \arg
47   /// Parser. The extension should use the AsmParser interfaces to register its
48   /// parsing routines.
49   virtual void Initialize(MCAsmParser &Parser);
50 
51   /// @name MCAsmParser Proxy Interfaces
52   /// @{
53 
getContext()54   MCContext &getContext() { return getParser().getContext(); }
getLexer()55   MCAsmLexer &getLexer() { return getParser().getLexer(); }
getParser()56   MCAsmParser &getParser() { return *Parser; }
getSourceManager()57   SourceMgr &getSourceManager() { return getParser().getSourceManager(); }
getStreamer()58   MCStreamer &getStreamer() { return getParser().getStreamer(); }
Warning(SMLoc L,const Twine & Msg)59   bool Warning(SMLoc L, const Twine &Msg) {
60     return getParser().Warning(L, Msg);
61   }
Error(SMLoc L,const Twine & Msg)62   bool Error(SMLoc L, const Twine &Msg) {
63     return getParser().Error(L, Msg);
64   }
TokError(const Twine & Msg)65   bool TokError(const Twine &Msg) {
66     return getParser().TokError(Msg);
67   }
68 
Lex()69   const AsmToken &Lex() { return getParser().Lex(); }
70 
getTok()71   const AsmToken &getTok() { return getParser().getTok(); }
72 
HasBracketExpressions()73   bool HasBracketExpressions() const { return BracketExpressionsSupported; }
74 
75   /// @}
76 };
77 
78 } // End llvm namespace
79 
80 #endif
81