blob: 91415bc7658e3a90fc9e4a552a0c912874ab7736 [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
13#include "llvm/Target/TargetLoweringObjectFile.h"
14#include <vector>
Chris Lattnera4629202009-08-12 23:53:59 +000015#include <string>
Chris Lattnerf0144122009-07-28 03:13:23 +000016
17namespace llvm {
18 class GlobalVariable;
19 class Module;
20 class PIC16TargetMachine;
Chris Lattner93b6db32009-08-08 23:39:42 +000021 class MCSectionPIC16;
Chris Lattnerf0144122009-07-28 03:13:23 +000022
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 Lattnerf7427e52009-08-08 21:37:01 +000031 /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
Chris Lattnerf0144122009-07-28 03:13:23 +000032 ///
33 struct PIC16Section {
Chris Lattner93b6db32009-08-08 23:39:42 +000034 const MCSectionPIC16 *S_; // Connection to actual Section.
Chris Lattnerf0144122009-07-28 03:13:23 +000035 unsigned Size; // Total size of the objects contained.
36 bool SectionPrinted;
37 std::vector<const GlobalVariable*> Items;
38
Chris Lattner93b6db32009-08-08 23:39:42 +000039 PIC16Section(const MCSectionPIC16 *s) {
Chris Lattnerf0144122009-07-28 03:13:23 +000040 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 Lattnera87dea42009-07-31 18:48:30 +000049 const TargetMachine *TM;
Chris Lattnerfbf1d272009-08-08 20:14:13 +000050
Chris Lattner93b6db32009-08-08 23:39:42 +000051 const MCSectionPIC16 *getPIC16Section(const char *Name,
52 SectionKind K) const;
Chris Lattnerf0144122009-07-28 03:13:23 +000053 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 Dunbar967ce7f2009-08-02 01:25:15 +000060
61 PIC16TargetObjectFile();
Chris Lattnerf0144122009-07-28 03:13:23 +000062 ~PIC16TargetObjectFile();
63
Chris Lattnera87dea42009-07-31 18:48:30 +000064 void Initialize(MCContext &Ctx, const TargetMachine &TM);
65
66
Chris Lattnera87dea42009-07-31 18:48:30 +000067 virtual const MCSection *
Chris Lattner24f654c2009-08-06 16:39:58 +000068 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
69 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattner759b8882009-08-06 16:27:28 +000070
Chris Lattnera87dea42009-07-31 18:48:30 +000071 virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattnerf9650c02009-08-01 21:46:23 +000072 SectionKind Kind,
Chris Lattnera87dea42009-07-31 18:48:30 +000073 Mangler *Mang,
74 const TargetMachine&) const;
Chris Lattner759b8882009-08-06 16:27:28 +000075
76 const MCSection *getSectionForFunction(const std::string &FnName) const;
77 const MCSection *getSectionForFunctionFrame(const std::string &FnName)const;
78
79
Chris Lattnerf0144122009-07-28 03:13:23 +000080 private:
81 std::string getSectionNameForSym(const std::string &Sym) const;
82
Chris Lattnera87dea42009-07-31 18:48:30 +000083 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 Lattnerf0144122009-07-28 03:13:23 +000087 std::string Addr = "") const;
Chris Lattnera87dea42009-07-31 18:48:30 +000088 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 Lattnerf0144122009-07-28 03:13:23 +000096 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