chigraph  master
Systems programming language written for beginners in LLVM
chi::FunctionCompiler Struct Reference

Class for compiling GraphFunctions into llvm::Functions. More...

#include <chi/FunctionCompiler.hpp>

Public Types

using DebugFile = llvm::DIFile
 
using DebugFunction = llvm::DISubprogram
 
using DebugFunctionType = llvm::DISubroutineType *
 

Public Member Functions

 FunctionCompiler (const GraphFunction &func, llvm::Module &moduleToGenInto, llvm::DICompileUnit &debugCU, llvm::DIBuilder &debugBuilder)
 Constructor. More...
 
llvm::BasicBlock & allocBlock () const
 The block for allocating variables at the beginning of the function. More...
 
Result compile ()
 Generates the contents of the function. More...
 
bool compiled () const
 Get if the function has been compiled (compile() has been called) More...
 
Contextcontext () const
 Get function().context() More...
 
DebugFunctionType createSubroutineType ()
 Create the subroutine type for the function. More...
 
llvm::DICompileUnit * debugCompileUnit () const
 The compile unit for the module. More...
 
llvm::DIBuilder & diBuilder () const
 The debug builder we're using for the module. More...
 
DebugFunction diFunction ()
 Get the debug function. More...
 
const GraphFunctionfunction () const
 Get the graph function The GraphFunction.
 
NodeCompilergetOrCreateNodeCompiler (NodeInstance &node)
 Get or create a node compiler for a node. More...
 
Result initialize (bool validate=true)
 Creates the function, but don't actually generate into it. More...
 
bool initialized () const
 Get if the function is initialized (initialize() has been called) More...
 
llvm::Function & llFunction () const
 Get the llvm function this compiler is generating. More...
 
llvm::Module & llvmModule () const
 Get the module being generated. More...
 
llvm::Value * localVariable (boost::string_view name)
 Get the value for a local variable. More...
 
GraphModulemodule () const
 Get function().module() More...
 
NodeCompilernodeCompiler (NodeInstance &node)
 Get a node compile for a certain node. More...
 
int nodeLineNumber (NodeInstance &node)
 Get the debug line number for the node instance Unique for each node. More...
 
llvm::Value & postPureBreak () const
 Get the value for the address to jump back to. More...
 

Detailed Description

Class for compiling GraphFunctions into llvm::Functions.

Definition at line 24 of file FunctionCompiler.hpp.

Constructor & Destructor Documentation

◆ FunctionCompiler()

chi::FunctionCompiler::FunctionCompiler ( const GraphFunction func,
llvm::Module &  moduleToGenInto,
llvm::DICompileUnit &  debugCU,
llvm::DIBuilder &  debugBuilder 
)

Constructor.

Parameters
funcThe function to compile
moduleToGenIntoThe module to create the function in
debugCUThe compile unit we're in
debugBuilderThe Debug information builder for the module

Definition at line 31 of file FunctionCompiler.cpp.

Member Function Documentation

◆ allocBlock()

llvm::BasicBlock& chi::FunctionCompiler::allocBlock ( ) const
inline

The block for allocating variables at the beginning of the function.

Precondition
initialized() == true
Returns
The alloc block

Definition at line 94 of file FunctionCompiler.hpp.

References initialized(), and localVariable().

Referenced by compile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compile()

Result chi::FunctionCompiler::compile ( )

Generates the contents of the function.

Precondition
initialized() == true
compiled() == false
Postcondition
compiled() == true
Returns
The Result

Definition at line 198 of file FunctionCompiler.cpp.

References allocBlock(), compiled(), chi::dependentPuresRecursive(), chi::NodeCompiler::firstBlock(), getOrCreateNodeCompiler(), initialized(), and nodeCompiler().

+ Here is the call graph for this function:

◆ compiled()

bool chi::FunctionCompiler::compiled ( ) const
inline

Get if the function has been compiled (compile() has been called)

Returns
True if it has, false otherwise

Definition at line 148 of file FunctionCompiler.hpp.

References chi::compileFunction(), getOrCreateNodeCompiler(), and nodeCompiler().

Referenced by compile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ context()

Context & chi::FunctionCompiler::context ( ) const

Get function().context()

Returns
function().context()

Definition at line 340 of file FunctionCompiler.cpp.

Referenced by createSubroutineType(), and function().

+ Here is the caller graph for this function:

◆ createSubroutineType()

FunctionCompiler::DebugFunctionType chi::FunctionCompiler::createSubroutineType ( )

Create the subroutine type for the function.

Returns
The subroutine type

Definition at line 275 of file FunctionCompiler.cpp.

References context(), chi::Context::langModule(), chi::LangModule::typeFromName(), and chi::DataType::valid().

Referenced by initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ debugCompileUnit()

