From f9c8f41232a67284fe692cb7d9f83ac0921c2091 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sun, 2 Jun 2019 13:37:51 -0500 Subject: [PATCH] Remove points_limit and update tests --- lib/middleware-common/src/metering.rs | 60 ++++++++++++++------------- lib/runtime-core/src/backend.rs | 2 - 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index c448378d4..a155485f6 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -113,30 +113,48 @@ pub fn set_points_used(_instance: &mut Instance, _value: u64) { mod tests { use super::*; use wabt::wat2wasm; - use wasmer_runtime_core::{ - backend::{Compiler, CompilerConfig}, - compile_with_config, imports, Func, - }; + + use wasmer_runtime_core::{backend::Compiler, compile_with, imports, Func}; #[cfg(feature = "llvm")] - fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() + fn get_compiler(limit: u64) -> impl Compiler { + use wasmer_llvm_backend::code::LLVMModuleCodeGenerator; + use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; + let c: StreamingCompiler = + StreamingCompiler::new(move || { + let mut chain = MiddlewareChain::new(); + chain.push(Metering::new(limit)); + chain + }); + c } #[cfg(feature = "singlepass")] - fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() + fn get_compiler(limit: u64) -> impl Compiler { + use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; + use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG; + let c: StreamingCompiler = StreamingCompiler::new(move || { + let mut chain = MiddlewareChain::new(); + chain.push(Metering::new(limit)); + chain + }); + c } #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] - fn get_compiler() -> impl Compiler { + fn get_compiler(_limit: u64) -> impl Compiler { panic!("compiler not specified, activate a compiler via features"); use wasmer_clif_backend::CraneliftCompiler; CraneliftCompiler::new() } + #[cfg(feature = "clif")] + fn get_compiler(_limit: u64) -> impl Compiler { + panic!("cranelift does not implement metering"); + use wasmer_clif_backend::CraneliftCompiler; + CraneliftCompiler::new() + } + // Assemblyscript // export function add_to(x: i32, y: i32): i32 { // for(var i = 0; i < x; i++){ @@ -202,15 +220,7 @@ mod tests { let limit = 100u64; - let module = compile_with_config( - &wasm_binary, - &get_compiler(), - CompilerConfig { - points_limit: Some(limit), - ..Default::default() - }, - ) - .unwrap(); + let module = compile_with(&wasm_binary, &get_compiler(limit)).unwrap(); let import_object = imports! {}; let mut instance = module.instantiate(&import_object).unwrap(); @@ -233,15 +243,7 @@ mod tests { let limit = 100u64; - let module = compile_with_config( - &wasm_binary, - &get_compiler(), - CompilerConfig { - points_limit: Some(limit), - ..Default::default() - }, - ) - .unwrap(); + let module = compile_with(&wasm_binary, &get_compiler(limit)).unwrap(); let import_object = imports! {}; let mut instance = module.instantiate(&import_object).unwrap(); diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 3c014c8aa..1d493c314 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -59,8 +59,6 @@ pub struct CompilerConfig { pub symbol_map: Option>, pub memory_bound_check_mode: MemoryBoundCheckMode, pub enforce_stack_check: bool, - /// Enables metering functionality if set and used as default points limit during compilation - pub points_limit: Option, } pub trait Compiler {