diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-10-15 15:02:14 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-10-15 15:02:14 +0000 |
commit | 1ead150c92d07aceca9f139376cb647feb8ff355 (patch) | |
tree | bab63bcd10539b25ada12979d52cb24dbfe0d02b /lib/Target/PIC16/AsmPrinter | |
parent | 8da373cf62d8dfdbf5e8a7c226d8a67153fe0013 (diff) | |
download | llvm-1ead150c92d07aceca9f139376cb647feb8ff355.tar.gz llvm-1ead150c92d07aceca9f139376cb647feb8ff355.tar.bz2 llvm-1ead150c92d07aceca9f139376cb647feb8ff355.tar.xz |
Revert "Complete Rewrite of AsmPrinter, TargetObjectFile based on new
PIC16Section class", it breaks globals.ll.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84184 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PIC16/AsmPrinter')
-rw-r--r-- | lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp | 170 | ||||
-rw-r--r-- | lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h | 8 |
2 files changed, 95 insertions, 83 deletions
diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp index 1afd3ee4f2..3f415afc10 100644 --- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp +++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp @@ -12,9 +12,8 @@ // //===----------------------------------------------------------------------===// -#include "PIC16ABINames.h" #include "PIC16AsmPrinter.h" -#include "PIC16Section.h" +#include "MCSectionPIC16.h" #include "PIC16MCAsmInfo.h" #include "llvm/DerivedTypes.h" #include "llvm/Function.h" @@ -40,7 +39,7 @@ PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM, : AsmPrinter(O, TM, T, V), DbgInfo(O, T) { PTLI = static_cast<PIC16TargetLowering*>(TM.getTargetLowering()); PMAI = static_cast<const PIC16MCAsmInfo*>(T); - PTOF = (PIC16TargetObjectFile *)&PTLI->getObjFileLowering(); + PTOF = (PIC16TargetObjectFile*)&PTLI->getObjFileLowering(); } bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) { @@ -74,12 +73,11 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) { DbgInfo.BeginFunction(MF); // Emit the autos section of function. - // EmitAutos(CurrentFnName); + EmitAutos(CurrentFnName); // Now emit the instructions of function in its code section. - const MCSection *fCodeSection - = getObjFileLowering().SectionForCode(CurrentFnName); - + const MCSection *fCodeSection = + getObjFileLowering().getSectionForFunction(CurrentFnName); // Start the Code Section. O << "\n"; OutStreamer.SwitchSection(fCodeSection); @@ -231,26 +229,12 @@ bool PIC16AsmPrinter::doInitialization(Module &M) { // Set the section names for all globals. for (Module::global_iterator I = M.global_begin(), E = M.global_end(); - I != E; ++I) { - - // Record External Var Decls. - if (I->isDeclaration()) { - ExternalVarDecls.push_back(I); - continue; - } - - // Record Exteranl Var Defs. - if (I->hasExternalLinkage() || I->hasCommonLinkage()) { - ExternalVarDefs.push_back(I); - } - - // Sectionify actual data. - if (!I->hasAvailableExternallyLinkage()) { + I != E; ++I) + if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) { const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM); - I->setSection(((const PIC16Section *)S)->getName()); + I->setSection(((const MCSectionPIC16*)S)->getName()); } - } DbgInfo.BeginModule(M); EmitFunctionDecls(M); @@ -258,9 +242,7 @@ bool PIC16AsmPrinter::doInitialization(Module &M) { EmitDefinedVars(M); EmitIData(M); EmitUData(M); - EmitAllAutos(M); EmitRomData(M); - EmitUserSections(M); return Result; } @@ -305,7 +287,7 @@ void PIC16AsmPrinter::EmitFunctionDecls(Module &M) { // Emit variables imported from other Modules. void PIC16AsmPrinter::EmitUndefinedVars(Module &M) { - std::vector<const GlobalVariable*> Items = ExternalVarDecls; + std::vector<const GlobalVariable*> Items = PTOF->ExternalVarDecls->Items; if (!Items.size()) return; O << "\n" << MAI->getCommentString() << "Imported Variables - BEGIN" << "\n"; @@ -317,7 +299,7 @@ void PIC16AsmPrinter::EmitUndefinedVars(Module &M) { // Emit variables defined in this module and are available to other modules. void PIC16AsmPrinter::EmitDefinedVars(Module &M) { - std::vector<const GlobalVariable*> Items = ExternalVarDefs; + std::vector<const GlobalVariable*> Items = PTOF->ExternalVarDefs->Items; if (!Items.size()) return; O << "\n" << MAI->getCommentString() << "Exported Variables - BEGIN" << "\n"; @@ -330,14 +312,24 @@ void PIC16AsmPrinter::EmitDefinedVars(Module &M) { // Emit initialized data placed in ROM. void PIC16AsmPrinter::EmitRomData(Module &M) { // Print ROM Data section. - const PIC16Section *ROSection = PTOF->ROMDATASection(); - if (ROSection == NULL) return; - EmitInitializedDataSection(ROSection); + const std::vector<PIC16Section*> &ROSections = PTOF->ROSections; + for (unsigned i = 0; i < ROSections.size(); i++) { + const std::vector<const GlobalVariable*> &Items = ROSections[i]->Items; + if (!Items.size()) continue; + O << "\n"; + OutStreamer.SwitchSection(PTOF->ROSections[i]->S_); + for (unsigned j = 0; j < Items.size(); j++) { + O << Mang->getMangledName(Items[j]); + Constant *C = Items[j]->getInitializer(); + int AddrSpace = Items[j]->getType()->getAddressSpace(); + EmitGlobalConstant(C, AddrSpace); + } + } } bool PIC16AsmPrinter::doFinalization(Module &M) { printLibcallDecls(); - // EmitRemainingAutos(); + EmitRemainingAutos(); DbgInfo.EndModule(M); O << "\n\t" << "END\n"; return AsmPrinter::doFinalization(M); @@ -351,7 +343,7 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) { O << "\n"; const MCSection *fPDataSection = - getObjFileLowering().SectionForFrame(CurrentFnName); + getObjFileLowering().getSectionForFunctionFrame(CurrentFnName); OutStreamer.SwitchSection(fPDataSection); // Emit function frame label @@ -387,80 +379,104 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) { O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize << '\n'; } +void PIC16AsmPrinter::EmitIData(Module &M) { -void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) { - /// Emit Section header. - OutStreamer.SwitchSection(S); - - std::vector<const GlobalVariable*> Items = S->Items; + // Print all IDATA sections. + const std::vector<PIC16Section*> &IDATASections = PTOF->IDATASections; + for (unsigned i = 0; i < IDATASections.size(); i++) { + O << "\n"; + if (IDATASections[i]->S_->getName().find("llvm.") != std::string::npos) + continue; + OutStreamer.SwitchSection(IDATASections[i]->S_); + std::vector<const GlobalVariable*> Items = IDATASections[i]->Items; for (unsigned j = 0; j < Items.size(); j++) { std::string Name = Mang->getMangledName(Items[j]); Constant *C = Items[j]->getInitializer(); int AddrSpace = Items[j]->getType()->getAddressSpace(); O << Name; EmitGlobalConstant(C, AddrSpace); - } + } + } } -void PIC16AsmPrinter::EmitIData(Module &M) { +void PIC16AsmPrinter::EmitUData(Module &M) { + const TargetData *TD = TM.getTargetData(); - // Print all IDATA sections. - const std::vector<PIC16Section *> &IDATASections = PTOF->IDATASections(); - for (unsigned i = 0; i < IDATASections.size(); i++) { + // Print all BSS sections. + const std::vector<PIC16Section*> &BSSSections = PTOF->BSSSections; + for (unsigned i = 0; i < BSSSections.size(); i++) { O << "\n"; - if (IDATASections[i]->getName().find("llvm.") != std::string::npos) - continue; - - EmitInitializedDataSection(IDATASections[i]); - } -} - -void PIC16AsmPrinter::EmitUninitializedDataSection(const PIC16Section *S) { - const TargetData *TD = TM.getTargetData(); - OutStreamer.SwitchSection(S); - std::vector<const GlobalVariable*> Items = S->Items; + OutStreamer.SwitchSection(BSSSections[i]->S_); + std::vector<const GlobalVariable*> Items = BSSSections[i]->Items; for (unsigned j = 0; j < Items.size(); j++) { std::string Name = Mang->getMangledName(Items[j]); Constant *C = Items[j]->getInitializer(); const Type *Ty = C->getType(); unsigned Size = TD->getTypeAllocSize(Ty); + O << Name << " RES " << Size << "\n"; } -} - -void PIC16AsmPrinter::EmitUData(Module &M) { - // Print all UDATA sections. - const std::vector<PIC16Section*> &UDATASections = PTOF->UDATASections(); - for (unsigned i = 0; i < UDATASections.size(); i++) { - O << "\n"; - EmitUninitializedDataSection(UDATASections[i]); } } -void PIC16AsmPrinter::EmitUserSections(Module &M) { - const std::vector<PIC16Section*> &USERSections = PTOF->USERSections(); - for (unsigned i = 0; i < USERSections.size(); i++) { +void PIC16AsmPrinter::EmitAutos(std::string FunctName) { + // Section names for all globals are already set. + const TargetData *TD = TM.getTargetData(); + + // Now print Autos section for this function. + std::string SectionName = PAN::getAutosSectionName(FunctName); + const std::vector<PIC16Section*> &AutosSections = PTOF->AutosSections; + for (unsigned i = 0; i < AutosSections.size(); i++) { O << "\n"; - const PIC16Section *S = USERSections[i]; - if (S->isUDATA_Type()) { - EmitUninitializedDataSection(S); - } else if (S->isIDATA_Type() || S->isROMDATA_Type()) { - EmitInitializedDataSection(S); - } else { - llvm_unreachable ("unknow user section type"); + if (AutosSections[i]->S_->getName() == SectionName) { + // Set the printing status to true + AutosSections[i]->setPrintedStatus(true); + OutStreamer.SwitchSection(AutosSections[i]->S_); + const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items; + for (unsigned j = 0; j < Items.size(); j++) { + std::string VarName = Mang->getMangledName(Items[j]); + Constant *C = Items[j]->getInitializer(); + const Type *Ty = C->getType(); + unsigned Size = TD->getTypeAllocSize(Ty); + // Emit memory reserve directive. + O << VarName << " RES " << Size << "\n"; + } + break; } } } -void PIC16AsmPrinter::EmitAllAutos(Module &M) { - // Print all AUTO sections. - const std::vector<PIC16Section*> &AUTOSections = PTOF->AUTOSections(); - for (unsigned i = 0; i < AUTOSections.size(); i++) { +// Print autos that were not printed during the code printing of functions. +// As the functions might themselves would have got deleted by the optimizer. +void PIC16AsmPrinter::EmitRemainingAutos() { + const TargetData *TD = TM.getTargetData(); + + // Now print Autos section for this function. + std::vector <PIC16Section *>AutosSections = PTOF->AutosSections; + for (unsigned i = 0; i < AutosSections.size(); i++) { + + // if the section is already printed then don't print again + if (AutosSections[i]->isPrinted()) + continue; + + // Set status as printed + AutosSections[i]->setPrintedStatus(true); + O << "\n"; - EmitUninitializedDataSection(AUTOSections[i]); + OutStreamer.SwitchSection(AutosSections[i]->S_); + const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items; + for (unsigned j = 0; j < Items.size(); j++) { + std::string VarName = Mang->getMangledName(Items[j]); + Constant *C = Items[j]->getInitializer(); + const Type *Ty = C->getType(); + unsigned Size = TD->getTypeAllocSize(Ty); + // Emit memory reserve directive. + O << VarName << " RES " << Size << "\n"; + } } } + extern "C" void LLVMInitializePIC16AsmPrinter() { RegisterAsmPrinter<PIC16AsmPrinter> X(ThePIC16Target); } diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h index 686d080849..2dd4600b76 100644 --- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h +++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h @@ -53,13 +53,11 @@ namespace llvm { void EmitDefinedVars (Module &M); void EmitIData (Module &M); void EmitUData (Module &M); - void EmitAllAutos (Module &M); + void EmitAutos (std::string FunctName); + void EmitRemainingAutos (); void EmitRomData (Module &M); - void EmitUserSections (Module &M); void EmitFunctionFrame(MachineFunction &MF); void printLibcallDecls(); - void EmitUninitializedDataSection(const PIC16Section *S); - void EmitInitializedDataSection(const PIC16Section *S); protected: bool doInitialization(Module &M); bool doFinalization(Module &M); @@ -76,8 +74,6 @@ namespace llvm { PIC16DbgInfo DbgInfo; const PIC16MCAsmInfo *PMAI; std::list<const char *> LibcallDecls; // List of extern decls. - std::vector<const GlobalVariable *> ExternalVarDecls; - std::vector<const GlobalVariable *> ExternalVarDefs; }; } // end of namespace |