mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 23:31:37 +00:00
* Fix printing of signed immediate values (Nate Begeman)
* Fix printing of `zeroinitializer' * Fix printing of `linkonce' globals, complete with stubs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15084 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1013ef5228
commit
97a296f743
@ -52,7 +52,7 @@ namespace {
|
|||||||
/// Name-mangler for global names.
|
/// Name-mangler for global names.
|
||||||
///
|
///
|
||||||
Mangler *Mang;
|
Mangler *Mang;
|
||||||
std::set<std::string> FnStubs, GVStubs;
|
std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
|
||||||
std::set<std::string> Strings;
|
std::set<std::string> Strings;
|
||||||
|
|
||||||
Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0)
|
Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0)
|
||||||
@ -331,7 +331,12 @@ void Printer::emitGlobalConstant(const Constant *CV) {
|
|||||||
case Type::FloatTyID: case Type::DoubleTyID:
|
case Type::FloatTyID: case Type::DoubleTyID:
|
||||||
assert (0 && "Should have already output floating point constant.");
|
assert (0 && "Should have already output floating point constant.");
|
||||||
default:
|
default:
|
||||||
assert (0 && "Can't handle printing this type of thing");
|
if (CV == Constant::getNullValue(type)) { // Zero initializer?
|
||||||
|
O << ".space\t" << TD.getTypeSize(type) << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::cerr << "Can't handle printing: " << *CV;
|
||||||
|
abort();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
O << "\t";
|
O << "\t";
|
||||||
@ -413,8 +418,11 @@ void Printer::printOp(const MachineOperand &MO,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_SignExtendedImmed:
|
case MachineOperand::MO_SignExtendedImmed:
|
||||||
|
O << (short)MO.getImmedValue();
|
||||||
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_UnextendedImmed:
|
case MachineOperand::MO_UnextendedImmed:
|
||||||
O << (int)MO.getImmedValue();
|
O << (unsigned short)MO.getImmedValue();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_PCRelativeDisp:
|
case MachineOperand::MO_PCRelativeDisp:
|
||||||
@ -601,9 +609,8 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
unsigned Size = TD.getTypeSize(C->getType());
|
unsigned Size = TD.getTypeSize(C->getType());
|
||||||
unsigned Align = TD.getTypeAlignment(C->getType());
|
unsigned Align = TD.getTypeAlignment(C->getType());
|
||||||
|
|
||||||
if (C->isNullValue() &&
|
if (C->isNullValue() && /* FIXME: Verify correct */
|
||||||
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
|
(I->hasInternalLinkage() || I->hasWeakLinkage())) {
|
||||||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
|
|
||||||
SwitchSection(O, CurSection, ".data");
|
SwitchSection(O, CurSection, ".data");
|
||||||
if (I->hasInternalLinkage())
|
if (I->hasInternalLinkage())
|
||||||
O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType())
|
O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType())
|
||||||
@ -616,13 +623,18 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
} else {
|
} else {
|
||||||
switch (I->getLinkage()) {
|
switch (I->getLinkage()) {
|
||||||
case GlobalValue::LinkOnceLinkage:
|
case GlobalValue::LinkOnceLinkage:
|
||||||
|
O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n"
|
||||||
|
<< ".weak_definition " << name << '\n'
|
||||||
|
<< ".private_extern " << name << '\n'
|
||||||
|
<< ".section __DATA,__datacoal_nt,coalesced,no_toc\n";
|
||||||
|
LinkOnceStubs.insert(name);
|
||||||
|
break;
|
||||||
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
||||||
// Nonnull linkonce -> weak
|
// Nonnull linkonce -> weak
|
||||||
O << "\t.weak " << name << "\n";
|
O << "\t.weak " << name << "\n";
|
||||||
SwitchSection(O, CurSection, "");
|
SwitchSection(O, CurSection, "");
|
||||||
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
|
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GlobalValue::AppendingLinkage:
|
case GlobalValue::AppendingLinkage:
|
||||||
// FIXME: appending linkage variables should go into a section of
|
// FIXME: appending linkage variables should go into a section of
|
||||||
// their name or something. For now, just emit them as external.
|
// their name or something. For now, just emit them as external.
|
||||||
@ -645,6 +657,16 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output stubs for link-once variables
|
||||||
|
if (LinkOnceStubs.begin() != LinkOnceStubs.end())
|
||||||
|
O << ".data\n.align 2\n";
|
||||||
|
for (std::set<std::string>::iterator i = LinkOnceStubs.begin(),
|
||||||
|
e = LinkOnceStubs.end(); i != e; ++i)
|
||||||
|
{
|
||||||
|
O << *i << "$non_lazy_ptr:\n"
|
||||||
|
<< "\t.long\t" << *i << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
// Output stubs for dynamically-linked functions
|
// Output stubs for dynamically-linked functions
|
||||||
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
||||||
i != e; ++i)
|
i != e; ++i)
|
||||||
|
@ -52,7 +52,7 @@ namespace {
|
|||||||
/// Name-mangler for global names.
|
/// Name-mangler for global names.
|
||||||
///
|
///
|
||||||
Mangler *Mang;
|
Mangler *Mang;
|
||||||
std::set<std::string> FnStubs, GVStubs;
|
std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
|
||||||
std::set<std::string> Strings;
|
std::set<std::string> Strings;
|
||||||
|
|
||||||
Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0)
|
Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0)
|
||||||
@ -331,7 +331,12 @@ void Printer::emitGlobalConstant(const Constant *CV) {
|
|||||||
case Type::FloatTyID: case Type::DoubleTyID:
|
case Type::FloatTyID: case Type::DoubleTyID:
|
||||||
assert (0 && "Should have already output floating point constant.");
|
assert (0 && "Should have already output floating point constant.");
|
||||||
default:
|
default:
|
||||||
assert (0 && "Can't handle printing this type of thing");
|
if (CV == Constant::getNullValue(type)) { // Zero initializer?
|
||||||
|
O << ".space\t" << TD.getTypeSize(type) << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::cerr << "Can't handle printing: " << *CV;
|
||||||
|
abort();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
O << "\t";
|
O << "\t";
|
||||||
@ -413,8 +418,11 @@ void Printer::printOp(const MachineOperand &MO,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_SignExtendedImmed:
|
case MachineOperand::MO_SignExtendedImmed:
|
||||||
|
O << (short)MO.getImmedValue();
|
||||||
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_UnextendedImmed:
|
case MachineOperand::MO_UnextendedImmed:
|
||||||
O << (int)MO.getImmedValue();
|
O << (unsigned short)MO.getImmedValue();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_PCRelativeDisp:
|
case MachineOperand::MO_PCRelativeDisp:
|
||||||
@ -601,9 +609,8 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
unsigned Size = TD.getTypeSize(C->getType());
|
unsigned Size = TD.getTypeSize(C->getType());
|
||||||
unsigned Align = TD.getTypeAlignment(C->getType());
|
unsigned Align = TD.getTypeAlignment(C->getType());
|
||||||
|
|
||||||
if (C->isNullValue() &&
|
if (C->isNullValue() && /* FIXME: Verify correct */
|
||||||
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
|
(I->hasInternalLinkage() || I->hasWeakLinkage())) {
|
||||||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
|
|
||||||
SwitchSection(O, CurSection, ".data");
|
SwitchSection(O, CurSection, ".data");
|
||||||
if (I->hasInternalLinkage())
|
if (I->hasInternalLinkage())
|
||||||
O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType())
|
O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType())
|
||||||
@ -616,13 +623,18 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
} else {
|
} else {
|
||||||
switch (I->getLinkage()) {
|
switch (I->getLinkage()) {
|
||||||
case GlobalValue::LinkOnceLinkage:
|
case GlobalValue::LinkOnceLinkage:
|
||||||
|
O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n"
|
||||||
|
<< ".weak_definition " << name << '\n'
|
||||||
|
<< ".private_extern " << name << '\n'
|
||||||
|
<< ".section __DATA,__datacoal_nt,coalesced,no_toc\n";
|
||||||
|
LinkOnceStubs.insert(name);
|
||||||
|
break;
|
||||||
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
||||||
// Nonnull linkonce -> weak
|
// Nonnull linkonce -> weak
|
||||||
O << "\t.weak " << name << "\n";
|
O << "\t.weak " << name << "\n";
|
||||||
SwitchSection(O, CurSection, "");
|
SwitchSection(O, CurSection, "");
|
||||||
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
|
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GlobalValue::AppendingLinkage:
|
case GlobalValue::AppendingLinkage:
|
||||||
// FIXME: appending linkage variables should go into a section of
|
// FIXME: appending linkage variables should go into a section of
|
||||||
// their name or something. For now, just emit them as external.
|
// their name or something. For now, just emit them as external.
|
||||||
@ -645,6 +657,16 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output stubs for link-once variables
|
||||||
|
if (LinkOnceStubs.begin() != LinkOnceStubs.end())
|
||||||
|
O << ".data\n.align 2\n";
|
||||||
|
for (std::set<std::string>::iterator i = LinkOnceStubs.begin(),
|
||||||
|
e = LinkOnceStubs.end(); i != e; ++i)
|
||||||
|
{
|
||||||
|
O << *i << "$non_lazy_ptr:\n"
|
||||||
|
<< "\t.long\t" << *i << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
// Output stubs for dynamically-linked functions
|
// Output stubs for dynamically-linked functions
|
||||||
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
||||||
i != e; ++i)
|
i != e; ++i)
|
||||||
|
@ -52,7 +52,7 @@ namespace {
|
|||||||
/// Name-mangler for global names.
|
/// Name-mangler for global names.
|
||||||
///
|
///
|
||||||
Mangler *Mang;
|
Mangler *Mang;
|
||||||
std::set<std::string> FnStubs, GVStubs;
|
std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
|
||||||
std::set<std::string> Strings;
|
std::set<std::string> Strings;
|
||||||
|
|
||||||
Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0)
|
Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0)
|
||||||
@ -331,7 +331,12 @@ void Printer::emitGlobalConstant(const Constant *CV) {
|
|||||||
case Type::FloatTyID: case Type::DoubleTyID:
|
case Type::FloatTyID: case Type::DoubleTyID:
|
||||||
assert (0 && "Should have already output floating point constant.");
|
assert (0 && "Should have already output floating point constant.");
|
||||||
default:
|
default:
|
||||||
assert (0 && "Can't handle printing this type of thing");
|
if (CV == Constant::getNullValue(type)) { // Zero initializer?
|
||||||
|
O << ".space\t" << TD.getTypeSize(type) << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::cerr << "Can't handle printing: " << *CV;
|
||||||
|
abort();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
O << "\t";
|
O << "\t";
|
||||||
@ -413,8 +418,11 @@ void Printer::printOp(const MachineOperand &MO,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_SignExtendedImmed:
|
case MachineOperand::MO_SignExtendedImmed:
|
||||||
|
O << (short)MO.getImmedValue();
|
||||||
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_UnextendedImmed:
|
case MachineOperand::MO_UnextendedImmed:
|
||||||
O << (int)MO.getImmedValue();
|
O << (unsigned short)MO.getImmedValue();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case MachineOperand::MO_PCRelativeDisp:
|
case MachineOperand::MO_PCRelativeDisp:
|
||||||
@ -601,9 +609,8 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
unsigned Size = TD.getTypeSize(C->getType());
|
unsigned Size = TD.getTypeSize(C->getType());
|
||||||
unsigned Align = TD.getTypeAlignment(C->getType());
|
unsigned Align = TD.getTypeAlignment(C->getType());
|
||||||
|
|
||||||
if (C->isNullValue() &&
|
if (C->isNullValue() && /* FIXME: Verify correct */
|
||||||
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
|
(I->hasInternalLinkage() || I->hasWeakLinkage())) {
|
||||||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
|
|
||||||
SwitchSection(O, CurSection, ".data");
|
SwitchSection(O, CurSection, ".data");
|
||||||
if (I->hasInternalLinkage())
|
if (I->hasInternalLinkage())
|
||||||
O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType())
|
O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType())
|
||||||
@ -616,13 +623,18 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
} else {
|
} else {
|
||||||
switch (I->getLinkage()) {
|
switch (I->getLinkage()) {
|
||||||
case GlobalValue::LinkOnceLinkage:
|
case GlobalValue::LinkOnceLinkage:
|
||||||
|
O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n"
|
||||||
|
<< ".weak_definition " << name << '\n'
|
||||||
|
<< ".private_extern " << name << '\n'
|
||||||
|
<< ".section __DATA,__datacoal_nt,coalesced,no_toc\n";
|
||||||
|
LinkOnceStubs.insert(name);
|
||||||
|
break;
|
||||||
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
||||||
// Nonnull linkonce -> weak
|
// Nonnull linkonce -> weak
|
||||||
O << "\t.weak " << name << "\n";
|
O << "\t.weak " << name << "\n";
|
||||||
SwitchSection(O, CurSection, "");
|
SwitchSection(O, CurSection, "");
|
||||||
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
|
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GlobalValue::AppendingLinkage:
|
case GlobalValue::AppendingLinkage:
|
||||||
// FIXME: appending linkage variables should go into a section of
|
// FIXME: appending linkage variables should go into a section of
|
||||||
// their name or something. For now, just emit them as external.
|
// their name or something. For now, just emit them as external.
|
||||||
@ -645,6 +657,16 @@ bool Printer::doFinalization(Module &M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output stubs for link-once variables
|
||||||
|
if (LinkOnceStubs.begin() != LinkOnceStubs.end())
|
||||||
|
O << ".data\n.align 2\n";
|
||||||
|
for (std::set<std::string>::iterator i = LinkOnceStubs.begin(),
|
||||||
|
e = LinkOnceStubs.end(); i != e; ++i)
|
||||||
|
{
|
||||||
|
O << *i << "$non_lazy_ptr:\n"
|
||||||
|
<< "\t.long\t" << *i << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
// Output stubs for dynamically-linked functions
|
// Output stubs for dynamically-linked functions
|
||||||
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
||||||
i != e; ++i)
|
i != e; ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user