1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Some preliminary variable asmprinting

llvm-svn: 86381
This commit is contained in:
Anton Korobeynikov 2009-11-07 17:12:58 +00:00
parent 8e023bc698
commit f72c6516bd
3 changed files with 92 additions and 7 deletions

View File

@ -22,6 +22,7 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
@ -79,13 +80,10 @@ namespace {
const char *ExtraCode);
void printInstructionThroughMCStreamer(const MachineInstr *MI);
void PrintGlobalVariable(const GlobalVariable* GVar);
void emitFunctionHeader(const MachineFunction &MF);
bool runOnMachineFunction(MachineFunction &F);
virtual void PrintGlobalVariable(const GlobalVariable *GV) {
// FIXME: No support for global variables?
}
void getAnalysisUsage(AnalysisUsage &AU) const {
AsmPrinter::getAnalysisUsage(AU);
AU.setPreservesAll();
@ -93,6 +91,90 @@ namespace {
};
} // end of anonymous namespace
void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
if (!GVar->hasInitializer())
return; // External global require no code
// Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(GVar))
return;
const TargetData *TD = TM.getTargetData();
std::string name = Mang->getMangledName(GVar);
Constant *C = GVar->getInitializer();
unsigned Size = TD->getTypeAllocSize(C->getType());
unsigned Align = TD->getPreferredAlignmentLog(GVar);
printVisibility(name, GVar->getVisibility());
O << "\t.type\t" << name << ",@object\n";
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
TM));
if (C->isNullValue() && !GVar->hasSection() &&
!GVar->isThreadLocal() &&
(GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasLocalLinkage())
O << "\t.local\t" << name << '\n';
O << MAI->getCOMMDirective() << name << ',' << Size;
if (MAI->getCOMMDirectiveTakesAlignment())
O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
if (VerboseAsm) {
O.PadToColumn(MAI->getCommentColumn());
O << MAI->getCommentString() << ' ';
WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
}
O << '\n';
return;
}
switch (GVar->getLinkage()) {
case GlobalValue::CommonLinkage:
case GlobalValue::LinkOnceAnyLinkage:
case GlobalValue::LinkOnceODRLinkage:
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
O << "\t.weak\t" << name << '\n';
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
O << "\t.globl " << name << '\n';
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::LinkerPrivateLinkage:
case GlobalValue::InternalLinkage:
break;
default:
assert(0 && "Unknown linkage type!");
}
// Use 16-bit alignment by default to simplify bunch of stuff
EmitAlignment(Align, GVar);
O << name << ":";
if (VerboseAsm) {
O.PadToColumn(MAI->getCommentColumn());
O << MAI->getCommentString() << ' ';
WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
}
O << '\n';
EmitGlobalConstant(C);
if (MAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << name << ", " << Size << '\n';
}
void MSP430AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
const Function *F = MF.getFunction();

View File

@ -15,7 +15,12 @@
using namespace llvm;
MSP430MCAsmInfo::MSP430MCAsmInfo(const Target &T, const StringRef &TT) {
PrivateGlobalPrefix = ".L";
WeakRefDirective ="\t.weak\t";
SetDirective = "\t.set\t";
PCSymbol=".";
AlignmentIsInBytes = false;
AllowNameToStartWithDigit = true;
PrivateGlobalPrefix = ".L";
UsesELFSectionDirectiveForBSS = true;
}

View File

@ -11,8 +11,6 @@ available pretty soon.
Some things are incomplete / not implemented yet (this list surely is not
complete as well):
0. Implement asmprinting for variables :)
1. Verify, how stuff is handling implicit zext with 8 bit operands (this might
be modelled currently in improper way - should we need to mark the superreg as
def for every 8 bit instruction?).