sun::codegen::functions::FunctionGenerator

sun::codegen::functions::FunctionGenerator

class · Source (opens in a new tab)

class sun::codegen::functions::FunctionGenerator

Emits 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 &)=delete

A 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

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 &)=delete

Binds 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 &)=delete

Disallows assignment so ownership and object identity cannot be duplicated.

Related: FunctionGenerator

Private Functions

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

private · variable · Source (opens in a new tab)

std::vector<ClosureContext> sun::codegen::functions::FunctionGenerator::closureStack

No documentation comment.

Related: ClosureContext

ctx

private · variable · Source (opens in a new tab)

sun::codegen::CodegenContext& sun::codegen::functions::FunctionGenerator::ctx

No documentation comment.

Related: sun::codegen::CodegenContext

currentFunctionCanError

private · variable · Source (opens in a new tab)

bool& sun::codegen::functions::FunctionGenerator::currentFunctionCanError

No documentation comment.

currentFunctionReturnsRef

private · variable · Source (opens in a new tab)

bool& sun::codegen::functions::FunctionGenerator::currentFunctionReturnsRef

No documentation comment.

currentFunctionValueType

private · variable · Source (opens in a new tab)

llvm::Type*& sun::codegen::functions::FunctionGenerator::currentFunctionValueType

No documentation comment.

debugInfo

private · variable · Source (opens in a new tab)

sun::codegen::DebugInfoBuilder& sun::codegen::functions::FunctionGenerator::debugInfo

No 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 = 0

No documentation comment.

module

private · variable · Source (opens in a new tab)

llvm::Module* sun::codegen::functions::FunctionGenerator::module

No 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::typeResolver

No documentation comment.

Related: sun::codegen::LLVMTypeResolver