llvm::DICompileUnit* chi::FunctionCompiler::debugCompileUnit ( ) const
inline

The compile unit for the module.

Returns
The DICompileUnit

Definition at line 89 of file FunctionCompiler.hpp.

Referenced by initialize().

+ Here is the caller graph for this function:

◆ diBuilder()

llvm::DIBuilder& chi::FunctionCompiler::diBuilder ( ) const
inline

The debug builder we're using for the module.

Returns
The DIBuilder

Definition at line 85 of file FunctionCompiler.hpp.

Referenced by initialize(), and chi::NodeCompiler::NodeCompiler().

+ Here is the caller graph for this function:

◆ diFunction()

DebugFunction chi::FunctionCompiler::diFunction ( )
inline

Get the debug function.

Precondition
initialized() == true
Returns
The debug function

Definition at line 73 of file FunctionCompiler.hpp.

References initialized().

+ Here is the call graph for this function:

◆ getOrCreateNodeCompiler()

NodeCompiler * chi::FunctionCompiler::getOrCreateNodeCompiler ( NodeInstance node)

Get or create a node compiler for a node.

Precondition
&node.function() == &function()
Returns
The compiler.

Definition at line 362 of file FunctionCompiler.cpp.

References chi::NodeInstance::function().

Referenced by compile(), and compiled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialize()

Result chi::FunctionCompiler::initialize ( bool  validate = true)

Creates the function, but don't actually generate into it.

Precondition
initialized() == false
Postcondition
initialized() == true
Parameters
validateShould the module be validated (using functions in FunctionValidator.hpp)?
Returns
The Result

Definition at line 35 of file FunctionCompiler.cpp.

References chi::Result::addEntry(), chi::Result::addScopedContext(), chi::GraphModule::createLineNumberAssoc(), createSubroutineType(), debugCompileUnit(), diBuilder(), chi::ChiModule::fullName(), initialized(), llvmModule(), chi::mangleFunctionName(), module(), nodeLineNumber(), and chi::validateFunction().

+ Here is the call graph for this function:

◆ initialized()

bool chi::FunctionCompiler::initialized ( ) const
inline

Get if the function is initialized (initialize() has been called)

Returns
True if it is, false otherwise

Definition at line 144 of file FunctionCompiler.hpp.

Referenced by allocBlock(), compile(), diFunction(), initialize(), llFunction(), localVariable(), and postPureBreak().

+ Here is the caller graph for this function:

◆ llFunction()

llvm::Function& chi::FunctionCompiler::llFunction ( ) const
inline

Get the llvm function this compiler is generating.

Precondition
initialized() == true
Returns
The function.

Definition at line 108 of file FunctionCompiler.hpp.

References initialized().

+ Here is the call graph for this function:

◆ llvmModule()

llvm::Module& chi::FunctionCompiler::llvmModule ( ) const
inline

Get the module being generated.

Returns
The Module

Definition at line 81 of file FunctionCompiler.hpp.

Referenced by initialize(), and chi::NodeCompiler::llvmModule().

+ Here is the caller graph for this function:

◆ localVariable()

llvm::Value * chi::FunctionCompiler::localVariable ( boost::string_view  name)

Get the value for a local variable.

Precondition
initialized() == true
Returns
nullptr if it doesn't exist. A value if it's valid.

Definition at line 330 of file FunctionCompiler.cpp.

References initialized().

Referenced by allocBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ module()

GraphModule & chi::FunctionCompiler::module ( ) const

Get function().module()

Returns
function().module()

Definition at line 339 of file FunctionCompiler.cpp.

Referenced by function(), and initialize().

+ Here is the caller graph for this function:

◆ nodeCompiler()

NodeCompiler * chi::FunctionCompiler::nodeCompiler ( NodeInstance node)

Get a node compile for a certain node.

Precondition
&node.function() == &function()
Returns
The node compiler for the function

Definition at line 353 of file FunctionCompiler.cpp.

References chi::NodeInstance::function().

Referenced by compile(), chi::NodeCompiler::compile_stage1(), and compiled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nodeLineNumber()

int chi::FunctionCompiler::nodeLineNumber ( NodeInstance node)

Get the debug line number for the node instance Unique for each node.

Precondition
&node.function() == &function()
Parameters
nodeThe instance to get the line number for
Returns
The line number

Definition at line 342 of file FunctionCompiler.cpp.

References chi::NodeInstance::function().

Referenced by function(), and initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ postPureBreak()

llvm::Value& chi::FunctionCompiler::postPureBreak ( ) const
inline

Get the value for the address to jump back to.

Precondition
initialized() == true
Returns
The value

Definition at line 117 of file FunctionCompiler.hpp.

References initialized().

+ Here is the call graph for this function:

The documentation for this struct was generated from the following files: