2008-05-13 17:02:57 +08: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 19:00:54 +08:00
|
|
|
#include "PIC16AsmPrinter.h"
|
|
|
|
#include "PIC16TargetAsmInfo.h"
|
2009-02-19 07:12:06 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-11-19 19:00:54 +08:00
|
|
|
#include "llvm/Function.h"
|
2008-05-13 17:02:57 +08:00
|
|
|
#include "llvm/Module.h"
|
2009-02-19 07:12:06 +08:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2008-05-13 17:02:57 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2009-02-19 07:12:06 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Support/Mangler.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-04-03 02:03:10 +08:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2008-05-13 17:02:57 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#include "PIC16GenAsmWriter.inc"
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|
|
|
printInstruction(MI);
|
|
|
|
return true;
|
2008-05-13 17:02:57 +08:00
|
|
|
}
|
|
|
|
|
2009-06-11 14:49:55 +08: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 17:02:57 +08:00
|
|
|
///
|
2008-11-19 19:00:54 +08:00
|
|
|
bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
2009-02-24 16:30:20 +08:00
|
|
|
this->MF = &MF;
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// This calls the base class function required to be called at beginning
|
|
|
|
// of runOnMachineFunction.
|
2008-05-13 17:02:57 +08:00
|
|
|
SetupMachineFunction(MF);
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Get the mangled name.
|
|
|
|
const Function *F = MF.getFunction();
|
2009-07-15 02:17:16 +08:00
|
|
|
CurrentFnName = Mang->getMangledName(F);
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2009-06-11 14:49:55 +08:00
|
|
|
// Emit the function frame (args and temps).
|
2009-05-29 02:24:11 +08:00
|
|
|
EmitFunctionFrame(MF);
|
|
|
|
|
2009-06-16 17:45:18 +08:00
|
|
|
DbgInfo.BeginFunction(MF);
|
2009-05-29 02:24:11 +08:00
|
|
|
|
2009-06-11 14:49:55 +08:00
|
|
|
// Emit the autos section of function.
|
2009-05-29 02:24:11 +08:00
|
|
|
EmitAutos(CurrentFnName);
|
2009-06-11 14:49:55 +08:00
|
|
|
|
|
|
|
// Now emit the instructions of function in its code section.
|
2009-05-10 13:23:47 +08:00
|
|
|
const char *codeSection = PAN::getCodeSectionName(CurrentFnName).c_str();
|
|
|
|
|
|
|
|
const Section *fCodeSection = TAI->getNamedSection(codeSection,
|
|
|
|
SectionFlags::Code);
|
|
|
|
// Start the Code Section.
|
2009-06-11 14:49:55 +08:00
|
|
|
O << "\n";
|
2009-01-14 03:18:47 +08:00
|
|
|
SwitchToSection (fCodeSection);
|
2009-04-08 14:24:04 +08:00
|
|
|
|
|
|
|
// Emit the frame address of the function at the beginning of code.
|
2009-05-10 13:23:47 +08:00
|
|
|
O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
|
|
|
|
O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
|
2009-04-08 13:38:48 +08:00
|
|
|
|
2009-05-10 13:23:47 +08:00
|
|
|
// Emit function start label.
|
|
|
|
O << CurrentFnName << ":\n";
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2009-06-16 17:45:18 +08:00
|
|
|
DebugLoc CurDL;
|
2009-05-29 02:24:11 +08:00
|
|
|
O << "\n";
|
2008-05-13 17:02:57 +08:00
|
|
|
// Print out code for the function.
|
|
|
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
|
|
|
I != E; ++I) {
|
2009-06-11 14:49:55 +08:00
|
|
|
|
2008-05-13 17:02:57 +08:00
|
|
|
// Print a label for the basic block.
|
|
|
|
if (I != MF.begin()) {
|
|
|
|
printBasicBlockLabel(I, true);
|
|
|
|
O << '\n';
|
|
|
|
}
|
2009-04-08 14:24:04 +08:00
|
|
|
|
2009-06-11 14:49:55 +08:00
|
|
|
// Print a basic block.
|
2008-05-13 17:02:57 +08:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
|
|
|
II != E; ++II) {
|
2009-06-11 14:49:55 +08:00
|
|
|
|
2009-04-08 14:24:04 +08:00
|
|
|
// Emit the line directive if source line changed.
|
|
|
|
const DebugLoc DL = II->getDebugLoc();
|
2009-06-16 17:45:18 +08:00
|
|
|
if (!DL.isUnknown() && DL != CurDL) {
|
|
|
|
DbgInfo.ChangeDebugLoc(MF, DL);
|
|
|
|
CurDL = DL;
|
2009-04-08 14:24:04 +08:00
|
|
|
}
|
2009-05-11 14:01:38 +08:00
|
|
|
|
2008-05-13 17:02:57 +08:00
|
|
|
// Print the assembly for the instruction.
|
2009-04-08 14:24:04 +08:00
|
|
|
printMachineInstruction(II);
|
2008-05-13 17:02:57 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-29 02:24:11 +08:00
|
|
|
|
|
|
|
// Emit function end debug directives.
|
2009-06-16 17:45:18 +08:00
|
|
|
DbgInfo.EndFunction(MF);
|
2009-06-11 14:49:55 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
return false; // we didn't modify anything.
|
|
|
|
}
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08: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.
|
|
|
|
///
|
|
|
|
FunctionPass *llvm::createPIC16CodePrinterPass(raw_ostream &o,
|
2009-02-24 16:30:20 +08:00
|
|
|
PIC16TargetMachine &tm,
|
2009-04-29 08:15:41 +08:00
|
|
|
bool verbose) {
|
2009-07-01 09:48:54 +08:00
|
|
|
return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
|
2008-05-13 17:02:57 +08:00
|
|
|
}
|
|
|
|
|
2009-05-11 14:01:38 +08:00
|
|
|
|
|
|
|
// printOperand - print operand of insn.
|
2008-11-19 19:00:54 +08:00
|
|
|
void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
|
2008-05-13 17:02:57 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(opNum);
|
|
|
|
|
2008-05-14 19:31:39 +08:00
|
|
|
switch (MO.getType()) {
|
2008-05-13 17:02:57 +08:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
|
2008-11-19 19:00:54 +08:00
|
|
|
O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
|
2008-05-13 17:02:57 +08:00
|
|
|
else
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("not implemented");
|
2009-07-12 04:10:48 +08:00
|
|
|
return;
|
2008-05-14 19:31:39 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
case MachineOperand::MO_Immediate:
|
2008-05-13 17:02:57 +08:00
|
|
|
O << (int)MO.getImm();
|
|
|
|
return;
|
2008-05-14 19:31:39 +08:00
|
|
|
|
2009-04-21 00:59:35 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2009-07-15 02:17:16 +08:00
|
|
|
O << Mang->getMangledName(MO.getGlobal());
|
2008-05-13 17:02:57 +08:00
|
|
|
break;
|
2009-04-21 00:59:35 +08:00
|
|
|
}
|
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
2009-05-11 14:01:38 +08: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 23:13:17 +08:00
|
|
|
LibcallDecls.push_back(Sname);
|
2009-05-11 14:01:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
O << Sname;
|
2008-05-13 17:02:57 +08:00
|
|
|
break;
|
2009-04-21 00:59:35 +08:00
|
|
|
}
|
2009-01-14 03:18:47 +08:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
printBasicBlockLabel(MO.getMBB());
|
|
|
|
return;
|
|
|
|
|
2008-05-13 17:02:57 +08:00
|
|
|
default:
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable(" Operand type not supported.");
|
2008-11-19 19:00:54 +08:00
|
|
|
}
|
2008-05-13 17:02:57 +08:00
|
|
|
}
|
|
|
|
|
2009-06-11 14:55:48 +08:00
|
|
|
/// printCCOperand - Print the cond code operand.
|
|
|
|
///
|
2009-01-14 03:18:47 +08:00
|
|
|
void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
|
|
|
|
int CC = (int)MI->getOperand(opNum).getImm();
|
|
|
|
O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
|
|
|
|
}
|
|
|
|
|
2009-06-11 14:55:48 +08:00
|
|
|
/// printLibcallDecls - print the extern declarations for compiler
|
|
|
|
/// intrinsics.
|
|
|
|
///
|
2009-05-13 23:13:17 +08:00
|
|
|
void PIC16AsmPrinter::printLibcallDecls(void) {
|
2009-05-11 14:01:38 +08:00
|
|
|
// If no libcalls used, return.
|
2009-05-13 23:13:17 +08:00
|
|
|
if (LibcallDecls.empty()) return;
|
2009-05-11 14:01:38 +08:00
|
|
|
|
2009-05-12 14:52:41 +08:00
|
|
|
O << TAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
|
2009-05-11 14:01:38 +08:00
|
|
|
// Remove duplicate entries.
|
2009-05-13 23:13:17 +08:00
|
|
|
LibcallDecls.sort();
|
|
|
|
LibcallDecls.unique();
|
|
|
|
for (std::list<const char*>::const_iterator I = LibcallDecls.begin();
|
|
|
|
I != LibcallDecls.end(); I++) {
|
2009-05-11 14:01:38 +08:00
|
|
|
O << TAI->getExternDirective() << *I << "\n";
|
2009-05-11 16:52:04 +08:00
|
|
|
O << TAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n";
|
|
|
|
O << TAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n";
|
2009-05-11 14:01:38 +08:00
|
|
|
}
|
2009-05-12 14:52:41 +08:00
|
|
|
O << TAI->getCommentString() << "External decls for libcalls - END." <<"\n";
|
2009-05-11 14:01:38 +08:00
|
|
|
}
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2009-06-11 14:55:48 +08: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.
|
|
|
|
///
|
2008-11-19 19:00:54 +08:00
|
|
|
bool PIC16AsmPrinter::doInitialization (Module &M) {
|
|
|
|
bool Result = AsmPrinter::doInitialization(M);
|
2009-05-29 02:24:11 +08:00
|
|
|
|
2008-11-19 19:00:54 +08: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-29 02:24:11 +08:00
|
|
|
O << "\n\t#include P16F1937.INC\n";
|
2009-04-03 02:03:10 +08:00
|
|
|
|
2009-05-13 01:07:27 +08: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 17:45:18 +08:00
|
|
|
DbgInfo.BeginModule(M);
|
2009-05-13 23:13:17 +08:00
|
|
|
EmitFunctionDecls(M);
|
|
|
|
EmitUndefinedVars(M);
|
|
|
|
EmitDefinedVars(M);
|
2009-05-13 01:07:27 +08:00
|
|
|
EmitIData(M);
|
|
|
|
EmitUData(M);
|
2008-11-19 19:00:54 +08:00
|
|
|
EmitRomData(M);
|
|
|
|
return Result;
|
2008-05-13 17:02:57 +08:00
|
|
|
}
|
|
|
|
|
2009-06-11 14:55:48 +08: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-05-13 23:13:17 +08:00
|
|
|
void PIC16AsmPrinter::EmitFunctionDecls (Module &M) {
|
2008-11-26 18:53:50 +08:00
|
|
|
// Emit declarations for external functions.
|
2009-06-14 01:35:54 +08:00
|
|
|
O <<"\n"<<TAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
|
2008-11-26 18:53:50 +08:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
std::string Name = Mang->getMangledName(I);
|
2009-05-10 13:23:47 +08:00
|
|
|
if (Name.compare("@abort") == 0)
|
2008-11-26 18:53:50 +08:00
|
|
|
continue;
|
2009-04-14 10:49:52 +08:00
|
|
|
|
|
|
|
// If it is llvm intrinsic call then don't emit
|
|
|
|
if (Name.find("llvm.") != std::string::npos)
|
|
|
|
continue;
|
|
|
|
|
2009-05-11 00:18:39 +08:00
|
|
|
if (! (I->isDeclaration() || I->hasExternalLinkage()))
|
|
|
|
continue;
|
2009-05-10 13:23:47 +08: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 18:53:50 +08:00
|
|
|
}
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2009-05-13 23:13:17 +08:00
|
|
|
O << TAI->getCommentString() << "Function Declarations - END." <<"\n";
|
|
|
|
}
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2009-05-13 23:13:17 +08:00
|
|
|
// Emit variables imported from other Modules.
|
|
|
|
void PIC16AsmPrinter::EmitUndefinedVars (Module &M)
|
|
|
|
{
|
|
|
|
std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDecls->Items;
|
|
|
|
if (! Items.size()) return;
|
2009-02-10 12:20:26 +08:00
|
|
|
|
2009-05-13 23:13:17 +08:00
|
|
|
O << "\n" << TAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
O << TAI->getExternDirective() << Mang->getMangledName(Items[j]) << "\n";
|
2009-05-13 23:13:17 +08:00
|
|
|
}
|
|
|
|
O << TAI->getCommentString() << "Imported Variables - END" << "\n";
|
|
|
|
}
|
2009-05-10 13:23:47 +08:00
|
|
|
|
2009-05-13 23:13:17 +08:00
|
|
|
// Emit variables defined in this module and are available to other modules.
|
|
|
|
void PIC16AsmPrinter::EmitDefinedVars (Module &M)
|
|
|
|
{
|
|
|
|
std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDefs->Items;
|
|
|
|
if (! Items.size()) return;
|
|
|
|
|
|
|
|
O << "\n" << TAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
O << TAI->getGlobalDirective() << Mang->getMangledName(Items[j]) << "\n";
|
2008-11-26 18:53:50 +08:00
|
|
|
}
|
2009-05-13 23:13:17 +08:00
|
|
|
O << TAI->getCommentString() << "Exported Variables - END" << "\n";
|
2008-11-26 18:53:50 +08:00
|
|
|
}
|
2009-02-10 12:20:26 +08:00
|
|
|
|
2009-05-13 23:13:17 +08:00
|
|
|
// Emit initialized data placed in ROM.
|
2008-11-19 19:00:54 +08:00
|
|
|
void PIC16AsmPrinter::EmitRomData (Module &M)
|
2008-05-13 17:02:57 +08:00
|
|
|
{
|
2009-07-06 18:18:37 +08:00
|
|
|
// Print ROM Data section.
|
|
|
|
std::vector <PIC16Section *>ROSections = PTAI->ROSections;
|
|
|
|
for (unsigned i = 0; i < ROSections.size(); i++) {
|
|
|
|
std::vector<const GlobalVariable*> Items = ROSections[i]->Items;
|
|
|
|
if (! Items.size()) continue;
|
|
|
|
O << "\n";
|
|
|
|
SwitchToSection(PTAI->ROSections[i]->S_);
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
O << Mang->getMangledName(Items[j]);
|
2009-07-06 18:18:37 +08:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
int AddrSpace = Items[j]->getType()->getAddressSpace();
|
|
|
|
EmitGlobalConstant(C, AddrSpace);
|
|
|
|
}
|
2008-05-13 17:02:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
bool PIC16AsmPrinter::doFinalization(Module &M) {
|
2009-05-13 23:13:17 +08:00
|
|
|
printLibcallDecls();
|
2009-06-09 23:31:19 +08:00
|
|
|
EmitRemainingAutos();
|
2009-06-16 17:45:18 +08:00
|
|
|
DbgInfo.EndModule(M);
|
2009-05-29 02:24:11 +08:00
|
|
|
O << "\n\t" << "END\n";
|
2008-11-19 19:00:54 +08:00
|
|
|
bool Result = AsmPrinter::doFinalization(M);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-05-29 02:24:11 +08:00
|
|
|
void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
|
2008-11-19 19:00:54 +08:00
|
|
|
const Function *F = MF.getFunction();
|
2009-07-15 02:17:16 +08:00
|
|
|
std::string FuncName = Mang->getMangledName(F);
|
2008-11-19 19:00:54 +08:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
// Emit the data section name.
|
|
|
|
O << "\n";
|
2009-05-10 13:23:47 +08:00
|
|
|
const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2009-05-10 13:23:47 +08:00
|
|
|
const Section *fPDataSection = TAI->getNamedSection(SectionName,
|
2009-04-21 00:59:35 +08:00
|
|
|
SectionFlags::Writeable);
|
|
|
|
SwitchToSection(fPDataSection);
|
2008-11-26 18:53:50 +08:00
|
|
|
|
2009-04-03 01:42:00 +08:00
|
|
|
// Emit function frame label
|
2009-05-10 13:23:47 +08:00
|
|
|
O << PAN::getFrameLabel(CurrentFnName) << ":\n";
|
2009-04-03 01:42:00 +08:00
|
|
|
|
2008-11-26 18:53:50 +08:00
|
|
|
const Type *RetType = F->getReturnType();
|
2009-01-14 03:18:47 +08:00
|
|
|
unsigned RetSize = 0;
|
|
|
|
if (RetType->getTypeID() != Type::VoidTyID)
|
2009-05-09 15:06:46 +08:00
|
|
|
RetSize = TD->getTypeAllocSize(RetType);
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2009-04-03 01:42:00 +08:00
|
|
|
//Emit function return value space
|
2009-05-10 13:23:47 +08: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-03 01:42:00 +08:00
|
|
|
if(RetSize > 0)
|
2009-05-10 13:23:47 +08:00
|
|
|
O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
|
2009-04-03 01:42:00 +08:00
|
|
|
else
|
2009-05-10 13:23:47 +08:00
|
|
|
O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
|
2009-04-03 01:42:00 +08: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 15:06:46 +08:00
|
|
|
ArgSize += TD->getTypeAllocSize(Ty);
|
2009-04-03 01:42:00 +08:00
|
|
|
}
|
2009-05-10 13:23:47 +08:00
|
|
|
|
|
|
|
O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
|
2009-04-03 01:42:00 +08:00
|
|
|
|
2009-04-14 10:49:52 +08:00
|
|
|
// Emit temporary space
|
|
|
|
int TempSize = PTLI->GetTmpSize();
|
|
|
|
if (TempSize > 0 )
|
2009-05-10 13:23:47 +08:00
|
|
|
O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize <<"\n";
|
2009-05-06 16:02:01 +08:00
|
|
|
}
|
|
|
|
|
2009-05-13 01:07:27 +08:00
|
|
|
void PIC16AsmPrinter::EmitIData (Module &M) {
|
2009-02-10 12:20:26 +08:00
|
|
|
|
2009-05-13 01:07:27 +08:00
|
|
|
// Print all IDATA sections.
|
2009-05-10 13:23:47 +08:00
|
|
|
std::vector <PIC16Section *>IDATASections = PTAI->IDATASections;
|
2009-05-06 16:02:01 +08:00
|
|
|
for (unsigned i = 0; i < IDATASections.size(); i++) {
|
2009-05-13 01:07:27 +08:00
|
|
|
O << "\n";
|
2009-07-07 02:07:06 +08:00
|
|
|
if (IDATASections[i]->S_->getName().find("llvm.") != std::string::npos)
|
|
|
|
continue;
|
2009-05-06 16:02:01 +08:00
|
|
|
SwitchToSection(IDATASections[i]->S_);
|
|
|
|
std::vector<const GlobalVariable*> Items = IDATASections[i]->Items;
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
std::string Name = Mang->getMangledName(Items[j]);
|
2009-05-06 16:02:01 +08:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
int AddrSpace = Items[j]->getType()->getAddressSpace();
|
|
|
|
O << Name;
|
|
|
|
EmitGlobalConstant(C, AddrSpace);
|
|
|
|
}
|
|
|
|
}
|
2009-05-13 01:07:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PIC16AsmPrinter::EmitUData (Module &M) {
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-05-06 16:02:01 +08:00
|
|
|
|
2009-05-13 01:07:27 +08:00
|
|
|
// Print all BSS sections.
|
2009-05-10 13:23:47 +08:00
|
|
|
std::vector <PIC16Section *>BSSSections = PTAI->BSSSections;
|
2009-05-06 16:02:01 +08:00
|
|
|
for (unsigned i = 0; i < BSSSections.size(); i++) {
|
2009-05-13 01:07:27 +08:00
|
|
|
O << "\n";
|
2009-05-06 16:02:01 +08:00
|
|
|
SwitchToSection(BSSSections[i]->S_);
|
|
|
|
std::vector<const GlobalVariable*> Items = BSSSections[i]->Items;
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
std::string Name = Mang->getMangledName(Items[j]);
|
2009-05-06 16:02:01 +08:00
|
|
|
Constant *C = Items[j]->getInitializer();
|
|
|
|
const Type *Ty = C->getType();
|
2009-05-09 15:06:46 +08:00
|
|
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
2009-05-06 16:02:01 +08:00
|
|
|
|
|
|
|
O << Name << " " <<"RES"<< " " << Size ;
|
|
|
|
O << "\n";
|
|
|
|
}
|
|
|
|
}
|
2008-11-19 19:00:54 +08:00
|
|
|
}
|
2009-05-06 16:02:01 +08:00
|
|
|
|
2009-05-29 02:24:11 +08:00
|
|
|
void PIC16AsmPrinter::EmitAutos (std::string FunctName)
|
2009-05-13 01:07:27 +08:00
|
|
|
{
|
|
|
|
// Section names for all globals are already set.
|
|
|
|
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
|
2009-05-29 02:24:11 +08:00
|
|
|
// Now print Autos section for this function.
|
|
|
|
std::string SectionName = PAN::getAutosSectionName(FunctName);
|
2009-05-13 01:07:27 +08:00
|
|
|
std::vector <PIC16Section *>AutosSections = PTAI->AutosSections;
|
|
|
|
for (unsigned i = 0; i < AutosSections.size(); i++) {
|
|
|
|
O << "\n";
|
2009-05-29 02:24:11 +08:00
|
|
|
if (AutosSections[i]->S_->getName() == SectionName) {
|
2009-06-09 23:31:19 +08:00
|
|
|
// Set the printing status to true
|
|
|
|
AutosSections[i]->setPrintedStatus(true);
|
2009-05-29 02:24:11 +08:00
|
|
|
SwitchToSection(AutosSections[i]->S_);
|
|
|
|
std::vector<const GlobalVariable*> Items = AutosSections[i]->Items;
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
std::string VarName = Mang->getMangledName(Items[j]);
|
2009-05-29 02:24:11 +08: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 21:58:45 +08:00
|
|
|
}
|
2009-05-29 02:24:11 +08:00
|
|
|
break;
|
2009-05-22 21:58:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-09 23:31:19 +08: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.
|
|
|
|
void PIC16AsmPrinter::EmitRemainingAutos()
|
|
|
|
{
|
|
|
|
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_);
|
|
|
|
std::vector<const GlobalVariable*> Items = AutosSections[i]->Items;
|
|
|
|
for (unsigned j = 0; j < Items.size(); j++) {
|
2009-07-15 02:17:16 +08:00
|
|
|
std::string VarName = Mang->getMangledName(Items[j]);
|
2009-06-09 23:31:19 +08: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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|