Crate gruel_compiler

Crate gruel_compiler 

Source
Expand description

Gruel compiler driver.

This crate orchestrates the compilation pipeline: Source -> Lexer -> Parser -> AstGen -> Sema -> CodeGen -> ELF

It re-exports types from the component crates for convenience.

§Diagnostic Formatting

The MultiFileFormatter provides a clean API for formatting errors and warnings:

use gruel_compiler::{MultiFileFormatter, SourceInfo, FileId};

let sources = vec![(FileId::new(1), SourceInfo::new(&source, "example.gruel"))];
let formatter = MultiFileFormatter::new(sources);

// Format an error
let error_output = formatter.format_error(&error);
eprintln!("{}", error_output);

§Tracing

This crate is instrumented with tracing spans for performance analysis. Use --log-level info or --time-passes to see timing information.

Structs§

Air
The complete AIR for a function.
AirOutput
Output from semantic analysis (compile_to_air).
AnalyzedFunction
Result of analyzing a function.
Ast
A complete source file (list of items).
AstGen
Generates RIR from an AST.
Cfg
The complete CFG for a function.
CfgBuilder
Builder that converts AIR to CFG.
CfgOutput
Output from CFG construction.
CompilationUnit
A unified compilation unit that owns all artifacts from source to machine code.
CompileErrors
A collection of compilation errors.
CompileOptions
Configuration options for compilation.
CompileOutput
Output from successful compilation.
CompileState
Intermediate compilation state after frontend processing.
CompileStateFromRir
Intermediate compilation state after frontend processing from RIR.
Diagnostic
Rich diagnostic information for errors and warnings.
ErrorCode
A unique error code for each error type.
FileId
A file identifier used to track which source file a span belongs to.
Function
A function definition.
FunctionWithCfg
A function with its typed IR (AIR) and control flow graph (CFG).
JsonDiagnostic
A diagnostic formatted for JSON output.
JsonSpan
A span in JSON format with file location and labels.
JsonSuggestion
A suggested fix in JSON format.
Lexer
Logos-based lexer that converts source text into tokens.
MergedProgram
Result of merging symbols from multiple parsed files.
MultiFileFormatter
A diagnostic formatter that supports diagnostics spanning one or more source files.
MultiFileJsonFormatter
Formats diagnostics as JSON for machine consumption.
ParsedFile
Result of parsing a single file.
ParsedProgram
Result of parsing all source files.
Parser
Chumsky-based parser that converts tokens into an AST.
Rir
The complete RIR for a source file.
RirPrinter
Printer for RIR that resolves symbols to their string values.
Sema
Semantic analyzer that converts RIR to AIR.
SemaOutput
Output from semantic analysis.
SourceFile
A source file with its path and content.
SourceInfo
Source code information for diagnostic rendering.
Span
A span representing a range in the source code.
Spur
The default key for every Rodeo, uses only 32 bits of space
StructDef
Definition of a struct type.
Suggestion
A suggested code fix that can be applied to resolve a diagnostic.
ThreadedRodeo
A concurrent string interner that caches strings quickly with a minimal memory footprint, returning a unique key to re-access it with O(1) internment and resolution.
Token
A token with its kind and source span.
Type
A type in the Gruel type system.
TypeInternPool
Thread-safe intern pool for all composite types.
ValidatedProgram
Result of validating and generating RIR from multiple parsed files.

Enums§

Applicability
How confident we are that a suggested fix is correct.
Arch
The CPU architecture of a target.
ColorChoice
Color choice for diagnostic output.
ErrorKind
The kind of compilation error.
Expr
An expression.
Item
A top-level item in a source file.
LinkerMode
Which linker to use for the final linking phase.
OptLevel
Optimization level, following standard compiler conventions.
PreviewFeature
A preview feature that can be enabled with --preview.
Target
A compilation target consisting of an architecture and operating system.
TokenKind
Token kinds in the Gruel language.
WarningKind
The kind of compilation warning.

Functions§

compile
Compile source code to an ELF binary.
compile_backend
Compile analyzed functions to a binary.
compile_frontend
Compile source code through all frontend phases (up to but not including codegen).
compile_frontend_from_ast
Compile from an already-parsed AST through all remaining frontend phases.
compile_frontend_from_ast_with_options
Compile from an already-parsed AST through all remaining frontend phases.
compile_frontend_from_ast_with_options_full
Like compile_frontend_from_ast_with_options, but additionally lets the caller suppress the on-the-fly stderr print of comptime @dbg output.
compile_frontend_from_rir_with_file_paths
Compile frontend from RIR with file paths for module resolution.
compile_frontend_from_rir_with_options
Compile from already-generated RIR through remaining frontend phases.
compile_frontend_with_options
Compile source code through all frontend phases.
compile_frontend_with_options_full
Like compile_frontend_with_options, but additionally lets the caller suppress the on-the-fly stderr print of comptime @dbg output. When suppress_comptime_dbg_print is true, output is only collected in the SemaOutput.comptime_dbg_output buffer. Used by fuzz harnesses that consume the buffer directly and don’t want noise on stderr.
compile_multi_file_with_options
Compile multiple source files to an ELF binary.
compile_to_air
Compile source code up to AIR (typed IR) without building CFG.
compile_to_cfg
Compile source code up to CFG (control flow graph).
compile_with_options
Compile source code to an ELF binary with the given options.
generate_llvm_ir
Generate LLVM textual IR from analyzed functions.
merge_symbols
Merge symbols from all parsed files into a unified program.
parse_all_files
Parse multiple source files with a shared interner.
validate_and_generate_rir_parallel
Validate symbols and generate RIR in parallel for multi-file compilation.

Type Aliases§

CompileError
A compilation error with optional source location information.
CompileResult
Result type for compilation operations.
CompileWarning
A compilation warning with optional source location information.
MultiErrorResult
Result type for operations that can produce multiple errors.
PreviewFeatures
A set of enabled preview features.