Index: src/wasm/wasm-module-builder.cc |
diff --git a/src/wasm/wasm-module-builder.cc b/src/wasm/wasm-module-builder.cc |
index 6458e06797ef0e67170aede5e1744e28c203ac7c..5ebe8662ee4605cbfa9ec3f2ae9c95e1b40da0e1 100644 |
--- a/src/wasm/wasm-module-builder.cc |
+++ b/src/wasm/wasm-module-builder.cc |
@@ -62,13 +62,20 @@ WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder) |
direct_calls_(builder->zone()), |
asm_offsets_(builder->zone(), 8) {} |
+void WasmFunctionBuilder::EmitVarInt(int32_t val) { |
+ byte buffer[5]; |
+ byte* ptr = buffer; |
+ LEBHelper::write_i32v(&ptr, val); |
+ DCHECK_GE(5, ptr - buffer); |
+ body_.insert(body_.end(), buffer, ptr); |
+} |
+ |
void WasmFunctionBuilder::EmitVarUint(uint32_t val) { |
- byte buffer[8]; |
+ byte buffer[5]; |
byte* ptr = buffer; |
LEBHelper::write_u32v(&ptr, val); |
- for (byte* p = buffer; p < ptr; p++) { |
- body_.push_back(*p); |
- } |
+ DCHECK_GE(5, ptr - buffer); |
+ body_.insert(body_.end(), buffer, ptr); |
} |
void WasmFunctionBuilder::SetSignature(FunctionSig* sig) { |
@@ -116,6 +123,11 @@ void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1, |
body_.push_back(imm2); |
} |
+void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, int32_t immediate) { |
+ body_.push_back(static_cast<byte>(opcode)); |
+ EmitVarInt(immediate); |
+} |
+ |
void WasmFunctionBuilder::EmitWithVarUint(WasmOpcode opcode, |
uint32_t immediate) { |
body_.push_back(static_cast<byte>(opcode)); |
@@ -123,13 +135,7 @@ void WasmFunctionBuilder::EmitWithVarUint(WasmOpcode opcode, |
} |
void WasmFunctionBuilder::EmitI32Const(int32_t value) { |
- if (-64 <= value && value <= 63) { |
- EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F)); |
- } else { |
- // TODO(titzer): variable-length signed and unsigned i32 constants. |
- byte code[] = {WASM_I32V_5(value)}; |
- EmitCode(code, sizeof(code)); |
- } |
+ EmitWithVarInt(kExprI32Const, value); |
} |
void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) { |