Cleaned up some code. No functionality change.
authorSanjiv Gupta <sanjiv.gupta@microchip.com>
Fri, 16 Oct 2009 08:58:34 +0000 (08:58 +0000)
committerSanjiv Gupta <sanjiv.gupta@microchip.com>
Fri, 16 Oct 2009 08:58:34 +0000 (08:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
lib/Target/PIC16/PIC16ABINames.h
lib/Target/PIC16/PIC16TargetObjectFile.cpp

index 1afd3ee4f2d82cc016feaf53d2e6db5289dbaa71..3f719b99ff70c4c621981f72155717ed58aeaa7a 100644 (file)
@@ -73,9 +73,6 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   DbgInfo.BeginFunction(MF);
 
-  // Emit the autos section of function.
-  // EmitAutos(CurrentFnName);
-
   // Now emit the instructions of function in its code section.
   const MCSection *fCodeSection 
     = getObjFileLowering().SectionForCode(CurrentFnName);
@@ -329,15 +326,11 @@ 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);
+  EmitSingleSection(PTOF->ROMDATASection());
 }
 
 bool PIC16AsmPrinter::doFinalization(Module &M) {
   printLibcallDecls();
-  // EmitRemainingAutos();
   DbgInfo.EndModule(M);
   O << "\n\t" << "END\n";
   return AsmPrinter::doFinalization(M);
@@ -402,20 +395,13 @@ void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) {
    }
 }
 
+// Print all IDATA sections.
 void PIC16AsmPrinter::EmitIData(Module &M) {
-
-  // Print all IDATA sections.
-  const std::vector<PIC16Section *> &IDATASections = PTOF->IDATASections();
-  for (unsigned i = 0; i < IDATASections.size(); i++) {
-    O << "\n";
-    if (IDATASections[i]->getName().find("llvm.") != std::string::npos)
-      continue;
-    
-    EmitInitializedDataSection(IDATASections[i]);
-    }
+  EmitSectionList (M, PTOF->IDATASections());
 }
 
-void PIC16AsmPrinter::EmitUninitializedDataSection(const PIC16Section *S) {
+void PIC16AsmPrinter::
+EmitUninitializedDataSection(const PIC16Section *S) {
     const TargetData *TD = TM.getTargetData();
     OutStreamer.SwitchSection(S);
     std::vector<const GlobalVariable*> Items = S->Items;
@@ -428,41 +414,52 @@ void PIC16AsmPrinter::EmitUninitializedDataSection(const PIC16Section *S) {
     }
 }
 
+// Print all UDATA sections.
 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]);
-  }
+  EmitSectionList (M, PTOF->UDATASections());
 }
 
+// Print all USER sections.
 void PIC16AsmPrinter::EmitUserSections(Module &M) {
-  const std::vector<PIC16Section*> &USERSections = PTOF->USERSections();
-  for (unsigned i = 0; i < USERSections.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");
-    }
-  }
+  EmitSectionList (M, PTOF->USERSections());
 }
 
+// Print all AUTO sections.
 void PIC16AsmPrinter::EmitAllAutos(Module &M) {
-  // Print all AUTO sections.
-  const std::vector<PIC16Section*> &AUTOSections = PTOF->AUTOSections();
-  for (unsigned i = 0; i < AUTOSections.size(); i++) {
-    O << "\n";
-    EmitUninitializedDataSection(AUTOSections[i]);
-  }
+  EmitSectionList (M, PTOF->AUTOSections());
 }
 
 extern "C" void LLVMInitializePIC16AsmPrinter() { 
   RegisterAsmPrinter<PIC16AsmPrinter> X(ThePIC16Target);
 }
 
+// Emit one data section using correct section emitter based on section type.
+void PIC16AsmPrinter::EmitSingleSection(const PIC16Section *S) {
+  if (S == NULL) return;
+
+  switch (S->getType()) {
+    default: llvm_unreachable ("unknow user section type");
+    case UDATA:
+    case UDATA_SHR:
+    case UDATA_OVR:
+      EmitUninitializedDataSection(S);
+      break;
+    case IDATA:
+    case ROMDATA:
+      EmitInitializedDataSection(S);
+      break;
+  }
+}
+
+// Emit a list of sections.
+void PIC16AsmPrinter::
+EmitSectionList(Module &M, const std::vector<PIC16Section *> &SList) {
+  for (unsigned i = 0; i < SList.size(); i++) {
+    // Exclude llvm specific metadata sections.
+    if (SList[i]->getName().find("llvm.") != std::string::npos)
+      continue;
+    O << "\n";
+    EmitSingleSection(SList[i]);
+  }
+}
 
