evmjit as sublibrary

This commit is contained in:
debris 2015-12-05 19:21:07 +01:00
parent 1a3e8fdb3b
commit 02c8ee3c91
5 changed files with 114 additions and 1 deletions

View File

@ -10,3 +10,7 @@ authors = ["Ethcore <admin@ethcore.io>"]
log = "0.3"
env_logger = "0.3"
ethcore-util = "0.1.0"
evmjit = { path = "rust-evmjit", optional = true }
[features]
jit = ["evmjit"]

3
rust-evmjit/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
target
Cargo.lock
*.swp

7
rust-evmjit/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "evmjit"
version = "0.1.0"
authors = ["debris <marek.kotewicz@gmail.com>"]
[dependencies]
libc = "0.2.2"

95
rust-evmjit/src/lib.rs Normal file
View File

@ -0,0 +1,95 @@
//! Bare rust wrapper around evmjit
//!
//! Requires latest version of Ethereum EVM JIT. https://github.com/debris/evmjit
extern crate libc;
use std::ptr;
#[repr(C)]
pub struct JitI256 {
pub words: [u64; 4]
}
impl JitI256 {
pub fn new() -> JitI256 {
JitI256 {
words: [0; 4]
}
}
}
#[repr(C)]
pub struct JitRuntimeData {
pub gas: i64,
pub gas_price: i64,
pub call_data: *const libc::c_char,
pub call_data_size: u64,
pub address: JitI256,
pub caller: JitI256,
pub origin: JitI256,
pub call_value: JitI256,
pub coinbase: JitI256,
pub difficulty: JitI256,
pub gas_limit: JitI256,
pub number: u64,
pub timestamp: i64,
pub code: *const libc::c_char,
pub code_size: u64,
pub code_hash: JitI256
}
impl JitRuntimeData {
pub fn new() -> JitRuntimeData {
JitRuntimeData {
gas: 0,
gas_price: 0,
call_data: ptr::null(),
call_data_size: 0,
address: JitI256::new(),
caller: JitI256::new(),
origin: JitI256::new(),
call_value: JitI256::new(),
coinbase: JitI256::new(),
difficulty: JitI256::new(),
gas_limit: JitI256::new(),
number: 0,
timestamp: 0,
code: ptr::null(),
code_size: 0,
code_hash: JitI256::new()
}
}
}
#[repr(C)]
#[derive(Debug)]
pub enum JitReturnCode {
Stop = 0,
Return = 1,
Suicide = 2,
OutOfGas = -1,
LLVMError = -101,
UnexpectedError = -111
}
#[derive(Copy, Clone)]
pub enum JitContext {}
#[link(name="evmjit")]
extern "C" {
pub fn evmjit_create(data: JitRuntimeData, env: u8) -> JitContext;
pub fn evmjit_exec(context: JitContext) -> JitReturnCode;
pub fn evmjit_destroy(context: JitContext);
}
#[test]
fn it_works() {
unsafe {
let context = evmjit_create(JitRuntimeData::new(), 0);
let _result = evmjit_exec(context);
evmjit_destroy(context);
}
}

View File

@ -1,6 +1,10 @@
#[macro_use] extern crate log;
#[macro_use]
extern crate log;
extern crate ethcore_util;
#[cfg(feature = "jit" )]
extern crate evmjit;
use ethcore_util::hash::*;
use ethcore_util::uint::*;