mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-04 09:30:13 +00:00
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147129 91177308-0d34-0410-b5e6-96231b3b80d8
78 lines
2.4 KiB
C++
78 lines
2.4 KiB
C++
//===-- 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);
|
|
}
|