blob: cf8bf848e45ec4e0c62d728630565fa89995e839 [file] [log] [blame]
Chris Lattnerf0144122009-07-28 03:13:23 +00001//===-- 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
Sanjiv Gupta753ec152009-10-15 19:26:25 +000013#include "PIC16.h"
14#include "PIC16ABINames.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000015#include "llvm/Target/TargetLoweringObjectFile.h"
Chris Lattner873bc4c2009-08-13 00:26:52 +000016#include "llvm/ADT/StringMap.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000017#include <vector>
Chris Lattnera4629202009-08-12 23:53:59 +000018#include <string>
Chris Lattnerf0144122009-07-28 03:13:23 +000019
20namespace llvm {
21 class GlobalVariable;
22 class Module;
23 class PIC16TargetMachine;
Sanjiv Gupta753ec152009-10-15 19:26:25 +000024 class PIC16Section;
Chris Lattnerf0144122009-07-28 03:13:23 +000025
26 enum { DataBankSize = 80 };
27
28 /// PIC16 Splits the global data into mulitple udata and idata sections.
29 /// Each udata and idata section needs to contain a list of globals that
30 /// they contain, in order to avoid scanning over all the global values
31 /// again and printing only those that match the current section.
32 /// Keeping values inside the sections make printing a section much easier.
33 ///
Sanjiv Gupta753ec152009-10-15 19:26:25 +000034 /// FIXME: MOVE ALL THIS STUFF TO PIC16Section.
Chris Lattnerf0144122009-07-28 03:13:23 +000035 ///
Sanjiv Gupta753ec152009-10-15 19:26:25 +000036
37 /// PIC16TargetObjectFile - PIC16 Object file. Contains data and code
38 /// sections.
39 // PIC16 Object File has two types of sections.
40 // 1. Standard Sections
41 // 1.1 un-initialized global data
42 // 1.2 initialized global data
43 // 1.3 program memory data
44 // 1.4 local variables of functions.
45 // 2. User defined sections
46 // 2.1 Objects placed in a specific section. (By _Section() macro)
47 // 2.2 Objects placed at a specific address. (By _Address() macro)
Chris Lattnerf0144122009-07-28 03:13:23 +000048 class PIC16TargetObjectFile : public TargetLoweringObjectFile {
Chris Lattner873bc4c2009-08-13 00:26:52 +000049 /// SectionsByName - Bindings of names to allocated sections.
Sanjiv Gupta753ec152009-10-15 19:26:25 +000050 mutable StringMap<PIC16Section*> SectionsByName;
Chris Lattner873bc4c2009-08-13 00:26:52 +000051
Chris Lattnera87dea42009-07-31 18:48:30 +000052 const TargetMachine *TM;
Chris Lattnerfbf1d272009-08-08 20:14:13 +000053
Sanjiv Gupta753ec152009-10-15 19:26:25 +000054 /// Lists of sections.
55 /// Standard Data Sections.
56 mutable std::vector<PIC16Section *> UDATASections_;
57 mutable std::vector<PIC16Section *> IDATASections_;
58 mutable PIC16Section * ROMDATASection_;
Sanjiv Guptae1ef91d2009-10-25 08:14:11 +000059 mutable PIC16Section * SHAREDUDATASection_;
Daniel Dunbar967ce7f2009-08-02 01:25:15 +000060
Sanjiv Gupta753ec152009-10-15 19:26:25 +000061 /// Standard Auto Sections.
62 mutable std::vector<PIC16Section *> AUTOSections_;
63
64 /// User specified sections.
65 mutable std::vector<PIC16Section *> USERSections_;
66
67
68 /// Find or Create a PIC16 Section, without adding it to any
69 /// section list.
70 PIC16Section *getPIC16Section(const std::string &Name,
71 PIC16SectionType Ty,
72 const std::string &Address = "",
73 int Color = -1) const;
74
75 /// Convenience functions. These wrappers also take care of adding
76 /// the newly created section to the appropriate sections list.
77
78 /// Find or Create PIC16 Standard Data Section.
79 PIC16Section *getPIC16DataSection(const std::string &Name,
80 PIC16SectionType Ty,
81 const std::string &Address = "",
82 int Color = -1) const;
83
84 /// Find or Create PIC16 Standard Auto Section.
85 PIC16Section *getPIC16AutoSection(const std::string &Name,
86 PIC16SectionType Ty = UDATA_OVR,
87 const std::string &Address = "",
88 int Color = -1) const;
89
90 /// Find or Create PIC16 Standard Auto Section.
91 PIC16Section *getPIC16UserSection(const std::string &Name,
92 PIC16SectionType Ty,
93 const std::string &Address = "",
94 int Color = -1) const;
95
96 /// Allocate Un-initialized data to a standard UDATA section.
97 const MCSection *allocateUDATA(const GlobalVariable *GV) const;
98
99 /// Allocate Initialized data to a standard IDATA section.
100 const MCSection *allocateIDATA(const GlobalVariable *GV) const;
101
102 /// Allocate ROM data to the standard ROMDATA section.
103 const MCSection *allocateROMDATA(const GlobalVariable *GV) const;
104
105 /// Allocate an AUTO variable to an AUTO section.
106 const MCSection *allocateAUTO(const GlobalVariable *GV) const;
107
108 /// Allocate DATA in user specified section.
109 const MCSection *allocateInGivenSection(const GlobalVariable *GV) const;
110
111 /// Allocate DATA at user specified address.
112 const MCSection *allocateAtGivenAddress(const GlobalVariable *GV,
113 const std::string &Addr) const;
Sanjiv Guptae1ef91d2009-10-25 08:14:11 +0000114
115 /// Allocate a shared variable to SHARED section.
116 const MCSection *allocateSHARED(const GlobalVariable *GV,
117 Mangler *Mang) const;
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000118
119 public:
Daniel Dunbar967ce7f2009-08-02 01:25:15 +0000120 PIC16TargetObjectFile();
Chris Lattnerf0144122009-07-28 03:13:23 +0000121 ~PIC16TargetObjectFile();
Chris Lattnera87dea42009-07-31 18:48:30 +0000122 void Initialize(MCContext &Ctx, const TargetMachine &TM);
123
Sanjiv Gupta4e4bba52009-10-21 10:42:44 +0000124 /// Return the section with the given Name. Null if not found.
125 PIC16Section *findPIC16Section(const std::string &Name);
126
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000127 /// Override section allocations for user specified sections.
Chris Lattnera87dea42009-07-31 18:48:30 +0000128 virtual const MCSection *
Chris Lattner24f654c2009-08-06 16:39:58 +0000129 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
130 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattner759b8882009-08-06 16:27:28 +0000131
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000132 /// Select sections for Data and Auto variables(globals).
Chris Lattnera87dea42009-07-31 18:48:30 +0000133 virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattnerf9650c02009-08-01 21:46:23 +0000134 SectionKind Kind,
Chris Lattnera87dea42009-07-31 18:48:30 +0000135 Mangler *Mang,
136 const TargetMachine&) const;
Chris Lattner759b8882009-08-06 16:27:28 +0000137
Sanjiv Gupta4e4bba52009-10-21 10:42:44 +0000138
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000139 /// Return a code section for a function.
Sanjiv Gupta7643ca52010-02-16 03:41:07 +0000140 const PIC16Section *SectionForCode (const std::string &FnName,
141 bool isISR) const;
Chris Lattnerf0144122009-07-28 03:13:23 +0000142
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000143 /// Return a frame section for a function.
144 const PIC16Section *SectionForFrame (const std::string &FnName) const;
145
146 /// Accessors for various section lists.
147 const std::vector<PIC16Section *> &UDATASections() const {
148 return UDATASections_;
Chris Lattnerf0144122009-07-28 03:13:23 +0000149 }
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000150 const std::vector<PIC16Section *> &IDATASections() const {
151 return IDATASections_;
Chris Lattnerf0144122009-07-28 03:13:23 +0000152 }
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000153 const PIC16Section *ROMDATASection() const {
154 return ROMDATASection_;
Chris Lattnerf0144122009-07-28 03:13:23 +0000155 }
Sanjiv Guptae1ef91d2009-10-25 08:14:11 +0000156 const PIC16Section *SHAREDUDATASection() const {
157 return SHAREDUDATASection_;
158 }
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000159 const std::vector<PIC16Section *> &AUTOSections() const {
160 return AUTOSections_;
Chris Lattnerf0144122009-07-28 03:13:23 +0000161 }
Sanjiv Gupta753ec152009-10-15 19:26:25 +0000162 const std::vector<PIC16Section *> &USERSections() const {
163 return USERSections_;
164 }
Chris Lattnerf0144122009-07-28 03:13:23 +0000165 };
166} // end namespace llvm
167
168#endif