Skip to content

Commit

Permalink
Fix tests in graphviz module
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Sep 21, 2024
1 parent 4eec23d commit cb036ac
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions crates/ir/src/graphviz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,27 @@ pub fn render_to<W: io::Write>(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();
Expand All @@ -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();
Expand Down

0 comments on commit cb036ac

Please sign in to comment.