blob: a8f4c63fd8611b4d346d9dc1427336f6ac1e3c8a [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"
Sanjiv Guptaeaa8b1f2009-08-21 15:22:33 +000015#include "llvm/Function.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000016#include <vector>
Chris Lattnera4629202009-08-12 23:53:59 +000017#include <string>
Chris Lattnerf0144122009-07-28 03:13:23 +000018
19namespace llvm {
20 class GlobalVariable;
21 class Module;
22 class PIC16TargetMachine;
Chris Lattner93b6db32009-08-08 23:39:42 +000023 class MCSectionPIC16;
Chris Lattnerf0144122009-07-28 03:13:23 +000024
25 enum { DataBankSize = 80 };
26
27 /// PIC16 Splits the global data into mulitple udata and idata sections.
28 /// Each udata and idata section needs to contain a list of globals that
29 /// they contain, in order to avoid scanning over all the global values
30 /// again and printing only those that match the current section.
31 /// Keeping values inside the sections make printing a section much easier.
32 ///
Chris Lattnerf7427e52009-08-08 21:37:01 +000033 /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
Chris Lattnerf0144122009-07-28 03:13:23 +000034 ///
35 struct PIC16Section {
Chris Lattner93b6db32009-08-08 23:39:42 +000036 const MCSectionPIC16 *S_; // Connection to actual Section.
Chris Lattnerf0144122009-07-28 03:13:23 +000037 unsigned Size; // Total size of the objects contained.
38 bool SectionPrinted;
39 std::vector<const GlobalVariable*> Items;
40
Chris Lattner93b6db32009-08-08 23:39:42 +000041 PIC16Section(const MCSectionPIC16 *s) {
Chris Lattnerf0144122009-07-28 03:13:23 +000042 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 class PIC16TargetObjectFile : public TargetLoweringObjectFile {
Chris Lattner873bc4c2009-08-13 00:26:52 +000051 /// SectionsByName - Bindings of names to allocated sections.
52 mutable StringMap<MCSectionPIC16*> SectionsByName;
53
Chris Lattnera87dea42009-07-31 18:48:30 +000054 const TargetMachine *TM;
Chris Lattnerfbf1d272009-08-08 20:14:13 +000055
Chris Lattner93b6db32009-08-08 23:39:42 +000056 const MCSectionPIC16 *getPIC16Section(const char *Name,
57 SectionKind K) const;
Chris Lattnerf0144122009-07-28 03:13:23 +000058 public:
59 mutable std::vector<PIC16Section*> BSSSections;
60 mutable std::vector<PIC16Section*> IDATASections;
61 mutable std::vector<PIC16Section*> AutosSections;
62 mutable std::vector<PIC16Section*> ROSections;
63 mutable PIC16Section *ExternalVarDecls;
64 mutable PIC16Section *ExternalVarDefs;
Daniel Dunbar967ce7f2009-08-02 01:25:15 +000065
66 PIC16TargetObjectFile();
Chris Lattnerf0144122009-07-28 03:13:23 +000067 ~PIC16TargetObjectFile();
68
Chris Lattnera87dea42009-07-31 18:48:30 +000069 void Initialize(MCContext &Ctx, const TargetMachine &TM);
70
71
Chris Lattnera87dea42009-07-31 18:48:30 +000072 virtual const MCSection *
Chris Lattner24f654c2009-08-06 16:39:58 +000073 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
74 Mangler *Mang, const TargetMachine &TM) const;
Chris Lattner759b8882009-08-06 16:27:28 +000075
Chris Lattnera87dea42009-07-31 18:48:30 +000076 virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattnerf9650c02009-08-01 21:46:23 +000077 SectionKind Kind,
Chris Lattnera87dea42009-07-31 18:48:30 +000078 Mangler *Mang,
79 const TargetMachine&) const;
Chris Lattner759b8882009-08-06 16:27:28 +000080
Sanjiv Guptaeb01aba2009-08-20 19:28:24 +000081 const MCSection *getSectionForFunction(const std::string &FnName,
82 bool isInterrupt=false) const;
Chris Lattner759b8882009-08-06 16:27:28 +000083 const MCSection *getSectionForFunctionFrame(const std::string &FnName)const;
84
Sanjiv Guptaeb01aba2009-08-20 19:28:24 +000085 // If the current function is cloned then create the new autos section
86 // also.
87 void createClonedSectionForAutos(const std::string &SecName);
Sanjiv Guptaeaa8b1f2009-08-21 15:22:33 +000088 std::string getNameForFunctFrame(const Function *F,
89 bool IsAutosSection = false);
90
Chris Lattnerf0144122009-07-28 03:13:23 +000091 private:
92 std::string getSectionNameForSym(const std::string &Sym) const;
93
Chris Lattnera87dea42009-07-31 18:48:30 +000094 const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
95 const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
96 const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
97 const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
Chris Lattnerf0144122009-07-28 03:13:23 +000098 std::string Addr = "") const;
Chris Lattnera87dea42009-07-31 18:48:30 +000099 const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
100 std::string Addr = "") const;
101 const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
102 const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
103 std::string Addr = "") const;
104 const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
105 Mangler *Mang,
106 const std::string &Addr = "") const;
Chris Lattnerf0144122009-07-28 03:13:23 +0000107 public:
108 void SetSectionForGVs(Module &M);
109 const std::vector<PIC16Section*> &getBSSSections() const {
110 return BSSSections;
111 }
112 const std::vector<PIC16Section*> &getIDATASections() const {
113 return IDATASections;
114 }
115 const std::vector<PIC16Section*> &getAutosSections() const {
116 return AutosSections;
117 }
118 const std::vector<PIC16Section*> &getROSections() const {
119 return ROSections;
120 }
121
122 };
123} // end namespace llvm
124
125#endif