Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions tests/integration/src/exec_vm.rs
Original file line number Diff line number Diff line change
@@ -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<TestFelt> {
// Reverse the arguments to counteract the StackInputs::new() reversing them into a stack
Expand All @@ -19,3 +19,25 @@ pub fn execute_vm(program: &Program, args: &[Felt]) -> Vec<TestFelt> {
.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<Vec<TestFelt>, 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())
}
10 changes: 7 additions & 3 deletions tests/integration/src/rust_masm_tests/abi_transform/tx_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -48,8 +49,11 @@ fn test_get_inputs(test_name: &str, expected_inputs: Vec<Felt>) {
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]
Expand Down