mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-24 08:33:39 +00:00
pull linkage emission code out to a new EmitLinkage function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94621 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b406a8141d
commit
a3e8883d71
@ -360,6 +360,8 @@ namespace llvm {
|
||||
void printOffset(int64_t Offset) const;
|
||||
|
||||
private:
|
||||
void EmitLinkage(unsigned Linkage, MCSymbol *GVSym);
|
||||
|
||||
void EmitJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
||||
const MachineBasicBlock *MBB,
|
||||
unsigned uid) const;
|
||||
|
@ -150,6 +150,50 @@ bool AsmPrinter::doInitialization(Module &M) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AsmPrinter::EmitLinkage(unsigned Linkage, MCSymbol *GVSym) {
|
||||
switch ((GlobalValue::LinkageTypes)Linkage) {
|
||||
case GlobalValue::CommonLinkage:
|
||||
case GlobalValue::LinkOnceAnyLinkage:
|
||||
case GlobalValue::LinkOnceODRLinkage:
|
||||
case GlobalValue::WeakAnyLinkage:
|
||||
case GlobalValue::WeakODRLinkage:
|
||||
case GlobalValue::LinkerPrivateLinkage:
|
||||
if (MAI->getWeakDefDirective() != 0) {
|
||||
// .globl _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
||||
// .weak_definition _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_WeakDefinition);
|
||||
} else if (const char *LinkOnce = MAI->getLinkOnceDirective()) {
|
||||
// .globl _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
||||
// FIXME: linkonce should be a section attribute, handled by COFF Section
|
||||
// assignment.
|
||||
// http://sourceware.org/binutils/docs-2.20/as/Linkonce.html#Linkonce
|
||||
// .linkonce same_size
|
||||
O << LinkOnce;
|
||||
} else {
|
||||
// .weak _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
|
||||
}
|
||||
break;
|
||||
case GlobalValue::DLLExportLinkage:
|
||||
case GlobalValue::AppendingLinkage:
|
||||
// FIXME: appending linkage variables should go into a section of
|
||||
// their name or something. For now, just emit them as external.
|
||||
case GlobalValue::ExternalLinkage:
|
||||
// If external or appending, declare as a global symbol.
|
||||
// .globl _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
||||
break;
|
||||
case GlobalValue::PrivateLinkage:
|
||||
case GlobalValue::InternalLinkage:
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unknown linkage type!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// EmitGlobalVariable - Emit the specified global variable to the .s file.
|
||||
void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
|
||||
if (!GV->hasInitializer()) // External globals require no code.
|
||||
@ -225,50 +269,9 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
|
||||
|
||||
OutStreamer.SwitchSection(TheSection);
|
||||
|
||||
// TODO: Factor into an 'emit linkage' thing that is shared with function
|
||||
// bodies.
|
||||
switch (GV->getLinkage()) {
|
||||
case GlobalValue::CommonLinkage:
|
||||
case GlobalValue::LinkOnceAnyLinkage:
|
||||
case GlobalValue::LinkOnceODRLinkage:
|
||||
case GlobalValue::WeakAnyLinkage:
|
||||
case GlobalValue::WeakODRLinkage:
|
||||
case GlobalValue::LinkerPrivateLinkage:
|
||||
if (MAI->getWeakDefDirective() != 0) {
|
||||
// .globl _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
||||
// .weak_definition _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_WeakDefinition);
|
||||
} else if (const char *LinkOnce = MAI->getLinkOnceDirective()) {
|
||||
// .globl _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
||||
// FIXME: linkonce should be a section attribute, handled by COFF Section
|
||||
// assignment.
|
||||
// http://sourceware.org/binutils/docs-2.20/as/Linkonce.html#Linkonce
|
||||
// .linkonce same_size
|
||||
O << LinkOnce;
|
||||
} else {
|
||||
// .weak _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
|
||||
}
|
||||
break;
|
||||
case GlobalValue::DLLExportLinkage:
|
||||
case GlobalValue::AppendingLinkage:
|
||||
// FIXME: appending linkage variables should go into a section of
|
||||
// their name or something. For now, just emit them as external.
|
||||
case GlobalValue::ExternalLinkage:
|
||||
// If external or appending, declare as a global symbol.
|
||||
// .globl _foo
|
||||
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
||||
break;
|
||||
case GlobalValue::PrivateLinkage:
|
||||
case GlobalValue::InternalLinkage:
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unknown linkage type!");
|
||||
}
|
||||
|
||||
EmitLinkage(GV->getLinkage(), GVSym);
|
||||
EmitAlignment(AlignLog, GV);
|
||||
|
||||
if (VerboseAsm) {
|
||||
WriteAsOperand(OutStreamer.GetCommentOS(), GV,
|
||||
/*PrintType=*/false, GV->getParent());
|
||||
|
Loading…
x
Reference in New Issue
Block a user