use hypothalamus::DEFAULT_TAPE_SIZE;
use hypothalamus::bf;
use hypothalamus::llvm::{self, LlvmOptions};
fn compile_example(source: &[u8], name: &str) -> String {
let ops = bf::parse(source).expect("example should parse");
llvm::generate_module(
&ops,
&LlvmOptions {
tape_size: DEFAULT_TAPE_SIZE,
target_triple: None,
source_filename: Some(name.to_string()),
bounds_check: false,
runtime: llvm::Runtime::Hosted,
},
)
.expect("example should lower to LLVM IR")
}
#[test]
fn hello_example_lowers_to_llvm() {
let ir = compile_example(include_bytes!("../examples/hello.bf"), "examples/hello.bf");
assert!(ir.contains("define i32 @main()"));
}
#[test]
fn scan_loop_fixture_lowers_to_explicit_scan() {
let ir = compile_example(b"+[>]", "scan-loop.bf");
assert!(ir.contains("define i32 @main()"));
assert!(ir.contains("scan_check_"));
}
#[test]
fn multiply_transfer_fixture_lowers_to_straight_line_ir() {
let ir = compile_example(b"+++++[->+++>++<<]>>.", "multiply-transfer.bf");
assert!(ir.contains("define i32 @main()"));
assert!(ir.contains("mul i8"));
assert!(!ir.contains("loop_check_"));
}