-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.h
186 lines (151 loc) · 4.99 KB
/
utility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef UTILITY_H
#define UTILITY_H
#include <iostream>
#include <map>
#define SRC_INFO_TEMP __FILE__, __func__, __LINE__
#define SRC_INFO (std::make_tuple(__FILE__, __func__, __LINE__))
typedef std::map<std::string, unsigned int> portMapping;
typedef std::tuple<std::string, portMapping> blockPortMapping;
typedef std::tuple<std::string, std::string, int> srcInfo;
class STLdriver;
class TimeInterval
{
public:
TimeInterval(std::string li, std::string l, std::string r, std::string ri) :
start(l),
end(r)
{
if ( (li != "[" && li != "(") || (ri != "]" && ri != ")") )
throw "Wrong interval delimiter";
startClosed = (li == "[");
endClosed = (ri == "]");
}
TimeInterval() {}
std::string start;
std::string end;
bool startClosed;
bool endClosed;
};
std::ostream& operator<<(std::ostream& os, const TimeInterval &obj);
enum ComparisonOperator { GEQ, LEQ, GREATER, SMALLER, EQUAL, NEQUAL };
enum LogicalOperator { AND, OR, NOT, COMPARISON, ISSTEP };
enum MathOperator { SUM, SUB, MUL, DIV, ABS, DIFF, CONST, PORT };
enum TemporalOperator { ALWAYS, EVENTUALLY };
struct MathOperation {
MathOperator op;
MathOperation *a;
MathOperation *b;
std::string value;
};
struct ComparisonOperation {
ComparisonOperator op;
MathOperation *a;
MathOperation *b;
};
struct LogicalOperation {
LogicalOperator op;
LogicalOperation *a;
LogicalOperation *b;
ComparisonOperation *value;
// For boolean functions
MathOperation *arg1;
MathOperation *arg2;
};
class TreeNode {
std::string _name;
protected:
TreeNode *left;
TreeNode *right;
public:
TreeNode(const std::string &name = "");
~TreeNode();
void setName(const std::string &name);
std::string getName() const;
virtual blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false) = 0;
};
class STLFormula : public TreeNode {
};
class BoolExpr : public STLFormula {
};
class STLFormulaNOT : public STLFormula {
public:
STLFormulaNOT(STLFormula *f);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class STLFormulaAND : public STLFormula {
public:
STLFormulaAND(STLFormula *f1, STLFormula *f2);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class STLAlways : public STLFormula {
TimeInterval _t;
bool _tSet;
public:
STLAlways(const TimeInterval &t, STLFormula *f);
STLAlways(STLFormula *f);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class STLEventually : public STLFormula {
TimeInterval _t;
bool _tSet;
public:
STLEventually(const TimeInterval &t, STLFormula *f);
STLEventually(STLFormula *f);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class STLFormulaUNTIL : public STLFormula {
TimeInterval _t;
bool _tSet;
public:
STLFormulaUNTIL(const TimeInterval &t, STLFormula *f1, STLFormula *f2);
STLFormulaUNTIL(STLFormula *f1, STLFormula *f2);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class Expression : public TreeNode {
std::string _value;
protected:
MathOperator _op;
public:
Expression() {}
Expression(MathOperator op, Expression *e1, Expression *e2);
Expression(MathOperator op, std::string value);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class ExpressionFunction : public Expression {
public:
ExpressionFunction(MathOperator op, Expression *e);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
/********* Boolean Expressions *********/
class BooleanExpression : public STLFormula {
};
class BooleanOperation : public BooleanExpression {
LogicalOperator _op;
public:
BooleanOperation(LogicalOperator op, BooleanExpression *b1, BooleanExpression *b2);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class ComparisonExpression : public BooleanExpression {
ComparisonOperator _op;
public:
ComparisonExpression(ComparisonOperator op, Expression *e1, Expression *e2);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class BooleanFunction : public BooleanExpression {};
class isStepFunction : public BooleanFunction {
public:
isStepFunction(Expression *e1, Expression *e2);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
class BooleanValue : public BooleanExpression {
bool _v;
public:
BooleanValue(bool v);
blockPortMapping generate(STLdriver *d, const std::string &parent, int vpos, bool rel_time = false);
};
void updateRequiredPorts(STLdriver *d,
const std::string &name,
portMapping &bpm,
const blockPortMapping &A,
unsigned int &portId);
#endif // UTILITY_H