Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Compiler_Driver Class Reference

Reusable orchestration object for compiler pipeline experiments. More...

#include <Compiler_Driver.H>

Collaboration diagram for Aleph::Compiler_Driver:
[legend]

Public Member Functions

 Compiler_Driver (const Compiler_Driver_Options &options={}, const size_t arena_size=1<< 20)
 Constructs a driver with one stable set of pipeline options.
 
 Compiler_Driver (const Compiler_Driver &)=delete
 
Compiler_Driver & operator= (const Compiler_Driver &)=delete
 
const Compiler_Driver_Options & options () const noexcept
 Returns the immutable construction-time configuration.
 
size_t arena_size () const noexcept
 Returns the arena size shared by the internal contexts.
 
void clear () noexcept
 Clears all stage outputs while preserving host prelude bindings.
 
bool bind_host_function (const std::string &name, const Interpreter_Host_Function callback, void *user_data=nullptr)
 Binds one host function into the persistent runtime prelude.
 
bool execute_sources (const DynArray< Compiler_Driver_Source > &inputs, const Compiler_Driver_Action action=Compiler_Driver_Action::Run)
 Runs the pipeline over in-memory sources.
 
bool execute_files (const DynArray< std::string > &paths, const Compiler_Driver_Action action=Compiler_Driver_Action::Run)
 Runs the pipeline over source files loaded from disk.
 
bool execute_source (const std::string &name, const std::string &text, const Compiler_Driver_Action action=Compiler_Driver_Action::Run)
 Convenience overload for a single in-memory source.
 
bool ok () const noexcept
 Returns whether the last driver action finished successfully.
 
Compiler_Driver_Action last_action () const noexcept
 Returns the last requested action.
 
const Source_Manager & source_manager () const noexcept
 Returns the shared source manager for the last run.
 
const Diagnostic_Engine & diagnostic_engine () const noexcept
 Returns the diagnostic engine populated by the last run.
 
const Compiler_Typed_Semantic_Analyzer & typed_analysis () const noexcept
 Returns the typed semantic analyzer state from the last run.
 
const DynArray< Compiler_Module * > & parsed_ast_modules () const noexcept
 Returns the parsed per-file AST modules from the last run.
 
const Compiler_Module * merged_ast_module () const noexcept
 Returns the merged AST module from the last run.
 
const Compiler_HIR_Module * hir_module () const noexcept
 Returns the lowered HIR module from the last run, when available.
 
const Compiler_IR_Module * ir_module () const noexcept
 Returns the lowered IR module from the last run, when available.
 
const Compiler_Bytecode_Module * bytecode_module () const noexcept
 Returns the lowered bytecode module from the last run, when available.
 
const Compiler_C_Backend_Emission & c_emission () const noexcept
 Returns the C emission payload from the last emit-c action.
 
const Compiler_Driver_Run_Output & run_output () const noexcept
 Returns the run summary from the last run action.
 
const DynArray< std::string > & errors () const noexcept
 Returns non-diagnostic driver-level hard errors.
 
const DynArray< std::string > & warnings () const noexcept
 Returns non-fatal driver-level warnings.
 
const DynArray< Compiler_Driver_Artifact > & artifacts () const noexcept
 Returns all recorded artifacts from the last run.
 
const Compiler_Driver_Artifact * find_artifact (std::string_view label) const noexcept
 Finds one artifact by label.
 
std::string diagnostics_text () const
 Renders diagnostics from the last run as plain text.
 

Private Member Functions

void append_error (const std::string &text)
 
void append_warning (const std::string &text)
 
void emit_driver_diagnostic (const Source_Span &span, const std::string &code, const std::string &message, const std::string &note="", const std::string &help="")
 
void record_text_artifact (const std::string &label, std::string text)
 
size_t find_source_index (std::string_view name) const noexcept
 
void record_import_order_artifact ()
 
void record_ast_artifacts ()
 
bool resolve_import_order ()
 
void merge_modules_from_order ()
 
void record_diagnostics_artifact ()
 
void record_driver_messages_artifact ()
 
bool parse_registered_sources ()
 
bool run_typed_semantics ()
 
bool lower_hir ()
 
bool lower_ir ()
 
