A modern B programming language compiler written in Go with LLVM IR backend and clang-like command-line interface.
The B programming language was developed by Ken Thompson and Dennis Ritchie at Bell Labs in 1969 as the predecessor to C.
Status: ✅ Feature-Complete • 225 tests passing • 75.1% coverage
# Build everything
make
# Compile and run a B program (automatic linking)
./blang examples/hello.b
./hello
Output: Hello, World!
- Go (>=1.21)
- clang/LLVM toolchain
- make
make
make install # installs to $HOME/.local
# ensure PATH contains $HOME/.local/bin
export PATH="$HOME/.local/bin:$PATH" # add to your shell profile
blang -V
make uninstall
make install DESTDIR=/custom/prefix
- Complete B Language Support: All B language features implemented
- Cross-platform: Runs natively on Linux (x86_64, aarch64) and macOS (x86_64, aarch64)
- Clang-like CLI Interface: Professional command-line options and workflow
- Multiple Output Formats: Executable, object files, assembly, LLVM IR
- LLVM IR Backend: Portable, optimized code generation
- Comprehensive Testing: 225 tests across 8 organized test files
- Modern Go Implementation: Clean, maintainable codebase
The blang
compiler provides a clang-like command-line interface with comprehensive options:
# Generate executable
blang hello.b -o hello
# Generate LLVM IR
blang -emit-llvm hello.b -o hello.ll
# Generate object file
blang -c hello.b -o hello.o
# Generate assembly
blang -S hello.b -o hello.s
Option | Description |
---|---|
-o <file> |
Place output into <file> |
-c |
Compile and assemble, but do not link |
-S |
Compile only; do not assemble or link |
-emit-llvm |
Emit LLVM IR instead of executable |
Option | Description |
---|---|
-O0 , -O1 , -O2 , -O3 |
Optimization levels |
-g |
Generate debug information |
-v |
Verbose output |
Option | Description |
---|---|
-L <dir> |
Add directory to library search path (can be repeated) |
-l <lib> |
Link with library (can be repeated) |
Option | Description |
---|---|
-save-temps |
Do not delete intermediate files |
-h , --help |
Display help information |
-V , --version |
Display version information |
# Optimized executable with debug info
blang -O2 -g hello.b -o optimized
# Verbose compilation
blang -v hello.b
# Multiple library directories and libraries
blang hello.b -L/usr/lib -L/usr/local/lib -lpthread -lmath
# Options after arguments (flexible ordering)
blang hello.b -O2 -v
# All flags combined
blang -v -O3 -g -save-temps hello.b
examples/hello.b
- Hello world using write()examples/fibonacci.b
- Fibonacci calculatorexamples/fizzbuzz.b
- FizzBuzz 1-100examples/e-2.b
- E-2 constant calculationexamples/b.b
- B compiler for PDP-7
# Run all tests
make test
# Run CLI-specific tests
go test -v -run TestCLI
# Run specific test categories
go test -v -run TestCLIBasicOptions
go test -v -run TestCLIOutputFormats
- CLI Usage Guide - Comprehensive command-line interface guide
- B Language Reference - Original manual by S.C.Johnson
- B Tutorial - A tutorial introduction by B.W.Kernighan
- Users' Reference to B - Ken Thompson's guide
- LLVM Documentation - LLVM IR reference
- BCause - C-based B compiler (inspiration)
MIT License - see LICENSE file.