index 686d08084944fedc80b9fa32a953dfdcf0c4a79f..580e2fdb7bc0fc2208f3d70da7b32987a09dc027 100644 (file)
@@ -60,6 +60,9 @@ namespace llvm {
     void printLibcallDecls();
     void EmitUninitializedDataSection(const PIC16Section *S);
     void EmitInitializedDataSection(const PIC16Section *S);
+    void EmitSingleSection(const PIC16Section *S);
+    void EmitSectionList(Module &M, 
+                         const std::vector< PIC16Section *> &SList);
   protected:
     bool doInitialization(Module &M);
     bool doFinalization(Module &M);
index 00e9e457144b1c038feac0e963100c0ee685ae62..7fa1721a76bdc4a3fedafd2f6d901cc0935816a9 100644 (file)
@@ -40,6 +40,7 @@ namespace llvm {
     // Global variables do not have any '.' in their names.
     // These are maily function names and global variable names.
     // Example - @foo,  @i
+    // Static local variables - @<func>.<var>
     // -------------------------------------------------------
     // Functions and auto variables.
     // Names are mangled as <prefix><funcname>.<tag>.<varname>
@@ -67,8 +68,12 @@ namespace llvm {
     // SECTION Names
     // uninitialized globals - @udata.<num>.#
     // initialized globals - @idata.<num>.#
+    // Program memory data - @romdata.#
+    // Variables with user defined section name - <user_defined_section>
+    // Variables with user defined address - @<var>.user_section.<address>.#
     // Function frame - @<func>.frame_section.
     // Function autos - @<func>.autos_section.
+    // Overlay sections - @<color>.##
     // Declarations - Enclosed in comments. No section for them.
     //----------------------------------------------------------
     
index 330722d4a9c34f228d7da0b81b9e8bfae04963f1..11c579cc570067d528b7b97e671d6dc31c8d27b2 100644 (file)
@@ -22,6 +22,9 @@ using namespace llvm;
 PIC16TargetObjectFile::PIC16TargetObjectFile() {
 }
 
+PIC16TargetObjectFile::~PIC16TargetObjectFile() {
+}
+
 /// Find a pic16 section. If not found, create one.
 PIC16Section *PIC16TargetObjectFile::
 getPIC16Section(const std::string &Name, PIC16SectionType Ty, 
@@ -104,19 +107,11 @@ getPIC16UserSection(const std::string &Name, PIC16SectionType Ty,
   return Entry;
 }
 
-/// Do some standard llvm stuff. PIC16 really does not need any of this.
+/// Do some standard initialization.
 void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
   TargetLoweringObjectFile::Initialize(Ctx, tm);
   TM = &tm;
   
-  // BSSSection = getPIC16DataSection("udata.#", UDATA);
-  // ReadOnlySection = getPIC16DataSection("romdata.#", ROMDATA);
-  // DataSection = getPIC16DataSection("idata.#", IDATA);
-  
-  // Need because otherwise a .text symbol is emitted by DwarfWriter
-  // in BeginModule, and gpasm cribbs for that .text symbol.
-  // FIXME: below
-  // TextSection = getPIC16DataSection("", UDATA);
   ROMDATASection_ = NULL;
 }
 
@@ -254,22 +249,7 @@ PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1,
   return TargetLoweringObjectFile::SelectSectionForGlobal(GV, Kind, Mang,TM);
 }
 
-PIC16TargetObjectFile::~PIC16TargetObjectFile() {
-#if 0
-  for (unsigned i = 0; i < UDATASections_.size(); i++)
-    delete UDATASections_[i]; 
-  for (unsigned i = 0; i < IDATASections_.size(); i++)
-    delete IDATASections_[i]; 
-  
-  delete ROMDATASection_;
 
-  for (unsigned i = 0; i < AUTOSections_.size(); i++)
-    delete AUTOSections_[i]; 
-
-  for (unsigned i = 0; i < USERSections_.size(); i++)
-    delete USERSections_[i];
-#endif
-}
 
 
 /// getExplicitSectionGlobal - Allow the target to completely override