bool lower_bytecode ()
 
bool emit_c ()
 
bool execute_hir_runtime ()
 
void append_run_failure_if_needed ()
 
bool finalize (const Compiler_Driver_Action action)
 
bool prepare_inputs (const DynArray< Compiler_Driver_Source > &inputs)
 

Private Attributes

Compiler_Driver_Options config_
 
Source_Manager sources_
 
Diagnostic_Engine diagnostics_
 
Compiler_Ast_Context ast_ctx_
 
Compiler_HIR_Context hir_ctx_
 
Compiler_IR_Context ir_ctx_
 
Compiler_Bytecode_Context bytecode_ctx_
 
Compiler_Typed_Semantic_Analyzer typed_
 
Interpreter_Runtime runtime_
 
size_t arena_bytes_ = 0
 
DynArray< std::string > source_names_
 
DynArray< Source_File_Id > source_file_ids_
 
DynArray< Compiler_Module * > parsed_modules_
 
DynArray< size_t > merge_order_
 
DynArray< Compiler_Driver_Artifact > artifacts_
 
DynArray< std::string > errors_
 
DynArray< std::string > warnings_
 
Compiler_Module * merged_ast_ = nullptr
 
Compiler_HIR_Module * hir_module_ = nullptr
 
Compiler_IR_Module * ir_module_ = nullptr
 
Compiler_Bytecode_Module * bytecode_module_ = nullptr
 
Compiler_C_Backend_Emission c_emission_
 
Compiler_Driver_Run_Output run_output_
 
Compiler_Driver_Action last_action_ = Compiler_Driver_Action::Parse_Only
 

Detailed Description

Reusable orchestration object for compiler pipeline experiments.

A driver object owns all contexts required by the current pipeline stages so that pointers returned by getters remain valid until clear() or destruction. The object can be reused across multiple runs; host functions bound into the embedded Interpreter_Runtime prelude remain installed.

Definition at line 106 of file Compiler_Driver.H.

Constructor & Destructor Documentation

◆ Compiler_Driver() [1/2]

Aleph::Compiler_Driver::Compiler_Driver ( const Compiler_Driver_Options &  options = {},
const size_t  arena_size = 1 << 20 
)
inlineexplicit

Constructs a driver with one stable set of pipeline options.

Parameters
optionsShared parser/sema/runtime/backend configuration.
arena_sizeArena capacity used by AST/HIR/IR/bytecode contexts.

Definition at line 432 of file Compiler_Driver.H.

◆ Compiler_Driver() [2/2]

Aleph::Compiler_Driver::Compiler_Driver ( const Compiler_Driver &  )
delete

Member Function Documentation

◆ append_error()

void Aleph::Compiler_Driver::append_error ( const std::string &  text)
inlineprivate

Definition at line 135 of file Compiler_Driver.H.

References Aleph::DynArray< T >::append(), and errors_.

◆ append_run_failure_if_needed()

◆ append_warning()

void Aleph::Compiler_Driver::append_warning ( const std::string &  text)
inlineprivate

Definition at line 140 of file Compiler_Driver.H.

References Aleph::DynArray< T >::append(), and warnings_.

◆ arena_size()

size_t Aleph::Compiler_Driver::arena_size ( ) const
inlinenoexcept

Returns the arena size shared by the internal contexts.

Definition at line 450 of file Compiler_Driver.H.

◆ artifacts()

const DynArray< Compiler_Driver_Artifact > & Aleph::Compiler_Driver::artifacts ( ) const
inlinenoexcept

Returns all recorded artifacts from the last run.

Definition at line 727 of file Compiler_Driver.H.

◆ bind_host_function()

bool Aleph::Compiler_Driver::bind_host_function ( const std::string &  name,
const Interpreter_Host_Function  callback,
void *  user_data = nullptr 
)
inline

Binds one host function into the persistent runtime prelude.

Definition at line 486 of file Compiler_Driver.H.

References Aleph::Interpreter_Runtime::bind_host_function(), and Aleph::blossom_maximum_cardinality_matching().

◆ bytecode_module()

const Compiler_Bytecode_Module * Aleph::Compiler_Driver::bytecode_module ( ) const
inlinenoexcept

