blob: 7029501e6a2e92715f3e2f9e5b020243cba6af28 [file] [log] [blame]
Benjamin Kramer5814fef2009-10-15 19:46:34 +00001//===-- PIC16Section.cpp - PIC16 Section ----------- --------------------===//
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#include "PIC16.h"
11#include "PIC16ABINames.h"
12#include "PIC16Section.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/Support/raw_ostream.h"
15using namespace llvm;
16
17
18// This is the only way to create a PIC16Section. Sections created here
19// do not need to be explicitly deleted as they are managed by auto_ptrs.
20PIC16Section *PIC16Section::Create(const StringRef &Name,
21 PIC16SectionType Ty,
22 const std::string &Address,
23 int Color, MCContext &Ctx) {
24
25 /// Determine the internal SectionKind info.
26 /// Users of PIC16Section class should not need to know the internal
27 /// SectionKind. They should work only with PIC16SectionType.
28 ///
29 /// PIC16 Terminology for section kinds is as below.
30 /// UDATA - BSS
31 /// IDATA - initialized data (equiv to Metadata)
32 /// ROMDATA - ReadOnly.
33 /// UDATA_OVR - Sections that can be overlaid. Section of such type is
34 /// used to contain function autos an frame. We can think of
35 /// it as equiv to llvm ThreadBSS)
36 /// UDATA_SHR - Shared RAM. Memory area that is mapped to all banks.
37
38 SectionKind K;
39 switch (Ty) {
40 default: llvm_unreachable ("can not create unknown section type");
41 case UDATA_OVR: {
42 K = SectionKind::getThreadBSS();
43 break;
44 }
45 case UDATA_SHR:
46 case UDATA: {
47 K = SectionKind::getBSS();
48 break;
49 }
50 case ROMDATA:
51 case IDATA: {
52 K = SectionKind::getMetadata();
53 break;
54 }
55 case CODE: {
56 K = SectionKind::getText();
57 break;
58 }
59
60 }
61
62 // Create the Section.
63 PIC16Section *S = new (Ctx) PIC16Section(Name, K, Address, Color);
64 S->T = Ty;
65 return S;
66}
67
68// A generic way to print all types of sections.
69void PIC16Section::PrintSwitchToSection(const MCAsmInfo &MAI,
70 raw_ostream &OS) const {
71 // Print name.
72 OS << getName() << '\t';
73
74 // Print type.
75 switch (getType()) {
76 default : llvm_unreachable ("unknown section type");
77 case UDATA: OS << "UDATA"; break;
78 case IDATA: OS << "IDATA"; break;
79 case ROMDATA: OS << "ROMDATA"; break;
80 case UDATA_SHR: OS << "UDATA_SHR"; break;
81 case UDATA_OVR: OS << "UDATA_OVR"; break;
82 case CODE: OS << "CODE"; break;
83 }
84
85 OS << '\t';
86
87 // Print Address.
88 OS << Address;
89
90 OS << '\n';
91}