sun::codegen::errors::ErrorGenerator

sun::codegen::errors::ErrorGenerator

class · Source (opens in a new tab)

class sun::codegen::errors::ErrorGenerator

Emits throw, try/catch, and every call that might unwind.

Functions

codegen

codegen(const ExprAST &expr)

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

llvm::Value * sun::codegen::errors::ErrorGenerator::codegen(const ExprAST &expr)

What throwing and catching borrow from the rest of codegen.

Related: ExprAST

codegen(const sun::ast::BlockExprAST &block)

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

llvm::Value * sun::codegen::errors::ErrorGenerator::codegen(const sun::ast::BlockExprAST &block)

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

Related: sun::ast::BlockExprAST

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

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

Value * sun::codegen::errors::ErrorGenerator::codegen(const sun::ast::TryCatchExprAST &expr)

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

Related: sun::ast::TryCatchExprAST

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

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

Value * sun::codegen::errors::ErrorGenerator::codegen(const sun::ast::UnsafeBlockAST &expr)

The body is emitted as written, in a scope of its own; the block's value is handed out to the enclosing scope.

Safety checks are done in sema.

Related: sun::ast::UnsafeBlockAST

codegen(const T &)=delete

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

template <typename T>
llvm::Value * sun::codegen::errors::ErrorGenerator::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::ThrowExprAST &expr)

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

Value * sun::codegen::errors::ErrorGenerator::codegen(const sun::ast::ThrowExprAST &expr)

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

Related: sun::ast::ThrowExprAST

Public Functions

ErrorGenerator

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

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

sun::codegen::errors::ErrorGenerator::ErrorGenerator(sun::codegen::CodegenState &state, sun::codegen::CodegenVisitor &gen)

Binds error propagation generation to the shared expression visitor and state.

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

ErrorGenerator(const ErrorGenerator &)=delete

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

sun::codegen::errors::ErrorGenerator::ErrorGenerator(const ErrorGenerator &)=delete

Binds error propagation generation to the shared expression visitor and state.

emitArithmeticErrorMethods

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

void sun::codegen::errors::ErrorGenerator::emitArithmeticErrorMethods(bool defineBodies=false)

Declares builtin error methods, optionally defining only referenced methods.

emitPossiblyThrowingCall

emitPossiblyThrowingCall(llvm::FunctionType *fnTy, llvm::Value *callee, llvm::ArrayRef< llvm::Value * > args, bool canThrow, const llvm::Twine &name)

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

llvm::Value * sun::codegen::errors::ErrorGenerator::emitPossiblyThrowingCall(llvm::FunctionType *fnTy, llvm::Value *callee, llvm::ArrayRef< llvm::Value * > args, bool canThrow, const llvm::Twine &name)

Emits a call that may unwind.

If canThrow and we are inside a try block, emits an invoke unwinding to the innermost try's landing pad and continues codegen in the normal-destination block; otherwise emits a plain call.

emitPossiblyThrowingCall(llvm::FunctionCallee callee, llvm::ArrayRef< llvm::Value * > args, bool canThrow, const llvm::Twine &name)

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

llvm::Value * sun::codegen::errors::ErrorGenerator::emitPossiblyThrowingCall(llvm::FunctionCallee callee, llvm::ArrayRef< llvm::Value * > args, bool canThrow, const llvm::Twine &name)

Emits a call and propagates its error result when the callee can throw.

operator=

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

ErrorGenerator & sun::codegen::errors::ErrorGenerator::operator=(const ErrorGenerator &)=delete

Disallows assignment so ownership and object identity cannot be duplicated.

Related: ErrorGenerator

throwArithmeticError

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

void sun::codegen::errors::ErrorGenerator::throwArithmeticError(int code)

Constructs and throws ArithmeticError, cleaning up live owners.

Private Functions

activeTry

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

TryContext * sun::codegen::errors::ErrorGenerator::activeTry()

Returns the innermost try in the function currently being emitted.

Related: TryContext

currentFunctionCanError

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

bool sun::codegen::errors::ErrorGenerator::currentFunctionCanError() const

