2019-02-07 01:56:01 +00:00
|
|
|
use libc::{c_char, c_int};
|
|
|
|
use wasmer_runtime_core::vm::Ctx;
|
|
|
|
|
|
|
|
// This may be problematic for msvc which uses inline functions for the printf family
|
|
|
|
// this cfg_attr will try to link with the legacy lib that does not inline printf
|
|
|
|
// this will allow for compiliation, but will produce a linker error if there is a problem
|
|
|
|
// finding printf.
|
2019-02-08 21:51:29 +00:00
|
|
|
//#[cfg_attr(
|
|
|
|
// all(windows, target_env = "msvc"),
|
|
|
|
// link(name = "legacy_stdio_definitions", kind = "static-nobundle")
|
|
|
|
//)]
|
|
|
|
//extern "C" {
|
|
|
|
// #[link_name = "printf"]
|
|
|
|
// pub fn _printf(s: *const c_char, ...) -> c_int;
|
|
|
|
//}
|
2019-02-07 01:56:01 +00:00
|
|
|
|
|
|
|
/// putchar
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn putchar(ctx: &mut Ctx, chr: i32) {
|
2019-02-07 01:56:01 +00:00
|
|
|
unsafe { libc::putchar(chr) };
|
|
|
|
}
|
|
|
|
|
|
|
|
/// printf
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
|
2019-02-07 01:56:01 +00:00
|
|
|
debug!("emscripten::printf {}, {}", memory_offset, extra);
|
2019-02-08 21:51:29 +00:00
|
|
|
// unsafe {
|
|
|
|
// let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
|
|
|
|
// _printf(addr, extra)
|
|
|
|
// }
|
|
|
|
-1
|
2019-02-07 01:56:01 +00:00
|
|
|
}
|