/
sequential.h
353 lines (284 loc) · 10.9 KB
/
sequential.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#ifndef IVL_sequential_H
#define IVL_sequential_H
/*
* Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com)
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "LineInfo.h"
# include "parse_types.h"
# include <set>
class ScopeBase;
class Entity;
class Expression;
class SequentialStmt;
struct SeqStmtVisitor {
virtual ~SeqStmtVisitor() {};
virtual void operator() (SequentialStmt*s) = 0;
};
class SequentialStmt : public LineInfo {
public:
SequentialStmt();
virtual ~SequentialStmt() =0;
public:
virtual int elaborate(Entity*ent, ScopeBase*scope);
virtual int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
virtual void dump(std::ostream&out, int indent) const;
virtual void write_to_stream(std::ostream&fd);
// Recursively visits a tree of sequential statements.
virtual void visit(SeqStmtVisitor& func) { func(this); }
};
/*
* The LoopStatement is an abstract base class for the various loop
* statements.
*/
class LoopStatement : public SequentialStmt {
public:
LoopStatement(perm_string block_name, std::list<SequentialStmt*>*);
virtual ~LoopStatement();
inline perm_string loop_name() const { return name_; }
void dump(std::ostream&out, int indent) const;
void visit(SeqStmtVisitor& func);
protected:
int elaborate_substatements(Entity*ent, ScopeBase*scope);
int emit_substatements(std::ostream&out, Entity*ent, ScopeBase*scope);
void write_to_stream_substatements(std::ostream&fd);
private:
perm_string name_;
std::list<SequentialStmt*> stmts_;
};
class IfSequential : public SequentialStmt {
public:
class Elsif : public LineInfo {
public:
Elsif(Expression*cond, std::list<SequentialStmt*>*tr);
~Elsif();
int elaborate(Entity*entity, ScopeBase*scope);
int condition_emit(std::ostream&out, Entity*entity, ScopeBase*scope);
int statement_emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void condition_write_to_stream(std::ostream&fd);
void statement_write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
void visit(SeqStmtVisitor& func);
private:
Expression*cond_;
std::list<SequentialStmt*>if_;
private: // not implemented
Elsif(const Elsif&);
Elsif& operator =(const Elsif&);
};
public:
IfSequential(Expression*cond, std::list<SequentialStmt*>*tr,
std::list<IfSequential::Elsif*>*elsif,
std::list<SequentialStmt*>*fa);
~IfSequential();
public:
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
void visit(SeqStmtVisitor& func);
const Expression*peek_condition() const { return cond_; }
size_t false_size() const { return else_.size(); }
// These method extract (and remove) the sub-statements from
// the true or false clause.
void extract_true(std::list<SequentialStmt*>&that);
void extract_false(std::list<SequentialStmt*>&that);
private:
Expression*cond_;
std::list<SequentialStmt*> if_;
std::list<IfSequential::Elsif*> elsif_;
std::list<SequentialStmt*> else_;
};
class ReturnStmt : public SequentialStmt {
public:
explicit ReturnStmt(Expression*val);
~ReturnStmt();
public:
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
const Expression*peek_expr() const { return val_; };
void cast_to(const VType*type);
private:
Expression*val_;
};
class SignalSeqAssignment : public SequentialStmt {
public:
SignalSeqAssignment(Expression*sig, std::list<Expression*>*wav);
~SignalSeqAssignment();
public:
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
private:
Expression*lval_;
std::list<Expression*> waveform_;
};
class CaseSeqStmt : public SequentialStmt {
public:
class CaseStmtAlternative : public LineInfo {
public:
CaseStmtAlternative(std::list<Expression*>*exp, std::list<SequentialStmt*>*stmts);
~CaseStmtAlternative();
void dump(std::ostream& out, int indent) const;
int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype);
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void visit(SeqStmtVisitor& func);
private:
std::list<Expression*>*exp_;
std::list<SequentialStmt*> stmts_;
private: // not implemented
CaseStmtAlternative(const CaseStmtAlternative&);
CaseStmtAlternative& operator =(const CaseStmtAlternative&);
};
public:
CaseSeqStmt(Expression*cond, std::list<CaseStmtAlternative*>*sp);
~CaseSeqStmt();
public:
void dump(std::ostream&out, int indent) const;
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void visit(SeqStmtVisitor& func);
private:
Expression* cond_;
std::list<CaseStmtAlternative*> alt_;
};
class ProcedureCall : public SequentialStmt {
public:
explicit ProcedureCall(perm_string name);
ProcedureCall(perm_string name, std::list<named_expr_t*>* param_list);
ProcedureCall(perm_string name, std::list<Expression*>* param_list);
~ProcedureCall();
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void dump(std::ostream&out, int indent) const;
private:
perm_string name_;
std::list<named_expr_t*>* param_list_;
SubprogramHeader*def_;
};
class VariableSeqAssignment : public SequentialStmt {
public:
VariableSeqAssignment(Expression*sig, Expression*rval);
~VariableSeqAssignment();
public:
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
private:
Expression*lval_;
Expression*rval_;
};
class WhileLoopStatement : public LoopStatement {
public:
WhileLoopStatement(perm_string loop_name,
Expression*, std::list<SequentialStmt*>*);
~WhileLoopStatement();
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*ent, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
private:
Expression* cond_;
};
class ForLoopStatement : public LoopStatement {
public:
ForLoopStatement(perm_string loop_name,
perm_string index, ExpRange*, std::list<SequentialStmt*>*);
~ForLoopStatement();
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*ent, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
private:
// Emits for-loop which direction is determined at run-time.
// It is used for 'range & 'reverse_range attributes.
int emit_runtime_(std::ostream&out, Entity*ent, ScopeBase*scope);
perm_string it_;
ExpRange* range_;
};
class BasicLoopStatement : public LoopStatement {
public:
BasicLoopStatement(perm_string lname, std::list<SequentialStmt*>*);
~BasicLoopStatement();
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*ent, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
void dump(std::ostream&out, int indent) const;
};
class ReportStmt : public SequentialStmt {
public:
typedef enum { UNSPECIFIED, NOTE, WARNING, ERROR, FAILURE } severity_t;
ReportStmt(Expression*message, severity_t severity);
virtual ~ReportStmt() {}
void dump(std::ostream&out, int indent) const;
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
inline Expression*message() const { return msg_; }
inline severity_t severity() const { return severity_; }
protected:
void dump_sev_msg(std::ostream&out, int indent) const;
Expression*msg_;
severity_t severity_;
};
class AssertStmt : public ReportStmt {
public:
AssertStmt(Expression*condition, Expression*message,
ReportStmt::severity_t severity = ReportStmt::ERROR);
void dump(std::ostream&out, int indent) const;
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
private:
Expression*cond_;
// Message displayed when there is no report assigned.
static const char*default_msg_;
};
class WaitForStmt : public SequentialStmt {
public:
explicit WaitForStmt(Expression*delay);
void dump(std::ostream&out, int indent) const;
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
private:
Expression*delay_;
};
class WaitStmt : public SequentialStmt {
public:
typedef enum { ON, UNTIL, FINAL } wait_type_t;
WaitStmt(wait_type_t typ, Expression*expression);
void dump(std::ostream&out, int indent) const;
int elaborate(Entity*ent, ScopeBase*scope);
int emit(std::ostream&out, Entity*entity, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
inline wait_type_t type() const { return type_; }
private:
wait_type_t type_;
Expression*expr_;
// Sensitivity list for 'wait until' statement
std::set<ExpName*> sens_list_;
};
#endif /* IVL_sequential_H */