sun::codegen::LLVMTypeResolver

sun::codegen::LLVMTypeResolver

class · Source (opens in a new tab)

class sun::codegen::LLVMTypeResolver

LLVMTypeResolver converts sun::types::Type to llvm::Type with proper handling of:

  • Primitive types (i32 -> i32, f64 -> double, etc.)
  • Function types -> closure struct { ptr, ptr }
  • Function and lambda types

It maintains a shared closure type to ensure type equality across the module.

Public Functions

LLVMTypeResolver

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

sun::codegen::LLVMTypeResolver::LLVMTypeResolver(llvm::LLVMContext &context, const llvm::DataLayout *dl=nullptr)

Creates a type resolver using the supplied LLVM context and target layout.

enumPayloadFieldIndex

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

unsigned sun::codegen::LLVMTypeResolver::enumPayloadFieldIndex(const EnumType &enumType, const std::string &variantName, size_t i)

Per-variant view struct { i32 tag, T1, T2, ... }.

Construction and pattern extraction GEP through this on the storage pointer, so field offsets are always consistent and naturally aligned. Field index of payload i in a variant view struct (field 0 is the tag; a padding field may follow it — see getEnumVariantStruct)

Related: EnumType

getClosureType

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

StructType * sun::codegen::LLVMTypeResolver::getClosureType()

Get or create the shared closure struct type { ptr, ptr }.

All function types use this same struct for type equality.

getEnumStorageType

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

StructType * sun::codegen::LLVMTypeResolver::getEnumStorageType(const EnumType &enumType)

Storage struct for a payload enum: { i32 tag, [M x unitTy] } where unitTy matches the max payload alignment, so LLVM's natural layout aligns the payload area.

Named "<QualifiedEnum>_struct" (not a well-known internal struct, so materializeStructReturn treats returns like class values).

Related: EnumType

getEnumVariantStruct

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

StructType * sun::codegen::LLVMTypeResolver::getEnumVariantStruct(const EnumType &enumType, const std::string &variantName)

Returns the enum variant struct stored by this object.

Related: EnumType

getStaticPtrType

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

StructType * sun::codegen::LLVMTypeResolver::getStaticPtrType()

Get or create the shared static pointer struct type { ptr, i64 }.

Used for static_ptr<T> types.

isCallable

isCallable(const sun::types::Type &type)

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

static bool sun::codegen::LLVMTypeResolver::isCallable(const sun::types::Type &type)

Check if a sun::types::Type is callable (either function or lambda).

Related: sun::types::Type

isCallable(const TypePtr &type)

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

static bool sun::codegen::LLVMTypeResolver::isCallable(const TypePtr &type)

Reports whether this value can be invoked as a function.

Related: TypePtr

isFunctionType

isFunctionType(const TypePtr &type)

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

static bool sun::codegen::LLVMTypeResolver::isFunctionType(const TypePtr &type)

Reports whether a semantic type represents an ordinary function.

Related: TypePtr

isFunctionType(const sun::types::Type &type)

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

static bool sun::codegen::LLVMTypeResolver::isFunctionType(const sun::types::Type &type)

Check if a sun::types::Type is a function type (named function, direct call).

Related: sun::types::Type

isLambdaType

isLambdaType(const sun::types::Type &type)

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

static bool sun::codegen::LLVMTypeResolver::isLambdaType(const sun::types::Type &type)

Check if a sun::types::Type is a lambda type (anonymous function, fat pointer call).

Related: sun::types::Type

isLambdaType(const TypePtr &type)

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

static bool sun::codegen::LLVMTypeResolver::isLambdaType(const TypePtr &type)

Reports whether a semantic type represents a captured callable.

Related: TypePtr

prepareEnumFieldStorage

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

void sun::codegen::LLVMTypeResolver::prepareEnumFieldStorage(const sun::types::ClassType &classType)

Build storage structs for payload-enum fields (transitively) so ClassType::getStructType can embed them from the enum's cache.

Related: sun::types::ClassType, ClassType::getStructType

resolve

resolve(const sun::types::Type &type)

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

