1 /*
2 * Copyright (c) 2011 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 "sequential.h"
21 # include "expression.h"
22 # include <fstream>
23 # include <iomanip>
24 # include <typeinfo>
25
26 using namespace std;
27
dump(ostream & out,int indent) const28 void SequentialStmt::dump(ostream&out, int indent) const
29 {
30 out << setw(indent) << "" << "SequentialStmt[" << typeid(*this).name() << "]"
31 << " at file=" << get_fileline() << endl;
32 }
33
dump(ostream & out,int indent) const34 void IfSequential::dump(ostream&out, int indent) const
35 {
36 out << setw(indent) << "" << "IfSequential at file=" << get_fileline() << endl;
37 out << setw(indent+3) << "" << "Condition:" << endl;
38 cond_->dump(out, indent+4);
39
40 out << setw(indent+3) << "" << "TRUE clause (" << if_.size() << "):" << endl;
41 for (list<SequentialStmt*>::const_iterator cur = if_.begin()
42 ; cur != if_.end() ; ++cur)
43 (*cur)->dump(out, indent+4);
44
45 for (list<IfSequential::Elsif*>::const_iterator cur = elsif_.begin()
46 ; cur != elsif_.end() ; ++cur)
47 (*cur)->dump(out, indent);
48
49 out << setw(indent+3) << "" << "FALSE clause (" << else_.size() << "):" << endl;
50 for (list<SequentialStmt*>::const_iterator cur = else_.begin()
51 ; cur != else_.end() ; ++cur)
52 (*cur)->dump(out, indent+4);
53
54 }
55
dump(ostream & out,int indent) const56 void IfSequential::Elsif::dump(ostream&out, int indent) const
57 {
58 out << setw(indent+3) << "" << "Elsif Condition at " << get_fileline() << ":" << endl;
59 cond_->dump(out, indent+4);
60
61 out << setw(indent+3) << "" << "ELSIF TRUE clause (" << if_.size() << "):" << endl;
62 for (list<SequentialStmt*>::const_iterator cur = if_.begin()
63 ; cur != if_.end() ; ++cur)
64 (*cur)->dump(out, indent+4);
65
66 }
67
dump(ostream & out,int indent) const68 void ReturnStmt::dump(ostream&out, int indent) const
69 {
70 out << setw(indent) << "" << "ReturnStmt at file=" << get_fileline() << endl;
71 if (val_)
72 val_->dump(out, indent+4);
73 else
74 out << setw(indent+4) << "" << "()" << endl;
75 }
76
dump(ostream & out,int indent) const77 void SignalSeqAssignment::dump(ostream&out, int indent) const
78 {
79 out << setw(indent) << "" << "SignalSeqAssignment at file=" << get_fileline() << endl;
80
81 out << setw(indent+3) << "" << "l-value:" << endl;
82 lval_->dump(out, indent+4);
83
84 out << setw(indent+3) << "" << "r-values (" << waveform_.size() << "):" << endl;
85 for (list<Expression*>::const_iterator cur = waveform_.begin()
86 ; cur != waveform_.end() ; ++cur)
87 (*cur)->dump(out, indent+4);
88 }
89
dump(ostream & out,int indent) const90 void CaseSeqStmt::dump(ostream& out, int indent) const
91 {
92 out << setw(indent) << "" << "CaseSeqStmt at file=" << get_fileline() << endl;
93
94 out << setw(indent+3) << "" << "Case: " << endl;
95 cond_->dump(out, indent+4);
96
97 for (list<CaseSeqStmt::CaseStmtAlternative*>::const_iterator cur = alt_.begin()
98 ; cur != alt_.end() ; ++cur)
99 (*cur)->dump(out, indent+4);
100 }
101
dump(ostream & out,int indent) const102 void CaseSeqStmt::CaseStmtAlternative::dump(ostream& out, int indent) const
103 {
104 out << setw(indent) << "" << "CaseStmtAlternative at file=" << get_fileline() << endl;
105
106 out << setw(indent) << "" << "when ";
107 if (exp_)
108 for (list<Expression*>::iterator it = exp_->begin(); it != exp_->end(); ++it) {
109 (*it)->dump(out, 0);
110 }
111 else
112 out << "others" << endl;
113
114 for (list<SequentialStmt*>::const_iterator cur = stmts_.begin()
115 ; cur != stmts_.end(); ++cur)
116 (*cur)->dump(out, indent+1);
117 }
118
dump(ostream & out,int indent) const119 void ProcedureCall::dump(ostream& out, int indent) const
120 {
121 out << setw(indent) << "" << "ProcedureCall at file=" << get_fileline() << endl;
122 out << setw(indent+2) << "" << name_ << "(";
123 for(list<named_expr_t*>::const_iterator it = param_list_->begin();
124 it != param_list_->end(); ++it)
125 (*it)->dump(out, indent);
126 out << ")" << endl;
127 }
128
dump(ostream & out,int indent) const129 void LoopStatement::dump(ostream&out, int indent) const
130 {
131 for(list<SequentialStmt*>::const_iterator it = stmts_.begin();
132 it != stmts_.end(); ++it)
133 (*it)->dump(out, indent);
134 }
135
dump(ostream & out,int indent) const136 void ForLoopStatement::dump(ostream&out, int indent) const
137 {
138 out << setw(indent) << "" << "ForLoopStatement at file=" << get_fileline() << endl;
139 out << setw(indent) << "" << it_ << " in ";
140 range_->dump(out, indent);
141 LoopStatement::dump(out, indent+2);
142 }
143
dump(ostream & out,int indent) const144 void VariableSeqAssignment::dump(ostream&out, int indent) const
145 {
146 out << setw(indent) << "" << "VariableSeqAssignment at file=" << get_fileline() << endl;
147
148 out << setw(indent+3) << "" << "l-value:" << endl;
149 lval_->dump(out, indent+4);
150
151 out << setw(indent+3) << "" << "r-value:" << endl;
152 rval_->dump(out, indent+4);
153 }
154
dump(ostream & out,int indent) const155 void WhileLoopStatement::dump(ostream&out, int indent) const
156 {
157 out << setw(indent) << "" << "WhileLoopStatement at file=" << get_fileline() << endl;
158 out << setw(indent) << "" << "condition: ";
159 cond_->dump(out, indent);
160 LoopStatement::dump(out, indent+2);
161 }
162
dump(ostream & out,int indent) const163 void BasicLoopStatement::dump(ostream&out, int indent) const
164 {
165 out << setw(indent) << "" << "BasicLoopStatement at file=" << get_fileline() << endl;
166 LoopStatement::dump(out, indent+2);
167 }
168
dump(ostream & out,int indent) const169 void ReportStmt::dump(ostream&out, int indent) const
170 {
171 out << setw(indent) << "" << "ReportStmt at file=" << get_fileline() << endl;
172 dump_sev_msg(out, indent+3);
173 }
174
dump_sev_msg(ostream & out,int indent) const175 void ReportStmt::dump_sev_msg(ostream&out, int indent) const
176 {
177 out << setw(indent) << "" << "severity: " << severity_ << endl;
178
179 if(msg_) {
180 out << setw(indent) << "" << "message: ";
181 msg_->dump(out, indent);
182 }
183 }
184
dump(ostream & out,int indent) const185 void AssertStmt::dump(ostream&out, int indent) const
186 {
187 out << setw(indent) << "" << "AssertStmt at file=" << get_fileline() << endl;
188 out << setw(indent+3) << "" << "condition: ";
189 dump_sev_msg(out, indent+3);
190 }
191
dump(ostream & out,int indent) const192 void WaitForStmt::dump(ostream&out, int indent) const
193 {
194 out << setw(indent) << "" << "WaitForStmt at file=" << get_fileline() << endl;
195 out << setw(indent+3) << "" << "delay: ";
196 delay_->dump(out, indent+3);
197 }
198
dump(ostream & out,int indent) const199 void WaitStmt::dump(ostream&out, int indent) const
200 {
201 out << setw(indent) << "" << "WaitStmt at file=" << get_fileline() << endl;
202 out << setw(indent+3) << "type = ";
203
204 switch(type_) {
205 case ON: out << "ON" << endl; break;
206 case UNTIL: out << "UNTIL" << endl; break;
207 case FINAL: out << "FINAL" << endl; break;
208 }
209
210 if(type_ != FINAL) {
211 out << setw(indent+3) << "" << "expression: ";
212 expr_->dump(out, indent+3);
213 }
214 }
215