Interfaces that the rest of the LLVM Backend code uses.
Code Map
//! Interfaces that the rest of the LLVM Backend code uses.
module volt.llvm.interfaces;
public import lib.llvm.core;
public import volta.ir.location;
public import volt.interfaces;
public import volta.ir = volta.ir
public import volt.llvm.debugInfo;
public import volt.llvm.type;
//! Represents a single LLVMValueRef plus the associated high level type.
class Value
{
public:
type: Type;
value: LLVMValueRef;
//! Is this a reference to the real value?
isPointer: bool;
public:
this() { }
this(val: Value) { }
}
//! Collection of objects used by pretty much all of the translation code.
//! It isn't called Module, Context or Builder because it will collide in
//! meaning with LLVM and language concepts.
class State
{
public:
class PathState
{
public:
prev: PathState;
landingBlock: LLVMBasicBlockRef;
continueBlock: LLVMBasicBlockRef;
breakBlock: LLVMBasicBlockRef;
scopeSuccess: LLVMValueRef[];
scopeFailure: LLVMValueRef[];
scopeLanding: LLVMBasicBlockRef[];
catchBlock: LLVMBasicBlockRef;
catchTypeInfos: LLVMValueRef[];
public:
this() { }
}
struct SwitchState
{
public:
def: LLVMBasicBlockRef;
cases: LLVMBasicBlockRef[i64];
}
struct FunctionState
{
public:
func: LLVMValueRef;
di: LLVMMetadataRef;
//! Tracking for auto branch generation.
fall: bool;
//! Nested value
nested: LLVMValueRef;
path: PathState;
entryBr: LLVMValueRef;
block: LLVMBasicBlockRef;
swi: SwitchState;
indexVar: LLVMValueRef;
exceptionVar: LLVMValueRef;
resumeBlock: LLVMBasicBlockRef;
exitBlock: LLVMBasicBlockRef;
}
public:
lp: LanguagePass;
target: TargetInfo;
irMod: ir.Module;
currentWorkingDir: string;
execDir: string;
identStr: string;
ehPersonality: ir.Function;
llvmTypeidFor: ir.Function;
context: LLVMContextRef;
builder: LLVMBuilderRef;
diBuilder: LLVMDIBuilderRef;
mod: LLVMModuleRef;
//! Cached llvm attributes.
attrSRet: LLVMAttributeRef;
//! Cached llvm attributes.
attrByVal: LLVMAttributeRef;
//! Cached llvm attributes.
attrUWTable: LLVMAttributeRef;
fnState: FunctionState;
//! Global and local constructors and destructors.
globalConstructors: LLVMValueRef[];
//! Global and local constructors and destructors.
globalDestructors: LLVMValueRef[];
//! Global and local constructors and destructors.
localConstructors: LLVMValueRef[];
//! Global and local constructors and destructors.
localDestructors: LLVMValueRef[];
//! Debug helper variables.
diCU: LLVMMetadataRef;
//! Cached type for convenience.
voidType: VoidType;
//! Cached type for convenience.
boolType: PrimitiveType;
//! Cached type for convenience.
byteType: PrimitiveType;
//! Cached type for convenience.
ubyteType: PrimitiveType;
//! Cached type for convenience.
intType: PrimitiveType;
//! Cached type for convenience.
uintType: PrimitiveType;
//! Cached type for convenience.
ulongType: PrimitiveType;
//! Cached type for convenience.
voidPtrType: PointerType;
//! Cached type for convenience.
sizeType: PrimitiveType;
//! Cached type for convenience.
voidFunctionType: FunctionType;
//! Cached type for convenience.
springType: FunctionType;
public:
this() { }
fn func() LLVMValueRef { }
fn fall() bool { }
fn block() LLVMBasicBlockRef { }
fn path() PathState { }
fn switchDefault() LLVMBasicBlockRef { }
fn switchSetCase(val: i64, ret: LLVMBasicBlockRef) LLVMBasicBlockRef { }
fn switchGetCase(val: i64, ret: LLVMBasicBlockRef) bool { }
fn findLanding() PathState { }
fn findCatch() PathState { }
fn findContinue() PathState { }
fn findBreak() PathState { }
//! LLVM intrinsic.
fn llvmTrap() LLVMValueRef;
//! Exception handling.
fn ehPersonalityFunc() LLVMValueRef;
//! Exception handling.
fn ehTypeIdFunc() LLVMValueRef;
//! Exception handling.
fn ehLandingType() LLVMTypeRef;
//! Exception handling.
fn ehResumeBlock() LLVMBasicBlockRef;
//! Exception handling.
fn ehExitBlock() LLVMBasicBlockRef;
//! Exception handling.
fn ehIndexVar() LLVMValueRef;
//! Exception handling.
fn ehExceptionVar() LLVMValueRef;
fn close();
fn onFunctionClose();
//! Build a complete module with this state.
fn compile(m: ir.Module);
//! Builds the given statement class at the current place, and any
//! sub-expressions & -statements.
fn evaluateStatement(node: ir.Node);
//! Builds a 'alloca' instructions and inserts it at the end of the entry
//! basic block that is at the top of the function.
fn buildAlloca(llvmType: LLVMTypeRef, name: string) LLVMValueRef { }
//! Returns the LLVMValueRef for the given expression, evaluated at the
//! current state.builder location.
fn getValue(exp: ir.Exp) LLVMValueRef { }
//! Returns the value, making sure that the value is not in reference form,
//! basically inserting load instructions where needed.
fn getValue(exp: ir.Exp, result: Value) { }
//! Returns the value in reference form, basically meaning that the return
//! value is a pointer to where it is held in memory.
fn getValueRef(exp: ir.Exp, result: Value) { }
//! Returns the value, without doing any checking if it is in reference
//! form or not.
fn getValueAnyForm(exp: ir.Exp, result: Value);
//! Returns the LLVMValueRef for the given constant expression, does not
//! require that state.builder is set.
fn getConstant(exp: ir.Exp) LLVMValueRef;
//! Returns the value, without doing any checking if it is in reference
//! form or not.
fn getConstantValueAnyForm(exp: ir.Exp, result: Value);
//! Makes a private mergable global constant. Used for strings, array
//! literal and storage for struct literals.
fn makeAnonGlobalConstant(t: LLVMTypeRef, val: LLVMValueRef) LLVMValueRef { }
//! Return the LLVMValueRef for the given Function.
fn getFunctionValue(func: ir.Function, type: Type) LLVMValueRef;
//! Return the LLVMValueRef for the given Variable.
fn getVariableValue(var: ir.Variable, type: Type) LLVMValueRef;
fn getVariableValue(var: ir.FunctionParam, type: Type) LLVMValueRef;
fn makeByValVariable(var: ir.FunctionParam, v: LLVMValueRef);
fn makeThisVariable(var: ir.Variable, v: LLVMValueRef);
fn makeNestVariable(var: ir.Variable, v: LLVMValueRef);
fn addType(type: Type, mangledName: string);
fn getTypeNoCreate(mangledName: string) Type;
//! Builds a call instruction, and set the location for the call
//! automatically.
fn buildCallNeverInvoke(loc: Location, argFunc: LLVMValueRef, args: LLVMValueRef[]) LLVMValueRef;
//! Builds either a call or a invoke. If invoke automatically sets up a
//! catch basic block and sets the currentBlock to it.
fn buildCallOrInvoke(loc: Location, func: LLVMValueRef, args: LLVMValueRef[]) LLVMValueRef;
//! Builds either a call or a invoke. If invoke automatically sets up a
//! catch basic block and sets the currentBlock to it.
fn buildCallOrInvoke(loc: Location, func: LLVMValueRef, args: LLVMValueRef[], landingPad: LLVMBasicBlockRef) LLVMValueRef;
//! Start using a new basic block, setting currentBlock.
fn startBlock(b: LLVMBasicBlockRef) { }
//! Helper function to swap out the currentContineBlock, returns the old
//! one.
fn replaceContinueBlock(b: LLVMBasicBlockRef) LLVMBasicBlockRef { }
//! Helper function to swap out the currentBreakBlock, returns the old
//! one.
fn replaceBreakBlock(b: LLVMBasicBlockRef) LLVMBasicBlockRef { }
//! Push a new Path, setting prev as needed.
fn pushPath() { }
//! Pop a PathState.
fn popPath() { }
}
Represents a single LLVMValueRef plus the associated high level type.
A Value can be in reference form where it is actually a pointer to the give value, since all variables are stored as alloca'd memory in a function we will not insert loads until needed. This is needed for '&' to work and struct lookups.
Is this a reference to the real value?
Collection of objects used by pretty much all of the translation code. It isn't called Module, Context or Builder because it will collide in meaning with LLVM and language concepts.
One is created for each Volt module that is compiled.
Cached llvm attributes.
Cached llvm attributes.
Cached llvm attributes.
Global and local constructors and destructors.
Global and local constructors and destructors.
Global and local constructors and destructors.
Global and local constructors and destructors.
Debug helper variables.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
Cached type for convenience.
LLVM intrinsic.
Exception handling.
Exception handling.
Exception handling.
Exception handling.
Exception handling.
Exception handling.
Exception handling.
Build a complete module with this state.
Builds the given statement class at the current place, and any sub-expressions & -statements.
Builds a 'alloca' instructions and inserts it at the end of the entry basic block that is at the top of the function.
Returns the LLVMValueRef for the given expression, evaluated at the current state.builder location.
Returns the value, making sure that the value is not in reference form, basically inserting load instructions where needed.
Returns the value in reference form, basically meaning that the return value is a pointer to where it is held in memory.
Returns the value, without doing any checking if it is in reference form or not.
Returns the LLVMValueRef for the given constant expression, does not require that state.builder is set.
Returns the value, without doing any checking if it is in reference form or not.
Makes a private mergable global constant. Used for strings, array literal and storage for struct literals.
Return the LLVMValueRef for the given Function.
If the value is not defined it will do so.
Return the LLVMValueRef for the given Variable.
If the value is not defined it will do so.
Builds a call instruction, and set the location for the call automatically.
Gets the landingPad from the current state.
Builds either a call or a invoke. If invoke automatically sets up a catch basic block and sets the currentBlock to it.
Gets the landingPad from the current state.
Builds either a call or a invoke. If invoke automatically sets up a catch basic block and sets the currentBlock to it.
Uses the given landingPad.
Start using a new basic block, setting currentBlock.
Side-Effects: Will reset currentFall. Will set the builder to the end of the given block.
Helper function to swap out the currentContineBlock, returns the old one.
Helper function to swap out the currentBreakBlock, returns the old one.
Push a new Path, setting prev as needed.
Pop a PathState.