mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
Have the OutputBuffer take the is64Bit and isLittleEndian booleans.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33316 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b266ccd0f4
commit
c904a5b925
@ -14,6 +14,7 @@
|
|||||||
#ifndef LLVM_SUPPORT_OUTPUTBUFFER_H
|
#ifndef LLVM_SUPPORT_OUTPUTBUFFER_H
|
||||||
#define LLVM_SUPPORT_OUTPUTBUFFER_H
|
#define LLVM_SUPPORT_OUTPUTBUFFER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -26,11 +27,9 @@ namespace llvm {
|
|||||||
/// machine directly, indicating what header values and flags to set.
|
/// machine directly, indicating what header values and flags to set.
|
||||||
bool is64Bit, isLittleEndian;
|
bool is64Bit, isLittleEndian;
|
||||||
public:
|
public:
|
||||||
OutputBuffer(const TargetMachine& TM,
|
OutputBuffer(std::vector<unsigned char> &Out,
|
||||||
std::vector<unsigned char> &Out) : Output(Out) {
|
bool is64bit, bool le)
|
||||||
is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
|
: Output(Out), is64Bit(is64bit), isLittleEndian(le) {}
|
||||||
isLittleEndian = TM.getTargetData()->isLittleEndian();
|
|
||||||
}
|
|
||||||
|
|
||||||
// align - Emit padding into the file until the current output position is
|
// align - Emit padding into the file until the current output position is
|
||||||
// aligned to the specified power of two boundary.
|
// aligned to the specified power of two boundary.
|
||||||
@ -107,7 +106,7 @@ namespace llvm {
|
|||||||
else
|
else
|
||||||
outxword(X);
|
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_copy = S.length() < Length ? S.length() : Length;
|
||||||
unsigned len_to_fill = S.length() < Length ? Length - S.length() : 0;
|
unsigned len_to_fill = S.length() < Length ? Length - S.length() : 0;
|
||||||
|
|
||||||
|
@ -115,7 +115,9 @@ void ELFCodeEmitter::startFunction(MachineFunction &F) {
|
|||||||
|
|
||||||
// Add padding zeros to the end of the buffer to make sure that the
|
// 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.
|
// 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);
|
OB.align(Align);
|
||||||
FnStart = OutBuffer->size();
|
FnStart = OutBuffer->size();
|
||||||
}
|
}
|
||||||
@ -182,7 +184,7 @@ bool ELFWriter::doInitialization(Module &M) {
|
|||||||
|
|
||||||
// Local alias to shortenify coming code.
|
// Local alias to shortenify coming code.
|
||||||
std::vector<unsigned char> &FH = FileHeader;
|
std::vector<unsigned char> &FH = FileHeader;
|
||||||
OutputBuffer FHOut(TM, FH);
|
OutputBuffer FHOut(FH, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
FHOut.outbyte(0x7F); // EI_MAG0
|
FHOut.outbyte(0x7F); // EI_MAG0
|
||||||
FHOut.outbyte('E'); // EI_MAG1
|
FHOut.outbyte('E'); // EI_MAG1
|
||||||
@ -353,7 +355,7 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
StrTab.Align = 1;
|
StrTab.Align = 1;
|
||||||
|
|
||||||
DataBuffer &StrTabBuf = StrTab.SectionData;
|
DataBuffer &StrTabBuf = StrTab.SectionData;
|
||||||
OutputBuffer StrTabOut(TM, StrTabBuf);
|
OutputBuffer StrTabOut(StrTabBuf, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
// Set the zero'th symbol to a null byte, as required.
|
// Set the zero'th symbol to a null byte, as required.
|
||||||
StrTabOut.outbyte(0);
|
StrTabOut.outbyte(0);
|
||||||
@ -389,7 +391,7 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
SymTab.Info = FirstNonLocalSymbol; // First non-STB_LOCAL symbol.
|
SymTab.Info = FirstNonLocalSymbol; // First non-STB_LOCAL symbol.
|
||||||
SymTab.EntSize = 16; // Size of each symtab entry. FIXME: wrong for ELF64
|
SymTab.EntSize = 16; // Size of each symtab entry. FIXME: wrong for ELF64
|
||||||
DataBuffer &SymTabBuf = SymTab.SectionData;
|
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.
|
if (!is64Bit) { // 32-bit and 64-bit formats are shuffled a bit.
|
||||||
for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
|
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
|
// Now that we know which section number is the .shstrtab section, update the
|
||||||
// e_shstrndx entry in the ELF header.
|
// e_shstrndx entry in the ELF header.
|
||||||
OutputBuffer FHOut(TM, FileHeader);
|
OutputBuffer FHOut(FileHeader, is64Bit, isLittleEndian);
|
||||||
FHOut.fixhalf(SHStrTab.SectionIdx, ELFHeader_e_shstrndx_Offset);
|
FHOut.fixhalf(SHStrTab.SectionIdx, ELFHeader_e_shstrndx_Offset);
|
||||||
|
|
||||||
// Set the NameIdx of each section in the string table and emit the bytes for
|
// 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
|
// Now that we know where all of the sections will be emitted, set the e_shnum
|
||||||
// entry in the ELF header.
|
// entry in the ELF header.
|
||||||
OutputBuffer FHOut(TM, FileHeader);
|
OutputBuffer FHOut(FileHeader, is64Bit, isLittleEndian);
|
||||||
FHOut.fixhalf(NumSections, ELFHeader_e_shnum_Offset);
|
FHOut.fixhalf(NumSections, ELFHeader_e_shnum_Offset);
|
||||||
|
|
||||||
// Now that we know the offset in the file of the section table, update the
|
// 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().swap(FileHeader);
|
||||||
|
|
||||||
DataBuffer Table;
|
DataBuffer Table;
|
||||||
OutputBuffer TableOut(TM, Table);
|
OutputBuffer TableOut(Table, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
// Emit all of the section data and build the section table itself.
|
// Emit all of the section data and build the section table itself.
|
||||||
while (!SectionList.empty()) {
|
while (!SectionList.empty()) {
|
||||||
|
@ -53,6 +53,10 @@ namespace llvm {
|
|||||||
/// Target machine description.
|
/// Target machine description.
|
||||||
TargetMachine &TM;
|
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
|
/// Relocations - These are the relocations that the function needs, as
|
||||||
/// emitted.
|
/// emitted.
|
||||||
std::vector<MachineRelocation> Relocations;
|
std::vector<MachineRelocation> Relocations;
|
||||||
@ -75,7 +79,10 @@ namespace llvm {
|
|||||||
std::vector<intptr_t> MBBLocations;
|
std::vector<intptr_t> MBBLocations;
|
||||||
|
|
||||||
public:
|
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 void startFunction(MachineFunction &F);
|
||||||
virtual bool finishFunction(MachineFunction &F);
|
virtual bool finishFunction(MachineFunction &F);
|
||||||
@ -230,7 +237,7 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
|||||||
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
||||||
|
|
||||||
MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty);
|
MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty);
|
||||||
OutputBuffer SecDataOut(TM, Sec->SectionData);
|
OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
CPLocations.push_back(Sec->SectionData.size());
|
CPLocations.push_back(Sec->SectionData.size());
|
||||||
CPSections.push_back(Sec->Index);
|
CPSections.push_back(Sec->Index);
|
||||||
@ -261,7 +268,7 @@ void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) {
|
|||||||
|
|
||||||
MachOWriter::MachOSection *Sec = MOW.getJumpTableSection();
|
MachOWriter::MachOSection *Sec = MOW.getJumpTableSection();
|
||||||
unsigned TextSecIndex = MOW.getTextSection()->Index;
|
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 (unsigned i = 0, e = JT.size(); i != e; ++i) {
|
||||||
// For each jump table, record its offset from the start of the section,
|
// 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
|
// 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
|
// desired section alignment, which must be at least as much as required by
|
||||||
// this symbol.
|
// this symbol.
|
||||||
OutputBuffer SecDataOut(TM, Sec->SectionData);
|
OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
if (Align) {
|
if (Align) {
|
||||||
uint64_t OrigSize = Sec->size;
|
uint64_t OrigSize = Sec->size;
|
||||||
@ -451,7 +458,7 @@ void MachOWriter::EmitHeaderAndLoadCommands() {
|
|||||||
// Step #3: write the header to the file
|
// Step #3: write the header to the file
|
||||||
// Local alias to shortenify coming code.
|
// Local alias to shortenify coming code.
|
||||||
DataBuffer &FH = Header.HeaderData;
|
DataBuffer &FH = Header.HeaderData;
|
||||||
OutputBuffer FHOut(TM, FH);
|
OutputBuffer FHOut(FH, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
FHOut.outword(Header.magic);
|
FHOut.outword(Header.magic);
|
||||||
FHOut.outword(Header.cputype);
|
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
|
// Write out a leading zero byte when emitting string table, for n_strx == 0
|
||||||
// which means an empty string.
|
// which means an empty string.
|
||||||
OutputBuffer StrTOut(TM, StrT);
|
OutputBuffer StrTOut(StrT, is64Bit, isLittleEndian);
|
||||||
StrTOut.outbyte(0);
|
StrTOut.outbyte(0);
|
||||||
|
|
||||||
// The order of the string table is:
|
// 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(),
|
for (std::vector<MachOSym>::iterator I = SymbolTable.begin(),
|
||||||
E = SymbolTable.end(); I != E; ++I) {
|
E = SymbolTable.end(); I != E; ++I) {
|
||||||
|
@ -93,11 +93,11 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
isExtern, PPC_RELOC_VANILLA);
|
isExtern, PPC_RELOC_VANILLA);
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
|
|
||||||
OutputBuffer RelocOut(TM, From.RelocBuffer);
|
OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
|
||||||
RelocOut.outword(VANILLA.r_address);
|
RelocOut.outword(VANILLA.r_address);
|
||||||
RelocOut.outword(VANILLA.getPackedFields());
|
RelocOut.outword(VANILLA.getPackedFields());
|
||||||
|
|
||||||
OutputBuffer SecOut(TM, From.SectionData);
|
OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
|
||||||
SecOut.fixword(Addr, MR.getMachineCodeOffset());
|
SecOut.fixword(Addr, MR.getMachineCodeOffset());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
Addr <<= 2;
|
Addr <<= 2;
|
||||||
Addr |= (From.SectionData[MR.getMachineCodeOffset()] << 24);
|
Addr |= (From.SectionData[MR.getMachineCodeOffset()] << 24);
|
||||||
|
|
||||||
OutputBuffer SecOut(TM, From.SectionData);
|
OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
|
||||||
SecOut.fixword(Addr, MR.getMachineCodeOffset());
|
SecOut.fixword(Addr, MR.getMachineCodeOffset());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
Addr -= MR.getMachineCodeOffset();
|
Addr -= MR.getMachineCodeOffset();
|
||||||
Addr &= 0xFFFC;
|
Addr &= 0xFFFC;
|
||||||
|
|
||||||
OutputBuffer SecOut(TM, From.SectionData);
|
OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
|
||||||
SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);
|
SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
|
|
||||||
OutputBuffer RelocOut(TM, From.RelocBuffer);
|
OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
|
||||||
RelocOut.outword(HA16.r_address);
|
RelocOut.outword(HA16.r_address);
|
||||||
RelocOut.outword(HA16.getPackedFields());
|
RelocOut.outword(HA16.getPackedFields());
|
||||||
RelocOut.outword(PAIR.r_address);
|
RelocOut.outword(PAIR.r_address);
|
||||||
@ -139,7 +139,7 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
printf("ha16: %x\n", (unsigned)Addr);
|
printf("ha16: %x\n", (unsigned)Addr);
|
||||||
Addr += 0x8000;
|
Addr += 0x8000;
|
||||||
|
|
||||||
OutputBuffer SecOut(TM, From.SectionData);
|
OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
|
||||||
SecOut.fixhalf(Addr >> 16, MR.getMachineCodeOffset() + 2);
|
SecOut.fixhalf(Addr >> 16, MR.getMachineCodeOffset() + 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -152,14 +152,14 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
|
|
||||||
OutputBuffer RelocOut(TM, From.RelocBuffer);
|
OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
|
||||||
RelocOut.outword(LO16.r_address);
|
RelocOut.outword(LO16.r_address);
|
||||||
RelocOut.outword(LO16.getPackedFields());
|
RelocOut.outword(LO16.getPackedFields());
|
||||||
RelocOut.outword(PAIR.r_address);
|
RelocOut.outword(PAIR.r_address);
|
||||||
RelocOut.outword(PAIR.getPackedFields());
|
RelocOut.outword(PAIR.getPackedFields());
|
||||||
printf("lo16: %x\n", (unsigned)Addr);
|
printf("lo16: %x\n", (unsigned)Addr);
|
||||||
|
|
||||||
OutputBuffer SecOut(TM, From.SectionData);
|
OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
|
||||||
SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);
|
SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user