Add MCAsmParser interface.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 20 Jul 2009 18:55:04 +0000 (18:55 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 20 Jul 2009 18:55:04 +0000 (18:55 +0000)
 - This provides the AsmParser interface to the target specific assembly
   parsers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76453 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmParser.h [new file with mode: 0644]
include/llvm/Target/TargetAsmParser.h
lib/MC/CMakeLists.txt
lib/MC/MCAsmParser.cpp [new file with mode: 0644]
lib/Target/X86/AsmParser/X86AsmParser.cpp
tools/llvm-mc/AsmParser.cpp
tools/llvm-mc/AsmParser.h
tools/llvm-mc/llvm-mc.cpp

diff --git a/include/llvm/MC/MCAsmParser.h b/include/llvm/MC/MCAsmParser.h
new file mode 100644 (file)
index 0000000..2379f21
--- /dev/null
@@ -0,0 +1,33 @@
+//===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCASMPARSER_H
+#define LLVM_MC_MCASMPARSER_H
+
+namespace llvm {
+class MCAsmParser;
+class MCInst;
+class Target;
+class TargetAsmParser;
+
+/// MCAsmParser - Generic assembler parser interface, for use by target specific
+/// assembly parsers.
+class MCAsmParser {
+  MCAsmParser(const MCAsmParser &);   // DO NOT IMPLEMENT
+  void operator=(const MCAsmParser &);  // DO NOT IMPLEMENT
+protected: // Can only create subclasses.
+  MCAsmParser();
+public:
+  virtual ~MCAsmParser();
+};
+
+} // End llvm namespace
+
+#endif
index bf96bf76ee837f68309a81dbc140d472c31c337e..c179991871e2046be23c453b5fddd45cb5bb3403 100644 (file)
@@ -11,6 +11,8 @@
 #define LLVM_TARGET_TARGETPARSER_H
 
 namespace llvm {
+class MCAsmParser;
+class MCInst;
 class Target;
 
 /// TargetAsmParser - Generic interface to target specific assembly parsers.
@@ -27,6 +29,21 @@ public:
   virtual ~TargetAsmParser();
 
   const Target &getTarget() const { return TheTarget; }
+
+  /// ParseInstruction - Parse one assembly instruction.
+  ///
+  /// The parser is positioned following the instruction name. The target
+  /// specific instruction parser should parse the entire instruction and
+  /// construct the appropriate MCInst, or emit an error. On success, the entire
+  /// line should be parsed up to and including the end-of-statement token. On
+  /// failure, the parser is not required to read to the end of the line.
+  //
+  /// \param AP - The current parser object.
+  /// \param Name - The instruction name.
+  /// \param Inst [out] - On success, the parsed instruction.
+  /// \return True on failure.
+  virtual bool ParseInstruction(MCAsmParser &AP, const char *Name, 
+                                MCInst &Inst) = 0;
 };
 
 } // End llvm namespace
index 4e16388fec67847bdb282f387906487f61564636..f0af7df959dfe6b210d091141e45543ce337d116 100644 (file)
@@ -1,4 +1,5 @@
 add_llvm_library(LLVMMC
+  MCAsmParser.cpp
   MCAsmStreamer.cpp
   MCContext.cpp
   MCStreamer.cpp
diff --git a/lib/MC/MCAsmParser.cpp b/lib/MC/MCAsmParser.cpp
new file mode 100644 (file)
index 0000000..2287e89
--- /dev/null
@@ -0,0 +1,18 @@
+//===-- MCAsmParser.cpp - Abstract Asm Parser Interface -------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/MC/MCAsmParser.h"
+
+using namespace llvm;
+
+MCAsmParser::MCAsmParser() {
+}
+
+MCAsmParser::~MCAsmParser() {
+}
index e548391e4ccf70b1b6914bf4a2ae010879fac6fa..b5f6ce608ddabae73608b5a7e434b143649f5241 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "X86.h"
+#include "llvm/MC/MCAsmParser.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetAsmParser.h"
 using namespace llvm;
@@ -17,6 +18,9 @@ namespace {
 class X86ATTAsmParser : public TargetAsmParser {
  public:
   explicit X86ATTAsmParser(const Target &);
+
+  virtual bool ParseInstruction(MCAsmParser &AP, const char *Name, 
+                                MCInst &Inst);
 };
 
 }
@@ -26,6 +30,11 @@ X86ATTAsmParser::X86ATTAsmParser(const Target &T)
 {
 }
 
+bool X86ATTAsmParser::ParseInstruction(MCAsmParser &AP, const char *Name, 
+                                       MCInst &Inst) {
+  return true;
+}
+
 namespace {
   TargetAsmParser *createAsmParser(const Target &T) {
     return new X86ATTAsmParser(T);
index 4629cfc34b9f3620dd0aa56abdc6b1c2035b96ba..066879ff48d0aeda586159b740aaf933d1c13c43 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetAsmParser.h"
 using namespace llvm;
 
 void AsmParser::Warning(SMLoc L, const char *Msg) {
@@ -548,7 +549,8 @@ bool AsmParser::ParseStatement() {
   }
 
   MCInst Inst;
-  if (ParseX86InstOperands(IDVal, Inst))
+  if (ParseX86InstOperands(IDVal, Inst) &&
+      getTargetParser().ParseInstruction(*this, IDVal, Inst))
     return true;
   
   if (Lexer.isNot(asmtok::EndOfStatement))
index 62aa4ef44c0345c1d25dbc8c507caf3f3c15911e..b99675850809c80eb79b06acd7686bf266b8d812 100644 (file)
@@ -15,6 +15,7 @@
 #define ASMPARSER_H
 
 #include "AsmLexer.h"
+#include "llvm/MC/MCAsmParser.h"
 #include "llvm/MC/MCStreamer.h"
 
 namespace llvm {
@@ -24,7 +25,7 @@ class MCInst;
 class MCStreamer;
 class MCValue;
 
-class AsmParser {
+class AsmParser : MCAsmParser {
 public:
   struct X86Operand;
 
@@ -32,14 +33,19 @@ private:
   AsmLexer Lexer;
   MCContext &Ctx;
   MCStreamer &Out;
+  TargetAsmParser &TargetParser;
   
 public:
-  AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
-    : Lexer(SM), Ctx(ctx), Out(OutStr) {}
+  AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, 
+            TargetAsmParser &_TargetParser)
+    : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
   ~AsmParser() {}
   
   bool Run();
   
+public:
+  TargetAsmParser &getTargetParser() const { return TargetParser; }
+
 private:
   bool ParseStatement();
 
index 6855a830e8afbafad5ed5aabb311c6efdce0edfc..ffc9b559f0756557d99750767044dc70f5b03f19 100644 (file)
@@ -186,9 +186,10 @@ static int AssembleInput(const char *ProgName) {
   OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs()));
 
   // FIXME: Target hook & command line option for initial section.
-  Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text,regular,pure_instructions"));
+  Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text,"
+                                          "regular,pure_instructions"));
 
-  AsmParser Parser(SrcMgr, Ctx, *Str.get());
+  AsmParser Parser(SrcMgr, Ctx, *Str.get(), *TAP);
   return Parser.Run();
 }