[llvm-commits] [llvm] r161477 - in /llvm/trunk: lib/MC/MCParser/DarwinAsmParser.cpp test/MC/MachO/previous.s test/MC/MachO/pushsection.s

Bill Wendling isanbard at gmail.com
Wed Aug 8 16:01:53 PDT 2012


Done. Thanks!

	http://llvm.org/bugs/show_bug.cgi?id=13557

-bw

On Aug 8, 2012, at 3:39 PM, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:

> This code is duplicated with the ELF asm parser. Do you intend to
> refactor it? If not, would you mind opening a bug and assigning it to
> me?
> 
> On 8 August 2012 02:30, Bill Wendling <isanbard at gmail.com> wrote:
>> Author: void
>> Date: Wed Aug  8 01:30:30 2012
>> New Revision: 161477
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=161477&view=rev
>> Log:
>> Add `.pushsection', `.popsection', and `.previous' directives to Darwin ASM.
>> 
>> There are situations where inline ASM may want to change the section -- for
>> instance, to create a variable in the .data section. However, it cannot do this
>> without (potentially) restoring to the wrong section. E.g.:
>> 
>>  asm volatile (".section __DATA, __data\n\t"
>>                ".globl _fnord\n\t"
>>                "_fnord: .quad 1f\n\t"
>>                ".text\n\t"
>>                "1:" :::);
>> 
>> This may be wrong if this is inlined into a function that has a "section"
>> attribute. The user should use `.pushsection' and `.popsection' here instead.
>> 
>> The addition of `.previous' is added for completeness.
>> <rdar://problem/12048387>
>> 
>> Added:
>>    llvm/trunk/test/MC/MachO/previous.s
>>    llvm/trunk/test/MC/MachO/pushsection.s
>> Modified:
>>    llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp
>> 
>> Modified: llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp?rev=161477&r1=161476&r2=161477&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp (original)
>> +++ llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp Wed Aug  8 01:30:30 2012
>> @@ -50,6 +50,9 @@
>>     AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".dump");
>>     AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".load");
>>     AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSection>(".section");
>> +    AddDirectiveHandler<&DarwinAsmParser::ParseDirectivePushSection>(".pushsection");
>> +    AddDirectiveHandler<&DarwinAsmParser::ParseDirectivePopSection>(".popsection");
>> +    AddDirectiveHandler<&DarwinAsmParser::ParseDirectivePrevious>(".previous");
>>     AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogUnique>(
>>       ".secure_log_unique");
>>     AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogReset>(
>> @@ -112,6 +115,9 @@
>>   bool ParseDirectiveDumpOrLoad(StringRef, SMLoc);
>>   bool ParseDirectiveLsym(StringRef, SMLoc);
>>   bool ParseDirectiveSection(StringRef, SMLoc);
>> +  bool ParseDirectivePushSection(StringRef, SMLoc);
>> +  bool ParseDirectivePopSection(StringRef, SMLoc);
>> +  bool ParseDirectivePrevious(StringRef, SMLoc);
>>   bool ParseDirectiveSecureLogReset(StringRef, SMLoc);
>>   bool ParseDirectiveSecureLogUnique(StringRef, SMLoc);
>>   bool ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
>> @@ -297,7 +303,7 @@
>> 
>> };
>> 
>> -}
>> +} // end anonymous namespace
>> 
>> bool DarwinAsmParser::ParseSectionSwitch(const char *Segment,
>>                                          const char *Section,
>> @@ -457,6 +463,37 @@
>>   return false;
>> }
>> 
>> +/// ParseDirectivePushSection:
>> +///   ::= .pushsection identifier (',' identifier)*
>> +bool DarwinAsmParser::ParseDirectivePushSection(StringRef S, SMLoc Loc) {
>> +  getStreamer().PushSection();
>> +
>> +  if (ParseDirectiveSection(S, Loc)) {
>> +    getStreamer().PopSection();
>> +    return true;
>> +  }
>> +
>> +  return false;
>> +}
>> +
>> +/// ParseDirectivePopSection:
>> +///   ::= .popsection
>> +bool DarwinAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
>> +  if (!getStreamer().PopSection())
>> +    return TokError(".popsection without corresponding .pushsection");
>> +  return false;
>> +}
>> +
>> +/// ParseDirectivePrevious:
>> +///   ::= .previous
>> +bool DarwinAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
>> +  const MCSection *PreviousSection = getStreamer().getPreviousSection();
>> +  if (PreviousSection == NULL)
>> +      return TokError(".previous without corresponding .section");
>> +  getStreamer().SwitchSection(PreviousSection);
>> +  return false;
>> +}
>> +
>> /// ParseDirectiveSecureLogUnique
>> ///  ::= .secure_log_unique ... message ...
>> bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
>> @@ -707,4 +744,4 @@
>>   return new DarwinAsmParser;
>> }
>> 
>> -}
>> +} // end llvm namespace
>> 
>> Added: llvm/trunk/test/MC/MachO/previous.s
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/previous.s?rev=161477&view=auto
>> ==============================================================================
>> --- llvm/trunk/test/MC/MachO/previous.s (added)
>> +++ llvm/trunk/test/MC/MachO/previous.s Wed Aug  8 01:30:30 2012
>> @@ -0,0 +1,13 @@
>> +// RUN: llvm-mc -triple i386-apple-darwin9 %s -o - | FileCheck %s
>> +
>> +.text
>> +// CHECK: .section __TEXT,__text
>> +
>> +.data
>> +// CHECK: .section __DATA,__data
>> +
>> +.previous
>> +// CHECK: .section __TEXT,__text
>> +
>> +.previous
>> +// CHECK: .section __DATA,__data
>> 
>> Added: llvm/trunk/test/MC/MachO/pushsection.s
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/pushsection.s?rev=161477&view=auto
>> ==============================================================================
>> --- llvm/trunk/test/MC/MachO/pushsection.s (added)
>> +++ llvm/trunk/test/MC/MachO/pushsection.s Wed Aug  8 01:30:30 2012
>> @@ -0,0 +1,16 @@
>> +// RUN: llvm-mc -triple i386-apple-darwin9 %s -o - | FileCheck %s
>> +
>> +.text
>> +// CHECK: .section __TEXT,__text
>> +
>> +.pushsection __DATA, __data
>> +// CHECK: .section __DATA,__data
>> +
>> +.pushsection __TEXT, initcode
>> +// CHECK: .section __TEXT,initcode
>> +
>> +.popsection
>> +// CHECK: .section __DATA,__data
>> +
>> +.popsection
>> +// CHECK: .section __TEXT,__text
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list