mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-29 13:24:25 +00:00
Some preliminary variable asmprinting
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86381 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -22,6 +22,7 @@
|
|||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include "llvm/CodeGen/AsmPrinter.h"
|
#include "llvm/CodeGen/AsmPrinter.h"
|
||||||
#include "llvm/CodeGen/DwarfWriter.h"
|
#include "llvm/CodeGen/DwarfWriter.h"
|
||||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||||
@ -79,13 +80,10 @@ namespace {
|
|||||||
const char *ExtraCode);
|
const char *ExtraCode);
|
||||||
void printInstructionThroughMCStreamer(const MachineInstr *MI);
|
void printInstructionThroughMCStreamer(const MachineInstr *MI);
|
||||||
|
|
||||||
|
void PrintGlobalVariable(const GlobalVariable* GVar);
|
||||||
void emitFunctionHeader(const MachineFunction &MF);
|
void emitFunctionHeader(const MachineFunction &MF);
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
bool runOnMachineFunction(MachineFunction &F);
|
||||||
|
|
||||||
virtual void PrintGlobalVariable(const GlobalVariable *GV) {
|
|
||||||
// FIXME: No support for global variables?
|
|
||||||
}
|
|
||||||
|
|
||||||
void getAnalysisUsage(AnalysisUsage &AU) const {
|
void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AsmPrinter::getAnalysisUsage(AU);
|
AsmPrinter::getAnalysisUsage(AU);
|
||||||
AU.setPreservesAll();
|
AU.setPreservesAll();
|
||||||
@ -93,6 +91,90 @@ namespace {
|
|||||||
};
|
};
|
||||||
} // end of anonymous 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) {
|
void MSP430AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
||||||
const Function *F = MF.getFunction();
|
const Function *F = MF.getFunction();
|
||||||
|
|
||||||
|
@ -15,7 +15,12 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
MSP430MCAsmInfo::MSP430MCAsmInfo(const Target &T, const StringRef &TT) {
|
MSP430MCAsmInfo::MSP430MCAsmInfo(const Target &T, const StringRef &TT) {
|
||||||
|
PrivateGlobalPrefix = ".L";
|
||||||
|
WeakRefDirective ="\t.weak\t";
|
||||||
|
SetDirective = "\t.set\t";
|
||||||
|
PCSymbol=".";
|
||||||
|
|
||||||
AlignmentIsInBytes = false;
|
AlignmentIsInBytes = false;
|
||||||
AllowNameToStartWithDigit = true;
|
AllowNameToStartWithDigit = true;
|
||||||
PrivateGlobalPrefix = ".L";
|
UsesELFSectionDirectiveForBSS = true;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ available pretty soon.
|
|||||||
Some things are incomplete / not implemented yet (this list surely is not
|
Some things are incomplete / not implemented yet (this list surely is not
|
||||||
complete as well):
|
complete as well):
|
||||||
|
|
||||||
0. Implement asmprinting for variables :)
|
|
||||||
|
|
||||||
1. Verify, how stuff is handling implicit zext with 8 bit operands (this might
|
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
|
be modelled currently in improper way - should we need to mark the superreg as
|
||||||
def for every 8 bit instruction?).
|
def for every 8 bit instruction?).
|
||||||
|
Reference in New Issue
Block a user