/// runOnMachineFunction - This emits the frame section, autos section and /// assembly for each instruction. Also takes care of function begin debug /// directive and file begin debug directive (if required) for the function. /// bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) { this->MF = &MF; // This calls the base class function required to be called at beginning // of runOnMachineFunction. SetupMachineFunction(MF); // Get the mangled name. const Function *F = MF.getFunction(); CurrentFnName = Mang->getMangledName(F); // Emit the function frame (args and temps). EmitFunctionFrame(MF); DbgInfo.BeginFunction(MF); // Emit the autos section of function. EmitAutos(CurrentFnName); // Now emit the instructions of function in its code section. const MCSection *fCodeSection = getObjFileLowering().getSectionForFunction(CurrentFnName); // Start the Code Section. O << "\n"; OutStreamer.SwitchSection(fCodeSection); // Emit the frame address of the function at the beginning of code. O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n"; O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n"; // Emit function start label. O << CurrentFnName << ":\n"; DebugLoc CurDL; O << "\n"; // Print out code for the function. for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { // Print a label for the basic block. if (I != MF.begin()) { printBasicBlockLabel(I, true); O << '\n'; } // Print a basic block. for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); II != E; ++II) { // Emit the line directive if source line changed. const DebugLoc DL = II->getDebugLoc(); if (!DL.isUnknown() && DL != CurDL) { DbgInfo.ChangeDebugLoc(MF, DL); CurDL = DL; } // Print the assembly for the instruction. printMachineInstruction(II); } } // Emit function end debug directives. DbgInfo.EndFunction(MF); return false; // we didn't modify anything. }
/// runOnMachineFunction - This uses the printInstruction() /// method to print assembly for each instruction. /// bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) { this->MF = &MF; // This calls the base class function required to be called at beginning // of runOnMachineFunction. SetupMachineFunction(MF); // Get the mangled name. const Function *F = MF.getFunction(); CurrentFnName = Mang->getValueName(F); // Emit the function variables. EmitFunctionFrame(MF); // Emit function begin debug directives DbgInfo.EmitFunctBeginDI(F); EmitAutos(CurrentFnName); const char *codeSection = PAN::getCodeSectionName(CurrentFnName).c_str(); const Section *fCodeSection = TAI->getNamedSection(codeSection, SectionFlags::Code); O << "\n"; // Start the Code Section. SwitchToSection (fCodeSection); // Emit the frame address of the function at the beginning of code. O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n"; O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n"; // Emit function start label. O << CurrentFnName << ":\n"; // For emitting line directives, we need to keep track of the current // source line. When it changes then only emit the line directive. unsigned CurLine = 0; O << "\n"; // Print out code for the function. for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { // Print a label for the basic block. if (I != MF.begin()) { printBasicBlockLabel(I, true); O << '\n'; } for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); II != E; ++II) { // Emit the line directive if source line changed. const DebugLoc DL = II->getDebugLoc(); if (!DL.isUnknown()) { unsigned line = MF.getDebugLocTuple(DL).Line; if (line != CurLine) { O << "\t.line " << line << "\n"; CurLine = line; } } // Print the assembly for the instruction. printMachineInstruction(II); } } // Emit function end debug directives. DbgInfo.EmitFunctEndDI(F, CurLine); return false; // we didn't modify anything. }