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
This commit is contained in:
Daniel Dunbar 2009-07-20 20:01:54 +00:00
parent 753480ad20
commit dbd692a66e
7 changed files with 91 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,5 @@
add_llvm_library(LLVMMC
MCAsmLexer.cpp
MCAsmParser.cpp
MCAsmStreamer.cpp
MCContext.cpp

18
lib/MC/MCAsmLexer.cpp Normal file
View File

@ -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() {
}

View 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 {

View 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;

View 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();