[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp MachineFunction.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.37 - 1.38 MachOWriter.cpp updated: 1.26 - 1.27 MachineFunction.cpp updated: 1.108 - 1.109 --- Log message: Generalize TargetData strings, to support more interesting forms of data. Patch by Scott Michel. --- Diffs of the changes: (+5 -4) ELFWriter.cpp |2 +- MachOWriter.cpp |4 ++-- MachineFunction.cpp |3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.37 llvm/lib/CodeGen/ELFWriter.cpp:1.38 --- llvm/lib/CodeGen/ELFWriter.cpp:1.37 Wed Feb 7 19:35:27 2007 +++ llvm/lib/CodeGen/ELFWriter.cpp Tue Feb 13 23:52:17 2007 @@ -255,7 +255,7 @@ } const Type *GVType = (const Type*)GV-getType(); - unsigned Align = TM.getTargetData()-getTypeAlignmentPref(GVType); + unsigned Align = TM.getTargetData()-getPrefTypeAlignment(GVType); unsigned Size = TM.getTargetData()-getTypeSize(GVType); // If this global has a zero initializer, it is part of the .bss or common Index: llvm/lib/CodeGen/MachOWriter.cpp diff -u llvm/lib/CodeGen/MachOWriter.cpp:1.26 llvm/lib/CodeGen/MachOWriter.cpp:1.27 --- llvm/lib/CodeGen/MachOWriter.cpp:1.26 Sat Feb 10 14:31:59 2007 +++ llvm/lib/CodeGen/MachOWriter.cppTue Feb 13 23:52:17 2007 @@ -147,7 +147,7 @@ // Align the output buffer to the appropriate alignment, power of 2. unsigned FnAlign = F-getAlignment(); - unsigned TDAlign = TD-getTypeAlignmentPref(F-getType()); + unsigned TDAlign = TD-getPrefTypeAlignment(F-getType()); unsigned Align = Log2_32(std::max(FnAlign, TDAlign)); assert(!(Align (Align-1)) Alignment is not a power of two!); @@ -332,7 +332,7 @@ unsigned Size = TM.getTargetData()-getTypeSize(Ty); unsigned Align = GV-getAlignment(); if (Align == 0) -Align = TM.getTargetData()-getTypeAlignmentPref(Ty); +Align = TM.getTargetData()-getPrefTypeAlignment(Ty); MachOSym Sym(GV, Mang-getValueName(GV), Sec-Index, TM); Index: llvm/lib/CodeGen/MachineFunction.cpp diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.108 llvm/lib/CodeGen/MachineFunction.cpp:1.109 --- llvm/lib/CodeGen/MachineFunction.cpp:1.108 Sat Jan 20 16:35:55 2007 +++ llvm/lib/CodeGen/MachineFunction.cppTue Feb 13 23:52:17 2007 @@ -13,6 +13,7 @@ // //===--===// +#include llvm/DerivedTypes.h #include llvm/CodeGen/MachineFunctionPass.h #include llvm/CodeGen/MachineInstr.h #include llvm/CodeGen/SSARegMap.h @@ -123,7 +124,7 @@ const TargetData TD = *TM.getTargetData(); bool IsPic = TM.getRelocationModel() == Reloc::PIC_; unsigned EntrySize = IsPic ? 4 : TD.getPointerSize(); - unsigned Alignment = IsPic ? TD.getIntABIAlignment() + unsigned Alignment = IsPic ? TD.getABITypeAlignment(Type::Int32Ty) : TD.getPointerABIAlignment(); JumpTableInfo = new MachineJumpTableInfo(EntrySize, Alignment); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.36 - 1.37 MachOWriter.cpp updated: 1.23 - 1.24 --- Log message: Add function to create a file writer. --- Diffs of the changes: (+28 -3) ELFWriter.cpp | 16 +++- MachOWriter.cpp | 15 +-- 2 files changed, 28 insertions(+), 3 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.36 llvm/lib/CodeGen/ELFWriter.cpp:1.37 --- llvm/lib/CodeGen/ELFWriter.cpp:1.36 Fri Jan 26 20:55:44 2007 +++ llvm/lib/CodeGen/ELFWriter.cpp Wed Feb 7 19:35:27 2007 @@ -31,18 +31,32 @@ // //===--===// -#include llvm/CodeGen/ELFWriter.h +#include ELFWriter.h #include llvm/Module.h +#include llvm/PassManager.h +#include llvm/CodeGen/FileWriters.h #include llvm/CodeGen/MachineCodeEmitter.h #include llvm/CodeGen/MachineConstantPool.h +#include llvm/CodeGen/MachineFunctionPass.h #include llvm/Target/TargetData.h #include llvm/Target/TargetELFWriterInfo.h #include llvm/Target/TargetMachine.h #include llvm/Support/Mangler.h #include llvm/Support/OutputBuffer.h #include llvm/Support/Streams.h +#include list using namespace llvm; +/// AddELFWriter - Concrete function to add the ELF writer to the function pass +/// manager. +MachineCodeEmitter *llvm::AddELFWriter(FunctionPassManager FPM, + std::ostream O, + TargetMachine TM) { + ELFWriter *EW = new ELFWriter(O, TM); + FPM.add(EW); + return EW-getMachineCodeEmitter(); +} + //===--===// // ELFCodeEmitter Implementation //===--===// Index: llvm/lib/CodeGen/MachOWriter.cpp diff -u llvm/lib/CodeGen/MachOWriter.cpp:1.23 llvm/lib/CodeGen/MachOWriter.cpp:1.24 --- llvm/lib/CodeGen/MachOWriter.cpp:1.23 Tue Feb 6 23:47:16 2007 +++ llvm/lib/CodeGen/MachOWriter.cppWed Feb 7 19:35:27 2007 @@ -22,13 +22,15 @@ // //===--===// +#include MachOWriter.h #include llvm/Constants.h #include llvm/DerivedTypes.h #include llvm/Module.h +#include llvm/PassManager.h +#include llvm/CodeGen/FileWriters.h #include llvm/CodeGen/MachineCodeEmitter.h #include llvm/CodeGen/MachineConstantPool.h #include llvm/CodeGen/MachineJumpTableInfo.h -#include llvm/CodeGen/MachOWriter.h #include llvm/ExecutionEngine/ExecutionEngine.h #include llvm/Target/TargetAsmInfo.h #include llvm/Target/TargetJITInfo.h @@ -37,9 +39,18 @@ #include llvm/Support/OutputBuffer.h #include llvm/Support/Streams.h #include algorithm - using namespace llvm; +/// AddMachOWriter - Concrete function to add the Mach-O writer to the function +/// pass manager. +MachineCodeEmitter *llvm::AddMachOWriter(FunctionPassManager FPM, + std::ostream O, + TargetMachine TM) { + MachOWriter *MOW = new MachOWriter(O, TM); + FPM.add(MOW); + return MOW-getMachineCodeEmitter(); +} + //===--===// // MachOCodeEmitter Implementation //===--===// ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp MachineFunction.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.34 - 1.35 MachOWriter.cpp updated: 1.16 - 1.17 MachineFunction.cpp updated: 1.107 - 1.108 --- Log message: Teach TargetData to handle 'preferred' alignment for each target, and use these alignment amounts to align scalars when we can. Patch by Scott Michel! --- Diffs of the changes: (+4 -3) ELFWriter.cpp |2 +- MachOWriter.cpp |2 +- MachineFunction.cpp |3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.34 llvm/lib/CodeGen/ELFWriter.cpp:1.35 --- llvm/lib/CodeGen/ELFWriter.cpp:1.34 Wed Jan 17 19:23:11 2007 +++ llvm/lib/CodeGen/ELFWriter.cpp Sat Jan 20 16:35:55 2007 @@ -241,7 +241,7 @@ } const Type *GVType = (const Type*)GV-getType(); - unsigned Align = TM.getTargetData()-getTypeAlignment(GVType); + unsigned Align = TM.getTargetData()-getTypeAlignmentPref(GVType); unsigned Size = TM.getTargetData()-getTypeSize(GVType); // If this global has a zero initializer, it is part of the .bss or common Index: llvm/lib/CodeGen/MachOWriter.cpp diff -u llvm/lib/CodeGen/MachOWriter.cpp:1.16 llvm/lib/CodeGen/MachOWriter.cpp:1.17 --- llvm/lib/CodeGen/MachOWriter.cpp:1.16 Wed Jan 17 19:23:11 2007 +++ llvm/lib/CodeGen/MachOWriter.cppSat Jan 20 16:35:55 2007 @@ -309,7 +309,7 @@ unsigned Size = TM.getTargetData()-getTypeSize(Ty); unsigned Align = GV-getAlignment(); if (Align == 0) -Align = TM.getTargetData()-getTypeAlignment(Ty); +Align = TM.getTargetData()-getTypeAlignmentPref(Ty); MachOSym Sym(GV, Mang-getValueName(GV), Sec-Index, TM); Index: llvm/lib/CodeGen/MachineFunction.cpp diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.107 llvm/lib/CodeGen/MachineFunction.cpp:1.108 --- llvm/lib/CodeGen/MachineFunction.cpp:1.107 Thu Dec 21 20:04:05 2006 +++ llvm/lib/CodeGen/MachineFunction.cppSat Jan 20 16:35:55 2007 @@ -123,7 +123,8 @@ const TargetData TD = *TM.getTargetData(); bool IsPic = TM.getRelocationModel() == Reloc::PIC_; unsigned EntrySize = IsPic ? 4 : TD.getPointerSize(); - unsigned Alignment = IsPic ? TD.getIntAlignment() : TD.getPointerAlignment(); + unsigned Alignment = IsPic ? TD.getIntABIAlignment() + : TD.getPointerABIAlignment(); JumpTableInfo = new MachineJumpTableInfo(EntrySize, Alignment); BasicBlocks.Parent = this; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.31 - 1.32 MachOWriter.cpp updated: 1.13 - 1.14 --- Log message: Revert patch. --- Diffs of the changes: (+126 -156) ELFWriter.cpp | 116 --- MachOWriter.cpp | 166 +--- 2 files changed, 126 insertions(+), 156 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.31 llvm/lib/CodeGen/ELFWriter.cpp:1.32 --- llvm/lib/CodeGen/ELFWriter.cpp:1.31 Tue Jan 16 21:49:21 2007 +++ llvm/lib/CodeGen/ELFWriter.cpp Wed Jan 17 03:06:13 2007 @@ -37,7 +37,6 @@ #include llvm/CodeGen/MachineConstantPool.h #include llvm/Target/TargetData.h #include llvm/Target/TargetMachine.h -#include llvm/Target/TargetObjInfo.h #include llvm/Support/Mangler.h #include llvm/Support/Streams.h using namespace llvm; @@ -54,20 +53,8 @@ ELFWriter::ELFSection *ES; // Section to write to. std::vectorunsigned char *OutBuffer; size_t FnStart; - -/// Target machine description. -/// -TargetMachine TM; - -/// Target object writer info. -/// -const TargetObjInfo *TOI; public: -ELFCodeEmitter(ELFWriter ew, TargetMachine tm) - : EW(ew), OutBuffer(0), TM(tm) { - // Create the target object info object for this target. - TOI = TM.getTargetObjInfo(); -} +ELFCodeEmitter(ELFWriter ew) : EW(ew), OutBuffer(0) {} void startFunction(MachineFunction F); bool finishFunction(MachineFunction F); @@ -126,7 +113,7 @@ // 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. - TOI-align(*OutBuffer, Align); + ELFWriter::align(*OutBuffer, Align); FnStart = OutBuffer-size(); } @@ -178,11 +165,8 @@ isLittleEndian = TM.getTargetData()-isLittleEndian(); // Create the machine code emitter object for this target. - MCE = new ELFCodeEmitter(*this, TM); + MCE = new ELFCodeEmitter(*this); NumSections = 0; - - // Create the target object info object for this target. - TOI = TM.getTargetObjInfo(); } ELFWriter::~ELFWriter() { @@ -197,36 +181,36 @@ // Local alias to shortenify coming code. std::vectorunsigned char FH = FileHeader; - TOI-outbyte(FH, 0x7F); // EI_MAG0 - TOI-outbyte(FH, 'E'); // EI_MAG1 - TOI-outbyte(FH, 'L'); // EI_MAG2 - TOI-outbyte(FH, 'F'); // EI_MAG3 - TOI-outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS - TOI-outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA - TOI-outbyte(FH, 1);// EI_VERSION - FH.resize(16); // EI_PAD up to 16 bytes. + outbyte(FH, 0x7F); // EI_MAG0 + outbyte(FH, 'E'); // EI_MAG1 + outbyte(FH, 'L'); // EI_MAG2 + outbyte(FH, 'F'); // EI_MAG3 + outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS + outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA + outbyte(FH, 1);// EI_VERSION + FH.resize(16); // EI_PAD up to 16 bytes. // This should change for shared objects. - TOI-outhalf(FH, 1); // e_type = ET_REL - TOI-outhalf(FH, e_machine); // e_machine = whatever the target wants - TOI-outword(FH, 1); // e_version = 1 - TOI-outaddr(FH, 0); // e_entry = 0 - no entry point in .o file - TOI-outaddr(FH, 0); // e_phoff = 0 - no program header for .o + outhalf(FH, 1); // e_type = ET_REL + outhalf(FH, e_machine); // e_machine = whatever the target wants + outword(FH, 1); // e_version = 1 + outaddr(FH, 0); // e_entry = 0 - no entry point in .o file + outaddr(FH, 0); // e_phoff = 0 - no program header for .o ELFHeader_e_shoff_Offset = FH.size(); - TOI-outaddr(FH, 0); // e_shoff - TOI-outword(FH, e_flags); // e_flags = whatever the target wants + outaddr(FH, 0); // e_shoff + outword(FH, e_flags); // e_flags = whatever the target wants - TOI-outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size - TOI-outhalf(FH, 0); // e_phentsize = prog header entry size - TOI-outhalf(FH, 0); // e_phnum = # prog header entries=0 - TOI-outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size + outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size + outhalf(FH, 0); // e_phentsize = prog header entry size + outhalf(FH, 0); // e_phnum = # prog header entries = 0 + outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size ELFHeader_e_shnum_Offset = FH.size(); - TOI-outhalf(FH, 0); // e_shnum = # of section header ents + outhalf(FH, 0);
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.32 - 1.33 MachOWriter.cpp updated: 1.14 - 1.15 --- Log message: Changed to use the OutputBuffer instead of the methods in MachO and ELF writers. --- Diffs of the changes: (+148 -126) ELFWriter.cpp | 112 -- MachOWriter.cpp | 162 ++-- 2 files changed, 148 insertions(+), 126 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.32 llvm/lib/CodeGen/ELFWriter.cpp:1.33 --- llvm/lib/CodeGen/ELFWriter.cpp:1.32 Wed Jan 17 03:06:13 2007 +++ llvm/lib/CodeGen/ELFWriter.cpp Wed Jan 17 16:22:31 2007 @@ -38,6 +38,7 @@ #include llvm/Target/TargetData.h #include llvm/Target/TargetMachine.h #include llvm/Support/Mangler.h +#include llvm/Support/OutputBuffer.h #include llvm/Support/Streams.h using namespace llvm; @@ -50,11 +51,12 @@ /// functions to the ELF file. class ELFCodeEmitter : public MachineCodeEmitter { ELFWriter EW; +TargetMachine TM; ELFWriter::ELFSection *ES; // Section to write to. std::vectorunsigned char *OutBuffer; size_t FnStart; public: -ELFCodeEmitter(ELFWriter ew) : EW(ew), OutBuffer(0) {} +ELFCodeEmitter(ELFWriter ew) : EW(ew), TM(EW.TM), OutBuffer(0) {} void startFunction(MachineFunction F); bool finishFunction(MachineFunction F); @@ -103,8 +105,8 @@ ELFWriter::ELFSection::SHF_EXECINSTR | ELFWriter::ELFSection::SHF_ALLOC); OutBuffer = ES-SectionData; - cerr FIXME: This code needs to be updated for changes in the - CodeEmitter interfaces. In particular, this should set + cerr FIXME: This code needs to be updated for changes in the +CodeEmitter interfaces. In particular, this should set BufferBegin/BufferEnd/CurBufferPtr, not deal with OutBuffer!; abort(); @@ -113,8 +115,8 @@ // 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. - ELFWriter::align(*OutBuffer, Align); - + OutputBuffer OB(TM, *OutBuffer); + OB.align(Align); FnStart = OutBuffer-size(); } @@ -145,7 +147,7 @@ FnSym.SetType(ELFWriter::ELFSym::STT_FUNC); FnSym.SectionIdx = ES-SectionIdx; -FnSym.Value = FnStart; // Value = Offset from start of Section. + FnSym.Value = FnStart; // Value = Offset from start of Section. FnSym.Size = OutBuffer-size()-FnStart; // Finally, add it to the symtab. @@ -180,37 +182,38 @@ // Local alias to shortenify coming code. std::vectorunsigned char FH = FileHeader; + OutputBuffer FHOut(TM, FH); - outbyte(FH, 0x7F); // EI_MAG0 - outbyte(FH, 'E'); // EI_MAG1 - outbyte(FH, 'L'); // EI_MAG2 - outbyte(FH, 'F'); // EI_MAG3 - outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS - outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA - outbyte(FH, 1);// EI_VERSION + FHOut.outbyte(0x7F); // EI_MAG0 + FHOut.outbyte('E'); // EI_MAG1 + FHOut.outbyte('L'); // EI_MAG2 + FHOut.outbyte('F'); // EI_MAG3 + FHOut.outbyte(is64Bit ? 2 : 1); // EI_CLASS + FHOut.outbyte(isLittleEndian ? 1 : 2); // EI_DATA + FHOut.outbyte(1);// EI_VERSION FH.resize(16); // EI_PAD up to 16 bytes. // This should change for shared objects. - outhalf(FH, 1); // e_type = ET_REL - outhalf(FH, e_machine); // e_machine = whatever the target wants - outword(FH, 1); // e_version = 1 - outaddr(FH, 0); // e_entry = 0 - no entry point in .o file - outaddr(FH, 0); // e_phoff = 0 - no program header for .o + FHOut.outhalf(1); // e_type = ET_REL + FHOut.outhalf(e_machine); // e_machine = whatever the target wants + FHOut.outword(1); // e_version = 1 + FHOut.outaddr(0); // e_entry = 0 - no entry point in .o file + FHOut.outaddr(0); // e_phoff = 0 - no program header for .o ELFHeader_e_shoff_Offset = FH.size(); - outaddr(FH, 0); // e_shoff - outword(FH, e_flags); // e_flags = whatever the target wants + FHOut.outaddr(0); // e_shoff + FHOut.outword(e_flags); // e_flags = whatever the target wants - outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size - outhalf(FH, 0); // e_phentsize = prog header entry size - outhalf(FH, 0); // e_phnum = # prog header entries = 0 - outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size + FHOut.outhalf(is64Bit ? 64 : 52); // e_ehsize = ELF header size + FHOut.outhalf(0); // e_phentsize = prog header
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp
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::vectorunsigned 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.cppWed 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::vectorMachineRelocation Relocations; @@ -75,7 +79,10 @@ std::vectorintptr_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
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.30 - 1.31 MachOWriter.cpp updated: 1.12 - 1.13 --- Log message: Use the methods in the TargetObjInfo object instead of internal methods. --- Diffs of the changes: (+156 -126) ELFWriter.cpp | 116 ++- MachOWriter.cpp | 166 ++-- 2 files changed, 156 insertions(+), 126 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.30 llvm/lib/CodeGen/ELFWriter.cpp:1.31 --- llvm/lib/CodeGen/ELFWriter.cpp:1.30 Wed Dec 6 19:30:31 2006 +++ llvm/lib/CodeGen/ELFWriter.cpp Tue Jan 16 21:49:21 2007 @@ -37,6 +37,7 @@ #include llvm/CodeGen/MachineConstantPool.h #include llvm/Target/TargetData.h #include llvm/Target/TargetMachine.h +#include llvm/Target/TargetObjInfo.h #include llvm/Support/Mangler.h #include llvm/Support/Streams.h using namespace llvm; @@ -53,8 +54,20 @@ ELFWriter::ELFSection *ES; // Section to write to. std::vectorunsigned char *OutBuffer; size_t FnStart; + +/// Target machine description. +/// +TargetMachine TM; + +/// Target object writer info. +/// +const TargetObjInfo *TOI; public: -ELFCodeEmitter(ELFWriter ew) : EW(ew), OutBuffer(0) {} +ELFCodeEmitter(ELFWriter ew, TargetMachine tm) + : EW(ew), OutBuffer(0), TM(tm) { + // Create the target object info object for this target. + TOI = TM.getTargetObjInfo(); +} void startFunction(MachineFunction F); bool finishFunction(MachineFunction F); @@ -113,7 +126,7 @@ // 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. - ELFWriter::align(*OutBuffer, Align); + TOI-align(*OutBuffer, Align); FnStart = OutBuffer-size(); } @@ -165,8 +178,11 @@ isLittleEndian = TM.getTargetData()-isLittleEndian(); // Create the machine code emitter object for this target. - MCE = new ELFCodeEmitter(*this); + MCE = new ELFCodeEmitter(*this, TM); NumSections = 0; + + // Create the target object info object for this target. + TOI = TM.getTargetObjInfo(); } ELFWriter::~ELFWriter() { @@ -181,36 +197,36 @@ // Local alias to shortenify coming code. std::vectorunsigned char FH = FileHeader; - outbyte(FH, 0x7F); // EI_MAG0 - outbyte(FH, 'E'); // EI_MAG1 - outbyte(FH, 'L'); // EI_MAG2 - outbyte(FH, 'F'); // EI_MAG3 - outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS - outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA - outbyte(FH, 1);// EI_VERSION - FH.resize(16); // EI_PAD up to 16 bytes. + TOI-outbyte(FH, 0x7F); // EI_MAG0 + TOI-outbyte(FH, 'E'); // EI_MAG1 + TOI-outbyte(FH, 'L'); // EI_MAG2 + TOI-outbyte(FH, 'F'); // EI_MAG3 + TOI-outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS + TOI-outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA + TOI-outbyte(FH, 1);// EI_VERSION + FH.resize(16); // EI_PAD up to 16 bytes. // This should change for shared objects. - outhalf(FH, 1); // e_type = ET_REL - outhalf(FH, e_machine); // e_machine = whatever the target wants - outword(FH, 1); // e_version = 1 - outaddr(FH, 0); // e_entry = 0 - no entry point in .o file - outaddr(FH, 0); // e_phoff = 0 - no program header for .o + TOI-outhalf(FH, 1); // e_type = ET_REL + TOI-outhalf(FH, e_machine); // e_machine = whatever the target wants + TOI-outword(FH, 1); // e_version = 1 + TOI-outaddr(FH, 0); // e_entry = 0 - no entry point in .o file + TOI-outaddr(FH, 0); // e_phoff = 0 - no program header for .o ELFHeader_e_shoff_Offset = FH.size(); - outaddr(FH, 0); // e_shoff - outword(FH, e_flags); // e_flags = whatever the target wants + TOI-outaddr(FH, 0); // e_shoff + TOI-outword(FH, e_flags); // e_flags = whatever the target wants - outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size - outhalf(FH, 0); // e_phentsize = prog header entry size - outhalf(FH, 0); // e_phnum = # prog header entries = 0 - outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size + TOI-outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size + TOI-outhalf(FH, 0); // e_phentsize = prog header entry size + TOI-outhalf(FH, 0); // e_phnum = # prog header entries=0 + TOI-outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size ELFHeader_e_shnum_Offset = FH.size(); - outhalf(FH, 0); // e_shnum =
[llvm-commits] CVS: llvm/lib/CodeGen/ELFWriter.cpp MachOWriter.cpp
Changes in directory llvm/lib/CodeGen: ELFWriter.cpp updated: 1.27 - 1.28 MachOWriter.cpp updated: 1.6 - 1.7 --- Log message: Match MachineCodeEmitter changes. --- Diffs of the changes: (+2 -2) ELFWriter.cpp |2 +- MachOWriter.cpp |2 +- 2 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/lib/CodeGen/ELFWriter.cpp diff -u llvm/lib/CodeGen/ELFWriter.cpp:1.27 llvm/lib/CodeGen/ELFWriter.cpp:1.28 --- llvm/lib/CodeGen/ELFWriter.cpp:1.27 Thu Nov 2 14:25:49 2006 +++ llvm/lib/CodeGen/ELFWriter.cpp Thu Nov 16 14:04:04 2006 @@ -81,7 +81,7 @@ } /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE! -void startFunctionStub(unsigned StubSize) { +void startFunctionStub(unsigned StubSize, unsigned Alignment = 1) { assert(0 JIT specific function called!); abort(); } Index: llvm/lib/CodeGen/MachOWriter.cpp diff -u llvm/lib/CodeGen/MachOWriter.cpp:1.6 llvm/lib/CodeGen/MachOWriter.cpp:1.7 --- llvm/lib/CodeGen/MachOWriter.cpp:1.6Sun Sep 10 18:03:44 2006 +++ llvm/lib/CodeGen/MachOWriter.cppThu Nov 16 14:04:04 2006 @@ -100,7 +100,7 @@ } /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE! -void startFunctionStub(unsigned StubSize) { +void startFunctionStub(unsigned StubSize, unsigned Alignment = 1) { assert(0 JIT specific function called!); abort(); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits