Merge pull request #54 from paritytech/fix-grow

Fix grow_memory transform
This commit is contained in:
Nikolay Volf 2018-02-05 16:42:11 +03:00 committed by GitHub
commit 3feb8da52b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,16 +41,15 @@ fn add_grow_counter(module: elements::Module, rules: &rules::Set, gas_func: u32)
let mut b = builder::from_module(module); let mut b = builder::from_module(module);
b.push_function( b.push_function(
builder::function() builder::function()
.signature().params().i32().i32().build().with_return_type(Some(elements::ValueType::I32)).build() .signature().params().i32().build().with_return_type(Some(elements::ValueType::I32)).build()
.body() .body()
.with_opcodes(elements::Opcodes::new(vec![ .with_opcodes(elements::Opcodes::new(vec![
GetLocal(0),
GetLocal(0), GetLocal(0),
I32Const(rules.grow_cost() as i32), I32Const(rules.grow_cost() as i32),
I32Mul, I32Mul,
TeeLocal(1),
// todo: there should be strong guarantee that it does not return anything on stack? // todo: there should be strong guarantee that it does not return anything on stack?
Call(gas_func), Call(gas_func),
GetLocal(1),
GrowMemory(0), GrowMemory(0),
GetLocal(0), GetLocal(0),
End, End,
@ -241,12 +240,11 @@ mod tests {
); );
assert_eq!( assert_eq!(
&vec![ &vec![
GetLocal(0),
GetLocal(0), GetLocal(0),
I32Const(10000), I32Const(10000),
I32Mul, I32Mul,
TeeLocal(1),
Call(0), Call(0),
GetLocal(1),
GrowMemory(0), GrowMemory(0),
GetLocal(0), GetLocal(0),
End, End,