Returns the lowered bytecode module from the last run, when available.

Definition at line 697 of file Compiler_Driver.H.

◆ c_emission()

const Compiler_C_Backend_Emission & Aleph::Compiler_Driver::c_emission ( ) const
inlinenoexcept

Returns the C emission payload from the last emit-c action.

Definition at line 703 of file Compiler_Driver.H.

◆ clear()

◆ diagnostic_engine()

const Diagnostic_Engine & Aleph::Compiler_Driver::diagnostic_engine ( ) const
inlinenoexcept

Returns the diagnostic engine populated by the last run.

Definition at line 661 of file Compiler_Driver.H.

◆ diagnostics_text()

std::string Aleph::Compiler_Driver::diagnostics_text ( ) const
inline

Renders diagnostics from the last run as plain text.

Definition at line 746 of file Compiler_Driver.H.

References out, and Aleph::Diagnostic_Engine::render_plain().

◆ emit_c()

◆ emit_driver_diagnostic()

void Aleph::Compiler_Driver::emit_driver_diagnostic ( const Source_Span &  span,
const std::string &  code,
const std::string &  message,
const std::string &  note = "",
const std::string &  help = "" 
)
inlineprivate

◆ errors()

const DynArray< std::string > & Aleph::Compiler_Driver::errors ( ) const
inlinenoexcept

Returns non-diagnostic driver-level hard errors.

Definition at line 715 of file Compiler_Driver.H.

◆ execute_files()

bool Aleph::Compiler_Driver::execute_files ( const DynArray< std::string > &  paths,
const Compiler_Driver_Action  action = Compiler_Driver_Action::Run 
)
inline

Runs the pipeline over source files loaded from disk.

Parameters
pathsOrdered file paths to register in the Source_Manager.
actionFinal stage requested by the caller.
Returns
true when the requested action finished successfully.

Definition at line 564 of file Compiler_Driver.H.

References Aleph::DynArray< T >::access(), Aleph::DynArray< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Emit_Bytecode, Aleph::Emit_C, Aleph::HIR, Aleph::IR, Aleph::DynArray< T >::is_empty(), Aleph::Source_Manager::load_file(), Aleph::Parse_Only, Aleph::Run, Aleph::Sema_Only, and Aleph::DynArray< T >::size().

◆ execute_hir_runtime()

◆ execute_source()

bool Aleph::Compiler_Driver::execute_source ( const std::string &  name,
const std::string &  text,
const Compiler_Driver_Action  action = Compiler_Driver_Action::Run 
)
inline

Convenience overload for a single in-memory source.

Definition at line 633 of file Compiler_Driver.H.

References Aleph::DynArray< T >::append(), and Aleph::blossom_maximum_cardinality_matching().

◆ execute_sources()

bool Aleph::Compiler_Driver::execute_sources ( const DynArray< Compiler_Driver_Source > &  inputs,
const Compiler_Driver_Action  action = Compiler_Driver_Action::Run 
)
inline

Runs the pipeline over in-memory sources.

Parameters
inputsOrdered source units to parse and merge.
actionFinal stage requested by the caller.
Returns
true when the requested action finished without diagnostics or driver-level hard errors.

Definition at line 500 of file Compiler_Driver.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Emit_Bytecode, Aleph::Emit_C, Aleph::HIR, Aleph::IR, Aleph::Parse_Only, Aleph::Run, and Aleph::Sema_Only.

◆ finalize()

bool Aleph::Compiler_Driver::finalize ( const Compiler_Driver_Action  action)
inlineprivate

Definition at line 395 of file Compiler_Driver.H.

References Aleph::blossom_maximum_cardinality_matching().

◆ find_artifact()

const Compiler_Driver_Artifact * Aleph::Compiler_Driver::find_artifact ( std::string_view  label) const
inlinenoexcept

Finds one artifact by label.

Parameters
labelExact artifact label to look up.
Returns
Matching artifact pointer, or nullptr if absent.

Definition at line 737 of file Compiler_Driver.H.

References Aleph::DynArray< T >::access(), and Aleph::DynArray< T >::size().

Referenced by main().

◆ find_source_index()

size_t Aleph::Compiler_Driver::find_source_index ( std::string_view  name) const
inlineprivatenoexcept

