sink the 'name' and 'isdirective' state out of MCSection into its derived classes.

This totally optimizes PIC16 sections by not having an 'isdirective' bit anymore!! ;-)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78517 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-08-08 23:39:42 +00:00
parent 8e9ece75db
commit 93b6db3de9
13 changed files with 167 additions and 116 deletions

View File

@ -41,8 +41,6 @@ namespace llvm {
/// We use a bump pointer allocator to avoid the need to track all allocated /// We use a bump pointer allocator to avoid the need to track all allocated
/// objects. /// objects.
BumpPtrAllocator Allocator; BumpPtrAllocator Allocator;
friend class MCSection;
public: public:
MCContext(); MCContext();
~MCContext(); ~MCContext();
@ -51,6 +49,13 @@ namespace llvm {
/// null if it doesn't exist. /// null if it doesn't exist.
MCSection *GetSection(const StringRef &Name) const; MCSection *GetSection(const StringRef &Name) const;
void SetSection(const StringRef &Name, MCSection *S) {
MCSection *&Entry = Sections[Name];
assert(Entry == 0 && "Multiple sections with the same name created");
Entry = S;
}
/// CreateSymbol - Create a new symbol with the specified @param Name. /// CreateSymbol - Create a new symbol with the specified @param Name.
/// ///
/// @param Name - The symbol name, which must be unique across all symbols. /// @param Name - The symbol name, which must be unique across all symbols.

View File

@ -27,27 +27,14 @@ namespace llvm {
/// section in the current translation unit. The MCContext class uniques and /// section in the current translation unit. The MCContext class uniques and
/// creates these. /// creates these.
class MCSection { class MCSection {
std::string Name;
/// IsDirective - This is true if the section name is a directive, not
/// something that should be printed with ".section".
///
/// FIXME: This is a hack. Switch to a semantic view of the section instead
/// of a syntactic one.
bool IsDirective;
MCSection(const MCSection&); // DO NOT IMPLEMENT MCSection(const MCSection&); // DO NOT IMPLEMENT
void operator=(const MCSection&); // DO NOT IMPLEMENT void operator=(const MCSection&); // DO NOT IMPLEMENT
protected: protected:
MCSection(const StringRef &Name, bool IsDirective, SectionKind K, MCSection(SectionKind K) : Kind(K) {}
MCContext &Ctx);
SectionKind Kind; SectionKind Kind;
public: public:
virtual ~MCSection(); virtual ~MCSection();
const std::string &getName() const { return Name; }
bool isDirective() const { return IsDirective; }
SectionKind getKind() const { return Kind; } SectionKind getKind() const { return Kind; }
virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
@ -56,37 +43,74 @@ namespace llvm {
class MCSectionELF : public MCSection { class MCSectionELF : public MCSection {
std::string Name;
/// IsDirective - This is true if the section name is a directive, not
/// something that should be printed with ".section".
///
/// FIXME: This is a hack. Switch to a semantic view of the section instead
/// of a syntactic one.
bool IsDirective;
MCSectionELF(const StringRef &Name, bool IsDirective, SectionKind K, MCSectionELF(const StringRef &Name, bool IsDirective, SectionKind K,
MCContext &Ctx) : MCSection(Name, IsDirective, K, Ctx) {} MCContext &Ctx);
public: public:
static MCSectionELF *Create(const StringRef &Name, bool IsDirective, static MCSectionELF *Create(const StringRef &Name, bool IsDirective,
SectionKind K, MCContext &Ctx); SectionKind K, MCContext &Ctx);
const std::string &getName() const { return Name; }
bool isDirective() const { return IsDirective; }
virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const; raw_ostream &OS) const;
}; };
class MCSectionMachO : public MCSection { class MCSectionMachO : public MCSection {
std::string Name;
/// IsDirective - This is true if the section name is a directive, not
/// something that should be printed with ".section".
///
/// FIXME: This is a hack. Switch to a semantic view of the section instead
/// of a syntactic one.
bool IsDirective;
MCSectionMachO(const StringRef &Name, bool IsDirective, SectionKind K, MCSectionMachO(const StringRef &Name, bool IsDirective, SectionKind K,
MCContext &Ctx) : MCSection(Name, IsDirective, K, Ctx) {} MCContext &Ctx);
public: public:
static MCSectionMachO *Create(const StringRef &Name, bool IsDirective, static MCSectionMachO *Create(const StringRef &Name, bool IsDirective,
SectionKind K, MCContext &Ctx); SectionKind K, MCContext &Ctx);
const std::string &getName() const { return Name; }
bool isDirective() const { return IsDirective; }
virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const; raw_ostream &OS) const;
}; };
class MCSectionCOFF : public MCSection { class MCSectionCOFF : public MCSection {
std::string Name;
/// IsDirective - This is true if the section name is a directive, not
/// something that should be printed with ".section".
///
/// FIXME: This is a hack. Switch to a semantic view of the section instead
/// of a syntactic one.
bool IsDirective;
MCSectionCOFF(const StringRef &Name, bool IsDirective, SectionKind K, MCSectionCOFF(const StringRef &Name, bool IsDirective, SectionKind K,
MCContext &Ctx) : MCSection(Name, IsDirective, K, Ctx) {} MCContext &Ctx);
public: public:
static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective, static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective,
SectionKind K, MCContext &Ctx); SectionKind K, MCContext &Ctx);
const std::string &getName() const { return Name; }
bool isDirective() const { return IsDirective; }
virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const; raw_ostream &OS) const;
}; };

View File

@ -2133,13 +2133,12 @@ void DwarfDebug::EmitDebugLines() {
// Isolate current sections line info. // Isolate current sections line info.
const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j]; const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
if (Asm->isVerbose()) { /*if (Asm->isVerbose()) {
const MCSection *S = SectionMap[j + 1]; const MCSection *S = SectionMap[j + 1];
O << '\t' << TAI->getCommentString() << " Section" O << '\t' << TAI->getCommentString() << " Section"
<< S->getName() << '\n'; << S->getName() << '\n';
} else { }*/
Asm->EOL(); Asm->EOL();
}
// Dwarf assumes we start with first line of first source file. // Dwarf assumes we start with first line of first source file.
unsigned Source = 1; unsigned Source = 1;

View File

@ -179,21 +179,21 @@ void ELFWriter::addExternalSymbol(const char *External) {
// getCtorSection - Get the static constructor section // getCtorSection - Get the static constructor section
ELFSection &ELFWriter::getCtorSection() { ELFSection &ELFWriter::getCtorSection() {
const MCSection *Ctor = TLOF.getStaticCtorSection(); const MCSection *Ctor = TLOF.getStaticCtorSection();
return getSection(Ctor->getName(), ELFSection::SHT_PROGBITS, return getSection(((MCSectionELF*)Ctor)->getName(), ELFSection::SHT_PROGBITS,
getElfSectionFlags(Ctor->getKind())); getElfSectionFlags(Ctor->getKind()));
} }
// getDtorSection - Get the static destructor section // getDtorSection - Get the static destructor section
ELFSection &ELFWriter::getDtorSection() { ELFSection &ELFWriter::getDtorSection() {
const MCSection *Dtor = TLOF.getStaticDtorSection(); const MCSection *Dtor = TLOF.getStaticDtorSection();
return getSection(Dtor->getName(), ELFSection::SHT_PROGBITS, return getSection(((MCSectionELF*)Dtor)->getName(), ELFSection::SHT_PROGBITS,
getElfSectionFlags(Dtor->getKind())); getElfSectionFlags(Dtor->getKind()));
} }
// getTextSection - Get the text section for the specified function // getTextSection - Get the text section for the specified function
ELFSection &ELFWriter::getTextSection(Function *F) { ELFSection &ELFWriter::getTextSection(Function *F) {
const MCSection *Text = TLOF.SectionForGlobal(F, Mang, TM); const MCSection *Text = TLOF.SectionForGlobal(F, Mang, TM);
return getSection(Text->getName(), ELFSection::SHT_PROGBITS, return getSection(((MCSectionELF*)Text)->getName(), ELFSection::SHT_PROGBITS,
getElfSectionFlags(Text->getKind())); getElfSectionFlags(Text->getKind()));
} }
@ -201,7 +201,7 @@ ELFSection &ELFWriter::getTextSection(Function *F) {
// emitting jump tables. TODO: add PIC support // emitting jump tables. TODO: add PIC support
ELFSection &ELFWriter::getJumpTableSection() { ELFSection &ELFWriter::getJumpTableSection() {
const MCSection *JT = TLOF.getSectionForConstant(SectionKind::getReadOnly()); const MCSection *JT = TLOF.getSectionForConstant(SectionKind::getReadOnly());
return getSection(JT->getName(), return getSection(((MCSectionELF*)JT)->getName(),
ELFSection::SHT_PROGBITS, ELFSection::SHT_PROGBITS,
getElfSectionFlags(JT->getKind()), getElfSectionFlags(JT->getKind()),
TM.getTargetData()->getPointerABIAlignment()); TM.getTargetData()->getPointerABIAlignment());
@ -226,7 +226,8 @@ ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) {
} }
} }
return getSection(TLOF.getSectionForConstant(Kind)->getName(), const MCSection *CPSect = TLOF.getSectionForConstant(Kind);
return getSection(((MCSectionELF*)CPSect)->getName(),
ELFSection::SHT_PROGBITS, ELFSection::SHT_PROGBITS,
getElfSectionFlags(Kind), getElfSectionFlags(Kind),
CPE.getAlignment()); CPE.getAlignment());
@ -369,7 +370,8 @@ void ELFWriter::EmitGlobal(const GlobalValue *GV) {
if (isELFCommonSym(GVar)) { if (isELFCommonSym(GVar)) {
GblSym->SectionIdx = ELFSection::SHN_COMMON; GblSym->SectionIdx = ELFSection::SHN_COMMON;
getSection(S->getName(), ELFSection::SHT_NOBITS, SectionFlags, 1); getSection(((MCSectionELF*)S)->getName(),
ELFSection::SHT_NOBITS, SectionFlags, 1);
// A new linkonce section is created for each global in the // A new linkonce section is created for each global in the
// common section, the default alignment is 1 and the symbol // common section, the default alignment is 1 and the symbol
@ -378,7 +380,8 @@ void ELFWriter::EmitGlobal(const GlobalValue *GV) {
} else if (isELFBssSym(GVar, Kind)) { } else if (isELFBssSym(GVar, Kind)) {
ELFSection &ES = ELFSection &ES =
getSection(S->getName(), ELFSection::SHT_NOBITS, SectionFlags); getSection(((MCSectionELF*)S)->getName(), ELFSection::SHT_NOBITS,
SectionFlags);
GblSym->SectionIdx = ES.SectionIdx; GblSym->SectionIdx = ES.SectionIdx;
// Update the size with alignment and the next object can // Update the size with alignment and the next object can
@ -393,7 +396,8 @@ void ELFWriter::EmitGlobal(const GlobalValue *GV) {
} else { // The symbol must go to some kind of data section } else { // The symbol must go to some kind of data section
ELFSection &ES = ELFSection &ES =
getSection(S->getName(), ELFSection::SHT_PROGBITS, SectionFlags); getSection(((MCSectionELF*)S)->getName(), ELFSection::SHT_PROGBITS,
SectionFlags);
GblSym->SectionIdx = ES.SectionIdx; GblSym->SectionIdx = ES.SectionIdx;
// GblSym->Value should contain the symbol offset inside the section, // GblSym->Value should contain the symbol offset inside the section,

View File

@ -100,13 +100,6 @@ static inline bool NeedsQuoting(const StringRef &Str) {
return false; return false;
} }
/// Allow printing sections directly to a raw_ostream with proper quoting.
static inline raw_ostream &operator<<(raw_ostream &os, const MCSection *S) {
if (NeedsQuoting(S->getName()))
return os << '"' << S->getName() << '"';
return os << S->getName();
}
/// Allow printing symbols directly to a raw_ostream with proper quoting. /// Allow printing symbols directly to a raw_ostream with proper quoting.
static inline raw_ostream &operator<<(raw_ostream &os, const MCSymbol *S) { static inline raw_ostream &operator<<(raw_ostream &os, const MCSymbol *S) {
if (NeedsQuoting(S->getName())) if (NeedsQuoting(S->getName()))
@ -144,10 +137,8 @@ void MCAsmStreamer::SwitchSection(MCSection *Section) {
if (Section != CurSection) { if (Section != CurSection) {
CurSection = Section; CurSection = Section;
// FIXME: Really we would like the segment, flags, etc. to be separate // FIXME: Needs TargetAsmInfo!
// values instead of embedded in the name. Not all assemblers understand all Section->PrintSwitchToSection(*(const TargetAsmInfo*)0, OS);
// this stuff though.
OS << ".section " << Section << "\n";
} }
} }
@ -228,7 +219,12 @@ void MCAsmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
// FIXME: Really we would like the segment and section names as well as the // FIXME: Really we would like the segment and section names as well as the
// section type to be separate values instead of embedded in the name. Not // section type to be separate values instead of embedded in the name. Not
// all assemblers understand all this stuff though. // all assemblers understand all this stuff though.
OS << ".zerofill " << Section; OS << ".zerofill ";
// This is a mach-o specific directive.
OS << '"' << ((MCSectionMachO*)Section)->getName() << '"';
if (Symbol != NULL) { if (Symbol != NULL) {
OS << ',' << Symbol << ',' << Size; OS << ',' << Symbol << ',' << Size;
if (Pow2Alignment != 0) if (Pow2Alignment != 0)

View File

@ -20,13 +20,6 @@ using namespace llvm;
MCSection::~MCSection() { MCSection::~MCSection() {
} }
MCSection::MCSection(const StringRef &N, bool isDirective, SectionKind K,
MCContext &Ctx)
: Name(N), IsDirective(isDirective), Kind(K) {
MCSection *&Entry = Ctx.Sections[Name];
assert(Entry == 0 && "Multiple sections with the same name created");
Entry = this;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// MCSectionELF // MCSectionELF
@ -37,6 +30,13 @@ Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx); return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
} }
MCSectionELF::MCSectionELF(const StringRef &name, bool isDirective,
SectionKind K, MCContext &Ctx)
: MCSection(K), Name(name), IsDirective(isDirective) {
Ctx.SetSection(Name, this);
}
void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI, void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const { raw_ostream &OS) const {
if (isDirective()) { if (isDirective()) {
@ -118,6 +118,12 @@ Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionMachO(Name, IsDirective, K, Ctx); return new (Ctx) MCSectionMachO(Name, IsDirective, K, Ctx);
} }
MCSectionMachO::MCSectionMachO(const StringRef &name, bool isDirective,
SectionKind K, MCContext &Ctx)
: MCSection(K), Name(name), IsDirective(isDirective) {
Ctx.SetSection(Name, this);
}
void MCSectionMachO::PrintSwitchToSection(const TargetAsmInfo &TAI, void MCSectionMachO::PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const { raw_ostream &OS) const {
if (!isDirective()) if (!isDirective())
@ -135,6 +141,13 @@ Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx); return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
} }
MCSectionCOFF::MCSectionCOFF(const StringRef &name, bool isDirective,
SectionKind K, MCContext &Ctx)
: MCSection(K), Name(name), IsDirective(isDirective) {
Ctx.SetSection(Name, this);
}
void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI, void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const { raw_ostream &OS) const {

View File

@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "PIC16AsmPrinter.h" #include "PIC16AsmPrinter.h"
#include "PIC16Section.h"
#include "PIC16TargetAsmInfo.h" #include "PIC16TargetAsmInfo.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/Function.h" #include "llvm/Function.h"
@ -21,7 +22,6 @@
#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/MC/MCSection.h"
#include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
@ -227,9 +227,11 @@ bool PIC16AsmPrinter::doInitialization(Module &M) {
// Set the section names for all globals. // Set the section names for all globals.
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) I != E; ++I)
if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) {
I->setSection(getObjFileLowering(). const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM);
SectionForGlobal(I, Mang,TM)->getName());
I->setSection(((const MCSectionPIC16*)S)->getName());
}
DbgInfo.BeginModule(M); DbgInfo.BeginModule(M);
EmitFunctionDecls(M); EmitFunctionDecls(M);

View File

@ -15,27 +15,23 @@
#define LLVM_PIC16SECTION_H #define LLVM_PIC16SECTION_H
#include "llvm/MC/MCSection.h" #include "llvm/MC/MCSection.h"
#include "llvm/MC/MCContext.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm { namespace llvm {
class MCSectionPIC16 : public MCSection { class MCSectionPIC16 : public MCSection {
MCSectionPIC16(const StringRef &Name, bool IsDirective, SectionKind K, std::string Name;
MCContext &Ctx) : MCSection(Name, IsDirective, K, Ctx) {}
MCSectionPIC16(const StringRef &name, SectionKind K,
MCContext &Ctx);
public: public:
static MCSectionPIC16 *Create(const StringRef &Name, bool IsDirective, const std::string &getName() const { return Name; }
SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionPIC16(Name, IsDirective, K, Ctx);
}
static MCSectionPIC16 *Create(const StringRef &Name,
SectionKind K, MCContext &Ctx);
virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const { raw_ostream &OS) const;
OS << getName() << '\n';
}
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -15,17 +15,37 @@
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/MC/MCSection.h" #include "llvm/MC/MCSection.h"
#include "llvm/MC/MCContext.h" #include "llvm/MC/MCContext.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm; 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() PIC16TargetObjectFile::PIC16TargetObjectFile()
: ExternalVarDecls(0), ExternalVarDefs(0) { : ExternalVarDecls(0), ExternalVarDefs(0) {
} }
const MCSection *PIC16TargetObjectFile:: const MCSectionPIC16 *PIC16TargetObjectFile::
getPIC16Section(const char *Name, bool isDirective, SectionKind Kind) const { getPIC16Section(const char *Name, SectionKind Kind) const {
if (MCSection *S = getContext().GetSection(Name)) if (MCSection *S = getContext().GetSection(Name))
return S; return (MCSectionPIC16*)S;
return MCSectionPIC16::Create(Name, isDirective, Kind, getContext()); return MCSectionPIC16::Create(Name, Kind, getContext());
} }
@ -33,39 +53,35 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
TargetLoweringObjectFile::Initialize(Ctx, tm); TargetLoweringObjectFile::Initialize(Ctx, tm);
TM = &tm; TM = &tm;
BSSSection = getPIC16Section("udata.# UDATA", false, BSSSection = getPIC16Section("udata.# UDATA", SectionKind::getBSS());
SectionKind::getBSS()); ReadOnlySection = getPIC16Section("romdata.# ROMDATA",
ReadOnlySection = getPIC16Section("romdata.# ROMDATA", false,
SectionKind::getReadOnly()); SectionKind::getReadOnly());
DataSection = getPIC16Section("idata.# IDATA", false, DataSection = getPIC16Section("idata.# IDATA", SectionKind::getDataRel());
SectionKind::getDataRel());
// Need because otherwise a .text symbol is emitted by DwarfWriter // Need because otherwise a .text symbol is emitted by DwarfWriter
// in BeginModule, and gpasm cribbs for that .text symbol. // in BeginModule, and gpasm cribbs for that .text symbol.
TextSection = getPIC16Section("", 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. // FIXME: I don't know what the classification of these sections really is.
ExternalVarDecls = new PIC16Section(getPIC16Section("ExternalVarDecls", ExternalVarDecls = new PIC16Section(getPIC16Section("ExternalVarDecls",
false,
SectionKind::getMetadata())); SectionKind::getMetadata()));
ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs", ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs",
false,
SectionKind::getMetadata())); SectionKind::getMetadata()));
} }
const MCSection *PIC16TargetObjectFile:: const MCSection *PIC16TargetObjectFile::
getSectionForFunction(const std::string &FnName) const { getSectionForFunction(const std::string &FnName) const {
std::string T = PAN::getCodeSectionName(FnName); std::string T = PAN::getCodeSectionName(FnName);
return getPIC16Section(T.c_str(), false, SectionKind::getText()); return getPIC16Section(T.c_str(), SectionKind::getText());
} }
const MCSection *PIC16TargetObjectFile:: const MCSection *PIC16TargetObjectFile::
getSectionForFunctionFrame(const std::string &FnName) const { getSectionForFunctionFrame(const std::string &FnName) const {
std::string T = PAN::getFrameSectionName(FnName); std::string T = PAN::getFrameSectionName(FnName);
return getPIC16Section(T.c_str(), false, SectionKind::getDataRel()); return getPIC16Section(T.c_str(), SectionKind::getDataRel());
} }
const MCSection * const MCSection *
@ -92,9 +108,8 @@ PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
// No BSS section spacious enough was found. Crate a new one. // No BSS section spacious enough was found. Crate a new one.
if (!FoundBSS) { if (!FoundBSS) {
std::string name = PAN::getUdataSectionName(BSSSections.size()); std::string name = PAN::getUdataSectionName(BSSSections.size());
const MCSection *NewSection = getPIC16Section(name.c_str(), false, const MCSectionPIC16 *NewSection
// FIXME. = getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
SectionKind::getMetadata());
FoundBSS = new PIC16Section(NewSection); FoundBSS = new PIC16Section(NewSection);
@ -134,9 +149,8 @@ PIC16TargetObjectFile::getIDATASectionForGlobal(const GlobalVariable *GV) const{
// No IDATA section spacious enough was found. Crate a new one. // No IDATA section spacious enough was found. Crate a new one.
if (!FoundIDATA) { if (!FoundIDATA) {
std::string name = PAN::getIdataSectionName(IDATASections.size()); std::string name = PAN::getIdataSectionName(IDATASections.size());
const MCSection *NewSection = getPIC16Section(name.c_str(), false, const MCSectionPIC16 *NewSection =
// FIXME. getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
SectionKind::getMetadata());
FoundIDATA = new PIC16Section(NewSection); FoundIDATA = new PIC16Section(NewSection);
@ -169,10 +183,8 @@ PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
// No Auto section was found. Crate a new one. // No Auto section was found. Crate a new one.
if (!FoundAutoSec) { if (!FoundAutoSec) {
const MCSection *NewSection = getPIC16Section(name.c_str(), const MCSectionPIC16 *NewSection =
// FIXME. getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
false,
SectionKind::getMetadata());
FoundAutoSec = new PIC16Section(NewSection); FoundAutoSec = new PIC16Section(NewSection);
@ -270,7 +282,7 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
return CreateSectionForGlobal(GVar, Mang); return CreateSectionForGlobal(GVar, Mang);
} }
return getPIC16Section(GV->getSection().c_str(), false, Kind); return getPIC16Section(GV->getSection().c_str(), Kind);
} }
// Create a new section for global variable. If Addr is given then create // Create a new section for global variable. If Addr is given then create
@ -322,8 +334,8 @@ PIC16TargetObjectFile::CreateBSSSectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewBSS = FoundBSS; PIC16Section *NewBSS = FoundBSS;
if (NewBSS == NULL) { if (NewBSS == NULL) {
const MCSection *NewSection = getPIC16Section(Name.c_str(), false, const MCSectionPIC16 *NewSection =
SectionKind::getBSS()); getPIC16Section(Name.c_str(), SectionKind::getBSS());
NewBSS = new PIC16Section(NewSection); NewBSS = new PIC16Section(NewSection);
BSSSections.push_back(NewBSS); BSSSections.push_back(NewBSS);
} }
@ -374,9 +386,8 @@ PIC16TargetObjectFile::CreateIDATASectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewIDATASec = FoundIDATASec; PIC16Section *NewIDATASec = FoundIDATASec;
if (NewIDATASec == NULL) { if (NewIDATASec == NULL) {
const MCSection *NewSection = getPIC16Section(Name.c_str(), false, const MCSectionPIC16 *NewSection =
// FIXME: getPIC16Section(Name.c_str(), /* FIXME */SectionKind::getMetadata());
SectionKind::getMetadata());
NewIDATASec = new PIC16Section(NewSection); NewIDATASec = new PIC16Section(NewSection);
IDATASections.push_back(NewIDATASec); IDATASections.push_back(NewIDATASec);
} }
@ -414,8 +425,8 @@ PIC16TargetObjectFile::CreateROSectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewRomSec = FoundROSec; PIC16Section *NewRomSec = FoundROSec;
if (NewRomSec == NULL) { if (NewRomSec == NULL) {
const MCSection *NewSection = getPIC16Section(Name.c_str(), false, const MCSectionPIC16 *NewSection =
SectionKind::getReadOnly()); getPIC16Section(Name.c_str(), SectionKind::getReadOnly());
NewRomSec = new PIC16Section(NewSection); NewRomSec = new PIC16Section(NewSection);
ROSections.push_back(NewRomSec); ROSections.push_back(NewRomSec);
} }

View File

@ -17,6 +17,7 @@ namespace llvm {
class GlobalVariable; class GlobalVariable;
class Module; class Module;
class PIC16TargetMachine; class PIC16TargetMachine;
class MCSectionPIC16;
enum { DataBankSize = 80 }; enum { DataBankSize = 80 };
@ -29,12 +30,12 @@ namespace llvm {
/// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16. /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16.
/// ///
struct PIC16Section { struct PIC16Section {
const MCSection *S_; // Connection to actual Section. const MCSectionPIC16 *S_; // Connection to actual Section.
unsigned Size; // Total size of the objects contained. unsigned Size; // Total size of the objects contained.
bool SectionPrinted; bool SectionPrinted;
std::vector<const GlobalVariable*> Items; std::vector<const GlobalVariable*> Items;
PIC16Section(const MCSection *s) { PIC16Section(const MCSectionPIC16 *s) {
S_ = s; S_ = s;
Size = 0; Size = 0;
SectionPrinted = false; SectionPrinted = false;
@ -46,7 +47,7 @@ namespace llvm {
class PIC16TargetObjectFile : public TargetLoweringObjectFile { class PIC16TargetObjectFile : public TargetLoweringObjectFile {
const TargetMachine *TM; const TargetMachine *TM;
const MCSection *getPIC16Section(const char *Name, bool isDirective, const MCSectionPIC16 *getPIC16Section(const char *Name,
SectionKind K) const; SectionKind K) const;
public: public:
mutable std::vector<PIC16Section*> BSSSections; mutable std::vector<PIC16Section*> BSSSections;

View File

@ -29,8 +29,8 @@ foo:
// CHECK: .long 11 // CHECK: .long 11
.long "a 0" .long "a 0"
// CHECK: .section "a 1,a 2" // XXCHCK: .section "a 1,a 2"
.section "a 1", "a 2" //.section "a 1", "a 2"
// CHECK: .globl "a 3" // CHECK: .globl "a 3"
.globl "a 3" .globl "a 3"

View File

@ -706,7 +706,7 @@ bool AsmParser::ParseDirectiveDarwinSection() {
// FIXME: Arch specific. // FIXME: Arch specific.
MCSection *S = Ctx.GetSection(Section); MCSection *S = Ctx.GetSection(Section);
if (S == 0) if (S == 0)
S = MCSectionCOFF::Create(Section, false, SectionKind(), Ctx); S = MCSectionMachO::Create(Section, false, SectionKind(), Ctx);
Out.SwitchSection(S); Out.SwitchSection(S);
return false; return false;
@ -727,7 +727,7 @@ bool AsmParser::ParseDirectiveSectionSwitch(const char *Section,
// FIXME: Arch specific. // FIXME: Arch specific.
MCSection *S = Ctx.GetSection(Section); MCSection *S = Ctx.GetSection(Section);
if (S == 0) if (S == 0)
S = MCSectionCOFF::Create(Section, false, SectionKind(), Ctx); S = MCSectionMachO::Create(Section, false, SectionKind(), Ctx);
Out.SwitchSection(S); Out.SwitchSection(S);
return false; return false;
@ -1118,7 +1118,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
// FIXME: Arch specific. // FIXME: Arch specific.
MCSection *S = Ctx.GetSection(Section); MCSection *S = Ctx.GetSection(Section);
if (S == 0) if (S == 0)
S = MCSectionCOFF::Create(Section, false, SectionKind(), Ctx); S = MCSectionMachO::Create(Section, false, SectionKind(), Ctx);
// Create the zerofill section but no symbol // Create the zerofill section but no symbol
Out.EmitZerofill(S); Out.EmitZerofill(S);
@ -1178,7 +1178,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
// FIXME: Arch specific. // FIXME: Arch specific.
MCSection *S = Ctx.GetSection(Section); MCSection *S = Ctx.GetSection(Section);
if (S == 0) if (S == 0)
S = MCSectionCOFF::Create(Section, false, SectionKind(), Ctx); S = MCSectionMachO::Create(Section, false, SectionKind(), Ctx);
// Create the zerofill Symbol with Size and Pow2Alignment // Create the zerofill Symbol with Size and Pow2Alignment
Out.EmitZerofill(S, Sym, Size, Pow2Alignment); Out.EmitZerofill(S, Sym, Size, Pow2Alignment);

View File

@ -186,7 +186,7 @@ static int AssembleInput(const char *ProgName) {
OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs())); OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs()));
// FIXME: Target hook & command line option for initial section. // FIXME: Target hook & command line option for initial section.
Str.get()->SwitchSection(MCSectionCOFF::Create("__TEXT,__text," Str.get()->SwitchSection(MCSectionMachO::Create("__TEXT,__text,"
"regular,pure_instructions", "regular,pure_instructions",
false, false,
SectionKind::getText(), SectionKind::getText(),