aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC/MachObjectWriter.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-11-13 07:33:40 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-11-13 07:33:40 +0000
commit115a3dd066c277c5417f4d9b9f642b732b76f4e7 (patch)
tree5e0b26f15fda2285f3afbff6ad4f6de8e4d33dae /lib/MC/MachObjectWriter.cpp
parent90eff7337d36b0398a22eac29da87c9c07b03b78 (diff)
downloadexternal_llvm-115a3dd066c277c5417f4d9b9f642b732b76f4e7.zip
external_llvm-115a3dd066c277c5417f4d9b9f642b732b76f4e7.tar.gz
external_llvm-115a3dd066c277c5417f4d9b9f642b732b76f4e7.tar.bz2
MC: Simplify Mach-O and ELF object writer implementations.
- What was I thinking????? git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118992 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MachObjectWriter.cpp')
-rw-r--r--lib/MC/MachObjectWriter.cpp72
1 files changed, 13 insertions, 59 deletions
diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp
index fc71125..41c11fb 100644
--- a/lib/MC/MachObjectWriter.cpp
+++ b/lib/MC/MachObjectWriter.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/MC/MachObjectWriter.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCAssembler.h"
@@ -159,7 +158,7 @@ static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,
namespace {
-class MachObjectWriterImpl {
+class MachObjectWriter : public MCObjectWriter {
// See <mach-o/loader.h>.
enum {
Header_Magic32 = 0xFEEDFACE,
@@ -284,29 +283,17 @@ class MachObjectWriterImpl {
/// @}
- MachObjectWriter *Writer;
-
- raw_ostream &OS;
-
unsigned Is64Bit : 1;
uint32_t CPUType;
uint32_t CPUSubtype;
public:
- MachObjectWriterImpl(MachObjectWriter *_Writer, bool _Is64Bit,
- uint32_t _CPUType, uint32_t _CPUSubtype)
- : Writer(_Writer), OS(Writer->getStream()), Is64Bit(_Is64Bit),
- CPUType(_CPUType), CPUSubtype(_CPUSubtype) {
- }
-
- void Write8(uint8_t Value) { Writer->Write8(Value); }
- void Write16(uint16_t Value) { Writer->Write16(Value); }
- void Write32(uint32_t Value) { Writer->Write32(Value); }
- void Write64(uint64_t Value) { Writer->Write64(Value); }
- void WriteZeros(unsigned N) { Writer->WriteZeros(N); }
- void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) {
- Writer->WriteBytes(Str, ZeroFillSize);
+ MachObjectWriter(raw_ostream &_OS,
+ bool _Is64Bit, uint32_t _CPUType, uint32_t _CPUSubtype,
+ bool _IsLittleEndian)
+ : MCObjectWriter(_OS, _IsLittleEndian),
+ Is64Bit(_Is64Bit), CPUType(_CPUType), CPUSubtype(_CPUSubtype) {
}
void WriteHeader(unsigned NumLoadCommands, unsigned LoadCommandsSize,
@@ -1170,7 +1157,7 @@ public:
return true;
}
- void WriteObject(const MCAssembler &Asm, const MCAsmLayout &Layout) {
+ void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
unsigned NumSections = Asm.size();
// The section data starts after the header, the segment load command (and
@@ -1271,7 +1258,7 @@ public:
// Write the actual section data.
for (MCAssembler::const_iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it)
- Asm.WriteSectionData(it, Layout, Writer);
+ Asm.WriteSectionData(it, Layout, this);
// Write the extra padding.
WriteZeros(SectionDataPadding);
@@ -1331,42 +1318,9 @@ public:
}
-MachObjectWriter::MachObjectWriter(raw_ostream &OS,
- bool Is64Bit,
- uint32_t CPUType,
- uint32_t CPUSubtype,
- bool IsLittleEndian)
- : MCObjectWriter(OS, IsLittleEndian)
-{
- Impl = new MachObjectWriterImpl(this, Is64Bit, CPUType, CPUSubtype);
-}
-
-MachObjectWriter::~MachObjectWriter() {
- delete (MachObjectWriterImpl*) Impl;
-}
-
-void MachObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {
- ((MachObjectWriterImpl*) Impl)->ExecutePostLayoutBinding(Asm);
-}
-
-void MachObjectWriter::RecordRelocation(const MCAssembler &Asm,
- const MCAsmLayout &Layout,
- const MCFragment *Fragment,
- const MCFixup &Fixup, MCValue Target,
- uint64_t &FixedValue) {
- ((MachObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup,
- Target, FixedValue);
-}
-
-bool MachObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm,
- const MCValue Target,
- bool IsPCRel,
- const MCFragment *DF) const {
- return ((MachObjectWriterImpl*) Impl)->IsFixupFullyResolved(Asm, Target,
- IsPCRel, DF);
-}
-
-void MachObjectWriter::WriteObject(MCAssembler &Asm,
- const MCAsmLayout &Layout) {
- ((MachObjectWriterImpl*) Impl)->WriteObject(Asm, Layout);
+MCObjectWriter *llvm::createMachObjectWriter(raw_ostream &OS, bool is64Bit,
+ uint32_t CPUType,
+ uint32_t CPUSubtype,
+ bool IsLittleEndian) {
+ return new MachObjectWriter(OS, is64Bit, CPUType, CPUSubtype, IsLittleEndian);
}