gem5 v24.0.0.0
|
#include <mathexpr.hh>
Classes | |
class | Node |
struct | OpSearch |
Public Types | |
typedef std::function< double(std::string)> | EvalCallback |
Public Member Functions | |
MathExpr (std::string expr) | |
std::string | toStr () const |
Prints an ASCII representation of the expression tree. | |
double | eval (EvalCallback fn) const |
Evaluates the expression. | |
std::vector< std::string > | getVariables () const |
Return all variables in the this expression. | |
Private Types | |
enum | Operator { bAdd , bSub , bMul , bDiv , bPow , uNeg , sValue , sVariable , nInvalid } |
typedef double(* | binOp) (double, double) |
Private Member Functions | |
Node * | parse (std::string expr) |
Parse and create nodes from string. | |
std::string | toStr (Node *n, std::string prefix) const |
Print tree as string. | |
double | eval (const Node *n, EvalCallback fn) const |
Eval a node. | |
void | getVariables (const Node *n, std::vector< std::string > &vars) const |
Return all variable reachable from a node to a vector of strings. | |
Private Attributes | |
const int | MAX_PRIO = 4 |
std::array< OpSearch, uNeg+1 > | ops |
Operator list. | |
Node * | root |
Root node. | |
Definition at line 50 of file mathexpr.hh.
|
private |
Definition at line 98 of file mathexpr.hh.
typedef std::function<double(std::string)> gem5::MathExpr::EvalCallback |
Definition at line 56 of file mathexpr.hh.
|
private |
Enumerator | |
---|---|
bAdd | |
bSub | |
bMul | |
bDiv | |
bPow | |
uNeg | |
sValue | |
sVariable | |
nInvalid |
Definition at line 91 of file mathexpr.hh.
gem5::MathExpr::MathExpr | ( | std::string | expr | ) |
Definition at line 50 of file mathexpr.cc.
References gem5::ArmISA::a, gem5::ArmISA::b, bAdd, bDiv, bMul, bPow, bSub, and uNeg.
|
private |
Eval a node.
Definition at line 153 of file mathexpr.cc.
References eval(), gem5::ArmISA::fn, gem5::ArmISA::n, ops, panic, sValue, and sVariable.
|
inline |
Evaluates the expression.
fn | A callback funcion to evaluate variables |
Definition at line 72 of file mathexpr.hh.
References eval(), gem5::ArmISA::fn, and root.
Referenced by eval(), eval(), and gem5::MathExprPowerModel::eval().
|
inline |
Return all variables in the this expression.
This function starts from the root node and traverses all nodes while adding the variables it finds to a vector. Returns the found variables in a vector of strings
Definition at line 83 of file mathexpr.hh.
References getVariables(), and root.
Referenced by getVariables(), and getVariables().
|
private |
Return all variable reachable from a node to a vector of strings.
Definition at line 181 of file mathexpr.cc.
References getVariables(), gem5::ArmISA::n, nInvalid, sValue, and sVariable.
|
private |
Parse and create nodes from string.
This function parses a string expression into an expression tree.
It will look for operators in priority order to recursively build the tree, respecting parenthesization. Constants can be expressed in any format accepted by std::stod, whereas variables are essentially [A-Za-z0-9.$\]+
Definition at line 78 of file mathexpr.cc.
References gem5::ArmISA::c, gem5::ArmISA::i, gem5::MipsISA::l, MAX_PRIO, gem5::ArmISA::n, ops, gem5::MipsISA::p, parse(), gem5::ArmISA::priority, gem5::MipsISA::r, sValue, sVariable, and gem5::ArmISA::v.
Referenced by parse().
|
inline |
|
private |
Print tree as string.
Definition at line 170 of file mathexpr.cc.
References gem5::ArmISA::n, and toStr().
|
private |
Definition at line 97 of file mathexpr.hh.
Referenced by parse().
|
private |
Root node.
Definition at line 136 of file mathexpr.hh.
Referenced by eval(), getVariables(), and toStr().