True when the function being emitted may return errors.

debugDeclareLocal

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

void sun::codegen::errors::ErrorGenerator::debugDeclareLocal(llvm::AllocaInst *alloca, const std::string &name, const sun::types::TypePtr &type, const sun::support::Position &loc)

Associates local storage with its source variable for debugging.

Related: sun::types::TypePtr, sun::support::Position

emitCxaThrowAndUnreachable

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

void sun::codegen::errors::ErrorGenerator::emitCxaThrowAndUnreachable(llvm::Value *excPtr, llvm::Function *destructor)

Emit __cxa_throw(excPtr, tinfo, destructor) (as an invoke to the innermost try's landing pad if inside a try, else a plain call), terminate the current block with unreachable, and leave the builder in a fresh dead block.

emitRethrow

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

void sun::codegen::errors::ErrorGenerator::emitRethrow()

Rethrows the active exception and ends exited catches during unwinding.

ensurePersonality

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

void sun::codegen::errors::ErrorGenerator::ensurePersonality(llvm::Function *fn)

Ensure fn has a personality function set (needed for any function that contains an invoke/landingpad).

Idempotent.

exceptionDestructor

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

llvm::Function * sun::codegen::errors::ErrorGenerator::exceptionDestructor(sun::types::ClassType *type)

Emits the callback that drops a concrete payload without freeing its buffer.

Related: sun::types::ClassType

exceptionStorageType

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

llvm::StructType * sun::codegen::errors::ErrorGenerator::exceptionStorageType(sun::types::ClassType *type)

Builds aligned exception storage containing the tag, view, and payload.

Related: sun::types::ClassType

getCxaAllocateException

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

FunctionCallee sun::codegen::errors::ErrorGenerator::getCxaAllocateException()

Get or declare the C++ ABI exception handling functions.

getCxaBeginCatch

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

FunctionCallee sun::codegen::errors::ErrorGenerator::getCxaBeginCatch()

Returns the cxa begin catch stored by this object.

getCxaEndCatch

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

FunctionCallee sun::codegen::errors::ErrorGenerator::getCxaEndCatch()

Returns the cxa end catch stored by this object.

getCxaRethrow

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

FunctionCallee sun::codegen::errors::ErrorGenerator::getCxaRethrow()

Returns the cxa rethrow stored by this object.

getCxaThrow

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

FunctionCallee sun::codegen::errors::ErrorGenerator::getCxaThrow()

Returns the cxa throw stored by this object.

getPersonalityFunction

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

Constant * sun::codegen::errors::ErrorGenerator::getPersonalityFunction()

Returns the personality function stored by this object.

getSunExceptionTypeInfo

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

Constant * sun::codegen::errors::ErrorGenerator::getSunExceptionTypeInfo()

Returns the runtime type information for Sun exceptions.

scopes

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

sun::codegen::scopes::ScopeManager & sun::codegen::errors::ErrorGenerator::scopes()

Provides the scope manager responsible for variable storage and cleanup.

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

typeRegistry

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

std::shared_ptr< sun::semantic_analysis::TypeRegistry > & sun::codegen::errors::ErrorGenerator::typeRegistry()

Provides the semantic types available to this code generator.

Related: sun::semantic_analysis::TypeRegistry

Private Fields

ctx

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

sun::codegen::CodegenContext& sun::codegen::errors::ErrorGenerator::ctx

No documentation comment.

Related: sun::codegen::CodegenContext

gen_

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

sun::codegen::CodegenVisitor& sun::codegen::errors::ErrorGenerator::gen_

No documentation comment.

Related: sun::codegen::CodegenVisitor

module

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

llvm::Module* sun::codegen::errors::ErrorGenerator::module

No documentation comment.

state_

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

sun::codegen::CodegenState& sun::codegen::errors::ErrorGenerator::state_

No documentation comment.

Related: sun::codegen::CodegenState

tryStack

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

std::vector<TryContext> sun::codegen::errors::ErrorGenerator::tryStack

No documentation comment.

Related: TryContext