A modern multi-target compiler for a simple C-like language featuring advanced code generation backends and WebAssembly integration with WasmEdge AOT optimization support.
- Variables:
auto x;(local),global y;(global) - Assignment:
x = 5; - Arithmetic:
+,-,*,/,%with operator precedence - Control Flow:
if/else,whileloops,returnstatements - Comparisons:
==,!=,<,>,<=,>= - Bitwise Operations:
<<,>>,&,|,^ - Function Calls:
add(x);,externdeclarations
The Bboop compiler features a sophisticated plugin-based target system supporting multiple architectures:
- x86_64: Native Linux x86-64 assembly generation
- ARM64: ARM AArch64 assembly generation
- ARM32: ARM 32-bit assembly generation
- WebAssembly: Standard WASM module generation
- WasmEdge AOT: Optimized WebAssembly with ahead-of-time compilation
./compiler -t x86_64 yourfile.b # Default x86-64 target
./compiler -t arm64 yourfile.b # ARM 64-bit target
./compiler -t wasm yourfile.b # Standard WebAssembly
./compiler -t wasmedge yourfile.b # WasmEdge AOT optimized
./compiler --list-targets # Show all available targetsThe WasmEdge target provides advanced ahead-of-time compilation with several key optimizations:
- AOT Pre-compilation: Converts WebAssembly to native machine code at compile time
- Memory Layout Optimization: Efficient memory management for AOT execution
- Runtime Integration: Seamless integration with WasmEdge runtime environment
- Performance Benchmarking: Built-in comparison tools for optimization analysis
Bboop Compiler Optimizations:
- Constant folding and propagation at IR level
- Dead code elimination
- Register allocation optimization
- Loop optimization techniques
WasmEdge AOT Optimizations:
- LLVM-based backend optimizations
- Native code generation with aggressive inlining
- Runtime profile-guided optimization
- Advanced vectorization and parallelization
# Run performance comparison
make benchmark
./tests/benchmark_wasmedge_aot.shThe WasmEdge AOT pipeline typically shows 2-5x performance improvement over interpreted WebAssembly, while Bboop's IR-level optimizations provide competitive performance for mathematical workloads.
-
Clone or download this repository.
-
Build using Makefile:
make
This will produce the
compilerexecutable in the project directory. -
Install WasmEdge (optional, for AOT support):
# Install WasmEdge runtime curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash
./compiler yourfile.b # Compile to x86_64 assembly
./compiler yourfile.b --print-ir # Print intermediate representation
./compiler -t wasm yourfile.b # Compile to WebAssembly./compiler -t wasmedge yourfile.b --asm-only # Generate WasmEdge-optimized WAT
./compiler --help # Show all optionsmake test # Run all test cases
./tests/benchmark_aot.sh # Performance benchmarkingsrc/
├── main.cpp # Compiler entry point
├── Parser.cpp/.h # Language parser
├── Tokenizer.cpp/.h # Lexical analyzer
├── ir.cpp # IR generation & optimization
├── target.cpp # Target management system
└── codegen/ # Code generation backends
├── x86_64_generator.cpp/.h # x86-64 backend
├── arm_generator.cpp/.h # ARM backend
├── wasm_generator.cpp/.h # WebAssembly backend
└── wasmedge_generator.cpp/.h # WasmEdge AOT backend
include/ # Header files
tests/ # Test suite and benchmarks
- Tokenization → Lexical analysis
- Parsing → Abstract Syntax Tree (AST) generation
- IR Generation → Three-address code intermediate representation
- Optimization → Multiple optimization passes
- Target Selection → Backend-specific code generation
- Assembly/Binary → Final executable or WebAssembly module
main() {
extern exit;
auto x, y, result;
x = 10;
y = 20;
if (x < y) {
result = x * y + 5;
while (result > 100) {
result = result - 50;
}
}
exit(result);
}- Three-address code format for efficient optimization
- Static Single Assignment (SSA) form support
- Control flow graph construction
- Data flow analysis capabilities
Bboop Compiler IR Optimizations:
- Constant folding and propagation
- Dead code elimination
- Common subexpression elimination
- Loop-invariant code motion
- Register allocation with graph coloring
WasmEdge AOT Pipeline Optimizations:
- LLVM backend optimizations (O2/O3 level)
- Aggressive function inlining
- Vectorization and loop unrolling
- Profile-guided optimization (PGO)
- Native code generation with runtime linking
The compiler includes built-in benchmarking tools to compare optimization effectiveness:
# Compare native vs WasmEdge AOT performance
./tests/benchmark_wasmedge_aot.sh
# Detailed timing breakdown
./tests/benchmark_heavy_detailed.shTypical Performance Results:
- Native x86_64: Baseline performance (1.0x)
- Bboop IR Optimized: 15-25% improvement over naive codegen
- WebAssembly (wasmtime): 60-80% of native performance
- WasmEdge AOT: 85-95% of native performance
The modular architecture makes it easy to add new targets:
- Create new generator in
src/codegen/your_target_generator.cpp - Implement the
TargetGeneratorinterface - Register target in
src/target.cpp - Add build rules to
Makefile
This project is licensed under the MIT License - see the LICENCE file for details.
- WasmEdge Community: For the excellent AOT compilation framework
- LLVM Project: For optimization techniques and IR design inspiration
- WebAssembly Specification: For standardized bytecode format