mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 08:10:49 +00:00
Cargo fmt
This commit is contained in:
parent
ae19e7f71b
commit
7808c68cb2
@ -32,6 +32,8 @@ mod sig_registry;
|
||||
pub mod structures;
|
||||
mod sys;
|
||||
pub mod table;
|
||||
#[cfg(all(unix, target_arch = "x86_64"))]
|
||||
pub mod trampoline_x64;
|
||||
pub mod typed_func;
|
||||
pub mod types;
|
||||
pub mod units;
|
||||
@ -39,8 +41,6 @@ pub mod vm;
|
||||
#[doc(hidden)]
|
||||
pub mod vmcalls;
|
||||
#[cfg(all(unix, target_arch = "x86_64"))]
|
||||
pub mod trampoline_x64;
|
||||
#[cfg(all(unix, target_arch = "x86_64"))]
|
||||
pub use trampoline_x64 as trampoline;
|
||||
|
||||
use self::error::CompileResult;
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Trampoline generator for carrying context with function pointer.
|
||||
//!
|
||||
//!
|
||||
//! This makes use of the `mm0` register to pass the context as an implicit "parameter" because `mm0` is
|
||||
//! not used to pass parameters and is almost never used by modern compilers. It's still better to call
|
||||
//! `get_context()` as early as possible in the callee function though, as a good practice.
|
||||
//!
|
||||
//!
|
||||
//! Variadic functions are not supported because `rax` is used by the trampoline code.
|
||||
|
||||
use crate::loader::CodeMemory;
|
||||
@ -60,7 +60,11 @@ impl TrampolineBufferBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_function(&mut self, target: *const CallTarget, context: *const CallContext) -> usize {
|
||||
pub fn add_function(
|
||||
&mut self,
|
||||
target: *const CallTarget,
|
||||
context: *const CallContext,
|
||||
) -> usize {
|
||||
let idx = self.offsets.len();
|
||||
self.offsets.push(self.code.len());
|
||||
self.code.extend_from_slice(&[
|
||||
@ -108,21 +112,19 @@ mod tests {
|
||||
value: i32,
|
||||
}
|
||||
extern "C" fn do_add(a: i32, b: f32) -> f32 {
|
||||
let ctx = unsafe {
|
||||
&*(get_context() as *const TestContext)
|
||||
};
|
||||
let ctx = unsafe { &*(get_context() as *const TestContext) };
|
||||
a as f32 + b + ctx.value as f32
|
||||
}
|
||||
let mut builder = TrampolineBufferBuilder::new();
|
||||
let ctx = TestContext {
|
||||
value: 3,
|
||||
};
|
||||
let idx = builder.add_function(do_add as usize as *const _, &ctx as *const TestContext as *const _);
|
||||
let ctx = TestContext { value: 3 };
|
||||
let idx = builder.add_function(
|
||||
do_add as usize as *const _,
|
||||
&ctx as *const TestContext as *const _,
|
||||
);
|
||||
let buf = builder.build();
|
||||
let t = buf.get_trampoline(idx);
|
||||
let ret = unsafe {
|
||||
::std::mem::transmute::<_, extern "C" fn (i32, f32) -> f32>(t)(1, 2.0) as i32
|
||||
};
|
||||
let ret =
|
||||
unsafe { ::std::mem::transmute::<_, extern "C" fn(i32, f32) -> f32>(t)(1, 2.0) as i32 };
|
||||
assert_eq!(ret, 6);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user