start refactoring pic16 section selection logic.
[oota-llvm.git] / lib / Target / PIC16 / PIC16TargetAsmInfo.h
1 //=====-- PIC16TargetAsmInfo.h - PIC16 asm properties ---------*- 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 // This file contains the declaration of the PIC16TargetAsmInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef PIC16TARGETASMINFO_H
15 #define PIC16TARGETASMINFO_H
16
17 #include "PIC16.h"
18 #include "llvm/Target/TargetAsmInfo.h"
19 #include <vector>
20 #include "llvm/Module.h"
21
22 namespace llvm {
23
24   enum { DataBankSize = 80 };
25
26   // Forward declaration.
27   class PIC16TargetMachine;
28   class GlobalVariable;
29
30   /// PIC16 Splits the global data into mulitple udata and idata sections.
31   /// Each udata and idata section needs to contain a list of globals that
32   /// they contain, in order to avoid scanning over all the global values 
33   /// again and printing only those that match the current section. 
34   /// Keeping values inside the sections make printing a section much easier.
35   struct PIC16Section {
36     const Section *S_; // Connection to actual Section.
37     unsigned Size;  // Total size of the objects contained.
38     bool SectionPrinted;
39     std::vector<const GlobalVariable*> Items;
40    
41     PIC16Section(const Section *s) {
42       S_ = s;
43       Size = 0;
44       SectionPrinted = false;
45     }
46     bool isPrinted() const { return SectionPrinted; }
47     void setPrintedStatus(bool status) { SectionPrinted = status; } 
48   };
49       
50   struct PIC16TargetAsmInfo : public TargetAsmInfo {
51     std::string getSectionNameForSym(const std::string &Sym) const;
52     PIC16TargetAsmInfo(const PIC16TargetMachine &TM);
53     mutable std::vector<PIC16Section *> BSSSections;
54     mutable std::vector<PIC16Section *> IDATASections;
55     mutable std::vector<PIC16Section *> AutosSections;
56     mutable std::vector<PIC16Section *> ROSections;
57     mutable PIC16Section *ExternalVarDecls;
58     mutable PIC16Section *ExternalVarDefs;
59     virtual ~PIC16TargetAsmInfo();
60
61   private:
62     const char *RomData8bitsDirective;
63     const char *RomData16bitsDirective;
64     const char *RomData32bitsDirective;
65     const char *getRomDirective(unsigned size) const;
66     virtual const char *getDataASDirective(unsigned size, unsigned AS) const;
67     const Section *getBSSSectionForGlobal(const GlobalVariable *GV) const;
68     const Section *getIDATASectionForGlobal(const GlobalVariable *GV) const;
69     const Section *getSectionForAuto(const GlobalVariable *GV) const;
70     const Section *CreateBSSSectionForGlobal(const GlobalVariable *GV,
71                                              std::string Addr = "") const;
72     const Section *CreateIDATASectionForGlobal(const GlobalVariable *GV,
73                                                std::string Addr = "") const;
74     const Section *getROSectionForGlobal(const GlobalVariable *GV) const;
75     const Section *CreateROSectionForGlobal(const GlobalVariable *GV,
76                                             std::string Addr = "") const;
77     virtual const Section *SelectSectionForGlobal(const GlobalValue *GV) const;
78     const Section *CreateSectionForGlobal(const GlobalVariable *GV,
79                                           const std::string &Addr = "") const;
80   public:
81     void SetSectionForGVs(Module &M);
82     const std::vector<PIC16Section*> &getBSSSections() const {
83       return BSSSections;
84     }
85     const std::vector<PIC16Section*> &getIDATASections() const {
86       return IDATASections;
87     }
88     const std::vector<PIC16Section*> &getAutosSections() const {
89       return AutosSections;
90     }
91     const std::vector<PIC16Section*> &getROSections() const {
92       return ROSections;
93     }
94     virtual const Section *SectionForGlobal(const GlobalValue *GV) const;
95   };
96
97 } // namespace llvm
98
99 #endif