1 //===-- PIC16Section.cpp - PIC16 Section ----------- --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "PIC16ABINames.h"
12 #include "PIC16Section.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/Support/raw_ostream.h"
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.
20 PIC16Section *PIC16Section::Create(StringRef Name, PIC16SectionType Ty,
21 StringRef Address, int Color,
24 /// Determine the internal SectionKind info.
25 /// Users of PIC16Section class should not need to know the internal
26 /// SectionKind. They should work only with PIC16SectionType.
28 /// PIC16 Terminology for section kinds is as below.
30 /// IDATA - initialized data (equiv to Metadata)
31 /// ROMDATA - ReadOnly.
32 /// UDATA_OVR - Sections that can be overlaid. Section of such type is
33 /// used to contain function autos an frame. We can think of
34 /// it as equiv to llvm ThreadBSS)
35 /// UDATA_SHR - Shared RAM. Memory area that is mapped to all banks.
39 default: llvm_unreachable ("can not create unknown section type");
41 K = SectionKind::getThreadBSS();
46 K = SectionKind::getBSS();
51 K = SectionKind::getMetadata();
55 K = SectionKind::getText();
61 // Copy strings into context allocated memory so they get free'd when the
62 // context is destroyed.
63 char *NameCopy = static_cast<char*>(Ctx.Allocate(Name.size(), 1));
64 memcpy(NameCopy, Name.data(), Name.size());
65 char *AddressCopy = static_cast<char*>(Ctx.Allocate(Address.size(), 1));
66 memcpy(AddressCopy, Address.data(), Address.size());
68 // Create the Section.
70 new (Ctx) PIC16Section(StringRef(NameCopy, Name.size()), K,
71 StringRef(AddressCopy, Address.size()), Color);
76 // A generic way to print all types of sections.
77 void PIC16Section::PrintSwitchToSection(const MCAsmInfo &MAI,
78 raw_ostream &OS) const {
80 // If the section is overlaid(i.e. it has a color), print overlay name for
81 // it. Otherwise print its normal name.
83 OS << PAN::getOverlayName(getName(), Color) << '\t';
85 OS << getName() << '\t';
89 default : llvm_unreachable ("unknown section type");
90 case UDATA: OS << "UDATA"; break;
91 case IDATA: OS << "IDATA"; break;
92 case ROMDATA: OS << "ROMDATA"; break;
93 case UDATA_SHR: OS << "UDATA_SHR"; break;
94 case UDATA_OVR: OS << "UDATA_OVR"; break;
95 case CODE: OS << "CODE"; break;