Build Graph Overview
The following diagram illustrates the complete build pipeline:Pipeline Stages
The build process consists of seven distinct stages, orchestrated by the target system.1. Frontend Compilation
Location:src/frontend.rs
Input:
- Dryft source code (
source.dry) - Standard library (
stdlib.dry)
- Lexical analysis and parsing
- Semantic analysis
- Code generation using the selected backend
2. Backend Code Generation
Location:src/backends/
Available backends:
- C99 (
src/backends/c99/): Generates C99-compliant C code - x86 (
src/backends/x86/): Generates NASM x86-64 assembly
Backend trait, providing methods for:
- Arithmetic operations (
fun_add,fun_sub, etc.) - Control flow (
create_conditional_statement,create_loop_block) - Functions (
create_function,user_function) - Variables (
create_variable,read_variable,write_variable) - Stack operations (
fun_copy,fun_drop,fun_swap)
intermediate field
3. Standard Library Compilation
Command: Defined in target’sstdlib field
Example (GCC target):
- Compiles native bindings for Dryft’s standard library
- Creates a separate object file for linking
obj2 in diagram)
Note: Some targets (like the x86 target) may skip this step if they don’t use external standard library bindings.
4. Assembly
Command: Defined in target’sassemble field
Example (GCC target):
- Passes the IR to an external compiler/assembler
- Converts IR into an object file
obj1 in diagram)
Skip with: --assembly-only flag prevents this and all subsequent steps
5. Linking
Command: Defined in target’slink field
Example (GCC target):
- Links program object with standard library object
- Resolves external symbols
- Produces final executable
--object-only flag stops after assembly, skipping the link step
6. Interpretation (Optional)
Command: Defined in target’sinterpret field (default: ./a.out)
When executed:
- Automatically in REPL mode after each input
- With file compilation when using the
--runflag
- Executes the compiled binary
- May invoke a VM or interpreter for non-native targets
Implementation Details
Build Functions
The build process is implemented insrc/main.rs with these key functions:
build_file() (line 85)
Compiles a source file to IR:
stdlib() (line 102)
Compiles the standard library using shell command:
assemble() (line 108)
Runs the external assembler/compiler:
link() (line 113)
Links object files into executable:
interpret() (line 122)
Executes the final binary:
Main Compilation Flow
Fromsrc/main.rs:219-235, the main function orchestrates the build:
Intermediate Files
Depending on your target and flags, the build process creates these intermediate files:| File | Stage | Description | Example |
|---|---|---|---|
| IR source | Frontend | Backend-specific intermediate representation | build/ir.c, build/ir.asm |
| Program object | Assembly | Compiled program code | build/ir.o |
| Stdlib object | Stdlib compilation | Standard library native code | build/stdc.o |
| Executable | Linking | Final runnable binary | a.out |
Build Flags and Their Effects
--assembly-only
- Frontend compilation ✓
- Backend code generation ✓
- Standard library compilation ✗
- Assembly ✗
- Linking ✗
--object-only
- Frontend compilation ✓
- Backend code generation ✓
- Standard library compilation ✓
- Assembly ✓
- Linking ✗
--run
- Frontend compilation ✓
- Backend code generation ✓
- Standard library compilation ✓
- Assembly ✓
- Linking ✓
- Interpretation ✓
Error Handling
Errors can occur at any stage:- Frontend errors: Syntax errors, semantic errors in Dryft code
- Backend errors: Code generation failures
- Assembly errors: Invalid IR, missing tools (gcc, nasm)
- Linking errors: Undefined symbols, missing libraries
- Runtime errors: Execution failures (segfaults, etc.)
Customizing the Build Process
You can customize any stage by creating a custom target file. See Target System for details on:- Changing compiler flags
- Using different assemblers/linkers
- Cross-compilation setups
- Alternative execution environments