tests: arch-power: Add 64-bit hello binaries
[gem5.git] / src / sim / mathexpr.hh
index 8f16cc8510bdded3538d8c0e5691e9d2fd0ebbd4..3dfe2b829eeb3f149e26cbadfd6157ec03bb2afa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 ARM Limited
+ * Copyright (c) 2016, 2020 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: David Guillen Fandos
  */
 
 #ifndef __SIM_MATHEXPR_HH__
 #define __SIM_MATHEXPR_HH__
 
 #include <algorithm>
+#include <array>
 #include <functional>
 #include <string>
+#include <vector>
 
 class MathExpr {
   public:
@@ -67,6 +67,22 @@ class MathExpr {
      */
     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<std::string> getVariables() const
+    {
+        std::vector<std::string> vars;
+        getVariables(root, vars);
+        return vars;
+    }
+
   private:
     enum Operator {
         bAdd, bSub, bMul, bDiv, bPow, uNeg, sValue, sVariable, nInvalid
@@ -120,8 +136,10 @@ class MathExpr {
 
     /** 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<std::string> &vars) const;
 };
 
 #endif
-
-