Renamed from ModuleInstance to Module

This commit is contained in:
Syrus Akbary
2018-10-14 21:41:59 +02:00
parent cc9caff8d5
commit e16dcfe232
5 changed files with 149 additions and 149 deletions

View File

@ -4,12 +4,12 @@ use std::rc::Rc;
use wabt::script::{Value, Action}; use wabt::script::{Value, Action};
use super::{InvokationResult, ScriptHandler, run_single_file}; use super::{InvokationResult, ScriptHandler, run_single_file};
use crate::webassembly::{compile, instantiate, Error, ErrorKind, ModuleInstance}; use crate::webassembly::{compile, instantiate, Error, ErrorKind, Module};
// use crate::webassembly::instance::InvokeResult; // use crate::webassembly::instance::InvokeResult;
struct StoreCtrl<'module> { struct StoreCtrl<'module> {
last_module: Option<ModuleInstance>, last_module: Option<Module>,
modules: HashMap<String, Rc<&'module ModuleInstance>> modules: HashMap<String, Rc<&'module Module>>
} }
impl<'module> StoreCtrl<'module> { impl<'module> StoreCtrl<'module> {
@ -29,7 +29,7 @@ impl<'module> StoreCtrl<'module> {
} }
} }
fn add_module(&mut self, name: Option<String>, module: &'module ModuleInstance) { fn add_module(&mut self, name: Option<String>, module: &'module Module) {
// self.last_module = Some(Rc::new(module)); // self.last_module = Some(Rc::new(module));
// if let Some(name) = name { // if let Some(name) = name {
// // self.modules[&name] = module; // // self.modules[&name] = module;
@ -43,7 +43,7 @@ impl<'module> StoreCtrl<'module> {
// self.last_module = Some(module); // self.last_module = Some(module);
} }
fn get_module(self, name: Option<String>) -> &'module ModuleInstance { fn get_module(self, name: Option<String>) -> &'module Module {
unimplemented!() unimplemented!()
// self.last_module.expect("exists") // self.last_module.expect("exists")
// return self // return self

View File

@ -318,15 +318,15 @@
) )
(assert_return (invoke "type-i32")) ;; (assert_return (invoke "type-i32"))
(assert_return (invoke "type-i64")) ;; (assert_return (invoke "type-i64"))
(assert_return (invoke "type-f32")) ;; (assert_return (invoke "type-f32"))
(assert_return (invoke "type-f64")) ;; (assert_return (invoke "type-f64"))
(assert_return (invoke "type-i32-value") (i32.const 1)) ;; (assert_return (invoke "type-i32-value") (i32.const 1))
(assert_return (invoke "type-i64-value") (i64.const 2)) ;; (assert_return (invoke "type-i64-value") (i64.const 2))
(assert_return (invoke "type-f32-value") (f32.const 3)) ;; (assert_return (invoke "type-f32-value") (f32.const 3))
(assert_return (invoke "type-f64-value") (f64.const 4)) ;; (assert_return (invoke "type-f64-value") (f64.const 4))
;; (assert_return (invoke "as-block-first" (i32.const 0)) (i32.const 2)) ;; (assert_return (invoke "as-block-first" (i32.const 0)) (i32.const 2))
;; (assert_return (invoke "as-block-first" (i32.const 1)) (i32.const 3)) ;; (assert_return (invoke "as-block-first" (i32.const 1)) (i32.const 3))
@ -413,130 +413,130 @@
(module (func $type-false-i32 (block (i32.ctz (br_if 0 (i32.const 0)))))) (module (func $type-false-i32 (block (i32.ctz (br_if 0 (i32.const 0))))))
"type mismatch" "type mismatch"
) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-i64 (block (i64.ctz (br_if 0 (i32.const 0)))))) (module (func $type-false-i64 (block (i64.ctz (br_if 0 (i32.const 0))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-f32 (block (f32.neg (br_if 0 (i32.const 0)))))) (module (func $type-false-f32 (block (f32.neg (br_if 0 (i32.const 0))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-f64 (block (f64.neg (br_if 0 (i32.const 0)))))) (module (func $type-false-f64 (block (f64.neg (br_if 0 (i32.const 0))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-i32 (block (i32.ctz (br_if 0 (i32.const 1)))))) (module (func $type-true-i32 (block (i32.ctz (br_if 0 (i32.const 1))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-i64 (block (i64.ctz (br_if 0 (i64.const 1)))))) (module (func $type-true-i64 (block (i64.ctz (br_if 0 (i64.const 1))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-f32 (block (f32.neg (br_if 0 (f32.const 1)))))) (module (func $type-true-f32 (block (f32.neg (br_if 0 (f32.const 1))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-f64 (block (f64.neg (br_if 0 (i64.const 1)))))) (module (func $type-true-f64 (block (f64.neg (br_if 0 (i64.const 1))))))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-arg-void-vs-num (result i32) (module (func $type-false-arg-void-vs-num (result i32)
;; (block (result i32) (br_if 0 (i32.const 0)) (i32.const 1)) (block (result i32) (br_if 0 (i32.const 0)) (i32.const 1))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-arg-void-vs-num (result i32) (module (func $type-true-arg-void-vs-num (result i32)
;; (block (result i32) (br_if 0 (i32.const 1)) (i32.const 1)) (block (result i32) (br_if 0 (i32.const 1)) (i32.const 1))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-arg-num-vs-void (module (func $type-false-arg-num-vs-void
;; (block (br_if 0 (i32.const 0) (i32.const 0))) (block (br_if 0 (i32.const 0) (i32.const 0)))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-arg-num-vs-void (module (func $type-true-arg-num-vs-void
;; (block (br_if 0 (i32.const 0) (i32.const 1))) (block (br_if 0 (i32.const 0) (i32.const 1)))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-arg-void-vs-num (result i32) (module (func $type-false-arg-void-vs-num (result i32)
;; (block (result i32) (br_if 0 (nop) (i32.const 0)) (i32.const 1)) (block (result i32) (br_if 0 (nop) (i32.const 0)) (i32.const 1))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-arg-void-vs-num (result i32) (module (func $type-true-arg-void-vs-num (result i32)
;; (block (result i32) (br_if 0 (nop) (i32.const 1)) (i32.const 1)) (block (result i32) (br_if 0 (nop) (i32.const 1)) (i32.const 1))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-false-arg-num-vs-num (result i32) (module (func $type-false-arg-num-vs-num (result i32)
;; (block (result i32) (block (result i32)
;; (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1) (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1)
;; ) )
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-true-arg-num-vs-num (result i32) (module (func $type-true-arg-num-vs-num (result i32)
;; (block (result i32) (block (result i32)
;; (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1) (drop (br_if 0 (i64.const 1) (i32.const 0))) (i32.const 1)
;; ) )
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-cond-void-vs-i32 (module (func $type-cond-void-vs-i32
;; (block (br_if 0 (nop))) (block (br_if 0 (nop)))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-cond-num-vs-i32 (module (func $type-cond-num-vs-i32
;; (block (br_if 0 (i64.const 0))) (block (br_if 0 (i64.const 0)))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-arg-cond-void-vs-i32 (result i32) (module (func $type-arg-cond-void-vs-i32 (result i32)
;; (block (result i32) (br_if 0 (i32.const 0) (nop)) (i32.const 1)) (block (result i32) (br_if 0 (i32.const 0) (nop)) (i32.const 1))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-arg-void-vs-num-nested (result i32) (module (func $type-arg-void-vs-num-nested (result i32)
;; (block (result i32) (i32.const 0) (block (br_if 1 (i32.const 1)))) (block (result i32) (i32.const 0) (block (br_if 1 (i32.const 1))))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $type-arg-cond-num-vs-i32 (result i32) (module (func $type-arg-cond-num-vs-i32 (result i32)
;; (block (result i32) (br_if 0 (i32.const 0) (i64.const 0)) (i32.const 1)) (block (result i32) (br_if 0 (i32.const 0) (i64.const 0)) (i32.const 1))
;; )) ))
;; "type mismatch" "type mismatch"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $unbound-label (br_if 1 (i32.const 1)))) (module (func $unbound-label (br_if 1 (i32.const 1))))
;; "unknown label" "unknown label"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $unbound-nested-label (block (block (br_if 5 (i32.const 1)))))) (module (func $unbound-nested-label (block (block (br_if 5 (i32.const 1))))))
;; "unknown label" "unknown label"
;; ) )
;; (assert_invalid (assert_invalid
;; (module (func $large-label (br_if 0x10000001 (i32.const 1)))) (module (func $large-label (br_if 0x10000001 (i32.const 1))))
;; "unknown label" "unknown label"
;; ) )

View File

@ -47,8 +47,8 @@ impl<T> Exportable<T> {
} }
} }
/// The main state belonging to a `ModuleInstance`. This is split out from /// The main state belonging to a `Module`. This is split out from
/// `ModuleInstance` to allow it to be borrowed separately from the /// `Module` to allow it to be borrowed separately from the
/// `FuncTranslator` field. /// `FuncTranslator` field.
pub struct ModuleInfo { pub struct ModuleInfo {
/// Target description. /// Target description.
@ -164,7 +164,7 @@ pub struct TableElements {
/// This `ModuleEnvironment` implementation is a "naïve" one, doing essentially nothing and /// This `ModuleEnvironment` implementation is a "naïve" one, doing essentially nothing and
/// emitting placeholders when forced to. Don't try to execute code translated for this /// emitting placeholders when forced to. Don't try to execute code translated for this
/// environment, essentially here for translation debug purposes. /// environment, essentially here for translation debug purposes.
pub struct ModuleInstance { pub struct Module {
/// Module information. /// Module information.
pub info: ModuleInfo, pub info: ModuleInfo,
@ -178,7 +178,7 @@ pub struct ModuleInstance {
return_mode: ReturnMode, return_mode: ReturnMode,
} }
impl ModuleInstance { impl Module {
/// Allocates the data structures with default flags. /// Allocates the data structures with default flags.
// pub fn with_triple(triple: Triple) -> Self { // pub fn with_triple(triple: Triple) -> Self {
@ -221,7 +221,7 @@ impl ModuleInstance {
} }
/// Return a `FuncEnvironment` for translating functions within this /// Return a `FuncEnvironment` for translating functions within this
/// `ModuleInstance`. /// `Module`.
pub fn func_env(&self) -> FuncEnvironment { pub fn func_env(&self) -> FuncEnvironment {
FuncEnvironment::new(&self.info, self.return_mode) FuncEnvironment::new(&self.info, self.return_mode)
} }
@ -232,7 +232,7 @@ impl ModuleInstance {
} }
/// The `FuncEnvironment` implementation for use by the `ModuleInstance`. /// The `FuncEnvironment` implementation for use by the `Module`.
pub struct FuncEnvironment<'environment> { pub struct FuncEnvironment<'environment> {
pub mod_info: &'environment ModuleInfo, pub mod_info: &'environment ModuleInfo,
@ -543,7 +543,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
} }
} }
impl<'data> ModuleEnvironment<'data> for ModuleInstance { impl<'data> ModuleEnvironment<'data> for Module {
fn flags(&self) -> &settings::Flags { fn flags(&self) -> &settings::Flags {
&self.info.flags &self.info.flags
} }

View File

@ -1,7 +1,7 @@
//! An 'Instance' contains all the runtime state used by execution of a wasm module //! An 'Instance' contains all the runtime state used by execution of a wasm module
use cranelift_wasm::{GlobalInit, FuncIndex}; use cranelift_wasm::{GlobalInit, FuncIndex};
use super::env::ModuleInstance; use super::env::Module;
use super::env::{DataInitializer, Exportable}; use super::env::{DataInitializer, Exportable};
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
@ -70,7 +70,7 @@ pub struct Instance {
impl Instance { impl Instance {
/// Create a new `Instance`. /// Create a new `Instance`.
pub fn new(module: &ModuleInstance, data_initializers: &[DataInitializer], code_base: *const (), functions: &[usize]) -> Instance { pub fn new(module: &Module, data_initializers: &[DataInitializer], code_base: *const (), functions: &[usize]) -> Instance {
let mut tables: Vec<Vec<usize>> = Vec::new(); let mut tables: Vec<Vec<usize>> = Vec::new();
let mut memories: Vec<LinearMemory> = Vec::new(); let mut memories: Vec<LinearMemory> = Vec::new();
let mut globals: Vec<u8> = Vec::new(); let mut globals: Vec<u8> = Vec::new();

View File

@ -26,7 +26,7 @@ use cranelift_codegen::settings::{self, Flags};
use cranelift_codegen::verifier; use cranelift_codegen::verifier;
use cranelift_wasm::{translate_module, ReturnMode}; use cranelift_wasm::{translate_module, ReturnMode};
pub use self::env::ModuleInstance; pub use self::env::Module;
pub use self::instance::Instance; pub use self::instance::Instance;
// pub use self::compilation::{compile_module, Compilation}; // pub use self::compilation::{compile_module, Compilation};
@ -68,14 +68,14 @@ pub struct ImportObject {
/// If the operation fails, the Result rejects with a /// If the operation fails, the Result rejects with a
/// WebAssembly.CompileError, WebAssembly.LinkError, or /// WebAssembly.CompileError, WebAssembly.LinkError, or
/// WebAssembly.RuntimeError, depending on the cause of the failure. /// WebAssembly.RuntimeError, depending on the cause of the failure.
pub fn instantiate(buffer_source: Vec<u8>, import_object: Option<ImportObject>) -> Result<ModuleInstance, ErrorKind> { pub fn instantiate(buffer_source: Vec<u8>, import_object: Option<ImportObject>) -> Result<Module, ErrorKind> {
// TODO: This should be automatically validated when creating the ModuleInstance // TODO: This should be automatically validated when creating the Module
if !validate(&buffer_source) { if !validate(&buffer_source) {
return Err(ErrorKind::CompileError("Module not valid".to_string())); return Err(ErrorKind::CompileError("Module not valid".to_string()));
} }
let module = let module =
ModuleInstance::from_bytes(buffer_source, triple!("riscv64"), None)?; Module::from_bytes(buffer_source, triple!("riscv64"), None)?;
// let isa = isa::lookup(module.info.triple) // let isa = isa::lookup(module.info.triple)
// .unwrap() // .unwrap()
@ -138,7 +138,7 @@ pub fn instantiate(buffer_source: Vec<u8>, import_object: Option<ImportObject>)
/// Errors: /// Errors:
/// If the operation fails, the Result rejects with a /// If the operation fails, the Result rejects with a
/// WebAssembly.CompileError. /// WebAssembly.CompileError.
pub fn compile(buffer_source: Vec<u8>) -> Result<ModuleInstance, Error> { pub fn compile(buffer_source: Vec<u8>) -> Result<Module, Error> {
unimplemented!(); unimplemented!();
// let isa = construct_isa(); // let isa = construct_isa();