summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2017-02-22 18:50:20 +0000
committerDan Gohman <dan433584@gmail.com>2017-02-22 18:50:20 +0000
commit7ea5adfff4c73c76d52fe5aad3106244b0b0e301 (patch)
tree70625b23dcc784cfa6dfb69d1762906b06b1c9bb
parentf1141285eb1f8bd857bb646ff54b2cacf75b28fc (diff)
downloadbcm5719-llvm-7ea5adfff4c73c76d52fe5aad3106244b0b0e301.tar.gz
bcm5719-llvm-7ea5adfff4c73c76d52fe5aad3106244b0b0e301.zip
[WebAssembly] Implement the wasm binary container header.
Also, update the version number to 0x1, which is what engines are now expecting. llvm-svn: 295860
-rw-r--r--llvm/include/llvm/Support/Wasm.h2
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp4
-rw-r--r--llvm/test/MC/WebAssembly/file-headers.ll9
-rw-r--r--llvm/test/MC/WebAssembly/lit.local.cfg2
4 files changed, 15 insertions, 2 deletions
diff --git a/llvm/include/llvm/Support/Wasm.h b/llvm/include/llvm/Support/Wasm.h
index b45149577a0..4bb9b4b8eb0 100644
--- a/llvm/include/llvm/Support/Wasm.h
+++ b/llvm/include/llvm/Support/Wasm.h
@@ -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;
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index cb11bab01eb..3a6114ad285 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -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,
diff --git a/llvm/test/MC/WebAssembly/file-headers.ll b/llvm/test/MC/WebAssembly/file-headers.ll
new file mode 100644
index 00000000000..1e5dd4b160a
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/file-headers.ll
@@ -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{{$}}
diff --git a/llvm/test/MC/WebAssembly/lit.local.cfg b/llvm/test/MC/WebAssembly/lit.local.cfg
new file mode 100644
index 00000000000..0dd8c920ff1
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/lit.local.cfg
@@ -0,0 +1,2 @@
+if 'WebAssembly' not in config.root.targets:
+ config.unsupported = True
OpenPOWER on IntegriCloud