[llvm-commits] [llvm] r76453 - in /llvm/trunk: include/llvm/MC/MCAsmParser.h include/llvm/Target/TargetAsmParser.h lib/MC/CMakeLists.txt lib/MC/MCAsmParser.cpp lib/Target/X86/AsmParser/X86AsmParser.cpp tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h tools/llvm-mc/llvm-mc.cpp
Daniel Dunbar
daniel at zuster.org
Mon Jul 20 11:55:05 PDT 2009
Author: ddunbar
Date: Mon Jul 20 13:55:04 2009
New Revision: 76453
URL: http://llvm.org/viewvc/llvm-project?rev=76453&view=rev
Log:
Add MCAsmParser interface.
- This provides the AsmParser interface to the target specific assembly
parsers.
Added:
llvm/trunk/include/llvm/MC/MCAsmParser.h
llvm/trunk/lib/MC/MCAsmParser.cpp
Modified:
llvm/trunk/include/llvm/Target/TargetAsmParser.h
llvm/trunk/lib/MC/CMakeLists.txt
llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.h
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
Added: llvm/trunk/include/llvm/MC/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmParser.h?rev=76453&view=auto
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmParser.h (added)
+++ llvm/trunk/include/llvm/MC/MCAsmParser.h Mon Jul 20 13:55:04 2009
@@ -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
Modified: llvm/trunk/include/llvm/Target/TargetAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmParser.h?rev=76453&r1=76452&r2=76453&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmParser.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmParser.h Mon Jul 20 13:55:04 2009
@@ -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 @@
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
Modified: llvm/trunk/lib/MC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/CMakeLists.txt?rev=76453&r1=76452&r2=76453&view=diff
==============================================================================
--- llvm/trunk/lib/MC/CMakeLists.txt (original)
+++ llvm/trunk/lib/MC/CMakeLists.txt Mon Jul 20 13:55:04 2009
@@ -1,4 +1,5 @@
add_llvm_library(LLVMMC
+ MCAsmParser.cpp
MCAsmStreamer.cpp
MCContext.cpp
MCStreamer.cpp
Added: llvm/trunk/lib/MC/MCAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmParser.cpp?rev=76453&view=auto
==============================================================================
--- llvm/trunk/lib/MC/MCAsmParser.cpp (added)
+++ llvm/trunk/lib/MC/MCAsmParser.cpp Mon Jul 20 13:55:04 2009
@@ -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() {
+}
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=76453&r1=76452&r2=76453&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Mon Jul 20 13:55:04 2009
@@ -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 @@
class X86ATTAsmParser : public TargetAsmParser {
public:
explicit X86ATTAsmParser(const Target &);
+
+ virtual bool ParseInstruction(MCAsmParser &AP, const char *Name,
+ MCInst &Inst);
};
}
@@ -26,6 +30,11 @@
{
}
+bool X86ATTAsmParser::ParseInstruction(MCAsmParser &AP, const char *Name,
+ MCInst &Inst) {
+ return true;
+}
+
namespace {
TargetAsmParser *createAsmParser(const Target &T) {
return new X86ATTAsmParser(T);
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=76453&r1=76452&r2=76453&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Mon Jul 20 13:55:04 2009
@@ -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 @@
}
MCInst Inst;
- if (ParseX86InstOperands(IDVal, Inst))
+ if (ParseX86InstOperands(IDVal, Inst) &&
+ getTargetParser().ParseInstruction(*this, IDVal, Inst))
return true;
if (Lexer.isNot(asmtok::EndOfStatement))
Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=76453&r1=76452&r2=76453&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Mon Jul 20 13:55:04 2009
@@ -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 MCStreamer;
class MCValue;
-class AsmParser {
+class AsmParser : MCAsmParser {
public:
struct X86Operand;
@@ -32,14 +33,19 @@
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();
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=76453&r1=76452&r2=76453&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Mon Jul 20 13:55:04 2009
@@ -186,9 +186,10 @@
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();
}
More information about the llvm-commits
mailing list