diff --git a/runner/build.sh b/runner/build.sh index afded07..3e21e7f 100755 --- a/runner/build.sh +++ b/runner/build.sh @@ -9,17 +9,22 @@ if [ ${file: -3} == ".rs" ] then # Rust is compiled with rustc rustc $file -o out/contract.js -O --target wasm32-unknown-emscripten + + # Allocator replacer + cargo run --manifest-path=./../ext/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm + + # Symbols optimizer + cargo run --manifest-path=./../opt/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm + + # Gas injector + cargo run --manifest-path=./../gas/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm + else # c/c++ can be compiled directly by emcc emcc $file -Os -s WASM=1 -s SIDE_MODULE=1 -o out/contract.wasm + + # Gas injector + cargo run --manifest-path=./../gas/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm fi -# Gas injector -cargo run --manifest-path=./../gas/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm - -# Allocator replacer -cargo run --manifest-path=./../ext/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm - -# Symbols optimizer -cargo run --manifest-path=./../opt/Cargo.toml --release -- ./out/contract.wasm ./out/contract.wasm diff --git a/samples/static_contract.c b/samples/static_contract.c new file mode 100644 index 0000000..e06fd86 --- /dev/null +++ b/samples/static_contract.c @@ -0,0 +1,65 @@ +int data; + +int call(void* descriptor) { + int* input_length = (int*)(descriptor+4); + data += *input_length; +} + +/* produces the following code (with gas counter) + +(module + (type (;0;) (func (param i32) (result i32))) + (type (;1;) (func)) + (type (;2;) (func (param i32))) + (import "env" "memoryBase" (global (;0;) i32)) + (import "env" "memory" (memory (;0;) 256)) + (import "env" "table" (table (;0;) 0 anyfunc)) + (import "env" "tableBase" (global (;1;) i32)) + (import "env" "gas" (func (;0;) (type 2))) + (func (;1;) (type 0) (param i32) (result i32) + i32.const 2 + call 0 + block i32 ;; label = @1 + i32.const 13 + call 0 + get_global 0 + i32.const 5242880 + i32.add + get_global 0 + i32.const 5242880 + i32.add + i32.load + get_local 0 + i32.load offset=4 + i32.add + i32.store + i32.const 0 + end) + (func (;2;) (type 1) + i32.const 2 + call 0 + nop) + (func (;3;) (type 1) + i32.const 2 + call 0 + block ;; label = @1 + i32.const 8 + call 0 + get_global 0 + set_global 2 + get_global 2 + i32.const 5242880 + i32.add + set_global 3 + call 2 + end) + (global (;2;) (mut i32) (i32.const 0)) + (global (;3;) (mut i32) (i32.const 0)) + (global (;4;) i32 (i32.const 5242880)) + (export "__post_instantiate" (func 3)) + (export "runPostSets" (func 2)) + (export "_call" (func 1)) + (export "_data" (global 4))) + + +*/ \ No newline at end of file