Merge branch 'main' of github.com:cfallin/waffle
This commit is contained in:
commit
0f42e16446
|
@ -1,6 +1,6 @@
|
||||||
//! Waffle IR interpreter.
|
//! Waffle IR interpreter.
|
||||||
|
|
||||||
use crate::entity::PerEntity;
|
use crate::entity::{EntityRef, PerEntity};
|
||||||
use crate::ir::*;
|
use crate::ir::*;
|
||||||
use crate::ops::Operator;
|
use crate::ops::Operator;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
@ -65,7 +65,11 @@ impl InterpContext {
|
||||||
) -> Option<SmallVec<[ConstVal; 2]>> {
|
) -> Option<SmallVec<[ConstVal; 2]>> {
|
||||||
let body = match &module.funcs[func] {
|
let body = match &module.funcs[func] {
|
||||||
FuncDecl::Lazy(..) => panic!("Un-expanded function"),
|
FuncDecl::Lazy(..) => panic!("Un-expanded function"),
|
||||||
FuncDecl::Import(_, name) => return self.call_import(&name[..], args),
|
FuncDecl::Import(..) => {
|
||||||
|
let import = &module.imports[func.index()];
|
||||||
|
assert_eq!(import.kind, ImportKind::Func(func));
|
||||||
|
return self.call_import(&import.name[..], args);
|
||||||
|
}
|
||||||
FuncDecl::Body(_, _, body) => body,
|
FuncDecl::Body(_, _, body) => body,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,25 @@ pub fn call_wasi(
|
||||||
args: &[ConstVal],
|
args: &[ConstVal],
|
||||||
) -> Option<SmallVec<[ConstVal; 2]>> {
|
) -> Option<SmallVec<[ConstVal; 2]>> {
|
||||||
match name {
|
match name {
|
||||||
"__wasi_fd_prestat_get" => {
|
"fd_prestat_get" => {
|
||||||
Some(smallvec![ConstVal::I32(8)]) // BADF
|
Some(smallvec![ConstVal::I32(8)]) // BADF
|
||||||
}
|
}
|
||||||
"__wasi_args_sizes_get" => {
|
"args_sizes_get" => {
|
||||||
let p_argc = args[0].as_u32().unwrap();
|
let p_argc = args[0].as_u32().unwrap();
|
||||||
let p_argv_size = args[1].as_u32().unwrap();
|
let p_argv_size = args[1].as_u32().unwrap();
|
||||||
write_u32(mem, p_argc, 0);
|
write_u32(mem, p_argc, 0);
|
||||||
write_u32(mem, p_argv_size, 0);
|
write_u32(mem, p_argv_size, 0);
|
||||||
Some(smallvec![ConstVal::I32(0)])
|
Some(smallvec![ConstVal::I32(0)])
|
||||||
}
|
}
|
||||||
"__wasi_args_get" => Some(smallvec![ConstVal::I32(0)]),
|
"environ_sizes_get" => {
|
||||||
"__wasi_fd_fdstat_get" => {
|
let p_environ_count = args[0].as_u32().unwrap();
|
||||||
|
let p_environ_buf_size = args[0].as_u32().unwrap();
|
||||||
|
write_u32(mem, p_environ_count, 0);
|
||||||
|
write_u32(mem, p_environ_buf_size, 0);
|
||||||
|
Some(smallvec![ConstVal::I32(0)])
|
||||||
|
}
|
||||||
|
"args_get" => Some(smallvec![ConstVal::I32(0)]),
|
||||||
|
"fd_fdstat_get" => {
|
||||||
let fd = args[0].as_u32().unwrap();
|
let fd = args[0].as_u32().unwrap();
|
||||||
let p_fdstat_t = args[1].as_u32().unwrap();
|
let p_fdstat_t = args[1].as_u32().unwrap();
|
||||||
if fd == 1 {
|
if fd == 1 {
|
||||||
|
@ -33,7 +40,7 @@ pub fn call_wasi(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"__wasi_fd_write" => {
|
"fd_write" => {
|
||||||
let fd = args[0].as_u32().unwrap();
|
let fd = args[0].as_u32().unwrap();
|
||||||
let p_iovs = args[1].as_u32().unwrap();
|
let p_iovs = args[1].as_u32().unwrap();
|
||||||
let iovs_len = args[2].as_u32().unwrap();
|
let iovs_len = args[2].as_u32().unwrap();
|
||||||
|
@ -54,10 +61,15 @@ pub fn call_wasi(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"__wasi_proc_exit" => {
|
"proc_exit" => {
|
||||||
eprintln!("WASI exit: {:?}", args[0]);
|
eprintln!("WASI exit: {:?}", args[0]);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
"clock_time_get" => {
|
||||||
|
let p_time = args[2].as_u32().unwrap();
|
||||||
|
write_u32(mem, p_time, 0);
|
||||||
|
Some(smallvec![ConstVal::I32(0)])
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub struct Import {
|
||||||
pub kind: ImportKind,
|
pub kind: ImportKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ImportKind {
|
pub enum ImportKind {
|
||||||
Table(Table),
|
Table(Table),
|
||||||
Func(Func),
|
Func(Func),
|
||||||
|
|
Loading…
Reference in a new issue