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

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

Issue 2390113003: [wasm] Refactor import handling for 0xC. (Closed)
Patch Set: Fix gc stress failure Created 4 years, 2 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') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | 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 084f5a0c1a08185d4c0021c86adc93957a93a9a1..941a0736c3272a53488121a3e3309619e4d90646 100644
--- a/src/wasm/wasm-module-builder.cc
+++ b/src/wasm/wasm-module-builder.cc
@@ -255,8 +255,9 @@ void WasmModuleBuilder::MarkStartFunction(WasmFunctionBuilder* function) {
}
uint32_t WasmModuleBuilder::AddGlobal(LocalType type, bool exported,
- bool mutability) {
- globals_.push_back({type, exported, mutability});
+ bool mutability,
+ const WasmInitExpr& init) {
+ globals_.push_back({type, exported, mutability, init});
return static_cast<uint32_t>(globals_.size() - 1);
}
@@ -344,29 +345,64 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
for (auto global : globals_) {
buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(global.type));
buffer.write_u8(global.mutability ? 1 : 0);
- switch (global.type) {
- case kAstI32: {
- static const byte code[] = {WASM_I32V_1(0)};
+ switch (global.init.kind) {
+ case WasmInitExpr::kI32Const: {
+ DCHECK_EQ(kAstI32, global.type);
+ const byte code[] = {WASM_I32V_5(global.init.val.i32_const)};
buffer.write(code, sizeof(code));
break;
}
- case kAstF32: {
- static const byte code[] = {WASM_F32(0)};
+ case WasmInitExpr::kI64Const: {
+ DCHECK_EQ(kAstI64, global.type);
+ const byte code[] = {WASM_I64V_10(global.init.val.i64_const)};
buffer.write(code, sizeof(code));
break;
}
- case kAstI64: {
- static const byte code[] = {WASM_I64V_1(0)};
+ case WasmInitExpr::kF32Const: {
+ DCHECK_EQ(kAstF32, global.type);
+ const byte code[] = {WASM_F32(global.init.val.f32_const)};
buffer.write(code, sizeof(code));
break;
}
- case kAstF64: {
- static const byte code[] = {WASM_F64(0.0)};
+ case WasmInitExpr::kF64Const: {
+ DCHECK_EQ(kAstF64, global.type);
+ const byte code[] = {WASM_F64(global.init.val.f64_const)};
buffer.write(code, sizeof(code));
break;
}
- default:
- UNREACHABLE();
+ case WasmInitExpr::kGlobalIndex: {
+ const byte code[] = {kExprGetGlobal,
+ U32V_5(global.init.val.global_index)};
+ buffer.write(code, sizeof(code));
+ break;
+ }
+ default: {
+ // No initializer, emit a default value.
+ switch (global.type) {
+ case kAstI32: {
+ const byte code[] = {WASM_I32V_1(0)};
+ buffer.write(code, sizeof(code));
+ break;
+ }
+ case kAstI64: {
+ const byte code[] = {WASM_I64V_1(0)};
+ buffer.write(code, sizeof(code));
+ break;
+ }
+ case kAstF32: {
+ const byte code[] = {WASM_F32(0.0)};
+ buffer.write(code, sizeof(code));
+ break;
+ }
+ case kAstF64: {
+ const byte code[] = {WASM_F64(0.0)};
+ buffer.write(code, sizeof(code));
+ break;
+ }
+ default:
+ UNREACHABLE();
+ }
+ }
}
buffer.write_u8(kExprEnd);
}
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698