From dbd692a66e6a5f60ec3ff120ed27ae3a918c375f Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 20 Jul 2009 20:01:54 +0000 Subject: [PATCH] Add MCAsmLexer interface. - 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 | 32 ++++++++++++++++++ include/llvm/MC/MCAsmParser.h | 7 ++-- lib/MC/CMakeLists.txt | 1 + lib/MC/MCAsmLexer.cpp | 18 ++++++++++ lib/Target/X86/AsmParser/X86AsmParser.cpp | 40 ++++++++++++++++++----- tools/llvm-mc/AsmLexer.h | 3 +- tools/llvm-mc/AsmParser.h | 3 ++ 7 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 include/llvm/MC/MCAsmLexer.h create mode 100644 lib/MC/MCAsmLexer.cpp diff --git a/include/llvm/MC/MCAsmLexer.h b/include/llvm/MC/MCAsmLexer.h new file mode 100644 index 00000000000..80628c3a3ad --- /dev/null +++ b/include/llvm/MC/MCAsmLexer.h @@ -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 diff --git a/include/llvm/MC/MCAsmParser.h b/include/llvm/MC/MCAsmParser.h index 2379f21e5af..7cb6433a29f 100644 --- a/include/llvm/MC/MCAsmParser.h +++ b/include/llvm/MC/MCAsmParser.h @@ -11,10 +11,7 @@ #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 diff --git a/lib/MC/CMakeLists.txt b/lib/MC/CMakeLists.txt index f0af7df959d..3dd1e181910 100644 --- a/lib/MC/CMakeLists.txt +++ b/lib/MC/CMakeLists.txt @@ -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 index 00000000000..5cbcbfd6de9 --- /dev/null +++ b/lib/MC/MCAsmLexer.cpp @@ -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() { +} diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index b5f6ce608dd..357ea6d3420 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -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 &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 &Operands, + MCInst &Inst) { + return false; +} + bool X86ATTAsmParser::ParseInstruction(MCAsmParser &AP, const char *Name, MCInst &Inst) { - return true; + MCAsmLexer &Lexer = AP.getLexer(); + llvm::SmallVector Operands; + (void) Lexer; + (void) Operands; + + return MatchInstruction(Name, Operands, Inst); } namespace { diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h index 5d59d0ad775..32bbb50e9fb 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -14,6 +14,7 @@ #ifndef ASMLEXER_H #define ASMLEXER_H +#include "llvm/MC/MCAsmLexer.h" #include "llvm/Support/DataTypes.h" #include #include @@ -52,7 +53,7 @@ namespace asmtok { } /// AsmLexer - Lexer class for assembly files. -class AsmLexer { +class AsmLexer : public MCAsmLexer { SourceMgr &SrcMgr; const char *CurPtr; diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index b9967585080..d9f4b4c197b 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -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();