Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Unified Diff: src/wasm/wasm-module-builder.cc

Issue 2692943002: [wasm] Introduce EmitVarInt and EmitWithVarInt (Closed)
Patch Set: Use bit_cast instead of static_cast Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698