Skip to content

Commit

Permalink
rexport macro uses
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Nov 22, 2024
1 parent 07597a4 commit ac92d2d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions hugr-llvm/src/emit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ impl Default for SimpleHugrConfig {
}
}

#[doc(hidden)]
pub use hugr_core;
#[doc(hidden)]
pub use inkwell;
#[doc(hidden)]
pub use insta;

/// A macro used to check the emission of a Hugr module,
/// and to assert the correctness of the emitted LLVM IR using [insta].
///
Expand All @@ -171,37 +178,41 @@ impl Default for SimpleHugrConfig {
macro_rules! check_emission {
// Call the macro with a snapshot name.
($snapshot_name:expr, $hugr: ident, $test_ctx:ident) => {{
let root = $crate::utils::fat::FatExt::fat_root::<hugr_core::ops::Module>(&$hugr).unwrap();
let root =
$crate::utils::fat::FatExt::fat_root::<$crate::emit::test::hugr_core::ops::Module>(
&$hugr,
)
.unwrap();
let emission =
$crate::emit::test::Emission::emit_hugr(root, $test_ctx.get_emit_hugr()).unwrap();

let mut settings = insta::Settings::clone_current();
let mut settings = $crate::emit::test::insta::Settings::clone_current();
let new_suffix = settings
.snapshot_suffix()
.map_or("pre-mem2reg".into(), |x| format!("pre-mem2reg@{x}"));
settings.set_snapshot_suffix(new_suffix);
settings.bind(|| {
let mod_str = emission.module().to_string();
if $snapshot_name == "" {
insta::assert_snapshot!(mod_str)
$crate::emit::test::insta::assert_snapshot!(mod_str)
} else {
insta::assert_snapshot!($snapshot_name, mod_str)
$crate::emit::test::insta::assert_snapshot!($snapshot_name, mod_str)
}
});

emission.verify().unwrap();

emission.opt(|| {
let pb = inkwell::passes::PassManager::create(());
let pb = $crate::emit::test::inkwell::passes::PassManager::create(());
pb.add_promote_memory_to_register_pass();
pb
});

let mod_str = emission.module().to_string();
if $snapshot_name == "" {
insta::assert_snapshot!(mod_str)
$crate::emit::test::insta::assert_snapshot!(mod_str)
} else {
insta::assert_snapshot!($snapshot_name, mod_str)
$crate::emit::test::insta::assert_snapshot!($snapshot_name, mod_str)
}
emission
}};
Expand Down

0 comments on commit ac92d2d

Please sign in to comment.