revert 79631
[oota-llvm.git] / lib / Target / PIC16 / PIC16TargetObjectFile.h
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 "llvm/ADT/StringMap.h"
15 #include <vector>
16 #include <string>
17
18 namespace llvm {
19   class GlobalVariable;
20   class Module;
21   class PIC16TargetMachine;
22   class MCSectionPIC16;
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   ///
32   /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
33   ///
34   struct PIC16Section {
35     const MCSectionPIC16 *S_; // Connection to actual Section.
36     unsigned Size;  // Total size of the objects contained.
37     bool SectionPrinted;
38     std::vector<const GlobalVariable*> Items;
39     
40     PIC16Section(const MCSectionPIC16 *s) {
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 {
50     /// SectionsByName - Bindings of names to allocated sections.
51     mutable StringMap<MCSectionPIC16*> SectionsByName;
52
53     const TargetMachine *TM;
54     
55     const MCSectionPIC16 *getPIC16Section(const char *Name,
56                                           SectionKind K) const;
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;
64
65     PIC16TargetObjectFile();
66     ~PIC16TargetObjectFile();
67     
68     void Initialize(MCContext &Ctx, const TargetMachine &TM);
69
70     
71     virtual const MCSection *
72     getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
73                              Mangler *Mang, const TargetMachine &TM) const;
74     
75     virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
76                                                     SectionKind Kind,
77                                                     Mangler *Mang,
78                                                     const TargetMachine&) const;
79
80     const MCSection *getSectionForFunction(const std::string &FnName, 
81                                            bool isInterrupt=false) const;
82     const MCSection *getSectionForFunctionFrame(const std::string &FnName)const;
83     
84     // If the current function is cloned then create the new autos section
85     // also. 
86     void createClonedSectionForAutos(const std::string &SecName);
87   private:
88     std::string getSectionNameForSym(const std::string &Sym) const;
89
90     const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
91     const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
92     const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
93     const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
94                                                std::string Addr = "") const;
95     const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
96                                                  std::string Addr = "") const;
97     const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
98     const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
99                                               std::string Addr = "") const;
100     const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
101                                             Mangler *Mang,
102                                             const std::string &Addr = "") const;
103   public:
104     void SetSectionForGVs(Module &M);
105     const std::vector<PIC16Section*> &getBSSSections() const {
106       return BSSSections;
107     }
108     const std::vector<PIC16Section*> &getIDATASections() const {
109       return IDATASections;
110     }
111     const std::vector<PIC16Section*> &getAutosSections() const {
112       return AutosSections;
113     }
114     const std::vector<PIC16Section*> &getROSections() const {
115       return ROSections;
116     }
117     
118   };
119 } // end namespace llvm
120
121 #endif