From cb036accbf25a626245ace6abe2fb4bcf7314e08 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sat, 21 Sep 2024 17:47:09 +0200 Subject: [PATCH] Fix tests in graphviz module --- crates/ir/src/graphviz/mod.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/crates/ir/src/graphviz/mod.rs b/crates/ir/src/graphviz/mod.rs index 1c57b293..049be19b 100644 --- a/crates/ir/src/graphviz/mod.rs +++ b/crates/ir/src/graphviz/mod.rs @@ -19,13 +19,27 @@ pub fn render_to(func: &Function, output: &mut W) -> io::Result<() #[cfg(test)] mod test { - use crate::{builder::test_util::test_func_builder, Type}; + + use macros::inst_set; + + use crate::{ + builder::test_util::test_func_builder, + inst::{ + arith::Add, + control_flow::{Br, Jump, Phi, Return}, + }, + Type, + }; use super::*; + #[inst_set(InstKind = "TestInstKind")] + struct TestInstSet(Add, Return, Jump, Phi, Br); + #[test] fn test_dump_ir() { let mut builder = test_func_builder(&[Type::I64], Type::Void); + let is = TestInstSet::new(); let entry_block = builder.append_block(); let then_block = builder.append_block(); @@ -35,20 +49,26 @@ mod test { let arg0 = builder.args()[0]; builder.switch_to_block(entry_block); - builder.br(arg0, then_block, else_block); + let br = Br::new(&is, arg0, then_block, else_block); + builder.insert_inst_no_result(br); builder.switch_to_block(then_block); let v1 = builder.make_imm_value(1i64); - builder.jump(merge_block); + let jump = Jump::new(&is, merge_block); + builder.insert_inst_no_result(jump); builder.switch_to_block(else_block); let v2 = builder.make_imm_value(2i64); - builder.jump(merge_block); + let jump = Jump::new(&is, merge_block); + builder.insert_inst_no_result(jump); builder.switch_to_block(merge_block); - let v3 = builder.phi(Type::I64, &[(v1, then_block), (v2, else_block)]); - builder.add(v3, arg0); - builder.ret(None); + let phi = Phi::new(&is, vec![(v1, then_block), (v2, else_block)], Type::I64); + let v3 = builder.insert_inst(phi, Type::I64); + let add = Add::new(&is, v3, arg0); + builder.insert_inst(add, Type::I64); + let ret = Return::new(&is, None); + builder.insert_inst_no_result(ret); builder.seal_all(); let module = builder.finish().build();