[llvm] r295860 - [WebAssembly] Implement the wasm binary container header.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 10:50:21 PST 2017


Author: djg
Date: Wed Feb 22 12:50:20 2017
New Revision: 295860

URL: http://llvm.org/viewvc/llvm-project?rev=295860&view=rev
Log:
[WebAssembly] Implement the wasm binary container header.

Also, update the version number to 0x1, which is what engines are now
expecting.

Added:
    llvm/trunk/test/MC/WebAssembly/
    llvm/trunk/test/MC/WebAssembly/file-headers.ll
    llvm/trunk/test/MC/WebAssembly/lit.local.cfg
      - copied, changed from r295843, llvm/trunk/test/MC/AArch64/lit.local.cfg
Modified:
    llvm/trunk/include/llvm/Support/Wasm.h
    llvm/trunk/lib/MC/WasmObjectWriter.cpp

Modified: llvm/trunk/include/llvm/Support/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Wasm.h?rev=295860&r1=295859&r2=295860&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Wasm.h (original)
+++ llvm/trunk/include/llvm/Support/Wasm.h Wed Feb 22 12:50:20 2017
@@ -23,7 +23,7 @@ namespace wasm {
 // Object file magic string.
 const char WasmMagic[] = {'\0', 'a', 's', 'm'};
 // Wasm binary format version
-const uint32_t WasmVersion = 0xd;
+const uint32_t WasmVersion = 0x1;
 
 struct WasmObjectHeader {
   StringRef Magic;

Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=295860&r1=295859&r2=295860&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Wed Feb 22 12:50:20 2017
@@ -32,6 +32,7 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/Wasm.h"
 #include <vector>
 
 using namespace llvm;
@@ -90,7 +91,8 @@ WasmObjectWriter::~WasmObjectWriter() {}
 
 // Emit the Wasm header.
 void WasmObjectWriter::writeHeader(const MCAssembler &Asm) {
-  // TODO: write the magic cookie and the version.
+  writeBytes(StringRef(wasm::WasmMagic, sizeof(wasm::WasmMagic)));
+  writeLE32(wasm::WasmVersion);
 }
 
 void WasmObjectWriter::executePostLayoutBinding(MCAssembler &Asm,

Added: llvm/trunk/test/MC/WebAssembly/file-headers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/file-headers.ll?rev=295860&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/file-headers.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/file-headers.ll Wed Feb 22 12:50:20 2017
@@ -0,0 +1,9 @@
+; RUN: llc -filetype=obj %s -o - | llvm-readobj -file-headers | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+; CHECK: Format: WASM{{$}}
+; CHECK: Arch: wasm32{{$}}
+; CHECK: AddressSize: 32bit{{$}}
+; CHECK: Version: 0x1{{$}}

Copied: llvm/trunk/test/MC/WebAssembly/lit.local.cfg (from r295843, llvm/trunk/test/MC/AArch64/lit.local.cfg)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/lit.local.cfg?p2=llvm/trunk/test/MC/WebAssembly/lit.local.cfg&p1=llvm/trunk/test/MC/AArch64/lit.local.cfg&r1=295843&r2=295860&rev=295860&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/lit.local.cfg (original)
+++ llvm/trunk/test/MC/WebAssembly/lit.local.cfg Wed Feb 22 12:50:20 2017
@@ -1,2 +1,2 @@
-if 'AArch64' not in config.root.targets:
+if 'WebAssembly' not in config.root.targets:
     config.unsupported = True




More information about the llvm-commits mailing list