mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-06-26 13:01:37 +00:00
fix call update
This commit is contained in:
@ -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) => {
|
||||
|
@ -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
|
@ -1,3 +0,0 @@
|
||||
int call(int x) {
|
||||
return 2 * x;
|
||||
}
|
Reference in New Issue
Block a user