mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-18 06:38:41 +00:00
Implement getSectionForFunction, use it when printing function body.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30737 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
52f0670470
commit
afbfdeddff
@ -26,6 +26,28 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
/// getSectionForFunction - Return the section that we should emit the
|
||||||
|
/// specified function body into.
|
||||||
|
std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
|
||||||
|
switch (F.getLinkage()) {
|
||||||
|
default: assert(0 && "Unknown linkage type!");
|
||||||
|
case Function::InternalLinkage:
|
||||||
|
case Function::DLLExportLinkage:
|
||||||
|
case Function::ExternalLinkage:
|
||||||
|
return TAI->getTextSection();
|
||||||
|
case Function::WeakLinkage:
|
||||||
|
case Function::LinkOnceLinkage:
|
||||||
|
if (Subtarget->isTargetDarwin()) {
|
||||||
|
return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
|
||||||
|
} else if (Subtarget->isTargetCygwin()) {
|
||||||
|
return "\t.section\t.llvm.linkonce.t." + CurrentFnName + ",\"ax\"\n";
|
||||||
|
} else {
|
||||||
|
return "\t.section\t.llvm.linkonce.t." + CurrentFnName +
|
||||||
|
",\"ax\",@progbits\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// runOnMachineFunction - This uses the printMachineInstruction()
|
/// runOnMachineFunction - This uses the printMachineInstruction()
|
||||||
/// method to print assembly for each instruction.
|
/// method to print assembly for each instruction.
|
||||||
///
|
///
|
||||||
@ -53,38 +75,30 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
|
|
||||||
X86SharedAsmPrinter::decorateName(CurrentFnName, F);
|
X86SharedAsmPrinter::decorateName(CurrentFnName, F);
|
||||||
|
|
||||||
|
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
||||||
|
|
||||||
switch (F->getLinkage()) {
|
switch (F->getLinkage()) {
|
||||||
default: assert(0 && "Unknown linkage type!");
|
default: assert(0 && "Unknown linkage type!");
|
||||||
case Function::InternalLinkage: // Symbols default to internal.
|
case Function::InternalLinkage: // Symbols default to internal.
|
||||||
SwitchToTextSection(TAI->getTextSection(), F);
|
|
||||||
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
||||||
break;
|
break;
|
||||||
case Function::DLLExportLinkage:
|
case Function::DLLExportLinkage:
|
||||||
DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
|
DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
|
||||||
//FALLS THROUGH
|
//FALLS THROUGH
|
||||||
case Function::ExternalLinkage:
|
case Function::ExternalLinkage:
|
||||||
SwitchToTextSection(TAI->getTextSection(), F);
|
|
||||||
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
||||||
O << "\t.globl\t" << CurrentFnName << "\n";
|
O << "\t.globl\t" << CurrentFnName << "\n";
|
||||||
break;
|
break;
|
||||||
case Function::WeakLinkage:
|
case Function::WeakLinkage:
|
||||||
case Function::LinkOnceLinkage:
|
case Function::LinkOnceLinkage:
|
||||||
if (Subtarget->isTargetDarwin()) {
|
if (Subtarget->isTargetDarwin()) {
|
||||||
SwitchToTextSection(
|
|
||||||
".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
|
|
||||||
O << "\t.globl\t" << CurrentFnName << "\n";
|
O << "\t.globl\t" << CurrentFnName << "\n";
|
||||||
O << "\t.weak_definition\t" << CurrentFnName << "\n";
|
O << "\t.weak_definition\t" << CurrentFnName << "\n";
|
||||||
} else if (Subtarget->isTargetCygwin()) {
|
} else if (Subtarget->isTargetCygwin()) {
|
||||||
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
||||||
O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
|
|
||||||
<< ",\"ax\"\n";
|
|
||||||
SwitchToTextSection("", F);
|
|
||||||
O << "\t.weak " << CurrentFnName << "\n";
|
O << "\t.weak " << CurrentFnName << "\n";
|
||||||
} else {
|
} else {
|
||||||
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
||||||
O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
|
|
||||||
<< ",\"ax\",@progbits\n";
|
|
||||||
SwitchToTextSection("", F);
|
|
||||||
O << "\t.weak " << CurrentFnName << "\n";
|
O << "\t.weak " << CurrentFnName << "\n";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -76,6 +76,10 @@ struct X86ATTAsmPrinter : public X86SharedAsmPrinter {
|
|||||||
const char *Modifier=NULL);
|
const char *Modifier=NULL);
|
||||||
void printPICLabel(const MachineInstr *MI, unsigned Op);
|
void printPICLabel(const MachineInstr *MI, unsigned Op);
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
bool runOnMachineFunction(MachineFunction &F);
|
||||||
|
|
||||||
|
/// getSectionForFunction - Return the section that we should emit the
|
||||||
|
/// specified function body into.
|
||||||
|
virtual std::string getSectionForFunction(const Function &F) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
@ -25,6 +25,11 @@
|
|||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
std::string X86IntelAsmPrinter::getSectionForFunction(const Function &F) const {
|
||||||
|
// Intel asm always emits functions to _text.
|
||||||
|
return "_text";
|
||||||
|
}
|
||||||
|
|
||||||
/// runOnMachineFunction - This uses the printMachineInstruction()
|
/// runOnMachineFunction - This uses the printMachineInstruction()
|
||||||
/// method to print assembly for each instruction.
|
/// method to print assembly for each instruction.
|
||||||
///
|
///
|
||||||
@ -46,10 +51,11 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
|
|
||||||
X86SharedAsmPrinter::decorateName(CurrentFnName, F);
|
X86SharedAsmPrinter::decorateName(CurrentFnName, F);
|
||||||
|
|
||||||
|
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
||||||
|
|
||||||
switch (F->getLinkage()) {
|
switch (F->getLinkage()) {
|
||||||
default: assert(0 && "Unsupported linkage type!");
|
default: assert(0 && "Unsupported linkage type!");
|
||||||
case Function::InternalLinkage:
|
case Function::InternalLinkage:
|
||||||
SwitchToTextSection("_text", F);
|
|
||||||
EmitAlignment(4);
|
EmitAlignment(4);
|
||||||
break;
|
break;
|
||||||
case Function::DLLExportLinkage:
|
case Function::DLLExportLinkage:
|
||||||
@ -57,7 +63,6 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
//FALLS THROUGH
|
//FALLS THROUGH
|
||||||
case Function::ExternalLinkage:
|
case Function::ExternalLinkage:
|
||||||
O << "\tpublic " << CurrentFnName << "\n";
|
O << "\tpublic " << CurrentFnName << "\n";
|
||||||
SwitchToTextSection("_text", F);
|
|
||||||
EmitAlignment(4);
|
EmitAlignment(4);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,10 @@ struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
|
|||||||
bool runOnMachineFunction(MachineFunction &F);
|
bool runOnMachineFunction(MachineFunction &F);
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
|
|
||||||
|
/// getSectionForFunction - Return the section that we should emit the
|
||||||
|
/// specified function body into.
|
||||||
|
virtual std::string getSectionForFunction(const Function &F) const;
|
||||||
|
|
||||||
virtual void EmitString(const ConstantArray *CVA) const;
|
virtual void EmitString(const ConstantArray *CVA) const;
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,7 @@ using namespace llvm;
|
|||||||
X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
|
X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
|
||||||
const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
|
const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
|
||||||
|
|
||||||
//FIXME - Should to be simplified.
|
// FIXME - Should be simplified.
|
||||||
|
|
||||||
switch (Subtarget->TargetType) {
|
switch (Subtarget->TargetType) {
|
||||||
case X86Subtarget::isDarwin:
|
case X86Subtarget::isDarwin:
|
||||||
@ -31,7 +31,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
|
|||||||
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
|
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
|
||||||
PrivateGlobalPrefix = "L"; // Marker for constant pool idxs
|
PrivateGlobalPrefix = "L"; // Marker for constant pool idxs
|
||||||
ConstantPoolSection = "\t.const\n";
|
ConstantPoolSection = "\t.const\n";
|
||||||
JumpTableDataSection = "\t.const\n"; // FIXME: depends on PIC mode
|
JumpTableDataSection = "\t.const\n";
|
||||||
FourByteConstantSection = "\t.literal4\n";
|
FourByteConstantSection = "\t.literal4\n";
|
||||||
EightByteConstantSection = "\t.literal8\n";
|
EightByteConstantSection = "\t.literal8\n";
|
||||||
if (Subtarget->is64Bit())
|
if (Subtarget->is64Bit())
|
||||||
@ -97,3 +97,4 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
|
|||||||
SectionEndDirectiveSuffix = "\tends\n";
|
SectionEndDirectiveSuffix = "\tends\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ namespace llvm {
|
|||||||
struct X86TargetAsmInfo : public TargetAsmInfo {
|
struct X86TargetAsmInfo : public TargetAsmInfo {
|
||||||
X86TargetAsmInfo(const X86TargetMachine &TM);
|
X86TargetAsmInfo(const X86TargetMachine &TM);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user