Get this test case's Wasm module. The Wasm module has the following imports: `host.check_stack: [] -> []`: The host can check the Wasm's understanding of its own stack against the host's understanding of the Wasm stack to find discrepancy bugs. `host.call_func: [funcref] -> []`: The host should call the given `funcref`, creating a call stack with multiple sequences of contiguous Wasm frames on
(&self)
| 127 | /// checking whether the host's view of the stack at a trap matches the |
| 128 | /// Wasm program's understanding. |
| 129 | pub fn wasm(&self) -> Vec<u8> { |
| 130 | let mut module = wasm_encoder::Module::new(); |
| 131 | |
| 132 | let mut types = wasm_encoder::TypeSection::new(); |
| 133 | |
| 134 | let run_type = types.len(); |
| 135 | types |
| 136 | .ty() |
| 137 | .function(vec![wasm_encoder::ValType::I32], vec![]); |
| 138 | |
| 139 | let get_stack_type = types.len(); |
| 140 | types.ty().function( |
| 141 | vec![], |
| 142 | vec![wasm_encoder::ValType::I32, wasm_encoder::ValType::I32], |
| 143 | ); |
| 144 | |
| 145 | let call_func_type = types.len(); |
| 146 | types |
| 147 | .ty() |
| 148 | .function(vec![wasm_encoder::ValType::FUNCREF], vec![]); |
| 149 | |
| 150 | let check_stack_type = types.len(); |
| 151 | types.ty().function(vec![], vec![]); |
| 152 | |
| 153 | let func_types_start = types.len(); |
| 154 | for func in self.funcs.iter() { |
| 155 | types.ty().function( |
| 156 | vec![ValType::I32; func.params], |
| 157 | vec![ValType::I32; func.results], |
| 158 | ); |
| 159 | } |
| 160 | |
| 161 | section(&mut module, types); |
| 162 | |
| 163 | let mut imports = wasm_encoder::ImportSection::new(); |
| 164 | let check_stack_func = 0; |
| 165 | imports.import( |
| 166 | "host", |
| 167 | "check_stack", |
| 168 | wasm_encoder::EntityType::Function(check_stack_type), |
| 169 | ); |
| 170 | let call_func_func = 1; |
| 171 | imports.import( |
| 172 | "host", |
| 173 | "call_func", |
| 174 | wasm_encoder::EntityType::Function(call_func_type), |
| 175 | ); |
| 176 | let num_imported_funcs = 2; |
| 177 | section(&mut module, imports); |
| 178 | |
| 179 | let mut funcs = wasm_encoder::FunctionSection::new(); |
| 180 | for (i, _) in self.funcs.iter().enumerate() { |
| 181 | funcs.function(func_types_start + (i as u32)); |
| 182 | } |
| 183 | let run_func = funcs.len() + num_imported_funcs; |
| 184 | funcs.function(run_type); |
| 185 | let get_stack_func = funcs.len() + num_imported_funcs; |
| 186 | funcs.function(get_stack_type); |