gem5  v22.0.0.2
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gem5::MathExpr Class Reference

#include <mathexpr.hh>


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. More...
double eval (EvalCallback fn) const
 Evaluates the expression. More...
std::vector< std::string > getVariables () const
 Return all variables in the this expression. More...

Private Types

enum  Operator {
  bAdd, bSub, bMul, bDiv,
  bPow, uNeg, sValue, sVariable,
typedef double(* binOp) (double, double)

Private Member Functions

Nodeparse (std::string expr)
 Parse and create nodes from string. More...
std::string toStr (Node *n, std::string prefix) const
 Print tree as string. More...
double eval (const Node *n, EvalCallback fn) const
 Eval a node. More...
void getVariables (const Node *n, std::vector< std::string > &vars) const
 Return all variable reachable from a node to a vector of strings. More...

Private Attributes

const int MAX_PRIO = 4
std::array< OpSearch, uNeg+1 > ops
 Operator list. More...
 Root node. More...

Detailed Description

Definition at line 50 of file mathexpr.hh.

Member Typedef Documentation

◆ binOp

typedef double(* gem5::MathExpr::binOp) (double, double)

Definition at line 98 of file mathexpr.hh.

◆ EvalCallback

typedef std::function<double(std::string)> gem5::MathExpr::EvalCallback

Definition at line 56 of file mathexpr.hh.

Member Enumeration Documentation

◆ Operator


Definition at line 91 of file mathexpr.hh.

Constructor & Destructor Documentation

◆ MathExpr()

gem5::MathExpr::MathExpr ( std::string  expr)

Definition at line 50 of file

References gem5::ArmISA::a, gem5::ArmISA::b, bAdd, bDiv, bMul, bPow, bSub, and uNeg.

Member Function Documentation

◆ eval() [1/2]

double gem5::MathExpr::eval ( const Node n,
EvalCallback  fn 
) const

Eval a node.

Definition at line 153 of file

References eval(), gem5::ArmISA::fn, gem5::ArmISA::n, ops, panic, sValue, and sVariable.

◆ eval() [2/2]

double gem5::MathExpr::eval ( EvalCallback  fn) const

Evaluates the expression.

fnA callback funcion to evaluate variables
The value for this expression

Definition at line 72 of file mathexpr.hh.

References eval(), gem5::ArmISA::fn, and root.

Referenced by gem5::MathExprPowerModel::eval(), and eval().

◆ getVariables() [1/2]

std::vector<std::string> gem5::MathExpr::getVariables ( ) const

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

A Vector with the names of all variables

Definition at line 83 of file mathexpr.hh.

References root.

Referenced by getVariables().

◆ getVariables() [2/2]

void gem5::MathExpr::getVariables ( const Node n,
std::vector< std::string > &  vars 
) const

Return all variable reachable from a node to a vector of strings.

Definition at line 181 of file

References getVariables(), gem5::ArmISA::n, nInvalid, sValue, and sVariable.

◆ parse()

MathExpr::Node * gem5::MathExpr::parse ( std::string  expr)

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

References gem5::VegaISA::c, gem5::ArmISA::i, gem5::VegaISA::l, MAX_PRIO, gem5::ArmISA::n, ops, gem5::VegaISA::p, gem5::VegaISA::r, sValue, sVariable, and gem5::VegaISA::v.

◆ toStr() [1/2]

std::string gem5::MathExpr::toStr ( ) const

Prints an ASCII representation of the expression tree.

A string containing the ASCII representation of the expression

Definition at line 63 of file mathexpr.hh.

References root, and toStr().

Referenced by toStr().

◆ toStr() [2/2]

std::string gem5::MathExpr::toStr ( Node n,
std::string  prefix 
) const

Print tree as string.

Definition at line 170 of file

References gem5::ArmISA::n, and toStr().

Member Data Documentation


const int gem5::MathExpr::MAX_PRIO = 4

Definition at line 97 of file mathexpr.hh.

Referenced by parse().

◆ ops

std::array<OpSearch, uNeg + 1> gem5::MathExpr::ops

Operator list.

Definition at line 109 of file mathexpr.hh.

Referenced by eval(), and parse().

◆ root

Node* gem5::MathExpr::root

Root node.

Definition at line 136 of file mathexpr.hh.

Referenced by eval(), getVariables(), and toStr().

The documentation for this class was generated from the following files:

Generated on Thu Jul 28 2022 13:33:06 for gem5 by doxygen 1.8.17