[gem5-dev] Change in gem5/gem5[develop]: sim: Add function that returns all variables in a MathExpr

2020-04-29 Thread Nikos Nikoleris (Gerrit) via gem5-dev
Nikos Nikoleris has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27889 )


Change subject: sim: Add function that returns all variables in a MathExpr
..

sim: Add function that returns all variables in a MathExpr

This changes adds support for retrieving all variables in a math
expression. The added function can be called in all valid expressions
and will return the variables in a vector of strings.

Change-Id: I086ba04aa1f798400c97a0b6bf982018a2457c64
Signed-off-by: Nikos Nikoleris 
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27889
Reviewed-by: Bobby R. Bruce 
Maintainer: Jason Lowe-Power 
Tested-by: kokoro 
---
M src/sim/mathexpr.cc
M src/sim/mathexpr.hh
2 files changed, 37 insertions(+), 4 deletions(-)

Approvals:
  Bobby R. Bruce: Looks good to me, approved
  Jason Lowe-Power: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/mathexpr.cc b/src/sim/mathexpr.cc
index f80c535..0cbcd90 100644
--- a/src/sim/mathexpr.cc
+++ b/src/sim/mathexpr.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 ARM Limited
+ * Copyright (c) 2016, 2020 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -174,3 +174,17 @@
 return ret;
 }

+void
+MathExpr::getVariables(const Node *n,
+   std::vector ) const
+{
+if (!n || n->op == sValue || n->op == nInvalid) {
+return;
+} else if (n->op == sVariable) {
+variables.push_back(n->variable);
+} else {
+getVariables(n->l, variables);
+getVariables(n->r, variables);
+}
+}
+
diff --git a/src/sim/mathexpr.hh b/src/sim/mathexpr.hh
index b8db739..3dfe2b8 100644
--- a/src/sim/mathexpr.hh
+++ b/src/sim/mathexpr.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 ARM Limited
+ * Copyright (c) 2016, 2020 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 

 class MathExpr {
   public:
@@ -66,6 +67,22 @@
  */
 double eval(EvalCallback fn) const { return eval(root, fn); }

+/**
+ * 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
+ *
+ * @return A Vector with the names of all variables
+*/
+std::vector getVariables() const
+{
+std::vector vars;
+getVariables(root, vars);
+return vars;
+}
+
   private:
 enum Operator {
 bAdd, bSub, bMul, bDiv, bPow, uNeg, sValue, sVariable, nInvalid
@@ -119,8 +136,10 @@

 /** Eval a node */
 double eval(const Node *n, EvalCallback fn) const;
+
+/** Return all variable reachable from a node to a vector of
+ * strings */
+void getVariables(const Node *n, std::vector ) const;
 };

 #endif
-
-

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27889
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I086ba04aa1f798400c97a0b6bf982018a2457c64
Gerrit-Change-Number: 27889
Gerrit-PatchSet: 2
Gerrit-Owner: Nikos Nikoleris 
Gerrit-Reviewer: Bobby R. Bruce 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-Reviewer: Nikos Nikoleris 
Gerrit-Reviewer: kokoro 
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s


[gem5-dev] Change in gem5/gem5[develop]: sim: Add function that returns all variables in a MathExpr

2020-04-20 Thread Nikos Nikoleris (Gerrit)
Nikos Nikoleris has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27889 )



Change subject: sim: Add function that returns all variables in a MathExpr
..

sim: Add function that returns all variables in a MathExpr

This changes adds support for retrieving all variables in a math
expression. The added function can be called in all valid expressions
and will return the variables in a vector of strings.

Change-Id: I086ba04aa1f798400c97a0b6bf982018a2457c64
Signed-off-by: Nikos Nikoleris 
---
M src/sim/mathexpr.cc
M src/sim/mathexpr.hh
2 files changed, 37 insertions(+), 4 deletions(-)



diff --git a/src/sim/mathexpr.cc b/src/sim/mathexpr.cc
index f80c535..0cbcd90 100644
--- a/src/sim/mathexpr.cc
+++ b/src/sim/mathexpr.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 ARM Limited
+ * Copyright (c) 2016, 2020 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -174,3 +174,17 @@
 return ret;
 }

+void
+MathExpr::getVariables(const Node *n,
+   std::vector ) const
+{
+if (!n || n->op == sValue || n->op == nInvalid) {
+return;
+} else if (n->op == sVariable) {
+variables.push_back(n->variable);
+} else {
+getVariables(n->l, variables);
+getVariables(n->r, variables);
+}
+}
+
diff --git a/src/sim/mathexpr.hh b/src/sim/mathexpr.hh
index b8db739..3dfe2b8 100644
--- a/src/sim/mathexpr.hh
+++ b/src/sim/mathexpr.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 ARM Limited
+ * Copyright (c) 2016, 2020 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 

 class MathExpr {
   public:
@@ -66,6 +67,22 @@
  */
 double eval(EvalCallback fn) const { return eval(root, fn); }

+/**
+ * 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
+ *
+ * @return A Vector with the names of all variables
+*/
+std::vector getVariables() const
+{
+std::vector vars;
+getVariables(root, vars);
+return vars;
+}
+
   private:
 enum Operator {
 bAdd, bSub, bMul, bDiv, bPow, uNeg, sValue, sVariable, nInvalid
@@ -119,8 +136,10 @@

 /** Eval a node */
 double eval(const Node *n, EvalCallback fn) const;
+
+/** Return all variable reachable from a node to a vector of
+ * strings */
+void getVariables(const Node *n, std::vector ) const;
 };

 #endif
-
-

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27889
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I086ba04aa1f798400c97a0b6bf982018a2457c64
Gerrit-Change-Number: 27889
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris 
Gerrit-MessageType: newchange
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev