Otawa  0.10
Expression.h
Go to the documentation of this file.
1 /*
2  * ilp::Expression class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2011, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef OTAWA_ILP_EXPRESSION_H_
22 #define OTAWA_ILP_EXPRESSION_H_
23 
24 #include <elm/genstruct/SLList.h>
25 
26 namespace otawa { namespace ilp {
27 
28 using namespace elm;
29 
30 class System;
31 class Var;
32 
33 typedef double coef_t;
34 
35 class Term {
36 public:
37  inline Term(coef_t c, Var *v = 0): fst(v), snd(c) { }
38  inline Term(Var *v, coef_t c = 1.): fst(v), snd(c) { }
39  Var *fst;
41 };
42 
43 class Expression {
44 public:
45  inline Expression(void) { }
46  inline Expression(const Expression *expr): terms(expr->terms) { }
47 
48  void add(coef_t coef, ilp::Var *var = 0);
49  inline void sub(coef_t coef, ilp::Var *var = 0) { terms.add(Term(var, -coef)); }
50  inline void add(const Term& t) { add(t.snd, t.fst); }
51  inline void sub(const Term& t) { sub(t.snd, t.fst); }
52  void add(const Expression *expr, coef_t coef = 1);
53  void sub(const Expression *expr, coef_t coef = 1);
54  void mul(coef_t coef);
55  void div(coef_t coef);
56  void add(const Expression& e);
57  void sub(const Expression& e);
58 
59  double eval(System *sys);
60 
61  class Iterator: public genstruct::SLList<Term>::Iterator {
62  public:
63  inline Iterator(const Expression *expr): genstruct::SLList<Term>::Iterator(expr->terms) { }
64  inline Iterator(const Iterator& iter): genstruct::SLList<Term>::Iterator(iter) { }
65  inline Iterator& operator=(const Iterator& iter) { genstruct::SLList<Term>::Iterator::operator=(iter); return *this; }
66  };
67 
68 private:
70 };
71 
72 } } // otawa::ilp
73 
74 #endif /* OTAWA_ILP_EXPRESSION_H_ */
An expression allows to represent a sum of terms and may be used to represent the value of an aliased...
Definition: Expression.h:43
Expression(const Expression *expr)
Build an expression by cloning the given one.
Definition: Expression.h:46
coef_t snd
Definition: Expression.h:40
void sub(const Term &t)
Definition: Expression.h:51
Term(coef_t c, Var *v=0)
Definition: Expression.h:37
double coef_t
Definition: Expression.h:31
Expression(void)
Build an empty expression.
Definition: Expression.h:45
inst mul(int d, int a, int b)
Definition: inst.h:172
void sub(coef_t coef, ilp::Var *var=0)
Subtract a term to the expression.
Definition: Expression.h:49
Iterator & operator=(const Iterator &iter)
Definition: Expression.h:65
Definition: Expression.h:61
Term(Var *v, coef_t c=1.)
Definition: Expression.h:38
void add(const Term &t)
Definition: Expression.h:50
genstruct::SLList< Term > terms
Definition: Expression.h:69
Definition: Expression.h:35
Iterator(const Expression *expr)
Definition: Expression.h:63
inst add(int d, int a, int b)
Definition: inst.h:163
inst sub(int d, int a, int b)
Definition: inst.h:164
Iterator(const Iterator &iter)
Definition: Expression.h:64
Var * fst
Definition: Expression.h:39
A variable is an identifier used for performing ILP computation.
Definition: Var.h:36
An ILP system is a colletion of ILP constraint that may maximize or minimize some object function...
Definition: System.h:42
Encapsulation for ilp::Var pointers for {ilp} expr user-fiendly interface.
Definition: expr.h:29
inst div(int d, int a, int b)
Definition: inst.h:174