◆ hir_module()

const Compiler_HIR_Module * Aleph::Compiler_Driver::hir_module ( ) const
inlinenoexcept

Returns the lowered HIR module from the last run, when available.

Definition at line 685 of file Compiler_Driver.H.

◆ ir_module()

const Compiler_IR_Module * Aleph::Compiler_Driver::ir_module ( ) const
inlinenoexcept

Returns the lowered IR module from the last run, when available.

Definition at line 691 of file Compiler_Driver.H.

◆ last_action()

Compiler_Driver_Action Aleph::Compiler_Driver::last_action ( ) const
inlinenoexcept

Returns the last requested action.

Definition at line 649 of file Compiler_Driver.H.

◆ lower_bytecode()

◆ lower_hir()

bool Aleph::Compiler_Driver::lower_hir ( )
inlineprivate

◆ lower_ir()

◆ merge_modules_from_order()

◆ merged_ast_module()

const Compiler_Module * Aleph::Compiler_Driver::merged_ast_module ( ) const
inlinenoexcept

Returns the merged AST module from the last run.

Definition at line 679 of file Compiler_Driver.H.

◆ ok()

bool Aleph::Compiler_Driver::ok ( ) const
inlinenoexcept

Returns whether the last driver action finished successfully.

Definition at line 643 of file Compiler_Driver.H.

References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Diagnostic_Engine::has_errors(), and Aleph::DynArray< T >::is_empty().

◆ operator=()

Compiler_Driver & Aleph::Compiler_Driver::operator= ( const Compiler_Driver &  )
delete

◆ options()

const Compiler_Driver_Options & Aleph::Compiler_Driver::options ( ) const
inlinenoexcept

Returns the immutable construction-time configuration.

Definition at line 444 of file Compiler_Driver.H.

◆ parse_registered_sources()

◆ parsed_ast_modules()

const DynArray< Compiler_Module * > & Aleph::Compiler_Driver::parsed_ast_modules ( ) const
inlinenoexcept

Returns the parsed per-file AST modules from the last run.

Definition at line 673 of file Compiler_Driver.H.

◆ prepare_inputs()

bool Aleph::Compiler_Driver::prepare_inputs ( const DynArray< Compiler_Driver_Source > &  inputs)
inlineprivate

◆ record_ast_artifacts()

void Aleph::Compiler_Driver::record_ast_artifacts ( )
inlineprivate

◆ record_diagnostics_artifact()

void Aleph::Compiler_Driver::record_diagnostics_artifact ( )
inlineprivate

Definition at line 266 of file Compiler_Driver.H.

References out, and Aleph::Diagnostic_Engine::render_plain().

◆ record_driver_messages_artifact()

void Aleph::Compiler_Driver::record_driver_messages_artifact ( )
inlineprivate

◆ record_import_order_artifact()

void Aleph::Compiler_Driver::record_import_order_artifact ( )
inlineprivate

◆ record_text_artifact()

void Aleph::Compiler_Driver::record_text_artifact ( const std::string &  label,
std::string  text 
)
inlineprivate

◆ resolve_import_order()

◆ run_output()

const Compiler_Driver_Run_Output & Aleph::Compiler_Driver::run_output ( ) const
inlinenoexcept

Returns the run summary from the last run action.

Definition at line 709 of file Compiler_Driver.H.

◆ run_typed_semantics()

◆ source_manager()

const Source_Manager & Aleph::Compiler_Driver::source_manager ( ) const
inlinenoexcept

Returns the shared source manager for the last run.

Definition at line 655 of file Compiler_Driver.H.

◆ typed_analysis()

const Compiler_Typed_Semantic_Analyzer & Aleph::Compiler_Driver::typed_analysis ( ) const
inlinenoexcept

Returns the typed semantic analyzer state from the last run.

Definition at line 667 of file Compiler_Driver.H.

◆ warnings()

const DynArray< std::string > & Aleph::Compiler_Driver::warnings ( ) const
inlinenoexcept

Returns non-fatal driver-level warnings.

Definition at line 721 of file Compiler_Driver.H.

Member Data Documentation

◆ arena_bytes_

size_t Aleph::Compiler_Driver::arena_bytes_ = 0
private

