2008-05-13 09:02:57 +00:00
|
|
|
//===-- PIC16AsmPrinter.cpp - PIC16 LLVM assembly writer ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to PIC16 assembly language.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
#include "PIC16AsmPrinter.h"
|
|
|
|
#include "PIC16TargetAsmInfo.h"
|
2009-02-18 23:12:06 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-11-19 11:00:54 +00:00
|
|
|
#include "llvm/Function.h"
|
2008-05-13 09:02:57 +00:00
|
|
|
#include "llvm/Module.h"
|
2009-02-18 23:12:06 +00:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2009-07-14 20:18:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2008-05-13 09:02:57 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2009-02-18 23:12:06 +00:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-04-02 18:03:10 +00:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2008-05-13 09:02:57 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#include "PIC16GenAsmWriter.inc"
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|
|
|
printInstruction(MI);
|
|
|
|
return true;
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 06:49:55 +00:00
|
|
|
/// 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.
|
2008-05-13 09:02:57 +00:00
|
|
|
///
|
2008-11-19 11:00:54 +00:00
|
|
|
bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
2009-02-24 08:30:20 +00:00
|
|
|
this->MF = &MF;
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
// This calls the base class function required to be called at beginning
|
|
|
|
// of runOnMachineFunction.
|
2008-05-13 09:02:57 +00:00
|
|
|
SetupMachineFunction(MF);
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
// Get the mangled name.
|
|
|
|
const Function *F = MF.getFunction();
|
2009-07-14 18:17:16 +00:00
|
|
|
CurrentFnName = Mang->getMangledName(F);
|
2008-05-13 09:02:57 +00:00
|
|
|
|
2009-06-11 06:49:55 +00:00
|
|
|
// Emit the function frame (args and temps).
|
2009-05-28 18:24:11 +00:00
|
|
|
EmitFunctionFrame(MF);
|
|
|
|
|
2009-06-16 09:45:18 +00:00
|
|
|
DbgInfo.BeginFunction(MF);
|
2009-05-28 18:24:11 +00:00
|
|
|
|
2009-06-11 06:49:55 +00:00
|
|
|
// Emit the autos section of function.
|
2009-05-28 18:24:11 +00:00
|
|
|
EmitAutos(CurrentFnName);
|
2009-06-11 06:49:55 +00:00
|
|
|
|
|
|
|
// Now emit the instructions of function in its code section.
|
2009-05-10 05:23:47 +00:00
|
|
|
const char *codeSection = PAN::getCodeSectionName(CurrentFnName).c_str();
|
|
|
|
|
|
|
|
const Section *fCodeSection = TAI->getNamedSection(codeSection,
|
|
|
|
SectionFlags::Code);
|
|
|
|
// Start the Code Section.
|
2009-06-11 06:49:55 +00:00
|
|
|
O << "\n";
|
2009-07-21 16:44:47 +00:00
|
|
|
SwitchToSection(fCodeSection);
|
2009-04-08 06:24:04 +00:00
|
|
|
|
|
|
|
// Emit the frame address of the function at the beginning of code.
|
2009-05-10 05:23:47 +00:00
|
|
|
O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
|
|
|
|
O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
|
2009-04-08 05:38:48 +00:00
|
|
|
|
2009-05-10 05:23:47 +00:00
|
|
|
// Emit function start label.
|
|
|
|
O << CurrentFnName << ":\n";
|
2008-05-13 09:02:57 +00:00
|
|
|
|
2009-06-16 09:45:18 +00:00
|
|
|
DebugLoc CurDL;
|
2009-05-28 18:24:11 +00:00
|
|
|
O << "\n";
|
2008-05-13 09:02:57 +00:00
|
|
|
// Print out code for the function.
|
|
|
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
|
|
|
I != E; ++I) {
|
2009-06-11 06:49:55 +00:00
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
// Print a label for the basic block.
|
|
|
|
if (I != MF.begin()) {
|
|
|
|
printBasicBlockLabel(I, true);
|
|
|
|
O << '\n';
|
|
|
|
}
|
2009-04-08 06:24:04 +00:00
|
|
|
|
2009-06-11 06:49:55 +00:00
|
|
|
// Print a basic block.
|
2008-05-13 09:02:57 +00:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
|
|
|
II != E; ++II) {
|
2009-06-11 06:49:55 +00:00
|
|
|
|
2009-04-08 06:24:04 +00:00
|
|
|
// Emit the line directive if source line changed.
|
|
|
|
const DebugLoc DL = II->getDebugLoc();
|
2009-06-16 09:45:18 +00:00
|
|
|
if (!DL.isUnknown() && DL != CurDL) {
|
|
|
|
DbgInfo.ChangeDebugLoc(MF, DL);
|
|
|
|
CurDL = DL;
|
2009-04-08 06:24:04 +00:00
|
|
|
}
|
2009-05-11 06:01:38 +00:00
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
// Print the assembly for the instruction.
|
2009-04-08 06:24:04 +00:00
|
|
|
printMachineInstruction(II);
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-28 18:24:11 +00:00
|
|
|
|
|
|
|
// Emit function end debug directives.
|
2009-06-16 09:45:18 +00:00
|
|
|
DbgInfo.EndFunction(MF);
|
2009-06-11 06:49:55 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
return false; // we didn't modify anything.
|
|
|
|
}
|
2008-05-13 09:02:57 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
/// createPIC16CodePrinterPass - Returns a pass that prints the PIC16
|
|
|
|
/// assembly code for a MachineFunction to the given output stream,
|
|
|
|
/// using the given target machine description. This should work
|
|
|
|
/// regardless of whether the function is in SSA form.
|
|
|
|
///
|
2009-07-14 20:18:05 +00:00
|
|
|
FunctionPass *llvm::createPIC16CodePrinterPass(formatted_raw_ostream &o,
|
2009-07-15 23:17:20 +00:00
|
|
|
TargetMachine &tm,
|
2009-04-29 00:15:41 +00:00
|
|
|
bool verbose) {
|
2009-07-01 01:48:54 +00:00
|
|
|
return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-05-11 06:01:38 +00:00
|
|
|
|
|
|
|
// printOperand - print operand of insn.
|
2008-11-19 11:00:54 +00:00
|
|
|
void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
|
2008-05-13 09:02:57 +00:00
|
|
|
const MachineOperand &MO = MI->getOperand(opNum);
|
|
|
|
|
2008-05-14 11:31:39 +00:00
|
|
|
switch (MO.getType()) {
|
2008-05-13 09:02:57 +00:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
|
2008-11-19 11:00:54 +00:00
|
|
|
O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
|
2008-05-13 09:02:57 +00:00
|
|
|
else
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("not implemented");
|
2009-07-11 20:10:48 +00:00
|
|
|
return;
|
2008-05-14 11:31:39 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
2008-05-13 09:02:57 +00:00
|
|
|
O << (int)MO.getImm();
|
|
|
|
return;
|
2008-05-14 11:31:39 +00:00
|
|
|
|
2009-04-20 16:59:35 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2009-07-14 18:17:16 +00:00
|
|
|
O << Mang->getMangledName(MO.getGlobal());
|
2008-05-13 09:02:57 +00:00
|
|
|
break;
|
2009-04-20 16:59:35 +00:00
|
|
|
}
|
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
2009-05-11 06:01:38 +00:00
|
|
|
const char *Sname = MO.getSymbolName();
|
|
|
|
|
|
|
|
// If its a libcall name, record it to decls section.
|
|
|
|
if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
|
2009-05-13 15:13:17 +00:00
|
|
|
LibcallDecls.push_back(Sname);
|
2009-05-11 06:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
O << Sname;
|
2008-05-13 09:02:57 +00:00
|
|
|
break;
|
2009-04-20 16:59:35 +00:00
|
|
|
}
|
2009-01-13 19:18:47 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
printBasicBlockLabel(MO.getMBB());
|
|
|
|
return;
|
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable(" Operand type not supported.");
|
2008-11-19 11:00:54 +00:00
|
|
|
}
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 06:55:48 +00:00
|
|
|
/// printCCOperand - Print the cond code operand.
|
|
|
|
///
|
2009-01-13 19:18:47 +00:00
|
|
|
void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
|
|
|
|
int CC = (int)MI->getOperand(opNum).getImm();
|
|
|
|
O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
|
|
|
|
}
|
|
|
|
|
2009-06-11 06:55:48 +00:00
|
|
|
/// printLibcallDecls - print the extern declarations for compiler
|
|
|
|
/// intrinsics.
|
|
|
|
///
|
2009-05-13 15:13:17 +00:00
|
|
|
void PIC16AsmPrinter::printLibcallDecls(void) {
|
2009-05-11 06:01:38 +00:00
|
|
|
// If no libcalls used, return.
|
2009-05-13 15:13:17 +00:00
|
|
|
if (LibcallDecls.empty()) return;
|
2009-05-11 06:01:38 +00:00
|
|
|
|
2009-05-12 06:52:41 +00:00
|
|
|
O << TAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
|
2009-05-11 06:01:38 +00:00
|
|
|
// Remove duplicate entries.
|
2009-05-13 15:13:17 +00:00
|
|
|
LibcallDecls.sort();
|
|
|
|
LibcallDecls.unique();
|
|
|
|
for (std::list<const char*>::const_iterator I = LibcallDecls.begin();
|
|
|
|
I != LibcallDecls.end(); I++) {
|
2009-05-11 06:01:38 +00:00
|
|
|
O << TAI->getExternDirective() << *I << "\n";
|
2009-05-11 08:52:04 +00:00
|
|
|
O << TAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n";
|
|
|
|
O << TAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n";
|
2009-05-11 06:01:38 +00:00
|
|
|
}
|
2009-05-12 06:52:41 +00:00
|
|
|
O << TAI->getCommentString() << "External decls for libcalls - END." <<"\n";
|
2009-05-11 06:01:38 +00:00
|
|
|
}
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2009-06-11 06:55:48 +00:00
|
|
|
/// doInitialization - Perfrom Module level initializations here.
|
|
|
|
/// One task that we do here is to sectionize all global variables.
|
|
|
|
/// The MemSelOptimizer pass depends on the sectionizing.
|
|
|
|
///
|
2009-07-21 16:44:47 +00:00
|
|
|
bool PIC16AsmPrinter::doInitialization(Module &M) {
|
2008-11-19 11:00:54 +00:00
|
|
|
bool Result = AsmPrinter::doInitialization(M);
|
2009-05-28 18:24:11 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
// FIXME:: This is temporary solution to generate the include file.
|
|
|
|
// The processor should be passed to llc as in input and the header file
|
|
|
|
// should be generated accordingly.
|
2009-05-28 18:24:11 +00:00
|
|
|
O << "\n\t#include P16F1937.INC\n";
|
2009-04-02 18:03:10 +00:00
|
|
|
|
2009-05-12 17:07:27 +00:00
|
|
|
// Set the section names for all globals.
|
|
|
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
I->setSection(TAI->SectionForGlobal(I)->getName());
|
|
|
|
}
|
|
|
|
|
2009-06-16 09:45:18 +00:00
|
|
|
DbgInfo.BeginModule(M);
|
2009-05-13 15:13:17 +00:00
|
|
|
EmitFunctionDecls(M);
|
|
|
|
EmitUndefinedVars(M);
|
|
|
|
EmitDefinedVars(M);
|
2009-05-12 17:07:27 +00:00
|
|
|
EmitIData(M);
|
|
|
|
EmitUData(M);
|
2008-11-19 11:00:54 +00:00
|
|
|
EmitRomData(M);
|
|
|
|
return Result;
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 06:55:48 +00:00
|
|
|
/// Emit extern decls for functions imported from other modules, and emit
|
|
|
|
/// global declarations for function defined in this module and which are
|
|
|
|
/// available to other modules.
|
|
|
|
///
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
|
2008-11-26 10:53:50 +00:00
|
|
|
// Emit declarations for external functions.
|
2009-06-13 17:35:54 +00:00
|
|
|
O <<"\n"<<TAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
|
2008-11-26 10:53:50 +00:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
|
2009-07-23 02:11:04 +00:00
|
|
|
if (I->isIntrinsic())
|
|
|
|
continue;
|
|
|
|
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string Name = Mang->getMangledName(I);
|
2009-05-10 05:23:47 +00:00
|
|
|
if (Name.compare("@abort") == 0)
|
2008-11-26 10:53:50 +00:00
|
|
|
continue;
|
2009-04-14 02:49:52 +00:00
|
|
|
|
2009-07-21 16:44:47 +00:00
|
|
|
if (!I->isDeclaration() && !I->hasExternalLinkage())
|
2009-05-10 16:18:39 +00:00
|
|
|
continue;
|
2009-05-10 05:23:47 +00:00
|
|
|
|
|
|
|
const char *directive = I->isDeclaration() ? TAI->getExternDirective() :
|
|
|
|
TAI->getGlobalDirective();
|
|
|
|
|
|
|
|
O << directive << Name << "\n";
|
|
|
|
O << directive << PAN::getRetvalLabel(Name) << "\n";
|
|
|
|
O << directive << PAN::getArgsLabel(Name) << "\n";
|
2008-11-26 10:53:50 +00:00
|
|
|
}
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2009-05-13 15:13:17 +00:00
|
|
|
O << TAI->getCommentString() << "Function Declarations - END." <<"\n";
|
|
|
|
}
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2009-05-13 15:13:17 +00:00
|
|
|
// Emit variables imported from other Modules.
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
|
2009-05-13 15:13:17 +00:00
|
|
|
std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDecls->Items;
|
2009-07-21 16:44:47 +00:00
|
|
|
if (!Items.size()) return;
|
2009-02-10 04:20:26 +00:00
|
|
|
|
2009-05-13 15:13:17 +00:00
|
|
|
O << "\n" << TAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
O << TAI->getExternDirective() << Mang->getMangledName(Items[j]) << "\n";
|
2009-05-13 15:13:17 +00:00
|
|
|
}
|
|
|
|
O << TAI->getCommentString() << "Imported Variables - END" << "\n";
|
|
|
|
}
|
2009-05-10 05:23:47 +00:00
|
|
|
|
2009-05-13 15:13:17 +00:00
|
|
|
// Emit variables defined in this module and are available to other modules.
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
|
2009-05-13 15:13:17 +00:00
|
|
|
std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDefs->Items;
|
2009-07-21 16:44:47 +00:00
|
|
|
if (!Items.size()) return;
|
2009-05-13 15:13:17 +00:00
|
|
|
|
2009-07-21 17:20:18 +00:00
|
|
|
O << "\n" << TAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
|
2009-05-13 15:13:17 +00:00
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
O << TAI->getGlobalDirective() << Mang->getMangledName(Items[j]) << "\n";
|
2008-11-26 10:53:50 +00:00
|
|
|
}
|
2009-05-13 15:13:17 +00:00
|
|
|
O << TAI->getCommentString() << "Exported Variables - END" << "\n";
|
2008-11-26 10:53:50 +00:00
|
|
|
}
|
2009-02-10 04:20:26 +00:00
|
|
|
|
2009-05-13 15:13:17 +00:00
|
|
|
// Emit initialized data placed in ROM.
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitRomData(Module &M) {
|
2009-07-06 10:18:37 +00:00
|
|
|
// Print ROM Data section.
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<PIC16Section*> &ROSections = PTAI->ROSections;
|
2009-07-06 10:18:37 +00:00
|
|
|
for (unsigned i = 0; i < ROSections.size(); i++) {
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<const GlobalVariable*> &Items = ROSections[i]->Items;
|
|
|
|
if (!Items.size()) continue;
|
2009-07-06 10:18:37 +00:00
|
|
|
O << "\n";
|
|
|
|
SwitchToSection(PTAI->ROSections[i]->S_);
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
O << Mang->getMangledName(Items[j]);
|
2009-07-06 10:18:37 +00:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
int AddrSpace = Items[j]->getType()->getAddressSpace();
|
|
|
|
EmitGlobalConstant(C, AddrSpace);
|
|
|
|
}
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
bool PIC16AsmPrinter::doFinalization(Module &M) {
|
2009-05-13 15:13:17 +00:00
|
|
|
printLibcallDecls();
|
2009-06-09 15:31:19 +00:00
|
|
|
EmitRemainingAutos();
|
2009-06-16 09:45:18 +00:00
|
|
|
DbgInfo.EndModule(M);
|
2009-05-28 18:24:11 +00:00
|
|
|
O << "\n\t" << "END\n";
|
2009-07-21 18:38:57 +00:00
|
|
|
return AsmPrinter::doFinalization(M);
|
2008-11-19 11:00:54 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 18:24:11 +00:00
|
|
|
void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
|
2008-11-19 11:00:54 +00:00
|
|
|
const Function *F = MF.getFunction();
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string FuncName = Mang->getMangledName(F);
|
2008-11-19 11:00:54 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
// Emit the data section name.
|
|
|
|
O << "\n";
|
2009-05-10 05:23:47 +00:00
|
|
|
const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2009-05-10 05:23:47 +00:00
|
|
|
const Section *fPDataSection = TAI->getNamedSection(SectionName,
|
2009-04-20 16:59:35 +00:00
|
|
|
SectionFlags::Writeable);
|
|
|
|
SwitchToSection(fPDataSection);
|
2008-11-26 10:53:50 +00:00
|
|
|
|
2009-04-02 17:42:00 +00:00
|
|
|
// Emit function frame label
|
2009-05-10 05:23:47 +00:00
|
|
|
O << PAN::getFrameLabel(CurrentFnName) << ":\n";
|
2009-04-02 17:42:00 +00:00
|
|
|
|
2008-11-26 10:53:50 +00:00
|
|
|
const Type *RetType = F->getReturnType();
|
2009-01-13 19:18:47 +00:00
|
|
|
unsigned RetSize = 0;
|
|
|
|
if (RetType->getTypeID() != Type::VoidTyID)
|
2009-05-09 07:06:46 +00:00
|
|
|
RetSize = TD->getTypeAllocSize(RetType);
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2009-04-02 17:42:00 +00:00
|
|
|
//Emit function return value space
|
2009-05-10 05:23:47 +00:00
|
|
|
// FIXME: Do not emit RetvalLable when retsize is zero. To do this
|
|
|
|
// we will need to avoid printing a global directive for Retval label
|
|
|
|
// in emitExternandGloblas.
|
2009-04-02 17:42:00 +00:00
|
|
|
if(RetSize > 0)
|
2009-05-10 05:23:47 +00:00
|
|
|
O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
|
2009-04-02 17:42:00 +00:00
|
|
|
else
|
2009-05-10 05:23:47 +00:00
|
|
|
O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
|
2009-04-02 17:42:00 +00:00
|
|
|
|
|
|
|
// Emit variable to hold the space for function arguments
|
|
|
|
unsigned ArgSize = 0;
|
|
|
|
for (Function::const_arg_iterator argi = F->arg_begin(),
|
|
|
|
arge = F->arg_end(); argi != arge ; ++argi) {
|
|
|
|
const Type *Ty = argi->getType();
|
2009-05-09 07:06:46 +00:00
|
|
|
ArgSize += TD->getTypeAllocSize(Ty);
|
2009-04-02 17:42:00 +00:00
|
|
|
}
|
2009-05-10 05:23:47 +00:00
|
|
|
|
|
|
|
O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
|
2009-04-02 17:42:00 +00:00
|
|
|
|
2009-04-14 02:49:52 +00:00
|
|
|
// Emit temporary space
|
|
|
|
int TempSize = PTLI->GetTmpSize();
|
2009-07-21 16:44:47 +00:00
|
|
|
if (TempSize > 0)
|
|
|
|
O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize << '\n';
|
2009-05-06 08:02:01 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitIData(Module &M) {
|
2009-02-10 04:20:26 +00:00
|
|
|
|
2009-05-12 17:07:27 +00:00
|
|
|
// Print all IDATA sections.
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<PIC16Section*> &IDATASections = PTAI->IDATASections;
|
2009-05-06 08:02:01 +00:00
|
|
|
for (unsigned i = 0; i < IDATASections.size(); i++) {
|
2009-05-12 17:07:27 +00:00
|
|
|
O << "\n";
|
2009-07-06 18:07:06 +00:00
|
|
|
if (IDATASections[i]->S_->getName().find("llvm.") != std::string::npos)
|
|
|
|
continue;
|
2009-05-06 08:02:01 +00:00
|
|
|
SwitchToSection(IDATASections[i]->S_);
|
|
|
|
std::vector<const GlobalVariable*> Items = IDATASections[i]->Items;
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string Name = Mang->getMangledName(Items[j]);
|
2009-05-06 08:02:01 +00:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
int AddrSpace = Items[j]->getType()->getAddressSpace();
|
|
|
|
O << Name;
|
|
|
|
EmitGlobalConstant(C, AddrSpace);
|
|
|
|
}
|
|
|
|
}
|
2009-05-12 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitUData(Module &M) {
|
2009-05-12 17:07:27 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-05-06 08:02:01 +00:00
|
|
|
|
2009-05-12 17:07:27 +00:00
|
|
|
// Print all BSS sections.
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<PIC16Section*> &BSSSections = PTAI->BSSSections;
|
2009-05-06 08:02:01 +00:00
|
|
|
for (unsigned i = 0; i < BSSSections.size(); i++) {
|
2009-05-12 17:07:27 +00:00
|
|
|
O << "\n";
|
2009-05-06 08:02:01 +00:00
|
|
|
SwitchToSection(BSSSections[i]->S_);
|
|
|
|
std::vector<const GlobalVariable*> Items = BSSSections[i]->Items;
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string Name = Mang->getMangledName(Items[j]);
|
2009-05-06 08:02:01 +00:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
const Type *Ty = C->getType();
|
2009-05-09 07:06:46 +00:00
|
|
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
2009-05-06 08:02:01 +00:00
|
|
|
|
2009-07-21 16:44:47 +00:00
|
|
|
O << Name << " RES " << Size << "\n";
|
2009-05-06 08:02:01 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-19 11:00:54 +00:00
|
|
|
}
|
2009-05-06 08:02:01 +00:00
|
|
|
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitAutos(std::string FunctName) {
|
2009-05-12 17:07:27 +00:00
|
|
|
// Section names for all globals are already set.
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
|
2009-05-28 18:24:11 +00:00
|
|
|
// Now print Autos section for this function.
|
|
|
|
std::string SectionName = PAN::getAutosSectionName(FunctName);
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<PIC16Section*> &AutosSections = PTAI->AutosSections;
|
2009-05-12 17:07:27 +00:00
|
|
|
for (unsigned i = 0; i < AutosSections.size(); i++) {
|
|
|
|
O << "\n";
|
2009-05-28 18:24:11 +00:00
|
|
|
if (AutosSections[i]->S_->getName() == SectionName) {
|
2009-06-09 15:31:19 +00:00
|
|
|
// Set the printing status to true
|
|
|
|
AutosSections[i]->setPrintedStatus(true);
|
2009-05-28 18:24:11 +00:00
|
|
|
SwitchToSection(AutosSections[i]->S_);
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items;
|
2009-05-28 18:24:11 +00:00
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string VarName = Mang->getMangledName(Items[j]);
|
2009-05-28 18:24:11 +00:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
const Type *Ty = C->getType();
|
|
|
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
|
|
|
// Emit memory reserve directive.
|
|
|
|
O << VarName << " RES " << Size << "\n";
|
2009-05-22 13:58:45 +00:00
|
|
|
}
|
2009-05-28 18:24:11 +00:00
|
|
|
break;
|
2009-05-22 13:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-09 15:31:19 +00:00
|
|
|
// Print autos that were not printed during the code printing of functions.
|
|
|
|
// As the functions might themselves would have got deleted by the optimizer.
|
2009-07-21 16:44:47 +00:00
|
|
|
void PIC16AsmPrinter::EmitRemainingAutos() {
|
2009-06-09 15:31:19 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
|
|
|
|
// Now print Autos section for this function.
|
|
|
|
std::vector <PIC16Section *>AutosSections = PTAI->AutosSections;
|
|
|
|
for (unsigned i = 0; i < AutosSections.size(); i++) {
|
|
|
|
|
|
|
|
// if the section is already printed then don't print again
|
|
|
|
if (AutosSections[i]->isPrinted())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Set status as printed
|
|
|
|
AutosSections[i]->setPrintedStatus(true);
|
|
|
|
|
|
|
|
O << "\n";
|
|
|
|
SwitchToSection(AutosSections[i]->S_);
|
2009-07-21 16:44:47 +00:00
|
|
|
const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items;
|
2009-06-09 15:31:19 +00:00
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string VarName = Mang->getMangledName(Items[j]);
|
2009-06-09 15:31:19 +00:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
const Type *Ty = C->getType();
|
|
|
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
|
|
|
// Emit memory reserve directive.
|
|
|
|
O << VarName << " RES " << Size << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|