1 /*
2  * Copyright (c) 1998-2019 Stephen Williams (steve@icarus.com)
3  *
4  *    This source code is free software; you can redistribute it
5  *    and/or modify it in source code form under the terms of the GNU
6  *    General Public License as published by the Free Software
7  *    Foundation; either version 2 of the License, or (at your option)
8  *    any later version.
9  *
10  *    This program is distributed in the hope that it will be useful,
11  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *    GNU General Public License for more details.
14  *
15  *    You should have received a copy of the GNU General Public License
16  *    along with this program; if not, write to the Free Software
17  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 # include "config.h"
21 
22 # include  "Statement.h"
23 # include  "PExpr.h"
24 # include  "ivl_assert.h"
25 
~Statement()26 Statement::~Statement()
27 {
28 }
29 
PAssign_(PExpr * lval__,PExpr * ex,bool is_constant)30 PAssign_::PAssign_(PExpr*lval__, PExpr*ex, bool is_constant)
31 : event_(0), count_(0), lval_(lval__), rval_(ex), is_constant_(is_constant)
32 {
33       delay_ = 0;
34 }
35 
PAssign_(PExpr * lval__,PExpr * de,PExpr * ex)36 PAssign_::PAssign_(PExpr*lval__, PExpr*de, PExpr*ex)
37 : event_(0), count_(0), lval_(lval__), rval_(ex), is_constant_(false)
38 {
39       delay_ = de;
40 }
41 
PAssign_(PExpr * lval__,PExpr * cnt,PEventStatement * ev,PExpr * ex)42 PAssign_::PAssign_(PExpr*lval__, PExpr*cnt, PEventStatement*ev, PExpr*ex)
43 : event_(ev), count_(cnt), lval_(lval__), rval_(ex), is_constant_(false)
44 {
45       delay_ = 0;
46 }
47 
~PAssign_()48 PAssign_::~PAssign_()
49 {
50       delete lval_;
51       delete rval_;
52 }
53 
PAssign(PExpr * lval__,PExpr * ex)54 PAssign::PAssign(PExpr*lval__, PExpr*ex)
55 : PAssign_(lval__, ex, false), op_(0)
56 {
57 }
58 
PAssign(PExpr * lval__,char op,PExpr * ex)59 PAssign::PAssign(PExpr*lval__, char op, PExpr*ex)
60 : PAssign_(lval__, ex, false), op_(op)
61 {
62 }
63 
PAssign(PExpr * lval__,PExpr * d,PExpr * ex)64 PAssign::PAssign(PExpr*lval__, PExpr*d, PExpr*ex)
65 : PAssign_(lval__, d, ex), op_(0)
66 {
67 }
68 
PAssign(PExpr * lval__,PExpr * cnt,PEventStatement * d,PExpr * ex)69 PAssign::PAssign(PExpr*lval__, PExpr*cnt, PEventStatement*d, PExpr*ex)
70 : PAssign_(lval__, cnt, d, ex), op_(0)
71 {
72 }
73 
PAssign(PExpr * lval__,PExpr * ex,bool is_constant)74 PAssign::PAssign(PExpr*lval__, PExpr*ex, bool is_constant)
75 : PAssign_(lval__, ex, is_constant), op_(0)
76 {
77 }
78 
~PAssign()79 PAssign::~PAssign()
80 {
81 }
82 
PAssignNB(PExpr * lval__,PExpr * ex)83 PAssignNB::PAssignNB(PExpr*lval__, PExpr*ex)
84 : PAssign_(lval__, ex, false)
85 {
86 }
87 
PAssignNB(PExpr * lval__,PExpr * d,PExpr * ex)88 PAssignNB::PAssignNB(PExpr*lval__, PExpr*d, PExpr*ex)
89 : PAssign_(lval__, d, ex)
90 {
91 }
92 
PAssignNB(PExpr * lval__,PExpr * cnt,PEventStatement * d,PExpr * ex)93 PAssignNB::PAssignNB(PExpr*lval__, PExpr*cnt, PEventStatement*d, PExpr*ex)
94 : PAssign_(lval__, cnt, d, ex)
95 {
96 }
97 
~PAssignNB()98 PAssignNB::~PAssignNB()
99 {
100 }
101 
PBlock(perm_string n,LexicalScope * parent,BL_TYPE t)102 PBlock::PBlock(perm_string n, LexicalScope*parent, BL_TYPE t)
103 : PScope(n, parent), bl_type_(t)
104 {
105 }
106 
PBlock(BL_TYPE t)107 PBlock::PBlock(BL_TYPE t)
108 : PScope(perm_string()), bl_type_(t)
109 {
110 }
111 
~PBlock()112 PBlock::~PBlock()
113 {
114       for (unsigned idx = 0 ;  idx < list_.size() ;  idx += 1)
115 	    delete list_[idx];
116 }
117 
var_init_needs_explicit_lifetime() const118 bool PBlock::var_init_needs_explicit_lifetime() const
119 {
120       return default_lifetime == STATIC;
121 }
122 
extract_chain_constructor()123 PChainConstructor* PBlock::extract_chain_constructor()
124 {
125       if (list_.empty())
126 	    return 0;
127 
128       if (PChainConstructor*res = dynamic_cast<PChainConstructor*> (list_[0])) {
129 	    for (size_t idx = 0 ; idx < list_.size()-1 ; idx += 1)
130 		  list_[idx] = list_[idx+1];
131 	    list_.resize(list_.size()-1);
132 	    return res;
133       }
134 
135       return 0;
136 }
137 
set_join_type(PBlock::BL_TYPE type)138 void PBlock::set_join_type(PBlock::BL_TYPE type)
139 {
140       assert(bl_type_ == BL_PAR);
141       assert(type==BL_PAR || type==BL_JOIN_NONE || type==BL_JOIN_ANY);
142       bl_type_ = type;
143 }
144 
set_statement(const vector<Statement * > & st)145 void PBlock::set_statement(const vector<Statement*>&st)
146 {
147       list_ = st;
148 }
149 
push_statement_front(Statement * that)150 void PBlock::push_statement_front(Statement*that)
151 {
152       ivl_assert(*this, bl_type_==BL_SEQ);
153 
154       list_.resize(list_.size()+1);
155       for (size_t idx = list_.size()-1 ; idx > 0 ; idx -= 1)
156 	    list_[idx] = list_[idx-1];
157 
158       list_[0] = that;
159 }
160 
symbol_type() const161 PNamedItem::SymbolType PBlock::symbol_type() const
162 {
163       return BLOCK;
164 }
165 
PCallTask(const pform_name_t & n,const list<PExpr * > & p)166 PCallTask::PCallTask(const pform_name_t&n, const list<PExpr*>&p)
167 : package_(0), path_(n), parms_(p.size())
168 {
169       list<PExpr*>::const_iterator cur = p.begin();
170       for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
171 	    parms_[idx] = *cur;
172 	    ++cur;
173       }
174       assert(cur == p.end());
175 }
176 
PCallTask(PPackage * pkg,const pform_name_t & n,const list<PExpr * > & p)177 PCallTask::PCallTask(PPackage*pkg, const pform_name_t&n, const list<PExpr*>&p)
178 : package_(pkg), path_(n), parms_(p.size())
179 {
180       list<PExpr*>::const_iterator cur = p.begin();
181       for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
182 	    parms_[idx] = *cur;
183 	    ++cur;
184       }
185       assert(cur == p.end());
186 }
187 
PCallTask(perm_string n,const list<PExpr * > & p)188 PCallTask::PCallTask(perm_string n, const list<PExpr*>&p)
189 : package_(0), parms_(p.size())
190 {
191       list<PExpr*>::const_iterator cur = p.begin();
192       for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
193 	    parms_[idx] = *cur;
194 	    ++cur;
195       }
196       assert(cur == p.end());
197       path_.push_back(name_component_t(n));
198 }
199 
~PCallTask()200 PCallTask::~PCallTask()
201 {
202 }
203 
path() const204 const pform_name_t& PCallTask::path() const
205 {
206       return path_;
207 }
208 
PCase(ivl_case_quality_t q,NetCase::TYPE t,PExpr * ex,svector<PCase::Item * > * l)209 PCase::PCase(ivl_case_quality_t q, NetCase::TYPE t, PExpr*ex, svector<PCase::Item*>*l)
210 : quality_(q), type_(t), expr_(ex), items_(l)
211 {
212 }
213 
~PCase()214 PCase::~PCase()
215 {
216       delete expr_;
217       for (unsigned idx = 0 ;  idx < items_->count() ;  idx += 1)
218 	    if ((*items_)[idx]->stat) delete (*items_)[idx]->stat;
219 
220       delete[]items_;
221 }
222 
PCAssign(PExpr * l,PExpr * r)223 PCAssign::PCAssign(PExpr*l, PExpr*r)
224 : lval_(l), expr_(r)
225 {
226 }
227 
~PCAssign()228 PCAssign::~PCAssign()
229 {
230       delete lval_;
231       delete expr_;
232 }
233 
PChainConstructor(const list<PExpr * > & parms)234 PChainConstructor::PChainConstructor(const list<PExpr*>&parms)
235 : parms_(parms.size())
236 {
237       list<PExpr*>::const_iterator cur = parms.begin();
238       for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
239 	    parms_[idx] = *cur;
240 	    ++cur;
241       }
242       assert(cur == parms.end());
243 }
244 
~PChainConstructor()245 PChainConstructor::~PChainConstructor()
246 {
247 }
248 
PCondit(PExpr * ex,Statement * i,Statement * e)249 PCondit::PCondit(PExpr*ex, Statement*i, Statement*e)
250 : expr_(ex), if_(i), else_(e)
251 {
252 }
253 
~PCondit()254 PCondit::~PCondit()
255 {
256       delete expr_;
257       delete if_;
258       delete else_;
259 }
260 
PDeassign(PExpr * l)261 PDeassign::PDeassign(PExpr*l)
262 : lval_(l)
263 {
264 }
265 
~PDeassign()266 PDeassign::~PDeassign()
267 {
268       delete lval_;
269 }
270 
271 
PDelayStatement(PExpr * d,Statement * st)272 PDelayStatement::PDelayStatement(PExpr*d, Statement*st)
273 : delay_(d), statement_(st)
274 {
275 }
276 
~PDelayStatement()277 PDelayStatement::~PDelayStatement()
278 {
279 }
280 
PDisable(const pform_name_t & sc)281 PDisable::PDisable(const pform_name_t&sc)
282 : scope_(sc)
283 {
284 }
285 
~PDisable()286 PDisable::~PDisable()
287 {
288 }
289 
PDoWhile(PExpr * ex,Statement * st)290 PDoWhile::PDoWhile(PExpr*ex, Statement*st)
291 : cond_(ex), statement_(st)
292 {
293 }
294 
~PDoWhile()295 PDoWhile::~PDoWhile()
296 {
297       delete cond_;
298       delete statement_;
299 }
300 
PEventStatement(const svector<PEEvent * > & ee)301 PEventStatement::PEventStatement(const svector<PEEvent*>&ee)
302 : expr_(ee), statement_(0), always_sens_(false)
303 {
304       assert(expr_.count() > 0);
305 }
306 
307 
PEventStatement(PEEvent * ee)308 PEventStatement::PEventStatement(PEEvent*ee)
309 : expr_(1), statement_(0), always_sens_(false)
310 {
311       expr_[0] = ee;
312 }
313 
PEventStatement(bool always_sens)314 PEventStatement::PEventStatement(bool always_sens)
315 : statement_(0), always_sens_(always_sens)
316 {
317 }
318 
~PEventStatement()319 PEventStatement::~PEventStatement()
320 {
321 	// delete the events and the statement?
322 }
323 
set_statement(Statement * st)324 void PEventStatement::set_statement(Statement*st)
325 {
326       statement_ = st;
327 }
328 
has_aa_term(Design * des,NetScope * scope)329 bool PEventStatement::has_aa_term(Design*des, NetScope*scope)
330 {
331       bool flag = false;
332       for (unsigned idx = 0 ; idx < expr_.count() ; idx += 1) {
333 	    flag = expr_[idx]->has_aa_term(des, scope) || flag;
334       }
335       return flag;
336 }
337 
PForce(PExpr * l,PExpr * r)338 PForce::PForce(PExpr*l, PExpr*r)
339 : lval_(l), expr_(r)
340 {
341 }
342 
~PForce()343 PForce::~PForce()
344 {
345       delete lval_;
346       delete expr_;
347 }
348 
PForeach(perm_string av,const list<perm_string> & ix,Statement * s)349 PForeach::PForeach(perm_string av, const list<perm_string>&ix, Statement*s)
350 : array_var_(av), index_vars_(ix.size()), statement_(s)
351 {
352       size_t idx = 0;
353       for (list<perm_string>::const_iterator cur = ix.begin()
354 		 ; cur != ix.end() ; ++cur)
355 	    index_vars_[idx++] = *cur;
356 }
357 
~PForeach()358 PForeach::~PForeach()
359 {
360       delete statement_;
361 }
362 
PForever(Statement * s)363 PForever::PForever(Statement*s)
364 : statement_(s)
365 {
366 }
367 
~PForever()368 PForever::~PForever()
369 {
370       delete statement_;
371 }
372 
PForStatement(PExpr * n1,PExpr * e1,PExpr * cond,Statement * step,Statement * st)373 PForStatement::PForStatement(PExpr*n1, PExpr*e1, PExpr*cond,
374 			     Statement*step, Statement*st)
375 : name1_(n1), expr1_(e1), cond_(cond), step_(step), statement_(st)
376 {
377 }
378 
~PForStatement()379 PForStatement::~PForStatement()
380 {
381 }
382 
~PProcess()383 PProcess::~PProcess()
384 {
385       delete statement_;
386 }
387 
PRelease(PExpr * l)388 PRelease::PRelease(PExpr*l)
389 : lval_(l)
390 {
391 }
392 
~PRelease()393 PRelease::~PRelease()
394 {
395       delete lval_;
396 }
397 
PRepeat(PExpr * e,Statement * s)398 PRepeat::PRepeat(PExpr*e, Statement*s)
399 : expr_(e), statement_(s)
400 {
401 }
402 
~PRepeat()403 PRepeat::~PRepeat()
404 {
405       delete expr_;
406       delete statement_;
407 }
408 
PReturn(PExpr * e)409 PReturn::PReturn(PExpr*e)
410 : expr_(e)
411 {
412 }
413 
~PReturn()414 PReturn::~PReturn()
415 {
416       delete expr_;
417 }
418 
PTrigger(PPackage * pkg,const pform_name_t & e)419 PTrigger::PTrigger(PPackage*pkg, const pform_name_t&e)
420 : package_(pkg), event_(e)
421 {
422 }
423 
~PTrigger()424 PTrigger::~PTrigger()
425 {
426 }
427 
PWhile(PExpr * ex,Statement * st)428 PWhile::PWhile(PExpr*ex, Statement*st)
429 : cond_(ex), statement_(st)
430 {
431 }
432 
~PWhile()433 PWhile::~PWhile()
434 {
435       delete cond_;
436       delete statement_;
437 }
438