[llvm-commits] [PATCH]: fix platform dependency in AsmParser

Eli Bendersky eliben at google.com
Mon Jan 14 09:43:46 PST 2013


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.

Please take a look.

P.S.: some streamers like the Asm streamer and Pure streamer still do
the MachO-specific thing. This should also be fixed, but probably in a
separate patch.

Eli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asmparser_init_section_fix.1.patch
Type: application/octet-stream
Size: 6763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130114/b43dcc0e/attachment.obj>


More information about the llvm-commits mailing list