Skip to content

Commit

Permalink
fix: cast count parameter in Wasm memory.copy op to U32;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Oct 14, 2024
1 parent fe28b1c commit 645aec4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
5 changes: 3 additions & 2 deletions frontend-wasm/src/code_translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ pub fn translate_operator(
Operator::MemoryCopy { dst_mem, src_mem } => {
// See semantics at https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md#memorycopy-instruction
if *src_mem == 0 && src_mem == dst_mem {
let len = state.pop1();
let count_i32 = state.pop1();
let src_i32 = state.pop1();
let dst_i32 = state.pop1();
let count = builder.ins().bitcast(count_i32, Type::U32, span);
let dst = prepare_addr(dst_i32, &U8, None, builder, span);
let src = prepare_addr(src_i32, &U8, None, builder, span);
builder.ins().memcpy(src, dst, len, span);
builder.ins().memcpy(src, dst, count, span);
} else {
unsupported_diag!(diagnostics, "MemoryCopy: only single memory is supported");
}
Expand Down
3 changes: 1 addition & 2 deletions frontend-wasm/src/component/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
) -> WasmResult<midenc_hir::Component> {
let mut component_builder: midenc_hir::ComponentBuilder<'a> =
midenc_hir::ComponentBuilder::new(&self.session.diagnostics);
dbg!(&wasm_translation.component.initializers);
// dbg!(&wasm_translation.component.initializers);
for initializer in &wasm_translation.component.initializers {
match initializer {
GlobalInitializer::InstantiateModule(instantiate_module) => {
Expand Down Expand Up @@ -287,7 +287,6 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
let import_func_name = import_names.first().unwrap();
let (full_interface_name, _) = wasm_component.import_types[*import_idx].clone();
let function_id = recover_imported_masm_function_id(&full_interface_name, import_func_name);
dbg!(&function_id);
if is_miden_abi_module(function_id.module.as_symbol())
|| is_miden_intrinsics_module(function_id.module.as_symbol())
{
Expand Down
15 changes: 8 additions & 7 deletions tests/integration/expected/rust_sdk/basic_wallet.hir
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
(block 1 (param v4 i32)
(ret v4))

(block 2 (param v20 i32)
(br (block 1 v20)))
(block 2 (param v21 i32)
(br (block 1 v21)))

(block 3
(let (v10 u32) (bitcast v1))
Expand All @@ -76,11 +76,12 @@
(let (v13 i32) (sext v12))
(let (v14 i1) (neq v13 0))
(let (v15 i32) (select v14 v1 v3))
(let (v16 u32) (bitcast v6))
(let (v17 (ptr u8)) (inttoptr v16))
(let (v18 u32) (bitcast v0))
(let (v19 (ptr u8)) (inttoptr v18))
(memcpy v19 v17 v15)
(let (v16 u32) (bitcast v15))
(let (v17 u32) (bitcast v6))
(let (v18 (ptr u8)) (inttoptr v17))
(let (v19 u32) (bitcast v0))
(let (v20 (ptr u8)) (inttoptr v19))
(memcpy v20 v18 v16)
(br (block 2 v6)))
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/src/rust_masm_tests/rust_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ fn rust_sdk_basic_wallet() {
let artifact_name = test.artifact_name().to_string();
test.expect_wasm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.wat")]);
test.expect_ir(expect_file![format!("../../expected/rust_sdk/{artifact_name}.hir")]);
test.expect_masm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.masm")]);
}
6 changes: 3 additions & 3 deletions tools/cargo-miden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ where
// Not a built-in command, run the cargo command
let args = args.into_iter().skip_while(|arg| arg == "miden").collect::<Vec<_>>();
let cargo_args = CargoArguments::parse_from(args.clone().into_iter())?;
dbg!(&cargo_args);
// dbg!(&cargo_args);
let cache_dir = std::env::var(CACHE_DIR_ENV_VAR).map(PathBuf::from).ok();
let config_file = std::env::var(CONFIG_FILE_ENV_VAR).map(PathBuf::from).ok();
let config = Config::new(
Expand Down Expand Up @@ -225,7 +225,7 @@ where

let mut builder = tokio::runtime::Builder::new_current_thread();
let rt = builder.enable_all().build()?;
dbg!(&packages);
// dbg!(&packages);
let mut wasm_outputs = rt.block_on(async {
let client = config.client(cache_dir, cargo_args.offline).await?;
run_cargo_command(
Expand All @@ -252,7 +252,7 @@ where
&env_vars,
)?;
}
dbg!(&wasm_outputs);
// dbg!(&wasm_outputs);
match build_output_type {
OutputType::Wasm => wasm_outputs,
OutputType::Masm => {
Expand Down

0 comments on commit 645aec4

Please sign in to comment.