blob: 1ced3bfde123860d9f69a680a123102a8569ca10 [file] [log] [blame]
Sanjiv Gupta09bb4202008-05-13 09:02:57 +00001//=====-- PIC16TargetAsmInfo.h - PIC16 asm properties ---------*- 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// This file contains the declaration of the PIC16TargetAsmInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef PIC16TARGETASMINFO_H
15#define PIC16TARGETASMINFO_H
16
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000017#include "PIC16.h"
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000018#include "llvm/Target/TargetAsmInfo.h"
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000019#include <vector>
20#include "llvm/Module.h"
Chris Lattner4b4c52d2009-07-21 17:20:18 +000021
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000022namespace llvm {
23
Chris Lattner4b4c52d2009-07-21 17:20:18 +000024 enum { DataBankSize = 80 };
25
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000026 // Forward declaration.
27 class PIC16TargetMachine;
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000028 class GlobalVariable;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000029
Chris Lattner4b4c52d2009-07-21 17:20:18 +000030 /// PIC16 Splits the global data into mulitple udata and idata sections.
31 /// Each udata and idata section needs to contain a list of globals that
32 /// they contain, in order to avoid scanning over all the global values
33 /// again and printing only those that match the current section.
34 /// Keeping values inside the sections make printing a section much easier.
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000035 struct PIC16Section {
Chris Lattner4b4c52d2009-07-21 17:20:18 +000036 const Section *S_; // Connection to actual Section.
37 unsigned Size; // Total size of the objects contained.
38 bool SectionPrinted;
39 std::vector<const GlobalVariable*> Items;
40
41 PIC16Section(const Section *s) {
42 S_ = s;
43 Size = 0;
44 SectionPrinted = false;
45 }
46 bool isPrinted() const { return SectionPrinted; }
47 void setPrintedStatus(bool status) { SectionPrinted = status; }
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000048 };
49
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000050 struct PIC16TargetAsmInfo : public TargetAsmInfo {
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000051 std::string getSectionNameForSym(const std::string &Sym) const;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000052 PIC16TargetAsmInfo(const PIC16TargetMachine &TM);
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000053 mutable std::vector<PIC16Section *> BSSSections;
54 mutable std::vector<PIC16Section *> IDATASections;
Sanjiv Guptadbe79112009-05-12 17:07:27 +000055 mutable std::vector<PIC16Section *> AutosSections;
Sanjiv Guptabb399cf2009-07-06 10:18:37 +000056 mutable std::vector<PIC16Section *> ROSections;
Sanjiv Gupta5ade9e82009-05-13 15:13:17 +000057 mutable PIC16Section *ExternalVarDecls;
58 mutable PIC16Section *ExternalVarDefs;
Sanjiv Guptaca549b72009-05-10 05:23:47 +000059 virtual ~PIC16TargetAsmInfo();
60
Chris Lattner4b4c52d2009-07-21 17:20:18 +000061 private:
Sanjiv Guptadc2943d2009-01-30 04:25:10 +000062 const char *RomData8bitsDirective;
63 const char *RomData16bitsDirective;
64 const char *RomData32bitsDirective;
Sanjiv Gupta46fc9fe2009-02-02 16:53:06 +000065 const char *getRomDirective(unsigned size) const;
Chris Lattnerc8859c52009-07-20 17:12:46 +000066 virtual const char *getDataASDirective(unsigned size, unsigned AS) const;
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000067 const Section *getBSSSectionForGlobal(const GlobalVariable *GV) const;
68 const Section *getIDATASectionForGlobal(const GlobalVariable *GV) const;
Sanjiv Guptadbe79112009-05-12 17:07:27 +000069 const Section *getSectionForAuto(const GlobalVariable *GV) const;
Sanjiv Guptabb399cf2009-07-06 10:18:37 +000070 const Section *CreateBSSSectionForGlobal(const GlobalVariable *GV,
71 std::string Addr = "") const;
72 const Section *CreateIDATASectionForGlobal(const GlobalVariable *GV,
73 std::string Addr = "") const;
74 const Section *getROSectionForGlobal(const GlobalVariable *GV) const;
75 const Section *CreateROSectionForGlobal(const GlobalVariable *GV,
76 std::string Addr = "") const;
Chris Lattnerbb0c9bf2009-07-24 18:42:53 +000077 virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattnercc195212009-07-25 23:21:55 +000078 SectionKind Kind) const;
Chris Lattnerb3889492009-07-24 17:13:27 +000079 const Section *CreateSectionForGlobal(const GlobalVariable *GV,
80 const std::string &Addr = "") const;
Chris Lattner4b4c52d2009-07-21 17:20:18 +000081 public:
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000082 void SetSectionForGVs(Module &M);
Chris Lattner4b4c52d2009-07-21 17:20:18 +000083 const std::vector<PIC16Section*> &getBSSSections() const {
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000084 return BSSSections;
85 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000086 const std::vector<PIC16Section*> &getIDATASections() const {
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000087 return IDATASections;
88 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000089 const std::vector<PIC16Section*> &getAutosSections() const {
Sanjiv Guptadbe79112009-05-12 17:07:27 +000090 return AutosSections;
91 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000092 const std::vector<PIC16Section*> &getROSections() const {
Sanjiv Guptabb399cf2009-07-06 10:18:37 +000093 return ROSections;
94 }
Chris Lattner0ad34562009-07-24 18:34:27 +000095
96 /// getSpecialCasedSectionGlobals - Allow the target to completely override
97 /// section assignment of a global.
98 virtual const Section *
99 getSpecialCasedSectionGlobals(const GlobalValue *GV,
Chris Lattnercc195212009-07-25 23:21:55 +0000100 SectionKind Kind) const;
Chris Lattner0ad34562009-07-24 18:34:27 +0000101
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000102 };
103
104} // namespace llvm
105
106#endif