[llvm-commits] [llvm] r118992 - in /llvm/trunk: include/llvm/MC/ELFObjectWriter.h include/llvm/MC/MCObjectWriter.h include/llvm/MC/MachObjectWriter.h lib/MC/ELFObjectWriter.cpp lib/MC/MachObjectWriter.cpp lib/Target/ARM/ARMAsmBackend.cpp lib/Target/MBlaze/MBlazeAsmBackend.cpp lib/Target/X86/X86AsmBackend.cpp

Daniel Dunbar daniel at zuster.org
Fri Nov 12 23:33:40 PST 2010


Author: ddunbar
Date: Sat Nov 13 01:33:40 2010
New Revision: 118992

URL: http://llvm.org/viewvc/llvm-project?rev=118992&view=rev
Log:
MC: Simplify Mach-O and ELF object writer implementations.
 - What was I thinking?????

Removed:
    llvm/trunk/include/llvm/MC/ELFObjectWriter.h
    llvm/trunk/include/llvm/MC/MachObjectWriter.h
Modified:
    llvm/trunk/include/llvm/MC/MCObjectWriter.h
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/lib/MC/MachObjectWriter.cpp
    llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp
    llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp
    llvm/trunk/lib/Target/X86/X86AsmBackend.cpp

Removed: llvm/trunk/include/llvm/MC/ELFObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/ELFObjectWriter.h?rev=118991&view=auto
==============================================================================
--- llvm/trunk/include/llvm/MC/ELFObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/ELFObjectWriter.h (removed)
@@ -1,53 +0,0 @@
-//===-- llvm/MC/ELFObjectWriter.h - ELF File Writer ---------*- 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_ELFOBJECTWRITER_H
-#define LLVM_MC_ELFOBJECTWRITER_H
-
-#include "llvm/ADT/Triple.h"
-#include "llvm/MC/MCObjectWriter.h"
-#include "llvm/Support/raw_ostream.h"
-#include <cassert>
-
-namespace llvm {
-class MCAsmFixup;
-class MCAssembler;
-class MCFragment;
-class MCValue;
-class raw_ostream;
-
-class ELFObjectWriter : public MCObjectWriter {
-  void *Impl;
-
-public:
-  ELFObjectWriter(raw_ostream &OS, bool Is64Bit, Triple::OSType OSType, 
-                  uint16_t EMachine, bool IsLittleEndian = true,
-                  bool HasRelocationAddend = true);
-
-  virtual ~ELFObjectWriter();
-
-  virtual void ExecutePostLayoutBinding(MCAssembler &Asm);
-
-  virtual void RecordRelocation(const MCAssembler &Asm,
-                                const MCAsmLayout &Layout,
-                                const MCFragment *Fragment,
-                                const MCFixup &Fixup, MCValue Target,
-                                uint64_t &FixedValue);
-
-  virtual bool IsFixupFullyResolved(const MCAssembler &Asm,
-                                    const MCValue Target,
-                                    bool IsPCRel,
-                                    const MCFragment *DF) const;
-
-  virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
-};
-
-} // End llvm namespace
-
-#endif

Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=118992&r1=118991&r2=118992&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Sat Nov 13 01:33:40 2010
@@ -10,6 +10,7 @@
 #ifndef LLVM_MC_MCOBJECTWRITER_H
 #define LLVM_MC_MCOBJECTWRITER_H
 
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/DataTypes.h"
 #include <cassert>
@@ -177,6 +178,13 @@
   static void EncodeULEB128(uint64_t Value, raw_ostream &OS);
 };
 
+MCObjectWriter *createMachObjectWriter(raw_ostream &OS, bool is64Bit,
+                                       uint32_t CPUType, uint32_t CPUSubtype,
+                                       bool IsLittleEndian);
+MCObjectWriter *createELFObjectWriter(raw_ostream &OS, bool is64Bit,
+                                      Triple::OSType OSType, uint16_t EMachine,
+                                      bool IsLittleEndian,
+                                      bool HasRelocationAddend);
 MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS, bool is64Bit);
 
 } // End llvm namespace

