|
25 | 25 | //! compiles it down into a `WasmModule` that can be used as a contract's code.
|
26 | 26 |
|
27 | 27 | use crate::Config;
|
28 |
| -use parity_wasm::elements::{ |
29 |
| - Instruction, Instructions, FuncBody, ValueType, BlockType, Section, CustomSection, |
| 28 | +use pwasm_utils::{ |
| 29 | + stack_height::inject_limiter, |
| 30 | + parity_wasm::{ |
| 31 | + elements::{ |
| 32 | + self, Instruction, Instructions, FuncBody, ValueType, BlockType, Section, |
| 33 | + CustomSection, |
| 34 | + }, |
| 35 | + builder, |
| 36 | + }, |
30 | 37 | };
|
31 |
| -use pwasm_utils::stack_height::inject_limiter; |
32 | 38 | use sp_core::crypto::UncheckedFrom;
|
33 | 39 | use sp_runtime::traits::Hash;
|
34 | 40 | use sp_sandbox::{EnvironmentDefinitionBuilder, Memory};
|
@@ -127,7 +133,7 @@ where
|
127 | 133 | let func_offset = u32::try_from(def.imported_functions.len()).unwrap();
|
128 | 134 |
|
129 | 135 | // Every contract must export "deploy" and "call" functions
|
130 |
| - let mut contract = parity_wasm::builder::module() |
| 136 | + let mut contract = builder::module() |
131 | 137 | // deploy function (first internal function)
|
132 | 138 | .function()
|
133 | 139 | .signature().build()
|
@@ -166,15 +172,15 @@ where
|
166 | 172 |
|
167 | 173 | // Import supervisor functions. They start with idx 0.
|
168 | 174 | for func in def.imported_functions {
|
169 |
| - let sig = parity_wasm::builder::signature() |
| 175 | + let sig = builder::signature() |
170 | 176 | .with_params(func.params)
|
171 | 177 | .with_results(func.return_type.into_iter().collect())
|
172 | 178 | .build_sig();
|
173 | 179 | let sig = contract.push_signature(sig);
|
174 | 180 | contract = contract.import()
|
175 | 181 | .module(func.module)
|
176 | 182 | .field(func.name)
|
177 |
| - .with_external(parity_wasm::elements::External::Function(sig)) |
| 183 | + .with_external(elements::External::Function(sig)) |
178 | 184 | .build();
|
179 | 185 | }
|
180 | 186 |
|
@@ -264,7 +270,7 @@ where
|
264 | 270 | /// `instantiate_with_code` for different sizes of wasm modules. The generated module maximizes
|
265 | 271 | /// instrumentation runtime by nesting blocks as deeply as possible given the byte budget.
|
266 | 272 | pub fn sized(target_bytes: u32) -> Self {
|
267 |
| - use parity_wasm::elements::Instruction::{If, I32Const, Return, End}; |
| 273 | + use self::elements::Instruction::{If, I32Const, Return, End}; |
268 | 274 | // Base size of a contract is 63 bytes and each expansion adds 6 bytes.
|
269 | 275 | // We do one expansion less to account for the code section and function body
|
270 | 276 | // size fields inside the binary wasm module representation which are leb128 encoded
|
@@ -496,7 +502,7 @@ pub mod body {
|
496 | 502 |
|
497 | 503 | /// Replace the locals of the supplied `body` with `num` i64 locals.
|
498 | 504 | pub fn inject_locals(body: &mut FuncBody, num: u32) {
|
499 |
| - use parity_wasm::elements::Local; |
| 505 | + use self::elements::Local; |
500 | 506 | *body.locals_mut() = (0..num).map(|i| Local::new(i, ValueType::I64)).collect()
|
501 | 507 | }
|
502 | 508 | }
|
|
0 commit comments