Well this isn't as ugly and it works better. At least gcc bootstraps again

llvm-svn: 34254
This commit is contained in:
Andrew Lenharth 2007-02-13 23:41:16 +00:00
parent 5153525402
commit 6719d3d0a2
1 changed files with 69 additions and 70 deletions

View File

@ -112,9 +112,13 @@ void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
O << MO.getSymbolName(); O << MO.getSymbolName();
return; return;
case MachineOperand::MO_GlobalAddress: case MachineOperand::MO_GlobalAddress: {
O << Mang->getValueName(MO.getGlobal()); GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
if (GV->isDeclaration() && GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
return; return;
}
case MachineOperand::MO_JumpTableIndex: case MachineOperand::MO_JumpTableIndex:
O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
@ -189,88 +193,83 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
bool AlphaAsmPrinter::doInitialization(Module &M) bool AlphaAsmPrinter::doInitialization(Module &M)
{ {
AsmPrinter::doInitialization(M);
if(TM.getSubtarget<AlphaSubtarget>().hasCT()) if(TM.getSubtarget<AlphaSubtarget>().hasCT())
O << "\t.arch ev6\n"; //This might need to be ev67, so leave this test here O << "\t.arch ev6\n"; //This might need to be ev67, so leave this test here
else else
O << "\t.arch ev6\n"; O << "\t.arch ev6\n";
O << "\t.set noat\n"; O << "\t.set noat\n";
AsmPrinter::doInitialization(M);
return false; return false;
} }
bool AlphaAsmPrinter::doFinalization(Module &M) { bool AlphaAsmPrinter::doFinalization(Module &M) {
const TargetData *TD = TM.getTargetData(); const TargetData *TD = TM.getTargetData();
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
if (I->hasInitializer()) { // External global require no code
// Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(I))
continue;
O << "\n\n";
std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer();
unsigned Size = TD->getTypeSize(C->getType());
// unsigned Align = TD->getPreferredTypeAlignmentShift(C->getType());
unsigned Align = TD->getPreferredAlignmentLog(I);
if (C->isNullValue() && if (!I->hasInitializer()) continue; // External global require no code
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
I->hasWeakLinkage() /* FIXME: Verify correct */)) { // Check to see if this is a special global used by LLVM, if so, emit it.
SwitchToDataSection("\t.section .data", I); if (EmitSpecialLLVMGlobal(I))
if (I->hasInternalLinkage()) continue;
O << "\t.local " << name << "\n";
std::string name = Mang->getValueName(I);
O << "\t.comm " << name << "," << TD->getTypeSize(C->getType()) Constant *C = I->getInitializer();
<< "," << (1 << Align) unsigned Size = TD->getTypeSize(C->getType());
<< "\n"; unsigned Align = TD->getPreferredAlignmentLog(I);
} else {
switch (I->getLinkage()) { //1: hidden?
case GlobalValue::LinkOnceLinkage: if (I->hasHiddenVisibility())
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. O << TAI->getHiddenDirective() << name << "\n";
// Nonnull linkonce -> weak
O << "\t.weak " << name << "\n"; //2: kind
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"; switch (I->getLinkage()) {
SwitchToDataSection("", I); case GlobalValue::LinkOnceLinkage:
break; case GlobalValue::WeakLinkage:
case GlobalValue::AppendingLinkage: O << TAI->getWeakRefDirective() << name << '\n';
// FIXME: appending linkage variables should go into a section of break;
// their name or something. For now, just emit them as external. case GlobalValue::AppendingLinkage:
case GlobalValue::ExternalLinkage: case GlobalValue::ExternalLinkage:
// If external or appending, declare as a global symbol O << "\t.globl " << name << "\n";
O << "\t.globl " << name << "\n"; break;
// FALL THROUGH case GlobalValue::InternalLinkage:
case GlobalValue::InternalLinkage: break;
SwitchToDataSection(C->isNullValue() ? "\t.section .bss" : default:
"\t.section .data", I); assert(0 && "Unknown linkage type!");
break; cerr << "Unknown linkage type!\n";
case GlobalValue::GhostLinkage: abort();
cerr << "GhostLinkage cannot appear in AlphaAsmPrinter!\n";
abort();
case GlobalValue::DLLImportLinkage:
cerr << "DLLImport linkage is not supported by this target!\n";
abort();
case GlobalValue::DLLExportLinkage:
cerr << "DLLExport linkage is not supported by this target!\n";
abort();
default:
assert(0 && "Unknown linkage type!");
}
EmitAlignment(Align);
O << "\t.type " << name << ",@object\n";
O << "\t.size " << name << "," << Size << "\n";
O << name << ":\n";
EmitGlobalConstant(C);
}
} }
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) //3: Section (if changed)
if (I->hasExternalWeakLinkage()) { if (I->hasSection() &&
O << "\n\n"; (I->getSection() == ".ctors" ||
std::string name = Mang->getValueName(I); I->getSection() == ".dtors")) {
O << "\t.weak " << name << "\n"; std::string SectionName = ".section\t" + I->getSection()
+ ",\"aw\",@progbits";
SwitchToDataSection(SectionName.c_str());
} else {
if (C->isNullValue())
SwitchToDataSection("\t.section\t.bss", I);
else
SwitchToDataSection("\t.section\t.data", I);
} }
//4: Type, Size, Align
O << "\t.type\t" << name << ", @object\n";
O << "\t.size\t" << name << ", " << Size << "\n";
EmitAlignment(Align, I);
O << name << ":\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}
AsmPrinter::doFinalization(M); AsmPrinter::doFinalization(M);
return false; return false;