8 #ifndef LLVMCodeGenBaseH
9 #define LLVMCodeGenBaseH
11 #include "ModelGeneratorContext.h"
13 #include "LLVMException.h"
15 #include <Poco/Logger.h>
18 #pragma warning(disable: 4146)
19 #pragma warning(disable: 4141)
20 #pragma warning(disable: 4267)
21 #pragma warning(disable: 4624)
24 #include "llvm/IR/Mangler.h"
27 #pragma warning(default: 4146)
28 #pragma warning(default: 4141)
29 #pragma warning(default: 4267)
30 #pragma warning(default: 4624)
42 typedef std::vector<std::string> StringVector;
43 typedef std::pair<std::string, int> StringIntPair;
44 typedef std::vector<StringIntPair> StringIntVector;
52 template <
typename FunctionPtrType>
56 llvm::Function* createFunction()
58 llvm::Function *func = (llvm::Function*)codeGen();
68 typedef FunctionPtrType FunctionPtr;
73 model(mgc.getModel()),
74 dataSymbols(mgc.getModelDataSymbols()),
75 modelSymbols(mgc.getModelSymbols()),
95 llvm::LLVMContext &context;
97 llvm::IRBuilder<> &builder;
98 llvm::Function *
function;
110 virtual llvm::Value *codeGen() = 0;
113 llvm::BasicBlock *codeGenHeader(
const char* functionName,
115 llvm::Type* (&argTypes)[N],
116 const char* (&argNames)[N],
117 llvm::Value* (&args)[N])
121 llvm::FunctionType *funcType = llvm::FunctionType::get(retType, argTypes,
false);
122 function = llvm::Function::Create(funcType,
123 llvm::Function::ExternalLinkage,
124 functionName, module);
127 llvm::BasicBlock *basicBlock = llvm::BasicBlock::Create(context,
"entry",
function);
128 builder.SetInsertPoint(basicBlock);
130 assert(function->arg_size() == N);
133 for (llvm::Function::arg_iterator ai = function->arg_begin();
134 ai != function->arg_end(); ++ai, ++i)
136 llvm::Value *arg = ai;
137 arg->setName(argNames[i]);
150 llvm::Type *argTypes[] = {
151 llvm::PointerType::get(
155 const char *argNames[] = {
"modelData" };
157 llvm::Value *args[] = { 0 };
159 llvm::BasicBlock *basicBlock = codeGenHeader(functionName,
160 llvm::Type::getVoidTy(context),
161 argTypes, argNames, args);
169 rrLogInfo << std::string(
"function: ") + to_string(
function);
173 if (llvm::verifyFunction(*
function))
175 std::string err =
"Corrupt Generated Function, " + to_string(
function);
178 throw LLVMException(err);
The roadrunner logger.
Definition: rrLogger.h:63
a convenience class to pull the vars out of a context, and store them as ivars.
Definition: CodeGenBase.h:54
llvm::BasicBlock * codeGenVoidModelDataHeader(const char *functionName, llvm::Value *&modelData)
the most common type of generated function takes a ModelData*, and returns void.
Definition: CodeGenBase.h:148
const unsigned options
the options bit field that was passed into the top level load method.
Definition: CodeGenBase.h:108
llvm::legacy::FunctionPassManager * functionPassManager
function pass manager.
Definition: CodeGenBase.h:103
llvm::Function * verifyFunction()
Definition: CodeGenBase.h:167
const libsbml::Model * model
could potentially be null, everything else is guaranteed to be valid
Definition: CodeGenBase.h:90
virtual llvm::Module * getModuleNonOwning()
returns a non owning pointer to the llvm::Module instance
Definition: Jit.cpp:72
virtual llvm::IRBuilder * getBuilderNonOwning()
returns a non owning pointer to the llvm::LLVMContext instance
Definition: Jit.cpp:91
stores the names of all the symbols in the sbml model and thier indexes in the ModelData arrays.
Definition: LLVMModelDataSymbols.h:128
Hold all the un-evaluated symbolic inforamtion in the model.
Definition: LLVMModelSymbols.h:26
static llvm::StructType * getStructType(llvm::Module *module)
get the ModelData struct type.
Definition: ModelDataIRBuilder.cpp:731
All LLVM code generating objects basically need at a minimum three things to operate:
Definition: ModelGeneratorContext.h:95