-/// finishFunction - This callback is invoked after the function is completely
-/// finished.
-bool MachOCodeEmitter::finishFunction(MachineFunction &MF) {
- // Get the Mach-O Section that this function belongs in.
- MachOWriter::MachOSection *MOS = MOW.getTextSection();
-
- // Get a symbol for the function to add to the symbol table
- // FIXME: it seems like we should call something like AddSymbolToSection
- // in startFunction rather than changing the section size and symbol n_value
- // here.
- const GlobalValue *FuncV = MF.getFunction();
- MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TM);
- FnSym.n_value = MOS->size;
- MOS->size = CurBufferPtr - BufferBegin;
-
- // Emit constant pool to appropriate section(s)
- emitConstantPool(MF.getConstantPool());
-
- // Emit jump tables to appropriate section
- emitJumpTables(MF.getJumpTableInfo());
-
- // If we have emitted any relocations to function-specific objects such as
- // basic blocks, constant pools entries, or jump tables, record their
- // addresses now so that we can rewrite them with the correct addresses
- // later.
- for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
- MachineRelocation &MR = Relocations[i];
- intptr_t Addr;
-
- if (MR.isBasicBlock()) {
- Addr = getMachineBasicBlockAddress(MR.getBasicBlock());
- MR.setConstantVal(MOS->Index);
- MR.setResultPointer((void*)Addr);
- } else if (MR.isJumpTableIndex()) {
- Addr = getJumpTableEntryAddress(MR.getJumpTableIndex());
- MR.setConstantVal(MOW.getJumpTableSection()->Index);
- MR.setResultPointer((void*)Addr);
- } else if (MR.isConstantPoolIndex()) {
- Addr = getConstantPoolEntryAddress(MR.getConstantPoolIndex());
- MR.setConstantVal(CPSections[MR.getConstantPoolIndex()]);
- MR.setResultPointer((void*)Addr);
- } else if (MR.isGlobalValue()) {
- // FIXME: This should be a set or something that uniques
- MOW.PendingGlobals.push_back(MR.getGlobalValue());
- } else {
- assert(0 && "Unhandled relocation type");
- }
- MOS->Relocations.push_back(MR);
- }
- Relocations.clear();
-
- // Finally, add it to the symtab.
- MOW.SymbolTable.push_back(FnSym);