Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1 | //===-- PIC16TargetObjectFile.h - PIC16 Object Info -------------*- C++ -*-===// |
| 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 | #ifndef LLVM_TARGET_PIC16_TARGETOBJECTFILE_H |
| 11 | #define LLVM_TARGET_PIC16_TARGETOBJECTFILE_H |
| 12 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 13 | #include "PIC16.h" |
| 14 | #include "PIC16ABINames.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | 873bc4c | 2009-08-13 00:26:52 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 17 | #include <vector> |
Chris Lattner | a462920 | 2009-08-12 23:53:59 +0000 | [diff] [blame] | 18 | #include <string> |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | class GlobalVariable; |
| 22 | class Module; |
| 23 | class PIC16TargetMachine; |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 24 | class PIC16Section; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 25 | |
| 26 | enum { DataBankSize = 80 }; |
| 27 | |
| 28 | /// PIC16 Splits the global data into mulitple udata and idata sections. |
| 29 | /// Each udata and idata section needs to contain a list of globals that |
| 30 | /// they contain, in order to avoid scanning over all the global values |
| 31 | /// again and printing only those that match the current section. |
| 32 | /// Keeping values inside the sections make printing a section much easier. |
| 33 | /// |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 34 | /// FIXME: MOVE ALL THIS STUFF TO PIC16Section. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 35 | /// |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 36 | |
| 37 | /// PIC16TargetObjectFile - PIC16 Object file. Contains data and code |
| 38 | /// sections. |
| 39 | // PIC16 Object File has two types of sections. |
| 40 | // 1. Standard Sections |
| 41 | // 1.1 un-initialized global data |
| 42 | // 1.2 initialized global data |
| 43 | // 1.3 program memory data |
| 44 | // 1.4 local variables of functions. |
| 45 | // 2. User defined sections |
| 46 | // 2.1 Objects placed in a specific section. (By _Section() macro) |
| 47 | // 2.2 Objects placed at a specific address. (By _Address() macro) |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 48 | class PIC16TargetObjectFile : public TargetLoweringObjectFile { |
Chris Lattner | 873bc4c | 2009-08-13 00:26:52 +0000 | [diff] [blame] | 49 | /// SectionsByName - Bindings of names to allocated sections. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 50 | mutable StringMap<PIC16Section*> SectionsByName; |
Chris Lattner | 873bc4c | 2009-08-13 00:26:52 +0000 | [diff] [blame] | 51 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 52 | const TargetMachine *TM; |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 53 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 54 | /// Lists of sections. |
| 55 | /// Standard Data Sections. |
| 56 | mutable std::vector<PIC16Section *> UDATASections_; |
| 57 | mutable std::vector<PIC16Section *> IDATASections_; |
| 58 | mutable PIC16Section * ROMDATASection_; |
Daniel Dunbar | 967ce7f | 2009-08-02 01:25:15 +0000 | [diff] [blame] | 59 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 60 | /// Standard Auto Sections. |
| 61 | mutable std::vector<PIC16Section *> AUTOSections_; |
| 62 | |
| 63 | /// User specified sections. |
| 64 | mutable std::vector<PIC16Section *> USERSections_; |
| 65 | |
| 66 | |
| 67 | /// Find or Create a PIC16 Section, without adding it to any |
| 68 | /// section list. |
| 69 | PIC16Section *getPIC16Section(const std::string &Name, |
| 70 | PIC16SectionType Ty, |
| 71 | const std::string &Address = "", |
| 72 | int Color = -1) const; |
| 73 | |
| 74 | /// Convenience functions. These wrappers also take care of adding |
| 75 | /// the newly created section to the appropriate sections list. |
| 76 | |
| 77 | /// Find or Create PIC16 Standard Data Section. |
| 78 | PIC16Section *getPIC16DataSection(const std::string &Name, |
| 79 | PIC16SectionType Ty, |
| 80 | const std::string &Address = "", |
| 81 | int Color = -1) const; |
| 82 | |
| 83 | /// Find or Create PIC16 Standard Auto Section. |
| 84 | PIC16Section *getPIC16AutoSection(const std::string &Name, |
| 85 | PIC16SectionType Ty = UDATA_OVR, |
| 86 | const std::string &Address = "", |
| 87 | int Color = -1) const; |
| 88 | |
| 89 | /// Find or Create PIC16 Standard Auto Section. |
| 90 | PIC16Section *getPIC16UserSection(const std::string &Name, |
| 91 | PIC16SectionType Ty, |
| 92 | const std::string &Address = "", |
| 93 | int Color = -1) const; |
| 94 | |
| 95 | /// Allocate Un-initialized data to a standard UDATA section. |
| 96 | const MCSection *allocateUDATA(const GlobalVariable *GV) const; |
| 97 | |
| 98 | /// Allocate Initialized data to a standard IDATA section. |
| 99 | const MCSection *allocateIDATA(const GlobalVariable *GV) const; |
| 100 | |
| 101 | /// Allocate ROM data to the standard ROMDATA section. |
| 102 | const MCSection *allocateROMDATA(const GlobalVariable *GV) const; |
| 103 | |
| 104 | /// Allocate an AUTO variable to an AUTO section. |
| 105 | const MCSection *allocateAUTO(const GlobalVariable *GV) const; |
| 106 | |
| 107 | /// Allocate DATA in user specified section. |
| 108 | const MCSection *allocateInGivenSection(const GlobalVariable *GV) const; |
| 109 | |
| 110 | /// Allocate DATA at user specified address. |
| 111 | const MCSection *allocateAtGivenAddress(const GlobalVariable *GV, |
| 112 | const std::string &Addr) const; |
| 113 | |
| 114 | public: |
Daniel Dunbar | 967ce7f | 2009-08-02 01:25:15 +0000 | [diff] [blame] | 115 | PIC16TargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 116 | ~PIC16TargetObjectFile(); |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 117 | void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 118 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 119 | /// Override section allocations for user specified sections. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 120 | virtual const MCSection * |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 121 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 122 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 123 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 124 | /// Select sections for Data and Auto variables(globals). |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 125 | virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 126 | SectionKind Kind, |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 127 | Mangler *Mang, |
| 128 | const TargetMachine&) const; |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 129 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 130 | /// Return a code section for a function. |
| 131 | const PIC16Section *SectionForCode (const std::string &FnName) const; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 132 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 133 | /// Return a frame section for a function. |
| 134 | const PIC16Section *SectionForFrame (const std::string &FnName) const; |
| 135 | |
| 136 | /// Accessors for various section lists. |
| 137 | const std::vector<PIC16Section *> &UDATASections() const { |
| 138 | return UDATASections_; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 139 | } |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 140 | const std::vector<PIC16Section *> &IDATASections() const { |
| 141 | return IDATASections_; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 142 | } |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 143 | const PIC16Section *ROMDATASection() const { |
| 144 | return ROMDATASection_; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 145 | } |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 146 | const std::vector<PIC16Section *> &AUTOSections() const { |
| 147 | return AUTOSections_; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 148 | } |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame^] | 149 | const std::vector<PIC16Section *> &USERSections() const { |
| 150 | return USERSections_; |
| 151 | } |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 152 | }; |
| 153 | } // end namespace llvm |
| 154 | |
| 155 | #endif |