Removed: llvm/trunk/include/llvm/MC/MachObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MachObjectWriter.h?rev=118991&view=auto
==============================================================================
--- llvm/trunk/include/llvm/MC/MachObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MachObjectWriter.h (removed)
@@ -1,50 +0,0 @@
-//===-- llvm/MC/MachObjectWriter.h - Mach-O File Writer ---------*- 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_MACHOBJECTWRITER_H
-#define LLVM_MC_MACHOBJECTWRITER_H
-
-#include "llvm/MC/MCObjectWriter.h"
-#include "llvm/Support/raw_ostream.h"
-#include <cassert>
-
-namespace llvm {
-class MCAssembler;
-class MCFragment;
-class MCFixup;
-class MCValue;
-class raw_ostream;
-
-class MachObjectWriter : public MCObjectWriter {
-  void *Impl;
-
-public:
-  MachObjectWriter(raw_ostream &OS, bool Is64Bit, uint32_t CPUType,
-                   uint32_t CPUSubtype, bool IsLittleEndian = true);
-  virtual ~MachObjectWriter();
-
-  virtual void ExecutePostLayoutBinding(MCAssembler &Asm);
-
-  virtual void RecordRelocation(const MCAssembler &Asm,
-                                const MCAsmLayout &Layout,
-                                const MCFragment *Fragment,
-                                const MCFixup &Fixup, MCValue Target,
-                                uint64_t &FixedValue);
-
-  virtual bool IsFixupFullyResolved(const MCAssembler &Asm,
-                                    const MCValue Target,
-                                    bool IsPCRel,
-                                    const MCFragment *DF) const;
-
-  virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
-};
-
-} // End llvm namespace
-
-#endif

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=118992&r1=118991&r2=118992&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Sat Nov 13 01:33:40 2010
@@ -11,7 +11,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/MC/ELFObjectWriter.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -99,8 +98,7 @@
 }
 
 namespace {
-
-  class ELFObjectWriterImpl {
+  class ELFObjectWriter : public MCObjectWriter {
     /*static bool isFixupKindX86RIPRel(unsigned Kind) {
       return Kind == X86::reloc_riprel_4byte ||
         Kind == X86::reloc_riprel_4byte_movq_load;
@@ -167,10 +165,6 @@
 
     bool NeedsSymtabShndx;
 
-    ELFObjectWriter *Writer;
-
-    raw_ostream &OS;
-
     unsigned Is64Bit : 1;
 
     bool HasRelocationAddend;
@@ -189,29 +183,20 @@
     unsigned ShstrtabIndex;
 
   public:
-    ELFObjectWriterImpl(ELFObjectWriter *_Writer, bool _Is64Bit,
-                        uint16_t _EMachine, bool _HasRelAddend,
-                        Triple::OSType _OSType)
-      : NeedsGOT(false), NeedsSymtabShndx(false), Writer(_Writer),
-        OS(Writer->getStream()),
+    ELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian,
+                    uint16_t _EMachine, bool _HasRelAddend,
+                    Triple::OSType _OSType)
+      : MCObjectWriter(_OS, IsLittleEndian),
+        NeedsGOT(false), NeedsSymtabShndx(false),
         Is64Bit(_Is64Bit), HasRelocationAddend(_HasRelAddend),
         OSType(_OSType), EMachine(_EMachine) {
     }
-
-    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);
-    //}
-
+  
     void WriteWord(uint64_t W) {
       if (Is64Bit)
-        Writer->Write64(W);
+        Write64(W);
       else
-        Writer->Write32(W);
+        Write32(W);
     }
 
     void StringLE16(char *buf, uint16_t Value) {
@@ -252,7 +237,7 @@
 
     void String16(MCDataFragment &F, uint16_t Value) {
       char buf[2];
-      if (Writer->isLittleEndian())
+      if (isLittleEndian())
         StringLE16(buf, Value);
       else
         StringBE16(buf, Value);
@@ -261,7 +246,7 @@
 
     void String32(MCDataFragment &F, uint32_t Value) {
       char buf[4];
-      if (Writer->isLittleEndian())
+      if (isLittleEndian())
         StringLE32(buf, Value);
       else
         StringBE32(buf, Value);
@@ -270,7 +255,7 @@
 
     void String64(MCDataFragment &F, uint64_t Value) {
       char buf[8];
-      if (Writer->isLittleEndian())
+      if (isLittleEndian())
         StringLE64(buf, Value);
       else
         StringBE64(buf, Value);
@@ -357,8 +342,8 @@
 }
 
 // Emit the ELF header.
-void ELFObjectWriterImpl::WriteHeader(uint64_t SectionDataSize,
-                                      unsigned NumberOfSections) {
+void ELFObjectWriter::WriteHeader(uint64_t SectionDataSize,
+                                  unsigned NumberOfSections) {
   // ELF Header
   // ----------
   //
@@ -375,7 +360,7 @@
   Write8(Is64Bit ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]
 
   // e_ident[EI_DATA]
-  Write8(Writer->isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
+  Write8(isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
 
   Write8(ELF::EV_CURRENT);        // e_ident[EI_VERSION]
   // e_ident[EI_OSABI]
@@ -423,13 +408,13 @@
     Write16(ShstrtabIndex);
 }
 
-void ELFObjectWriterImpl::WriteSymbolEntry(MCDataFragment *SymtabF,
-                                           MCDataFragment *ShndxF,
-                                           uint64_t name,
-                                           uint8_t info, uint64_t value,
-                                           uint64_t size, uint8_t other,
-                                           uint32_t shndx,
-                                           bool Reserved) {
+void ELFObjectWriter::WriteSymbolEntry(MCDataFragment *SymtabF,
+                                       MCDataFragment *ShndxF,
+                                       uint64_t name,
+                                       uint8_t info, uint64_t value,
+                                       uint64_t size, uint8_t other,
+                                       uint32_t shndx,
+                                       bool Reserved) {
   if (ShndxF) {
     if (shndx >= ELF::SHN_LORESERVE && !Reserved)
       String32(*ShndxF, shndx);
@@ -497,7 +482,7 @@
   return *S;
 }
 
-void ELFObjectWriterImpl::ExecutePostLayoutBinding(MCAssembler &Asm) {
+void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {
   // The presence of symbol versions causes undefined symbols and
   // versions declared with @@@ to be renamed.
 
@@ -543,10 +528,10 @@
   }
 }
 
-void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *SymtabF,
-                                      MCDataFragment *ShndxF,
-                                      ELFSymbolData &MSD,
-                                      const MCAsmLayout &Layout) {
+void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
+                                  MCDataFragment *ShndxF,
+                                  ELFSymbolData &MSD,
+                                  const MCAsmLayout &Layout) {
   MCSymbolData &OrigData = *MSD.SymbolData;
   MCSymbolData &Data =
     Layout.getAssembler().getSymbolData(AliasedSymbol(OrigData.getSymbol()));
@@ -590,10 +575,10 @@
                    Size, Other, MSD.SectionIndex, IsReserved);
 }
 
-void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *SymtabF,
-                                           MCDataFragment *ShndxF,
-                                           const MCAssembler &Asm,
-                                           const MCAsmLayout &Layout,
+void ELFObjectWriter::WriteSymbolTable(MCDataFragment *SymtabF,
+                                       MCDataFragment *ShndxF,
+                                       const MCAssembler &Asm,
+                                       const MCAsmLayout &Layout,
                                      const SectionIndexMapTy &SectionIndexMap) {
   // The string table must be emitted first because we need the index
   // into the string table for all the symbol names.
@@ -679,12 +664,12 @@
 }
 
 // FIXME: this is currently X86/X86_64 only
-void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
-                                           const MCAsmLayout &Layout,
-                                           const MCFragment *Fragment,
-                                           const MCFixup &Fixup,
-                                           MCValue Target,
-                                           uint64_t &FixedValue) {
+void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
+                                       const MCAsmLayout &Layout,
+                                       const MCFragment *Fragment,
+                                       const MCFixup &Fixup,
+                                       MCValue Target,
+                                       uint64_t &FixedValue) {
   int64_t Addend = 0;
   int Index = 0;
   int64_t Value = Target.getConstant();
@@ -886,8 +871,8 @@
 }
 
 uint64_t
-ELFObjectWriterImpl::getSymbolIndexInSymbolTable(const MCAssembler &Asm,
-                                                 const MCSymbol *S) {
+ELFObjectWriter::getSymbolIndexInSymbolTable(const MCAssembler &Asm,
+                                             const MCSymbol *S) {
   MCSymbolData &SD = Asm.getSymbolData(*S);
 
   // Local symbol.
@@ -938,8 +923,8 @@
   return true;
 }
 
-void ELFObjectWriterImpl::ComputeIndexMap(MCAssembler &Asm,
-                                          SectionIndexMapTy &SectionIndexMap) {
+void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,
+                                      SectionIndexMapTy &SectionIndexMap) {
   unsigned Index = 1;
   for (MCAssembler::iterator it = Asm.begin(),
          ie = Asm.end(); it != ie; ++it) {
@@ -960,7 +945,7 @@
   }
 }
 
-void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm,
+void ELFObjectWriter::ComputeSymbolTable(MCAssembler &Asm,
                                      const SectionIndexMapTy &SectionIndexMap) {
   // FIXME: Is this the correct place to do this?
   if (NeedsGOT) {
@@ -1057,8 +1042,8 @@
     UndefinedSymbolData[i].SymbolData->setIndex(Index++);
 }
 
-void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
-                                          const MCSectionData &SD) {
+void ELFObjectWriter::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
+                                      const MCSectionData &SD) {
   if (!Relocations[&SD].empty()) {
     MCContext &Ctx = Asm.getContext();
     const MCSectionELF *RelaSection;
@@ -1087,16 +1072,16 @@
 
     WriteRelocationsFragment(Asm, F, &SD);
 
-    Asm.AddSectionToTheEnd(*Writer, RelaSD, Layout);
+    Asm.AddSectionToTheEnd(*this, RelaSD, Layout);
   }
 }
 
-void ELFObjectWriterImpl::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
-                                           uint64_t Flags, uint64_t Address,
-                                           uint64_t Offset, uint64_t Size,
-                                           uint32_t Link, uint32_t Info,
-                                           uint64_t Alignment,
-                                           uint64_t EntrySize) {
+void ELFObjectWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
+                                       uint64_t Flags, uint64_t Address,
+                                       uint64_t Offset, uint64_t Size,
+                                       uint32_t Link, uint32_t Info,
+                                       uint64_t Alignment,
+                                       uint64_t EntrySize) {
   Write32(Name);        // sh_name: index into string table
   Write32(Type);        // sh_type
   WriteWord(Flags);     // sh_flags
@@ -1109,9 +1094,9 @@
   WriteWord(EntrySize); // sh_entsize
 }
 
-void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm,
-                                                   MCDataFragment *F,
-                                                   const MCSectionData *SD) {
+void ELFObjectWriter::WriteRelocationsFragment(const MCAssembler &Asm,
+                                               MCDataFragment *F,
+                                               const MCSectionData *SD) {
   std::vector<ELFRelocationEntry> &Relocs = Relocations[SD];
   // sort by the r_offset just like gnu as does
   array_pod_sort(Relocs.begin(), Relocs.end());
@@ -1145,8 +1130,8 @@
   }
 }
 
-void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,
-                                                 MCAsmLayout &Layout,
+void ELFObjectWriter::CreateMetadataSections(MCAssembler &Asm,
+                                             MCAsmLayout &Layout,
                                     const SectionIndexMapTy &SectionIndexMap) {
   MCContext &Ctx = Asm.getContext();
   MCDataFragment *F;
@@ -1193,14 +1178,14 @@
   MCDataFragment *ShndxF = NULL;
   if (NeedsSymtabShndx) {
     ShndxF = new MCDataFragment(SymtabShndxSD);
-    Asm.AddSectionToTheEnd(*Writer, *SymtabShndxSD, Layout);
+    Asm.AddSectionToTheEnd(*this, *SymtabShndxSD, Layout);
   }
   WriteSymbolTable(F, ShndxF, Asm, Layout, SectionIndexMap);
-  Asm.AddSectionToTheEnd(*Writer, SymtabSD, Layout);
+  Asm.AddSectionToTheEnd(*this, SymtabSD, Layout);
 
   F = new MCDataFragment(&StrtabSD);
   F->getContents().append(StringTable.begin(), StringTable.end());
-  Asm.AddSectionToTheEnd(*Writer, StrtabSD, Layout);
+  Asm.AddSectionToTheEnd(*this, StrtabSD, Layout);
 
   F = new MCDataFragment(&ShstrtabSD);
 
@@ -1233,13 +1218,13 @@
     F->getContents() += '\x00';
   }
 
-  Asm.AddSectionToTheEnd(*Writer, ShstrtabSD, Layout);
+  Asm.AddSectionToTheEnd(*this, ShstrtabSD, Layout);
 }
 
-bool ELFObjectWriterImpl::IsFixupFullyResolved(const MCAssembler &Asm,
-                                               const MCValue Target,
-                                               bool IsPCRel,
-                                               const MCFragment *DF) const {
+bool ELFObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm,
+                                           const MCValue Target,
+                                           bool IsPCRel,
+                                           const MCFragment *DF) const {
   // If this is a PCrel relocation, find the section this fixup value is
   // relative to.
   const MCSection *BaseSection = 0;
@@ -1270,9 +1255,9 @@
   return !SectionB && BaseSection == SectionA;
 }
 
-void ELFObjectWriterImpl::CreateGroupSections(MCAssembler &Asm,
-                                              MCAsmLayout &Layout,
-                                              GroupMapTy &GroupMap) {
+void ELFObjectWriter::CreateGroupSections(MCAssembler &Asm,
+                                          MCAsmLayout &Layout,
+                                          GroupMapTy &GroupMap) {
   typedef DenseMap<const MCSymbol*, const MCSectionELF*> RevGroupMapTy;
   // Build the groups
   RevGroupMapTy Groups;
@@ -1316,16 +1301,16 @@
        i != e; ++i) {
     const MCSectionELF *Group = i->second;
     MCSectionData &Data = Asm.getOrCreateSectionData(*Group);
-    Asm.AddSectionToTheEnd(*Writer, Data, Layout);
+    Asm.AddSectionToTheEnd(*this, Data, Layout);
   }
 }
 
-void ELFObjectWriterImpl::WriteSection(MCAssembler &Asm,
-                                       const SectionIndexMapTy &SectionIndexMap,
-                                       uint32_t GroupSymbolIndex,
-                                       uint64_t Offset, uint64_t Size,
-                                       uint64_t Alignment,
-                                       const MCSectionELF &Section) {
+void ELFObjectWriter::WriteSection(MCAssembler &Asm,
+                                   const SectionIndexMapTy &SectionIndexMap,
+                                   uint32_t GroupSymbolIndex,
+                                   uint64_t Offset, uint64_t Size,
+                                   uint64_t Alignment,
+                                   const MCSectionELF &Section) {
   uint64_t sh_link = 0;
   uint64_t sh_info = 0;
 
@@ -1390,9 +1375,8 @@
                    Alignment, Section.getEntrySize());
 }
 
-void ELFObjectWriterImpl::WriteObject(MCAssembler &Asm,
-                                      const MCAsmLayout &Layout) {
-
+void ELFObjectWriter::WriteObject(MCAssembler &Asm,
+                                  const MCAsmLayout &Layout) {
   GroupMapTy GroupMap;
   CreateGroupSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap);
 
@@ -1460,7 +1444,7 @@
 
     FileOff += Layout.getSectionFileSize(&SD);
 
-    Asm.WriteSectionData(&SD, Layout, Writer);
+    Asm.WriteSectionData(&SD, Layout, this);
   }
 
   uint64_t Padding = OffsetToAlignment(FileOff, NaturalAlignment);
@@ -1492,44 +1476,12 @@
   }
 }
 
-ELFObjectWriter::ELFObjectWriter(raw_ostream &OS,
-                                 bool Is64Bit,
-                                 Triple::OSType OSType,
-                                 uint16_t EMachine,
-                                 bool IsLittleEndian,
-                                 bool HasRelocationAddend)
-  : MCObjectWriter(OS, IsLittleEndian)
-{
-  Impl = new ELFObjectWriterImpl(this, Is64Bit, EMachine,
-                                 HasRelocationAddend, OSType);
-}
-
-ELFObjectWriter::~ELFObjectWriter() {
-  delete (ELFObjectWriterImpl*) Impl;
-}
-
-void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {
-  ((ELFObjectWriterImpl*) Impl)->ExecutePostLayoutBinding(Asm);
-}
-
-void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
-                                       const MCAsmLayout &Layout,
-                                       const MCFragment *Fragment,
-                                       const MCFixup &Fixup, MCValue Target,
-                                       uint64_t &FixedValue) {
-  ((ELFObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup,
-                                                  Target, FixedValue);
-}
-
-bool ELFObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm,
-                                           const MCValue Target,
-                                           bool IsPCRel,
-                                           const MCFragment *DF) const {
-  return ((ELFObjectWriterImpl*) Impl)->IsFixupFullyResolved(Asm, Target,
-                                                             IsPCRel, DF);
-}
-
-void ELFObjectWriter::WriteObject(MCAssembler &Asm,
-                                  const MCAsmLayout &Layout) {
-  ((ELFObjectWriterImpl*) Impl)->WriteObject(Asm, Layout);
+MCObjectWriter *llvm::createELFObjectWriter(raw_ostream &OS,
+                                            bool Is64Bit,
+                                            Triple::OSType OSType,
+                                            uint16_t EMachine,
+                                            bool IsLittleEndian,
+                                            bool HasRelocationAddend) {
+  return new ELFObjectWriter(OS, Is64Bit, IsLittleEndian, EMachine,
+                             HasRelocationAddend, OSType);
 }

Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=118992&r1=118991&r2=118992&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Sat Nov 13 01:33:40 2010
@@ -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 @@
 
 namespace {
 
-class MachObjectWriterImpl {
+class MachObjectWriter : public MCObjectWriter {
   // See <mach-o/loader.h>.
   enum {
     Header_Magic32 = 0xFEEDFACE,
@@ -284,29 +283,17 @@
 
   /// @}
 
-  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 @@
     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 @@
     // 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 @@
 
 }
 
-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);
 }

Modified: llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp?rev=118992&r1=118991&r2=118992&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp Sat Nov 13 01:33:40 2010
@@ -11,14 +11,12 @@
 #include "ARM.h"
 #include "ARMFixupKinds.h"
 #include "llvm/ADT/Twine.h"
-#include "llvm/MC/ELFObjectWriter.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectFormat.h"
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MachObjectWriter.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/MachO.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -94,10 +92,10 @@
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return new ELFObjectWriter(OS, /*Is64Bit=*/false,
-                               OSType, ELF::EM_ARM,
-                               /*IsLittleEndian=*/true,
-                               /*HasRelocationAddend=*/false);
+    return createELFObjectWriter(OS, /*Is64Bit=*/false,
+                                 OSType, ELF::EM_ARM,
+                                 /*IsLittleEndian=*/true,
+                                 /*HasRelocationAddend=*/false);
   }
 };
 
