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" |
| 14 | #include <vector> |
| 15 | |
| 16 | namespace llvm { |
| 17 | class GlobalVariable; |
| 18 | class Module; |
| 19 | class PIC16TargetMachine; |
| 20 | |
| 21 | enum { DataBankSize = 80 }; |
| 22 | |
| 23 | /// PIC16 Splits the global data into mulitple udata and idata sections. |
| 24 | /// Each udata and idata section needs to contain a list of globals that |
| 25 | /// they contain, in order to avoid scanning over all the global values |
| 26 | /// again and printing only those that match the current section. |
| 27 | /// Keeping values inside the sections make printing a section much easier. |
| 28 | /// |
| 29 | /// FIXME: Reimplement by inheriting from MCSection. |
| 30 | /// |
| 31 | struct PIC16Section { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 32 | const MCSection *S_; // Connection to actual Section. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 33 | unsigned Size; // Total size of the objects contained. |
| 34 | bool SectionPrinted; |
| 35 | std::vector<const GlobalVariable*> Items; |
| 36 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 37 | PIC16Section(const MCSection *s) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 38 | S_ = s; |
| 39 | Size = 0; |
| 40 | SectionPrinted = false; |
| 41 | } |
| 42 | bool isPrinted() const { return SectionPrinted; } |
| 43 | void setPrintedStatus(bool status) { SectionPrinted = status; } |
| 44 | }; |
| 45 | |
| 46 | class PIC16TargetObjectFile : public TargetLoweringObjectFile { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 47 | const TargetMachine *TM; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 48 | public: |
| 49 | mutable std::vector<PIC16Section*> BSSSections; |
| 50 | mutable std::vector<PIC16Section*> IDATASections; |
| 51 | mutable std::vector<PIC16Section*> AutosSections; |
| 52 | mutable std::vector<PIC16Section*> ROSections; |
| 53 | mutable PIC16Section *ExternalVarDecls; |
| 54 | mutable PIC16Section *ExternalVarDefs; |
| 55 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 56 | ~PIC16TargetObjectFile(); |
| 57 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 58 | void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 59 | |
| 60 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 61 | /// getSpecialCasedSectionGlobals - Allow the target to completely override |
| 62 | /// section assignment of a global. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 63 | virtual const MCSection * |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 64 | getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame^] | 65 | SectionInfo Info) const; |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 66 | virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV, |
Chris Lattner | 968ff11 | 2009-08-01 21:11:14 +0000 | [diff] [blame^] | 67 | SectionInfo Info, |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 68 | Mangler *Mang, |
| 69 | const TargetMachine&) const; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 70 | private: |
| 71 | std::string getSectionNameForSym(const std::string &Sym) const; |
| 72 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 73 | const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const; |
| 74 | const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const; |
| 75 | const MCSection *getSectionForAuto(const GlobalVariable *GV) const; |
| 76 | const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV, |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 77 | std::string Addr = "") const; |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 78 | const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV, |
| 79 | std::string Addr = "") const; |
| 80 | const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const; |
| 81 | const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV, |
| 82 | std::string Addr = "") const; |
| 83 | const MCSection *CreateSectionForGlobal(const GlobalVariable *GV, |
| 84 | Mangler *Mang, |
| 85 | const std::string &Addr = "") const; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 86 | public: |
| 87 | void SetSectionForGVs(Module &M); |
| 88 | const std::vector<PIC16Section*> &getBSSSections() const { |
| 89 | return BSSSections; |
| 90 | } |
| 91 | const std::vector<PIC16Section*> &getIDATASections() const { |
| 92 | return IDATASections; |
| 93 | } |
| 94 | const std::vector<PIC16Section*> &getAutosSections() const { |
| 95 | return AutosSections; |
| 96 | } |
| 97 | const std::vector<PIC16Section*> &getROSections() const { |
| 98 | return ROSections; |
| 99 | } |
| 100 | |
| 101 | }; |
| 102 | } // end namespace llvm |
| 103 | |
| 104 | #endif |