diff options
author | Eli Bendersky <eliben@google.com> | 2013-01-14 19:04:57 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2013-01-14 19:04:57 +0000 |
commit | 030f63a397edc20f8f661bac62f7b90cb5cf57bc (patch) | |
tree | c102045afd6db912521b48e1c84a111551d990ef /lib/MC | |
parent | 9bac6b29b832419f8b76bb2c27af74bb57a8d99a (diff) | |
download | llvm-030f63a397edc20f8f661bac62f7b90cb5cf57bc.tar.gz llvm-030f63a397edc20f8f661bac62f7b90cb5cf57bc.tar.bz2 llvm-030f63a397edc20f8f661bac62f7b90cb5cf57bc.tar.xz |
Expose an InitToTextSection through MCStreamer.
The aim of this patch is to fix the following piece of code in the
platform-independent AsmParser:
void AsmParser::CheckForValidSection() {
if (!ParsingInlineAsm && !getStreamer().getCurrentSection()) {
TokError("expected section directive before assembly directive");
Out.SwitchSection(Ctx.getMachOSection(
"__TEXT", "__text",
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
0, SectionKind::getText()));
}
}
This was added for the "-n" option of llvm-mc.
The proposed fix adds another virtual method to MCStreamer, called
InitToTextSection. Conceptually, it's similar to the existing
InitSections which initializes all common sections and switches to
text. The new method is implemented by each platform streamer in a way
that it sees fit. So AsmParser can now do this:
void AsmParser::CheckForValidSection() {
if (!ParsingInlineAsm && !getStreamer().getCurrentSection()) {
TokError("expected section directive before assembly directive");
Out.InitToTextSection();
}
}
Which is much more reasonable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172450 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 11 | ||||
-rw-r--r-- | lib/MC/MCELFStreamer.cpp | 4 | ||||
-rw-r--r-- | lib/MC/MCMachOStreamer.cpp | 11 | ||||
-rw-r--r-- | lib/MC/MCNullStreamer.cpp | 3 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 5 | ||||
-rw-r--r-- | lib/MC/MCPureStreamer.cpp | 6 | ||||
-rw-r--r-- | lib/MC/WinCOFFStreamer.cpp | 5 |
7 files changed, 34 insertions, 11 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index e234dfed16..dd5112c771 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -127,11 +127,16 @@ public: virtual void ChangeSection(const MCSection *Section); virtual void InitSections() { + InitToTextSection(); + } + + virtual void InitToTextSection() { // FIXME, this is MachO specific, but the testsuite // expects this. - SwitchSection(getContext().getMachOSection("__TEXT", "__text", - MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, - 0, SectionKind::getText())); + SwitchSection(getContext().getMachOSection( + "__TEXT", "__text", + MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, + 0, SectionKind::getText())); } virtual void EmitLabel(MCSymbol *Symbol); diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index d05fcca49e..cae73be298 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -65,6 +65,10 @@ inline void MCELFStreamer::SetSectionBss() { MCELFStreamer::~MCELFStreamer() { } +void MCELFStreamer::InitToTextSection() { + SetSectionText(); +} + void MCELFStreamer::InitSections() { // This emulates the same behavior of GNU as. This makes it easier // to compare the output as the major sections are in the same order. diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 82ccdd4ac0..f947dda83d 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -42,6 +42,7 @@ public: /// @{ virtual void InitSections(); + virtual void InitToTextSection(); virtual void EmitLabel(MCSymbol *Symbol); virtual void EmitDebugLabel(MCSymbol *Symbol); virtual void EmitEHSymAttributes(const MCSymbol *Symbol, @@ -90,10 +91,14 @@ public: } // end anonymous namespace. void MCMachOStreamer::InitSections() { - SwitchSection(getContext().getMachOSection("__TEXT", "__text", - MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, - 0, SectionKind::getText())); + InitToTextSection(); +} +void MCMachOStreamer::InitToTextSection() { + SwitchSection(getContext().getMachOSection( + "__TEXT", "__text", + MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 0, + SectionKind::getText())); } void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, diff --git a/lib/MC/MCNullStreamer.cpp b/lib/MC/MCNullStreamer.cpp index 364c324b3f..3eee5caf6f 100644 --- a/lib/MC/MCNullStreamer.cpp +++ b/lib/MC/MCNullStreamer.cpp @@ -24,6 +24,9 @@ namespace { /// @name MCStreamer Interface /// @{ + virtual void InitToTextSection() { + } + virtual void InitSections() { } diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 752cc19132..262cb2ca61 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -708,10 +708,7 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { void AsmParser::CheckForValidSection() { if (!ParsingInlineAsm && !getStreamer().getCurrentSection()) { TokError("expected section directive before assembly directive"); - Out.SwitchSection(Ctx.getMachOSection( - "__TEXT", "__text", - MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, - 0, SectionKind::getText())); + Out.InitToTextSection(); } } diff --git a/lib/MC/MCPureStreamer.cpp b/lib/MC/MCPureStreamer.cpp index 97e5a69973..6ce7ae81d5 100644 --- a/lib/MC/MCPureStreamer.cpp +++ b/lib/MC/MCPureStreamer.cpp @@ -36,6 +36,7 @@ public: /// @{ virtual void InitSections(); + virtual void InitToTextSection(); virtual void EmitLabel(MCSymbol *Symbol); virtual void EmitDebugLabel(MCSymbol *Symbol); virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, @@ -104,11 +105,14 @@ public: } // end anonymous namespace. void MCPureStreamer::InitSections() { + InitToTextSection(); +} + +void MCPureStreamer::InitToTextSection() { // FIMXE: To what!? SwitchSection(getContext().getMachOSection("__TEXT", "__text", MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 0, SectionKind::getText())); - } void MCPureStreamer::EmitLabel(MCSymbol *Symbol) { diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 5489ef8d89..cc2c272f38 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -50,6 +50,7 @@ public: // MCStreamer interface virtual void InitSections(); + virtual void InitToTextSection(); virtual void EmitLabel(MCSymbol *Symbol); virtual void EmitDebugLabel(MCSymbol *Symbol); virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); @@ -173,6 +174,10 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size, // MCStreamer interface +void WinCOFFStreamer::InitToTextSection() { + SetSectionText(); +} + void WinCOFFStreamer::InitSections() { SetSectionText(); SetSectionData(); |