@@ -133,8 +131,9 @@
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
     // FIXME: Subtarget info should be derived. Force v7 for now.
-    return new MachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeARM,
-                                MachO::CPUSubType_ARM_V7);
+    return createMachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeARM,
+                                  MachO::CPUSubType_ARM_V7,
+                                  /*IsLittleEndian=*/true);
   }
 
   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {

Modified: llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp?rev=118992&r1=118991&r2=118992&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp Sat Nov 13 01:33:40 2010
@@ -11,14 +11,12 @@
 #include "MBlaze.h"
 #include "MBlazeFixupKinds.h"
 #include "llvm/ADT/Twine.h"
-#include "llvm/MC/ELFObjectWriter.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectFormat.h"
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MachObjectWriter.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -104,10 +102,10 @@
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return new ELFObjectWriter(OS, /*Is64Bit=*/false,
-                               OSType, ELF::EM_MBLAZE,
-                               /*IsLittleEndian=*/false,
-                               /*HasRelocationAddend=*/true);
+    return createELFObjectWriter(OS, /*Is64Bit=*/false,
+                                 OSType, ELF::EM_MBLAZE,
+                                 /*IsLittleEndian=*/false,
+                                 /*HasRelocationAddend=*/true);
   }
 };
 

Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=118992&r1=118991&r2=118992&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Sat Nov 13 01:33:40 2010
@@ -11,7 +11,6 @@
 #include "X86.h"
 #include "X86FixupKinds.h"
 #include "llvm/ADT/Twine.h"
