Merge pull request #534 from sunfishcode/macro_use

Miscellaneous cleanups
This commit is contained in:
Dan Gohman
2019-11-08 20:42:12 -08:00
committed by GitHub
78 changed files with 243 additions and 354 deletions

View File

@@ -58,7 +58,10 @@ fn main() -> anyhow::Result<()> {
)
.expect("generating tests");
} else {
println!("cargo:warning=The spec testsuite is disabled. To enable, run `git submodule update --remote`.");
println!(
"cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
update --remote`."
);
}
writeln!(out, "}}")?;

View File

@@ -1,12 +1,10 @@
use crate::r#ref::HostRef;
use crate::runtime::Store;
use crate::trampoline::generate_func_export;
use crate::trap::Trap;
use crate::types::FuncType;
use crate::values::Val;
use alloc::rc::Rc;
use alloc::vec::Vec;
use crate::trampoline::generate_func_export;
use alloc::{rc::Rc, vec::Vec};
use cranelift_codegen::ir;
use wasmtime_jit::InstanceHandle;
use wasmtime_runtime::Export;

View File

@@ -1,10 +1,8 @@
use alloc::rc::Rc;
use core::cell::{RefCell, RefMut};
use core::hash::{Hash, Hasher};
use wasmtime_jit::{CompilationStrategy, Compiler, Features};
use cranelift_codegen::settings;
use wasmtime_jit::{CompilationStrategy, Compiler, Features};
#[derive(Clone)]
pub struct Context {

View File

@@ -4,14 +4,10 @@ use crate::module::Module;
use crate::r#ref::HostRef;
use crate::runtime::Store;
use crate::{HashMap, HashSet};
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{borrow::ToOwned, boxed::Box, rc::Rc, vec::Vec};
use anyhow::Result;
use core::cell::RefCell;
use wasmtime_jit::{instantiate, Resolver};
use wasmtime_runtime::{Export, InstanceHandle};

View File

@@ -16,7 +16,6 @@ mod values;
pub mod wasm;
#[macro_use]
extern crate alloc;
pub use crate::callable::Callable;

View File

@@ -4,11 +4,8 @@ use crate::types::{
ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability,
TableType, ValType,
};
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use alloc::{boxed::Box, string::String, vec::Vec};
use anyhow::Result;
use wasmparser::{validate, ExternalKind, ImportSectionEntryType, ModuleReader, SectionCode};
fn into_memory_type(mt: wasmparser::MemoryType) -> MemoryType {

View File

@@ -1,12 +1,8 @@
use crate::HashMap;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use core::cell::RefCell;
use crate::context::{create_compiler, Context};
use crate::r#ref::HostRef;
use crate::HashMap;
use alloc::{boxed::Box, rc::Rc, string::String};
use core::cell::RefCell;
use cranelift_codegen::{ir, settings};
use wasmtime_jit::{CompilationStrategy, Features};

View File

@@ -1,21 +1,18 @@
//! Support for a calling of an imported function.
use anyhow::Result;
use cranelift_entity::PrimaryMap;
use cranelift_wasm::DefinedFuncIndex;
//use target_lexicon::HOST;
use wasmtime_environ::Module;
use wasmtime_runtime::{Imports, InstanceHandle, VMFunctionBody};
use crate::runtime::Store;
use crate::{HashMap, HashSet};
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use alloc::vec::Vec;
use anyhow::Result;
use core::any::Any;
use core::cell::{RefCell, RefMut};
use crate::runtime::Store;
use cranelift_entity::PrimaryMap;
use cranelift_wasm::DefinedFuncIndex;
use wasmtime_environ::Module;
use wasmtime_runtime::{Imports, InstanceHandle, VMFunctionBody};
pub(crate) fn create_handle(
module: Module,

View File

@@ -1,11 +1,13 @@
//! Support for a calling of an imported function.
use super::create_handle::create_handle;
use crate::r#ref::HostRef;
use crate::{Callable, FuncType, Store, Trap, Val};
use alloc::{boxed::Box, rc::Rc, string::ToString, vec::Vec};
use anyhow::Result;
use cranelift_codegen::ir::types;
use cranelift_codegen::ir::{InstBuilder, StackSlotData, StackSlotKind, TrapCode};
use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir, isa};
use core::cmp;
use cranelift_codegen::ir::{types, InstBuilder, StackSlotData, StackSlotKind, TrapCode};
use cranelift_codegen::{binemit, ir, isa, Context};
use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_wasm::{DefinedFuncIndex, FuncIndex};
@@ -13,16 +15,6 @@ use wasmtime_environ::{CompiledFunction, Export, Module};
use wasmtime_jit::CodeMemory;
use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody};
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::ToString;
use alloc::vec::Vec;
use core::cmp;
use crate::{Callable, FuncType, Store, Trap, Val};
use super::create_handle::create_handle;
struct TrampolineState {
func: Rc<dyn Callable + 'static>,
trap: Option<HostRef<Trap>>,
@@ -58,7 +50,7 @@ unsafe extern "C" fn stub_fn(vmctx: *mut VMContext, call_id: u32, values_vec: *m
Ok(()) => {
for i in 0..returns_len {
// TODO check signature.returns[i].value_type ?
returns[i].write_value_to(values_vec.offset(i as isize));
returns[i].write_value_to(values_vec.add(i));
}
0
}

View File

@@ -1,12 +1,11 @@
use super::create_handle::create_handle;
use crate::{GlobalType, Mutability, Val};
use alloc::boxed::Box;
use anyhow::Result;
use cranelift_entity::PrimaryMap;
use wasmtime_environ::Module;
use wasmtime_runtime::{InstanceHandle, VMGlobalDefinition};
use super::create_handle::create_handle;
use crate::{GlobalType, Mutability, Val};
#[allow(dead_code)]
pub struct GlobalState {
definition: Box<VMGlobalDefinition>,

View File

@@ -1,3 +1,5 @@
use super::create_handle::create_handle;
use crate::MemoryType;
use alloc::boxed::Box;
use alloc::string::ToString;
use anyhow::Result;
@@ -5,9 +7,6 @@ use cranelift_entity::PrimaryMap;
use wasmtime_environ::Module;
use wasmtime_runtime::InstanceHandle;
use super::create_handle::create_handle;
use crate::MemoryType;
#[allow(dead_code)]
pub fn create_handle_with_memory(memory: &MemoryType) -> Result<InstanceHandle> {

View File

@@ -6,15 +6,14 @@ mod global;
mod memory;
mod table;
use crate::r#ref::HostRef;
use alloc::rc::Rc;
use anyhow::Result;
use self::func::create_handle_with_function;
use self::global::create_global;
use self::memory::create_handle_with_memory;
use self::table::create_handle_with_table;
use super::{Callable, FuncType, GlobalType, MemoryType, Store, TableType, Val};
use crate::r#ref::HostRef;
use alloc::rc::Rc;
use anyhow::Result;
pub use self::global::GlobalState;

View File

@@ -1,3 +1,5 @@
use super::create_handle::create_handle;
use crate::{TableType, ValType};
use alloc::boxed::Box;
use alloc::string::ToString;
use anyhow::Result;
@@ -6,9 +8,6 @@ use cranelift_wasm::TableElementType;
use wasmtime_environ::Module;
use wasmtime_runtime::InstanceHandle;
use super::create_handle::create_handle;
use crate::{TableType, ValType};
pub fn create_handle_with_table(table: &TableType) -> Result<InstanceHandle> {
let mut module = Module::new();

View File

@@ -3,7 +3,6 @@ use crate::r#ref::{AnyRef, HostRef};
use crate::runtime::Store;
use crate::types::ValType;
use core::ptr;
use cranelift_codegen::ir;
use wasmtime_jit::RuntimeValue;

View File

@@ -12,9 +12,7 @@ use super::{
};
use alloc::boxed::Box;
use alloc::rc::Rc;
use core::mem;
use core::ptr;
use core::slice;
use core::{mem, ptr, slice};
macro_rules! declare_vec {
($name:ident, $elem_ty:path) => {
@@ -460,13 +458,13 @@ pub unsafe extern "C" fn wasm_func_call(
let func = (*func).func.borrow();
let mut params = Vec::with_capacity(func.param_arity());
for i in 0..func.param_arity() {
let val = &(*args.offset(i as isize));
let val = &(*args.add(i));
params.push(val.val());
}
match func.call(&params) {
Ok(out) => {
for i in 0..func.result_arity() {
let val = &mut (*results.offset(i as isize));
let val = &mut (*results.add(i));
*val = wasm_val_t::from_val(&out[i]);
}
ptr::null_mut()
@@ -666,7 +664,7 @@ pub unsafe extern "C" fn wasm_instance_new(
let store = &(*store).store;
let mut externs: Vec<Extern> = Vec::with_capacity((*module).imports.len());
for i in 0..(*module).imports.len() {
let import = *imports.offset(i as isize);
let import = *imports.add(i);
externs.push((*import).ext.clone());
}
let module = &(*module).module;

View File

@@ -1,17 +1,12 @@
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use std::collections::HashMap;
use std::path::PathBuf;
use wasmparser::{self, ModuleReader, SectionCode};
use gimli;
use alloc::{boxed::Box, string::String, vec::Vec};
use gimli::{
DebugAbbrev, DebugAddr, DebugInfo, DebugLine, DebugLineStr, DebugLoc, DebugLocLists,
DebugRanges, DebugRngLists, DebugStr, DebugStrOffsets, DebugTypes, EndianSlice, LittleEndian,
LocationLists, RangeLists,
};
use std::collections::HashMap;
use std::path::PathBuf;
use wasmparser::{self, ModuleReader, SectionCode};
trait Reader: gimli::Reader<Offset = usize, Endian = LittleEndian> {}

View File

@@ -1,18 +1,14 @@
use crate::HashMap;
use alloc::vec::Vec;
use failure::Error;
use gimli;
use gimli::{AttributeValue, DebugLineOffset, DebugStr, DebuggingInformationEntry, UnitOffset};
use gimli::write;
use super::address_transform::AddressTransform;
use super::expression::{compile_expression, CompiledExpression, FunctionFrameInfo};
use super::range_info_builder::RangeInfoBuilder;
use super::unit::PendingDieRef;
use super::{DebugInputContext, Reader, TransformError};
use crate::HashMap;
use alloc::vec::Vec;
use failure::Error;
use gimli::{
write, AttributeValue, DebugLineOffset, DebugStr, DebuggingInformationEntry, UnitOffset,
};
pub(crate) enum FileAttributeContext<'a> {
Root(Option<DebugLineOffset>),

View File

@@ -7,8 +7,7 @@ use cranelift_codegen::ValueLabelsRanges;
use cranelift_entity::EntityRef;
use cranelift_wasm::{get_vmctx_value_label, DefinedFuncIndex};
use failure::Error;
use gimli::write;
use gimli::{self, Expression, Operation, Reader, ReaderOffset, Register, X86_64};
use gimli::{self, write, Expression, Operation, Reader, ReaderOffset, Register, X86_64};
use more_asserts::{assert_le, assert_lt};
#[derive(Debug)]

View File

@@ -6,9 +6,9 @@ use alloc::vec::Vec;
use core::iter::FromIterator;
use cranelift_entity::EntityRef;
use failure::Error;
use gimli;
use gimli::write;
use gimli::{DebugLine, DebugLineOffset, DebugStr, DebuggingInformationEntry, LineEncoding, Unit};
use gimli::{
write, DebugLine, DebugLineOffset, DebugStr, DebuggingInformationEntry, LineEncoding, Unit,
};
use more_asserts::assert_le;
#[derive(Debug)]

View File

@@ -1,24 +1,18 @@
use crate::gc::build_dependencies;
use crate::DebugInfoData;
use crate::HashSet;
use crate::{DebugInfoData, HashSet};
use cranelift_codegen::isa::TargetFrontendConfig;
use failure::Error;
use gimli::{
write, DebugAddr, DebugAddrBase, DebugLine, DebugStr, LocationLists, RangeLists,
UnitSectionOffset,
};
use simulate::generate_simulated_dwarf;
use thiserror::Error;
use unit::clone_unit;
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};
use gimli;
use gimli::{
DebugAddr, DebugAddrBase, DebugLine, DebugStr, LocationLists, RangeLists, UnitSectionOffset,
};
use gimli::write;
pub use address_transform::AddressTransform;
use unit::clone_unit;
mod address_transform;
mod attr;
mod expression;

View File

@@ -1,13 +1,10 @@
use super::address_transform::AddressTransform;
use super::DebugInputContext;
use super::Reader;
use super::{DebugInputContext, Reader};
use alloc::vec::Vec;
use cranelift_entity::EntityRef;
use cranelift_wasm::DefinedFuncIndex;
use failure::Error;
use gimli;
use gimli::write;
use gimli::{AttributeValue, DebuggingInformationEntry, RangeListsOffset};
use gimli::{write, AttributeValue, DebuggingInformationEntry, RangeListsOffset};
use more_asserts::assert_lt;
pub(crate) enum RangeInfoBuilder {

View File

@@ -1,20 +1,19 @@
use super::expression::{CompiledExpression, FunctionFrameInfo};
use super::utils::{add_internal_types, append_vmctx_info, get_function_frame_info};
use super::AddressTransform;
use crate::read_debuginfo::WasmFileInfo;
pub use crate::read_debuginfo::{DebugInfoData, FunctionMetadata, WasmType};
use crate::{HashMap, HashSet};
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_entity::EntityRef;
use cranelift_wasm::get_vmctx_value_label;
use failure::Error;
use gimli::write;
use gimli::{self, LineEncoding};
use std::path::PathBuf;
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};
use gimli::write;
use gimli::{self, LineEncoding};
use super::expression::{CompiledExpression, FunctionFrameInfo};
use super::utils::{add_internal_types, append_vmctx_info, get_function_frame_info};
use super::AddressTransform;
pub use crate::read_debuginfo::{DebugInfoData, FunctionMetadata, WasmType};
const PRODUCER_NAME: &str = "wasmtime";

View File

@@ -1,16 +1,3 @@
use crate::{HashMap, HashSet};
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_entity::EntityRef;
use failure::Error;
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};
use gimli;
use gimli::{AttributeValue, DebuggingInformationEntry, Unit, UnitOffset};
use gimli::write;
use super::address_transform::AddressTransform;
use super::attr::{clone_die_attributes, FileAttributeContext};
use super::expression::compile_expression;
@@ -18,6 +5,13 @@ use super::line_program::clone_line_program;
use super::range_info_builder::RangeInfoBuilder;
use super::utils::{add_internal_types, append_vmctx_info, get_function_frame_info};
use super::{DebugInputContext, Reader, TransformError};
use crate::{HashMap, HashSet};
use alloc::{string::String, vec::Vec};
use cranelift_entity::EntityRef;
use failure::Error;
use gimli::write;
use gimli::{AttributeValue, DebuggingInformationEntry, Unit, UnitOffset};
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};
pub(crate) type PendingDieRef = (write::UnitEntryId, gimli::DwAt, UnitOffset);

View File

@@ -1,13 +1,10 @@
use super::address_transform::AddressTransform;
use super::expression::{CompiledExpression, FunctionFrameInfo};
use alloc::vec::Vec;
use cranelift_wasm::DefinedFuncIndex;
use failure::Error;
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};
use gimli;
use gimli::write;
use super::address_transform::AddressTransform;
use super::expression::{CompiledExpression, FunctionFrameInfo};
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};
pub(crate) fn add_internal_types(
comp_unit: &mut write::Unit,

View File

@@ -1,11 +1,9 @@
use alloc::string::String;
use alloc::vec::Vec;
use gimli::write::{Address, Dwarf, EndianVec, Result, Sections, Writer};
use gimli::{RunTimeEndian, SectionId};
use alloc::{string::String, vec::Vec};
use core::result;
use faerie::artifact::{Decl, SectionKind};
use faerie::*;
use gimli::write::{Address, Dwarf, EndianVec, Result, Sections, Writer};
use gimli::{RunTimeEndian, SectionId};
#[derive(Clone)]
struct DebugReloc {

View File

@@ -265,7 +265,11 @@ impl WorkerThread {
let errno_val = errno::errno().0;
if errno_val != 0 {
warn!("Failed to lower worker thread priority. It might affect application performance. errno: {}", errno_val);
warn!(
"Failed to lower worker thread priority. It might affect application performance. \
errno: {}",
errno_val
);
} else {
debug!("New nice value of worker thread: {}", current_nice);
}
@@ -333,10 +337,7 @@ impl WorkerThread {
.ok()
})
.and_then(|cache_bytes| {
zstd::encode_all(
&cache_bytes[..],
opt_compr_lvl,
)
zstd::encode_all(&cache_bytes[..], opt_compr_lvl)
.map_err(|err| warn!("Failed to compress cached code: {}", err))
.ok()
})
@@ -379,21 +380,31 @@ impl WorkerThread {
// the cache file and the stats file (they are not updated together atomically)
// Possible solution is to use directories per cache entry, but it complicates the system
// and is not worth it.
debug!("DETECTED task did more than once (or race with new file): recompression of {}. \
Note: if optimized compression level setting has changed in the meantine, \
the stats file might contain inconsistent compression level due to race.", path.display());
}
else {
debug!(
"DETECTED task did more than once (or race with new file): \
recompression of {}. Note: if optimized compression level setting \
has changed in the meantine, the stats file might contain \
inconsistent compression level due to race.",
path.display()
);
} else {
new_stats.compression_level = opt_compr_lvl;
let _ = write_stats_file(stats_path.as_ref(), &new_stats);
}
if new_stats.usages < stats.usages {
debug!("DETECTED lower usage count (new file or race with counter increasing): file {}", path.display());
debug!(
"DETECTED lower usage count (new file or race with counter \
increasing): file {}",
path.display()
);
}
}
else {
debug!("Can't read stats file again to update compression level (it might got cleaned up): file {}", stats_path.display());
} else {
debug!(
"Can't read stats file again to update compression level (it might got \
cleaned up): file {}",
stats_path.display()
);
}
});
@@ -691,8 +702,12 @@ impl WorkerThread {
[file: stats_path],
unwrap_or!(
mod_metadata.modified(),
add_unrecognized_and!([file: stats_path, file: mod_path], continue),
"Failed to get mtime, deleting BOTH module cache and stats files",
add_unrecognized_and!(
[file: stats_path, file: mod_path],
continue
),
"Failed to get mtime, deleting BOTH module cache and stats \
files",
mod_path
)
),

View File

@@ -7,7 +7,6 @@
#![deny(missing_docs)]
#[macro_use]
extern crate alloc;
use alloc::boxed::Box;

View File

@@ -22,7 +22,6 @@
)
)]
#[macro_use]
extern crate alloc;
#[cfg(not(feature = "std"))]

View File

@@ -41,11 +41,11 @@ pub fn link_module(
if signature != *import_signature {
// TODO: If the difference is in the calling convention,
// we could emit a wrapper function to fix it up.
return Err(LinkError(
format!("{}/{}: incompatible import type: exported function with signature {} incompatible with function import with signature {}",
module_name, field,
signature, import_signature)
));
return Err(LinkError(format!(
"{}/{}: incompatible import type: exported function with signature {} \
incompatible with function import with signature {}",
module_name, field, signature, import_signature
)));
}
dependencies.insert(unsafe { InstanceHandle::from_vmctx(vmctx) });
function_imports.push(VMFunctionImport {
@@ -81,7 +81,8 @@ pub fn link_module(
let import_table = &module.table_plans[index];
if !is_table_compatible(&table, import_table) {
return Err(LinkError(format!(
"{}/{}: incompatible import type: exported table incompatible with table import",
"{}/{}: incompatible import type: exported table incompatible with \
table import",
module_name, field,
)));
}
@@ -119,7 +120,8 @@ pub fn link_module(
let import_memory = &module.memory_plans[index];
if !is_memory_compatible(&memory, import_memory) {
return Err(LinkError(format!(
"{}/{}: incompatible import type: exported memory incompatible with memory import",
"{}/{}: incompatible import type: exported memory incompatible with \
memory import",
module_name, field
)));
}
@@ -167,7 +169,8 @@ pub fn link_module(
Some(export_value) => match export_value {
Export::Table { .. } | Export::Memory { .. } | Export::Function { .. } => {
return Err(LinkError(format!(
"{}/{}: incompatible import type: exported global incompatible with global import",
"{}/{}: incompatible import type: exported global incompatible with \
global import",
module_name, field
)));
}
@@ -179,7 +182,8 @@ pub fn link_module(
let imported_global = module.globals[index];
if !is_global_compatible(&global, &imported_global) {
return Err(LinkError(format!(
"{}/{}: incompatible import type: exported global incompatible with global import",
"{}/{}: incompatible import type: exported global incompatible with \
global import",
module_name, field
)));
}
@@ -408,6 +412,6 @@ extern "C" {
pub fn __chkstk();
// ___chkstk (note the triple underscore) is implemented in compiler-builtins/src/x86_64.rs
// by the Rust compiler for the MinGW target
#[cfg(all(target_os = "windows", target_env = "gnu",))]
#[cfg(all(target_os = "windows", target_env = "gnu"))]
pub fn ___chkstk();
}

View File

@@ -162,7 +162,7 @@ Lightbeam passes 100% of the specification test suite, but that doesn't necessar
## Getting involved
Our [issue tracker][issue tracker] is pretty barren right now since this is currently more-or-less a one-person project, but if you want to get involved jump into the [CraneStation Gitter room][cranestation-gitter] and someone can direct you to the right place. I wish I could say "the most useful thing you can do is play with it and open issues where you find problems" but until it passes the spec suite that won't be very helpful.
You can file issues in the [Wasmtime issue tracker][issue tracker]. If you want to get involved jump into the [CraneStation Gitter room][cranestation-gitter] and someone can direct you to the right place. I wish I could say "the most useful thing you can do is play with it and open issues where you find problems" but until it passes the spec suite that won't be very helpful.
[cranestation-gitter]: https://gitter.im/CraneStation/Lobby
[issue tracker]: https://github.com/CraneStation/lightbeam/issues
[Wasmtime issue tracker]: https://github.com/CraneStation/wasmtime/issues

View File

@@ -1,5 +1,3 @@
extern crate lightbeam;
use lightbeam::translate;
use std::fs::File;
use std::io;

View File

@@ -173,7 +173,7 @@ where
actual_regs.mark_used(*gpr);
}
}
assert_eq!(actual_regs, ctx.block_state.regs,);
assert_eq!(actual_regs, ctx.block_state.regs);
}
};
}
@@ -486,7 +486,11 @@ where
if block.calling_convention.is_some() {
let new_cc = block.calling_convention.clone();
assert!(cc.is_none() || cc == new_cc, "Can't pass different params to different elements of `br_table` yet");
assert!(
cc.is_none() || cc == new_cc,
"Can't pass different params to different elements of `br_table` \
yet"
);
cc = new_cc;
}
@@ -500,22 +504,22 @@ where
.to_drop
.as_ref()
.map(|t| t.clone().count())
.unwrap_or_default() as u32
.unwrap_or_default() as u32,
);
}
let cc = cc.map(|cc| {
match cc {
let cc = cc
.map(|cc| match cc {
Left(cc) => Left(ctx.serialize_block_args(&cc, max_params)),
Right(cc) => Right(cc),
}
}).unwrap_or_else(||
})
.unwrap_or_else(|| {
if max_num_callers.map(|callers| callers <= 1).unwrap_or(false) {
Right(ctx.virtual_calling_convention())
} else {
Left(ctx.serialize_args(max_params))
}
);
});
for target in targets.iter().chain(std::iter::once(&default)).unique() {
let block = blocks.get_mut(&target.target).unwrap();

View File

@@ -1,19 +1,6 @@
#![cfg_attr(test, feature(test))]
#![feature(proc_macro_hygiene)]
#[macro_use]
extern crate smallvec;
extern crate capstone;
extern crate either;
pub extern crate wasmparser;
#[macro_use]
extern crate memoffset;
extern crate dynasm;
extern crate dynasmrt;
extern crate itertools;
// Just so we can implement `Signature` for `cranelift_codegen::ir::Signature`
extern crate cranelift_codegen;
extern crate multi_mut;
#[cfg(test)]
extern crate test;

View File

@@ -1,5 +1,5 @@
use crate::module::{ModuleContext, SigType, Signature};
use smallvec::SmallVec;
use smallvec::{smallvec, SmallVec};
use std::{
convert::TryInto,
fmt,

View File

@@ -7,6 +7,7 @@ use cranelift_codegen::{
ir::{self, AbiParam, Signature as CraneliftSignature},
isa,
};
use memoffset::offset_of;
use more_asserts::assert_le;
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};

View File

@@ -1,8 +1,6 @@
#[inline(never)]
#[no_mangle]
pub extern fn gcd(m_: u32, n_: u32) -> u32
{
pub extern "C" fn gcd(m_: u32, n_: u32) -> u32 {
let mut m = m_;
let mut n = n_;
while m > 0 {
@@ -14,6 +12,6 @@ pub extern fn gcd(m_: u32, n_: u32) -> u32
}
#[no_mangle]
pub extern fn test() -> u32 {
pub extern "C" fn test() -> u32 {
gcd(24, 9)
}

View File

@@ -1,4 +1,3 @@
extern "C" {
fn answer() -> u32;
}
@@ -8,7 +7,7 @@ extern "C" {
static mut PLACE: u32 = 23;
#[no_mangle]
pub extern fn bar() -> *const u32 {
pub extern "C" fn bar() -> *const u32 {
unsafe {
PLACE = answer();
// Return a pointer to the exported memory.

View File

@@ -2,14 +2,12 @@
extern crate alloc;
use pyo3::prelude::*;
use pyo3::types::PyTuple;
use crate::value::{pyobj_to_value, value_to_pyobj};
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::ir;
use pyo3::prelude::*;
use pyo3::types::PyTuple;
use wasmtime_interface_types::ModuleData;
use wasmtime_jit::{Context, InstanceHandle};
use wasmtime_runtime::Export;

View File

@@ -2,12 +2,12 @@
extern crate alloc;
use pyo3::prelude::*;
use pyo3::types::{PyAny, PyDict, PyTuple};
use crate::function::Function;
use crate::memory::Memory;
use crate::value::{read_value_from, write_value_to};
use alloc::rc::Rc;
use core::cell::RefCell;
use core::cmp;
use cranelift_codegen::ir::types;
use cranelift_codegen::ir::{InstBuilder, StackSlotData, StackSlotKind};
use cranelift_codegen::Context;
@@ -15,16 +15,14 @@ use cranelift_codegen::{binemit, ir, isa};
use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_wasm::{DefinedFuncIndex, FuncIndex};
use pyo3::prelude::*;
use pyo3::types::{PyAny, PyDict, PyTuple};
use std::collections::{HashMap, HashSet};
use target_lexicon::HOST;
use wasmtime_environ::{CompiledFunction, Export, Module};
use wasmtime_jit::CodeMemory;
use wasmtime_runtime::{Imports, InstanceHandle, VMContext, VMFunctionBody};
use alloc::rc::Rc;
use core::cell::RefCell;
use core::cmp;
use std::collections::{HashMap, HashSet};
struct BoundPyFunction {
name: String,
obj: PyObject,
@@ -71,12 +69,7 @@ unsafe extern "C" fn stub_fn(vmctx: *mut VMContext, call_id: u32, values_vec: *m
}
result.clone_ref(py)
};
write_value_to(
py,
values_vec.offset(i as isize),
signature.returns[i].value_type,
val,
);
write_value_to(py, values_vec.add(i), signature.returns[i].value_type, val);
}
}

View File

@@ -2,16 +2,13 @@
extern crate alloc;
use pyo3::prelude::*;
use pyo3::types::PyDict;
use crate::function::Function;
use crate::memory::Memory;
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::ir;
use cranelift_codegen::ir::types;
use cranelift_codegen::ir::{self, types};
use pyo3::prelude::*;
use pyo3::types::PyDict;
use wasmtime_environ::Export;
use wasmtime_interface_types::ModuleData;
use wasmtime_jit::{Context, InstanceHandle};

View File

@@ -1,13 +1,12 @@
use pyo3::exceptions::Exception;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict, PySet};
use pyo3::wrap_pyfunction;
use crate::import::into_instance_from_obj;
use crate::instance::Instance;
use crate::memory::Memory;
use crate::module::Module;
use core::cell::RefCell;
use pyo3::exceptions::Exception;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict, PySet};
use pyo3::wrap_pyfunction;
use std::rc::Rc;
use wasmtime_interface_types::ModuleData;

View File

@@ -2,17 +2,15 @@
extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::ptr;
use pyo3::class::PyBufferProtocol;
use pyo3::exceptions::BufferError;
use pyo3::ffi;
use pyo3::prelude::*;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::ptr;
use std::ffi::CStr;
use std::os::raw::{c_int, c_void};
use wasmtime_environ::MemoryPlan;
use wasmtime_jit::{Context, InstanceHandle};
use wasmtime_runtime::{Export, VMMemoryDefinition, VMMemoryImport};

View File

@@ -2,9 +2,8 @@
extern crate alloc;
use pyo3::prelude::*;
use alloc::rc::Rc;
use pyo3::prelude::*;
#[pyclass]
pub struct Module {

View File

@@ -1,11 +1,10 @@
//! Utility functions to handle values conversion between abstractions/targets.
use pyo3::exceptions::Exception;
use pyo3::prelude::*;
use pyo3::types::PyAny;
use core::ptr;
use cranelift_codegen::ir;
use pyo3::exceptions::Exception;
use pyo3::prelude::*;
use pyo3::types::PyAny;
use wasmtime_interface_types::Value;
pub fn pyobj_to_value(_: Python, p: &PyAny) -> PyResult<Value> {

View File

@@ -24,15 +24,13 @@ use core::any::Any;
use core::borrow::Borrow;
use core::cell::RefCell;
use core::convert::TryFrom;
use core::slice;
use core::{mem, ptr};
use cranelift_entity::EntityRef;
use cranelift_entity::{BoxedSlice, PrimaryMap};
use core::{mem, ptr, slice};
use cranelift_entity::{BoxedSlice, EntityRef, PrimaryMap};
use cranelift_wasm::{
DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex,
GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex,
};
use indexmap;
use memoffset::offset_of;
use more_asserts::assert_lt;
use thiserror::Error;
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};

View File

@@ -23,10 +23,6 @@
)]
#![cfg_attr(not(feature = "std"), no_std)]
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate memoffset;
extern crate alloc;
mod export;

View File

@@ -8,6 +8,7 @@ use crate::vmcontext::VMContext;
use crate::RwLock;
use core::borrow::{Borrow, BorrowMut};
use core::cell::Cell;
use lazy_static::lazy_static;
#[derive(Default)]
struct TrapContext {

View File

@@ -21,6 +21,7 @@ pub struct VMFunctionImport {
mod test_vmfunction_import {
use super::VMFunctionImport;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -76,6 +77,7 @@ pub struct VMTableImport {
mod test_vmtable_import {
use super::VMTableImport;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -113,6 +115,7 @@ pub struct VMMemoryImport {
mod test_vmmemory_import {
use super::VMMemoryImport;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -147,6 +150,7 @@ pub struct VMGlobalImport {
mod test_vmglobal_import {
use super::VMGlobalImport;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -181,6 +185,7 @@ pub struct VMMemoryDefinition {
mod test_vmmemory_definition {
use super::VMMemoryDefinition;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -224,6 +229,7 @@ pub struct VMTableDefinition {
mod test_vmtable_definition {
use super::VMTableDefinition;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -480,6 +486,7 @@ pub struct VMCallerCheckedAnyfunc {
mod test_vmcaller_checked_anyfunc {
use super::VMCallerCheckedAnyfunc;
use core::mem::size_of;
use memoffset::offset_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]

View File

@@ -1,6 +1,3 @@
extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::env;
use std::path::PathBuf;

View File

@@ -146,11 +146,8 @@ pub fn instantiate_wasi_c(
let mut wasm_fd = 3;
for (dir, file) in preopened_dirs {
assert!(fd_table_insert_existing(curfds, wasm_fd, file.as_raw_fd()));
assert!(fd_prestats_insert(
prestats,
CString::new(dir.as_str()).unwrap().as_ptr(),
wasm_fd,
));
let dir_cstr = CString::new(dir.as_str()).unwrap();
assert!(fd_prestats_insert(prestats, dir_cstr.as_ptr(), wasm_fd));
wasm_fd += 1;
}
}

View File

@@ -1,5 +1,3 @@
#[macro_use]
extern crate log;
extern crate alloc;
extern crate core;

View File

@@ -1,10 +1,10 @@
use crate::host;
use crate::host::{argv_environ_values, fd_prestats, fd_table};
use crate::instantiate::WASIState;
use crate::translate::*;
use crate::wasm32;
use crate::{host, wasm32};
use core::convert::TryFrom;
use cranelift_codegen::ir::types::{Type, I32, I64};
use log::{log_enabled, trace};
use std::{mem, ptr, slice, str};
use wasmtime_runtime::VMContext;

View File

@@ -1,6 +1,6 @@
use crate::host;
use crate::wasm32;
use crate::{host, wasm32};
use core::convert::TryFrom;
use log::{debug, error};
use more_asserts::assert_le;
use std::mem::{align_of, size_of, zeroed};
use std::slice;

View File

@@ -2,9 +2,8 @@
#![allow(clippy::use_self)]
use crate::wasi;
use std::convert::Infallible;
use std::fmt;
use std::num::TryFromIntError;
use std::str;
use std::{fmt, str};
use thiserror::Error;
#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)]

View File

@@ -2,7 +2,6 @@
use crate::ctx::WasiCtx;
use crate::{wasi, wasi32};
use log::trace;
use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]

View File

@@ -181,7 +181,7 @@ pub(crate) fn enc_slice_of_wasi32_uintptr(
}
macro_rules! dec_enc_scalar {
( $ty:ident, $dec_byref:ident, $enc_byref:ident) => {
($ty:ident, $dec_byref:ident, $enc_byref:ident) => {
pub(crate) fn $dec_byref(memory: &mut [u8], ptr: wasi32::uintptr_t) -> Result<wasi::$ty> {
dec_int_byref::<wasi::$ty>(memory, ptr)
}

View File

@@ -6,9 +6,8 @@
#![allow(non_snake_case)]
#![allow(dead_code)]
use wig::witx_wasi32_types;
use crate::wasi::*;
use wig::witx_wasi32_types;
pub type uintptr_t = u32;
pub type size_t = u32;

View File

@@ -1,5 +1,3 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]

View File

@@ -1,5 +1,3 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]

View File

@@ -1,5 +1,3 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]

View File

@@ -1,5 +1,3 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]

View File

@@ -1,5 +1,3 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]

View File

@@ -1,7 +1,4 @@
extern crate proc_macro;
extern crate proc_macro2;
extern crate quote;
extern crate witx;
mod raw_types;
mod utils;

View File

@@ -1,5 +1,6 @@
#![allow(non_camel_case_types)]
use crate::{winerror, Result};
use bitflags::bitflags;
use cvt::cvt;
use std::ffi::{c_void, OsString};
use std::fs::File;

View File

@@ -21,9 +21,6 @@
)]
#![cfg(windows)]
#[macro_use]
extern crate bitflags;
pub mod file;
pub mod time;
pub mod winerror;

View File

@@ -9,8 +9,8 @@ publish = false
cargo-fuzz = true
[dependencies]
wasmtime-environ = { path = "../wasmtime-environ" }
wasmtime-jit = { path = "../wasmtime-jit" }
wasmtime-environ = { path = "../crates/environ" }
wasmtime-jit = { path = "../crates/jit" }
cranelift-codegen = { version = "0.49", features = ["enable-serde"] }
cranelift-wasm = { version = "0.49", features = ["enable-serde"] }
cranelift-native = "0.49"

View File

@@ -1,13 +1,13 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate alloc;
extern crate core;
extern crate libfuzzer_sys;
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::settings;
use libfuzzer_sys::fuzz_target;
use std::collections::HashMap;
use wasmparser::validate;
use wasmtime_jit::{CompilationStrategy, CompiledModule, Compiler, NullResolver};

View File

@@ -1,14 +1,9 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate cranelift_codegen;
extern crate cranelift_native;
extern crate wasmparser;
extern crate wasmtime_environ;
extern crate wasmtime_jit;
use cranelift_codegen::settings;
use libfuzzer_sys::fuzz_target;
use wasmparser::validate;
use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver};

View File

@@ -1,14 +1,9 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate cranelift_codegen;
extern crate cranelift_native;
extern crate wasmparser;
extern crate wasmtime_environ;
extern crate wasmtime_jit;
use cranelift_codegen::settings;
use libfuzzer_sys::fuzz_target;
use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver};
fuzz_target!(|data: &[u8]| {

View File

@@ -29,11 +29,9 @@
)
)]
use cranelift_codegen::isa;
use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_codegen::{isa, settings};
use cranelift_entity::EntityRef;
use cranelift_native;
use cranelift_wasm::DefinedMemoryIndex;
use docopt::Docopt;
use faerie::Artifact;
@@ -41,21 +39,18 @@ use serde::Deserialize;
use std::error::Error;
use std::fmt::format;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use std::str;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{io, process, str};
use target_lexicon::Triple;
use wasmtime_cli::pick_compilation_strategy;
use wasmtime_debug::{emit_debugsections, read_debuginfo};
#[cfg(feature = "lightbeam")]
use wasmtime_environ::Lightbeam;
use wasmtime_environ::{cache_create_new_config, cache_init};
use wasmtime_environ::{
Compiler, Cranelift, ModuleEnvironment, ModuleVmctxInfo, Tunables, VMOffsets,
cache_create_new_config, cache_init, Compiler, Cranelift, ModuleEnvironment, ModuleVmctxInfo,
Tunables, VMOffsets,
};
use wasmtime_jit::CompilationStrategy;
use wasmtime_obj::emit_module;
@@ -67,7 +62,8 @@ The translation is dependent on the environment chosen.
The default is a dummy environment that produces placeholder values.
Usage:
wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=<cache_config_file>] [--enable-simd] [--lightbeam | --cranelift] <file> -o <output>
wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=<cache_config_file>] \
[--enable-simd] [--lightbeam | --cranelift] <file> -o <output>
wasm2obj --create-cache-config [--cache-config=<cache_config_file>]
wasm2obj --help | --version

View File

@@ -34,13 +34,11 @@ use anyhow::{bail, Context as _, Result};
use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use docopt::Docopt;
use pretty_env_logger;
use serde::Deserialize;
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fs::File;
use std::path::Component;
use std::path::Path;
use std::path::{Component, Path};
use std::process::exit;
use wasi_common::preopen_dir;
use wasmtime_api::{Config, Engine, HostRef, Instance, Module, Store};
@@ -49,10 +47,9 @@ use wasmtime_environ::{cache_create_new_config, cache_init};
use wasmtime_interface_types::ModuleData;
use wasmtime_jit::Features;
use wasmtime_wasi::instantiate_wasi;
use wasmtime_wast::instantiate_spectest;
#[cfg(feature = "wasi-c")]
use wasmtime_wasi_c::instantiate_wasi_c;
use wasmtime_wast::instantiate_spectest;
const USAGE: &str = "
Wasm runner.
@@ -62,8 +59,12 @@ including calling the start function if one is present. Additional functions
given with --invoke are then called.
Usage:
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] [--lightbeam | --cranelift] <file> [<arg>...]
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> [--lightbeam | --cranelift] <file> [<arg>...]
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | \
--cache-config=<cache_config_file>] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] \
[--mapdir=<mapping>...] [--lightbeam | --cranelift] <file> [<arg>...]
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | \
--cache-config=<cache_config_file>] [--env=<env>...] [--dir=<dir>...] \
[--mapdir=<mapping>...] --invoke=<fn> [--lightbeam | --cranelift] <file> [<arg>...]
wasmtime --create-cache-config [--cache-config=<cache_config_file>]
wasmtime --help | --version
@@ -128,7 +129,10 @@ fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(Str
for mapdir in flag_mapdir {
let parts: Vec<&str> = mapdir.split("::").collect();
if parts.len() != 2 {
println!("--mapdir argument must contain exactly one double colon ('::'), separating a guest directory name and a host directory name");
println!(
"--mapdir argument must contain exactly one double colon ('::'), separating a \
guest directory name and a host directory name"
);
exit(1);
}
let (key, value) = (parts[0], parts[1]);

View File

@@ -42,7 +42,8 @@ const USAGE: &str = "
Wast test runner.
Usage:
wast [-do] [--enable-simd] [--disable-cache | --cache-config=<cache_config_file>] [--lightbeam | --cranelift] <file>...
wast [-do] [--enable-simd] [--disable-cache | --cache-config=<cache_config_file>] [--lightbeam \
| --cranelift] <file>...
wast --create-cache-config [--cache-config=<cache_config_file>]
wast --help | --version

View File

@@ -1,8 +1,5 @@
use cranelift_native;
use cranelift_codegen::isa;
use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_codegen::{isa, settings};
use std::path::Path;
use wasmtime_jit::{CompilationStrategy, Compiler, Features};
use wasmtime_wast::WastContext;