25 #include "ExprConfig.h"
48 std::cerr <<
"SeExpr2 Debug Mode Enabled " << __VERSION__ <<
" built " << __DATE__ <<
" " << __TIME__
51 #ifdef SEEXPR_ENABLE_LLVM
52 if (
char* env = getenv(
"SE_EXPR_EVAL")) {
53 if (
Expression::debugging) std::cerr <<
"Overriding SeExpr Evaluation Default to be " << env << std::endl;
78 sprintf(buf,
"%*s", depth * 2,
" ");
79 std::cout << buf <<
"'" << examinee->
toString() <<
"' " <<
typeid(*examinee).name()
86 : _wantVec(true), _expression(
""), _evaluationStrategy(evaluationStrategy), _context(&
Context::global()),
87 _desiredReturnType(
ExprType().FP(3).Varying()), _parseTree(0), _isValid(0), _parsed(0), _prepped(0),
96 : _wantVec(true), _expression(e), _evaluationStrategy(evaluationStrategy), _context(&context),
97 _desiredReturnType(type), _parseTree(0), _isValid(0), _parsed(0), _prepped(0), _interpreter(0),
110 std::cerr <<
"return slot " <<
_returnSlot << std::endl;
192 int tempStartPos, tempEndPos;
201 #ifdef SEEXPR_PERFORMANCE
226 std::cerr <<
"Eval strategy is interpreter" << std::endl;
234 if (dimWanted > dimHave) {
246 std::cerr <<
"Eval strategy is llvm" << std::endl;
263 std::vector<int> lines;
267 if (*p ==
'\n') lines.push_back(p - start);
270 lines.push_back(p - start);
272 std::stringstream sstream;
273 for (
unsigned int i = 0; i <
_errors.size(); i++) {
274 int* bound = std::lower_bound(&*lines.begin(), &*lines.end(),
_errors[i].startPos);
275 int line = bound - &*lines.begin() + 1;
276 int lineStart = line == 1 ? 0 : lines[line-1];
277 int col =
_errors[i].startPos - lineStart;
278 sstream <<
" Line " << line <<
" Col " << col <<
_errors[i].error << std::endl;
284 std::cerr <<
"ending with isValid " <<
_isValid << std::endl;
285 std::cerr <<
"parse error \n" <<
parseError()<<std::endl;
309 static double noCrash[16]={};
321 double* destBase =
reinterpret_cast<double**
>(varBlock->
data())[outputVarBlockOffset];
322 for (
size_t i = rangeStart; i < rangeEnd; i++) {
324 const double*
f =
evalFP(varBlock);
325 for (
int k = 0; k < dim; k++) {
326 destBase[dim * i + k] = f[k];
int allocFP(int n)
! Allocate a floating point set of data of dimension n
void prepIfNeeded() const
bool usesVar(const std::string &name) const
A thread local evaluation context. Just allocate and fill in with data.
EvaluationStrategy
Types of evaluation strategies that are available.
const ExprType & type() const
The type of the node.
void setContext(const Context &context)
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
std::vector< std::string > _threadUnsafeFunctionCalls
void addError(const std::string &error, const int startPos, const int endPos) const
void walk(T_NODE *examinee)
Preorder walk.
std::vector< char * > s
constant and evaluated pointer data
char ** data()
Raw data of the data block pointer (used by compiler)
bool isFP() const
Direct is predicate checks.
void setDesiredReturnType(const ExprType &type)
bool usesFunc(const std::string &name) const
void print(int pc=-1) const
Debug by printing program.
std::string toString() const
Stringify the type into a printable string.
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd) const
Evaluate multiple blocks.
void debugPrintLLVM() const
bool ExprParse(SeExpr2::ExprNode *&parseTree, std::string &error, int &errorStart, int &errorEnd, std::vector< std::pair< int, int > > &_comments, const SeExpr2::Expression *expr, const char *str, bool wantVec=true)
const std::string & parseError() const
EvaluationStrategy _evaluationStrategy
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
with numParticles numAttributes A variable block contains variable names and types but doesn t care what the values are< pre > void f(const std::string &s, MyParticleData *p, int outputDim=3)
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
std::set< std::string > _funcs
const Context & context() const
ExprType _desiredReturnType
static bool debugging
Whether to debug expressions.
A class that lets you register for the variables used by one or more expressions. ...
void eval(VarBlock *varBlock, bool debug=false)
Evaluate program.
void debugPrintParseTree() const
int addOperand(int param)
! Adds an operand. Note this should be done after doing the addOp!
const ExprNode * parent() const
Access parent node - root node has no parent.
bool isLifetimeConstant() const
validity check: type is not an error
int addOp(OpF op)
! adds an operator to the program (pointing to the data at the current location)
const VarBlockCreator * _varBlockCreator
void reset()
Reset to factory state (one empty environment that is current)
std::vector< Error > _errors
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
std::vector< double > d
Double data (constants and evaluated)
void debugPrintInterpreter() const
void endOp(bool execute=true)
bool prepLLVM(ExprNode *parseTree, ExprType desiredReturnType)
If a scalar is used in a vector context
const double * evalFP(VarBlock *varBlock=nullptr) const
const char * evalStr(VarBlock *varBlock)
const char * evalStr(VarBlock *varBlock=nullptr) const
std::set< std::string > _vars
void setVarBlockCreator(const VarBlockCreator *varBlockCreator)
int indirectIndex
indirect index to add to pointer based data
void setExpr(const std::string &e)
ExprVarEnvBuilder _envBuilder
std::vector< std::pair< int, int > > _comments
static Expression::EvaluationStrategy chooseDefaultEvaluationStrategy()
void parseIfNeeded() const
bool isVec() const
True if node has a vector result.
const ExprType & returnType() const
Interpreter * _interpreter
std::string toString() const
Access to original string representation of current expression.
virtual bool examine(const SeExpr2::ExprNode *examinee)
const double * evalFP(VarBlock *varBlock)
static void init()
call to define built-in funcs and load standard plugins
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
LLVMEvaluator * _llvmEvaluator
Expression(EvaluationStrategy be=Expression::defaultEvaluationStrategy)
ExprType & Error()
Mutate this into an error type.