sun::codegen::classes::ClassGenerator
class · Source (opens in a new tab)
class sun::codegen::classes::ClassGeneratorEmits 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 &)=deleteA 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
- codegenPrecompiledClass
- codegenStackClassInstance
- createBorrowedInterfaceUpcast
- createInterfaceFatPointer
- declareBlockClassMethods
- declareMethodFromAST
- finishFallibleConstruction
- generateMethodBody
- getOrCreateInterfaceVtable
- moduleMemberGlobal
- operator=
- prepareClassForRefInterface
- upcastInterface
ClassGenerator
ClassGenerator(const ClassGenerator &)=delete
public · function · Source (opens in a new tab)
sun::codegen::classes::ClassGenerator::ClassGenerator(const ClassGenerator &)=deleteBinds 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 &)=deleteDisallows 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
- codegenBoundMethodReference
- codegenObjectPtr
- createEntryBlockAlloca
- debugDeclareParam
- declareClassMethods
- emitCallArguments
- emitMethodPrologueThis
- functions
- generateCtorArgs
- intrinsics
- isPrecompiledFunction
- materializeMethodClosure
- materializeMethodClosureValue
- scopes
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.
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 > ¶mTypes, 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 > ¶mTypes)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
- ctx
- currentClass
- currentFunctionCanError
- currentFunctionReturnsRef
- currentFunctionValueType
- debugInfo
- gen_
- librarySpecializations
- module
- state_
- thisPtr
- typeRegistry
- typeResolver
- vtableGlobals
codegenedClasses
private · variable · Source (opens in a new tab)
std::set<DeclarationId> sun::codegen::classes::ClassGenerator::codegenedClassesNo documentation comment.
Related: DeclarationId
ctx
private · variable · Source (opens in a new tab)
sun::codegen::CodegenContext& sun::codegen::classes::ClassGenerator::ctxNo documentation comment.
Related: sun::codegen::CodegenContext
currentClass
private · variable · Source (opens in a new tab)
std::shared_ptr<ClassType>& sun::codegen::classes::ClassGenerator::currentClassNo documentation comment.
Related: ClassType
currentFunctionCanError
private · variable · Source (opens in a new tab)
bool& sun::codegen::classes::ClassGenerator::currentFunctionCanErrorNo documentation comment.
currentFunctionReturnsRef
private · variable · Source (opens in a new tab)
bool& sun::codegen::classes::ClassGenerator::currentFunctionReturnsRefNo documentation comment.
currentFunctionValueType
private · variable · Source (opens in a new tab)
llvm::Type*& sun::codegen::classes::ClassGenerator::currentFunctionValueTypeNo documentation comment.
debugInfo
private · variable · Source (opens in a new tab)
sun::codegen::DebugInfoBuilder& sun::codegen::classes::ClassGenerator::debugInfoNo 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::librarySpecializationsNo documentation comment.
Related: DeclarationId
module
private · variable · Source (opens in a new tab)
llvm::Module* sun::codegen::classes::ClassGenerator::moduleNo 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::thisPtrNo documentation comment.
typeRegistry
private · variable · Source (opens in a new tab)
std::shared_ptr<sun::semantic_analysis::TypeRegistry>& sun::codegen::classes::ClassGenerator::typeRegistryNo documentation comment.
Related: sun::semantic_analysis::TypeRegistry
typeResolver
private · variable · Source (opens in a new tab)
sun::codegen::LLVMTypeResolver& sun::codegen::classes::ClassGenerator::typeResolverNo 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::vtableGlobalsShared dispatch tables, keyed by concrete class and interface.
Related: DeclarationId