llvm::Type * sun::codegen::LLVMTypeResolver::resolve(const sun::types::Type &type)

Resolve a sun::types::Type to its corresponding llvm::Type.

  • Function types become the closure struct type
  • Primitives map directly
  • Class types become LLVM struct types

Related: sun::types::Type

resolve(const TypePtr &type)

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

llvm::Type * sun::codegen::LLVMTypeResolver::resolve(const TypePtr &type)

Maps a semantic type to the LLVM representation used in generated code.

Related: TypePtr

resolveDirectFunctionSignature

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

llvm::FunctionType * sun::codegen::LLVMTypeResolver::resolveDirectFunctionSignature(const sun::types::FunctionType &funcType)

Get the LLVM function type for a sun::types::FunctionType WITHOUT closure.

This is a direct function with no hidden parameter. Signature: (user_params...) -> return_type

Related: sun::types::FunctionType

resolveForReturn

resolveForReturn(const sun::types::Type &type)

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

llvm::Type * sun::codegen::LLVMTypeResolver::resolveForReturn(const sun::types::Type &type)

Chooses the LLVM representation for a function return value.

Related: sun::types::Type

resolveForReturn(const TypePtr &type)

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

llvm::Type * sun::codegen::LLVMTypeResolver::resolveForReturn(const TypePtr &type)

Resolve a type for use as a function return type.

For compound types (classes), this returns the struct type by value rather than a pointer, enabling proper return-by-value semantics.

Related: TypePtr

resolveFunctionSignature

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

llvm::FunctionType * sun::codegen::LLVMTypeResolver::resolveFunctionSignature(const sun::types::FunctionType &funcType)

Get the LLVM function type for a sun::types::FunctionType with closure.

This includes the hidden closure pointer as the first parameter. Signature: (ptr, user_params...) -> return_type

Related: sun::types::FunctionType

resolveLambdaSignature

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

llvm::FunctionType * sun::codegen::LLVMTypeResolver::resolveLambdaSignature(const LambdaType &lambdaType)

Get the LLVM function type for a sun::types::LambdaType.

This includes the hidden fat pointer as the first parameter. Signature: (ptr, user_params...) -> return_type

Related: LambdaType, sun::types::LambdaType

resolveParamTypes

resolveParamTypes(const sun::types::FunctionType &funcType)

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

std::vector< llvm::Type * > sun::codegen::LLVMTypeResolver::resolveParamTypes(const sun::types::FunctionType &funcType)

Resolve function parameter types.

Function parameters become closure struct types.

Related: sun::types::FunctionType

resolveParamTypes(const LambdaType &lambdaType)

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

std::vector< llvm::Type * > sun::codegen::LLVMTypeResolver::resolveParamTypes(const LambdaType &lambdaType)

Resolve lambda parameter types.

Related: LambdaType

resolveReturnType

resolveReturnType(const sun::types::FunctionType &funcType)

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

llvm::Type * sun::codegen::LLVMTypeResolver::resolveReturnType(const sun::types::FunctionType &funcType)

Resolve a function type's return type.

If the return type is itself a function, returns closure type.

Related: sun::types::FunctionType

resolveReturnType(const LambdaType &lambdaType)

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

llvm::Type * sun::codegen::LLVMTypeResolver::resolveReturnType(const LambdaType &lambdaType)

Resolve a lambda type's return type.

Related: LambdaType

Private Fields

closureType

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

llvm::StructType* sun::codegen::LLVMTypeResolver::closureType = nullptr

No documentation comment.

ctx

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

llvm::LLVMContext& sun::codegen::LLVMTypeResolver::ctx

No documentation comment.

dataLayout

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

const llvm::DataLayout* sun::codegen::LLVMTypeResolver::dataLayout = nullptr

No documentation comment.

staticPtrType

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

llvm::StructType* sun::codegen::LLVMTypeResolver::staticPtrType = nullptr

No documentation comment.

typeCache

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

std::map<sun::types::Type*, llvm::Type*> sun::codegen::LLVMTypeResolver::typeCache

No documentation comment.

Related: sun::types::Type