1 #ifndef IVL_architec_H 2 #define IVL_architec_H 3 /* 4 * Copyright (c) 2011-2014 Stephen Williams (steve@icarus.com) 5 * 6 * This source code is free software; you can redistribute it 7 * and/or modify it in source code form under the terms of the GNU 8 * General Public License as published by the Free Software 9 * Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program 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 this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 # include "StringHeap.h" 23 # include "LineInfo.h" 24 # include "scope.h" 25 # include <list> 26 # include <map> 27 28 class ComponentInstantiation; 29 class Entity; 30 class Expression; 31 class ExpName; 32 class GenerateStatement; 33 class ProcessStatement; 34 class SequentialStmt; 35 class Signal; 36 class named_expr_t; 37 class ExpRange; 38 39 /* 40 * The Architecture class carries the contents (name, statements, 41 * etc.) of a parsed VHDL architecture. These objects are ultimately 42 * put into entities. 43 */ 44 class Architecture : public Scope, public LineInfo { 45 46 public: 47 // Architectures contain concurrent statements, that are 48 // derived from this nested class. 49 class Statement : public LineInfo { 50 51 public: 52 Statement(); 53 virtual ~Statement() =0; 54 55 virtual int elaborate(Entity*ent, Architecture*arc); 56 virtual int emit(ostream&out, Entity*ent, Architecture*arc); 57 virtual void dump(ostream&out, int indent = 0) const; 58 }; 59 60 public: 61 // Create an architecture from its name and its statements. 62 // NOTE: The statement list passed in is emptied. 63 Architecture(perm_string name, const ActiveScope&ref, 64 std::list<Architecture::Statement*>&s); 65 ~Architecture(); 66 get_name()67 perm_string get_name() const { return name_; } 68 69 bool find_constant(perm_string by_name, const VType*&typ, Expression*&exp) const; 70 Variable* find_variable(perm_string by_name) const; 71 72 // Sets the currently processed component (to be able to reach its parameters). set_cur_component(ComponentInstantiation * component)73 void set_cur_component(ComponentInstantiation*component) { 74 assert(!cur_component_ || !component); 75 cur_component_ = component; 76 } 77 78 // Sets the currently elaborated process (to use its scope for variable resolving). set_cur_process(ProcessStatement * process)79 void set_cur_process(ProcessStatement*process) { 80 assert(!cur_process_ || !process); 81 cur_process_ = process; 82 } 83 84 // Elaborate this architecture in the context of the given entity. 85 int elaborate(Entity*entity); 86 87 // These methods are used while in the scope of a generate 88 // block to mark that a name is a genvar at this point. 89 const VType* probe_genvar_type(perm_string); 90 void push_genvar_type(perm_string gname, const VType*gtype); 91 void pop_genvar_type(void); 92 93 // These methods are used during EMIT to check for names that 94 // are genvar names. 95 const GenerateStatement* probe_genvar_emit(perm_string); 96 void push_genvar_emit(perm_string gname, const GenerateStatement*); 97 void pop_genvar_emit(void); 98 99 // Emit this architecture to the given out file in the context 100 // of the specified entity. This method is used by the 101 // elaborate code to display generated code to the specified 102 // output. 103 int emit(ostream&out, Entity*entity); 104 105 // The dump method writes a debug display to the given output. 106 void dump(ostream&out, perm_string of_entity, int indent = 0) const; 107 108 private: 109 perm_string name_; 110 // Concurrent statements local to this architecture 111 std::list<Architecture::Statement*> statements_; 112 113 struct genvar_type_t { 114 perm_string name; 115 const VType*vtype; 116 }; 117 std::list<genvar_type_t> genvar_type_stack_; 118 119 struct genvar_emit_t { 120 perm_string name; 121 const GenerateStatement*gen; 122 }; 123 std::list<genvar_emit_t> genvar_emit_stack_; 124 125 // Currently processed component (or NULL if none). 126 ComponentInstantiation*cur_component_; 127 128 // Currently elaborated process (or NULL if none). 129 ProcessStatement*cur_process_; 130 }; 131 132 /* 133 * This is a base class for various generate statement types. It holds 134 * the generate statement name, and a list of substatements. 135 */ 136 class GenerateStatement : public Architecture::Statement { 137 138 public: 139 GenerateStatement(perm_string gname, std::list<Architecture::Statement*>&s); 140 ~GenerateStatement(); 141 get_name()142 inline perm_string get_name() const { return name_; } 143 144 protected: 145 int elaborate_statements(Entity*ent, Architecture*arc); 146 int emit_statements(ostream&out, Entity*ent, Architecture*arc); 147 void dump_statements(ostream&out, int indent) const; 148 149 private: 150 perm_string name_; 151 std::list<Architecture::Statement*> statements_; 152 }; 153 154 class ForGenerate : public GenerateStatement { 155 156 public: 157 ForGenerate(perm_string gname, perm_string genvar, 158 ExpRange*rang, std::list<Architecture::Statement*>&s); 159 ~ForGenerate(); 160 161 int elaborate(Entity*ent, Architecture*arc); 162 int emit(ostream&out, Entity*entity, Architecture*arc); 163 void dump(ostream&out, int ident =0) const; 164 165 private: 166 perm_string genvar_; 167 Expression*lsb_; 168 Expression*msb_; 169 }; 170 171 class IfGenerate : public GenerateStatement { 172 173 public: 174 IfGenerate(perm_string gname, Expression*cond, 175 std::list<Architecture::Statement*>&s); 176 ~IfGenerate(); 177 178 int elaborate(Entity*ent, Architecture*arc); 179 int emit(ostream&out, Entity*entity, Architecture*arc); 180 181 private: 182 Expression*cond_; 183 }; 184 185 /* 186 * The SignalAssignment class represents the 187 * concurrent_signal_assignment that is placed in an architecture. 188 */ 189 class SignalAssignment : public Architecture::Statement { 190 191 public: 192 SignalAssignment(ExpName*target, std::list<Expression*>&rval); 193 SignalAssignment(ExpName*target, Expression*rval); 194 ~SignalAssignment(); 195 196 virtual int elaborate(Entity*ent, Architecture*arc); 197 virtual int emit(ostream&out, Entity*entity, Architecture*arc); 198 virtual void dump(ostream&out, int ident =0) const; 199 200 private: 201 ExpName*lval_; 202 std::list<Expression*> rval_; 203 }; 204 205 class CondSignalAssignment : public Architecture::Statement { 206 207 public: 208 CondSignalAssignment(ExpName*target, std::list<ExpConditional::case_t*>&options); 209 ~CondSignalAssignment(); 210 211 int elaborate(Entity*ent, Architecture*arc); 212 int emit(ostream&out, Entity*entity, Architecture*arc); 213 void dump(ostream&out, int ident =0) const; 214 215 private: 216 ExpName*lval_; 217 std::list<ExpConditional::case_t*> options_; 218 219 // List of signals that should be emitted in the related process 220 // sensitivity list. It is filled during the elaboration step. 221 std::list<const ExpName*>sens_list_; 222 }; 223 224 class ComponentInstantiation : public Architecture::Statement { 225 226 public: 227 ComponentInstantiation(perm_string iname, perm_string cname, 228 std::list<named_expr_t*>*parms, 229 std::list<named_expr_t*>*ports); 230 ~ComponentInstantiation(); 231 232 virtual int elaborate(Entity*ent, Architecture*arc); 233 virtual int emit(ostream&out, Entity*entity, Architecture*arc); 234 virtual void dump(ostream&out, int indent =0) const; 235 236 // Returns the expression that initializes a generic (or NULL if not found). 237 Expression*find_generic_map(perm_string by_name) const; 238 instance_name()239 inline perm_string instance_name() const { return iname_; } component_name()240 inline perm_string component_name() const { return cname_; } 241 242 private: 243 perm_string iname_; 244 perm_string cname_; 245 246 std::map<perm_string,Expression*> generic_map_; 247 std::map<perm_string,Expression*> port_map_; 248 }; 249 250 class StatementList : public Architecture::Statement { 251 public: 252 StatementList(std::list<SequentialStmt*>*statement_list); 253 virtual ~StatementList(); 254 elaborate(Entity * ent,Architecture * arc)255 int elaborate(Entity*ent, Architecture*arc) { 256 return elaborate(ent, static_cast<ScopeBase*>(arc)); 257 } 258 emit(ostream & out,Entity * ent,Architecture * arc)259 int emit(ostream&out, Entity*ent, Architecture*arc) { 260 return emit(out, ent, static_cast<ScopeBase*>(arc)); 261 } 262 263 virtual int elaborate(Entity*ent, ScopeBase*scope); 264 virtual int emit(ostream&out, Entity*entity, ScopeBase*scope); 265 virtual void dump(ostream&out, int indent =0) const; 266 stmt_list()267 std::list<SequentialStmt*>& stmt_list() { return statements_; } 268 269 private: 270 std::list<SequentialStmt*> statements_; 271 }; 272 273 // There is no direct VHDL counterpart to SV 'initial' statement, 274 // but we can still use it during the translation process. 275 class InitialStatement : public StatementList { 276 public: InitialStatement(std::list<SequentialStmt * > * statement_list)277 InitialStatement(std::list<SequentialStmt*>*statement_list) 278 : StatementList(statement_list) {} 279 280 int emit(ostream&out, Entity*entity, ScopeBase*scope); 281 void dump(ostream&out, int indent =0) const; 282 }; 283 284 // There is no direct VHDL counterpart to SV 'final' statement, 285 // but we can still use it during the translation process. 286 class FinalStatement : public StatementList { 287 public: FinalStatement(std::list<SequentialStmt * > * statement_list)288 FinalStatement(std::list<SequentialStmt*>*statement_list) 289 : StatementList(statement_list) {} 290 291 int emit(ostream&out, Entity*entity, ScopeBase*scope); 292 void dump(ostream&out, int indent =0) const; 293 }; 294 295 class ProcessStatement : public StatementList, public Scope { 296 297 public: 298 ProcessStatement(perm_string iname, 299 const ActiveScope&ref, 300 std::list<Expression*>*sensitivity_list, 301 std::list<SequentialStmt*>*statement_list); 302 ~ProcessStatement(); 303 304 int elaborate(Entity*ent, Architecture*arc); 305 int emit(ostream&out, Entity*entity, Architecture*arc); 306 void dump(ostream&out, int indent =0) const; 307 308 private: 309 perm_string iname_; 310 std::list<Expression*> sensitivity_list_; 311 }; 312 313 #endif /* IVL_architec_H */ 314