CLI option for using JITEVM (#1103)

* easily configurable vm (in progress)

* completely removed vm_factory from engine

* --jitvm command line flag
This commit is contained in:
Marek Kotewicz
2016-05-19 00:44:49 +02:00
committed by Gav Wood
parent 46f3b5f913
commit 6cff58055d
20 changed files with 204 additions and 155 deletions

View File

@@ -17,11 +17,10 @@
//! Evm factory.
//!
//! TODO: consider spliting it into two separate files.
#[cfg(test)]
use std::fmt;
use evm::Evm;
#[derive(Clone)]
#[derive(Debug, Clone)]
/// Type of EVM to use.
pub enum VMType {
/// JIT EVM
@@ -31,7 +30,6 @@ pub enum VMType {
Interpreter
}
#[cfg(test)]
impl fmt::Display for VMType {
#[cfg(feature="jit")]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -48,8 +46,12 @@ impl fmt::Display for VMType {
}
}
#[cfg(test)]
#[cfg(feature = "json-tests")]
impl Default for VMType {
fn default() -> Self {
VMType::Interpreter
}
}
impl VMType {
/// Return all possible VMs (JIT, Interpreter)
#[cfg(feature = "jit")]
@@ -62,6 +64,18 @@ impl VMType {
pub fn all() -> Vec<VMType> {
vec![VMType::Interpreter]
}
/// Return new jit if it's possible
#[cfg(not(feature = "jit"))]
pub fn jit() -> Option<Self> {
None
}
/// Return new jit if it's possible
#[cfg(feature = "jit")]
pub fn jit() -> Option<Self> {
Some(VMType::Jit)
}
}
/// Evm factory. Creates appropriate Evm.
@@ -80,7 +94,7 @@ impl Factory {
VMType::Interpreter => {
Box::new(super::interpreter::Interpreter)
}
}
}
}
/// Create fresh instance of VM
@@ -90,17 +104,17 @@ impl Factory {
VMType::Interpreter => {
Box::new(super::interpreter::Interpreter)
}
}
}
}
/// Create new instance of specific `VMType` factory
#[cfg(test)]
pub fn new(evm: VMType) -> Factory {
pub fn new(evm: VMType) -> Self {
Factory {
evm: evm
}
}
}
impl Default for Factory {
/// Returns jitvm factory
#[cfg(feature = "jit")]

View File

@@ -31,6 +31,5 @@ mod tests;
pub use self::evm::{Evm, Error, Result};
pub use self::ext::{Ext, ContractCreateResult, MessageCallResult};
pub use self::factory::Factory;
pub use self::factory::{Factory, VMType};
pub use self::schedule::Schedule;
pub use self::factory::VMType;