From 3fe980b127a61608bd6d44c0939ba716ca21625c Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Fri, 15 Jan 2010 18:51:18 +0000 Subject: Hook up llc's -filetype=obj to use MCStreamer if an MCCodeEmitter is available. Remove most of old Mach-O Writer support, it has been replaced by MCMachOStreamer Further refactoring to completely remove MachOWriter and drive the object file writer with the AsmPrinter MCInst/MCSection logic is forthcoming. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93527 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachOWriter.h | 192 +++++++++------------------------------------- 1 file changed, 37 insertions(+), 155 deletions(-) (limited to 'lib/CodeGen/MachOWriter.h') diff --git a/lib/CodeGen/MachOWriter.h b/lib/CodeGen/MachOWriter.h index 9273f38548..2e7e67d2db 100644 --- a/lib/CodeGen/MachOWriter.h +++ b/lib/CodeGen/MachOWriter.h @@ -15,191 +15,73 @@ #define MACHOWRITER_H #include "llvm/CodeGen/MachineFunctionPass.h" -#include -#include +#include "llvm/Target/TargetMachine.h" namespace llvm { - class Constant; class GlobalVariable; class Mangler; - class MachineBasicBlock; - class MachineRelocation; - class MachOCodeEmitter; - struct MachODySymTab; - struct MachOHeader; - struct MachOSection; - struct MachOSym; - class TargetData; - class TargetMachine; - class MCAsmInfo; - class ObjectCodeEmitter; - class OutputBuffer; - class raw_ostream; - + class MCCodeEmitter; + class MCContext; + class MCStreamer; + /// MachOWriter - This class implements the common target-independent code for /// writing Mach-O files. Targets should derive a class from this to /// parameterize the output format. /// class MachOWriter : public MachineFunctionPass { - friend class MachOCodeEmitter; - public: static char ID; - ObjectCodeEmitter *getObjectCodeEmitter() { - return reinterpret_cast(MachOCE); - } - - MachOWriter(raw_ostream &O, TargetMachine &TM); - virtual ~MachOWriter(); - - virtual const char *getPassName() const { - return "Mach-O Writer"; - } - protected: /// Output stream to send the resultant object file to. /// - raw_ostream &O; + formatted_raw_ostream &O; /// Target machine description. /// TargetMachine &TM; - /// Mang - The object used to perform name mangling for this module. + /// Target Asm Printer information. /// - Mangler *Mang; - - /// MachOCE - The MachineCodeEmitter object that we are exposing to emit - /// machine code for functions to the .o file. - MachOCodeEmitter *MachOCE; - - /// is64Bit/isLittleEndian - This information is inferred from the target - /// machine directly, indicating what header values and flags to set. - bool is64Bit, isLittleEndian; - - // Target Asm Info const MCAsmInfo *MAI; - - /// Header - An instance of MachOHeader that we will update while we build - /// the file, and then emit during finalization. - MachOHeader Header; - + + /// MCCE - The MCCodeEmitter object that we are exposing to emit machine + /// code for functions to the .o file. + MCCodeEmitter *MCCE; + + /// OutContext - This is the context for the output file that we are + /// streaming. This owns all of the global MC-related objects for the + /// generated translation unit. + MCContext &OutContext; + + /// OutStreamer - This is the MCStreamer object for the file we are + /// generating. This contains the transient state for the current + /// translation unit that we are generating (such as the current section + /// etc). + MCStreamer &OutStreamer; + + /// Name-mangler for global names. + /// + Mangler *Mang; + /// doInitialization - Emit the file header and all of the global variables /// for the module to the Mach-O file. bool doInitialization(Module &M); - bool runOnMachineFunction(MachineFunction &MF); - /// doFinalization - Now that the module has been completely processed, emit /// the Mach-O file to 'O'. bool doFinalization(Module &M); - private: - - /// SectionList - This is the list of sections that we have emitted to the - /// file. Once the file has been completely built, the segment load command - /// SectionCommands are constructed from this info. - std::vector SectionList; - - /// SectionLookup - This is a mapping from section name to SectionList entry - std::map SectionLookup; - - /// GVSection - This is a mapping from a GlobalValue to a MachOSection, - /// to aid in emitting relocations. - std::map GVSection; - - /// GVOffset - This is a mapping from a GlobalValue to an offset from the - /// start of the section in which the GV resides, to aid in emitting - /// relocations. - std::map GVOffset; - - /// getSection - Return the section with the specified name, creating a new - /// section if one does not already exist. - MachOSection *getSection(const std::string &seg, const std::string §, - unsigned Flags = 0); - - /// getTextSection - Return text section with different flags for code/data - MachOSection *getTextSection(bool isCode = true); - - MachOSection *getDataSection() { - return getSection("__DATA", "__data"); + bool runOnMachineFunction(MachineFunction &MF); + + public: + explicit MachOWriter(formatted_raw_ostream &O, TargetMachine &TM, + const MCAsmInfo *T, MCCodeEmitter *MCE); + + virtual ~MachOWriter(); + + virtual const char *getPassName() const { + return "Mach-O Writer"; } - - MachOSection *getBSSSection(); - MachOSection *getConstSection(Constant *C); - MachOSection *getJumpTableSection(); - - /// MachOSymTab - This struct contains information about the offsets and - /// size of symbol table information. - /// segment. - struct MachOSymTab { - uint32_t cmd; // LC_SYMTAB - uint32_t cmdsize; // sizeof( MachOSymTab ) - uint32_t symoff; // symbol table offset - uint32_t nsyms; // number of symbol table entries - uint32_t stroff; // string table offset - uint32_t strsize; // string table size in bytes - - // Constants for the cmd field - // see - enum { LC_SYMTAB = 0x02 // link-edit stab symbol table info - }; - - MachOSymTab() : cmd(LC_SYMTAB), cmdsize(6 * sizeof(uint32_t)), symoff(0), - nsyms(0), stroff(0), strsize(0) { } - }; - - /// SymTab - The "stab" style symbol table information - MachOSymTab SymTab; - /// DySymTab - symbol table info for the dynamic link editor - MachODySymTab DySymTab; - - protected: - - /// SymbolTable - This is the list of symbols we have emitted to the file. - /// This actually gets rearranged before emission to the file (to put the - /// local symbols first in the list). - std::vector SymbolTable; - - /// SymT - A buffer to hold the symbol table before we write it out at the - /// appropriate location in the file. - std::vector SymT; - - /// StrT - A buffer to hold the string table before we write it out at the - /// appropriate location in the file. - std::vector StrT; - - /// PendingSyms - This is a list of externally defined symbols that we have - /// been asked to emit, but have not seen a reference to. When a reference - /// is seen, the symbol will move from this list to the SymbolTable. - std::vector PendingGlobals; - - /// DynamicSymbolTable - This is just a vector of indices into - /// SymbolTable to aid in emitting the DYSYMTAB load command. - std::vector DynamicSymbolTable; - - static void InitMem(const Constant *C, uintptr_t Offset, - const TargetData *TD, MachOSection* mos); - - private: - void AddSymbolToSection(MachOSection *MOS, GlobalVariable *GV); - void EmitGlobal(GlobalVariable *GV); - void EmitHeaderAndLoadCommands(); - void EmitSections(); - void EmitRelocations(); - void BufferSymbolAndStringTable(); - void CalculateRelocations(MachOSection &MOS); - - // GetJTRelocation - Get a relocation a new BB relocation based - // on target information. - MachineRelocation GetJTRelocation(unsigned Offset, - MachineBasicBlock *MBB) const; - - /// GetTargetRelocation - Returns the number of relocations. - unsigned GetTargetRelocation(MachineRelocation &MR, unsigned FromIdx, - unsigned ToAddr, unsigned ToIndex, - OutputBuffer &RelocOut, OutputBuffer &SecOut, - bool Scattered, bool Extern); }; } -- cgit v1.2.3