153131982d6290e3a865f400174778deaac452ff3Daniel Dunbar//===-- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks -------*- C++ -*-===//
253131982d6290e3a865f400174778deaac452ff3Daniel Dunbar//
353131982d6290e3a865f400174778deaac452ff3Daniel Dunbar//                     The LLVM Compiler Infrastructure
453131982d6290e3a865f400174778deaac452ff3Daniel Dunbar//
553131982d6290e3a865f400174778deaac452ff3Daniel Dunbar// This file is distributed under the University of Illinois Open Source
653131982d6290e3a865f400174778deaac452ff3Daniel Dunbar// License. See LICENSE.TXT for details.
753131982d6290e3a865f400174778deaac452ff3Daniel Dunbar//
853131982d6290e3a865f400174778deaac452ff3Daniel Dunbar//===----------------------------------------------------------------------===//
953131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
10674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
11674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
1253131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
131edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar#include "llvm/ADT/StringRef.h"
14255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/MC/MCParser/MCAsmParser.h"
1553131982d6290e3a865f400174778deaac452ff3Daniel Dunbar#include "llvm/Support/SMLoc.h"
1653131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
1753131982d6290e3a865f400174778deaac452ff3Daniel Dunbarnamespace llvm {
18f21e4e9326aa3ebc78bc2770722fb5150fe7ede9Daniel Dunbarclass Twine;
1953131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
2053131982d6290e3a865f400174778deaac452ff3Daniel Dunbar/// \brief Generic interface for extending the MCAsmParser,
2153131982d6290e3a865f400174778deaac452ff3Daniel Dunbar/// which is implemented by target and object file assembly parser
2253131982d6290e3a865f400174778deaac452ff3Daniel Dunbar/// implementations.
2353131982d6290e3a865f400174778deaac452ff3Daniel Dunbarclass MCAsmParserExtension {
241f7210e808373fa92be3a2d4fa653a6f79d5088bCraig Topper  MCAsmParserExtension(const MCAsmParserExtension &) LLVM_DELETED_FUNCTION;
251f7210e808373fa92be3a2d4fa653a6f79d5088bCraig Topper  void operator=(const MCAsmParserExtension &) LLVM_DELETED_FUNCTION;
2653131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
2753131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  MCAsmParser *Parser;
2853131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
2953131982d6290e3a865f400174778deaac452ff3Daniel Dunbarprotected:
3053131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  MCAsmParserExtension();
3153131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
321edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar  // Helper template for implementing static dispatch functions.
331edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar  template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
341edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar  static bool HandleDirective(MCAsmParserExtension *Target,
351edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar                              StringRef Directive,
361edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar                              SMLoc DirectiveLoc) {
371edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar    T *Obj = static_cast<T*>(Target);
381edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar    return (Obj->*Handler)(Directive, DirectiveLoc);
391edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar  }
401edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar
4193c65e6e661eda75711363bdd5ca15909920e1f0Joerg Sonnenberger  bool BracketExpressionsSupported;
4293c65e6e661eda75711363bdd5ca15909920e1f0Joerg Sonnenberger
4353131982d6290e3a865f400174778deaac452ff3Daniel Dunbarpublic:
4453131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  virtual ~MCAsmParserExtension();
4553131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
46c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// \brief Initialize the extension for parsing using the given \p Parser.
47c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// The extension should use the AsmParser interfaces to register its
4853131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  /// parsing routines.
4953131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  virtual void Initialize(MCAsmParser &Parser);
5053131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
5153131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  /// @name MCAsmParser Proxy Interfaces
5253131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  /// @{
5353131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
5453131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  MCContext &getContext() { return getParser().getContext(); }
5553131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  MCAsmLexer &getLexer() { return getParser().getLexer(); }
5653131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  MCAsmParser &getParser() { return *Parser; }
574e82bbb745160f19d76b9b5de5b93ebe224e1acfDaniel Dunbar  SourceMgr &getSourceManager() { return getParser().getSourceManager(); }
5853131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  MCStreamer &getStreamer() { return getParser().getStreamer(); }
59f8cd708f14a7a172d51899b68809510ae0c4c4c8Joerg Sonnenberger  bool Warning(SMLoc L, const Twine &Msg) {
6053131982d6290e3a865f400174778deaac452ff3Daniel Dunbar    return getParser().Warning(L, Msg);
6153131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  }
6253131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  bool Error(SMLoc L, const Twine &Msg) {
6353131982d6290e3a865f400174778deaac452ff3Daniel Dunbar    return getParser().Error(L, Msg);
6453131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  }
65f21e4e9326aa3ebc78bc2770722fb5150fe7ede9Daniel Dunbar  bool TokError(const Twine &Msg) {
66f21e4e9326aa3ebc78bc2770722fb5150fe7ede9Daniel Dunbar    return getParser().TokError(Msg);
67f21e4e9326aa3ebc78bc2770722fb5150fe7ede9Daniel Dunbar  }
6853131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
6953131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  const AsmToken &Lex() { return getParser().Lex(); }
7053131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
7153131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  const AsmToken &getTok() { return getParser().getTok(); }
7253131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
7393c65e6e661eda75711363bdd5ca15909920e1f0Joerg Sonnenberger  bool HasBracketExpressions() const { return BracketExpressionsSupported; }
7493c65e6e661eda75711363bdd5ca15909920e1f0Joerg Sonnenberger
7553131982d6290e3a865f400174778deaac452ff3Daniel Dunbar  /// @}
7653131982d6290e3a865f400174778deaac452ff3Daniel Dunbar};
7753131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
7853131982d6290e3a865f400174778deaac452ff3Daniel Dunbar} // End llvm namespace
7953131982d6290e3a865f400174778deaac452ff3Daniel Dunbar
8053131982d6290e3a865f400174778deaac452ff3Daniel Dunbar#endif
81