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
- createInterfaceView
- declareBlockClassMethods
- declareMethodFromAST
- generateMethodBody
- getOrCreateInterfaceVtable
- interfaceViewAddress
- moduleMemberGlobal
- operator=
- prepareInterfaceReference
- 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
createInterfaceView
public · function · Source (opens in a new tab)
Value * sun::codegen::classes::ClassGenerator::createInterfaceView(llvm::Value *address, TypePtr sourceType, InterfaceType *target)Builds the two-pointer value used for an interface borrow.
For example, borrowing an Item as a Node pairs its address with Item's Node table. Borrowing a Child owner as a Node keeps its receiver and selects the ancestor table.
param
-
address: Address of the concrete object, owner, or borrowed view. -
sourceType: Sun type of the source, including its reference qualifier. -
target: Interface required by the borrower.
return: The receiver and dispatch table as an LLVM struct value.
Related: TypePtr, 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
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
interfaceViewAddress
public · function · Source (opens in a new tab)
Value * sun::codegen::classes::ClassGenerator::interfaceViewAddress(llvm::Value *address, TypePtr sourceType)Locates the borrowed view within an interface handle.
For example, an owning value: INode has the following layout.
[owner][object][vtable][deinit]
^ ^
input result
A caller can load the object and vtable pointers together at the result address. For view: ref INode, the input already points to that pair.
param
-
address: LLVM pointer to the source value's storage. -
sourceType: Sun type of the source, including any reference qualifier.
return: The address of the object pointer field for an owning interface, or address itself for any other source type.
Related: TypePtr
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
prepareInterfaceReference
public · function · Source (opens in a new tab)
Value * sun::codegen::classes::ClassGenerator::prepareInterfaceReference(llvm::Value *address, TypePtr sourceType, TypePtr targetType)Prepares an address for binding a borrowed interface reference.
For example, borrowing an INode owner reuses its embedded view. Borrowing a concrete Node or converting to a parent interface needs a new view.
param
-
address: Address of the source value. -
sourceType: Sun type of the source, including its reference qualifier. -
targetType: Sun type of the binding or parameter.
return: The view address, or the input address for other reference bindings.
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 view or moved owner to an ancestor by replacing its table.
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
- 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.
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