//===----------------------------------------------------------------------===//
#include "PIC16TargetObjectFile.h"
+#include "PIC16Section.h"
#include "PIC16ISelLowering.h"
#include "PIC16TargetMachine.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+MCSectionPIC16::MCSectionPIC16(const StringRef &name, SectionKind K,
+ MCContext &Ctx) : MCSection(K), Name(name) {
+ Ctx.SetSection(Name, this);
+}
+
+MCSectionPIC16 *MCSectionPIC16::Create(const StringRef &Name,
+ SectionKind K, MCContext &Ctx) {
+ return new (Ctx) MCSectionPIC16(Name, K, Ctx);
+}
+
+
+void MCSectionPIC16::PrintSwitchToSection(const TargetAsmInfo &TAI,
+ raw_ostream &OS) const {
+ OS << getName() << '\n';
+}
+
+
+
+
+PIC16TargetObjectFile::PIC16TargetObjectFile()
+ : ExternalVarDecls(0), ExternalVarDefs(0) {
+}
+
+const MCSectionPIC16 *PIC16TargetObjectFile::
+getPIC16Section(const char *Name, SectionKind Kind) const {
+ if (MCSection *S = getContext().GetSection(Name))
+ return (MCSectionPIC16*)S;
+ return MCSectionPIC16::Create(Name, Kind, getContext());
+}
+
+
void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
TargetLoweringObjectFile::Initialize(Ctx, tm);
TM = &tm;
- BSSSection = getOrCreateSection("udata.# UDATA", false,
- SectionKind::getBSS());
- ReadOnlySection = getOrCreateSection("romdata.# ROMDATA", false,
- SectionKind::getReadOnly());
- DataSection = getOrCreateSection("idata.# IDATA", false,
- SectionKind::getDataRel());
+ BSSSection = getPIC16Section("udata.# UDATA", SectionKind::getBSS());
+ ReadOnlySection = getPIC16Section("romdata.# ROMDATA",
+ SectionKind::getReadOnly());
+ DataSection = getPIC16Section("idata.# IDATA", SectionKind::getDataRel());
// Need because otherwise a .text symbol is emitted by DwarfWriter
// in BeginModule, and gpasm cribbs for that .text symbol.
- TextSection = getOrCreateSection("", true,
- SectionKind::getText());
+ TextSection = getPIC16Section("", SectionKind::getText());
- ROSections.push_back(new PIC16Section(ReadOnlySection));
+ ROSections.push_back(new PIC16Section((MCSectionPIC16*)ReadOnlySection));
// FIXME: I don't know what the classification of these sections really is.
- ExternalVarDecls = new PIC16Section(getOrCreateSection("ExternalVarDecls",
- false,
+ ExternalVarDecls = new PIC16Section(getPIC16Section("ExternalVarDecls",
SectionKind::getMetadata()));
- ExternalVarDefs = new PIC16Section(getOrCreateSection("ExternalVarDefs",
- false,
+ ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs",
SectionKind::getMetadata()));
}
+const MCSection *PIC16TargetObjectFile::
+getSectionForFunction(const std::string &FnName) const {
+ std::string T = PAN::getCodeSectionName(FnName);
+ return getPIC16Section(T.c_str(), SectionKind::getText());
+}
+
+
+const MCSection *PIC16TargetObjectFile::
+getSectionForFunctionFrame(const std::string &FnName) const {
+ std::string T = PAN::getFrameSectionName(FnName);
+ return getPIC16Section(T.c_str(), SectionKind::getDataRel());
+}
const MCSection *
PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
// No BSS section spacious enough was found. Crate a new one.
if (!FoundBSS) {
std::string name = PAN::getUdataSectionName(BSSSections.size());
- const MCSection *NewSection = getOrCreateSection(name.c_str(), false,
- // FIXME.
- SectionKind::getMetadata());
+ const MCSectionPIC16 *NewSection
+ = getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
FoundBSS = new PIC16Section(NewSection);
// No IDATA section spacious enough was found. Crate a new one.
if (!FoundIDATA) {
std::string name = PAN::getIdataSectionName(IDATASections.size());
- const MCSection *NewSection = getOrCreateSection(name.c_str(), false,
- // FIXME.
- SectionKind::getMetadata());
+ const MCSectionPIC16 *NewSection =
+ getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
FoundIDATA = new PIC16Section(NewSection);
// No Auto section was found. Crate a new one.
if (!FoundAutoSec) {
- const MCSection *NewSection = getOrCreateSection(name.c_str(),
- // FIXME.
- false,
- SectionKind::getMetadata());
+ const MCSectionPIC16 *NewSection =
+ getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
FoundAutoSec = new PIC16Section(NewSection);
/// getSpecialCasedSectionGlobals - Allow the target to completely override
/// section assignment of a global.
-const MCSection *
-PIC16TargetObjectFile::getSpecialCasedSectionGlobals(const GlobalValue *GV,
- Mangler *Mang,
- SectionKind Kind) const {
- // If GV has a sectin name or section address create that section now.
- if (GV->hasSection()) {
- if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
- std::string SectName = GVar->getSection();
- // If address for a variable is specified, get the address and create
- // section.
- std::string AddrStr = "Address=";
- if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
- std::string SectAddr = SectName.substr(AddrStr.length());
- return CreateSectionForGlobal(GVar, Mang, SectAddr);
- }
-
- // Create the section specified with section attribute.
- return CreateSectionForGlobal(GVar, Mang);
+const MCSection *PIC16TargetObjectFile::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
+ Mangler *Mang, const TargetMachine &TM) const {
+ assert(GV->hasSection());
+
+ if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
+ std::string SectName = GVar->getSection();
+ // If address for a variable is specified, get the address and create
+ // section.
+ std::string AddrStr = "Address=";
+ if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
+ std::string SectAddr = SectName.substr(AddrStr.length());
+ return CreateSectionForGlobal(GVar, Mang, SectAddr);
}
+
+ // Create the section specified with section attribute.
+ return CreateSectionForGlobal(GVar, Mang);
}
- return 0;
+ return getPIC16Section(GV->getSection().c_str(), Kind);
}
// Create a new section for global variable. If Addr is given then create
PIC16Section *NewBSS = FoundBSS;
if (NewBSS == NULL) {
- const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
- SectionKind::getBSS());
+ const MCSectionPIC16 *NewSection =
+ getPIC16Section(Name.c_str(), SectionKind::getBSS());
NewBSS = new PIC16Section(NewSection);
BSSSections.push_back(NewBSS);
}
PIC16Section *NewIDATASec = FoundIDATASec;
if (NewIDATASec == NULL) {
- const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
- // FIXME:
- SectionKind::getMetadata());
+ const MCSectionPIC16 *NewSection =
+ getPIC16Section(Name.c_str(), /* FIXME */SectionKind::getMetadata());
NewIDATASec = new PIC16Section(NewSection);
IDATASections.push_back(NewIDATASec);
}
PIC16Section *NewRomSec = FoundROSec;
if (NewRomSec == NULL) {
- const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
- SectionKind::getReadOnly());
+ const MCSectionPIC16 *NewSection =
+ getPIC16Section(Name.c_str(), SectionKind::getReadOnly());
NewRomSec = new PIC16Section(NewSection);
ROSections.push_back(NewRomSec);
}