#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/CodeGen/DwarfWriter.h"
-#include "llvm/Support/FormattedStream.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/Support/Mangler.h"
-#include "llvm/Support/ErrorHandling.h"
#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/MC/MCSection.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
-
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Mangler.h"
using namespace llvm;
#include "PIC16GenAsmWriter.inc"
: AsmPrinter(O, TM, T, V), DbgInfo(O, T) {
PTLI = static_cast<const PIC16TargetLowering*>(TM.getTargetLowering());
PTAI = static_cast<const PIC16TargetAsmInfo*>(T);
- PTOF = static_cast<const PIC16TargetObjectFile*>(&PTLI->getObjFileLowering());
+ PTOF = (PIC16TargetObjectFile*)&PTLI->getObjFileLowering();
}
bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
std::string T = PAN::getCodeSectionName(CurrentFnName);
const char *codeSection = T.c_str();
- const Section *fCodeSection =
+ const MCSection *fCodeSection =
getObjFileLowering().getOrCreateSection(codeSection, false,
- SectionKind::Text);
+ SectionKind::getText());
// Start the Code Section.
O << "\n";
SwitchToSection(fCodeSection);
return;
case MachineOperand::MO_GlobalAddress: {
- O << Mang->getMangledName(MO.getGlobal());
+ std::string Sname = Mang->getMangledName(MO.getGlobal());
+ // FIXME: currently we do not have a memcpy def coming in the module
+ // by any chance, as we do not link in those as .bc lib. So these calls
+ // are always external and it is safe to emit an extern.
+ if (PAN::isMemIntrinsic(Sname)) {
+ LibcallDecls.push_back(createESName(Sname));
+ }
+
+ O << Sname;
break;
}
case MachineOperand::MO_ExternalSymbol: {
LibcallDecls.push_back(Sname);
}
- O << Sname;
+ // Record a call to intrinsic to print the extern declaration for it.
+ std::string Sym = Sname;
+ if (PAN::isMemIntrinsic(Sym)) {
+ Sym = PAN::addPrefix(Sym);
+ LibcallDecls.push_back(createESName(Sym));
+ }
+
+ O << Sym;
break;
}
case MachineOperand::MO_MachineBasicBlock:
// Set the section names for all globals.
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
- I->setSection(getObjFileLowering().SectionForGlobal(I, TM)->getName());
+ if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage())
+ I->setSection(getObjFileLowering().
+ SectionForGlobal(I, Mang,TM)->getName());
DbgInfo.BeginModule(M);
EmitFunctionDecls(M);
if (!I->isDeclaration() && !I->hasExternalLinkage())
continue;
+ // Do not emit memcpy, memset, and memmove here.
+ // Calls to these routines can be generated in two ways,
+ // 1. User calling the standard lib function
+ // 2. Codegen generating these calls for llvm intrinsics.
+ // In the first case a prototype is alread availale, while in
+ // second case the call is via and externalsym and the prototype is missing.
+ // So declarations for these are currently always getting printing by
+ // tracking both kind of references in printInstrunction.
+ if (I->isDeclaration() && PAN::isMemIntrinsic(Name)) continue;
+
const char *directive = I->isDeclaration() ? TAI->getExternDirective() :
TAI->getGlobalDirective();
std::string T = PAN::getFrameSectionName(CurrentFnName);
const char *SectionName = T.c_str();
- const Section *fPDataSection =
+ const MCSection *fPDataSection =
getObjFileLowering().getOrCreateSection(SectionName, false,
- SectionKind::DataRel);
+ SectionKind::getDataRel());
SwitchToSection(fPDataSection);
// Emit function frame label