Add MCAsmLexer interface.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 20 Jul 2009 20:01:54 +0000 (20:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 20 Jul 2009 20:01:54 +0000 (20:01 +0000)
 - This provides the AsmLexer interface to the target specific assembly parsers.

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

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

diff --git a/include/llvm/MC/MCAsmLexer.h b/include/llvm/MC/MCAsmLexer.h
new file mode 100644 (file)
index 0000000..80628c3
--- /dev/null
@@ -0,0 +1,32 @@
+//===-- llvm/MC/MCAsmLexer.h - Abstract Asm Lexer 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_MCASMLEXER_H
+#define LLVM_MC_MCASMLEXER_H
+
+namespace llvm {
+class MCAsmLexer;
+class MCInst;
+class Target;
+
+/// MCAsmLexer - Generic assembler lexer interface, for use by target specific
+/// assembly lexers.
+class MCAsmLexer {
+  MCAsmLexer(const MCAsmLexer &);   // DO NOT IMPLEMENT
+  void operator=(const MCAsmLexer &);  // DO NOT IMPLEMENT
+protected: // Can only create subclasses.
+  MCAsmLexer();
+public:
+  virtual ~MCAsmLexer();
+};
+
+} // End llvm namespace
+
+#endif
index 2379f21e5aff91f24ababbeb769950bb617316e3..7cb6433a29fe7ea9c8b5f0e7e894dacabbd7c8f6 100644 (file)
 #define LLVM_MC_MCASMPARSER_H
 
 namespace llvm {
-class MCAsmParser;
-class MCInst;
-class Target;
-class TargetAsmParser;
+class MCAsmLexer;
 
 /// MCAsmParser - Generic assembler parser interface, for use by target specific
 /// assembly parsers.
@@ -26,6 +23,8 @@ protected: // Can only create subclasses.
  
 public:
   virtual ~MCAsmParser();
+
+  virtual MCAsmLexer &getLexer() = 0;
 };
 
 } // End llvm namespace
index f0af7df959dfe6b210d091141e45543ce337d116..3dd1e181910dbed4e92f9e56d6d89fb1ac149c68 100644 (file)
@@ -1,4 +1,5 @@
 add_llvm_library(LLVMMC
+  MCAsmLexer.cpp
   MCAsmParser.cpp
   MCAsmStreamer.cpp
   MCContext.cpp
diff --git a/lib/MC/MCAsmLexer.cpp b/lib/MC/MCAsmLexer.cpp
new file mode 100644 (file)
index 0000000..5cbcbfd
--- /dev/null
@@ -0,0 +1,18 @@
+//===-- MCAsmLexer.cpp - Abstract Asm Lexer 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/MCAsmLexer.h"
+
+using namespace llvm;
+
+MCAsmLexer::MCAsmLexer() {
+}
+
+MCAsmLexer::~MCAsmLexer() {
+}
index b5f6ce608ddabae73608b5a7e434b143649f5241..357ea6d3420c103f3bad0d78092f355ac4117613 100644 (file)
@@ -8,21 +8,29 @@
 //===----------------------------------------------------------------------===//
 
 #include "X86.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/MC/MCAsmParser.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetAsmParser.h"
 using namespace llvm;
 
 namespace {
+  struct X86Operand {
+  };
 
-class X86ATTAsmParser : public TargetAsmParser {
- public:
-  explicit X86ATTAsmParser(const Target &);
-
-  virtual bool ParseInstruction(MCAsmParser &AP, const char *Name, 
-                                MCInst &Inst);
-};
+  class X86ATTAsmParser : public TargetAsmParser {
+    bool ParseOperand(X86Operand &Op);
+    
+    bool MatchInstruction(const char *Name, 
+                          llvm::SmallVector<X86Operand, 3> &Operands,
+                          MCInst &Inst);
 
+  public:
+    explicit X86ATTAsmParser(const Target &);
+    
+    virtual bool ParseInstruction(MCAsmParser &AP, const char *Name, 
+                                  MCInst &Inst);
+  };
 }
 
 X86ATTAsmParser::X86ATTAsmParser(const Target &T) 
@@ -30,9 +38,25 @@ X86ATTAsmParser::X86ATTAsmParser(const Target &T)
 {
 }
 
+bool X86ATTAsmParser::ParseOperand(X86Operand &Op) {
+  return true;
+}
+
+bool 
+X86ATTAsmParser::MatchInstruction(const char *Name, 
+                                  llvm::SmallVector<X86Operand, 3> &Operands,
+                                  MCInst &Inst) {
+  return false;
+}
+
 bool X86ATTAsmParser::ParseInstruction(MCAsmParser &AP, const char *Name, 
                                        MCInst &Inst) {
-  return true;
+  MCAsmLexer &Lexer = AP.getLexer();
+  llvm::SmallVector<X86Operand, 3> Operands;
+  (void) Lexer;
+  (void) Operands;
+  
+  return MatchInstruction(Name, Operands, Inst);
 }
 
 namespace {
index 5d59d0ad7751365ca66665a6f7d360699989653f..32bbb50e9fb1b45c68922a9772a5817ddd6fdc57 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef ASMLEXER_H
 #define ASMLEXER_H
 
+#include "llvm/MC/MCAsmLexer.h"
 #include "llvm/Support/DataTypes.h"
 #include <string>
 #include <cassert>
@@ -52,7 +53,7 @@ namespace asmtok {
 }
 
 /// AsmLexer - Lexer class for assembly files.
-class AsmLexer {
+class AsmLexer : public MCAsmLexer {
   SourceMgr &SrcMgr;
   
   const char *CurPtr;
index b99675850809c80eb79b06acd7686bf266b8d812..d9f4b4c197be9915d5842cda70744ee3bab82ca5 100644 (file)
@@ -24,6 +24,7 @@ class MCContext;
 class MCInst;
 class MCStreamer;
 class MCValue;
+class TargetAsmParser;
 
 class AsmParser : MCAsmParser {
 public:
@@ -46,6 +47,8 @@ public:
 public:
   TargetAsmParser &getTargetParser() const { return TargetParser; }
 
+  virtual MCAsmLexer &getLexer() { return Lexer; }
+
 private:
   bool ParseStatement();