]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Update format of 'names' section.
authorDerek Schuff <dschuff@google.com>
Wed, 15 Mar 2017 19:36:02 +0000 (19:36 +0000)
committerDerek Schuff <dschuff@google.com>
Wed, 15 Mar 2017 19:36:02 +0000 (19:36 +0000)
This change updates to the format of the 'names' sectionin the
generated wasm binary to match the latest changesto the design
and 'wabt'.

Differential Revision: https://reviews.llvm.org/D30950

Patch by Sam Clegg

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297877 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Wasm.h
lib/MC/WasmObjectWriter.cpp

index cd15e21d02348602dd6d51a1906fa47bc69fcf8d..553ed721870bdba563fa4cf25250376fe5cebc22 100644 (file)
@@ -81,6 +81,11 @@ enum : unsigned {
   WASM_OPCODE_F64_CONST  = 0x44,
 };
 
+enum : unsigned {
+  WASM_NAMES_FUNCTION    = 0x1,
+  WASM_NAMES_LOCAL       = 0x2,
+};
+
 // Subset of types that a value can have
 enum class ValType {
   I32 = WASM_TYPE_I32,
index 20ace61825b37d58df6c82fa9c4ebe7a4ef11dd5..39ddc30eb7d84ab7f106e384bb38a13826b6582a 100644 (file)
@@ -982,25 +982,30 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
   }
 
   // === Name Section ==========================================================
-  if (NumFuncImports != 0 || !Functions.empty()) {
+  uint32_t TotalFunctions = NumFuncImports + Functions.size();
+  if (TotalFunctions != 0) {
     startSection(Section, wasm::WASM_SEC_CUSTOM, "name");
+    SectionBookkeeping SubSection;
+    startSection(SubSection, wasm::WASM_NAMES_FUNCTION);
 
-    encodeULEB128(NumFuncImports + Functions.size(), getStream());
+    encodeULEB128(TotalFunctions, getStream());
+    uint32_t Index = 0;
     for (const WasmImport &Import : Imports) {
       if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION) {
+        encodeULEB128(Index, getStream());
         encodeULEB128(Import.FieldName.size(), getStream());
         writeBytes(Import.FieldName);
-        encodeULEB128(0, getStream()); // local count, meaningless for imports
+        ++Index;
       }
     }
     for (const WasmFunction &Func : Functions) {
+      encodeULEB128(Index, getStream());
       encodeULEB128(Func.Sym->getName().size(), getStream());
       writeBytes(Func.Sym->getName());
-
-      // TODO: Local names.
-      encodeULEB128(0, getStream()); // local count
+      ++Index;
     }
 
+    endSection(SubSection);
     endSection(Section);
   }