sun::codegen::classes::ClassGenerator

sun::codegen::classes::ClassGenerator

class · Source (opens in a new tab)

class sun::codegen::classes::ClassGenerator

Emits class, interface and enum definitions, member access, method bodies, interface dispatch, and the specializations generics ask for.

Functions

codegen

codegen(const sun::ast::StructLiteralAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::StructLiteralAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: sun::ast::StructLiteralAST

codegen(const ClassDefinitionAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const ClassDefinitionAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: ClassDefinitionAST

codegen(const sun::ast::InterfaceDefinitionAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::InterfaceDefinitionAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: sun::ast::InterfaceDefinitionAST

codegen(const sun::ast::BlockExprAST &block, size_t start=0)

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

llvm::Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::BlockExprAST &block, size_t start=0)

Emits a block, optionally skipping a prefix already emitted by its caller.

Related: sun::ast::BlockExprAST

codegen(const sun::ast::MemberAccessAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::MemberAccessAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: sun::ast::MemberAccessAST

codegen(const sun::ast::ThisExprAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::ThisExprAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: sun::ast::ThisExprAST

codegen(const ExprAST &expr)

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

llvm::Value * sun::codegen::classes::ClassGenerator::codegen(const ExprAST &expr)

What class codegen borrows from the rest of codegen.

The BlockExprAST overload matters: without it a method 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&)

codegen(const T &)=delete

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

template <typename T>
llvm::Value * sun::codegen::classes::ClassGenerator::codegen(const T &)=delete

A node kind with its own overload must not silently bind to the ExprAST forwarder above: that path attaches an expression debug location, so a block routed through it changes DWARF output.

Make it a compile error instead. Add an overload here when a new kind is needed.

Related: ExprAST, sun::ast::BlockExprAST, ExprAST

codegen(const sun::ast::MemberAssignmentAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::MemberAssignmentAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: sun::ast::MemberAssignmentAST

codegen(const sun::ast::GenericCallAST &expr)

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegen(const sun::ast::GenericCallAST &expr)

Emits LLVM instructions for this syntax node and returns its generated value.

Related: sun::ast::GenericCallAST

Public Functions

ClassGenerator

ClassGenerator(const ClassGenerator &)=delete

public · function · Source (opens in a new tab)

sun::codegen::classes::ClassGenerator::ClassGenerator(const ClassGenerator &)=delete

Binds class generation to shared compiler state and the expression visitor.

ClassGenerator(sun::codegen::CodegenState &state, sun::codegen::CodegenVisitor &gen)

public · function · Source (opens in a new tab)

sun::codegen::classes::ClassGenerator::ClassGenerator(sun::codegen::CodegenState &state, sun::codegen::CodegenVisitor &gen)

Binds class generation to shared compiler state and the expression visitor.

Related: sun::codegen::CodegenState, sun::codegen::CodegenVisitor

codegenPrecompiledClass

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegenPrecompiledClass(const ClassDefinitionAST &expr)

A class that arrived from precompiled bitcode: register its type and emit only the generic specializations this program asked for.

Related: ClassDefinitionAST

codegenStackClassInstance

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::codegenStackClassInstance(const sun::ast::CallExprAST &expr, ClassType &classType)

Build a class instance in a stack slot and run its constructor.

Related: sun::ast::CallExprAST, ClassType

createBorrowedInterfaceUpcast

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::createBorrowedInterfaceUpcast(llvm::Value *value, TypePtr sourceType, TypePtr targetType)

Borrows an ancestor interface in a temporary stack slot without moving the object.

Returns value unchanged unless both types are interfaces and targetType is a reference to a different interface. Invalid ancestor conversions report an error.

Related: TypePtr

createInterfaceFatPointer

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::createInterfaceFatPointer(llvm::Value *objectPtr, ClassType *classType, InterfaceType *ifaceType)

Creates a borrowed fat pointer { data_ptr, vtable_ptr }.

The concrete object remains in its current owner's storage.

Related: ClassType, InterfaceType

declareBlockClassMethods

public · function · Source (opens in a new tab)

void sun::codegen::classes::ClassGenerator::declareBlockClassMethods(const ClassDefinitionAST &expr)

Declare the methods of a class a block defines — including each specialization of a generic class — before any body is emitted.

Related: ClassDefinitionAST

declareMethodFromAST

public · function · Source (opens in a new tab)

Function * sun::codegen::classes::ClassGenerator::declareMethodFromAST(const sun::ast::FunctionAST &specializedAST)

Declare a method function from a specialized AST (no body generated).

Related: sun::ast::FunctionAST

finishFallibleConstruction

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::finishFallibleConstruction(const ExprAST &expr, ClassType &classType, llvm::Value *object, llvm::Value *status, sun::types::EnumType &statusType)

Wraps a completed object or constructor error in the construction result.

Builds the result tag and transfers the selected payload without allocating.

Related: ExprAST, ClassType, sun::types::EnumType

generateMethodBody

public · function · Source (opens in a new tab)

void sun::codegen::classes::ClassGenerator::generateMethodBody(const sun::ast::FunctionAST &methodFunc)

Generate a method body for an already-declared function.

Related: sun::ast::FunctionAST

getOrCreateInterfaceVtable

public · function · Source (opens in a new tab)

GlobalVariable * sun::codegen::classes::ClassGenerator::getOrCreateInterfaceVtable(ClassType *classType, InterfaceType *ifaceType)

Returns the vtable global for a (class, interface) pair, building it on demand if the class was not codegen'd in this module (e.g.

an stdlib error class referenced only by a throw). Missing methods are declared as externals resolved from the defining module at link/JIT time.

Related: ClassType, InterfaceType

moduleMemberGlobal

public · function · Source (opens in a new tab)

GlobalVariable * sun::codegen::classes::ClassGenerator::moduleMemberGlobal(const ExprAST &object, DeclarationId id)

A module is compile-time only, so mod.name reads and writes the global that the member's own declaration emitted.

Related: ExprAST, DeclarationId

operator=

public · function · Source (opens in a new tab)

ClassGenerator & sun::codegen::classes::ClassGenerator::operator=(const ClassGenerator &)=delete

Disallows assignment so ownership and object identity cannot be duplicated.

Related: ClassGenerator

prepareClassForRefInterface

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::prepareClassForRefInterface(llvm::Value *classPtr, TypePtr argType, TypePtr paramType)

Prepares a class argument for a ref Interface parameter by creating a fat pointer on the stack.

Returns nullptr if not a class->ref Interface conversion, otherwise returns pointer to the fat pointer on stack.

Related: TypePtr

upcastInterface

public · function · Source (opens in a new tab)

Value * sun::codegen::classes::ClassGenerator::upcastInterface(llvm::Value *value, InterfaceType *source, InterfaceType *target)

Converts a borrowed child view to an ancestor without copying its object.

Related: InterfaceType

Private Functions

assignToVariableSlot

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

void sun::codegen::classes::ClassGenerator::assignToVariableSlot(llvm::Value *slot, llvm::Value *value, const TypePtr &varType, const std::string &name)

Stores a generated value in the variable's allocated storage.

Related: TypePtr

codegenBoundMethodReference

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

Value * sun::codegen::classes::ClassGenerator::codegenBoundMethodReference(const sun::ast::MemberAccessAST &expr, llvm::Value *objectPtr)

Bound method reference: obj.method in value position (lambda-typed).

Related: sun::ast::MemberAccessAST

codegenObjectPtr

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

std::pair< llvm::Value *, sun::types::ClassType * > sun::codegen::classes::ClassGenerator::codegenObjectPtr(const ExprAST &object)

Emits the address of the receiver used for member operations.

Related: ClassType, ExprAST

createEntryBlockAlloca

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

llvm::AllocaInst * sun::codegen::classes::ClassGenerator::createEntryBlockAlloca(llvm::Function *func, llvm::StringRef varName, llvm::Type *type)

Allocates local storage in the function entry block.

debugDeclareParam

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

void sun::codegen::classes::ClassGenerator::debugDeclareParam(llvm::AllocaInst *alloca, const std::string &name, const sun::ast::PrototypeAST &proto, unsigned userArgIdx, unsigned argNoBase=1)

Associates generated parameter storage with its source declaration.

Related: sun::ast::PrototypeAST

declareClassMethods

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

void sun::codegen::classes::ClassGenerator::declareClassMethods(const ClassDefinitionAST &expr, const std::shared_ptr< ClassType > &classType)

Declare every method of one class (no bodies).

Related: ClassDefinitionAST, ClassType

emitCallArguments

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

bool sun::codegen::classes::ClassGenerator::emitCallArguments(const std::vector< std::unique_ptr< ExprAST > > &args, const std::vector< sun::semantic_analysis::ArgConversion > &conversions, const std::vector< TypePtr > &paramTypes, llvm::FunctionType *calleeTy, std::vector< llvm::Value * > &argValues, const std::string &calleeName, size_t firstArg=0)

Emits argument values and applies the conversions selected by analysis.

Related: ExprAST, sun::semantic_analysis::ArgConversion, TypePtr

emitMethodPrologueThis

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

void sun::codegen::classes::ClassGenerator::emitMethodPrologueThis(llvm::Function *func)

Method prologue: unwrap the receiver from the closure arg into a 'this.addr' alloca, set the frame's thisPtr, and register "this" in scope.

functions

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

sun::codegen::functions::FunctionRegistry & sun::codegen::classes::ClassGenerator::functions()

Provides the registry of generated functions and their metadata.

Related: sun::codegen::functions::FunctionRegistry

generateCtorArgs

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

std::vector< Value * > sun::codegen::classes::ClassGenerator::generateCtorArgs(llvm::Function *ctorFunc, llvm::Value *thisPtr, const std::vector< std::unique_ptr< ExprAST > > &args, const std::vector< sun::semantic_analysis::ArgConversion > &conversions, const std::vector< TypePtr > &paramTypes)

Generate constructor argument values as semantic analysis decided them.

Arg 0 is the method closure { ctorFunc, thisPtr }.

Related: ExprAST, sun::semantic_analysis::ArgConversion, TypePtr

intrinsics

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

sun::codegen::intrinsics::IntrinsicsGenerator & sun::codegen::classes::ClassGenerator::intrinsics()

Provides the generator for built-in operations.

Related: sun::codegen::intrinsics::IntrinsicsGenerator

isPrecompiledFunction

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

bool sun::codegen::classes::ClassGenerator::isPrecompiledFunction(const std::string &name)

Reports whether a function is supplied by an already compiled library.

materializeMethodClosure

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

llvm::Value * sun::codegen::classes::ClassGenerator::materializeMethodClosure(llvm::Value *fnPtr, llvm::Value *receiverPtr, llvm::StringRef name)

Builds a callable value that retains the method receiver.

materializeMethodClosureValue

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

llvm::Value * sun::codegen::classes::ClassGenerator::materializeMethodClosureValue(llvm::Value *fnPtr, llvm::Value *receiverPtr)

Pairs a method pointer with its receiver to form a callable value.

scopes

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

sun::codegen::scopes::ScopeManager & sun::codegen::classes::ClassGenerator::scopes()

Provides the scope manager responsible for variable storage and cleanup.

Related: sun::codegen::scopes::ScopeManager

Private Fields

codegenedClasses

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

std::set<DeclarationId> sun::codegen::classes::ClassGenerator::codegenedClasses

No documentation comment.

Related: DeclarationId

ctx

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

sun::codegen::CodegenContext& sun::codegen::classes::ClassGenerator::ctx

No documentation comment.

Related: sun::codegen::CodegenContext

currentClass

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

std::shared_ptr<ClassType>& sun::codegen::classes::ClassGenerator::currentClass

No documentation comment.

Related: ClassType

currentFunctionCanError

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

bool& sun::codegen::classes::ClassGenerator::currentFunctionCanError

No documentation comment.

currentFunctionReturnsRef

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

bool& sun::codegen::classes::ClassGenerator::currentFunctionReturnsRef

No documentation comment.

currentFunctionValueType

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

llvm::Type*& sun::codegen::classes::ClassGenerator::currentFunctionValueType

No documentation comment.

debugInfo

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

sun::codegen::DebugInfoBuilder& sun::codegen::classes::ClassGenerator::debugInfo

No documentation comment.

Related: sun::codegen::DebugInfoBuilder

gen_

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

sun::codegen::CodegenVisitor& sun::codegen::classes::ClassGenerator::gen_

No documentation comment.

Related: sun::codegen::CodegenVisitor

librarySpecializations

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

std::set<DeclarationId> sun::codegen::classes::ClassGenerator::librarySpecializations

No documentation comment.

Related: DeclarationId

module

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

llvm::Module* sun::codegen::classes::ClassGenerator::module

No documentation comment.

state_

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

sun::codegen::CodegenState& sun::codegen::classes::ClassGenerator::state_

No documentation comment.

Related: sun::codegen::CodegenState

thisPtr

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

llvm::Value*& sun::codegen::classes::ClassGenerator::thisPtr

No documentation comment.

typeRegistry

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

std::shared_ptr<sun::semantic_analysis::TypeRegistry>& sun::codegen::classes::ClassGenerator::typeRegistry

No documentation comment.

Related: sun::semantic_analysis::TypeRegistry

typeResolver

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

sun::codegen::LLVMTypeResolver& sun::codegen::classes::ClassGenerator::typeResolver

No documentation comment.

Related: sun::codegen::LLVMTypeResolver

vtableGlobals

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

std::map<std::pair<DeclarationId, DeclarationId>, llvm::GlobalVariable*> sun::codegen::classes::ClassGenerator::vtableGlobals

Shared dispatch tables, keyed by concrete class and interface.

Related: DeclarationId