[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp

Bill Wendling isanbard at gmail.com
Wed Jan 17 17:23:30 PST 2007



Changes in directory llvm/lib/CodeGen:

ELFWriter.cpp updated: 1.33 -> 1.34
MachOWriter.cpp updated: 1.15 -> 1.16
---
Log message:

Have the OutputBuffer take the is64Bit and isLittleEndian booleans.


---
Diffs of the changes:  (+23 -14)

 ELFWriter.cpp   |   16 +++++++++-------
 MachOWriter.cpp |   21 ++++++++++++++-------
 2 files changed, 23 insertions(+), 14 deletions(-)


Index: llvm/lib/CodeGen/ELFWriter.cpp
diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.33 llvm/lib/CodeGen/ELFWriter.cpp:1.34
--- llvm/lib/CodeGen/ELFWriter.cpp:1.33	Wed Jan 17 16:22:31 2007
+++ llvm/lib/CodeGen/ELFWriter.cpp	Wed Jan 17 19:23:11 2007
@@ -115,7 +115,9 @@
 
   // 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 @@
 
   // 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 @@
   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 @@
   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 @@
 
   // 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 @@
 
   // 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 @@
   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: llvm/lib/CodeGen/MachOWriter.cpp
diff -u llvm/lib/CodeGen/MachOWriter.cpp:1.15 llvm/lib/CodeGen/MachOWriter.cpp:1.16
--- llvm/lib/CodeGen/MachOWriter.cpp:1.15	Wed Jan 17 16:22:31 2007
+++ llvm/lib/CodeGen/MachOWriter.cpp	Wed Jan 17 19:23:11 2007
@@ -53,6 +53,10 @@
     /// 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 @@
     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 @@
     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 @@
 
   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 @@
   // 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 @@
   // 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 @@
   
   // 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 @@
     }
   }
 
-  OutputBuffer SymTOut(TM, SymT);
+  OutputBuffer SymTOut(SymT, is64Bit, isLittleEndian);
 
   for (std::vector<MachOSym>::iterator I = SymbolTable.begin(),
          E = SymbolTable.end(); I != E; ++I) {






More information about the llvm-commits mailing list