fix call update

This commit is contained in:
NikVolf
2017-04-12 18:44:03 +03:00
parent 96e6073006
commit d8626454bc
3 changed files with 19 additions and 11 deletions

View File

@ -34,12 +34,10 @@ fn main() {
let import_sig = mbuilder.push_signature(
builder::signature()
.param().i32()
.param().i32()
.return_type().i32()
.build_sig()
);
let gas_func = mbuilder.push_import(
let mut gas_func = mbuilder.push_import(
builder::import()
.module("env")
.field("gas")
@ -47,8 +45,20 @@ fn main() {
.build()
);
// Updating calling addresses (all calls to function index >= `gas_func` should be incremented)
// back to plain module
let mut module = mbuilder.build();
// calculate actual function index of the imported definition
// (substract all imports that are NOT functions)
for import_entry in module.import_section().expect("Builder should have insert the import section").entries() {
match *import_entry.external() {
elements::External::Function(_) => {},
_ => { gas_func -= 1; }
}
}
// Updating calling addresses (all calls to function index >= `gas_func` should be incremented)
for section in module.sections_mut() {
match section {
&mut elements::Section::Code(ref mut code_section) => {

View File

@ -14,9 +14,10 @@ else
emcc $file -Os -s WASM=1 -s SIDE_MODULE=1 -o out/contract.wasm
fi
if [ ! -f ./../gas/target/release/gas ] && [ ! -f ./../gas/target/release/gas.exe ] then
if [ ! -f ./../gas/target/release/gas ] && [ ! -f ./../gas/target/release/gas.exe ]
then
echo "No gas utility, compile it in /gas folder with"
echo "cargo build --release"
echo "cargo build --release"
else
./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm
fi
./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm

View File

@ -1,3 +0,0 @@
int call(int x) {
return 2 * x;
}