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> |
44#include <regex> 45#include <string> 46 47#include "base/misc.hh" 48 49MathExpr::MathExpr(std::string expr) 50 : ops( |
51 std::array<OpSearch, uNeg + 1> {{ |
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); } |
59 }}, |
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 --- |