blob: 75f6cced0ab8221215fde9269fa7e4fa28eb600b [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"
Chris Lattner873bc4c2009-08-13 00:26:52 +000014#include "llvm/ADT/StringMap.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000015#include <vector>
Chris Lattnera4629202009-08-12 23:53:59 +000016#include <string>
Chris Lattnerf0144122009-07-28 03:13:23 +000017
18namespace llvm {
19 class GlobalVariable;
20 class Module;
21 class PIC16TargetMachine;
Chris Lattner93b6db32009-08-08 23:39:42 +000022 class MCSectionPIC16;
Chris Lattnerf0144122009-07-28 03:13:23 +000023
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 ///
Chris Lattnerf7427e52009-08-08 21:37:01 +000032 /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
Chris Lattnerf0144122009-07-28 03:13:23 +000033 ///
34 struct PIC16Section {
Chris Lattner93b6db32009-08-08 23:39:42 +000035 const MCSectionPIC16 *S_; // Connection to actual Section.
Chris Lattnerf0144122009-07-28 03:13:23 +000036 unsigned Size; // Total size of the objects contained.
37 bool SectionPrinted;
38 std::vector<const GlobalVariable*> Items;
39
Chris Lattner93b6db32009-08-08 23:39:42 +000040 PIC16Section(const MCSectionPIC16 *s) {
Chris Lattnerf0144122009-07-28 03:13:23 +000041 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 {
Chris Lattner873bc4c2009-08-13 00:26:52 +000050 /// SectionsByName - Bindings of names to allocated sections.
51 mutable StringMap<MCSectionPIC16*> SectionsByName;
52
Chris Lattnera87dea42009-07-31 18:48:30 +000053 const TargetMachine *TM;
Chris Lattnerfbf1d272009-08-08 20:14:13 +000054
Chris Lattner93b6db32009-08-08 23:39:42 +000055 const MCSectionPIC16 *getPIC16Section(const char *Name,
Sanjiv Guptab9ef7642009-08-25 19:39:05 +000056 SectionKind K,
Sanjiv Gupta72f9ab02009-09-01 10:47:31 +000057 int Address = -1,
58 int Color = -1) const;
Chris Lattnerf0144122009-07-28 03:13:23 +000059 public:
60 mutable std::vector<PIC16Section*> BSSSections;
61 mutable std::vector<PIC16Section*> IDATASections;
62 mutable std::vector<PIC16Section*> AutosSections;
63 mutable std::vector<PIC16Section*> ROSections;
64 mutable PIC16Section *ExternalVarDecls;
65 mutable PIC16Section *ExternalVarDefs;
Daniel Dunbar967ce7f2009-08-02 01:25:15 +000066
67 PIC16TargetObjectFile();
Chris Lattnerf0144122009-07-28 03:13:23 +000068 ~PIC16TargetObjectFile();
69
Chris Lattnera87dea42009-07-31 18:48:30 +000070 void Initialize(MCContext &Ctx, const TargetMachine &TM);
71
72
Chris Lattnera87dea42009-07-31 18:48:30 +000073 virtual const MCSection *
Chris Lattner24f654c2009-08-06 16:39:58 +000074 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
75 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattner759b8882009-08-06 16:27:28 +000076
Chris Lattnera87dea42009-07-31 18:48:30 +000077 virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattnerf9650c02009-08-01 21:46:23 +000078 SectionKind Kind,
Chris Lattnera87dea42009-07-31 18:48:30 +000079 Mangler *Mang,
80 const TargetMachine&) const;
Chris Lattner759b8882009-08-06 16:27:28 +000081
Chris Lattner35a27c82009-08-21 23:12:15 +000082 const MCSection *getSectionForFunction(const std::string &FnName) const;
Chris Lattner759b8882009-08-06 16:27:28 +000083 const MCSection *getSectionForFunctionFrame(const std::string &FnName)const;
84
Chris Lattner35a27c82009-08-21 23:12:15 +000085
Chris Lattnerf0144122009-07-28 03:13:23 +000086 private:
87 std::string getSectionNameForSym(const std::string &Sym) const;
88
Chris Lattnera87dea42009-07-31 18:48:30 +000089 const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
90 const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
91 const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
92 const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
Chris Lattnerf0144122009-07-28 03:13:23 +000093 std::string Addr = "") const;
Chris Lattnera87dea42009-07-31 18:48:30 +000094 const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
95 std::string Addr = "") const;
96 const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
97 const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
98 std::string Addr = "") const;
99 const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
100 Mangler *Mang,
101 const std::string &Addr = "") const;
Chris Lattnerf0144122009-07-28 03:13:23 +0000102 public:
103 void SetSectionForGVs(Module &M);
104 const std::vector<PIC16Section*> &getBSSSections() const {
105 return BSSSections;
106 }
107 const std::vector<PIC16Section*> &getIDATASections() const {
108 return IDATASections;
109 }
110 const std::vector<PIC16Section*> &getAutosSections() const {
111 return AutosSections;
112 }
113 const std::vector<PIC16Section*> &getROSections() const {
114 return ROSections;
115 }
116
117 };
118} // end namespace llvm
119
120#endif