Initial support for function, table, memory, and global imports.
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
use cranelift_codegen::ir::types;
|
||||
use cranelift_codegen::{ir, isa};
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::{Global, GlobalInit, Memory, Table, TableElementType};
|
||||
use std::ptr;
|
||||
use target_lexicon::HOST;
|
||||
use wasmtime_environ::{translate_signature, MemoryPlan, MemoryStyle, TablePlan, TableStyle};
|
||||
use wasmtime_execute::{ExportValue, Resolver, VMFunctionBody, VMGlobal, VMMemory, VMTable};
|
||||
use wasmtime_environ::{
|
||||
translate_signature, MemoryPlan, MemoryStyle, Module, TablePlan, TableStyle,
|
||||
};
|
||||
use wasmtime_execute::{Export, Resolver};
|
||||
use wasmtime_runtime::{
|
||||
Imports, Instance, VMFunctionBody, VMGlobalDefinition, VMMemoryDefinition, VMTableDefinition,
|
||||
};
|
||||
|
||||
extern "C" fn spectest_print() {}
|
||||
|
||||
@@ -41,44 +47,60 @@ extern "C" fn spectest_print_f64_f64(x: f64, y: f64) {
|
||||
}
|
||||
|
||||
pub struct SpecTest {
|
||||
spectest_global_i32: VMGlobal,
|
||||
spectest_global_f32: VMGlobal,
|
||||
spectest_global_f64: VMGlobal,
|
||||
spectest_table: VMTable,
|
||||
spectest_memory: VMMemory,
|
||||
instance: Instance,
|
||||
spectest_global_i32: VMGlobalDefinition,
|
||||
spectest_global_f32: VMGlobalDefinition,
|
||||
spectest_global_f64: VMGlobalDefinition,
|
||||
spectest_table: VMTableDefinition,
|
||||
spectest_memory: VMMemoryDefinition,
|
||||
}
|
||||
|
||||
impl SpecTest {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
spectest_global_i32: VMGlobal::definition(&Global {
|
||||
pub fn new() -> Result<Self, String> {
|
||||
let finished_functions = PrimaryMap::new();
|
||||
let imports = Imports::none();
|
||||
let data_initializers = Vec::new();
|
||||
Ok(Self {
|
||||
instance: Instance::new(
|
||||
&Module::new(),
|
||||
&finished_functions.into_boxed_slice(),
|
||||
imports,
|
||||
&data_initializers,
|
||||
)?,
|
||||
spectest_global_i32: VMGlobalDefinition::new(&Global {
|
||||
ty: types::I32,
|
||||
mutability: true,
|
||||
initializer: GlobalInit::I32Const(0),
|
||||
}),
|
||||
spectest_global_f32: VMGlobal::definition(&Global {
|
||||
spectest_global_f32: VMGlobalDefinition::new(&Global {
|
||||
ty: types::I32,
|
||||
mutability: true,
|
||||
initializer: GlobalInit::F32Const(0),
|
||||
}),
|
||||
spectest_global_f64: VMGlobal::definition(&Global {
|
||||
spectest_global_f64: VMGlobalDefinition::new(&Global {
|
||||
ty: types::I32,
|
||||
mutability: true,
|
||||
initializer: GlobalInit::F64Const(0),
|
||||
}),
|
||||
spectest_table: VMTable::definition(ptr::null_mut(), 0),
|
||||
spectest_memory: VMMemory::definition(ptr::null_mut(), 0),
|
||||
}
|
||||
spectest_table: VMTableDefinition {
|
||||
base: ptr::null_mut(),
|
||||
current_elements: 0,
|
||||
},
|
||||
spectest_memory: VMMemoryDefinition {
|
||||
base: ptr::null_mut(),
|
||||
current_length: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Resolver for SpecTest {
|
||||
fn resolve(&mut self, module: &str, field: &str) -> Option<ExportValue> {
|
||||
fn resolve(&mut self, module: &str, field: &str) -> Option<Export> {
|
||||
let call_conv = isa::CallConv::triple_default(&HOST);
|
||||
let pointer_type = types::Type::triple_pointer_type(&HOST);
|
||||
match module {
|
||||
"spectest" => match field {
|
||||
"print" => Some(ExportValue::function(
|
||||
"print" => Some(Export::function(
|
||||
spectest_print as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -89,7 +111,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"print_i32" => Some(ExportValue::function(
|
||||
"print_i32" => Some(Export::function(
|
||||
spectest_print_i32 as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -100,7 +122,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"print_i64" => Some(ExportValue::function(
|
||||
"print_i64" => Some(Export::function(
|
||||
spectest_print_i64 as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -111,7 +133,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"print_f32" => Some(ExportValue::function(
|
||||
"print_f32" => Some(Export::function(
|
||||
spectest_print_f32 as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -122,7 +144,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"print_f64" => Some(ExportValue::function(
|
||||
"print_f64" => Some(Export::function(
|
||||
spectest_print_f64 as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -133,7 +155,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"print_i32_f32" => Some(ExportValue::function(
|
||||
"print_i32_f32" => Some(Export::function(
|
||||
spectest_print_i32_f32 as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -147,7 +169,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"print_f64_f64" => Some(ExportValue::function(
|
||||
"print_f64_f64" => Some(Export::function(
|
||||
spectest_print_f64_f64 as *const VMFunctionBody,
|
||||
translate_signature(
|
||||
ir::Signature {
|
||||
@@ -161,7 +183,7 @@ impl Resolver for SpecTest {
|
||||
pointer_type,
|
||||
),
|
||||
)),
|
||||
"global_i32" => Some(ExportValue::global(
|
||||
"global_i32" => Some(Export::global(
|
||||
&mut self.spectest_global_i32,
|
||||
Global {
|
||||
ty: ir::types::I32,
|
||||
@@ -169,7 +191,7 @@ impl Resolver for SpecTest {
|
||||
initializer: GlobalInit::I32Const(0),
|
||||
},
|
||||
)),
|
||||
"global_f32" => Some(ExportValue::global(
|
||||
"global_f32" => Some(Export::global(
|
||||
&mut self.spectest_global_f32,
|
||||
Global {
|
||||
ty: ir::types::F32,
|
||||
@@ -177,7 +199,7 @@ impl Resolver for SpecTest {
|
||||
initializer: GlobalInit::F32Const(0),
|
||||
},
|
||||
)),
|
||||
"global_f64" => Some(ExportValue::global(
|
||||
"global_f64" => Some(Export::global(
|
||||
&mut self.spectest_global_f64,
|
||||
Global {
|
||||
ty: ir::types::F64,
|
||||
@@ -185,8 +207,9 @@ impl Resolver for SpecTest {
|
||||
initializer: GlobalInit::F64Const(0),
|
||||
},
|
||||
)),
|
||||
"table" => Some(ExportValue::table(
|
||||
"table" => Some(Export::table(
|
||||
&mut self.spectest_table,
|
||||
self.instance.vmctx_mut(),
|
||||
TablePlan {
|
||||
table: Table {
|
||||
ty: TableElementType::Func,
|
||||
@@ -196,8 +219,9 @@ impl Resolver for SpecTest {
|
||||
style: TableStyle::CallerChecksSignature,
|
||||
},
|
||||
)),
|
||||
"memory" => Some(ExportValue::memory(
|
||||
"memory" => Some(Export::memory(
|
||||
&mut self.spectest_memory,
|
||||
self.instance.vmctx_mut(),
|
||||
MemoryPlan {
|
||||
memory: Memory {
|
||||
minimum: 0,
|
||||
|
||||
Reference in New Issue
Block a user