sun::codegen::functions::FunctionGenerator
class · Source (opens in a new tab)
class sun::codegen::functions::FunctionGeneratorEmits function and lambda definitions, the closures they need, and returns.
Functions
codegen
codegen(const sun::ast::ReturnExprAST &expr)
public · function · Source (opens in a new tab)
Value * sun::codegen::functions::FunctionGenerator::codegen(const sun::ast::ReturnExprAST &expr)Emits LLVM instructions for this syntax node and returns its generated value.
Related: sun::ast::ReturnExprAST
codegen(const BlockExprAST &block)
private · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::codegen(const BlockExprAST &block)Emits LLVM instructions for this syntax node and returns its generated value.
Related: BlockExprAST
codegen(const PrototypeAST &proto, llvm::StructType *envType, bool isLambda, llvm::Type *returnType=nullptr)
public · function · Source (opens in a new tab)
std::pair< Function *, llvm::StructType * > sun::codegen::functions::FunctionGenerator::codegen(const PrototypeAST &proto, llvm::StructType *envType, bool isLambda, llvm::Type *returnType=nullptr)Declare a prototype's LLVM signature, body to follow.
Related: PrototypeAST
codegen(const T &)=delete
private · function · Source (opens in a new tab)
template <typename T>
llvm::Value * sun::codegen::functions::FunctionGenerator::codegen(const T &)=deleteA node kind with its own overload must not silently bind to the ExprAST forwarder above.
Make it a compile error instead.
Related: ExprAST, BlockExprAST, sun::ast::ReturnExprAST, ExprAST
codegen(const ExprAST &expr)
private · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::codegen(const ExprAST &expr)What function codegen borrows from the rest of codegen.
The BlockExprAST overload matters: without it a body would bind to codegen(const ExprAST&), which attaches an expression debug location the block path does not want.
Related: ExprAST, BlockExprAST, codegen(const ExprAST&)
Public Functions
- FunctionGenerator
- codegenExternFunc
- codegenFunc
- codegenGenericFunc
- codegenLambda
- createCaptureSlotAddress
- createLoadVarFromClosure
- declareBlockSignatures
- declareFuncSignature
- forwardDeclareFunction
- operator=
FunctionGenerator
FunctionGenerator(sun::codegen::CodegenState &state, sun::codegen::CodegenVisitor &gen)
public · function · Source (opens in a new tab)
sun::codegen::functions::FunctionGenerator::FunctionGenerator(sun::codegen::CodegenState &state, sun::codegen::CodegenVisitor &gen)Binds function generation to the shared expression visitor and state.
Related: sun::codegen::CodegenState, sun::codegen::CodegenVisitor
FunctionGenerator(const FunctionGenerator &)=delete
public · function · Source (opens in a new tab)
sun::codegen::functions::FunctionGenerator::FunctionGenerator(const FunctionGenerator &)=deleteBinds function generation to the shared expression visitor and state.
codegenExternFunc
public · function · Source (opens in a new tab)
Value * sun::codegen::functions::FunctionGenerator::codegenExternFunc(FunctionAST &func)Emits LLVM code for an external function declaration.
Related: FunctionAST
codegenFunc
public · function · Source (opens in a new tab)
Value * sun::codegen::functions::FunctionGenerator::codegenFunc(FunctionAST &func)Emits LLVM code for a function body.
Related: FunctionAST
codegenGenericFunc
public · function · Source (opens in a new tab)
Value * sun::codegen::functions::FunctionGenerator::codegenGenericFunc(FunctionAST &func)Emits LLVM code for a specialized generic function.
Related: FunctionAST
codegenLambda
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::codegenLambda(sun::ast::LambdaAST &lambda)Emits LLVM code for a lambda and its captured environment.
Related: sun::ast::LambdaAST
createCaptureSlotAddress
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::createCaptureSlotAddress(sun::semantic_analysis::DeclarationId id, llvm::Type **valueTypeOut=nullptr, bool *byRefOut=nullptr, bool *ownedOut=nullptr)Address of a captured variable's storage: the environment slot for a by-value capture, the stored pointer for a [ref x] capture.
Returns nullptr when the name is not a capture.
Related: sun::semantic_analysis::DeclarationId
createLoadVarFromClosure
public · function · Source (opens in a new tab)
llvm::LoadInst * sun::codegen::functions::FunctionGenerator::createLoadVarFromClosure(sun::semantic_analysis::DeclarationId id)Loads a variable from the closure context if it is one.
Related: sun::semantic_analysis::DeclarationId
declareBlockSignatures
public · function · Source (opens in a new tab)
void sun::codegen::functions::FunctionGenerator::declareBlockSignatures(const BlockExprAST &block)Declare every function and method in a block's module subtree before any body is emitted, so calls may name things defined later in merged input.
Related: BlockExprAST
declareFuncSignature
public · function · Source (opens in a new tab)
FuncDeclResult sun::codegen::functions::FunctionGenerator::declareFuncSignature(PrototypeAST &proto)Declares an LLVM function from its analyzed Sun signature.
Related: FuncDeclResult, PrototypeAST
forwardDeclareFunction
public · function · Source (opens in a new tab)
void sun::codegen::functions::FunctionGenerator::forwardDeclareFunction(const PrototypeAST &proto)Declare one function signature, body to follow.
Related: PrototypeAST
operator=
public · function · Source (opens in a new tab)
FunctionGenerator & sun::codegen::functions::FunctionGenerator::operator=(const FunctionGenerator &)=deleteDisallows assignment so ownership and object identity cannot be duplicated.
Related: FunctionGenerator
Private Functions
- applyMoveSemantics
- classes
- computeCaptureInitValue
- createEntryBlockAlloca
- createEnvTypeForFunc
- createFatClosure
- createFatTypeForFunc
- debugDeclareParam
- externC
- fillCaptureSlots
- functions
- scopes
applyMoveSemantics
private · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::applyMoveSemantics(llvm::Value *argVal, sun::types::TypePtr argSunType)Transfers an argument value according to its ownership requirements.
Related: sun::types::TypePtr
classes
private · function · Source (opens in a new tab)
sun::codegen::classes::ClassGenerator & sun::codegen::functions::FunctionGenerator::classes()Provides the generator for class storage and method operations.
Related: sun::codegen::classes::ClassGenerator
computeCaptureInitValue
private · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::computeCaptureInitValue(const sun::ast::Capture &cap)Environment slot initializer at closure creation: the value for a by-value capture, the referent's address for a [ref x] capture.
Related: sun::ast::Capture
createEntryBlockAlloca
private · function · Source (opens in a new tab)
llvm::AllocaInst * sun::codegen::functions::FunctionGenerator::createEntryBlockAlloca(llvm::Function *func, llvm::StringRef varName, llvm::Type *type)Allocates local storage in the function entry block.
createEnvTypeForFunc
private · function · Source (opens in a new tab)
llvm::StructType * sun::codegen::functions::FunctionGenerator::createEnvTypeForFunc(const PrototypeAST &proto)Builds the LLVM structure holding a function's captured environment.
Related: PrototypeAST
createFatClosure
private · function · Source (opens in a new tab)
llvm::Value * sun::codegen::functions::FunctionGenerator::createFatClosure(llvm::Function *func, llvm::StructType *fatType, llvm::StructType *envType, const PrototypeAST &proto)Creates a callable value containing its function pointer and captures.
Related: PrototypeAST
createFatTypeForFunc
private · function · Source (opens in a new tab)
llvm::StructType * sun::codegen::functions::FunctionGenerator::createFatTypeForFunc(llvm::Function *func, llvm::StructType *envType, const PrototypeAST &proto)Builds the LLVM representation combining a function and its environment.
Related: PrototypeAST
debugDeclareParam
private · function · Source (opens in a new tab)
void sun::codegen::functions::FunctionGenerator::debugDeclareParam(llvm::AllocaInst *alloca, const std::string &name, const PrototypeAST &proto, unsigned userArgIdx, unsigned argNoBase=1)Associates generated parameter storage with its source declaration.
Related: PrototypeAST
externC
private · function · Source (opens in a new tab)
sun::codegen::abi::ExternCEmitter & sun::codegen::functions::FunctionGenerator::externC()Provides the emitter for calls using the C calling convention.
Related: sun::codegen::abi::ExternCEmitter
fillCaptureSlots
private · function · Source (opens in a new tab)
bool sun::codegen::functions::FunctionGenerator::fillCaptureSlots(llvm::StructType *envType, llvm::Value *envAlloca, const PrototypeAST &proto, llvm::IRBuilder<> &entryBuilder)Fill a closure environment's capture slots.
Owned captures of compound values move in and the slot is registered for drop.
Related: PrototypeAST
functions
private · function · Source (opens in a new tab)
FunctionRegistry & sun::codegen::functions::FunctionGenerator::functions()Provides the registry of generated functions and their metadata.
Related: FunctionRegistry
scopes
private · function · Source (opens in a new tab)
sun::codegen::scopes::ScopeManager & sun::codegen::functions::FunctionGenerator::scopes()Provides the scope manager responsible for variable storage and cleanup.
Related: sun::codegen::scopes::ScopeManager
Private Fields
- closureStack
- ctx
- currentFunctionCanError
- currentFunctionReturnsRef
- currentFunctionValueType
- debugInfo
- gen_
- lambdaCounter
- module
- state_
- typeResolver
closureStack
private · variable · Source (opens in a new tab)
std::vector<ClosureContext> sun::codegen::functions::FunctionGenerator::closureStackNo documentation comment.
Related: ClosureContext
ctx
private · variable · Source (opens in a new tab)
sun::codegen::CodegenContext& sun::codegen::functions::FunctionGenerator::ctxNo documentation comment.
Related: sun::codegen::CodegenContext
currentFunctionCanError
private · variable · Source (opens in a new tab)
bool& sun::codegen::functions::FunctionGenerator::currentFunctionCanErrorNo documentation comment.
currentFunctionReturnsRef
private · variable · Source (opens in a new tab)
bool& sun::codegen::functions::FunctionGenerator::currentFunctionReturnsRefNo documentation comment.
currentFunctionValueType
private · variable · Source (opens in a new tab)
llvm::Type*& sun::codegen::functions::FunctionGenerator::currentFunctionValueTypeNo documentation comment.
debugInfo
private · variable · Source (opens in a new tab)
sun::codegen::DebugInfoBuilder& sun::codegen::functions::FunctionGenerator::debugInfoNo documentation comment.
Related: sun::codegen::DebugInfoBuilder
gen_
private · variable · Source (opens in a new tab)
sun::codegen::CodegenVisitor& sun::codegen::functions::FunctionGenerator::gen_No documentation comment.
Related: sun::codegen::CodegenVisitor
lambdaCounter
private · variable · Source (opens in a new tab)
unsigned sun::codegen::functions::FunctionGenerator::lambdaCounter = 0No documentation comment.
module
private · variable · Source (opens in a new tab)
llvm::Module* sun::codegen::functions::FunctionGenerator::moduleNo documentation comment.
state_
private · variable · Source (opens in a new tab)
sun::codegen::CodegenState& sun::codegen::functions::FunctionGenerator::state_No documentation comment.
Related: sun::codegen::CodegenState
typeResolver
private · variable · Source (opens in a new tab)
sun::codegen::LLVMTypeResolver& sun::codegen::functions::FunctionGenerator::typeResolverNo documentation comment.
Related: sun::codegen::LLVMTypeResolver