Definition at line 117 of file Compiler_Driver.H.

◆ artifacts_

DynArray<Compiler_Driver_Artifact> Aleph::Compiler_Driver::artifacts_
private

Definition at line 123 of file Compiler_Driver.H.

Referenced by record_text_artifact().

◆ ast_ctx_

Compiler_Ast_Context Aleph::Compiler_Driver::ast_ctx_
private

Definition at line 111 of file Compiler_Driver.H.

◆ bytecode_ctx_

Compiler_Bytecode_Context Aleph::Compiler_Driver::bytecode_ctx_
private

Definition at line 114 of file Compiler_Driver.H.

◆ bytecode_module_

Compiler_Bytecode_Module* Aleph::Compiler_Driver::bytecode_module_ = nullptr
private

Definition at line 130 of file Compiler_Driver.H.

◆ c_emission_

Compiler_C_Backend_Emission Aleph::Compiler_Driver::c_emission_
private

Definition at line 131 of file Compiler_Driver.H.

◆ config_

Compiler_Driver_Options Aleph::Compiler_Driver::config_
private

Definition at line 108 of file Compiler_Driver.H.

◆ diagnostics_

Diagnostic_Engine Aleph::Compiler_Driver::diagnostics_
private

Definition at line 110 of file Compiler_Driver.H.

Referenced by emit_driver_diagnostic().

◆ errors_

DynArray<std::string> Aleph::Compiler_Driver::errors_
private

Definition at line 124 of file Compiler_Driver.H.

Referenced by append_error().

◆ hir_ctx_

Compiler_HIR_Context Aleph::Compiler_Driver::hir_ctx_
private

Definition at line 112 of file Compiler_Driver.H.

◆ hir_module_

Compiler_HIR_Module* Aleph::Compiler_Driver::hir_module_ = nullptr
private

Definition at line 128 of file Compiler_Driver.H.

◆ ir_ctx_

Compiler_IR_Context Aleph::Compiler_Driver::ir_ctx_
private

Definition at line 113 of file Compiler_Driver.H.

◆ ir_module_

Compiler_IR_Module* Aleph::Compiler_Driver::ir_module_ = nullptr
private

Definition at line 129 of file Compiler_Driver.H.

◆ last_action_

Compiler_Driver_Action Aleph::Compiler_Driver::last_action_ = Compiler_Driver_Action::Parse_Only
private

Definition at line 133 of file Compiler_Driver.H.

◆ merge_order_

DynArray<size_t> Aleph::Compiler_Driver::merge_order_
private

Definition at line 122 of file Compiler_Driver.H.

◆ merged_ast_

Compiler_Module* Aleph::Compiler_Driver::merged_ast_ = nullptr
private

Definition at line 127 of file Compiler_Driver.H.

◆ parsed_modules_

DynArray<Compiler_Module *> Aleph::Compiler_Driver::parsed_modules_
private

Definition at line 121 of file Compiler_Driver.H.

◆ run_output_

Compiler_Driver_Run_Output Aleph::Compiler_Driver::run_output_
private

Definition at line 132 of file Compiler_Driver.H.

◆ runtime_

Interpreter_Runtime Aleph::Compiler_Driver::runtime_
private

Definition at line 116 of file Compiler_Driver.H.

◆ source_file_ids_

DynArray<Source_File_Id> Aleph::Compiler_Driver::source_file_ids_
private

Definition at line 120 of file Compiler_Driver.H.

◆ source_names_

DynArray<std::string> Aleph::Compiler_Driver::source_names_
private

Definition at line 119 of file Compiler_Driver.H.

Referenced by find_source_index(), and record_import_order_artifact().

◆ sources_

Source_Manager Aleph::Compiler_Driver::sources_
private

Definition at line 109 of file Compiler_Driver.H.

◆ typed_

Compiler_Typed_Semantic_Analyzer Aleph::Compiler_Driver::typed_
private

Definition at line 115 of file Compiler_Driver.H.

◆ warnings_

DynArray<std::string> Aleph::Compiler_Driver::warnings_
private

Definition at line 125 of file Compiler_Driver.H.

Referenced by append_warning().


The documentation for this class was generated from the following file: