#ifndef LLVM_CODEGEN_MACHOWRITER_H
#define LLVM_CODEGEN_MACHOWRITER_H
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineRelocation.h"
class Mangler;
class MachineCodeEmitter;
class MachOCodeEmitter;
+ class OutputBuffer;
/// MachOSym - This struct contains information about each symbol that is
/// added to logical symbol table for the module. This is eventually
MachineCodeEmitter &getMachineCodeEmitter() const {
return *(MachineCodeEmitter*)MCE;
}
+ virtual ~MachOWriter();
- ~MachOWriter();
+ virtual const char *getPassName() const {
+ return "Mach-O Writer";
+ }
typedef std::vector<unsigned char> DataBuffer;
-
protected:
MachOWriter(std::ostream &O, TargetMachine &TM);
initprot(VM_PROT_ALL), nsects(0), flags(0) { }
};
- /// MachORelocation - This struct contains information about each relocation
- /// that needs to be emitted to the file.
- /// see <mach-o/reloc.h>
- struct MachORelocation {
- uint32_t r_address; // offset in the section to what is being relocated
- uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index
- bool r_pcrel; // was relocated pc-relative already
- uint8_t r_length; // length = 2 ^ r_length
- bool r_extern; //
- uint8_t r_type; // if not 0, machine-specific relocation type.
-
- uint32_t getPackedFields() {
- return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) |
- (r_extern << 4) | (r_type & 15);
- }
-
- MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len,
- bool ext, uint8_t type) : r_address(addr),
- r_symbolnum(index), r_pcrel(pcrel), r_length(len), r_extern(ext),
- r_type(type) {}
- };
-
/// MachOSection - This struct contains information about each section in a
/// particular segment that is emitted to the file. This is eventually
/// turned into the SectionCommand in the load command for a particlar
MachOSection *getDataSection() {
return getSection("__DATA", "__data");
}
- MachOSection *getConstSection(const Type *Ty) {
- // FIXME: support cstring literals and pointer literal
+ MachOSection *getConstSection(Constant *C) {
+ const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+ if (CVA && CVA->isCString())
+ return getSection("__TEXT", "__cstring",
+ MachOSection::S_CSTRING_LITERALS);
+
+ const Type *Ty = C->getType();
if (Ty->isPrimitiveType() || Ty->isInteger()) {
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
switch(Size) {
MachineBasicBlock *MBB) const {
return TM.getMachOWriterInfo()->GetJTRelocation(Offset, MBB);
}
- virtual void GetTargetRelocation(MachineRelocation &MR, MachOSection &From,
- MachOSection &To) = 0;
+
+ /// GetTargetRelocation - Returns the number of relocations.
+ unsigned GetTargetRelocation(MachineRelocation &MR,
+ unsigned FromIdx,
+ unsigned ToAddr,
+ unsigned ToIndex,
+ OutputBuffer &RelocOut,
+ OutputBuffer &SecOut,
+ bool Scattered) {
+ return TM.getMachOWriterInfo()->GetTargetRelocation(MR, FromIdx, ToAddr,
+ ToIndex, RelocOut,
+ SecOut, Scattered);
+ }
};
}