LibWasm: Add missing spec-test imports

This commit is contained in:
Diego 2024-06-10 15:42:05 -07:00 committed by Ali Mohammad Pur
parent d20f1a99f8
commit 40fcb00c14
Notes: sideshowbarker 2024-07-17 02:08:15 +09:00
2 changed files with 56 additions and 7 deletions

View File

@ -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};')

View File

@ -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<Wasm::FunctionAddress> 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<Wasm::Value> {} };
},
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<Wasm::Linker::Name, Wasm::ExternValue> s_spec_test_namespace;