///
typedef std::map<const Value *, unsigned> ValueMapTy;
ValueMapTy NumberForBB;
+ std::string CurSection;
virtual const char *getPassName() const {
return "Alpha Assembly Printer";
bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M);
bool doFinalization(Module &M);
+ void SwitchSection(std::ostream &OS, const char *NewSection);
};
} // end of anonymous namespace
O << MO.getSymbolName();
return;
- case MachineOperand::MO_GlobalAddress:
- O << Mang->getValueName(MO.getGlobal());
+ case MachineOperand::MO_GlobalAddress:
+ //Abuse PCrel to specify pcrel calls
+ //calls are the only thing that use this flag
+ if (MO.isPCRelative())
+ O << "$" << Mang->getValueName(MO.getGlobal()) << "..ng";
+ else
+ O << Mang->getValueName(MO.getGlobal());
return;
default:
printConstantPool(MF.getConstantPool());
// Print out labels for the function.
- O << "\t.text\n";
- emitAlignment(3);
+ SwitchSection(O, "text");
+ emitAlignment(4);
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.ent\t" << CurrentFnName << "\n";
if (CP.empty()) return;
+ SwitchSection(O, "section .rodata");
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
- O << "\t.section\t.rodata\n";
+ // SwitchSection(O, "section .rodata, \"dr\"");
emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
O << "CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString
<< *CP[i] << "\n";
// SwitchSection - Switch to the specified section of the executable if we are
// not already in it!
//
-static void SwitchSection(std::ostream &OS, std::string &CurSection,
- const char *NewSection) {
+void AlphaAsmPrinter::SwitchSection(std::ostream &OS, const char *NewSection)
+{
if (CurSection != NewSection) {
CurSection = NewSection;
if (!CurSection.empty())
- OS << "\t" << NewSection << "\n";
+ OS << "\t." << NewSection << "\n";
}
}
bool AlphaAsmPrinter::doFinalization(Module &M) {
const TargetData &TD = TM.getTargetData();
- std::string CurSection;
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
if (I->hasInitializer()) { // External global require no code
if (C->isNullValue() &&
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
- SwitchSection(O, CurSection, ".data");
+ SwitchSection(O, "data");
if (I->hasInternalLinkage())
O << "\t.local " << name << "\n";
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
// Nonnull linkonce -> weak
O << "\t.weak " << name << "\n";
- SwitchSection(O, CurSection, "");
+ SwitchSection(O, "");
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
break;
case GlobalValue::AppendingLinkage:
// FALL THROUGH
case GlobalValue::InternalLinkage:
if (C->isNullValue())
- SwitchSection(O, CurSection, ".data"); //was .bss
+ SwitchSection(O, "bss"); //was .bss
else
- SwitchSection(O, CurSection, ".data");
+ SwitchSection(O, "data");
break;
case GlobalValue::GhostLinkage:
std::cerr << "GhostLinkage cannot appear in AlphaAsmPrinter!\n";
if (GlobalAddressSDNode *GASD =
dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
{
- //if (GASD->getGlobal()->isExternal()) {
+ if (GASD->getGlobal()->isExternal()) {
//use safe calling convention
AlphaLowering.restoreGP(BB);
has_sym = true;
- BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal(),true);
- //} else {
+ BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal());
+ } else {
//use PC relative branch call
- //BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true);
- //}
+ BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true);
+ }
}
else if (ExternalSymbolSDNode *ESSDN =
dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))