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 | |
| 13 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | 873bc4c | 2009-08-13 00:26:52 +0000 | [diff] [blame^] | 14 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 15 | #include <vector> |
Chris Lattner | a462920 | 2009-08-12 23:53:59 +0000 | [diff] [blame] | 16 | #include <string> |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
| 19 | class GlobalVariable; |
| 20 | class Module; |
| 21 | class PIC16TargetMachine; |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 22 | class MCSectionPIC16; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 23 | |
| 24 | enum { DataBankSize = 80 }; |
| 25 | |
| 26 | /// PIC16 Splits the global data into mulitple udata and idata sections. |
| 27 | /// Each udata and idata section needs to contain a list of globals that |
| 28 | /// they contain, in order to avoid scanning over all the global values |
| 29 | /// again and printing only those that match the current section. |
| 30 | /// Keeping values inside the sections make printing a section much easier. |
| 31 | /// |
Chris Lattner | f7427e5 | 2009-08-08 21:37:01 +0000 | [diff] [blame] | 32 | /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 33 | /// |
| 34 | struct PIC16Section { |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 35 | const MCSectionPIC16 *S_; // Connection to actual Section. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 36 | unsigned Size; // Total size of the objects contained. |
| 37 | bool SectionPrinted; |
| 38 | std::vector<const GlobalVariable*> Items; |
| 39 | |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 40 | PIC16Section(const MCSectionPIC16 *s) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 41 | S_ = s; |
| 42 | Size = 0; |
| 43 | SectionPrinted = false; |
| 44 | } |
| 45 | bool isPrinted() const { return SectionPrinted; } |
| 46 | void setPrintedStatus(bool status) { SectionPrinted = status; } |
| 47 | }; |
| 48 | |
| 49 | class PIC16TargetObjectFile : public TargetLoweringObjectFile { |
Chris Lattner | 873bc4c | 2009-08-13 00:26:52 +0000 | [diff] [blame^] | 50 | /// SectionsByName - Bindings of names to allocated sections. |
| 51 | mutable StringMap<MCSectionPIC16*> SectionsByName; |
| 52 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 53 | const TargetMachine *TM; |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 55 | const MCSectionPIC16 *getPIC16Section(const char *Name, |
| 56 | SectionKind K) const; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 57 | public: |
| 58 | mutable std::vector<PIC16Section*> BSSSections; |
| 59 | mutable std::vector<PIC16Section*> IDATASections; |
| 60 | mutable std::vector<PIC16Section*> AutosSections; |
| 61 | mutable std::vector<PIC16Section*> ROSections; |
| 62 | mutable PIC16Section *ExternalVarDecls; |
| 63 | mutable PIC16Section *ExternalVarDefs; |
Daniel Dunbar | 967ce7f | 2009-08-02 01:25:15 +0000 | [diff] [blame] | 64 | |
| 65 | PIC16TargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 66 | ~PIC16TargetObjectFile(); |
| 67 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 68 | void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 69 | |
| 70 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 71 | virtual const MCSection * |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 72 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 73 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 74 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 75 | virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 76 | SectionKind Kind, |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 77 | Mangler *Mang, |
| 78 | const TargetMachine&) const; |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 79 | |
| 80 | const MCSection *getSectionForFunction(const std::string &FnName) const; |
| 81 | const MCSection *getSectionForFunctionFrame(const std::string &FnName)const; |
| 82 | |
| 83 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 84 | private: |
| 85 | std::string getSectionNameForSym(const std::string &Sym) const; |
| 86 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 87 | const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const; |
| 88 | const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const; |
| 89 | const MCSection *getSectionForAuto(const GlobalVariable *GV) const; |
| 90 | const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV, |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 91 | std::string Addr = "") const; |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 92 | const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV, |
| 93 | std::string Addr = "") const; |
| 94 | const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const; |
| 95 | const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV, |
| 96 | std::string Addr = "") const; |
| 97 | const MCSection *CreateSectionForGlobal(const GlobalVariable *GV, |
| 98 | Mangler *Mang, |
| 99 | const std::string &Addr = "") const; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 100 | public: |
| 101 | void SetSectionForGVs(Module &M); |
| 102 | const std::vector<PIC16Section*> &getBSSSections() const { |
| 103 | return BSSSections; |
| 104 | } |
| 105 | const std::vector<PIC16Section*> &getIDATASections() const { |
| 106 | return IDATASections; |
| 107 | } |
| 108 | const std::vector<PIC16Section*> &getAutosSections() const { |
| 109 | return AutosSections; |
| 110 | } |
| 111 | const std::vector<PIC16Section*> &getROSections() const { |
| 112 | return ROSections; |
| 113 | } |
| 114 | |
| 115 | }; |
| 116 | } // end namespace llvm |
| 117 | |
| 118 | #endif |