Move the MBlaze ELF writer bits to lib/Target/MBlaze.

llvm-svn: 147129
This commit is contained in:
Rafael Espindola 2011-12-22 02:28:24 +00:00
parent cc36f698af
commit cc369ac0a2
6 changed files with 86 additions and 71 deletions

View File

@ -1261,9 +1261,8 @@ MCObjectWriter *llvm::createELFObjectWriter(MCELFObjectTargetWriter *MOTW,
case ELF::EM_ARM:
case ELF::EM_PPC:
case ELF::EM_PPC64:
return new ELFObjectWriter(MOTW, OS, IsLittleEndian); break;
case ELF::EM_MBLAZE:
return new MBlazeELFObjectWriter(MOTW, OS, IsLittleEndian); break;
return new ELFObjectWriter(MOTW, OS, IsLittleEndian); break;
case ELF::EM_MIPS:
return new MipsELFObjectWriter(MOTW, OS, IsLittleEndian); break;
default: llvm_unreachable("Unsupported architecture"); break;
@ -1280,51 +1279,6 @@ unsigned ELFObjectWriter::GetRelocType(const MCValue &Target,
}
/// START OF SUBCLASSES for ELFObjectWriter
//===- MBlazeELFObjectWriter -------------------------------------------===//
MBlazeELFObjectWriter::MBlazeELFObjectWriter(MCELFObjectTargetWriter *MOTW,
raw_ostream &_OS,
bool IsLittleEndian)
: ELFObjectWriter(MOTW, _OS, IsLittleEndian) {
}
MBlazeELFObjectWriter::~MBlazeELFObjectWriter() {
}
unsigned MBlazeELFObjectWriter::GetRelocType(const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel,
bool IsRelocWithSymbol,
int64_t Addend) const {
// determine the type of the relocation
unsigned Type;
if (IsPCRel) {
switch ((unsigned)Fixup.getKind()) {
default:
llvm_unreachable("Unimplemented");
case FK_PCRel_4:
Type = ELF::R_MICROBLAZE_64_PCREL;
break;
case FK_PCRel_2:
Type = ELF::R_MICROBLAZE_32_PCREL;
break;
}
} else {
switch ((unsigned)Fixup.getKind()) {
default: llvm_unreachable("invalid fixup kind!");
case FK_Data_4:
Type = ((IsRelocWithSymbol || Addend !=0)
? ELF::R_MICROBLAZE_32
: ELF::R_MICROBLAZE_64);
break;
case FK_Data_2:
Type = ELF::R_MICROBLAZE_32;
break;
}
}
return Type;
}
//===- MipsELFObjectWriter -------------------------------------------===//
MipsELFObjectWriter::MipsELFObjectWriter(MCELFObjectTargetWriter *MOTW,

View File

@ -355,21 +355,6 @@ class ELFObjectWriter : public MCObjectWriter {
int64_t Addend) const;
};
//===- MBlazeELFObjectWriter -------------------------------------------===//
class MBlazeELFObjectWriter : public ELFObjectWriter {
public:
MBlazeELFObjectWriter(MCELFObjectTargetWriter *MOTW,
raw_ostream &_OS,
bool IsLittleEndian);
virtual ~MBlazeELFObjectWriter();
protected:
virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel, bool IsRelocWithSymbol,
int64_t Addend) const;
};
//===- MipsELFObjectWriter -------------------------------------------===//
class MipsELFObjectWriter : public ELFObjectWriter {

View File

@ -3,6 +3,7 @@ add_llvm_library(LLVMMBlazeDesc
MBlazeMCAsmInfo.cpp
MBlazeMCCodeEmitter.cpp
MBlazeMCTargetDesc.cpp
MBlazeELFObjectWriter.cpp
)
add_dependencies(LLVMMBlazeDesc MBlazeCommonTableGen)

View File

@ -39,12 +39,6 @@ static unsigned getFixupKindSize(unsigned Kind) {
namespace {
class MBlazeELFObjectWriter : public MCELFObjectTargetWriter {
public:
MBlazeELFObjectWriter(uint8_t OSABI)
: MCELFObjectTargetWriter(/*is64Bit*/ false, OSABI, ELF::EM_MBLAZE,
/*HasRelocationAddend*/ true) {}
};
class MBlazeAsmBackend : public MCAsmBackend {
public:
@ -131,8 +125,7 @@ public:
uint64_t Value) const;
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(new MBlazeELFObjectWriter(OSABI), OS,
/*IsLittleEndian*/ false);
return createMBlazeELFObjectWriter(OS, OSABI);
}
};

View File

@ -0,0 +1,77 @@
//===-- MBlazeELFObjectWriter.cpp - MBlaze ELF Writer ---------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "MCTargetDesc/MBlazeMCTargetDesc.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
namespace {
class MBlazeELFObjectWriter : public MCELFObjectTargetWriter {
public:
MBlazeELFObjectWriter(uint8_t OSABI);
virtual ~MBlazeELFObjectWriter();
protected:
virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel, bool IsRelocWithSymbol,
int64_t Addend) const;
};
}
MBlazeELFObjectWriter::MBlazeELFObjectWriter(uint8_t OSABI)
: MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI, ELF::EM_MBLAZE,
/*HasRelocationAddend*/ false) {}
MBlazeELFObjectWriter::~MBlazeELFObjectWriter() {
}
unsigned MBlazeELFObjectWriter::GetRelocType(const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel,
bool IsRelocWithSymbol,
int64_t Addend) const {
// determine the type of the relocation
unsigned Type;
if (IsPCRel) {
switch ((unsigned)Fixup.getKind()) {
default:
llvm_unreachable("Unimplemented");
case FK_PCRel_4:
Type = ELF::R_MICROBLAZE_64_PCREL;
break;
case FK_PCRel_2:
Type = ELF::R_MICROBLAZE_32_PCREL;
break;
}
} else {
switch ((unsigned)Fixup.getKind()) {
default: llvm_unreachable("invalid fixup kind!");
case FK_Data_4:
Type = ((IsRelocWithSymbol || Addend !=0)
? ELF::R_MICROBLAZE_32
: ELF::R_MICROBLAZE_64);
break;
case FK_Data_2:
Type = ELF::R_MICROBLAZE_32;
break;
}
}
return Type;
}
MCObjectWriter *llvm::createMBlazeELFObjectWriter(raw_ostream &OS,
uint8_t OSABI) {
MCELFObjectTargetWriter *MOTW = new MBlazeELFObjectWriter(OSABI);
return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/ false);
}

View File

@ -14,24 +14,29 @@
#ifndef MBLAZEMCTARGETDESC_H
#define MBLAZEMCTARGETDESC_H
#include "llvm/Support/DataTypes.h"
namespace llvm {
class MCAsmBackend;
class MCContext;
class MCCodeEmitter;
class MCInstrInfo;
class MCObjectWriter;
class MCSubtargetInfo;
class Target;
class StringRef;
class formatted_raw_ostream;
class raw_ostream;
extern Target TheMBlazeTarget;
MCCodeEmitter *createMBlazeMCCodeEmitter(const MCInstrInfo &MCII,
const MCSubtargetInfo &STI,
MCContext &Ctx);
MCAsmBackend *createMBlazeAsmBackend(const Target &T, StringRef TT);
MCObjectWriter *createMBlazeELFObjectWriter(raw_ostream &OS, uint8_t OSABI);
} // End llvm namespace
// Defines symbolic names for MBlaze registers. This defines a mapping from