6 #ifndef CHI_FUNCTION_COMPILER_HPP 7 #define CHI_FUNCTION_COMPILER_HPP 13 #include <llvm/IR/DebugInfo.h> 16 #include <unordered_map> 18 #include <boost/bimap.hpp> 19 #include <boost/utility/string_view.hpp> 31 llvm::DICompileUnit& debugCU, llvm::DIBuilder& debugBuilder);
47 using DebugFunctionType =
48 #if LLVM_VERSION_LESS_EQUAL(3, 6) 51 llvm::DISubroutineType*
59 using DebugFunction = llvm::DISubprogram
60 #if LLVM_VERSION_AT_LEAST(3, 7) 64 using DebugFile = llvm::DIFile
65 #if LLVM_VERSION_AT_LEAST(3, 7) 75 "Please initialize the function compiler before getting the debug function");
85 llvm::DIBuilder&
diBuilder()
const {
return *mDIBuilder; }
96 "Please initialize the function compiler before getting the alloc block");
110 "Please initialize the function compiler before trying to get the LLVM function");
119 "Please initialize the function compiler before trying to get the post-pure break");
120 return *mPostPureBreak;
161 std::unordered_map<std::string, llvm::Value*> mLocalVariables;
163 llvm::Module* mModule =
nullptr;
164 llvm::DIBuilder* mDIBuilder =
nullptr;
165 llvm::DICompileUnit* mDebugCU =
nullptr;
167 DebugFunction mDebugFunc{};
171 llvm::Function* mLLFunction =
nullptr;
172 llvm::BasicBlock* mAllocBlock =
nullptr;
174 std::unordered_map<NodeInstance*, NodeCompiler> mNodeCompilers;
176 boost::bimap<unsigned, NodeInstance*> mNodeLocations;
178 bool mInitialized =
false;
179 bool mCompiled =
false;
181 llvm::Value* mPostPureBreak =
nullptr;
191 llvm::DIBuilder& debugBuilder);
194 #endif // CHI_FUNCTION_COMPILER_HPP
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
NodeCompiler * nodeCompiler(NodeInstance &node)
Get a node compile for a certain node.
Forward declares all the chigraph data types.
llvm::Module & llvmModule() const
Get the module being generated.
DebugFunction diFunction()
Get the debug function.
Result compile()
Generates the contents of the function.
llvm::DICompileUnit * debugCompileUnit() const
The compile unit for the module.
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Class for compiling GraphFunctions into llvm::Functions.
llvm::Value & postPureBreak() const
Get the value for the address to jump back to.
int nodeLineNumber(NodeInstance &node)
Get the debug line number for the node instance Unique for each node.
llvm::BasicBlock & allocBlock() const
The block for allocating variables at the beginning of the function.
NodeCompiler * getOrCreateNodeCompiler(NodeInstance &node)
Get or create a node compiler for a node.
bool compiled() const
Get if the function has been compiled (compile() has been called)
FunctionCompiler(const GraphFunction &func, llvm::Module &moduleToGenInto, llvm::DICompileUnit &debugCU, llvm::DIBuilder &debugBuilder)
Constructor.
Result compileFunction(const GraphFunction &func, llvm::Module *mod, llvm::DICompileUnit *debugCU, llvm::DIBuilder &debugBuilder)
Compile the graph to an llvm::Function (usually called from JsonModule::generateModule) ...
llvm::Value * localVariable(boost::string_view name)
Get the value for a local variable.
Context & context() const
Get function().context()
llvm::DIBuilder & diBuilder() const
The debug builder we're using for the module.
Module that holds graph functions.
llvm::Function & llFunction() const
Get the llvm function this compiler is generating.
The namespace where chigraph lives.
Result initialize(bool validate=true)
Creates the function, but don't actually generate into it.
bool initialized() const
Get if the function is initialized (initialize() has been called)
The result object, used for identifiying errors with good diagnostics.
GraphModule & module() const
Get function().module()
DebugFunctionType createSubroutineType()
Create the subroutine type for the function.