Have the OutputBuffer take the is64Bit and isLittleEndian booleans.
authorBill Wendling <isanbard@gmail.com>
Thu, 18 Jan 2007 01:23:11 +0000 (01:23 +0000)
committerBill Wendling <isanbard@gmail.com>
Thu, 18 Jan 2007 01:23:11 +0000 (01:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33316 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/OutputBuffer.h
lib/CodeGen/ELFWriter.cpp
lib/CodeGen/MachOWriter.cpp
lib/Target/PowerPC/PPCMachOWriter.cpp

index 24a655cef6c16352b6d65a8a1537753f454fddd2..73a4a631debd11be328ac539bcf8448f561aed21 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_OUTPUTBUFFER_H
 #define LLVM_SUPPORT_OUTPUTBUFFER_H
 
+#include <string>
 #include <vector>
 
 namespace llvm {
@@ -26,11 +27,9 @@ namespace llvm {
     /// machine directly, indicating what header values and flags to set.
     bool is64Bit, isLittleEndian;
   public:
-    OutputBuffer(const TargetMachine& TM,
-                 std::vector<unsigned char> &Out) : Output(Out) {
-      is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
-      isLittleEndian = TM.getTargetData()->isLittleEndian();
-    }
+    OutputBuffer(std::vector<unsigned char> &Out,
+                 bool is64bit, bool le)
+      : Output(Out), is64Bit(is64bit), isLittleEndian(le) {}
 
     // align - Emit padding into the file until the current output position is
     // aligned to the specified power of two boundary.
@@ -107,7 +106,7 @@ namespace llvm {
       else
         outxword(X);
     }
-    void outstring(std::string &S, unsigned Length) {
+    void outstring(const std::string &S, unsigned Length) {
       unsigned len_to_copy = S.length() < Length ? S.length() : Length;
       unsigned len_to_fill = S.length() < Length ? Length - S.length() : 0;
       
index e43346897d9ab74bace73a80123eee587788423b..4f988070fddf558289da9b9055318998d0d6365e 100644 (file)
@@ -115,7 +115,9 @@ void ELFCodeEmitter::startFunction(MachineFunction &F) {
 
   // Add padding zeros to the end of the buffer to make sure that the
   // function will start on the correct byte alignment within the section.
-  OutputBuffer OB(TM, *OutBuffer);
+  OutputBuffer OB(*OutBuffer,
+                  TM.getTargetData()->getPointerSizeInBits() == 64,
+                  TM.getTargetData()->isLittleEndian());
   OB.align(Align);
   FnStart = OutBuffer->size();
 }
@@ -182,7 +184,7 @@ bool ELFWriter::doInitialization(Module &M) {
 
   // Local alias to shortenify coming code.
   std::vector<unsigned char> &FH = FileHeader;
-  OutputBuffer FHOut(TM, FH);
+  OutputBuffer FHOut(FH, is64Bit, isLittleEndian);
 
   FHOut.outbyte(0x7F);                     // EI_MAG0
   FHOut.outbyte('E');                      // EI_MAG1
@@ -353,7 +355,7 @@ void ELFWriter::EmitSymbolTable() {
   StrTab.Align = 1;
 
   DataBuffer &StrTabBuf = StrTab.SectionData;
-  OutputBuffer StrTabOut(TM, StrTabBuf);
+  OutputBuffer StrTabOut(StrTabBuf, is64Bit, isLittleEndian);
 
   // Set the zero'th symbol to a null byte, as required.
   StrTabOut.outbyte(0);
@@ -389,7 +391,7 @@ void ELFWriter::EmitSymbolTable() {
   SymTab.Info = FirstNonLocalSymbol;   // First non-STB_LOCAL symbol.
   SymTab.EntSize = 16; // Size of each symtab entry. FIXME: wrong for ELF64
   DataBuffer &SymTabBuf = SymTab.SectionData;
-  OutputBuffer SymTabOut(TM, SymTabBuf);
+  OutputBuffer SymTabOut(SymTabBuf, is64Bit, isLittleEndian);
 
   if (!is64Bit) {   // 32-bit and 64-bit formats are shuffled a bit.
     for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
@@ -425,7 +427,7 @@ void ELFWriter::EmitSectionTableStringTable() {
 
   // Now that we know which section number is the .shstrtab section, update the
   // e_shstrndx entry in the ELF header.
-  OutputBuffer FHOut(TM, FileHeader);
+  OutputBuffer FHOut(FileHeader, is64Bit, isLittleEndian);
   FHOut.fixhalf(SHStrTab.SectionIdx, ELFHeader_e_shstrndx_Offset);
 
   // Set the NameIdx of each section in the string table and emit the bytes for
@@ -477,7 +479,7 @@ void ELFWriter::OutputSectionsAndSectionTable() {
 
   // Now that we know where all of the sections will be emitted, set the e_shnum
   // entry in the ELF header.
-  OutputBuffer FHOut(TM, FileHeader);
+  OutputBuffer FHOut(FileHeader, is64Bit, isLittleEndian);
   FHOut.fixhalf(NumSections, ELFHeader_e_shnum_Offset);
 
   // Now that we know the offset in the file of the section table, update the
@@ -491,7 +493,7 @@ void ELFWriter::OutputSectionsAndSectionTable() {
   DataBuffer().swap(FileHeader);
 
   DataBuffer Table;
-  OutputBuffer TableOut(TM, Table);
+  OutputBuffer TableOut(Table, is64Bit, isLittleEndian);
 
   // Emit all of the section data and build the section table itself.
   while (!SectionList.empty()) {
index 29c070b3712eea3781c933e3f1c7b80441f757c7..64e11010b3c508246c6ab58d732f427804285d41 100644 (file)
@@ -53,6 +53,10 @@ namespace llvm {
     /// Target machine description.
     TargetMachine &TM;
 
+    /// is64Bit/isLittleEndian - This information is inferred from the target
+    /// machine directly, indicating what header values and flags to set.
+    bool is64Bit, isLittleEndian;
+
     /// Relocations - These are the relocations that the function needs, as
     /// emitted.
     std::vector<MachineRelocation> Relocations;
@@ -75,7 +79,10 @@ namespace llvm {
     std::vector<intptr_t> MBBLocations;
     
   public:
-    MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) {}
+    MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) {
+      is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
+      isLittleEndian = TM.getTargetData()->isLittleEndian();
+    }
 
     virtual void startFunction(MachineFunction &F);
     virtual bool finishFunction(MachineFunction &F);
@@ -230,7 +237,7 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
     unsigned Size = TM.getTargetData()->getTypeSize(Ty);
 
     MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty);
-    OutputBuffer SecDataOut(TM, Sec->SectionData);
+    OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
 
     CPLocations.push_back(Sec->SectionData.size());
     CPSections.push_back(Sec->Index);
@@ -261,7 +268,7 @@ void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) {
 
   MachOWriter::MachOSection *Sec = MOW.getJumpTableSection();
   unsigned TextSecIndex = MOW.getTextSection()->Index;
-  OutputBuffer SecDataOut(TM, Sec->SectionData);
+  OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
 
   for (unsigned i = 0, e = JT.size(); i != e; ++i) {
     // For each jump table, record its offset from the start of the section,
@@ -309,7 +316,7 @@ void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
   // Reserve space in the .bss section for this symbol while maintaining the
   // desired section alignment, which must be at least as much as required by
   // this symbol.
-  OutputBuffer SecDataOut(TM, Sec->SectionData);
+  OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
 
   if (Align) {
     uint64_t OrigSize = Sec->size;
@@ -451,7 +458,7 @@ void MachOWriter::EmitHeaderAndLoadCommands() {
   // Step #3: write the header to the file
   // Local alias to shortenify coming code.
   DataBuffer &FH = Header.HeaderData;
-  OutputBuffer FHOut(TM, FH);
+  OutputBuffer FHOut(FH, is64Bit, isLittleEndian);
 
   FHOut.outword(Header.magic);
   FHOut.outword(Header.cputype);
@@ -638,7 +645,7 @@ void MachOWriter::BufferSymbolAndStringTable() {
   
   // Write out a leading zero byte when emitting string table, for n_strx == 0
   // which means an empty string.
-  OutputBuffer StrTOut(TM, StrT);
+  OutputBuffer StrTOut(StrT, is64Bit, isLittleEndian);
   StrTOut.outbyte(0);
 
   // The order of the string table is:
@@ -656,7 +663,7 @@ void MachOWriter::BufferSymbolAndStringTable() {
     }
   }
 
-  OutputBuffer SymTOut(TM, SymT);
+  OutputBuffer SymTOut(SymT, is64Bit, isLittleEndian);
 
   for (std::vector<MachOSym>::iterator I = SymbolTable.begin(),
          E = SymbolTable.end(); I != E; ++I) {
index 5208060749af8ac889c2dec2977a6c71111df8bc..4d9ec4c94b5035c77907512b388cfd3393fdbe8c 100644 (file)
@@ -93,11 +93,11 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
                               isExtern, PPC_RELOC_VANILLA);
       ++From.nreloc;
 
-      OutputBuffer RelocOut(TM, From.RelocBuffer);
+      OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
       RelocOut.outword(VANILLA.r_address);
       RelocOut.outword(VANILLA.getPackedFields());
 
-      OutputBuffer SecOut(TM, From.SectionData);
+      OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
       SecOut.fixword(Addr, MR.getMachineCodeOffset());
       break;
     }
@@ -109,7 +109,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
       Addr <<= 2;
       Addr |= (From.SectionData[MR.getMachineCodeOffset()] << 24);
 
-      OutputBuffer SecOut(TM, From.SectionData);
+      OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
       SecOut.fixword(Addr, MR.getMachineCodeOffset());
       break;
     }
@@ -118,7 +118,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
       Addr -= MR.getMachineCodeOffset();
       Addr &= 0xFFFC;
 
-      OutputBuffer SecOut(TM, From.SectionData);
+      OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
       SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);
       break;
     }
@@ -131,7 +131,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
       ++From.nreloc;
       ++From.nreloc;
 
-      OutputBuffer RelocOut(TM, From.RelocBuffer);
+      OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
       RelocOut.outword(HA16.r_address);
       RelocOut.outword(HA16.getPackedFields());
       RelocOut.outword(PAIR.r_address);
@@ -139,7 +139,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
       printf("ha16: %x\n", (unsigned)Addr);
       Addr += 0x8000;
 
-      OutputBuffer SecOut(TM, From.SectionData);
+      OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
       SecOut.fixhalf(Addr >> 16, MR.getMachineCodeOffset() + 2);
       break;
     }
@@ -152,14 +152,14 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
       ++From.nreloc;
       ++From.nreloc;
 
-      OutputBuffer RelocOut(TM, From.RelocBuffer);
+      OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
       RelocOut.outword(LO16.r_address);
       RelocOut.outword(LO16.getPackedFields());
       RelocOut.outword(PAIR.r_address);
       RelocOut.outword(PAIR.getPackedFields());
       printf("lo16: %x\n", (unsigned)Addr);
 
-      OutputBuffer SecOut(TM, From.SectionData);
+      OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
       SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);
       break;
     }