1 //===-- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
11 #define LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/Support/SMLoc.h"
20 /// \brief Generic interface for extending the MCAsmParser,
21 /// which is implemented by target and object file assembly parser
23 class MCAsmParserExtension {
24 MCAsmParserExtension(const MCAsmParserExtension &) = delete;
25 void operator=(const MCAsmParserExtension &) = delete;
30 MCAsmParserExtension();
32 // Helper template for implementing static dispatch functions.
33 template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
34 static bool HandleDirective(MCAsmParserExtension *Target,
37 T *Obj = static_cast<T*>(Target);
38 return (Obj->*Handler)(Directive, DirectiveLoc);
41 bool BracketExpressionsSupported;
44 virtual ~MCAsmParserExtension();
46 /// \brief Initialize the extension for parsing using the given \p Parser.
47 /// The extension should use the AsmParser interfaces to register its
49 virtual void Initialize(MCAsmParser &Parser);
51 /// \name MCAsmParser Proxy Interfaces
54 MCContext &getContext() { return getParser().getContext(); }
56 MCAsmLexer &getLexer() { return getParser().getLexer(); }
57 const MCAsmLexer &getLexer() const {
58 return const_cast<MCAsmParserExtension *>(this)->getLexer();
61 MCAsmParser &getParser() { return *Parser; }
62 const MCAsmParser &getParser() const {
63 return const_cast<MCAsmParserExtension*>(this)->getParser();
66 SourceMgr &getSourceManager() { return getParser().getSourceManager(); }
67 MCStreamer &getStreamer() { return getParser().getStreamer(); }
68 bool Warning(SMLoc L, const Twine &Msg) {
69 return getParser().Warning(L, Msg);
71 bool Error(SMLoc L, const Twine &Msg) {
72 return getParser().Error(L, Msg);
74 void Note(SMLoc L, const Twine &Msg) {
75 getParser().Note(L, Msg);
77 bool TokError(const Twine &Msg) {
78 return getParser().TokError(Msg);
81 const AsmToken &Lex() { return getParser().Lex(); }
83 const AsmToken &getTok() { return getParser().getTok(); }
85 bool HasBracketExpressions() const { return BracketExpressionsSupported; }
90 } // End llvm namespace