Skip to content

Commit

Permalink
Add test case for bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ejrgilbert committed Oct 1, 2024
1 parent 7e342ec commit 44a9341
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions tests/func_builder.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use orca_wasm::ir::id::FunctionID;
use orca_wasm::ir::id::{FunctionID, TypeID};
use orca_wasm::opcode::Instrumenter;
use orca_wasm::Opcode;
use orca_wasm::{DataType, Opcode};
use orca_wasm::{Location, Module};
use std::process::Command;
use log::trace;
use orca_wasm::ir::function::FunctionBuilder;
use orca_wasm::iterator::iterator_trait::Iterator;
use orca_wasm::iterator::module_iterator::ModuleIterator;

// #[test]
// build factorial from scratch
Expand Down Expand Up @@ -61,3 +65,33 @@ fn run_start_orca_default() {
let out = wasmprinter::print_bytes(result.clone()).expect("couldn't translate Wasm to wat");
println!("{}", out);
}
#[test]
// test start function instrumentation with FunctionModifier
fn add_import_and_local_fn_then_iterate() {
let file_name = "tests/test_inputs/handwritten/modules/_start.wat";
let wasm = wat::parse_file(file_name).expect("couldn't convert the input wat to Wasm");
let mut module = Module::parse(&wasm, false).expect("Unable to parse");
// add an imported function AND THEN a new local function
module.add_import_func("new".to_string(), "import".to_string(), TypeID(0));
assert_eq!(module.num_import_func(), 1);

let params = vec![];
let results = vec![DataType::I32];

let mut new_func = FunctionBuilder::new(&params, &results);
new_func.i32_const(1);
new_func.finish_module(&mut module);

// now iterate over module
let mut mod_it = ModuleIterator::new(&mut module, &vec![]);
loop {
let _op = mod_it.curr_op();
if mod_it.next().is_none() {
break;
};
}

let result = module.encode();
let out = wasmprinter::print_bytes(result.clone()).expect("couldn't translate Wasm to wat");
println!("{}", out);
}

0 comments on commit 44a9341

Please sign in to comment.