mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 16:41:33 +00:00
Fixed all Rust code warnings
This commit is contained in:
@ -4,9 +4,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Read};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::SystemTime;
|
|
||||||
use wabt::script::{Action, Command, CommandKind, ModuleBinary, ScriptParser, Value};
|
use wabt::script::{Action, Command, CommandKind, ModuleBinary, ScriptParser, Value};
|
||||||
use wabt::wasm2wat;
|
use wabt::wasm2wat;
|
||||||
|
|
||||||
@ -74,10 +72,10 @@ const TESTS: [&str; 54] = [
|
|||||||
|
|
||||||
fn wabt2rust_type(v: &Value) -> String {
|
fn wabt2rust_type(v: &Value) -> String {
|
||||||
match v {
|
match v {
|
||||||
Value::I32(v) => format!("i32"),
|
Value::I32(_v) => format!("i32"),
|
||||||
Value::I64(v) => format!("i64"),
|
Value::I64(_v) => format!("i64"),
|
||||||
Value::F32(v) => format!("f32"),
|
Value::F32(_v) => format!("f32"),
|
||||||
Value::F64(v) => format!("f64"),
|
Value::F64(_v) => format!("f64"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,32 +93,30 @@ fn wabt2rust_value(v: &Value) -> String {
|
|||||||
Value::I32(v) => format!("{:?} as i32", v),
|
Value::I32(v) => format!("{:?} as i32", v),
|
||||||
Value::I64(v) => format!("{:?} as i64", v),
|
Value::I64(v) => format!("{:?} as i64", v),
|
||||||
Value::F32(v) => {
|
Value::F32(v) => {
|
||||||
match *v {
|
if v.is_infinite() {
|
||||||
std::f32::INFINITY => "f32::INFINITY".to_string(),
|
if v.is_sign_negative() {
|
||||||
std::f32::NEG_INFINITY => "f32::NEG_INFINITY".to_string(),
|
"f32::NEG_INFINITY".to_string()
|
||||||
// std::f32::NAN => "f32::NAN".to_string(),
|
} else {
|
||||||
_ => {
|
"f32::INFINITY".to_string()
|
||||||
if v.is_nan() {
|
|
||||||
// Support for non-canonical NaNs
|
|
||||||
format!("f32::from_bits({:?})", v.to_bits())
|
|
||||||
} else {
|
|
||||||
format!("{:?} as f32", v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if v.is_nan() {
|
||||||
|
// Support for non-canonical NaNs
|
||||||
|
format!("f32::from_bits({:?})", v.to_bits())
|
||||||
|
} else {
|
||||||
|
format!("{:?} as f32", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::F64(v) => {
|
Value::F64(v) => {
|
||||||
match *v {
|
if v.is_infinite() {
|
||||||
std::f64::INFINITY => "f64::INFINITY".to_string(),
|
if v.is_sign_negative() {
|
||||||
std::f64::NEG_INFINITY => "f64::NEG_INFINITY".to_string(),
|
"f64::NEG_INFINITY".to_string()
|
||||||
// std::f64::NAN => "f64::NAN".to_string(),
|
} else {
|
||||||
_ => {
|
"f64::INFINITY".to_string()
|
||||||
if v.is_nan() {
|
|
||||||
format!("f64::from_bits({:?})", v.to_bits())
|
|
||||||
} else {
|
|
||||||
format!("{:?} as f64", v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if v.is_nan() {
|
||||||
|
format!("f64::from_bits({:?})", v.to_bits())
|
||||||
|
} else {
|
||||||
|
format!("{:?} as f64", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,9 +136,8 @@ impl WastTestGenerator {
|
|||||||
fn new(path: &PathBuf) -> Self {
|
fn new(path: &PathBuf) -> Self {
|
||||||
let filename = path.file_name().unwrap().to_str().unwrap();
|
let filename = path.file_name().unwrap().to_str().unwrap();
|
||||||
let source = fs::read(&path).unwrap();
|
let source = fs::read(&path).unwrap();
|
||||||
let mut script: ScriptParser =
|
let script: ScriptParser = ScriptParser::from_source_and_name(&source, filename).unwrap();
|
||||||
ScriptParser::from_source_and_name(&source, filename).unwrap();
|
let buffer = String::new();
|
||||||
let mut buffer = String::new();
|
|
||||||
WastTestGenerator {
|
WastTestGenerator {
|
||||||
last_module: 0,
|
last_module: 0,
|
||||||
last_line: 0,
|
last_line: 0,
|
||||||
@ -216,7 +211,7 @@ fn test_module_{}() {{
|
|||||||
self.module_calls.remove(&module);
|
self.module_calls.remove(&module);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_module(&mut self, module: &ModuleBinary, name: &Option<String>) {
|
fn visit_module(&mut self, module: &ModuleBinary, _name: &Option<String>) {
|
||||||
let wasm_binary: Vec<u8> = module.clone().into_vec();
|
let wasm_binary: Vec<u8> = module.clone().into_vec();
|
||||||
let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
|
let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
|
||||||
self.flush_module_calls(self.last_module);
|
self.flush_module_calls(self.last_module);
|
||||||
@ -280,12 +275,12 @@ fn {}_assert_invalid() {{
|
|||||||
fn visit_assert_return_arithmetic_nan(&mut self, action: &Action) {
|
fn visit_assert_return_arithmetic_nan(&mut self, action: &Action) {
|
||||||
match action {
|
match action {
|
||||||
Action::Invoke {
|
Action::Invoke {
|
||||||
module,
|
module: _,
|
||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
let mut return_type = wabt2rust_type(&args[0]);
|
let return_type = wabt2rust_type(&args[0]);
|
||||||
let mut func_return = format!(" -> {}", return_type);
|
let func_return = format!(" -> {}", return_type);
|
||||||
let assertion = String::from("assert!(result.is_quiet_nan())");
|
let assertion = String::from("assert!(result.is_quiet_nan())");
|
||||||
|
|
||||||
// We map the arguments provided into the raw Arguments provided
|
// We map the arguments provided into the raw Arguments provided
|
||||||
@ -333,16 +328,16 @@ fn {}_assert_invalid() {{
|
|||||||
fn visit_assert_return_canonical_nan(&mut self, action: &Action) {
|
fn visit_assert_return_canonical_nan(&mut self, action: &Action) {
|
||||||
match action {
|
match action {
|
||||||
Action::Invoke {
|
Action::Invoke {
|
||||||
module,
|
module: _,
|
||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
let mut return_type = match &field.as_str() {
|
let return_type = match &field.as_str() {
|
||||||
&"f64.promote_f32" => String::from("f64"),
|
&"f64.promote_f32" => String::from("f64"),
|
||||||
&"f32.promote_f64" => String::from("f32"),
|
&"f32.promote_f64" => String::from("f32"),
|
||||||
_ => wabt2rust_type(&args[0]),
|
_ => wabt2rust_type(&args[0]),
|
||||||
};
|
};
|
||||||
let mut func_return = format!(" -> {}", return_type);
|
let func_return = format!(" -> {}", return_type);
|
||||||
let assertion = String::from("assert!(result.is_quiet_nan())");
|
let assertion = String::from("assert!(result.is_quiet_nan())");
|
||||||
|
|
||||||
// We map the arguments provided into the raw Arguments provided
|
// We map the arguments provided into the raw Arguments provided
|
||||||
@ -409,7 +404,7 @@ fn {}_assert_malformed() {{
|
|||||||
fn visit_action(&mut self, action: &Action, expected: Option<&Vec<Value>>) -> Option<String> {
|
fn visit_action(&mut self, action: &Action, expected: Option<&Vec<Value>>) -> Option<String> {
|
||||||
match action {
|
match action {
|
||||||
Action::Invoke {
|
Action::Invoke {
|
||||||
module,
|
module: _,
|
||||||
field,
|
field,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
@ -554,16 +549,25 @@ fn {}() {{
|
|||||||
CommandKind::AssertMalformed { module, message: _ } => {
|
CommandKind::AssertMalformed { module, message: _ } => {
|
||||||
self.visit_assert_malformed(module);
|
self.visit_assert_malformed(module);
|
||||||
}
|
}
|
||||||
CommandKind::AssertUninstantiable { module, message: _ } => {
|
CommandKind::AssertUninstantiable {
|
||||||
|
module: _,
|
||||||
|
message: _,
|
||||||
|
} => {
|
||||||
// Do nothing for now
|
// Do nothing for now
|
||||||
}
|
}
|
||||||
CommandKind::AssertExhaustion { action } => {
|
CommandKind::AssertExhaustion { action: _ } => {
|
||||||
// Do nothing for now
|
// Do nothing for now
|
||||||
}
|
}
|
||||||
CommandKind::AssertUnlinkable { module, message: _ } => {
|
CommandKind::AssertUnlinkable {
|
||||||
|
module: _,
|
||||||
|
message: _,
|
||||||
|
} => {
|
||||||
// Do nothing for now
|
// Do nothing for now
|
||||||
}
|
}
|
||||||
CommandKind::Register { name, as_name } => {
|
CommandKind::Register {
|
||||||
|
name: _,
|
||||||
|
as_name: _,
|
||||||
|
} => {
|
||||||
// Do nothing for now
|
// Do nothing for now
|
||||||
}
|
}
|
||||||
CommandKind::PerformAction(action) => {
|
CommandKind::PerformAction(action) => {
|
||||||
@ -592,7 +596,7 @@ fn wast_to_rust(wast_filepath: &str) -> (String, i32) {
|
|||||||
.expect("Can't get wast file metadata")
|
.expect("Can't get wast file metadata")
|
||||||
.modified()
|
.modified()
|
||||||
.expect("Can't get wast file modified date");
|
.expect("Can't get wast file modified date");
|
||||||
let should_modify = match fs::metadata(&rust_test_filepath) {
|
let _should_modify = match fs::metadata(&rust_test_filepath) {
|
||||||
Ok(m) => {
|
Ok(m) => {
|
||||||
m.modified()
|
m.modified()
|
||||||
.expect("Can't get rust test file modified date")
|
.expect("Can't get rust test file modified date")
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use crate::webassembly::{ImportObject, VmCtx};
|
use crate::webassembly::{ImportObject, VmCtx};
|
||||||
use libc::{printf, putchar};
|
use libc::{printf, putchar};
|
||||||
use std::io;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
extern "C" fn _printf(memory_offset: i32, extra: i32, vm_context: &mut VmCtx) -> i32 {
|
extern "C" fn _printf(memory_offset: i32, extra: i32, vm_context: &mut VmCtx) -> i32 {
|
||||||
// println!("PRINTF");
|
// println!("PRINTF");
|
||||||
@ -23,10 +21,7 @@ pub fn generate_libc_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::generate_libc_env;
|
use super::generate_libc_env;
|
||||||
use crate::webassembly::{
|
use crate::webassembly::{instantiate, Export, VmCtx};
|
||||||
instantiate, ErrorKind, Export, ImportObject, Instance, Module, ResultObject, VmCtx,
|
|
||||||
};
|
|
||||||
use libc::putchar;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_putchar() {
|
fn test_putchar() {
|
||||||
@ -34,7 +29,7 @@ mod tests {
|
|||||||
let import_object = generate_libc_env();
|
let import_object = generate_libc_env();
|
||||||
let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
||||||
let module = result_object.module;
|
let module = result_object.module;
|
||||||
let mut instance = result_object.instance;
|
let instance = result_object.instance;
|
||||||
let func_index = match module.info.exports.get("main") {
|
let func_index = match module.info.exports.get("main") {
|
||||||
Some(&Export::Function(index)) => index,
|
Some(&Export::Function(index)) => index,
|
||||||
_ => panic!("Function not found"),
|
_ => panic!("Function not found"),
|
||||||
@ -50,7 +45,7 @@ mod tests {
|
|||||||
let import_object = generate_libc_env();
|
let import_object = generate_libc_env();
|
||||||
let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
||||||
let module = result_object.module;
|
let module = result_object.module;
|
||||||
let mut instance = result_object.instance;
|
let instance = result_object.instance;
|
||||||
let func_index = match module.info.exports.get("main") {
|
let func_index = match module.info.exports.get("main") {
|
||||||
Some(&Export::Function(index)) => index,
|
Some(&Export::Function(index)) => index,
|
||||||
_ => panic!("Function not found"),
|
_ => panic!("Function not found"),
|
||||||
|
@ -19,8 +19,8 @@ macro_rules! get_instance_function {
|
|||||||
macro_rules! include_wast2wasm_bytes {
|
macro_rules! include_wast2wasm_bytes {
|
||||||
($x:expr) => {{
|
($x:expr) => {{
|
||||||
use wabt::wat2wasm;
|
use wabt::wat2wasm;
|
||||||
const wast_bytes: &[u8] = include_bytes!($x);
|
const WAST_BYTES: &[u8] = include_bytes!($x);
|
||||||
wat2wasm(wast_bytes.to_vec()).expect(&format!("Can't convert {} file to wasm", $x))
|
wat2wasm(WAST_BYTES.to_vec()).expect(&format!("Can't convert {} file to wasm", $x))
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
src/main.rs
15
src/main.rs
@ -3,12 +3,11 @@
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
#[macro_use]
|
|
||||||
extern crate structopt;
|
|
||||||
extern crate cranelift_codegen;
|
extern crate cranelift_codegen;
|
||||||
extern crate cranelift_entity;
|
extern crate cranelift_entity;
|
||||||
extern crate cranelift_native;
|
extern crate cranelift_native;
|
||||||
extern crate cranelift_wasm;
|
extern crate cranelift_wasm;
|
||||||
|
extern crate structopt;
|
||||||
extern crate wabt;
|
extern crate wabt;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate target_lexicon;
|
extern crate target_lexicon;
|
||||||
@ -16,14 +15,14 @@ extern crate nix;
|
|||||||
extern crate spin;
|
extern crate spin;
|
||||||
|
|
||||||
// use std::alloc::System;
|
// use std::alloc::System;
|
||||||
use std::time::{Duration, Instant};
|
// use std::time::{Duration, Instant};
|
||||||
|
|
||||||
// #[global_allocator]
|
// #[global_allocator]
|
||||||
// static A: System = System;
|
// static A: System = System;
|
||||||
|
|
||||||
// #[macro_use] extern crate log;
|
// #[macro_use] extern crate log;
|
||||||
|
|
||||||
use libc;
|
// use libc;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -78,11 +77,9 @@ fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let import_object = integrations::generate_libc_env();
|
let import_object = integrations::generate_libc_env();
|
||||||
let webassembly::ResultObject {
|
let webassembly::ResultObject { module, instance } =
|
||||||
module,
|
webassembly::instantiate(wasm_binary, import_object)
|
||||||
mut instance,
|
.map_err(|err| String::from(err.description()))?;
|
||||||
} = webassembly::instantiate(wasm_binary, import_object)
|
|
||||||
.map_err(|err| String::from(err.description()))?;
|
|
||||||
let func_index = instance
|
let func_index = instance
|
||||||
.start_func
|
.start_func
|
||||||
.unwrap_or_else(|| match module.info.exports.get("main") {
|
.unwrap_or_else(|| match module.info.exports.get("main") {
|
||||||
|
@ -18,13 +18,13 @@ pub unsafe fn install_sighandler() {
|
|||||||
sigaction(SIGILL, &sa).unwrap();
|
sigaction(SIGILL, &sa).unwrap();
|
||||||
sigaction(SIGSEGV, &sa).unwrap();
|
sigaction(SIGSEGV, &sa).unwrap();
|
||||||
sigaction(SIGBUS, &sa).unwrap();
|
sigaction(SIGBUS, &sa).unwrap();
|
||||||
let result = setjmp((&mut setjmp_buffer[..]).as_mut_ptr() as *mut ::nix::libc::c_void);
|
let result = setjmp((&mut SETJMP_BUFFER[..]).as_mut_ptr() as *mut ::nix::libc::c_void);
|
||||||
if result != 0 {
|
if result != 0 {
|
||||||
panic!("Signal Error: {}", result);
|
panic!("Signal Error: {}", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut setjmp_buffer: [::nix::libc::c_int; 27] = [0; 27];
|
static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27];
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int;
|
fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int;
|
||||||
fn longjmp(env: *mut ::nix::libc::c_void, val: ::nix::libc::c_int);
|
fn longjmp(env: *mut ::nix::libc::c_void, val: ::nix::libc::c_int);
|
||||||
@ -32,7 +32,7 @@ extern "C" {
|
|||||||
extern "C" fn signal_trap_handler(_: ::nix::libc::c_int) {
|
extern "C" fn signal_trap_handler(_: ::nix::libc::c_int) {
|
||||||
unsafe {
|
unsafe {
|
||||||
longjmp(
|
longjmp(
|
||||||
(&mut setjmp_buffer).as_mut_ptr() as *mut ::nix::libc::c_void,
|
(&mut SETJMP_BUFFER).as_mut_ptr() as *mut ::nix::libc::c_void,
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ pub trait NaNCheck {
|
|||||||
impl NaNCheck for f32 {
|
impl NaNCheck for f32 {
|
||||||
/// The MSB of the mantissa must be set for a NaN to be a quiet NaN.
|
/// The MSB of the mantissa must be set for a NaN to be a quiet NaN.
|
||||||
fn is_quiet_nan(&self) -> bool {
|
fn is_quiet_nan(&self) -> bool {
|
||||||
let bit_mask = (0b1 << 22); // Used to check if 23rd bit is set, which is MSB of the mantissa
|
let bit_mask = 0b1 << 22; // Used to check if 23rd bit is set, which is MSB of the mantissa
|
||||||
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
|
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ impl NaNCheck for f32 {
|
|||||||
impl NaNCheck for f64 {
|
impl NaNCheck for f64 {
|
||||||
/// The MSB of the mantissa must be set for a NaN to be a quiet NaN.
|
/// The MSB of the mantissa must be set for a NaN to be a quiet NaN.
|
||||||
fn is_quiet_nan(&self) -> bool {
|
fn is_quiet_nan(&self) -> bool {
|
||||||
let bit_mask = (0b1 << 51); // Used to check if 51st bit is set, which is MSB of the mantissa
|
let bit_mask = 0b1 << 51; // Used to check if 51st bit is set, which is MSB of the mantissa
|
||||||
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
|
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,4 +65,3 @@ impl NaNCheck for f64 {
|
|||||||
(self.to_bits() & bit_mask) == bit_mask
|
(self.to_bits() & bit_mask) == bit_mask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ use region;
|
|||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ptr::write_unaligned;
|
use std::ptr::write_unaligned;
|
||||||
|
use std::slice;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{mem, slice};
|
|
||||||
|
|
||||||
use super::super::common::slice::{BoundedSlice, UncheckedSlice};
|
use super::super::common::slice::{BoundedSlice, UncheckedSlice};
|
||||||
use super::errors::ErrorKind;
|
use super::errors::ErrorKind;
|
||||||
@ -59,7 +59,7 @@ fn get_function_addr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
#[repr(C, packed)]
|
#[repr(C)]
|
||||||
pub struct VmCtx<'phantom> {
|
pub struct VmCtx<'phantom> {
|
||||||
pub user_data: UserData,
|
pub user_data: UserData,
|
||||||
globals: UncheckedSlice<u8>,
|
globals: UncheckedSlice<u8>,
|
||||||
@ -69,7 +69,7 @@ pub struct VmCtx<'phantom> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
#[repr(C, packed)]
|
#[repr(C)]
|
||||||
pub struct UserData {
|
pub struct UserData {
|
||||||
// pub process: Dispatch<Process>,
|
// pub process: Dispatch<Process>,
|
||||||
pub instance: Instance,
|
pub instance: Instance,
|
||||||
@ -126,7 +126,7 @@ impl Instance {
|
|||||||
// We walk through the imported functions and set the relocations
|
// We walk through the imported functions and set the relocations
|
||||||
// for each of this functions to be an empty vector (as is defined outside of wasm)
|
// for each of this functions to be an empty vector (as is defined outside of wasm)
|
||||||
for (module, field) in module.info.imported_funcs.iter() {
|
for (module, field) in module.info.imported_funcs.iter() {
|
||||||
let mut function = import_object
|
let function = import_object
|
||||||
.get(&module.as_str(), &field.as_str())
|
.get(&module.as_str(), &field.as_str())
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ErrorKind::LinkError(format!(
|
ErrorKind::LinkError(format!(
|
||||||
@ -163,7 +163,7 @@ impl Instance {
|
|||||||
.compile_and_emit(&*isa, &mut code_buf, &mut reloc_sink, &mut trap_sink)
|
.compile_and_emit(&*isa, &mut code_buf, &mut reloc_sink, &mut trap_sink)
|
||||||
.map_err(|e| ErrorKind::CompileError(e.to_string()))?;
|
.map_err(|e| ErrorKind::CompileError(e.to_string()))?;
|
||||||
// We set this code_buf to be readable & executable
|
// We set this code_buf to be readable & executable
|
||||||
protect_codebuf(&code_buf);
|
protect_codebuf(&code_buf).unwrap();
|
||||||
|
|
||||||
let func_offset = code_buf;
|
let func_offset = code_buf;
|
||||||
functions.push(func_offset);
|
functions.push(func_offset);
|
||||||
@ -334,7 +334,7 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
for init in &module.info.data_initializers {
|
for init in &module.info.data_initializers {
|
||||||
debug_assert!(init.base.is_none(), "globalvar base not supported yet");
|
debug_assert!(init.base.is_none(), "globalvar base not supported yet");
|
||||||
let mut offset = init.offset;
|
let offset = init.offset;
|
||||||
let mem_mut = memories[init.memory_index].as_mut();
|
let mem_mut = memories[init.memory_index].as_mut();
|
||||||
let to_init = &mut mem_mut[offset..offset + init.data.len()];
|
let to_init = &mut mem_mut[offset..offset + init.data.len()];
|
||||||
to_init.copy_from_slice(&init.data);
|
to_init.copy_from_slice(&init.data);
|
||||||
@ -359,7 +359,7 @@ impl Instance {
|
|||||||
GlobalInit::I64Const(n) => n,
|
GlobalInit::I64Const(n) => n,
|
||||||
GlobalInit::F32Const(f) => f as _, // unsafe { mem::transmute(f as f64) },
|
GlobalInit::F32Const(f) => f as _, // unsafe { mem::transmute(f as f64) },
|
||||||
GlobalInit::F64Const(f) => f as _, // unsafe { mem::transmute(f) },
|
GlobalInit::F64Const(f) => f as _, // unsafe { mem::transmute(f) },
|
||||||
GlobalInit::GlobalRef(global_index) => {
|
GlobalInit::GlobalRef(_global_index) => {
|
||||||
unimplemented!("GlobalInit::GlobalRef is not yet supported")
|
unimplemented!("GlobalInit::GlobalRef is not yet supported")
|
||||||
}
|
}
|
||||||
GlobalInit::Import() => {
|
GlobalInit::Import() => {
|
||||||
@ -484,7 +484,7 @@ impl Clone for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn grow_memory(size: u32, memory_index: u32, vmctx: &mut VmCtx) -> i32 {
|
extern "C" fn grow_memory(size: u32, memory_index: u32, vmctx: &mut VmCtx) -> i32 {
|
||||||
let mut instance = &mut vmctx.user_data.instance;
|
let instance = &mut vmctx.user_data.instance;
|
||||||
instance
|
instance
|
||||||
.memory_mut(memory_index as usize)
|
.memory_mut(memory_index as usize)
|
||||||
.grow(size)
|
.grow(size)
|
||||||
|
@ -6,12 +6,9 @@ pub mod module;
|
|||||||
pub mod relocation;
|
pub mod relocation;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
use cranelift_native;
|
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::ptr;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::{Duration, Instant};
|
use target_lexicon;
|
||||||
use target_lexicon::{self, Triple};
|
|
||||||
use wasmparser;
|
use wasmparser;
|
||||||
|
|
||||||
pub use self::errors::{Error, ErrorKind};
|
pub use self::errors::{Error, ErrorKind};
|
||||||
@ -58,8 +55,8 @@ pub fn instantiate(
|
|||||||
/// a WebAssembly module directly from a streamed underlying source.
|
/// a WebAssembly module directly from a streamed underlying source.
|
||||||
/// This is the most efficient, optimized way to load wasm code.
|
/// This is the most efficient, optimized way to load wasm code.
|
||||||
pub fn instantiate_streaming(
|
pub fn instantiate_streaming(
|
||||||
buffer_source: Vec<u8>,
|
_buffer_source: Vec<u8>,
|
||||||
import_object: ImportObject<&str, &str>,
|
_import_object: ImportObject<&str, &str>,
|
||||||
) -> Result<ResultObject, ErrorKind> {
|
) -> Result<ResultObject, ErrorKind> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ use cranelift_codegen::cursor::FuncCursor;
|
|||||||
use cranelift_codegen::ir::immediates::{Imm64, Offset32};
|
use cranelift_codegen::ir::immediates::{Imm64, Offset32};
|
||||||
use cranelift_codegen::ir::types::*;
|
use cranelift_codegen::ir::types::*;
|
||||||
use cranelift_codegen::ir::{
|
use cranelift_codegen::ir::{
|
||||||
self, AbiParam, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, Function, InstBuilder,
|
self, AbiParam, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, InstBuilder, Signature,
|
||||||
Signature,
|
|
||||||
};
|
};
|
||||||
use cranelift_codegen::print_errors::pretty_verifier_error;
|
use cranelift_codegen::print_errors::pretty_verifier_error;
|
||||||
use cranelift_codegen::settings::CallConv;
|
use cranelift_codegen::settings::CallConv;
|
||||||
@ -244,9 +243,9 @@ impl Module {
|
|||||||
FuncEnvironment::new(&self.info) //, self.return_mode)
|
FuncEnvironment::new(&self.info) //, self.return_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn native_pointer(&self) -> ir::Type {
|
// fn native_pointer(&self) -> ir::Type {
|
||||||
self.func_env().pointer_type()
|
// self.func_env().pointer_type()
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// Convert a `DefinedFuncIndex` into a `FuncIndex`.
|
/// Convert a `DefinedFuncIndex` into a `FuncIndex`.
|
||||||
pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex {
|
pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex {
|
||||||
@ -293,12 +292,12 @@ impl<'environment> FuncEnvironment<'environment> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_real_call_args(func: &Function, call_args: &[ir::Value]) -> Vec<ir::Value> {
|
// fn get_real_call_args(func: &Function, call_args: &[ir::Value]) -> Vec<ir::Value> {
|
||||||
let mut real_call_args = Vec::with_capacity(call_args.len() + 1);
|
// let mut real_call_args = Vec::with_capacity(call_args.len() + 1);
|
||||||
real_call_args.extend_from_slice(call_args);
|
// real_call_args.extend_from_slice(call_args);
|
||||||
real_call_args.push(func.special_param(ArgumentPurpose::VMContext).unwrap());
|
// real_call_args.push(func.special_param(ArgumentPurpose::VMContext).unwrap());
|
||||||
real_call_args
|
// real_call_args
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Create a signature for `sigidx` amended with a `vmctx` argument after the standard wasm
|
// Create a signature for `sigidx` amended with a `vmctx` argument after the standard wasm
|
||||||
// arguments.
|
// arguments.
|
||||||
@ -562,7 +561,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
index: MemoryIndex,
|
index: MemoryIndex,
|
||||||
heap: ir::Heap,
|
_heap: ir::Heap,
|
||||||
val: ir::Value,
|
val: ir::Value,
|
||||||
) -> WasmResult<ir::Value> {
|
) -> WasmResult<ir::Value> {
|
||||||
debug_assert_eq!(index, 0, "non-default memories not supported yet");
|
debug_assert_eq!(index, 0, "non-default memories not supported yet");
|
||||||
@ -597,7 +596,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
index: MemoryIndex,
|
index: MemoryIndex,
|
||||||
heap: ir::Heap,
|
_heap: ir::Heap,
|
||||||
) -> WasmResult<ir::Value> {
|
) -> WasmResult<ir::Value> {
|
||||||
debug_assert_eq!(index, 0, "non-default memories not supported yet");
|
debug_assert_eq!(index, 0, "non-default memories not supported yet");
|
||||||
let cur_mem_func = self.mod_info.current_memory_extfunc.unwrap_or_else(|| {
|
let cur_mem_func = self.mod_info.current_memory_extfunc.unwrap_or_else(|| {
|
||||||
|
@ -6,7 +6,6 @@ use cranelift_codegen::binemit;
|
|||||||
use cranelift_codegen::ir::{self, ExternalName, LibCall, SourceLoc, TrapCode};
|
use cranelift_codegen::ir::{self, ExternalName, LibCall, SourceLoc, TrapCode};
|
||||||
|
|
||||||
pub use cranelift_codegen::binemit::Reloc;
|
pub use cranelift_codegen::binemit::Reloc;
|
||||||
use cranelift_wasm::FuncIndex;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Relocation {
|
pub struct Relocation {
|
||||||
|
Reference in New Issue
Block a user