sun::driver::Driver
class · Source (opens in a new tab)
class sun::driver::DriverDriver orchestrates the compilation pipeline: parse → analyze → codegen → execute.
It owns all compilation components and provides static factory methods for easy construction.
Types
- sun::driver::Driver::AnalyzedProgram (public)
Public Functions
- addJITStaticLibrary
- analyzeFiles
- analyzeString
- compileFile
- compileFiles
- compileString
- createForAOT
- createForJIT
- executeFile
- executeFiles
- executeString
- getDebugFolder
- getModule
- getNativeArchivePaths
- getStaticInitOrder
- printReachableIR
- printUserDefinedIR
- programHasTests
- setDebugMode
- setDumpIR
- setDumpProtoSun
- setDumpReachable
- setExternSymbolRenames
- setMetadataCallback
- setMoonImports
- setOwnBundleHash
- setProtoFiles
- setTestHandling
addJITStaticLibrary
public · function · Source (opens in a new tab)
void sun::driver::Driver::addJITStaticLibrary(const std::string &path)Make a static archive named with -l resolvable by the JIT.
Shared libraries are dlopen'd into the process instead; an archive has to go through the JIT's own linker. Throws when the archive cannot be read. No effect on an AOT driver, which passes archives to the system linker.
analyzeFiles
public · function · Source (opens in a new tab)
Driver::AnalyzedProgram sun::driver::Driver::analyzeFiles(const std::vector< std::string > &sourceFiles, const std::vector< MoonImport > &moonImports={}, const std::vector< std::string > &protoFiles={}, const std::map< std::string, std::string > &sourceOverrides={})Parse and analyze a set of files (merged like compileFiles) without generating code.
sourceOverrides maps a canonical path to in-memory text used instead of the file on disk.
Related: AnalyzedProgram, MoonImport
analyzeString
public · function · Source (opens in a new tab)
Driver::AnalyzedProgram sun::driver::Driver::analyzeString(const std::string &source, const std::string &filePath="")Parse and analyze a source string without generating code.
Related: AnalyzedProgram
compileFile
public · function · Source (opens in a new tab)
void sun::driver::Driver::compileFile(const std::string &filename)Compile a file to IR without executing.
compileFiles
public · function · Source (opens in a new tab)
void sun::driver::Driver::compileFiles(const std::vector< std::string > &sourceFiles, const std::vector< MoonImport > &moonImports={}, const std::vector< std::string > &protoFiles={}, const std::map< std::string, std::string > &sourceOverrides={})Compile multiple source files with optional precompiled moon libraries This is the merged-AST compilation model: all files are parsed and merged into a single AST before semantic analysis and codegen.
param
-
sourceFiles: List of .sun source files to compile -
moonImports: Precompiled .moon libraries with optional aliasing -
protoFiles: .proto schemas to synthesize into Sun modules -
sourceOverrides: Editor buffers keyed by normalized source paths
Related: MoonImport
compileString
public · function · Source (opens in a new tab)
void sun::driver::Driver::compileString(const std::string &source, const std::string &filePath="")Compile a source string to IR without executing filePath is used for error messages (optional).
createForAOT
public · function · static · Source (opens in a new tab)
std::unique_ptr< Driver > sun::driver::Driver::createForAOT(const std::string &moduleName="module", const std::string &targetTriple="", bool debugInfo=false, bool optimize=true)Create a Driver for AOT compilation (no JIT).
A non-empty targetTriple cross-compiles for that target (object/IR emission only — linking and execution stay host-only). debugInfo enables DWARF emission. Optimization is enabled by default, independently of debug info.
createForJIT
public · function · static · Source (opens in a new tab)
std::unique_ptr< Driver > sun::driver::Driver::createForJIT(const std::string &moduleName="sun", bool debugInfo=false, bool optimize=true)Create a JIT driver with independent debug-info and optimization settings.
Related: Driver
executeFile
public · function · Source (opens in a new tab)
SunValue sun::driver::Driver::executeFile(const std::string &filename, int argc=0, char **argv=nullptr)Execute a file with optional command-line arguments; returns main()'s value (VoidValue for void main).
Related: sun::driver::SunValue, main(), VoidValue
executeFiles
public · function · Source (opens in a new tab)
SunValue sun::driver::Driver::executeFiles(const std::vector< std::string > &sourceFiles, const std::vector< MoonImport > &moonImports={}, int argc=0, char **argv=nullptr, const std::vector< std::string > &protoFiles={})Execute multiple source files with optional precompiled moon libraries.
param
-
sourceFiles: List of .sun source files to compile and execute -
moonImports: Precompiled .moon libraries with optional aliasing -
argc: Argument count for main() -
argv: Argument vector for main() -
protoFiles: Protobuf schemas to synthesize into Sun modules
Related: sun::driver::SunValue, MoonImport, main()
executeString
public · function · Source (opens in a new tab)
SunValue sun::driver::Driver::executeString(const std::string &source, int argc=0, char **argv=nullptr, const std::string &filePath="")Execute a source string with optional command-line arguments filePath is used for error messages (optional).
Related: sun::driver::SunValue
getDebugFolder
public · function · Source (opens in a new tab)
const std::string & sun::driver::Driver::getDebugFolder() constReturns the directory used for compiler inspection artifacts.
getModule
public · function · Source (opens in a new tab)
llvm::Module & sun::driver::Driver::getModule()Access the underlying module (for emitting object code after compilation).
getNativeArchivePaths
public · function · Source (opens in a new tab)
const std::vector< std::string > & sun::driver::Driver::getNativeArchivePaths() constStatic archives this compilation must link, as paths on disk: those the program's manifest declares plus those carried by the .moon bundles it linked against.
Empty when there are none.
getStaticInitOrder
public · function · Source (opens in a new tab)
uint32_t sun::driver::Driver::getStaticInitOrder() constWhere the startup function of the code being compiled runs relative to those of its imports: zero when it imports nothing, otherwise one more than the highest value among the imported bundles.
A bundle records it so its own importers can order themselves after it. Valid once analysis has finished, which includes the metadata callback.
printReachableIR
public · function · Source (opens in a new tab)
void sun::driver::Driver::printReachableIR()Print IR for all functions reachable from main() (includes stdlib).
Related: main()
printUserDefinedIR
public · function · Source (opens in a new tab)
void sun::driver::Driver::printUserDefinedIR()Print only user-defined IR (filters out imports and linked libraries).
programHasTests
public · function · Source (opens in a new tab)
bool sun::driver::Driver::programHasTests() constTrue when the last compilation encountered test functions or the manifest listed test_files.
Valid after compileFile/executeFile.
setDebugMode
public · function · Source (opens in a new tab)
void sun::driver::Driver::setDebugMode(bool enable, const std::string &inputFile="")Enable debug mode and set the debug output folder Creates <basename>_debug/ folder with ast.dot and ir.ll.
setDumpIR
public · function · Source (opens in a new tab)
void sun::driver::Driver::setDumpIR(bool dump)Enable/disable LLVM IR dumping to stdout.
setDumpProtoSun
public · function · Source (opens in a new tab)
void sun::driver::Driver::setDumpProtoSun(bool dump)Print the Sun source synthesized from each imported .proto to stdout.
setDumpReachable
public · function · Source (opens in a new tab)
void sun::driver::Driver::setDumpReachable(bool dump)Enable dumping all reachable functions (includes stdlib).
setExternSymbolRenames
public · function · Source (opens in a new tab)
void sun::driver::Driver::setExternSymbolRenames(std::map< std::string, std::string > renames)C symbols the bundle being built carries in its archives, mapped to their prefixed spelling (SSL_new -> $sethash$_SSL_new).
The program's own extern "C" declarations naming a key are emitted, and recorded in the bundle's metadata, under the value, so the bundle and its importers bind to the carried copy. Must be set before compileFiles.
setMetadataCallback
public · function · Source (opens in a new tab)
void sun::driver::Driver::setMetadataCallback(std::function< void(const BlockExprAST &, SemanticAnalyzer &)> callback)Receive the analyzed program after borrow checking and before code generation.
Related: BlockExprAST, SemanticAnalyzer
setMoonImports
public · function · Source (opens in a new tab)
void sun::driver::Driver::setMoonImports(std::vector< MoonImport > imports)Set moon libraries to preload for single-file compilation modes (executeString, compileFile, etc.).
Related: MoonImport
setOwnBundleHash
public · function · Source (opens in a new tab)
void sun::driver::Driver::setOwnBundleHash(std::string hash)Compile as the body of a .moon bundle with this hash, which is the bundle's input hash (see input_hash.h): the program's own declarations are analyzed under a $hash$ module scope, so every symbol and struct type is spelled the way importers of the bundle will spell it.
Must be set before compileFiles.
Related: input_hash.h
setProtoFiles
public · function · Source (opens in a new tab)
void sun::driver::Driver::setProtoFiles(std::vector< std::string > protos)Set .proto schemas to import natively (see ProtoImporter): each is synthesized into ordinary Sun source and compiled with the program.
setTestHandling
public · function · Source (opens in a new tab)
void sun::driver::Driver::setTestHandling(TestHandling handling)Selects how compilation discovers and emits test functions.
Related: TestHandling
Public Enums
TestHandling
public · enum · Source (opens in a new tab)
enum class sun::driver::Driver::TestHandlingHow a compilation treats test_function declarations.
Editor analysis (analyzeFiles/analyzeString) never goes through runPipeline, so it always sees tests and needs no mode.
Strip
Strip
No documentation comment.
Compile
Compile
No documentation comment.
Private Functions
- Driver
- analyzeProgram
- applyTestHandling
- collectNativeArchives
- dumpUserDefinedIR
- ensureLLVMInitialized
- parseAndMergeFiles
- parseSynthesizedProtoModules
- prepareStringParser
- registerArchivesWithJIT
- runPipeline
- startAnalysisSession
- writeUserDefinedIR
Driver
private · function · Source (opens in a new tab)
sun::driver::Driver::Driver(std::unique_ptr< sun::codegen::CodegenContext > ctx, std::shared_ptr< AnalysisResults > analysisResults, std::unique_ptr< sun::codegen::CodegenVisitor > codegenVisitor, std::unique_ptr< SemanticAnalyzer > analyzer)Private constructor - use factory methods.
Related: sun::codegen::CodegenContext, AnalysisResults, sun::codegen::CodegenVisitor, SemanticAnalyzer
analyzeProgram
private · function · Source (opens in a new tab)
void sun::driver::Driver::analyzeProgram(BlockExprAST &blockAst, Parser &parser)Front half of the pipeline shared by compilation and analysis: lowering, moon stub injection and semantic analysis (no borrow check, no codegen).
Related: BlockExprAST, Parser
applyTestHandling
private · function · Source (opens in a new tab)
void sun::driver::Driver::applyTestHandling(BlockExprAST &blockAst)Strip test functions (production builds) or collect them, make them public and splice in the synthesized runner main (test builds).
Runs first in runPipeline, before any analysis.
Related: BlockExprAST
collectNativeArchives
private · function · Source (opens in a new tab)
void sun::driver::Driver::collectNativeArchives(const std::set< std::string > &linkedModules)Gather the archives to link: the manifest's own, then those carried by the bundles just linked (put on disk first), so AOT can pass them to the linker and the JIT can load them.
Warns when the set looks troublesome: two versions of one library, or a plain extern naming a symbol a bundle carries only under its own prefix.
dumpUserDefinedIR
private · function · Source (opens in a new tab)
void sun::driver::Driver::dumpUserDefinedIR(llvm::raw_ostream &OS)Writes LLVM IR for user-defined code to the supplied stream.
ensureLLVMInitialized
private · function · static · Source (opens in a new tab)
static void sun::driver::Driver::ensureLLVMInitialized()Initialize LLVM targets once (thread-safe).
parseAndMergeFiles
private · function · Source (opens in a new tab)
std::unique_ptr< BlockExprAST > sun::driver::Driver::parseAndMergeFiles(const std::vector< std::string > &sourceFiles, const std::vector< std::string > &protoFiles, const std::map< std::string, std::string > &sourceOverrides)Read, parse and merge every source file plus synthesized .proto modules.
sourceOverrides maps a canonical path to text used instead of the file on disk (an editor's unsaved buffer).
Related: BlockExprAST
parseSynthesizedProtoModules
private · function · Source (opens in a new tab)
void sun::driver::Driver::parseSynthesizedProtoModules(const std::vector< std::string > &protoFiles, std::vector< std::unique_ptr< BlockExprAST > > &parsedFiles, std::vector< std::string > &canonicalPaths)Synthesize Sun modules for manifest .proto files and parse them into parsedFiles/canonicalPaths (see ProtoImporter).
Related: BlockExprAST
prepareStringParser
private · function · Source (opens in a new tab)
Parser sun::driver::Driver::prepareStringParser(const std::string &source, const std::string &filePath)Register a source string for error reporting and create its parser.
Related: Parser
registerArchivesWithJIT
private · function · Source (opens in a new tab)
void sun::driver::Driver::registerArchivesWithJIT()Load the gathered archives into the JIT, exactly as the AOT link would link them.
runPipeline
private · function · Source (opens in a new tab)
SunValue sun::driver::Driver::runPipeline(std::unique_ptr< BlockExprAST > program, Parser &parser, bool execute, int argc=0, char **argv=nullptr)Internal helper: run full pipeline on parsed AST.
Related: sun::driver::SunValue, BlockExprAST, Parser
startAnalysisSession
private · function · Source (opens in a new tab)
void sun::driver::Driver::startAnalysisSession()Start independent declaration and type storage for editor analysis.
writeUserDefinedIR
private · function · Source (opens in a new tab)
void sun::driver::Driver::writeUserDefinedIR(const std::string &path)Saves LLVM IR for user-defined code to a file.
Private Fields
- analysisResults
- analyzedTree_
- analyzer
- archiveTempDir_
- baseDir
- codegenVisitor
- ctx
- debugFolder_
- debugMode_
- dumpIR
- dumpProtoSun_
- dumpReachable
- externRenames_
- hasTests_
- manifestArchivePaths_
- metadataCallback_
- moonImports_
- nativeArchivePaths_
- ownBundleHash_
- protoFiles_
- staticInitOrder_
- testHandling_
- unmappedExternLinkNames_
analysisResults
private · variable · Source (opens in a new tab)
std::shared_ptr<AnalysisResults> sun::driver::Driver::analysisResultsNo documentation comment.
Related: AnalysisResults
analyzedTree_
private · variable · Source (opens in a new tab)
std::unique_ptr<BlockExprAST> sun::driver::Driver::analyzedTree_No documentation comment.
Related: BlockExprAST
analyzer
private · variable · Source (opens in a new tab)
std::unique_ptr<SemanticAnalyzer> sun::driver::Driver::analyzerNo documentation comment.
Related: SemanticAnalyzer
archiveTempDir_
private · variable · Source (opens in a new tab)
std::filesystem::path sun::driver::Driver::archiveTempDir_No documentation comment.
baseDir
private · variable · Source (opens in a new tab)
std::string sun::driver::Driver::baseDirNo documentation comment.
codegenVisitor
private · variable · Source (opens in a new tab)
std::unique_ptr<sun::codegen::CodegenVisitor> sun::driver::Driver::codegenVisitorNo documentation comment.
Related: sun::codegen::CodegenVisitor
ctx
private · variable · Source (opens in a new tab)
std::unique_ptr<sun::codegen::CodegenContext> sun::driver::Driver::ctxNo documentation comment.
Related: sun::codegen::CodegenContext
debugFolder_
private · variable · Source (opens in a new tab)
std::string sun::driver::Driver::debugFolder_No documentation comment.
debugMode_
private · variable · Source (opens in a new tab)
bool sun::driver::Driver::debugMode_ = falseNo documentation comment.
dumpIR
private · variable · Source (opens in a new tab)
bool sun::driver::Driver::dumpIR = falseNo documentation comment.
dumpProtoSun_
private · variable · Source (opens in a new tab)
bool sun::driver::Driver::dumpProtoSun_ = falseNo documentation comment.
dumpReachable
private · variable · Source (opens in a new tab)
bool sun::driver::Driver::dumpReachable = falseNo documentation comment.
externRenames_
private · variable · Source (opens in a new tab)
std::map<std::string, std::string> sun::driver::Driver::externRenames_No documentation comment.
hasTests_
private · variable · Source (opens in a new tab)
bool sun::driver::Driver::hasTests_ = falseNo documentation comment.
manifestArchivePaths_
private · variable · Source (opens in a new tab)
std::vector<std::string> sun::driver::Driver::manifestArchivePaths_No documentation comment.
metadataCallback_
private · variable · Source (opens in a new tab)
std::function<void(const BlockExprAST&, SemanticAnalyzer&)> sun::driver::Driver::metadataCallback_No documentation comment.
Related: BlockExprAST, SemanticAnalyzer
moonImports_
private · variable · Source (opens in a new tab)
std::vector<MoonImport> sun::driver::Driver::moonImports_No documentation comment.
Related: MoonImport
nativeArchivePaths_
private · variable · Source (opens in a new tab)
std::vector<std::string> sun::driver::Driver::nativeArchivePaths_No documentation comment.
ownBundleHash_
private · variable · Source (opens in a new tab)
std::string sun::driver::Driver::ownBundleHash_No documentation comment.
protoFiles_
private · variable · Source (opens in a new tab)
std::vector<std::string> sun::driver::Driver::protoFiles_No documentation comment.
staticInitOrder_
private · variable · Source (opens in a new tab)
uint32_t sun::driver::Driver::staticInitOrder_ = 0No documentation comment.
testHandling_
private · variable · Source (opens in a new tab)
TestHandling sun::driver::Driver::testHandling_ = TestHandling::StripNo documentation comment.
Related: TestHandling, TestHandling::Strip
unmappedExternLinkNames_
private · variable · Source (opens in a new tab)
std::vector<std::string> sun::driver::Driver::unmappedExternLinkNames_No documentation comment.