blob: 8013bba9df9bc3b1e2f55e1daed934e3e0f51fa2 [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;
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000077 virtual const Section *SelectSectionForGlobal(const GlobalValue *GV) const;
Sanjiv Guptabb399cf2009-07-06 10:18:37 +000078 const Section * CreateSectionForGlobal(const GlobalValue *GV,
79 std::string Addr = "") const;
Chris Lattner4b4c52d2009-07-21 17:20:18 +000080 public:
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000081 void SetSectionForGVs(Module &M);
Chris Lattner4b4c52d2009-07-21 17:20:18 +000082 const std::vector<PIC16Section*> &getBSSSections() const {
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000083 return BSSSections;
84 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000085 const std::vector<PIC16Section*> &getIDATASections() const {
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000086 return IDATASections;
87 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000088 const std::vector<PIC16Section*> &getAutosSections() const {
Sanjiv Guptadbe79112009-05-12 17:07:27 +000089 return AutosSections;
90 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000091 const std::vector<PIC16Section*> &getROSections() const {
Sanjiv Guptabb399cf2009-07-06 10:18:37 +000092 return ROSections;
93 }
Chris Lattner4b4c52d2009-07-21 17:20:18 +000094 virtual const Section *SectionForGlobal(const GlobalValue *GV) const;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000095 };
96
97} // namespace llvm
98
99#endif