Skip to content

Commit

Permalink
Expose an InitToTextSection through MCStreamer.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eliben committed Jan 14, 2013
1 parent 9bac6b2 commit 030f63a
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/llvm/MC/MCELFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MCELFStreamer : public MCObjectStreamer {
/// @{

virtual void InitSections();
virtual void InitToTextSection();
virtual void ChangeSection(const MCSection *Section);
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitDebugLabel(MCSymbol *Symbol);
Expand Down
3 changes: 3 additions & 0 deletions include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ namespace llvm {
/// InitSections - Create the default sections and set the initial one.
virtual void InitSections() = 0;

/// InitToTextSection - Create a text section and switch the streamer to it.
virtual void InitToTextSection() = 0;

/// EmitLabel - Emit a label for @p Symbol into the current section.
///
/// This corresponds to an assembler statement such as:
Expand Down
11 changes: 8 additions & 3 deletions lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ class MCAsmStreamer : public MCStreamer {
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);
Expand Down
4 changes: 4 additions & 0 deletions lib/MC/MCELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions lib/MC/MCMachOStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MCMachOStreamer : public MCObjectStreamer {
/// @{

virtual void InitSections();
virtual void InitToTextSection();
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitDebugLabel(MCSymbol *Symbol);
virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
Expand Down Expand Up @@ -90,10 +91,14 @@ class MCMachOStreamer : public MCObjectStreamer {
} // 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,
Expand Down
3 changes: 3 additions & 0 deletions lib/MC/MCNullStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace {
/// @name MCStreamer Interface
/// @{

virtual void InitToTextSection() {
}

virtual void InitSections() {
}

Expand Down
5 changes: 1 addition & 4 deletions lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
6 changes: 5 additions & 1 deletion lib/MC/MCPureStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MCPureStreamer : public MCObjectStreamer {
/// @{

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,
Expand Down Expand Up @@ -104,11 +105,14 @@ class MCPureStreamer : public MCObjectStreamer {
} // 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) {
Expand Down
5 changes: 5 additions & 0 deletions lib/MC/WinCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WinCOFFStreamer : public MCObjectStreamer {
// MCStreamer interface

virtual void InitSections();
virtual void InitToTextSection();
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitDebugLabel(MCSymbol *Symbol);
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Expand Down Expand Up @@ -173,6 +174,10 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,

// MCStreamer interface

void WinCOFFStreamer::InitToTextSection() {
SetSectionText();
}

void WinCOFFStreamer::InitSections() {
SetSectionText();
SetSectionData();
Expand Down
1 change: 1 addition & 0 deletions tools/lto/LTOModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ namespace {

// Noop calls.
virtual void ChangeSection(const MCSection *Section) {}
virtual void InitToTextSection() {}
virtual void InitSections() {}
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {}
virtual void EmitThumbFunc(MCSymbol *Func) {}
Expand Down

0 comments on commit 030f63a

Please sign in to comment.