[PATCH] D63901: [WebAssembly] Added visibility and ident directives to WasmAsmParser.

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 14:49:51 PDT 2019


aardappel created this revision.
aardappel added a reviewer: dschuff.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, sbc100.
Herald added a project: LLVM.

These are output by clang -S, so can now be roundtripped thru clang.

(partially) fixes: https://bugs.llvm.org/show_bug.cgi?id=34544


Repository:
  rL LLVM

https://reviews.llvm.org/D63901

Files:
  lib/MC/MCParser/WasmAsmParser.cpp
  test/MC/WebAssembly/basic-assembly.s


Index: test/MC/WebAssembly/basic-assembly.s
===================================================================
--- test/MC/WebAssembly/basic-assembly.s
+++ test/MC/WebAssembly/basic-assembly.s
@@ -88,11 +88,13 @@
     end_function
 
     .section	.rodata..L.str,"",@
+    .hidden     .L.str
 .L.str:
     .int8	'H'
     .asciz	"ello, World!"
     .size	.L.str, 14
 
+    .ident	"clang version 9.0.0 (trunk 364502) (llvm/trunk 364571)"
     .globaltype	__stack_pointer, i32
 
 # CHECK:           .text
@@ -174,6 +176,7 @@
 # CHECK-NEXT:      end_function
 
 # CHECK:	    .section	.rodata..L.str,"",@
+# CHECK-NEXT:   .hidden     .L.str
 # CHECK-NEXT:.L.str:
 # CHECK-NEXT:	.int8	72
 # CHECK-NEXT:	.asciz	"ello, World!"
Index: lib/MC/MCParser/WasmAsmParser.cpp
===================================================================
--- lib/MC/MCParser/WasmAsmParser.cpp
+++ lib/MC/MCParser/WasmAsmParser.cpp
@@ -56,6 +56,17 @@
     addDirectiveHandler<&WasmAsmParser::parseSectionDirective>(".section");
     addDirectiveHandler<&WasmAsmParser::parseDirectiveSize>(".size");
     addDirectiveHandler<&WasmAsmParser::parseDirectiveType>(".type");
+    addDirectiveHandler<&WasmAsmParser::ParseDirectiveIdent>(".ident");
+    addDirectiveHandler<
+      &WasmAsmParser::ParseDirectiveSymbolAttribute>(".weak");
+    addDirectiveHandler<
+      &WasmAsmParser::ParseDirectiveSymbolAttribute>(".local");
+    addDirectiveHandler<
+      &WasmAsmParser::ParseDirectiveSymbolAttribute>(".protected");
+    addDirectiveHandler<
+      &WasmAsmParser::ParseDirectiveSymbolAttribute>(".internal");
+    addDirectiveHandler<
+      &WasmAsmParser::ParseDirectiveSymbolAttribute>(".hidden");
   }
 
   bool error(const StringRef &Msg, const AsmToken &Tok) {
@@ -198,6 +209,51 @@
     Lex();
     return expect(AsmToken::EndOfStatement, "EOL");
   }
+
+  // FIXME: Shared with ELF.
+  /// ParseDirectiveIdent
+  ///  ::= .ident string
+  bool ParseDirectiveIdent(StringRef, SMLoc) {
+    if (getLexer().isNot(AsmToken::String))
+      return TokError("unexpected token in '.ident' directive");
+    StringRef Data = getTok().getIdentifier();
+    Lex();
+    if (getLexer().isNot(AsmToken::EndOfStatement))
+      return TokError("unexpected token in '.ident' directive");
+    Lex();
+    getStreamer().EmitIdent(Data);
+    return false;
+  }
+
+  // FIXME: Shared with ELF.
+  /// ParseDirectiveSymbolAttribute
+  ///  ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ]
+  bool ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
+    MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
+      .Case(".weak", MCSA_Weak)
+      .Case(".local", MCSA_Local)
+      .Case(".hidden", MCSA_Hidden)
+      .Case(".internal", MCSA_Internal)
+      .Case(".protected", MCSA_Protected)
+      .Default(MCSA_Invalid);
+    assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
+    if (getLexer().isNot(AsmToken::EndOfStatement)) {
+      while (true) {
+        StringRef Name;
+        if (getParser().parseIdentifier(Name))
+          return TokError("expected identifier in directive");
+        MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
+        getStreamer().EmitSymbolAttribute(Sym, Attr);
+        if (getLexer().is(AsmToken::EndOfStatement))
+          break;
+        if (getLexer().isNot(AsmToken::Comma))
+          return TokError("unexpected token in directive");
+        Lex();
+      }
+    }
+    Lex();
+    return false;
+  }
 };
 
 } // end anonymous namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63901.206943.patch
Type: text/x-patch
Size: 3517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190627/57fd9af7/attachment.bin>


More information about the llvm-commits mailing list