7 #ifndef RRLLVMSETVALUECODEGENBASE_H_
8 #define RRLLVMSETVALUECODEGENBASE_H_
10 #include "CodeGenBase.h"
11 #include "ModelGeneratorContext.h"
12 #include "SymbolForest.h"
13 #include "ASTNodeFactory.h"
14 #include "ModelDataIRBuilder.h"
15 #include "ModelDataSymbolResolver.h"
16 #include "LLVMException.h"
18 #include <sbml/Model.h>
19 #include <Poco/Logger.h>
25 typedef bool (*SetValueCodeGenBase_FunctionPtr)(LLVMModelData*, int32_t, double);
31 template <
typename Derived,
bool substanceUnits>
39 llvm::Value* codeGen();
41 typedef SetValueCodeGenBase_FunctionPtr FunctionPtr;
44 template <
typename Derived,
bool substanceUnits>
51 template <
typename Derived,
bool substanceUnits>
52 SetValueCodeGenBase<Derived, substanceUnits>::~SetValueCodeGenBase()
56 template <
typename Derived,
bool substanceUnits>
57 llvm::Value* SetValueCodeGenBase<Derived, substanceUnits>::codeGen()
60 llvm::Type* argTypes[] = {
62 llvm::Type::getInt32Ty(this->context),
63 llvm::Type::getDoubleTy(this->context)
66 const char* argNames[] = {
67 "modelData", Derived::IndexArgName,
"value"
70 llvm::Value* args[] = { 0, 0, 0 };
72 llvm::BasicBlock* entry = this->codeGenHeader(Derived::FunctionName, llvm::Type::getInt8Ty(this->context),
73 argTypes, argNames, args);
75 StringIntVector ids =
static_cast<Derived*
>(
this)->getIds();
77 ModelDataLoadSymbolResolver loadResolver(args[0], this->modelGenContext);
79 ModelDataStoreSymbolResolver storeResolver(args[0], this->model, this->modelSymbols,
80 this->dataSymbols, this->builder, loadResolver);
83 llvm::BasicBlock* def = llvm::BasicBlock::Create(this->context,
"default", this->
function);
84 this->builder.SetInsertPoint(def);
87 this->builder.CreateRet(llvm::ConstantInt::get(llvm::Type::getInt8Ty(this->context), 0));
91 this->builder.SetInsertPoint(entry);
93 llvm::SwitchInst* s = this->builder.CreateSwitch(args[1], def,
static_cast<unsigned int>(ids.size()));
95 for (
int i = 0; i < ids.size(); ++i)
97 llvm::BasicBlock* block = llvm::BasicBlock::Create(this->context, ids[i].first +
"_block", this->
function);
98 this->builder.SetInsertPoint(block);
99 loadResolver.flushCache();
103 llvm::Value* value = args[2];
107 const libsbml::SBase* sbase =
const_cast<libsbml::Model*
>(model)->getElementBySId(ids[i].first);
108 if (sbase && sbase->getTypeCode() == libsbml::SBML_SPECIES)
110 const libsbml::Species* species =
static_cast<const libsbml::Species*
>(sbase);
111 if (species->getHasOnlySubstanceUnits())
117 llvm::Value* comp = loadResolver.loadSymbolValue(species->getCompartment());
118 value = this->builder.CreateFMul(value, comp, ids[i].first +
"_amt");
127 llvm::Value* comp = loadResolver.loadSymbolValue(species->getCompartment());
128 value = this->builder.CreateFDiv(value, comp, ids[i].first +
"_value_conc");
134 storeResolver.storeSymbolValue(ids[i].first, value);
137 this->builder.CreateRet(llvm::ConstantInt::get(llvm::Type::getInt8Ty(this->context), 1));
138 s->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(this->context), ids[i].second), block);
141 return this->verifyFunction();
a convenience class to pull the vars out of a context, and store them as ivars.
Definition: CodeGenBase.h:54
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
base class for setting values.
Definition: SetValueCodeGenBase.h:34