blob: f8389a6adc7529f14004233d20f800a0d30278a5 [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>
15
16namespace llvm {
17 class GlobalVariable;
18 class Module;
19 class PIC16TargetMachine;
20
21 enum { DataBankSize = 80 };
22
23 /// PIC16 Splits the global data into mulitple udata and idata sections.
24 /// Each udata and idata section needs to contain a list of globals that
25 /// they contain, in order to avoid scanning over all the global values
26 /// again and printing only those that match the current section.
27 /// Keeping values inside the sections make printing a section much easier.
28 ///
Chris Lattnerf7427e52009-08-08 21:37:01 +000029 /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
Chris Lattnerf0144122009-07-28 03:13:23 +000030 ///
31 struct PIC16Section {
Chris Lattnera87dea42009-07-31 18:48:30 +000032 const MCSection *S_; // Connection to actual Section.
Chris Lattnerf0144122009-07-28 03:13:23 +000033 unsigned Size; // Total size of the objects contained.
34 bool SectionPrinted;
35 std::vector<const GlobalVariable*> Items;
36
Chris Lattnera87dea42009-07-31 18:48:30 +000037 PIC16Section(const MCSection *s) {
Chris Lattnerf0144122009-07-28 03:13:23 +000038 S_ = s;
39 Size = 0;
40 SectionPrinted = false;
41 }
42 bool isPrinted() const { return SectionPrinted; }
43 void setPrintedStatus(bool status) { SectionPrinted = status; }
44 };
45
46 class PIC16TargetObjectFile : public TargetLoweringObjectFile {
Chris Lattnera87dea42009-07-31 18:48:30 +000047 const TargetMachine *TM;
Chris Lattnerfbf1d272009-08-08 20:14:13 +000048
Chris Lattner9aee1812009-08-08 20:23:47 +000049 const MCSection *getPIC16Section(const char *Name, bool isDirective,
50 SectionKind K) const;
Chris Lattnerf0144122009-07-28 03:13:23 +000051 public:
52 mutable std::vector<PIC16Section*> BSSSections;
53 mutable std::vector<PIC16Section*> IDATASections;
54 mutable std::vector<PIC16Section*> AutosSections;
55 mutable std::vector<PIC16Section*> ROSections;
56 mutable PIC16Section *ExternalVarDecls;
57 mutable PIC16Section *ExternalVarDefs;
Daniel Dunbar967ce7f2009-08-02 01:25:15 +000058
59 PIC16TargetObjectFile();
Chris Lattnerf0144122009-07-28 03:13:23 +000060 ~PIC16TargetObjectFile();
61
Chris Lattnera87dea42009-07-31 18:48:30 +000062 void Initialize(MCContext &Ctx, const TargetMachine &TM);
63
64
Chris Lattnera87dea42009-07-31 18:48:30 +000065 virtual const MCSection *
Chris Lattner24f654c2009-08-06 16:39:58 +000066 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
67 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattner759b8882009-08-06 16:27:28 +000068
Chris Lattnera87dea42009-07-31 18:48:30 +000069 virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattnerf9650c02009-08-01 21:46:23 +000070 SectionKind Kind,
Chris Lattnera87dea42009-07-31 18:48:30 +000071 Mangler *Mang,
72 const TargetMachine&) const;
Chris Lattner759b8882009-08-06 16:27:28 +000073
74 const MCSection *getSectionForFunction(const std::string &FnName) const;
75 const MCSection *getSectionForFunctionFrame(const std::string &FnName)const;
76
77
Chris Lattnerf0144122009-07-28 03:13:23 +000078 private:
79 std::string getSectionNameForSym(const std::string &Sym) const;
80
Chris Lattnera87dea42009-07-31 18:48:30 +000081 const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
82 const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
83 const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
84 const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
Chris Lattnerf0144122009-07-28 03:13:23 +000085 std::string Addr = "") const;
Chris Lattnera87dea42009-07-31 18:48:30 +000086 const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
87 std::string Addr = "") const;
88 const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
89 const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
90 std::string Addr = "") const;
91 const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
92 Mangler *Mang,
93 const std::string &Addr = "") const;
Chris Lattnerf0144122009-07-28 03:13:23 +000094 public:
95 void SetSectionForGVs(Module &M);
96 const std::vector<PIC16Section*> &getBSSSections() const {
97 return BSSSections;
98 }
99 const std::vector<PIC16Section*> &getIDATASections() const {
100 return IDATASections;
101 }
102 const std::vector<PIC16Section*> &getAutosSections() const {
103 return AutosSections;
104 }
105 const std::vector<PIC16Section*> &getROSections() const {
106 return ROSections;
107 }
108
109 };
110} // end namespace llvm
111
112#endif