mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-30 17:25:21 +00:00
De-virtualize SwitchSection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28047 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -26,12 +26,10 @@ namespace llvm {
|
|||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
|
|
||||||
class AsmPrinter : public MachineFunctionPass {
|
class AsmPrinter : public MachineFunctionPass {
|
||||||
protected:
|
|
||||||
/// CurrentSection - The current section we are emitting to. This is
|
/// CurrentSection - The current section we are emitting to. This is
|
||||||
/// controlled and used by the SwitchSection method.
|
/// controlled and used by the SwitchSection method.
|
||||||
std::string CurrentSection;
|
std::string CurrentSection;
|
||||||
|
|
||||||
private:
|
|
||||||
/// FunctionNumber - This provides a unique ID for each function emitted in
|
/// FunctionNumber - This provides a unique ID for each function emitted in
|
||||||
/// this translation unit. It is autoincremented by SetupMachineFunction,
|
/// this translation unit. It is autoincremented by SetupMachineFunction,
|
||||||
/// and can be accessed with getFunctionNumber() and
|
/// and can be accessed with getFunctionNumber() and
|
||||||
@@ -139,6 +137,7 @@ namespace llvm {
|
|||||||
/// emit a global to an arbitrary section. The section name is emited after
|
/// emit a global to an arbitrary section. The section name is emited after
|
||||||
/// this.
|
/// this.
|
||||||
const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
|
const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
|
||||||
|
bool MLSections; // True if Microsoft ML assembler is targetted
|
||||||
|
|
||||||
/// ConstantPoolSection - This is the section that we SwitchToSection right
|
/// ConstantPoolSection - This is the section that we SwitchToSection right
|
||||||
/// before emitting the constant pool for a function.
|
/// before emitting the constant pool for a function.
|
||||||
@@ -188,7 +187,7 @@ namespace llvm {
|
|||||||
/// If the new section is an empty string, this method forgets what the
|
/// If the new section is an empty string, this method forgets what the
|
||||||
/// current section is, but does not emit a .section directive.
|
/// current section is, but does not emit a .section directive.
|
||||||
///
|
///
|
||||||
virtual void SwitchSection(const char *NewSection, const GlobalValue *GV);
|
void SwitchSection(const char *NewSection, const GlobalValue *GV);
|
||||||
|
|
||||||
/// getPreferredAlignmentLog - Return the preferred alignment of the
|
/// getPreferredAlignmentLog - Return the preferred alignment of the
|
||||||
/// specified global, returned in log form. This includes an explicitly
|
/// specified global, returned in log form. This includes an explicitly
|
||||||
|
@@ -47,6 +47,7 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
|
|||||||
AlignDirective("\t.align\t"),
|
AlignDirective("\t.align\t"),
|
||||||
AlignmentIsInBytes(true),
|
AlignmentIsInBytes(true),
|
||||||
SwitchToSectionDirective("\t.section\t"),
|
SwitchToSectionDirective("\t.section\t"),
|
||||||
|
MLSections(false),
|
||||||
ConstantPoolSection("\t.section .rodata\n"),
|
ConstantPoolSection("\t.section .rodata\n"),
|
||||||
JumpTableSection("\t.section .rodata\n"),
|
JumpTableSection("\t.section .rodata\n"),
|
||||||
StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
|
StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
|
||||||
@@ -63,16 +64,47 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
|
|||||||
///
|
///
|
||||||
void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) {
|
void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) {
|
||||||
std::string NS;
|
std::string NS;
|
||||||
|
|
||||||
if (GV && GV->hasSection())
|
// Microsoft ML/MASM has a fundamentally different approach to handling
|
||||||
NS = SwitchToSectionDirective + GV->getSection();
|
// sections.
|
||||||
else
|
|
||||||
NS = std::string("\t")+NewSection;
|
if (MLSections) {
|
||||||
|
if (*NewSection == 0) {
|
||||||
if (CurrentSection != NS) {
|
// Simply end the current section, if any.
|
||||||
CurrentSection = NS;
|
if (CurrentSection != "") {
|
||||||
if (!CurrentSection.empty())
|
O << CurrentSection << "\tends\n";
|
||||||
O << CurrentSection << '\n';
|
CurrentSection = "";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isData = strcmp(NewSection , ".data") == 0;
|
||||||
|
|
||||||
|
if (GV && GV->hasSection())
|
||||||
|
NS = GV->getSection();
|
||||||
|
else if (isData)
|
||||||
|
NS = "_data";
|
||||||
|
else
|
||||||
|
NS = "_text";
|
||||||
|
|
||||||
|
if (CurrentSection != NS) {
|
||||||
|
if (CurrentSection != "")
|
||||||
|
O << CurrentSection << "\tends\n";
|
||||||
|
CurrentSection = NS;
|
||||||
|
O << CurrentSection << (isData ? "\tsegment 'DATA'\n"
|
||||||
|
: "\tsegment 'CODE'\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (GV && GV->hasSection())
|
||||||
|
NS = SwitchToSectionDirective + GV->getSection();
|
||||||
|
else
|
||||||
|
NS = std::string("\t")+NewSection;
|
||||||
|
|
||||||
|
if (CurrentSection != NS) {
|
||||||
|
CurrentSection = NS;
|
||||||
|
if (!CurrentSection.empty())
|
||||||
|
O << CurrentSection << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ X86IntelAsmPrinter::X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM)
|
|||||||
GlobalPrefix = "_";
|
GlobalPrefix = "_";
|
||||||
PrivateGlobalPrefix = "$";
|
PrivateGlobalPrefix = "$";
|
||||||
AlignDirective = "\talign\t";
|
AlignDirective = "\talign\t";
|
||||||
|
MLSections = true;
|
||||||
ZeroDirective = "\tdb\t";
|
ZeroDirective = "\tdb\t";
|
||||||
ZeroDirectiveSuffix = " dup(0)";
|
ZeroDirectiveSuffix = " dup(0)";
|
||||||
AsciiDirective = "\tdb\t";
|
AsciiDirective = "\tdb\t";
|
||||||
@@ -443,36 +444,11 @@ bool X86IntelAsmPrinter::doInitialization(Module &M) {
|
|||||||
|
|
||||||
bool X86IntelAsmPrinter::doFinalization(Module &M) {
|
bool X86IntelAsmPrinter::doFinalization(Module &M) {
|
||||||
X86SharedAsmPrinter::doFinalization(M);
|
X86SharedAsmPrinter::doFinalization(M);
|
||||||
if (CurrentSection != "")
|
SwitchSection("", 0);
|
||||||
O << CurrentSection << "\tends\n";
|
|
||||||
O << "\tend\n";
|
O << "\tend\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void X86IntelAsmPrinter::SwitchSection(const char *NewSection,
|
|
||||||
const GlobalValue *GV) {
|
|
||||||
if (*NewSection == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::string NS;
|
|
||||||
bool isData = strcmp(NewSection , ".data") == 0;
|
|
||||||
|
|
||||||
if (GV && GV->hasSection())
|
|
||||||
NS = GV->getSection();
|
|
||||||
else if (isData)
|
|
||||||
NS = "_data";
|
|
||||||
else
|
|
||||||
NS = "_text";
|
|
||||||
|
|
||||||
if (CurrentSection != NS) {
|
|
||||||
if (CurrentSection != "")
|
|
||||||
O << CurrentSection << "\tends\n";
|
|
||||||
CurrentSection = NS;
|
|
||||||
O << CurrentSection << (isData ? "\tsegment 'DATA'\n"
|
|
||||||
: "\tsegment 'CODE'\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void X86IntelAsmPrinter::EmitString(const ConstantArray *CVA) const {
|
void X86IntelAsmPrinter::EmitString(const ConstantArray *CVA) const {
|
||||||
unsigned NumElts = CVA->getNumOperands();
|
unsigned NumElts = CVA->getNumOperands();
|
||||||
if (NumElts) {
|
if (NumElts) {
|
||||||
|
@@ -92,7 +92,6 @@ struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
|
|||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
|
|
||||||
virtual void SwitchSection(const char *NewSection, const GlobalValue *GV);
|
|
||||||
virtual void EmitString(const ConstantArray *CVA) const;
|
virtual void EmitString(const ConstantArray *CVA) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user