diff --git a/tests/integration/src/exec_vm.rs b/tests/integration/src/exec_vm.rs index f1db1d4ce..ca2a950b6 100644 --- a/tests/integration/src/exec_vm.rs +++ b/tests/integration/src/exec_vm.rs @@ -1,10 +1,10 @@ use miden_core::{Program, StackInputs}; -use miden_processor::{DefaultHost, ExecutionOptions}; +use miden_processor::{DefaultHost, ExecutionError, ExecutionOptions}; use midenc_hir::Felt; use crate::felt_conversion::TestFelt; -/// Execute the module using the VM with the given arguments +/// Execute the program using the VM with the given arguments /// Arguments are expected to be in the order they are passed to the entrypoint function pub fn execute_vm(program: &Program, args: &[Felt]) -> Vec { // Reverse the arguments to counteract the StackInputs::new() reversing them into a stack @@ -19,3 +19,25 @@ pub fn execute_vm(program: &Program, args: &[Felt]) -> Vec { .expect("failed to execute program on VM"); trace.stack_outputs().stack().iter().map(|i| TestFelt(*i)).collect() } + +/// Execute the program using the VM with the given arguments +/// Prints the trace (VM state) after each step to stdout +/// Arguments are expected to be in the order they are passed to the entrypoint function +#[allow(unused)] +pub fn execute_vm_tracing( + program: &Program, + args: &[Felt], +) -> Result, ExecutionError> { + // Reverse the arguments to counteract the StackInputs::new() reversing them into a stack + let args_reversed = args.iter().copied().rev().collect(); + let stack_inputs = StackInputs::new(args_reversed).expect("invalid stack inputs"); + let vm_state_iterator = + miden_processor::execute_iter(program, stack_inputs, DefaultHost::default()); + let mut last_stack = Vec::new(); + for vm_state in vm_state_iterator { + let vm_state = vm_state?; + eprintln!("{}", vm_state); + last_stack.clone_from(&vm_state.stack); + } + Ok(last_stack.into_iter().map(TestFelt).collect()) +} diff --git a/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs b/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs index 1f712f15b..0af3771bc 100644 --- a/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs +++ b/tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs @@ -3,8 +3,9 @@ use std::fmt::Write; use expect_test::expect_file; use miden_assembly::LibraryPath; use miden_core::{Felt, FieldElement}; +use miden_processor::ExecutionError; -use crate::CompilerTest; +use crate::{exec_vm::execute_vm_tracing, execute_emulator, execute_vm, CompilerTest}; #[allow(unused)] fn setup_log() { @@ -48,8 +49,11 @@ fn test_get_inputs(test_name: &str, expected_inputs: Vec) { test.expect_ir(expect_file![format!("../../../expected/{artifact_name}.hir")]); test.expect_masm(expect_file![format!("../../../expected/{artifact_name}.masm")]); - let _vm_program = test.vm_masm_program(); - // let _vm_out = execute_vm(&vm_program, &[]); + let vm_program = test.vm_masm_program(); + // let vm_out = execute_vm_tracing(&vm_program, &[]).unwrap(); + + // let ir_program = test.ir_masm_program(); + // let emul_out = execute_emulator(ir_program.clone(), &[]); } #[test]