8 #ifndef EVENTCODEGENBASE_H_
9 #define EVENTCODEGENBASE_H_
11 #include "CodeGenBase.h"
12 #include "ModelGeneratorContext.h"
13 #include "SymbolForest.h"
14 #include "ASTNodeCodeGen.h"
15 #include "ASTNodeFactory.h"
16 #include "ModelDataIRBuilder.h"
17 #include "ModelDataSymbolResolver.h"
18 #include "LLVMException.h"
20 #include <sbml/Model.h>
21 #include <Poco/Logger.h>
28 typedef void (*EventCodeGenBase_FunctionPtr)(LLVMModelData*, size_t,
double*);
33 template <
typename Derived>
45 llvm::Value* codeGen();
58 const libsbml::Event* event)
63 typedef EventCodeGenBase_FunctionPtr FunctionPtr;
66 template <
typename Derived>
67 llvm::Value* EventCodeGenBase<Derived>::codeGen()
70 llvm::Type* argTypes[] = {
72 llvm::Type::getInt32Ty(this->context),
73 llvm::Type::getDoublePtrTy(this->context)
76 const char* argNames[] = {
77 "modelData",
"eventIndx",
"data"
80 llvm::Value* args[] = { 0, 0, 0 };
82 llvm::Type* retType = llvm::Type::getVoidTy(context);
84 llvm::BasicBlock* entry = this->codeGenHeader(Derived::FunctionName, retType,
85 argTypes, argNames, args);
87 const libsbml::ListOfEvents* events = this->model->getListOfEvents();
90 llvm::BasicBlock* def = llvm::BasicBlock::Create(this->context,
"default", this->
function);
91 this->builder.SetInsertPoint(def);
93 this->builder.CreateRetVoid();
97 this->builder.SetInsertPoint(entry);
99 llvm::SwitchInst* s = this->builder.CreateSwitch(args[1], def, events->size());
101 for (uint i = 0; i < events->size(); ++i)
104 std::sprintf(block_name,
"event_%i_block", i);
105 llvm::BasicBlock* block = llvm::BasicBlock::Create(this->context, block_name, this->
function);
106 this->builder.SetInsertPoint(block);
108 const libsbml::Event*
event = events->get(i);
110 bool cont =
static_cast<Derived*
>(
this)->eventCodeGen(args[0], args[2], event);
112 this->builder.CreateRetVoid();
113 s->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(this->context), i), block);
118 return this->verifyFunction();
a convenience class to pull the vars out of a context, and store them as ivars.
Definition: CodeGenBase.h:54
Base class for evaluating various types of SBML events.
Definition: EventCodeGenBase.h:36
bool eventCodeGen(llvm::Value *modelData, llvm::Value *data, const libsbml::Event *event)
derived classes must implement this method to generate the event trigger / assignment code.
Definition: EventCodeGenBase.h:57
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