mathexpr.cc (11527:9007a9729815) mathexpr.cc (11532:05ac17048f55)
1/*
2 * Copyright (c) 2016 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 26 unchanged lines hidden (view full) ---

35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: David Guillen Fandos
38 */
39
40#include "sim/mathexpr.hh"
41
42#include <algorithm>
1/*
2 * Copyright (c) 2016 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 26 unchanged lines hidden (view full) ---

35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: David Guillen Fandos
38 */
39
40#include "sim/mathexpr.hh"
41
42#include <algorithm>
43#include <cmath>
43#include <regex>
44#include <string>
45
46#include "base/misc.hh"
47
48MathExpr::MathExpr(std::string expr)
49 : ops(
44#include <regex>
45#include <string>
46
47#include "base/misc.hh"
48
49MathExpr::MathExpr(std::string expr)
50 : ops(
50 std::array<OpSearch, uNeg + 1> {
51 std::array<OpSearch, uNeg + 1> {{
51 OpSearch {true, bAdd, 0, '+', [](double a, double b) { return a + b; }},
52 OpSearch {true, bSub, 0, '-', [](double a, double b) { return a - b; }},
53 OpSearch {true, bMul, 1, '*', [](double a, double b) { return a * b; }},
54 OpSearch {true, bDiv, 1, '/', [](double a, double b) { return a / b; }},
55 OpSearch {false,uNeg, 2, '-', [](double a, double b) { return -b; }},
56 OpSearch {true, bPow, 3, '^', [](double a, double b) {
57 return std::pow(a,b); }
52 OpSearch {true, bAdd, 0, '+', [](double a, double b) { return a + b; }},
53 OpSearch {true, bSub, 0, '-', [](double a, double b) { return a - b; }},
54 OpSearch {true, bMul, 1, '*', [](double a, double b) { return a * b; }},
55 OpSearch {true, bDiv, 1, '/', [](double a, double b) { return a / b; }},
56 OpSearch {false,uNeg, 2, '-', [](double a, double b) { return -b; }},
57 OpSearch {true, bPow, 3, '^', [](double a, double b) {
58 return std::pow(a,b); }
58 },
59 }},
59 })
60{
61 // Cleanup
62 expr.erase(remove_if(expr.begin(), expr.end(), isspace), expr.end());
63
64 root = MathExpr::parse(expr);
65 panic_if(!root, "Invalid expression\n");
66}

--- 111 unchanged lines hidden ---
60 })
61{
62 // Cleanup
63 expr.erase(remove_if(expr.begin(), expr.end(), isspace), expr.end());
64
65 root = MathExpr::parse(expr);
66 panic_if(!root, "Invalid expression\n");
67}

--- 111 unchanged lines hidden ---