From 7fb391fea3af9d4f0f970e2bf4b16cead76dc3b0 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 25 Apr 2017 17:11:56 +0000 Subject: [PATCH] [WebAssembly] Read global index in init expression as LEB Subscribers: jfb, dschuff Differential Revision: https://reviews.llvm.org/D32462 llvm-svn: 301330 --- llvm/lib/Object/WasmObjectFile.cpp | 2 +- llvm/lib/ObjectYAML/WasmYAML.cpp | 3 +++ llvm/test/ObjectYAML/wasm/elem_section.yaml | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 5b254b2957ac2..e1b3c4e1f39e5 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -144,7 +144,7 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr, const uint8_t *&Ptr) { Expr.Value.Float64 = readFloat64(Ptr); break; case wasm::WASM_OPCODE_GET_GLOBAL: - Expr.Value.Global = readUint32(Ptr); + Expr.Value.Global = readULEB128(Ptr); break; default: return make_error("Invalid opcode in init_expr", diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp index 3e1bed19d61fe..1c7c07ae29e8b 100644 --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -294,6 +294,9 @@ void MappingTraits::mapping(IO &IO, case wasm::WASM_OPCODE_F64_CONST: IO.mapRequired("Value", Expr.Value.Float64); break; + case wasm::WASM_OPCODE_GET_GLOBAL: + IO.mapRequired("Index", Expr.Value.Global); + break; } } diff --git a/llvm/test/ObjectYAML/wasm/elem_section.yaml b/llvm/test/ObjectYAML/wasm/elem_section.yaml index 498c9aa93ea2a..c55e94ce2d079 100644 --- a/llvm/test/ObjectYAML/wasm/elem_section.yaml +++ b/llvm/test/ObjectYAML/wasm/elem_section.yaml @@ -18,8 +18,8 @@ Sections: Functions: - 1 - Offset: - Opcode: I32_CONST - Value: 5 + Opcode: GET_GLOBAL + Index: 1 Functions: - 4 ... @@ -34,7 +34,7 @@ Sections: # CHECK: Value: 3 # CHECK: Functions: [ 1 ] # CHECK: - Offset: -# CHECK: Opcode: I32_CONST -# CHECK: Value: 5 +# CHECK: Opcode: GET_GLOBAL +# CHECK: Index: 1 # CHECK: Functions: [ 4 ] # CHECK: ...