-#include "llvm/MC/ELFObjectWriter.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectFormat.h"
@@ -19,7 +18,6 @@
 #include "llvm/MC/MCSectionCOFF.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MachObjectWriter.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/MachO.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -310,10 +308,10 @@
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return new ELFObjectWriter(OS, /*Is64Bit=*/false,
-                               OSType, ELF::EM_386,
-                               /*IsLittleEndian=*/true,
-                               /*HasRelocationAddend=*/false);
+    return createELFObjectWriter(OS, /*Is64Bit=*/false,
+                                 OSType, ELF::EM_386,
+                                 /*IsLittleEndian=*/true,
+                                 /*HasRelocationAddend=*/false);
   }
 };
 
@@ -327,10 +325,10 @@
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return new ELFObjectWriter(OS, /*Is64Bit=*/true,
-                               OSType, ELF::EM_X86_64,
-                               /*IsLittleEndian=*/true,
-                               /*HasRelocationAddend=*/true);
+    return createELFObjectWriter(OS, /*Is64Bit=*/true,
+                                 OSType, ELF::EM_X86_64,
+                                 /*IsLittleEndian=*/true,
+                                 /*HasRelocationAddend=*/true);
   }
 };
 
@@ -397,8 +395,9 @@
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return new MachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeI386,
-                                MachO::CPUSubType_I386_ALL);
+    return createMachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeI386,
+                                  MachO::CPUSubType_I386_ALL,
+                                  /*IsLittleEndian=*/true);
   }
 };
 
@@ -414,8 +413,9 @@
   }
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return new MachObjectWriter(OS, /*Is64Bit=*/true, MachO::CPUTypeX86_64,
-                                MachO::CPUSubType_I386_ALL);
+    return createMachObjectWriter(OS, /*Is64Bit=*/true, MachO::CPUTypeX86_64,
+                                  MachO::CPUSubType_I386_ALL,
+                                  /*IsLittleEndian=*/true);
   }
 
   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {





More information about the llvm-commits mailing list