Compute the ELF SectionKind from the flags.

Any code creating an MCSectionELF knows ELF and already provides the flags.

SectionKind is an abstraction used by common code that uses a plain
MCSection.

Use the flags to compute the SectionKind. This removes a lot of
guessing and boilerplate from the MCSectionELF construction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227476 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-01-29 17:33:21 +00:00
parent dec5091220
commit 9936b80df5
21 changed files with 192 additions and 387 deletions

View File

@ -199,8 +199,7 @@ bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
return true;
}
getStreamer().SwitchSection(getContext().getELFSection(
Section, Type, Flags, Kind),
getStreamer().SwitchSection(getContext().getELFSection(Section, Type, Flags),
Subsection);
return false;
@ -269,40 +268,6 @@ bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
return false;
}
static SectionKind computeSectionKind(unsigned Flags, unsigned ElemSize) {
if (Flags & ELF::SHF_EXECINSTR)
return SectionKind::getText();
if (Flags & ELF::SHF_TLS)
return SectionKind::getThreadData();
if (Flags & ELF::SHF_MERGE) {
if (Flags & ELF::SHF_STRINGS) {
switch (ElemSize) {
default:
break;
case 1:
return SectionKind::getMergeable1ByteCString();
case 2:
return SectionKind::getMergeable2ByteCString();
case 4:
return SectionKind::getMergeable4ByteCString();
}
} else {
switch (ElemSize) {
default:
break;
case 4:
return SectionKind::getMergeableConst4();
case 8:
return SectionKind::getMergeableConst8();
case 16:
return SectionKind::getMergeableConst16();
}
}
}
return SectionKind::getDataRel();
}
static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
unsigned flags = 0;
@ -544,9 +509,8 @@ EndStmt:
}
}
SectionKind Kind = computeSectionKind(Flags, Size);
const MCSection *ELFSection = getContext().getELFSection(
SectionName, Type, Flags, Kind, Size, GroupName);
const MCSection *ELFSection =
getContext().getELFSection(SectionName, Type, Flags, Size, GroupName);
getStreamer().SwitchSection(ELFSection, Subsection);
if (getContext().getGenDwarfForAssembly()) {
@ -697,9 +661,7 @@ bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
Lex();
const MCSection *Note =
getContext().getELFSection(".note", ELF::SHT_NOTE, 0,
SectionKind::getReadOnly());
const MCSection *Note = getContext().getELFSection(".note", ELF::SHT_NOTE, 0);
getStreamer().PushSection();
getStreamer().SwitchSection(Note);