diff --git a/Cargo.toml b/Cargo.toml index 4dd40d78..9246314c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,8 @@ edition = "2018" [dependencies] flexi_logger = "0.14.4" +# FIXME: Migrate +# inkwell = { git = "https://github.com/TheDan64/inkwell.git", branch = "llvm10-0" } llvm-alt = { git = "https://github.com/gwsystems/llvm-rs", branch = "sfbase"} log = "0.4.8" structopt = "0.3.2" diff --git a/runtime/libc/wasmception_backing.c b/runtime/libc/wasmception_backing.c index f64a5014..b141cf66 100644 --- a/runtime/libc/wasmception_backing.c +++ b/runtime/libc/wasmception_backing.c @@ -440,7 +440,7 @@ i32 wasm_writev(i32 fd, i32 iov_offset, i32 iovcnt) { i32 len = iov[i].len; void* ptr = get_memory_ptr_void(iov[i].base_offset, len); - printf("%.*s", len, ptr); + printf("%.*s", len, (char*) ptr); sum += len; } return sum; diff --git a/src/codegen/block.rs b/src/codegen/block.rs index 382272c8..db290e0d 100644 --- a/src/codegen/block.rs +++ b/src/codegen/block.rs @@ -282,7 +282,8 @@ pub fn compile_block<'a, 'b>( &[table_index, type_index.compile(m_ctx.llvm_ctx)], ); // Then cast it from a void pointer to a function pointer - let f_type = PointerType::new(wasm_func_type_to_llvm_type(m_ctx.llvm_ctx, f_type)); + let f_type = + PointerType::new(wasm_func_type_to_llvm_type(m_ctx.llvm_ctx, f_type).itype()); let f_ptr = b.build_bit_cast(f_ptr_as_void, f_type); let result = b.build_value_call(f_ptr, &args); diff --git a/src/codegen/breakout.rs b/src/codegen/breakout.rs index c506433d..2f155025 100644 --- a/src/codegen/breakout.rs +++ b/src/codegen/breakout.rs @@ -34,7 +34,10 @@ impl<'a> BreakoutTarget<'a> { } } - pub fn new_wrapped(bb: &'a BasicBlock, result_type: Option) -> WBreakoutTarget<'a> { + pub fn new_wrapped( + bb: &'a BasicBlock, + result_type: Option, + ) -> WBreakoutTarget<'a> { let bt = Self::new(bb, result_type); Rc::new(RefCell::new(bt)) } @@ -68,7 +71,7 @@ impl<'a> BreakoutTarget<'a> { // We probably should emit an unreachable instruction in this case, but that might mess up future compilation // Instead we just produce zeroes, and hope llvm notices this is unreachable code // TODO: Figure out if we can instead produce an unreachable result - new_locals.push(llvm_type_to_zeroed_value(ctx, local_type)); + new_locals.push(llvm_type_to_zeroed_value(ctx, local_type).ivalue()); } else if jump_back_count == 1 { new_locals.push(jump_back_values[i][0].1); } else if !jump_back_values[i].is_empty() { @@ -79,6 +82,7 @@ impl<'a> BreakoutTarget<'a> { new_locals } + #[allow(clippy::needless_range_loop)] pub fn modify_phis<'b>(&self, phi_instructions: &[&'b Value]) where 'a: 'b, @@ -113,7 +117,7 @@ impl<'a> BreakoutTarget<'a> { // See above comment about unreachablity // TODO: Figure out if we can instead produce an unreachable result if let TypeOrFuncType::Type(t) = ty { - wasm_type_to_zeroed_value(ctx, t) + wasm_type_to_zeroed_value(ctx, t).ivalue() } else { panic!() } diff --git a/src/codegen/function.rs b/src/codegen/function.rs index e035805f..c88a1182 100644 --- a/src/codegen/function.rs +++ b/src/codegen/function.rs @@ -3,10 +3,10 @@ use std::ffi::CString; use std::mem; use std::sync::atomic::{AtomicBool, Ordering}; -use llvm::{BasicBlock, Sub}; use llvm::Builder; use llvm::Function; use llvm::Value; +use llvm::{BasicBlock, Sub}; use wasmparser::TypeOrFuncType; @@ -48,12 +48,7 @@ unsafe fn add_string_attr(k: &str, v: &str, v_ref: *mut llvm::ffi::LLVMValue, ct target_features_value.as_bytes().len() as u32, ); - crate::llvm_externs::LLVMAddAttributeAtIndex( - v_ref, - idx, - attr_ref - ); - + crate::llvm_externs::LLVMAddAttributeAtIndex(v_ref, idx, attr_ref); } // HACK: We only want to emit a note about the cortex-m override once @@ -96,13 +91,16 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) { let llvm_ctx: *mut llvm::ffi::LLVMContext = mem::transmute(ctx.llvm_ctx as &llvm::Context); let nounwind = CString::new("nounwind").unwrap(); - let kind = crate::llvm_externs::LLVMGetEnumAttributeKindForName(nounwind.as_ptr(), nounwind.as_bytes().len()); + let kind = crate::llvm_externs::LLVMGetEnumAttributeKindForName( + nounwind.as_ptr(), + nounwind.as_bytes().len(), + ); let attr_ref = crate::llvm_externs::LLVMCreateEnumAttribute(llvm_ctx, kind, 0); crate::llvm_externs::LLVMAddAttributeAtIndex( v_ref, crate::llvm_externs::LLVMAttributeFunctionIndex, - attr_ref + attr_ref, ); if cm_override { if !CORTEX_OVERRIDE_MESSAGE_SENT.load(Ordering::Relaxed) { @@ -112,75 +110,25 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) { CORTEX_OVERRIDE_MESSAGE_SENT.store(true, Ordering::Relaxed); } - add_string_attr( - "correctly-rounded-divide-sqrt-fp-math", - "false", - v_ref, - ctx - ); + add_string_attr("correctly-rounded-divide-sqrt-fp-math", "false", v_ref, ctx); - add_string_attr( - "disable-tail-calls", - "false", - v_ref, - ctx - ); + add_string_attr("disable-tail-calls", "false", v_ref, ctx); - add_string_attr( - "less-precise-fpmad", - "false", - v_ref, - ctx - ); + add_string_attr("less-precise-fpmad", "false", v_ref, ctx); - add_string_attr( - "min-legal-vector-width", - "0", - v_ref, - ctx - ); + add_string_attr("min-legal-vector-width", "0", v_ref, ctx); - add_string_attr( - "no-frame-pointer-elim", - "false", - v_ref, - ctx - ); + add_string_attr("no-frame-pointer-elim", "false", v_ref, ctx); - add_string_attr( - "no-infs-fp-math", - "false", - v_ref, - ctx - ); + add_string_attr("no-infs-fp-math", "false", v_ref, ctx); - add_string_attr( - "no-jump-tables", - "false", - v_ref, - ctx - ); + add_string_attr("no-jump-tables", "false", v_ref, ctx); - add_string_attr( - "no-nans-fp-math", - "false", - v_ref, - ctx - ); + add_string_attr("no-nans-fp-math", "false", v_ref, ctx); - add_string_attr( - "no-signed-zeros-fp-math", - "false", - v_ref, - ctx - ); + add_string_attr("no-signed-zeros-fp-math", "false", v_ref, ctx); - add_string_attr( - "no-trapping-math", - "false", - v_ref, - ctx - ); + add_string_attr("no-trapping-math", "false", v_ref, ctx); // add_string_attr( // "stack-protector-buffer-size", @@ -189,27 +137,11 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) { // ctx // ); - add_string_attr( - "target-cpu", - "cortex-m7", - v_ref, - ctx - ); - - add_string_attr( - "unsafe-fp-math", - "false", - v_ref, - ctx - ); + add_string_attr("target-cpu", "cortex-m7", v_ref, ctx); - add_string_attr( - "use-soft-float", - "false", - v_ref, - ctx - ); + add_string_attr("unsafe-fp-math", "false", v_ref, ctx); + add_string_attr("use-soft-float", "false", v_ref, ctx); add_string_attr( "target-features", @@ -227,7 +159,7 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) { } // Then the actual locals for local in &f.locals { - locals.push(wasm_type_to_zeroed_value(ctx.llvm_ctx, *local)); + locals.push(wasm_type_to_zeroed_value(ctx.llvm_ctx, *local).ivalue()); } let builder = &*Builder::new(ctx.llvm_ctx); @@ -242,7 +174,10 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) { }; let termination_block = llvm_f.append("exit"); - let root_breakout_target = BreakoutTarget::new_wrapped(termination_block, f.get_return_type().map(TypeOrFuncType::Type)); + let root_breakout_target = BreakoutTarget::new_wrapped( + termination_block, + f.get_return_type().map(TypeOrFuncType::Type), + ); // In WASM, a break out of the root block is the same as returning from the function // Thus the termination block needs to do that diff --git a/src/codegen/globals.rs b/src/codegen/globals.rs index 7eea3913..be9dc30c 100644 --- a/src/codegen/globals.rs +++ b/src/codegen/globals.rs @@ -12,10 +12,10 @@ use crate::wasm::Global; use crate::wasm::Instruction; use crate::Opt; -use crate::codegen::ModuleCtx; use crate::codegen::runtime_stubs::*; use crate::codegen::type_conversions::llvm_type_to_wasm_type; use crate::codegen::type_conversions::wasm_type_to_llvm_type; +use crate::codegen::ModuleCtx; pub enum GlobalValue<'a> { InlinedConstant(&'a Value), @@ -85,8 +85,10 @@ fn insert_native_globals<'a>( content_type, mutable, } => { - let llvm_global = - llvm_module.add_global(&name, wasm_type_to_llvm_type(&*llvm_ctx, content_type)); + let llvm_global = llvm_module.add_global( + &name, + wasm_type_to_llvm_type(&*llvm_ctx, content_type).itype(), + ); llvm_global.set_constant(!mutable); GlobalValue::Native(llvm_global.to_super()) } diff --git a/src/codegen/llvm_wrapper/llvm_type.rs b/src/codegen/llvm_wrapper/llvm_type.rs new file mode 100644 index 00000000..da510d00 --- /dev/null +++ b/src/codegen/llvm_wrapper/llvm_type.rs @@ -0,0 +1,77 @@ +use llvm::Compile; +use llvm::Type; + +#[derive(Clone)] +pub struct BasicType<'a> { + ty: &'a Type, +} + +impl<'a> BasicType<'a> { + pub fn void_ty<'b: 'a>(ctx: &'b llvm::Context) -> Self { + Self { + ty: <()>::get_type(ctx), + } + } + + pub fn i32_ty<'b: 'a>(ctx: &'b llvm::Context) -> Self { + Self { + ty: ::get_type(ctx), + } + } + + pub fn i64_ty<'b: 'a>(ctx: &'b llvm::Context) -> Self { + Self { + ty: ::get_type(ctx), + } + } + + pub fn f32_ty<'b: 'a>(ctx: &'b llvm::Context) -> Self { + Self { + ty: ::get_type(ctx), + } + } + + pub fn f64_ty<'b: 'a>(ctx: &'b llvm::Context) -> Self { + Self { + ty: ::get_type(ctx), + } + } + + pub fn itype(&self) -> &'a Type { + self.ty + } +} + +#[derive(Clone)] +pub struct FunctionType<'a> { + ty: &'a Type, +} + +impl<'a> FunctionType<'a> { + pub fn new<'b: 'a, 'c: 'a>( + _ctx: &'b llvm::Context, + params: &[BasicType<'c>], + res: BasicType<'c>, + ) -> Self { + let mut wrapped_params = Vec::new(); + wrapped_params.extend(params.iter().map(BasicType::itype)); + + let ty = llvm::FunctionType::new(res.itype(), &wrapped_params); + + Self { ty } + } + + #[allow(dead_code)] + pub fn new_ret_void<'b: 'a, 'c: 'a>(ctx: &'b llvm::Context, params: &[BasicType<'c>]) -> Self { + let mut wrapped_params = Vec::new(); + wrapped_params.extend(params.iter().map(BasicType::itype)); + + let ty = llvm::FunctionType::new(BasicType::void_ty(ctx).itype(), &wrapped_params); + + Self { ty } + } + + pub fn itype(&self) -> &'a Type { + self.ty + } +} diff --git a/src/codegen/llvm_wrapper/llvm_value.rs b/src/codegen/llvm_wrapper/llvm_value.rs new file mode 100644 index 00000000..77e97ddc --- /dev/null +++ b/src/codegen/llvm_wrapper/llvm_value.rs @@ -0,0 +1,37 @@ +use llvm::Compile; +use llvm::Context; +use llvm::Value; + +pub struct BasicValue<'a> { + v: &'a Value, +} + +impl<'a> BasicValue<'a> { + pub fn i32_zero<'b: 'a>(ctx: &'b Context) -> Self { + Self { + v: 0i32.compile(ctx), + } + } + + pub fn i64_zero<'b: 'a>(ctx: &'b Context) -> Self { + Self { + v: 0i64.compile(ctx), + } + } + + pub fn f32_zero<'b: 'a>(ctx: &'b Context) -> Self { + Self { + v: 0f32.compile(ctx), + } + } + + pub fn f64_zero<'b: 'a>(ctx: &'b Context) -> Self { + Self { + v: 0f64.compile(ctx), + } + } + + pub fn ivalue(&self) -> &'a Value { + self.v + } +} diff --git a/src/codegen/llvm_wrapper/mod.rs b/src/codegen/llvm_wrapper/mod.rs new file mode 100644 index 00000000..2890dec6 --- /dev/null +++ b/src/codegen/llvm_wrapper/mod.rs @@ -0,0 +1,5 @@ +mod llvm_type; +pub use llvm_type::*; + +mod llvm_value; +pub use llvm_value::*; diff --git a/src/codegen/memory.rs b/src/codegen/memory.rs index d229476a..689c7723 100644 --- a/src/codegen/memory.rs +++ b/src/codegen/memory.rs @@ -11,9 +11,9 @@ use crate::wasm::DataInitializer; use crate::wasm::ImplementedFunction; use crate::wasm::Instruction; -use crate::codegen::ModuleCtx; use crate::codegen::function::compile_function; use crate::codegen::type_conversions::wasm_func_type_to_llvm_type; +use crate::codegen::ModuleCtx; // We add in globals to tell the runtime how much memory to allocate and startup // (And what the max amount of allocated memory should be) @@ -100,7 +100,7 @@ pub fn generate_offset_function<'a>( // Compile function assumes the function is already prototyped let offset_func = ctx.llvm_module.add_function( &offset_func_name, - wasm_func_type_to_llvm_type(ctx.llvm_ctx, &offset_func_type), + wasm_func_type_to_llvm_type(ctx.llvm_ctx, &offset_func_type).itype(), ); compile_function( diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index b473db55..679e8582 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -23,6 +23,8 @@ mod globals; use self::globals::insert_globals; use self::globals::GlobalValue; +mod llvm_wrapper; + mod memory; use self::memory::add_memory_size_globals; use self::memory::generate_memory_initialization_stub; @@ -86,7 +88,7 @@ pub fn process_to_llvm( for f in &wasm_module.functions { let llvm_f = llvm_module.add_function( f.get_name(), - wasm_func_type_to_llvm_type(&llvm_ctx, f.get_type()), + wasm_func_type_to_llvm_type(&llvm_ctx, f.get_type()).itype(), ); functions.push((&*llvm_f, f.clone())); } diff --git a/src/codegen/table.rs b/src/codegen/table.rs index 1c99d82a..843f115c 100644 --- a/src/codegen/table.rs +++ b/src/codegen/table.rs @@ -6,8 +6,8 @@ use llvm::Sub; use crate::wasm::TableInitializer; -use crate::codegen::ModuleCtx; use crate::codegen::memory::generate_offset_function; +use crate::codegen::ModuleCtx; use crate::codegen::runtime_stubs::*; diff --git a/src/codegen/type_conversions.rs b/src/codegen/type_conversions.rs index 9b555413..6156592a 100644 --- a/src/codegen/type_conversions.rs +++ b/src/codegen/type_conversions.rs @@ -1,30 +1,31 @@ use std::ptr; use llvm::ffi::prelude::LLVMTypeRef; -use llvm::Compile; use llvm::Context; -use llvm::Sub; + +use crate::codegen::llvm_wrapper::{BasicType, BasicValue, FunctionType}; pub fn llvm_type_to_wasm_type(ctx: &Context, ty: &llvm::Type) -> wasmparser::Type { + // FIXME: Move this to the `llvm_wrapper` let ty_ref: LLVMTypeRef = ty.into(); // In llvm, types have a canonical pointer, so we can compare that way - let i32_ref: LLVMTypeRef = ::get_type(ctx).into(); + let i32_ref: LLVMTypeRef = BasicType::i32_ty(ctx).itype().into(); if ptr::eq(ty_ref, i32_ref) { return wasmparser::Type::I32; } - let i64_ref: LLVMTypeRef = ::get_type(ctx).into(); + let i64_ref: LLVMTypeRef = BasicType::i64_ty(ctx).itype().into(); if ptr::eq(ty_ref, i64_ref) { return wasmparser::Type::I64; } - let f32_ref: LLVMTypeRef = ::get_type(ctx).into(); + let f32_ref: LLVMTypeRef = BasicType::f32_ty(ctx).itype().into(); if ptr::eq(ty_ref, f32_ref) { return wasmparser::Type::F32; } - let f64_ref: LLVMTypeRef = ::get_type(ctx).into(); + let f64_ref: LLVMTypeRef = BasicType::f64_ty(ctx).itype().into(); if ptr::eq(ty_ref, f64_ref) { return wasmparser::Type::F64; } @@ -32,27 +33,27 @@ pub fn llvm_type_to_wasm_type(ctx: &Context, ty: &llvm::Type) -> wasmparser::Typ panic!("llvm type {:?} does not have a wasm representation", ty); } -pub fn llvm_type_to_zeroed_value<'a>(ctx: &'a Context, ty: &'a llvm::Type) -> &'a llvm::Value { +pub fn llvm_type_to_zeroed_value<'a>(ctx: &'a Context, ty: &'a llvm::Type) -> BasicValue<'a> { let wasm_type = llvm_type_to_wasm_type(ctx, ty); wasm_type_to_zeroed_value(ctx, wasm_type) } -pub fn wasm_type_to_llvm_type(ctx: &Context, wasm_type: wasmparser::Type) -> &llvm::Type { +pub fn wasm_type_to_llvm_type(ctx: &Context, wasm_type: wasmparser::Type) -> BasicType { match wasm_type { - wasmparser::Type::I32 => ::get_type(ctx), - wasmparser::Type::I64 => ::get_type(ctx), - wasmparser::Type::F32 => ::get_type(ctx), - wasmparser::Type::F64 => ::get_type(ctx), + wasmparser::Type::I32 => BasicType::i32_ty(ctx), + wasmparser::Type::I64 => BasicType::i64_ty(ctx), + wasmparser::Type::F32 => BasicType::f32_ty(ctx), + wasmparser::Type::F64 => BasicType::f64_ty(ctx), e => panic!("wasm type {:?} does not have a llvm representation", e), } } -pub fn wasm_type_to_zeroed_value(ctx: &Context, wasm_type: wasmparser::Type) -> &llvm::Value { +pub fn wasm_type_to_zeroed_value(ctx: &Context, wasm_type: wasmparser::Type) -> BasicValue { match wasm_type { - wasmparser::Type::I32 => 0i32.compile(ctx), - wasmparser::Type::I64 => 0i64.compile(ctx), - wasmparser::Type::F32 => 0f32.compile(ctx), - wasmparser::Type::F64 => 0f64.compile(ctx), + wasmparser::Type::I32 => BasicValue::i32_zero(ctx), + wasmparser::Type::I64 => BasicValue::i64_zero(ctx), + wasmparser::Type::F32 => BasicValue::f32_zero(ctx), + wasmparser::Type::F64 => BasicValue::f64_zero(ctx), e => panic!("wasm type {:?} does not have a llvm representation", e), } } @@ -60,18 +61,19 @@ pub fn wasm_type_to_zeroed_value(ctx: &Context, wasm_type: wasmparser::Type) -> pub fn wasm_func_type_to_llvm_type<'a>( ctx: &'a Context, f_type: &wasmparser::FuncType, -) -> &'a llvm::Type { +) -> FunctionType<'a> { let return_count = f_type.returns.len(); assert!(return_count <= 1); let return_type = if return_count == 0 { - <()>::get_type(ctx) + BasicType::void_ty(ctx) } else { wasm_type_to_llvm_type(ctx, f_type.returns[0]) }; - let mut params: Vec<&llvm::Type> = Vec::new(); + + let mut params = Vec::new(); for t in &*f_type.params { params.push(wasm_type_to_llvm_type(ctx, *t)) } - llvm::FunctionType::new(return_type, ¶ms).to_super() + FunctionType::new(ctx, ¶ms, return_type) } diff --git a/src/llvm_externs.rs b/src/llvm_externs.rs index 3285c94a..abad9ff3 100644 --- a/src/llvm_externs.rs +++ b/src/llvm_externs.rs @@ -31,8 +31,5 @@ extern "C" { VLength: c_uint, ) -> LLVMAttributeRef; - pub fn LLVMGetEnumAttributeKindForName( - Name: *const c_char, - SLen: usize, - ) -> c_uint; -} \ No newline at end of file + pub fn LLVMGetEnumAttributeKindForName(Name: *const c_char, SLen: usize) -> c_uint; +} diff --git a/src/wasm.rs b/src/wasm.rs index 908b96a5..52650bb3 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -1,6 +1,5 @@ use std::str; -use wasmparser::{CustomSectionKind, TypeOrFuncType}; use wasmparser::ExternalKind; use wasmparser::FuncType; use wasmparser::ImportSectionEntryType; @@ -12,6 +11,7 @@ use wasmparser::SectionCode; use wasmparser::TableType; use wasmparser::Type; use wasmparser::WasmDecoder; +use wasmparser::{CustomSectionKind, TypeOrFuncType}; #[derive(Debug)] pub struct WasmModule { @@ -66,14 +66,8 @@ impl Global { pub fn in_memory_size(&self) -> usize { let typ = match self { - Global::Imported { - content_type, - .. - } => content_type, - Global::InModule { - content_type, - .. - } => content_type + Global::Imported { content_type, .. } => content_type, + Global::InModule { content_type, .. } => content_type, }; match typ { @@ -243,29 +237,54 @@ pub struct TableInitializer { #[derive(Clone, Debug, PartialEq)] pub enum Instruction { - BlockStart { produced_type: Option }, - LoopStart { produced_type: Option }, + BlockStart { + produced_type: Option, + }, + LoopStart { + produced_type: Option, + }, End, - Br { depth: u32 }, - BrIf { depth: u32 }, - BrTable { table: Vec, default: u32 }, + Br { + depth: u32, + }, + BrIf { + depth: u32, + }, + BrTable { + table: Vec, + default: u32, + }, Return, Unreachable, - Call { index: u32 }, - CallIndirect { type_index: u32 }, + Call { + index: u32, + }, + CallIndirect { + type_index: u32, + }, Drop, Nop, Select, - GetLocal { index: u32 }, - SetLocal { index: u32 }, - TeeLocal { index: u32 }, + GetLocal { + index: u32, + }, + SetLocal { + index: u32, + }, + TeeLocal { + index: u32, + }, - GetGlobal { index: u32 }, - SetGlobal { index: u32 }, + GetGlobal { + index: u32, + }, + SetGlobal { + index: u32, + }, I32Const(i32), @@ -420,32 +439,101 @@ pub enum Instruction { F64Ceil, F64Nearest, - I32Load { flags: u32, offset: u32 }, - I32Store { flags: u32, offset: u32 }, - I32Load8S { flags: u32, offset: u32 }, - I32Load8U { flags: u32, offset: u32 }, - I32Store8 { flags: u32, offset: u32 }, - I32Load16S { flags: u32, offset: u32 }, - I32Load16U { flags: u32, offset: u32 }, - I32Store16 { flags: u32, offset: u32 }, - - I64Load { flags: u32, offset: u32 }, - I64Store { flags: u32, offset: u32 }, - I64Load8S { flags: u32, offset: u32 }, - I64Load8U { flags: u32, offset: u32 }, - I64Store8 { flags: u32, offset: u32 }, - I64Load16S { flags: u32, offset: u32 }, - I64Load16U { flags: u32, offset: u32 }, - I64Store16 { flags: u32, offset: u32 }, - I64Load32S { flags: u32, offset: u32 }, - I64Load32U { flags: u32, offset: u32 }, - I64Store32 { flags: u32, offset: u32 }, - - F32Load { flags: u32, offset: u32 }, - F32Store { flags: u32, offset: u32 }, - - F64Load { flags: u32, offset: u32 }, - F64Store { flags: u32, offset: u32 }, + I32Load { + flags: u32, + offset: u32, + }, + I32Store { + flags: u32, + offset: u32, + }, + I32Load8S { + flags: u32, + offset: u32, + }, + I32Load8U { + flags: u32, + offset: u32, + }, + I32Store8 { + flags: u32, + offset: u32, + }, + I32Load16S { + flags: u32, + offset: u32, + }, + I32Load16U { + flags: u32, + offset: u32, + }, + I32Store16 { + flags: u32, + offset: u32, + }, + + I64Load { + flags: u32, + offset: u32, + }, + I64Store { + flags: u32, + offset: u32, + }, + I64Load8S { + flags: u32, + offset: u32, + }, + I64Load8U { + flags: u32, + offset: u32, + }, + I64Store8 { + flags: u32, + offset: u32, + }, + I64Load16S { + flags: u32, + offset: u32, + }, + I64Load16U { + flags: u32, + offset: u32, + }, + I64Store16 { + flags: u32, + offset: u32, + }, + I64Load32S { + flags: u32, + offset: u32, + }, + I64Load32U { + flags: u32, + offset: u32, + }, + I64Store32 { + flags: u32, + offset: u32, + }, + + F32Load { + flags: u32, + offset: u32, + }, + F32Store { + flags: u32, + offset: u32, + }, + + F64Load { + flags: u32, + offset: u32, + }, + F64Store { + flags: u32, + offset: u32, + }, MemorySize, MemoryGrow, @@ -850,7 +938,8 @@ impl WasmModule { } pub fn log_diagnostics(&self) { - let global_variable_memory_use: usize = self.globals.iter().map(|g| g.in_memory_size()).sum(); + let global_variable_memory_use: usize = + self.globals.iter().map(|g| g.in_memory_size()).sum(); info!("Globals taking up {} bytes", global_variable_memory_use); let mut data_initializer_memory_use = 0; @@ -859,13 +948,19 @@ impl WasmModule { data_initializer_memory_use += body_bytes.len(); } } - info!("Data initializers taking up {} bytes", data_initializer_memory_use); + info!( + "Data initializers taking up {} bytes", + data_initializer_memory_use + ); let mut function_table_entries = 0; for initializer in &self.table_initializers { function_table_entries += initializer.function_indexes.len(); } - info!("Function table entries {} (ignoring fragmentation)", function_table_entries); + info!( + "Function table entries {} (ignoring fragmentation)", + function_table_entries + ); } fn implement_function(&mut self, mut f: ImplementedFunction) { diff --git a/tests/code_benches.rs b/tests/code_benches.rs index 2b2ead8c..c789b2d8 100644 --- a/tests/code_benches.rs +++ b/tests/code_benches.rs @@ -31,4 +31,3 @@ fn code_benches_test() -> Result<(), Box> { assert!(status.success()); Ok(()) } -