[WebAssembly] Read global index in init expression as LEB
authorSam Clegg <sbc@chromium.org>
Tue, 25 Apr 2017 17:11:56 +0000 (17:11 +0000)
committerSam Clegg <sbc@chromium.org>
Tue, 25 Apr 2017 17:11:56 +0000 (17:11 +0000)
Subscribers: jfb, dschuff

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

llvm-svn: 301330

llvm/lib/Object/WasmObjectFile.cpp
llvm/lib/ObjectYAML/WasmYAML.cpp
llvm/test/ObjectYAML/wasm/elem_section.yaml

index 5b254b2..e1b3c4e 100644 (file)
@@ -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<GenericBinaryError>("Invalid opcode in init_expr",
index 3e1bed1..1c7c07a 100644 (file)
@@ -294,6 +294,9 @@ void MappingTraits<wasm::WasmInitExpr>::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;
   }
 }
 
index 498c9aa..c55e94c 100644 (file)
@@ -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: ...