diff --git a/Meta/generate-libwasm-spec-test.py b/Meta/generate-libwasm-spec-test.py index a952ad91d4a..7063449582d 100644 --- a/Meta/generate-libwasm-spec-test.py +++ b/Meta/generate-libwasm-spec-test.py @@ -341,7 +341,7 @@ let _field = {module}.getExport("{get.field}");""" def gen_register(register: Register, _: Context): module = "module" if register.name is not None: - module = f'namedModules["{module}"]' + module = f'namedModules["{register.name}"]' print(f'globalImportObject["{register.as_}"] = {module};') diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 207e8c7c993..d524239ebf7 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -82,17 +82,66 @@ private: { if (!s_spec_test_namespace.is_empty()) return s_spec_test_namespace; - Wasm::FunctionType print_i32_type { { Wasm::ValueType(Wasm::ValueType::I32) }, {} }; - auto address = m_machine.store().allocate(Wasm::HostFunction { + Wasm::FunctionType print_i32_type { { Wasm::ValueType(Wasm::ValueType::I32) }, {} }; + auto address_i32 = alloc_noop_function(print_i32_type); + s_spec_test_namespace.set({ "spectest", "print_i32", print_i32_type }, Wasm::ExternValue { *address_i32 }); + + Wasm::FunctionType print_i64_type { { Wasm::ValueType(Wasm::ValueType::I64) }, {} }; + auto address_i64 = alloc_noop_function(print_i64_type); + s_spec_test_namespace.set({ "spectest", "print_i64", print_i64_type }, Wasm::ExternValue { *address_i64 }); + + Wasm::FunctionType print_f32_type { { Wasm::ValueType(Wasm::ValueType::F32) }, {} }; + auto address_f32 = alloc_noop_function(print_f32_type); + s_spec_test_namespace.set({ "spectest", "print_f32", print_f32_type }, Wasm::ExternValue { *address_f32 }); + + Wasm::FunctionType print_f64_type { { Wasm::ValueType(Wasm::ValueType::F64) }, {} }; + auto address_f64 = alloc_noop_function(print_f64_type); + s_spec_test_namespace.set({ "spectest", "print_f64", print_f64_type }, Wasm::ExternValue { *address_f64 }); + + Wasm::FunctionType print_i32_f32_type { { Wasm::ValueType(Wasm::ValueType::I32), Wasm::ValueType(Wasm::ValueType::F32) }, {} }; + auto address_i32_f32 = alloc_noop_function(print_i32_f32_type); + s_spec_test_namespace.set({ "spectest", "print_i32_f32", print_i32_f32_type }, Wasm::ExternValue { *address_i32_f32 }); + + Wasm::FunctionType print_f64_f64_type { { Wasm::ValueType(Wasm::ValueType::F64), Wasm::ValueType(Wasm::ValueType::F64) }, {} }; + auto address_f64_f64 = alloc_noop_function(print_f64_f64_type); + s_spec_test_namespace.set({ "spectest", "print_f64_f64", print_f64_f64_type }, Wasm::ExternValue { *address_f64_f64 }); + + Wasm::TableType table_type { Wasm::ValueType(Wasm::ValueType::FunctionReference), Wasm::Limits(10, 20) }; + auto table_address = m_machine.store().allocate(table_type); + s_spec_test_namespace.set({ "spectest", "table", table_type }, Wasm::ExternValue { *table_address }); + + Wasm::MemoryType memory_type { Wasm::Limits(1, 2) }; + auto memory_address = m_machine.store().allocate(memory_type); + s_spec_test_namespace.set({ "spectest", "memory", memory_type }, Wasm::ExternValue { *memory_address }); + + Wasm::GlobalType global_i32 { Wasm::ValueType(Wasm::ValueType::I32), false }; + auto global_i32_address = m_machine.store().allocate(global_i32, Wasm::Value(666)); + s_spec_test_namespace.set({ "spectest", "global_i32", global_i32 }, Wasm::ExternValue { *global_i32_address }); + + Wasm::GlobalType global_i64 { Wasm::ValueType(Wasm::ValueType::I64), false }; + auto global_i64_address = m_machine.store().allocate(global_i64, Wasm::Value((i64)666)); + s_spec_test_namespace.set({ "spectest", "global_i64", global_i64 }, Wasm::ExternValue { *global_i64_address }); + + Wasm::GlobalType global_f32 { Wasm::ValueType(Wasm::ValueType::F32), false }; + auto global_f32_address = m_machine.store().allocate(global_f32, Wasm::Value(666.6f)); + s_spec_test_namespace.set({ "spectest", "global_f32", global_f32 }, Wasm::ExternValue { *global_f32_address }); + + Wasm::GlobalType global_f64 { Wasm::ValueType(Wasm::ValueType::F64), false }; + auto global_f64_address = m_machine.store().allocate(global_f64, Wasm::Value(666.6)); + s_spec_test_namespace.set({ "spectest", "global_f64", global_f64 }, Wasm::ExternValue { *global_f64_address }); + + return s_spec_test_namespace; + } + + static Optional alloc_noop_function(Wasm::FunctionType type) + { + return m_machine.store().allocate(Wasm::HostFunction { [](auto&, auto&) -> Wasm::Result { // Noop, this just needs to exist. return Wasm::Result { Vector {} }; }, - print_i32_type }); - s_spec_test_namespace.set({ "spectest", "print_i32", print_i32_type }, Wasm::ExternValue { *address }); - - return s_spec_test_namespace; + type }); } static HashMap s_spec_test_namespace;