forked from AndySomogyi/sbmlsolver
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1180 from sys-bio/issue-piecewise-fix
Add rootfinding breaks for when piecewise conditions change.
- Loading branch information
Showing
31 changed files
with
925 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* GetPiecewiseTriggerCodeGen.cpp | ||
* | ||
* Created on: Aug 10, 2013 | ||
* Author: andy | ||
*/ | ||
#pragma hdrstop | ||
#include "GetPiecewiseTriggerCodeGen.h" | ||
#include "LLVMException.h" | ||
#include "ModelDataSymbolResolver.h" | ||
#include "rrLogger.h" | ||
|
||
#include <Poco/Logger.h> | ||
#include <llvm/GetPiecewiseTriggerCodeGen.h> | ||
#include <vector> | ||
|
||
using namespace llvm; | ||
|
||
using namespace libsbml; | ||
|
||
namespace rrllvm | ||
{ | ||
const char* GetPiecewiseTriggerCodeGen::FunctionName = "getPiecewiseTrigger"; | ||
const char* GetPiecewiseTriggerCodeGen::IndexArgName = "triggerIndx"; | ||
|
||
GetPiecewiseTriggerCodeGen::GetPiecewiseTriggerCodeGen(const ModelGeneratorContext& mgc) | ||
: CodeGenBase<GetPiecewiseTriggerCodeGen_FunctionPtr>(mgc) | ||
, piecewiseTriggers(mgc.getPiecewiseTriggers()) | ||
{ | ||
}; | ||
|
||
llvm::Value* GetPiecewiseTriggerCodeGen::codeGen() | ||
{ | ||
// make the set init value function | ||
llvm::Type* argTypes[] = { | ||
llvm::PointerType::get(ModelDataIRBuilder::getStructType(this->module), 0), | ||
llvm::Type::getInt32Ty(this->context) | ||
}; | ||
|
||
const char* argNames[] = { | ||
"modelData", IndexArgName | ||
}; | ||
|
||
llvm::Value* args[] = { 0, 0 }; | ||
|
||
llvm::Type* retType = getRetType(); | ||
|
||
llvm::BasicBlock* entry = this->codeGenHeader(FunctionName, retType, | ||
argTypes, argNames, args); | ||
|
||
ModelDataLoadSymbolResolver resolver(args[0], this->modelGenContext); | ||
|
||
ASTNodeCodeGen astCodeGen(this->builder, resolver, this->modelGenContext, args[0]); | ||
|
||
// default, return NaN | ||
llvm::BasicBlock* def = llvm::BasicBlock::Create(this->context, "default", this->function); | ||
this->builder.SetInsertPoint(def); | ||
|
||
llvm::Value* defRet = createRet(0); | ||
this->builder.CreateRet(defRet); | ||
|
||
// write the switch at the func entry point, the switch is also the | ||
// entry block terminator | ||
this->builder.SetInsertPoint(entry); | ||
|
||
llvm::SwitchInst* s = this->builder.CreateSwitch(args[1], def, piecewiseTriggers->size()); | ||
|
||
for (uint i = 0; i < piecewiseTriggers->size(); ++i) | ||
{ | ||
char block_name[64]; | ||
std::sprintf(block_name, "piecewiseTrigger_%i_block", i); | ||
llvm::BasicBlock* block = llvm::BasicBlock::Create(this->context, block_name, this->function); | ||
this->builder.SetInsertPoint(block); | ||
resolver.flushCache(); | ||
|
||
llvm::Value* value = astCodeGen.codeGenBoolean((*piecewiseTriggers)[i]); | ||
|
||
// convert type to return type | ||
value = createRet(value); | ||
|
||
this->builder.CreateRet(value); | ||
s->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(this->context), i), block); | ||
} | ||
|
||
return this->verifyFunction(); | ||
} | ||
|
||
llvm::Type* GetPiecewiseTriggerCodeGen::getRetType() | ||
{ | ||
return llvm::Type::getInt8Ty(context); | ||
}; | ||
|
||
llvm::Value* GetPiecewiseTriggerCodeGen::createRet(llvm::Value* value) | ||
{ | ||
if (!value) | ||
{ | ||
return llvm::ConstantInt::get(getRetType(), 0xff, false); | ||
} | ||
else | ||
{ | ||
return builder.CreateIntCast(value, getRetType(), false); | ||
} | ||
} | ||
|
||
|
||
} /* namespace rr */ | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* GetPiecewiseTriggerCodeGen.h | ||
* | ||
* Created on: Aug 10, 2013 | ||
* Author: andy | ||
*/ | ||
|
||
#ifndef RRLLVMGetPiecewiseTriggerCodeGen_H_ | ||
#define RRLLVMGetPiecewiseTriggerCodeGen_H_ | ||
|
||
#include "CodeGenBase.h" | ||
#include "ModelGeneratorContext.h" | ||
#include "SymbolForest.h" | ||
#include "ASTNodeCodeGen.h" | ||
#include "ASTNodeFactory.h" | ||
#include "ModelDataIRBuilder.h" | ||
#include "ModelDataSymbolResolver.h" | ||
#include "LLVMException.h" | ||
#include "rrLogger.h" | ||
#include <sbml/Model.h> | ||
#include <Poco/Logger.h> | ||
#include <vector> | ||
#include <cstdio> | ||
|
||
namespace rrllvm | ||
{ | ||
//Based on GetEventTriggerCodeGen (-LS) | ||
|
||
typedef unsigned char (*GetPiecewiseTriggerCodeGen_FunctionPtr)(LLVMModelData*, size_t); | ||
|
||
class GetPiecewiseTriggerCodeGen : | ||
public CodeGenBase<GetPiecewiseTriggerCodeGen_FunctionPtr> | ||
{ | ||
public: | ||
GetPiecewiseTriggerCodeGen(const ModelGeneratorContext& mgc); | ||
virtual ~GetPiecewiseTriggerCodeGen() {}; | ||
|
||
llvm::Value* codeGen(); | ||
|
||
typedef GetPiecewiseTriggerCodeGen_FunctionPtr FunctionPtr; | ||
|
||
static const char* FunctionName; | ||
static const char* IndexArgName; | ||
|
||
llvm::Type* getRetType(); | ||
|
||
llvm::Value* createRet(llvm::Value*); | ||
|
||
private: | ||
const std::vector<libsbml::ASTNode*>* piecewiseTriggers; | ||
}; | ||
|
||
|
||
} /* namespace rr */ | ||
|
||
|
||
|
||
|
||
#endif /* RRLLVMGETVALUECODEGENBASE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.