| Benjamin Kramer | 5814fef | 2009-10-15 19:46:34 +0000 | [diff] [blame] | 1 | //===-- PIC16Section.cpp - PIC16 Section ----------- --------------------===// | 
 | 2 | // | 
 | 3 | //                     The LLVM Compiler Infrastructure | 
 | 4 | // | 
 | 5 | // This file is distributed under the University of Illinois Open Source | 
 | 6 | // License. See LICENSE.TXT for details. | 
 | 7 | // | 
 | 8 | //===----------------------------------------------------------------------===// | 
 | 9 |  | 
 | 10 | #include "PIC16.h" | 
 | 11 | #include "PIC16ABINames.h" | 
 | 12 | #include "PIC16Section.h" | 
 | 13 | #include "llvm/MC/MCContext.h" | 
 | 14 | #include "llvm/Support/raw_ostream.h" | 
 | 15 | using namespace llvm; | 
 | 16 |  | 
 | 17 |  | 
 | 18 | // This is the only way to create a PIC16Section. Sections created here | 
 | 19 | // do not need to be explicitly deleted as they are managed by auto_ptrs. | 
 | 20 | PIC16Section *PIC16Section::Create(const StringRef &Name, | 
 | 21 |                                    PIC16SectionType Ty, | 
 | 22 |                                    const std::string &Address,  | 
 | 23 |                                    int Color, MCContext &Ctx) { | 
 | 24 |  | 
 | 25 |   /// Determine the internal SectionKind info. | 
 | 26 |   /// Users of PIC16Section class should not need to know the internal | 
 | 27 |   /// SectionKind. They should work only with PIC16SectionType. | 
 | 28 |   /// | 
 | 29 |   /// PIC16 Terminology for section kinds is as below. | 
 | 30 |   /// UDATA - BSS | 
 | 31 |   /// IDATA - initialized data (equiv to Metadata)  | 
 | 32 |   /// ROMDATA - ReadOnly. | 
 | 33 |   /// UDATA_OVR - Sections that can be overlaid. Section of such type is | 
 | 34 |   ///             used to contain function autos an frame. We can think of | 
 | 35 |   ///             it as equiv to llvm ThreadBSS) | 
 | 36 |   /// UDATA_SHR - Shared RAM. Memory area that is mapped to all banks. | 
 | 37 |  | 
 | 38 |   SectionKind K; | 
 | 39 |   switch (Ty) { | 
 | 40 |     default: llvm_unreachable ("can not create unknown section type"); | 
 | 41 |     case UDATA_OVR: { | 
 | 42 |       K = SectionKind::getThreadBSS(); | 
 | 43 |       break; | 
 | 44 |     } | 
 | 45 |     case UDATA_SHR: | 
 | 46 |     case UDATA: { | 
 | 47 |       K = SectionKind::getBSS(); | 
 | 48 |       break; | 
 | 49 |     } | 
 | 50 |     case ROMDATA: | 
 | 51 |     case IDATA: { | 
 | 52 |       K = SectionKind::getMetadata(); | 
 | 53 |       break; | 
 | 54 |     } | 
 | 55 |     case CODE: { | 
 | 56 |       K = SectionKind::getText(); | 
 | 57 |       break; | 
 | 58 |     } | 
 | 59 |        | 
 | 60 |   } | 
 | 61 |  | 
 | 62 |   // Create the Section. | 
 | 63 |   PIC16Section *S = new (Ctx) PIC16Section(Name, K, Address, Color); | 
 | 64 |   S->T = Ty; | 
 | 65 |   return S; | 
 | 66 | } | 
 | 67 |  | 
 | 68 | // A generic way to print all types of sections. | 
 | 69 | void PIC16Section::PrintSwitchToSection(const MCAsmInfo &MAI, | 
 | 70 |                                           raw_ostream &OS) const { | 
| Sanjiv Gupta | 4e4bba5 | 2009-10-21 10:42:44 +0000 | [diff] [blame] | 71 |   | 
 | 72 |   // If the section is overlaid(i.e. it has a color), print overlay name for  | 
 | 73 |   // it. Otherwise print its normal name. | 
 | 74 |   if (Color != -1) | 
 | 75 |     OS << PAN::getOverlayName(getName(), Color) << '\t'; | 
 | 76 |   else | 
 | 77 |     OS << getName() << '\t'; | 
| Benjamin Kramer | 5814fef | 2009-10-15 19:46:34 +0000 | [diff] [blame] | 78 |  | 
 | 79 |   // Print type. | 
 | 80 |   switch (getType()) { | 
 | 81 |   default : llvm_unreachable ("unknown section type");  | 
 | 82 |   case UDATA: OS << "UDATA"; break; | 
 | 83 |   case IDATA: OS << "IDATA"; break; | 
 | 84 |   case ROMDATA: OS << "ROMDATA"; break; | 
 | 85 |   case UDATA_SHR: OS << "UDATA_SHR"; break; | 
 | 86 |   case UDATA_OVR: OS << "UDATA_OVR"; break; | 
 | 87 |   case CODE: OS << "CODE"; break; | 
 | 88 |   } | 
 | 89 |  | 
 | 90 |   OS << '\t'; | 
 | 91 |  | 
 | 92 |   // Print Address. | 
 | 93 |   OS << Address; | 
 | 94 |  | 
 | 95 |   OS << '\n'; | 
 | 96 | } |