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