From 633fc04ba441d294fd24bab2d422fdea93b565db Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 18 Sep 2023 18:02:44 +0300 Subject: [PATCH] test: temporarily translate unsupported `call_indirect`, `ctz`, `clz` to get dlmalloc code translation further. --- frontend-wasm/src/code_translator.rs | 14 ++++++++++++++ .../src/code_translator/tests_unsupported.rs | 14 +++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/frontend-wasm/src/code_translator.rs b/frontend-wasm/src/code_translator.rs index 029127762..1149905c9 100644 --- a/frontend-wasm/src/code_translator.rs +++ b/frontend-wasm/src/code_translator.rs @@ -119,6 +119,14 @@ pub fn translate_operator( Operator::Call { function_index } => { translate_call(state, builder, function_index, mod_info, span, diagnostics)?; } + Operator::CallIndirect { + type_index: _, + table_index: _, + table_byte: _, + } => { + builder.ins().unreachable(span); + state.reachable = false; + } /******************************* Memory management *********************************/ Operator::MemoryGrow { .. } => { // Do nothing and return total Miden memory size @@ -196,6 +204,12 @@ pub fn translate_operator( let val = state.pop1(); state.push1(builder.ins().trunc(val, I32, span)); } + Operator::I32Clz | Operator::I32Ctz => { + let val = state.pop1(); + // Using popcnt (same sig as ctz/clz) to get dlmalloc code processed further + // TODO: use proper instructions when available + state.push1(builder.ins().popcnt(val, span)); + } /****************************** Binary Operators ************************************/ Operator::I32Add | Operator::I64Add => { let (arg1, arg2) = state.pop2(); diff --git a/frontend-wasm/src/code_translator/tests_unsupported.rs b/frontend-wasm/src/code_translator/tests_unsupported.rs index a1bf91517..d3dfd0962 100644 --- a/frontend-wasm/src/code_translator/tests_unsupported.rs +++ b/frontend-wasm/src/code_translator/tests_unsupported.rs @@ -59,11 +59,11 @@ fn check_unsupported(op: &Operator) { // Wasm Spec v1.0 const UNSUPPORTED_WASM_V1_OPS: &[Operator] = &[ - CallIndirect { - type_index: 0, - table_index: 0, - table_byte: 0, - }, + // CallIndirect { + // type_index: 0, + // table_index: 0, + // table_byte: 0, + // }, /****************************** Memory Operators ************************************/ F32Load { memarg: MemArg { @@ -89,8 +89,8 @@ const UNSUPPORTED_WASM_V1_OPS: &[Operator] = &[ // }, /****************************** Unary Operators ************************************/ - I32Ctz, - I32Clz, + // I32Ctz, + // I32Clz, I64Ctz, I64Clz, F32Sqrt,