Skip to main content

Crate hypothalamus

Crate hypothalamus 

Source
Expand description

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, lowering it into LLVM IR, and optionally driving external LLVM tools through reusable target profiles.

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.bf".to_string()),
        bounds_check: false,
        runtime: hypothalamus::llvm::Runtime::Hosted,
    },
)
.expect("LLVM IR");

assert!(ir.contains("define i32 @main()"));

Lower-level callers can use bf, ir, and llvm directly. Tooling that wants Hypothalamus’ command-line behavior without shelling out can use driver with a target::TargetProfile.

Re-exports§

pub use driver::CompilerConfig;
pub use driver::EmitKind;
pub use driver::OptLevel;
pub use driver::compile_to_llvm;
pub use driver::compile_with_tools;
pub use target::RuntimeAbi;
pub use target::TargetImageFormat;
pub use target::TargetProfile;

Modules§

bf
Brainfuck parser and optimizer. Brainfuck parsing and local normalization.
diagnostics
Toolchain and target diagnostics. Toolchain diagnostics for the command-line tools doctor command.
driver
Compiler-driver configuration and LLVM tool invocation. Compiler driver types and tool invocation helpers.
ir
Optimized intermediate representation and Brainfuck-specific optimization. Optimized intermediate representation for Brainfuck programs.
llvm
LLVM IR backend for parsed Brainfuck operations. LLVM IR generation for normalized Brainfuck operations.
target
Named target profiles and runtime ABI defaults. Target profiles for hosted and freestanding Brainfuck output.
targets
Target-specific complete-image builders. Target-specific complete-image builders.

Constants§

DEFAULT_TAPE_SIZE
Default number of byte cells in the generated Brainfuck tape.