summaryrefslogtreecommitdiffstats
path: root/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp')
-rw-r--r--lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp121
1 files changed, 70 insertions, 51 deletions
diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
index 1001d29..c46db46 100644
--- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
+++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
@@ -19,9 +19,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
-#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
@@ -29,23 +27,26 @@
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/ADT/SmallString.h"
#include <cstring>
using namespace llvm;
#include "PIC16GenAsmWriter.inc"
-PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
- MCStreamer &Streamer)
-: AsmPrinter(O, TM, Streamer), DbgInfo(O, TM.getMCAsmInfo()) {
+PIC16AsmPrinter::PIC16AsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
+: AsmPrinter(TM, Streamer), DbgInfo(Streamer, TM.getMCAsmInfo()) {
PTLI = static_cast<PIC16TargetLowering*>(TM.getTargetLowering());
PMAI = static_cast<const PIC16MCAsmInfo*>(TM.getMCAsmInfo());
PTOF = (PIC16TargetObjectFile *)&PTLI->getObjFileLowering();
}
void PIC16AsmPrinter::EmitInstruction(const MachineInstr *MI) {
- printInstruction(MI);
- OutStreamer.AddBlankLine();
+ SmallString<128> Str;
+ raw_svector_ostream OS(Str);
+ printInstruction(MI, OS);
+
+ OutStreamer.EmitRawText(OS.str());
}
static int getFunctionColor(const Function *F) {
@@ -111,33 +112,33 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
PAN::isISR(F->getSection()));
// Start the Code Section.
- O << "\n";
OutStreamer.SwitchSection(fCodeSection);
// Emit the frame address of the function at the beginning of code.
- O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnSym->getName()) << ")\n";
- O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnSym->getName()) << ")\n";
+ OutStreamer.EmitRawText("\tretlw low(" +
+ Twine(PAN::getFrameLabel(CurrentFnSym->getName())) +
+ ")");
+ OutStreamer.EmitRawText("\tretlw high(" +
+ Twine(PAN::getFrameLabel(CurrentFnSym->getName())) +
+ ")");
// Emit function start label.
- O << *CurrentFnSym << ":\n";
+ OutStreamer.EmitLabel(CurrentFnSym);
DebugLoc CurDL;
- O << "\n";
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
I != E; ++I) {
// Print a label for the basic block.
- if (I != MF.begin()) {
+ if (I != MF.begin())
EmitBasicBlockStart(I);
- }
// Print a basic block.
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) {
-
// Emit the line directive if source line changed.
- const DebugLoc DL = II->getDebugLoc();
+ DebugLoc DL = II->getDebugLoc();
if (!DL.isUnknown() && DL != CurDL) {
DbgInfo.ChangeDebugLoc(MF, DL);
CurDL = DL;
@@ -156,7 +157,8 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// printOperand - print operand of insn.
-void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
+void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum,
+ raw_ostream &O) {
const MachineOperand &MO = MI->getOperand(opNum);
const Function *F = MI->getParent()->getParent()->getFunction();
@@ -167,9 +169,7 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
std::string RegName = getRegisterName(MO.getReg());
if ((MI->getOpcode() == PIC16::load_indirect) ||
(MI->getOpcode() == PIC16::store_indirect))
- {
RegName.replace (0, 3, "INDF");
- }
O << RegName;
}
return;
@@ -216,7 +216,8 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
/// printCCOperand - Print the cond code operand.
///
-void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
+void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum,
+ raw_ostream &O) {
int CC = (int)MI->getOperand(opNum).getImm();
O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
}
@@ -228,13 +229,15 @@ void PIC16AsmPrinter::printLibcallDecls() {
// If no libcalls used, 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(),
- E = LibcallDecls.end(); I != E; I++) {
- O << MAI->getExternDirective() << *I << "\n";
- }
- O << MAI->getCommentString() << "External decls for libcalls - END." <<"\n";
+ E = LibcallDecls.end(); I != E; I++)
+ OutStreamer.EmitRawText(MAI->getExternDirective() + Twine(*I));
+
+ OutStreamer.AddComment("External decls for libcalls - END");
+ OutStreamer.AddBlankLine();
}
/// doInitialization - Perform Module level initializations here.
@@ -245,8 +248,8 @@ bool PIC16AsmPrinter::doInitialization(Module &M) {
bool Result = AsmPrinter::doInitialization(M);
// Every asmbly contains these std headers.
- O << "\n#include p16f1xxx.inc";
- O << "\n#include stdmacros.inc";
+ OutStreamer.EmitRawText(StringRef("\n#include p16f1xxx.inc"));
+ OutStreamer.EmitRawText(StringRef("#include stdmacros.inc"));
// Set the section names for all globals.
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
@@ -289,7 +292,8 @@ bool PIC16AsmPrinter::doInitialization(Module &M) {
///
void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
// 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++) {
if (I->isIntrinsic() || I->getName() == "@abort")
continue;
@@ -312,12 +316,16 @@ void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
MAI->getGlobalDirective();
- O << directive << Sym->getName() << "\n";
- O << directive << PAN::getRetvalLabel(Sym->getName()) << "\n";
- O << directive << PAN::getArgsLabel(Sym->getName()) << "\n";
+ OutStreamer.EmitRawText(directive + Twine(Sym->getName()));
+ OutStreamer.EmitRawText(directive +
+ 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.
@@ -325,10 +333,14 @@ void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
std::vector<const GlobalVariable*> Items = ExternalVarDecls;
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++)
- O << MAI->getExternDirective() << *Mang->getSymbol(Items[j]) << "\n";
- O << MAI->getCommentString() << "Imported Variables - END" << "\n";
+ OutStreamer.EmitRawText(MAI->getExternDirective() +
+ 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.
@@ -336,10 +348,14 @@ void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
std::vector<const GlobalVariable*> Items = ExternalVarDefs;
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++)
- O << MAI->getGlobalDirective() << *Mang->getSymbol(Items[j]) << "\n";
- O << MAI->getCommentString() << "Exported Variables - END" << "\n";
+ OutStreamer.EmitRawText(MAI->getGlobalDirective() +
+ Twine(Mang->getSymbol(Items[j])->getName()));
+ OutStreamer.AddComment("Exported Variables - END");
+ OutStreamer.AddBlankLine();
}
// Emit initialized data placed in ROM.
@@ -356,7 +372,7 @@ bool PIC16AsmPrinter::doFinalization(Module &M) {
EmitAllAutos(M);
printLibcallDecls();
DbgInfo.EndModule(M);
- O << "\n\t" << "END\n";
+ OutStreamer.EmitRawText(StringRef("\tEND"));
return AsmPrinter::doFinalization(M);
}
@@ -364,7 +380,6 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
const Function *F = MF.getFunction();
const TargetData *TD = TM.getTargetData();
// Emit the data section name.
- O << "\n";
PIC16Section *fPDataSection =
const_cast<PIC16Section *>(getObjFileLowering().
@@ -374,7 +389,8 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
OutStreamer.SwitchSection(fPDataSection);
// Emit function frame label
- O << PAN::getFrameLabel(CurrentFnSym->getName()) << ":\n";
+ OutStreamer.EmitRawText(PAN::getFrameLabel(CurrentFnSym->getName()) +
+ Twine(":"));
const Type *RetType = F->getReturnType();
unsigned RetSize = 0;
@@ -386,10 +402,11 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
// we will need to avoid printing a global directive for Retval label
// in emitExternandGloblas.
if(RetSize > 0)
- O << PAN::getRetvalLabel(CurrentFnSym->getName())
- << " RES " << RetSize << "\n";
+ OutStreamer.EmitRawText(PAN::getRetvalLabel(CurrentFnSym->getName()) +
+ Twine(" RES ") + Twine(RetSize));
else
- O << PAN::getRetvalLabel(CurrentFnSym->getName()) << ": \n";
+ OutStreamer.EmitRawText(PAN::getRetvalLabel(CurrentFnSym->getName()) +
+ Twine(":"));
// Emit variable to hold the space for function arguments
unsigned ArgSize = 0;
@@ -399,13 +416,14 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
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
int TempSize = PTLI->GetTmpSize();
if (TempSize > 0)
- O << PAN::getTempdataLabel(CurrentFnSym->getName()) << " RES "
- << TempSize << '\n';
+ OutStreamer.EmitRawText(PAN::getTempdataLabel(CurrentFnSym->getName()) +
+ Twine(" RES ") + Twine(TempSize));
}
@@ -417,7 +435,7 @@ void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) {
for (unsigned j = 0; j < Items.size(); j++) {
Constant *C = Items[j]->getInitializer();
int AddrSpace = Items[j]->getType()->getAddressSpace();
- O << *Mang->getSymbol(Items[j]);
+ OutStreamer.EmitRawText(Mang->getSymbol(Items[j])->getName());
EmitGlobalConstant(C, AddrSpace);
}
}
@@ -436,7 +454,8 @@ EmitUninitializedDataSection(const PIC16Section *S) {
Constant *C = Items[j]->getInitializer();
const Type *Ty = C->getType();
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 +503,7 @@ EmitSectionList(Module &M, const std::vector<PIC16Section *> &SList) {
// Exclude llvm specific metadata sections.
if (SList[i]->getName().find("llvm.") != std::string::npos)
continue;
- O << "\n";
+ OutStreamer.AddBlankLine();
EmitSingleSection(SList[i]);
}
}
OpenPOWER on IntegriCloud