mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-19 03:41:22 +00:00
State representation.
This commit is contained in:
@ -4,6 +4,7 @@ use crate::{
|
|||||||
typed_func::Wasm,
|
typed_func::Wasm,
|
||||||
types::{LocalFuncIndex, SigIndex},
|
types::{LocalFuncIndex, SigIndex},
|
||||||
vm,
|
vm,
|
||||||
|
state::FunctionStateMap,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -84,6 +85,11 @@ pub trait RunnableModule: Send + Sync {
|
|||||||
local_func_index: LocalFuncIndex,
|
local_func_index: LocalFuncIndex,
|
||||||
) -> Option<NonNull<vm::Func>>;
|
) -> Option<NonNull<vm::Func>>;
|
||||||
|
|
||||||
|
fn get_func_statemap(
|
||||||
|
&self,
|
||||||
|
_local_func_index: LocalFuncIndex,
|
||||||
|
) -> Option<FunctionStateMap> { None }
|
||||||
|
|
||||||
/// A wasm trampoline contains the necesarry data to dynamically call an exported wasm function.
|
/// A wasm trampoline contains the necesarry data to dynamically call an exported wasm function.
|
||||||
/// Given a particular signature index, we are returned a trampoline that is matched with that
|
/// Given a particular signature index, we are returned a trampoline that is matched with that
|
||||||
/// signature and an invoke function that can call the trampoline.
|
/// signature and an invoke function that can call the trampoline.
|
||||||
|
@ -43,6 +43,7 @@ pub mod vm;
|
|||||||
pub mod vmcalls;
|
pub mod vmcalls;
|
||||||
#[cfg(all(unix, target_arch = "x86_64"))]
|
#[cfg(all(unix, target_arch = "x86_64"))]
|
||||||
pub use trampoline_x64 as trampoline;
|
pub use trampoline_x64 as trampoline;
|
||||||
|
pub mod state;
|
||||||
|
|
||||||
use self::error::CompileResult;
|
use self::error::CompileResult;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
75
lib/runtime-core/src/state.rs
Normal file
75
lib/runtime-core/src/state.rs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct RegisterIndex(pub usize);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct FunctionStateMap {
|
||||||
|
pub local_to_locations: Vec<Location>,
|
||||||
|
pub diffs: Vec<StateDiff>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct StateDiff {
|
||||||
|
pub last: Option<usize>,
|
||||||
|
pub stack_to_locations_push: Vec<Location>,
|
||||||
|
pub stack_to_locations_pop: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum Location {
|
||||||
|
Virtual, // no physical storage
|
||||||
|
Memory(RegisterIndex, i32),
|
||||||
|
Register(RegisterIndex),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, target_arch = "x86_64"))]
|
||||||
|
pub mod x64 {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
|
pub enum GPR {
|
||||||
|
RAX,
|
||||||
|
RCX,
|
||||||
|
RDX,
|
||||||
|
RBX,
|
||||||
|
RSP,
|
||||||
|
RBP,
|
||||||
|
RSI,
|
||||||
|
RDI,
|
||||||
|
R8,
|
||||||
|
R9,
|
||||||
|
R10,
|
||||||
|
R11,
|
||||||
|
R12,
|
||||||
|
R13,
|
||||||
|
R14,
|
||||||
|
R15,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
|
pub enum XMM {
|
||||||
|
XMM0,
|
||||||
|
XMM1,
|
||||||
|
XMM2,
|
||||||
|
XMM3,
|
||||||
|
XMM4,
|
||||||
|
XMM5,
|
||||||
|
XMM6,
|
||||||
|
XMM7,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum X64Register {
|
||||||
|
GPR(GPR),
|
||||||
|
XMM(XMM),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl X64Register {
|
||||||
|
pub fn to_index(&self) -> RegisterIndex {
|
||||||
|
match *self {
|
||||||
|
X64Register::GPR(x) => RegisterIndex(x as usize),
|
||||||
|
X64Register::XMM(x) => RegisterIndex(x as usize + 1000),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
#![allow(clippy::forget_copy)] // Used by dynasm.
|
#![allow(clippy::forget_copy)] // Used by dynasm.
|
||||||
|
#![warn(unused_imports)]
|
||||||
|
|
||||||
use crate::emitter_x64::*;
|
use crate::emitter_x64::*;
|
||||||
use crate::machine::*;
|
use crate::machine::*;
|
||||||
@ -28,6 +29,7 @@ use wasmer_runtime_core::{
|
|||||||
TableIndex, Type,
|
TableIndex, Type,
|
||||||
},
|
},
|
||||||
vm::{self, LocalGlobal, LocalTable, INTERNALS_SIZE},
|
vm::{self, LocalGlobal, LocalTable, INTERNALS_SIZE},
|
||||||
|
state::{FunctionStateMap, StateDiff, x64::X64Register, Location as StateLocation},
|
||||||
};
|
};
|
||||||
use wasmparser::{Operator, Type as WpType};
|
use wasmparser::{Operator, Type as WpType};
|
||||||
|
|
||||||
@ -139,6 +141,7 @@ enum LocalOrTemp {
|
|||||||
pub struct X64FunctionCode {
|
pub struct X64FunctionCode {
|
||||||
signatures: Arc<Map<SigIndex, FuncSig>>,
|
signatures: Arc<Map<SigIndex, FuncSig>>,
|
||||||
function_signatures: Arc<Map<FuncIndex, SigIndex>>,
|
function_signatures: Arc<Map<FuncIndex, SigIndex>>,
|
||||||
|
state_map: FunctionStateMap,
|
||||||
|
|
||||||
assembler: Option<Assembler>,
|
assembler: Option<Assembler>,
|
||||||
function_labels: Option<HashMap<usize, (DynamicLabel, Option<AssemblyOffset>)>>,
|
function_labels: Option<HashMap<usize, (DynamicLabel, Option<AssemblyOffset>)>>,
|
||||||
@ -356,6 +359,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
|
|||||||
let code = X64FunctionCode {
|
let code = X64FunctionCode {
|
||||||
signatures: self.signatures.as_ref().unwrap().clone(),
|
signatures: self.signatures.as_ref().unwrap().clone(),
|
||||||
function_signatures: self.function_signatures.as_ref().unwrap().clone(),
|
function_signatures: self.function_signatures.as_ref().unwrap().clone(),
|
||||||
|
state_map: FunctionStateMap::default(),
|
||||||
|
|
||||||
assembler: Some(assembler),
|
assembler: Some(assembler),
|
||||||
function_labels: Some(function_labels),
|
function_labels: Some(function_labels),
|
||||||
|
@ -1,38 +1,5 @@
|
|||||||
use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
|
use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
|
||||||
|
pub use wasmer_runtime_core::state::x64::{GPR, XMM};
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
|
||||||
pub enum GPR {
|
|
||||||
RAX,
|
|
||||||
RCX,
|
|
||||||
RDX,
|
|
||||||
RBX,
|
|
||||||
RSP,
|
|
||||||
RBP,
|
|
||||||
RSI,
|
|
||||||
RDI,
|
|
||||||
R8,
|
|
||||||
R9,
|
|
||||||
R10,
|
|
||||||
R11,
|
|
||||||
R12,
|
|
||||||
R13,
|
|
||||||
R14,
|
|
||||||
R15,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
|
||||||
pub enum XMM {
|
|
||||||
XMM0,
|
|
||||||
XMM1,
|
|
||||||
XMM2,
|
|
||||||
XMM3,
|
|
||||||
XMM4,
|
|
||||||
XMM5,
|
|
||||||
XMM6,
|
|
||||||
XMM7,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
pub enum Location {
|
pub enum Location {
|
||||||
|
Reference in New Issue
Block a user