sun::codegen::support
namespace · Source (opens in a new tab)
Provides scalar conversions and checked integer arithmetic emission.
Provides shared diagnostics, source tracking, and compiler utilities.
Emits scalar conversions and arithmetic shared by code generators.
Structs
- sun::codegen::support::TypeCheck (public)
Functions
- createIntDivRem
- createIntShift
- describeKind
- extendInt
- fieldAlign
- fieldPtr
- getPointeeType
- lvalueAlign
- requireType
- requireTypePtr
- storeIntoSlot
- tryGetType
- tryGetTypePtr
- widenNumericIfNeeded
createIntDivRem
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::support::createIntDivRem(llvm::IRBuilder<> &builder, llvm::Value *L, llvm::Value *R, bool isModulo, bool isUnsigned, llvm::function_ref< void(int)> throwError)Checks and emits integer division or remainder.
The callback emits a terminating throw for division by zero (code 4) or signed overflow (code 5).
createIntShift
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::support::createIntShift(llvm::IRBuilder<> &builder, llvm::Value *L, llvm::Value *R, bool isRight, bool isUnsigned)Emits a shift with the count masked to the widened operand bit width.
describeKind
public · function · Source (opens in a new tab)
const char * sun::codegen::support::describeKind(sun::types::Type::Kind kind)How a kind is named in an error message ("must be a class type").
Related: sun::types::Type::Kind
extendInt
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::support::extendInt(llvm::IRBuilder<> &builder, llvm::Value *value, llvm::Type *destTy, const TypePtr &sourceType)Widens an integer to destTy.
Extends an integer to the requested width using its signedness.
The source expression's Sun type decides zero- versus sign-extension, and this is the single place that owns that rule.
Related: TypePtr
fieldAlign
public · function · Source (opens in a new tab)
llvm::Align sun::codegen::support::fieldAlign(const ClassType *owner, llvm::Type *fieldTy, const llvm::DataLayout &dl)Alignment for a field access, honouring packed layout.
Returns the alignment available for a class field access.
owner is the class the field belongs to; a packed owner drops the alignment to 1. Pass nullptr for a standalone slot such as a local variable.
Related: ClassType
fieldPtr
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::support::fieldPtr(llvm::IRBuilder<> &builder, ClassType *classType, llvm::Value *objectPtr, const sun::types::ClassField &field, const std::string &name)Address of one field of a class instance.
Computes the LLVM address of a field in class storage.
Related: ClassType, sun::types::ClassField
getPointeeType
public · function · Source (opens in a new tab)
TypePtr sun::codegen::support::getPointeeType(const TypePtr &type)What a raw_ptr<T> or static_ptr<T> points at; null for every other type.
Both spellings are just an address at a call site, so the code that looks through one rarely cares which it had.
Related: TypePtr
lvalueAlign
public · function · Source (opens in a new tab)
llvm::Align sun::codegen::support::lvalueAlign(const sun::ast::ExprAST &target, llvm::Type *slotTy, const llvm::DataLayout &dl)Alignment for writing through an lvalue.
Returns the alignment available when accessing an assignable expression.
Related: sun::ast::ExprAST
requireType
requireType(const TypePtr &type, std::string_view what, std::optional< sun::support::Position > loc=std::nullopt)
public · function · Source (opens in a new tab)
template <typename T>
T & sun::codegen::support::requireType(const TypePtr &type, std::string_view what, std::optional< sun::support::Position > loc=std::nullopt)Returns the requested semantic type or reports a type mismatch.
Related: TypePtr, sun::support::Position
requireType(const ExprAST &expr, std::string_view what)
public · function · Source (opens in a new tab)
template <typename T>
T & sun::codegen::support::requireType(const ExprAST &expr, std::string_view what)Returns the requested semantic type or reports a type mismatch.
Related: ExprAST
requireTypePtr
requireTypePtr(const ExprAST &expr, std::string_view what)
public · function · Source (opens in a new tab)
template <typename T>
std::shared_ptr< T > sun::codegen::support::requireTypePtr(const ExprAST &expr, std::string_view what)Returns a pointer to the requested semantic type or reports a mismatch.
Related: ExprAST
requireTypePtr(const TypePtr &type, std::string_view what, std::optional< sun::support::Position > loc=std::nullopt)
public · function · Source (opens in a new tab)
template <typename T>
std::shared_ptr< T > sun::codegen::support::requireTypePtr(const TypePtr &type, std::string_view what, std::optional< sun::support::Position > loc=std::nullopt)Returns a pointer to the requested semantic type or reports a mismatch.
Related: TypePtr, sun::support::Position
storeIntoSlot
public · function · Source (opens in a new tab)
void sun::codegen::support::storeIntoSlot(llvm::IRBuilder<> &builder, const llvm::DataLayout &dl, llvm::Value *dest, llvm::Value *value, const sun::types::TypePtr &slotType, const ClassType *owner=nullptr)Writes a value into a storage slot, copying the struct when the slot is a class.
Stores a generated value with the alignment required by its storage.
Codegen of a class-valued expression yields the object's ADDRESS, not the struct itself. Storing that address would write a pointer over the object's leading bytes — and it fits silently, because a two-word class is exactly pointer-sized, so the mistake surfaces as corrupted fields rather than as a verifier error. Every site that writes a class into storage goes through here so the copy cannot be forgotten again.
Related: sun::types::TypePtr, ClassType
tryGetType
tryGetType(const TypePtr &type)
public · function · Source (opens in a new tab)
template <typename T>
T * sun::codegen::support::tryGetType(const TypePtr &type)Returns the requested semantic type when it matches, otherwise no result.
Related: TypePtr
tryGetType(const ExprAST &expr)
public · function · Source (opens in a new tab)
template <typename T>
T * sun::codegen::support::tryGetType(const ExprAST &expr)Returns the requested semantic type when it matches, otherwise no result.
Related: ExprAST
tryGetTypePtr
tryGetTypePtr(const ExprAST &expr)
public · function · Source (opens in a new tab)
template <typename T>
std::shared_ptr< T > sun::codegen::support::tryGetTypePtr(const ExprAST &expr)Returns a pointer to the requested semantic type when it matches.
Related: ExprAST
tryGetTypePtr(const TypePtr &type)
public · function · Source (opens in a new tab)
template <typename T>
std::shared_ptr< T > sun::codegen::support::tryGetTypePtr(const TypePtr &type)Returns a pointer to the requested semantic type when it matches.
Related: TypePtr
widenNumericIfNeeded
public · function · Source (opens in a new tab)
llvm::Value * sun::codegen::support::widenNumericIfNeeded(llvm::IRBuilder<> &builder, sun::codegen::LLVMTypeResolver &types, llvm::Value *argVal, const TypePtr ¶mType, const TypePtr &sourceType)Widens an integer or float argument to what the parameter expects (i32 to i64, f32 to f64).
Widens numeric operands to a compatible LLVM representation when needed.
Returns the value unchanged if no widening is needed.
Related: sun::codegen::LLVMTypeResolver, TypePtr