mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-28 03:25:23 +00:00
Use the shared asmprinter code for printing special llvm globals
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24695 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -198,14 +198,14 @@ namespace {
|
|||||||
AlignmentIsInBytes = false; // Alignment is by power of 2.
|
AlignmentIsInBytes = false; // Alignment is by power of 2.
|
||||||
ConstantPoolSection = "\t.const\t";
|
ConstantPoolSection = "\t.const\t";
|
||||||
LCOMMDirective = "\t.lcomm\t";
|
LCOMMDirective = "\t.lcomm\t";
|
||||||
|
StaticCtorsSection = ".mod_init_func";
|
||||||
|
StaticDtorsSection = ".mod_term_func";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char *getPassName() const {
|
virtual const char *getPassName() const {
|
||||||
return "Darwin PPC Assembly Printer";
|
return "Darwin PPC Assembly Printer";
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitXXStructorList(Constant *List);
|
|
||||||
|
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
bool runOnMachineFunction(MachineFunction &F);
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
@@ -415,21 +415,6 @@ bool DarwinAsmPrinter::doInitialization(Module &M) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitXXStructorList - Emit the ctor or dtor list. On darwin, this just
|
|
||||||
/// prints out the function pointers.
|
|
||||||
void DarwinAsmPrinter::EmitXXStructorList(Constant *List) {
|
|
||||||
// Should be an array of '{ int, void ()* }' structs. The first value is the
|
|
||||||
// init priority, which we ignore.
|
|
||||||
if (!isa<ConstantArray>(List)) return;
|
|
||||||
ConstantArray *InitList = cast<ConstantArray>(List);
|
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
|
|
||||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
|
|
||||||
if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
|
|
||||||
// Emit the function pointer.
|
|
||||||
EmitGlobalConstant(CS->getOperand(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DarwinAsmPrinter::doFinalization(Module &M) {
|
bool DarwinAsmPrinter::doFinalization(Module &M) {
|
||||||
const TargetData &TD = TM.getTargetData();
|
const TargetData &TD = TM.getTargetData();
|
||||||
|
|
||||||
@@ -438,22 +423,9 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
|
|||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
if (!I->hasInitializer()) continue; // External global require no code
|
if (!I->hasInitializer()) continue; // External global require no code
|
||||||
|
|
||||||
// Check to see if this is a special global used by LLVM.
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
||||||
if (I->hasAppendingLinkage()) {
|
if (I->hasAppendingLinkage() && EmitSpecialLLVMGlobal(I))
|
||||||
if (I->getName() == "llvm.used")
|
continue;
|
||||||
continue; // No need to emit this at all.
|
|
||||||
if (I->getName() == "llvm.global_ctors") {
|
|
||||||
SwitchSection(".mod_init_func", 0);
|
|
||||||
EmitAlignment(2, 0);
|
|
||||||
EmitXXStructorList(I->getInitializer());
|
|
||||||
continue;
|
|
||||||
} else if (I->getName() == "llvm.global_dtors") {
|
|
||||||
SwitchSection(".mod_term_func", 0);
|
|
||||||
EmitAlignment(2, 0);
|
|
||||||
EmitXXStructorList(I->getInitializer());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
O << '\n';
|
O << '\n';
|
||||||
std::string name = Mang->getValueName(I);
|
std::string name = Mang->getValueName(I);
|
||||||
|
@@ -58,6 +58,8 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
|
|||||||
COMMDirectiveTakesAlignment = false;
|
COMMDirectiveTakesAlignment = false;
|
||||||
HasDotTypeDotSizeDirective = false;
|
HasDotTypeDotSizeDirective = false;
|
||||||
forDarwin = true;
|
forDarwin = true;
|
||||||
|
StaticCtorsSection = ".mod_init_func";
|
||||||
|
StaticDtorsSection = ".mod_term_func";
|
||||||
break;
|
break;
|
||||||
case X86Subtarget::isCygwin:
|
case X86Subtarget::isCygwin:
|
||||||
GlobalPrefix = "_";
|
GlobalPrefix = "_";
|
||||||
@@ -74,21 +76,6 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
|
|||||||
return AsmPrinter::doInitialization(M);
|
return AsmPrinter::doInitialization(M);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitXXStructorList - Emit the ctor or dtor list. On darwin, this just
|
|
||||||
/// prints out the function pointers.
|
|
||||||
void X86SharedAsmPrinter::EmitXXStructorList(Constant *List) {
|
|
||||||
// Should be an array of '{ int, void ()* }' structs. The first value is the
|
|
||||||
// init priority, which we ignore.
|
|
||||||
if (!isa<ConstantArray>(List)) return;
|
|
||||||
ConstantArray *InitList = cast<ConstantArray>(List);
|
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
|
|
||||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
|
|
||||||
if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
|
|
||||||
// Emit the function pointer.
|
|
||||||
EmitGlobalConstant(CS->getOperand(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
||||||
const TargetData &TD = TM.getTargetData();
|
const TargetData &TD = TM.getTargetData();
|
||||||
|
|
||||||
@@ -97,28 +84,9 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
|||||||
E = M.global_end(); I != E; ++I) {
|
E = M.global_end(); I != E; ++I) {
|
||||||
if (!I->hasInitializer()) continue; // External global require no code
|
if (!I->hasInitializer()) continue; // External global require no code
|
||||||
|
|
||||||
// Check to see if this is a special global used by LLVM.
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
||||||
if (I->hasAppendingLinkage()) {
|
if (I->hasAppendingLinkage() && EmitSpecialLLVMGlobal(I))
|
||||||
if (I->getName() == "llvm.used")
|
continue;
|
||||||
continue; // No need to emit this at all.
|
|
||||||
if (I->getName() == "llvm.global_ctors") {
|
|
||||||
if (forDarwin)
|
|
||||||
SwitchSection(".mod_init_func", 0);
|
|
||||||
else
|
|
||||||
SwitchSection(".ctors,\"aw\",@progbits", 0);
|
|
||||||
EmitAlignment(2, 0);
|
|
||||||
EmitXXStructorList(I->getInitializer());
|
|
||||||
continue;
|
|
||||||
} else if (I->getName() == "llvm.global_dtors") {
|
|
||||||
if (forDarwin)
|
|
||||||
SwitchSection(".mod_term_func", 0);
|
|
||||||
else
|
|
||||||
SwitchSection(".dtors,\"aw\",@progbits", 0);
|
|
||||||
EmitAlignment(2, 0);
|
|
||||||
EmitXXStructorList(I->getInitializer());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
O << "\n\n";
|
O << "\n\n";
|
||||||
std::string name = Mang->getValueName(I);
|
std::string name = Mang->getValueName(I);
|
||||||
|
@@ -33,7 +33,6 @@ struct X86SharedAsmPrinter : public AsmPrinter {
|
|||||||
|
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
void EmitXXStructorList(Constant *List);
|
|
||||||
|
|
||||||
bool forDarwin; // FIXME: eliminate.
|
bool forDarwin; // FIXME: eliminate.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user