mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-06-27 05:21:38 +00:00
fix call update
This commit is contained in:
@ -34,12 +34,10 @@ fn main() {
|
|||||||
let import_sig = mbuilder.push_signature(
|
let import_sig = mbuilder.push_signature(
|
||||||
builder::signature()
|
builder::signature()
|
||||||
.param().i32()
|
.param().i32()
|
||||||
.param().i32()
|
|
||||||
.return_type().i32()
|
|
||||||
.build_sig()
|
.build_sig()
|
||||||
);
|
);
|
||||||
|
|
||||||
let gas_func = mbuilder.push_import(
|
let mut gas_func = mbuilder.push_import(
|
||||||
builder::import()
|
builder::import()
|
||||||
.module("env")
|
.module("env")
|
||||||
.field("gas")
|
.field("gas")
|
||||||
@ -47,8 +45,20 @@ fn main() {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Updating calling addresses (all calls to function index >= `gas_func` should be incremented)
|
// back to plain module
|
||||||
let mut module = mbuilder.build();
|
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() {
|
for section in module.sections_mut() {
|
||||||
match section {
|
match section {
|
||||||
&mut elements::Section::Code(ref mut code_section) => {
|
&mut elements::Section::Code(ref mut code_section) => {
|
||||||
|
@ -14,9 +14,10 @@ else
|
|||||||
emcc $file -Os -s WASM=1 -s SIDE_MODULE=1 -o out/contract.wasm
|
emcc $file -Os -s WASM=1 -s SIDE_MODULE=1 -o out/contract.wasm
|
||||||
fi
|
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 "No gas utility, compile it in /gas folder with"
|
||||||
echo "cargo build --release"
|
echo "cargo build --release"
|
||||||
fi
|
else
|
||||||
|
|
||||||
./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm
|
./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm
|
||||||
|
fi
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
int call(int x) {
|
|
||||||
return 2 * x;
|
|
||||||
}
|
|
Reference in New Issue
Block a user