2012-02-17 16:55:11 +08:00
|
|
|
//===-- MipsAsmParser.cpp - Parse Mips assembly to MCInst instructions ----===//
|
2012-01-11 11:56:41 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MCTargetDesc/MipsMCTargetDesc.h"
|
|
|
|
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
|
|
|
#include "llvm/MC/MCTargetAsmParser.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-08-18 04:16:42 +08:00
|
|
|
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
|
|
|
|
#include "llvm/MC/MCTargetAsmParser.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-01-11 11:56:41 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class MipsAsmParser : public MCTargetAsmParser {
|
2012-08-18 04:16:42 +08:00
|
|
|
|
|
|
|
#define GET_ASSEMBLER_HEADER
|
|
|
|
#include "MipsGenAsmMatcher.inc"
|
|
|
|
|
2012-01-11 11:56:41 +08:00
|
|
|
bool MatchAndEmitInstruction(SMLoc IDLoc,
|
|
|
|
SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
|
|
|
MCStreamer &Out);
|
|
|
|
|
|
|
|
bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
|
|
|
|
|
|
|
|
bool ParseInstruction(StringRef Name, SMLoc NameLoc,
|
2012-08-18 04:16:42 +08:00
|
|
|
SmallVectorImpl<MCParsedAsmOperand*> &Operands);
|
2012-01-11 11:56:41 +08:00
|
|
|
|
|
|
|
bool ParseDirective(AsmToken DirectiveID);
|
|
|
|
|
2012-08-18 04:16:42 +08:00
|
|
|
OperandMatchResultTy parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*>&);
|
2012-09-04 02:47:45 +08:00
|
|
|
|
2012-09-05 09:15:43 +08:00
|
|
|
unsigned getMCInstOperandNum(unsigned Kind, MCInst &Inst,
|
2012-09-04 02:47:45 +08:00
|
|
|
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
2012-09-04 04:31:23 +08:00
|
|
|
unsigned OperandNum, unsigned &NumMCOperands);
|
2012-09-04 02:47:45 +08:00
|
|
|
|
2012-01-11 11:56:41 +08:00
|
|
|
public:
|
|
|
|
MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)
|
|
|
|
: MCTargetAsmParser() {
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-08-18 04:16:42 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// MipsOperand - Instances of this class represent a parsed Mips machine
|
|
|
|
/// instruction.
|
|
|
|
class MipsOperand : public MCParsedAsmOperand {
|
|
|
|
enum KindTy {
|
|
|
|
k_CondCode,
|
|
|
|
k_CoprocNum,
|
|
|
|
k_Immediate,
|
|
|
|
k_Memory,
|
|
|
|
k_PostIndexRegister,
|
|
|
|
k_Register,
|
|
|
|
k_Token
|
|
|
|
} Kind;
|
|
|
|
|
|
|
|
MipsOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
|
|
|
|
public:
|
|
|
|
void addRegOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
llvm_unreachable("unimplemented!");
|
|
|
|
}
|
|
|
|
void addExpr(MCInst &Inst, const MCExpr *Expr) const{
|
|
|
|
llvm_unreachable("unimplemented!");
|
|
|
|
}
|
|
|
|
void addImmOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
llvm_unreachable("unimplemented!");
|
|
|
|
}
|
|
|
|
void addMemOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
llvm_unreachable("unimplemented!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isReg() const { return Kind == k_Register; }
|
|
|
|
bool isImm() const { return Kind == k_Immediate; }
|
|
|
|
bool isToken() const { return Kind == k_Token; }
|
|
|
|
bool isMem() const { return Kind == k_Memory; }
|
|
|
|
|
|
|
|
StringRef getToken() const {
|
|
|
|
assert(Kind == k_Token && "Invalid access!");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getReg() const {
|
|
|
|
assert((Kind == k_Register) && "Invalid access!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void print(raw_ostream &OS) const {
|
|
|
|
llvm_unreachable("unimplemented!");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-09-04 02:47:45 +08:00
|
|
|
unsigned MipsAsmParser::
|
2012-09-05 09:15:43 +08:00
|
|
|
getMCInstOperandNum(unsigned Kind, MCInst &Inst,
|
2012-09-04 02:47:45 +08:00
|
|
|
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
2012-09-04 04:31:23 +08:00
|
|
|
unsigned OperandNum, unsigned &NumMCOperands) {
|
2012-09-05 09:15:43 +08:00
|
|
|
assert (0 && "getMCInstOperandNum() not supported by the Mips target.");
|
2012-09-04 03:04:35 +08:00
|
|
|
// The Mips backend doesn't currently include the matcher implementation, so
|
2012-09-05 09:15:43 +08:00
|
|
|
// the getMCInstOperandNumImpl() is undefined. This is a temporary
|
2012-09-04 03:04:35 +08:00
|
|
|
// work around.
|
2012-09-04 04:31:23 +08:00
|
|
|
NumMCOperands = 0;
|
2012-09-04 02:47:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 11:56:41 +08:00
|
|
|
bool MipsAsmParser::
|
|
|
|
MatchAndEmitInstruction(SMLoc IDLoc,
|
|
|
|
SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
|
|
|
MCStreamer &Out) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsAsmParser::
|
|
|
|
ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsAsmParser::
|
|
|
|
ParseInstruction(StringRef Name, SMLoc NameLoc,
|
|
|
|
SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsAsmParser::
|
|
|
|
ParseDirective(AsmToken DirectiveID) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-18 04:16:42 +08:00
|
|
|
MipsAsmParser::OperandMatchResultTy MipsAsmParser::
|
|
|
|
parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*>&) {
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2012-01-11 11:56:41 +08:00
|
|
|
extern "C" void LLVMInitializeMipsAsmParser() {
|
|
|
|
RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
|
|
|
|
RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
|
|
|
|
RegisterMCAsmParser<MipsAsmParser> A(TheMips64Target);
|
|
|
|
RegisterMCAsmParser<MipsAsmParser> B(TheMips64elTarget);
|
|
|
|
}
|