1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Hypothalamus' reusable compiler library.
//!
//! The crate exposes the pipeline stages used by the command-line compiler:
//! parsing Brainfuck source into a compact operation tree, optimizing that tree
//! into a backend-oriented intermediate representation, then lowering it into
//! LLVM IR.
//!
//! Typical library usage starts with [`bf::parse`] and passes the resulting
//! operations to [`llvm::generate_module`]:
//!
//! ```
//! use hypothalamus::bf;
//! use hypothalamus::llvm::{self, LlvmOptions};
//! use hypothalamus::DEFAULT_TAPE_SIZE;
//!
//! let ops = bf::parse(b"++.").expect("valid Brainfuck");
//! let ir = llvm::generate_module(
//! &ops,
//! &LlvmOptions {
//! tape_size: DEFAULT_TAPE_SIZE,
//! target_triple: None,
//! source_filename: Some("example.b".to_string()),
//! bounds_check: false,
//! },
//! )
//! .expect("LLVM IR");
//!
//! assert!(ir.contains("define i32 @main()"));
//! ```
//!
//! Hypothalamus intentionally keeps policy in the binary and the mechanics in
//! this crate. The library does not invoke `clang` or `lli`, write files, choose
//! output paths, or validate platform toolchains; it only parses source,
//! optimizes operations, and produces text LLVM IR.
/// Brainfuck parser and optimizer.
/// Optimized intermediate representation and Brainfuck-specific optimization.
/// LLVM IR backend for parsed Brainfuck operations.
/// Default number of byte cells in the generated Brainfuck tape.
///
/// This matches the conventional 30,000-cell tape used by many Brainfuck
/// implementations. The parser itself is independent of the tape size; this
/// value is consumed by the LLVM backend when it declares the global tape.
pub const DEFAULT_TAPE_SIZE: usize = 30_000;