mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-23 14:25:07 +00:00
streamerize the rest of PIC16 asm printer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100317 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "llvm/Target/TargetLoweringObjectFile.h"
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/FormattedStream.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -44,8 +45,11 @@ PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PIC16AsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
void PIC16AsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||||
printInstruction(MI, O);
|
SmallString<128> Str;
|
||||||
OutStreamer.AddBlankLine();
|
raw_svector_ostream OS(Str);
|
||||||
|
printInstruction(MI, OS);
|
||||||
|
|
||||||
|
OutStreamer.EmitRawText(OS.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getFunctionColor(const Function *F) {
|
static int getFunctionColor(const Function *F) {
|
||||||
@@ -111,33 +115,33 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
PAN::isISR(F->getSection()));
|
PAN::isISR(F->getSection()));
|
||||||
|
|
||||||
// Start the Code Section.
|
// Start the Code Section.
|
||||||
O << "\n";
|
|
||||||
OutStreamer.SwitchSection(fCodeSection);
|
OutStreamer.SwitchSection(fCodeSection);
|
||||||
|
|
||||||
// Emit the frame address of the function at the beginning of code.
|
// Emit the frame address of the function at the beginning of code.
|
||||||
O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnSym->getName()) << ")\n";
|
OutStreamer.EmitRawText("\tretlw low(" +
|
||||||
O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnSym->getName()) << ")\n";
|
Twine(PAN::getFrameLabel(CurrentFnSym->getName())) +
|
||||||
|
")");
|
||||||
|
OutStreamer.EmitRawText("\tretlw high(" +
|
||||||
|
Twine(PAN::getFrameLabel(CurrentFnSym->getName())) +
|
||||||
|
")");
|
||||||
|
|
||||||
// Emit function start label.
|
// Emit function start label.
|
||||||
O << *CurrentFnSym << ":\n";
|
OutStreamer.EmitLabel(CurrentFnSym);
|
||||||
|
|
||||||
DebugLoc CurDL;
|
DebugLoc CurDL;
|
||||||
O << "\n";
|
|
||||||
// Print out code for the function.
|
// Print out code for the function.
|
||||||
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
|
|
||||||
// Print a label for the basic block.
|
// Print a label for the basic block.
|
||||||
if (I != MF.begin()) {
|
if (I != MF.begin())
|
||||||
EmitBasicBlockStart(I);
|
EmitBasicBlockStart(I);
|
||||||
}
|
|
||||||
|
|
||||||
// Print a basic block.
|
// Print a basic block.
|
||||||
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
||||||
II != E; ++II) {
|
II != E; ++II) {
|
||||||
|
|
||||||
// Emit the line directive if source line changed.
|
// Emit the line directive if source line changed.
|
||||||
const DebugLoc DL = II->getDebugLoc();
|
DebugLoc DL = II->getDebugLoc();
|
||||||
if (!DL.isUnknown() && DL != CurDL) {
|
if (!DL.isUnknown() && DL != CurDL) {
|
||||||
DbgInfo.ChangeDebugLoc(MF, DL);
|
DbgInfo.ChangeDebugLoc(MF, DL);
|
||||||
CurDL = DL;
|
CurDL = DL;
|
||||||
@@ -228,13 +232,15 @@ void PIC16AsmPrinter::printLibcallDecls() {
|
|||||||
// If no libcalls used, return.
|
// If no libcalls used, return.
|
||||||
if (LibcallDecls.empty()) return;
|
if (LibcallDecls.empty()) return;
|
||||||
|
|
||||||
O << MAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
|
OutStreamer.AddComment("External decls for libcalls - BEGIN");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
|
|
||||||
for (std::set<std::string>::const_iterator I = LibcallDecls.begin(),
|
for (std::set<std::string>::const_iterator I = LibcallDecls.begin(),
|
||||||
E = LibcallDecls.end(); I != E; I++) {
|
E = LibcallDecls.end(); I != E; I++)
|
||||||
O << MAI->getExternDirective() << *I << "\n";
|
OutStreamer.EmitRawText(MAI->getExternDirective() + Twine(*I));
|
||||||
}
|
|
||||||
O << MAI->getCommentString() << "External decls for libcalls - END." <<"\n";
|
OutStreamer.AddComment("External decls for libcalls - END");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// doInitialization - Perform Module level initializations here.
|
/// doInitialization - Perform Module level initializations here.
|
||||||
@@ -245,8 +251,8 @@ bool PIC16AsmPrinter::doInitialization(Module &M) {
|
|||||||
bool Result = AsmPrinter::doInitialization(M);
|
bool Result = AsmPrinter::doInitialization(M);
|
||||||
|
|
||||||
// Every asmbly contains these std headers.
|
// Every asmbly contains these std headers.
|
||||||
O << "\n#include p16f1xxx.inc";
|
OutStreamer.EmitRawText(StringRef("\n#include p16f1xxx.inc"));
|
||||||
O << "\n#include stdmacros.inc";
|
OutStreamer.EmitRawText(StringRef("#include stdmacros.inc"));
|
||||||
|
|
||||||
// Set the section names for all globals.
|
// Set the section names for all globals.
|
||||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||||
@@ -289,7 +295,8 @@ bool PIC16AsmPrinter::doInitialization(Module &M) {
|
|||||||
///
|
///
|
||||||
void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
|
void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
|
||||||
// Emit declarations for external functions.
|
// Emit declarations for external functions.
|
||||||
O <<"\n"<<MAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
|
OutStreamer.AddComment("Function Declarations - BEGIN");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
|
||||||
if (I->isIntrinsic() || I->getName() == "@abort")
|
if (I->isIntrinsic() || I->getName() == "@abort")
|
||||||
continue;
|
continue;
|
||||||
@@ -312,12 +319,16 @@ void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
|
|||||||
const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
|
const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
|
||||||
MAI->getGlobalDirective();
|
MAI->getGlobalDirective();
|
||||||
|
|
||||||
O << directive << Sym->getName() << "\n";
|
OutStreamer.EmitRawText(directive + Twine(Sym->getName()));
|
||||||
O << directive << PAN::getRetvalLabel(Sym->getName()) << "\n";
|
OutStreamer.EmitRawText(directive +
|
||||||
O << directive << PAN::getArgsLabel(Sym->getName()) << "\n";
|
Twine(PAN::getRetvalLabel(Sym->getName())));
|
||||||
|
OutStreamer.EmitRawText(directive +
|
||||||
|
Twine(PAN::getArgsLabel(Sym->getName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
O << MAI->getCommentString() << "Function Declarations - END." <<"\n";
|
OutStreamer.AddComment("Function Declarations - END");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit variables imported from other Modules.
|
// Emit variables imported from other Modules.
|
||||||
@@ -325,10 +336,14 @@ void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
|
|||||||
std::vector<const GlobalVariable*> Items = ExternalVarDecls;
|
std::vector<const GlobalVariable*> Items = ExternalVarDecls;
|
||||||
if (!Items.size()) return;
|
if (!Items.size()) return;
|
||||||
|
|
||||||
O << "\n" << MAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
|
OutStreamer.AddComment("Imported Variables - BEGIN");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
for (unsigned j = 0; j < Items.size(); j++)
|
for (unsigned j = 0; j < Items.size(); j++)
|
||||||
O << MAI->getExternDirective() << *Mang->getSymbol(Items[j]) << "\n";
|
OutStreamer.EmitRawText(MAI->getExternDirective() +
|
||||||
O << MAI->getCommentString() << "Imported Variables - END" << "\n";
|
Twine(Mang->getSymbol(Items[j])->getName()));
|
||||||
|
|
||||||
|
OutStreamer.AddComment("Imported Variables - END");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit variables defined in this module and are available to other modules.
|
// Emit variables defined in this module and are available to other modules.
|
||||||
@@ -336,10 +351,14 @@ void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
|
|||||||
std::vector<const GlobalVariable*> Items = ExternalVarDefs;
|
std::vector<const GlobalVariable*> Items = ExternalVarDefs;
|
||||||
if (!Items.size()) return;
|
if (!Items.size()) return;
|
||||||
|
|
||||||
O << "\n" << MAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
|
OutStreamer.AddComment("Exported Variables - BEGIN");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
|
|
||||||
for (unsigned j = 0; j < Items.size(); j++)
|
for (unsigned j = 0; j < Items.size(); j++)
|
||||||
O << MAI->getGlobalDirective() << *Mang->getSymbol(Items[j]) << "\n";
|
OutStreamer.EmitRawText(MAI->getGlobalDirective() +
|
||||||
O << MAI->getCommentString() << "Exported Variables - END" << "\n";
|
Twine(Mang->getSymbol(Items[j])->getName()));
|
||||||
|
OutStreamer.AddComment("Exported Variables - END");
|
||||||
|
OutStreamer.AddBlankLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit initialized data placed in ROM.
|
// Emit initialized data placed in ROM.
|
||||||
@@ -356,7 +375,7 @@ bool PIC16AsmPrinter::doFinalization(Module &M) {
|
|||||||
EmitAllAutos(M);
|
EmitAllAutos(M);
|
||||||
printLibcallDecls();
|
printLibcallDecls();
|
||||||
DbgInfo.EndModule(M);
|
DbgInfo.EndModule(M);
|
||||||
O << "\n\t" << "END\n";
|
OutStreamer.EmitRawText(StringRef("\tEND"));
|
||||||
return AsmPrinter::doFinalization(M);
|
return AsmPrinter::doFinalization(M);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +383,6 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
|
|||||||
const Function *F = MF.getFunction();
|
const Function *F = MF.getFunction();
|
||||||
const TargetData *TD = TM.getTargetData();
|
const TargetData *TD = TM.getTargetData();
|
||||||
// Emit the data section name.
|
// Emit the data section name.
|
||||||
O << "\n";
|
|
||||||
|
|
||||||
PIC16Section *fPDataSection =
|
PIC16Section *fPDataSection =
|
||||||
const_cast<PIC16Section *>(getObjFileLowering().
|
const_cast<PIC16Section *>(getObjFileLowering().
|
||||||
@@ -374,7 +392,8 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
|
|||||||
OutStreamer.SwitchSection(fPDataSection);
|
OutStreamer.SwitchSection(fPDataSection);
|
||||||
|
|
||||||
// Emit function frame label
|
// Emit function frame label
|
||||||
O << PAN::getFrameLabel(CurrentFnSym->getName()) << ":\n";
|
OutStreamer.EmitRawText(PAN::getFrameLabel(CurrentFnSym->getName()) +
|
||||||
|
Twine(":"));
|
||||||
|
|
||||||
const Type *RetType = F->getReturnType();
|
const Type *RetType = F->getReturnType();
|
||||||
unsigned RetSize = 0;
|
unsigned RetSize = 0;
|
||||||
@@ -386,10 +405,11 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
|
|||||||
// we will need to avoid printing a global directive for Retval label
|
// we will need to avoid printing a global directive for Retval label
|
||||||
// in emitExternandGloblas.
|
// in emitExternandGloblas.
|
||||||
if(RetSize > 0)
|
if(RetSize > 0)
|
||||||
O << PAN::getRetvalLabel(CurrentFnSym->getName())
|
OutStreamer.EmitRawText(PAN::getRetvalLabel(CurrentFnSym->getName()) +
|
||||||
<< " RES " << RetSize << "\n";
|
Twine(" RES ") + Twine(RetSize));
|
||||||
else
|
else
|
||||||
O << PAN::getRetvalLabel(CurrentFnSym->getName()) << ": \n";
|
OutStreamer.EmitRawText(PAN::getRetvalLabel(CurrentFnSym->getName()) +
|
||||||
|
Twine(":"));
|
||||||
|
|
||||||
// Emit variable to hold the space for function arguments
|
// Emit variable to hold the space for function arguments
|
||||||
unsigned ArgSize = 0;
|
unsigned ArgSize = 0;
|
||||||
@@ -399,13 +419,14 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
|
|||||||
ArgSize += TD->getTypeAllocSize(Ty);
|
ArgSize += TD->getTypeAllocSize(Ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
O << PAN::getArgsLabel(CurrentFnSym->getName()) << " RES " << ArgSize << "\n";
|
OutStreamer.EmitRawText(PAN::getArgsLabel(CurrentFnSym->getName()) +
|
||||||
|
Twine(" RES ") + Twine(ArgSize));
|
||||||
|
|
||||||
// Emit temporary space
|
// Emit temporary space
|
||||||
int TempSize = PTLI->GetTmpSize();
|
int TempSize = PTLI->GetTmpSize();
|
||||||
if (TempSize > 0)
|
if (TempSize > 0)
|
||||||
O << PAN::getTempdataLabel(CurrentFnSym->getName()) << " RES "
|
OutStreamer.EmitRawText(PAN::getTempdataLabel(CurrentFnSym->getName()) +
|
||||||
<< TempSize << '\n';
|
Twine(" RES ") + Twine(TempSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -417,7 +438,7 @@ void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) {
|
|||||||
for (unsigned j = 0; j < Items.size(); j++) {
|
for (unsigned j = 0; j < Items.size(); j++) {
|
||||||
Constant *C = Items[j]->getInitializer();
|
Constant *C = Items[j]->getInitializer();
|
||||||
int AddrSpace = Items[j]->getType()->getAddressSpace();
|
int AddrSpace = Items[j]->getType()->getAddressSpace();
|
||||||
O << *Mang->getSymbol(Items[j]);
|
OutStreamer.EmitRawText(Mang->getSymbol(Items[j])->getName());
|
||||||
EmitGlobalConstant(C, AddrSpace);
|
EmitGlobalConstant(C, AddrSpace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,7 +457,8 @@ EmitUninitializedDataSection(const PIC16Section *S) {
|
|||||||
Constant *C = Items[j]->getInitializer();
|
Constant *C = Items[j]->getInitializer();
|
||||||
const Type *Ty = C->getType();
|
const Type *Ty = C->getType();
|
||||||
unsigned Size = TD->getTypeAllocSize(Ty);
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
||||||
O << *Mang->getSymbol(Items[j]) << " RES " << Size << "\n";
|
OutStreamer.EmitRawText(Mang->getSymbol(Items[j])->getName() +
|
||||||
|
Twine(" RES ") + Twine(Size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,7 +506,7 @@ EmitSectionList(Module &M, const std::vector<PIC16Section *> &SList) {
|
|||||||
// Exclude llvm specific metadata sections.
|
// Exclude llvm specific metadata sections.
|
||||||
if (SList[i]->getName().find("llvm.") != std::string::npos)
|
if (SList[i]->getName().find("llvm.") != std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
O << "\n";
|
OutStreamer.AddBlankLine();
|
||||||
EmitSingleSection(SList[i]);
|
EmitSingleSection(SList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user