00001 #ifndef SYSTEMC_DEFINITION_H_INCLUDED_ 00002 #define SYSTEMC_DEFINITION_H_INCLUDED_ 00003 00004 #include "rose.h" 00005 00006 #include "rose_nodes.h" 00007 00008 namespace risc { 00009 00010 namespace tools { 00011 00016 class SystemCDefinitions { 00017 00018 public: 00019 00020 static SgClassDefinition* get_sc_module() 00021 { 00022 if (!is_initialized_) initialize(); 00023 return sc_module_; 00024 } 00025 00026 static SgClassDefinition* get_sc_port() 00027 { 00028 if (!is_initialized_) initialize(); 00029 return sc_port_; 00030 } 00031 00032 static SgClassDefinition* get_sc_port_base() 00033 { 00034 if (!is_initialized_) initialize(); 00035 return sc_port_base_; 00036 } 00037 00038 static SgClassDefinition* get_sc_in() 00039 { 00040 if (!is_initialized_) initialize(); 00041 return sc_in_; 00042 } 00043 00044 static SgClassDefinition* get_sc_out() 00045 { 00046 if (!is_initialized_) initialize(); 00047 return sc_out_; 00048 } 00049 00050 static SgClassDefinition* get_sc_inout() 00051 { 00052 if (!is_initialized_) initialize(); 00053 return sc_inout_; 00054 } 00055 00056 static SgClassDefinition* get_sc_event() 00057 { 00058 if (!is_initialized_) initialize(); 00059 return sc_event_; 00060 } 00061 00062 static SgClassDefinition* get_sc_event_and_list() 00063 { 00064 if (!is_initialized_) initialize(); 00065 return sc_event_and_list_; 00066 } 00067 00068 static SgClassDefinition* get_sc_event_or_list() 00069 { 00070 if (!is_initialized_) initialize(); 00071 return sc_event_or_list_; 00072 } 00073 00074 static SgClassDefinition* get_sc_prim_channel() 00075 { 00076 if (!is_initialized_) initialize(); 00077 return sc_prim_channel_; 00078 } 00079 00080 static SgClassDefinition* get_sc_interface() 00081 { 00082 if (!is_initialized_) initialize(); 00083 return sc_interface_; 00084 } 00085 00086 static SgClassDefinition* get_sc_channel() 00087 { 00088 if (!is_initialized_) initialize(); 00089 return sc_channel_; 00090 } 00091 00092 static SgClassDefinition* get_sc_in_clk() 00093 { 00094 if (!is_initialized_) initialize(); 00095 return sc_in_clk_; 00096 } 00097 00098 static SgClassDefinition* get_sc_out_clk() 00099 { 00100 if (!is_initialized_) initialize(); 00101 return sc_out_clk_; 00102 } 00103 00104 static SgClassDefinition* get_sc_inout_clk() 00105 { 00106 if (!is_initialized_) initialize(); 00107 return sc_inout_clk_; 00108 } 00109 00110 static SgClassDefinition* get_sc_fifo() 00111 { 00112 if (!is_initialized_) initialize(); 00113 return sc_fifo_; 00114 } 00115 00116 static SgClassDefinition* get_sc_fifo_in() 00117 { 00118 if (!is_initialized_) initialize(); 00119 return sc_fifo_in_; 00120 } 00121 00122 static SgClassDefinition* get_sc_fifo_out() 00123 { 00124 if (!is_initialized_) initialize(); 00125 return sc_fifo_out_; 00126 } 00127 00128 static SgFunctionDefinition* get_sc_main() 00129 { 00130 if (!is_initialized_) initialize(); 00131 // RD: in PSG mode, this won't be found, so we delay the error until it's needed 00132 if (!sc_main_) { // complain if not found (RD, 07/06/18) 00133 std::cerr << std::endl << "ERROR: Cannot find definition of function '" 00134 << "sc_main" << "' (in source code). Aborting." 00135 << std::endl; 00136 exit(10); 00137 } 00138 return sc_main_; 00139 } 00140 00141 static SgClassDefinition* get_sc_simcontext() 00142 { 00143 if (!is_initialized_) initialize(); 00144 return sc_simcontext_; 00145 } 00146 00147 static SgClassDefinition* get_sc_segid() 00148 { 00149 if (!is_initialized_) initialize(); 00150 return sc_segid_; 00151 } 00152 00153 static SgClassDefinition* get_sc_process_b() 00154 { 00155 if (!is_initialized_) initialize(); 00156 return sc_process_b_; 00157 } 00158 00159 static SgFunctionDeclaration* get_sc_curr_proc() 00160 { 00161 if (!is_initialized_) initialize(); 00162 return sc_get_curr_proc_; 00163 } 00164 00165 static SgFunctionDeclaration* get_sc_segid_ctor() 00166 { 00167 if (!is_initialized_) initialize(); 00168 return sc_segid_ctor_; 00169 } 00170 00171 static SgFunctionDeclaration* get_sc_get_curr_simcontext() 00172 { 00173 if (!is_initialized_) initialize(); 00174 return sc_get_curr_simcontext_; 00175 } 00176 00177 static SgFunctionDeclaration* get_get_upcoming_segment_ids() 00178 { 00179 if (!is_initialized_) initialize(); 00180 return get_upcoming_segment_ids_; 00181 } 00182 00183 static SgFunctionDeclaration* get_set_upcoming_segment_ids() 00184 { 00185 if (!is_initialized_) initialize(); 00186 return set_upcoming_segment_ids_; 00187 } 00188 00189 static const std::vector<SgNamespaceDefinitionStatement*>& get_sc_core() 00190 { 00191 if (!is_initialized_) initialize(); 00192 return sc_core_; 00193 } 00194 00195 static const std::vector<SgNamespaceDefinitionStatement*>& get_sc_dt() 00196 { 00197 if (!is_initialized_) initialize(); 00198 return sc_dt_; 00199 } 00200 00201 static const std::set<SgFunctionDefinition*>& get_sc_wait_funcs() 00202 { 00203 if (!is_initialized_) initialize(); 00204 return sc_wait_funcs_; 00205 } 00206 00207 static const SgMemberFunctionDeclaration* get_interface() 00208 { 00209 if (!is_initialized_) initialize(); 00210 return get_interface_; 00211 } 00212 00213 private: 00214 static void initialize(); 00215 00216 /* 00217 * \brief Pointer to the sc_module definition in the rose ast tree 00218 */ 00219 static SgClassDefinition *sc_module_; 00220 static SgClassDefinition *sc_port_; 00221 static SgClassDefinition *sc_port_base_; 00222 static SgClassDefinition *sc_in_; 00223 static SgClassDefinition *sc_out_; 00224 static SgClassDefinition *sc_inout_; 00225 static SgClassDefinition *sc_event_; 00226 static SgClassDefinition *sc_event_and_list_; 00227 static SgClassDefinition *sc_event_or_list_; 00228 static SgClassDefinition *sc_prim_channel_; 00229 static SgClassDefinition *sc_interface_; 00230 static SgClassDefinition *sc_fifo_; 00231 static SgClassDefinition *sc_fifo_in_; 00232 static SgClassDefinition *sc_fifo_out_; 00233 static SgClassDefinition *sc_simcontext_; 00234 static SgClassDefinition *sc_segid_; 00235 static SgClassDefinition *sc_process_b_; 00236 00237 // This is a hack. Please see the comment in the source file. 00238 static SgClassDefinition *sc_channel_; 00239 static SgClassDefinition *sc_in_clk_; 00240 static SgClassDefinition *sc_out_clk_; 00241 static SgClassDefinition *sc_inout_clk_; 00242 00243 static SgFunctionDefinition *sc_main_; 00244 static SgFunctionDeclaration *sc_get_curr_simcontext_; 00245 static SgMemberFunctionDeclaration *sc_get_curr_proc_; 00246 static SgMemberFunctionDeclaration *sc_segid_ctor_; 00247 static SgMemberFunctionDeclaration *get_upcoming_segment_ids_; 00248 static SgMemberFunctionDeclaration *set_upcoming_segment_ids_; 00249 static SgMemberFunctionDeclaration *get_interface_; 00250 00251 // Namespace of systemc 00252 static std::vector<SgNamespaceDefinitionStatement*> sc_core_; 00253 static std::vector<SgNamespaceDefinitionStatement*> sc_dt_; 00254 00255 // Wait functions 00256 static std::set<SgFunctionDefinition*> sc_wait_funcs_; 00257 00258 static bool is_initialized_; 00259 }; 00260 00261 // NEW: efficient type comparison functions (RD, 07/14/18) 00262 00263 inline bool is_type_sc_module(SgType *type) 00264 { 00265 return type->stripTypedefsAndModifiers() == 00266 SystemCDefinitions::get_sc_module() 00267 ->get_declaration()->get_type(); 00268 } 00269 00270 inline bool is_type_sc_port(SgType *type) 00271 { 00272 return type->stripTypedefsAndModifiers() == 00273 SystemCDefinitions::get_sc_port() 00274 ->get_declaration()->get_type(); 00275 } 00276 00277 inline bool is_type_sc_port_base(SgType *type) 00278 { 00279 return type->stripTypedefsAndModifiers() == 00280 SystemCDefinitions::get_sc_port_base() 00281 ->get_declaration()->get_type(); 00282 } 00283 00284 inline bool is_type_sc_in(SgType *type) 00285 { 00286 return type->stripTypedefsAndModifiers() == 00287 SystemCDefinitions::get_sc_in() 00288 ->get_declaration()->get_type(); 00289 } 00290 00291 inline bool is_type_sc_out(SgType *type) 00292 { 00293 return type->stripTypedefsAndModifiers() == 00294 SystemCDefinitions::get_sc_out() 00295 ->get_declaration()->get_type(); 00296 } 00297 00298 inline bool is_type_sc_inout(SgType *type) 00299 { 00300 return type->stripTypedefsAndModifiers() == 00301 SystemCDefinitions::get_sc_inout() 00302 ->get_declaration()->get_type(); 00303 } 00304 00305 inline bool is_type_sc_event(SgType *type) 00306 { 00307 return type->stripTypedefsAndModifiers() == 00308 SystemCDefinitions::get_sc_event() 00309 ->get_declaration()->get_type(); 00310 } 00311 00312 inline bool is_type_sc_event_and_list(SgType *type) 00313 { 00314 return type->stripTypedefsAndModifiers() == 00315 SystemCDefinitions::get_sc_event_and_list() 00316 ->get_declaration()->get_type(); 00317 } 00318 00319 inline bool is_type_sc_event_or_list(SgType *type) 00320 { 00321 return type->stripTypedefsAndModifiers() == 00322 SystemCDefinitions::get_sc_event_or_list() 00323 ->get_declaration()->get_type(); 00324 } 00325 00326 inline bool is_type_sc_prim_channel(SgType *type) 00327 { 00328 return type->stripTypedefsAndModifiers() == 00329 SystemCDefinitions::get_sc_prim_channel() 00330 ->get_declaration()->get_type(); 00331 } 00332 00333 inline bool is_type_sc_interface(SgType *type) 00334 { 00335 return type->stripTypedefsAndModifiers() == 00336 SystemCDefinitions::get_sc_interface() 00337 ->get_declaration()->get_type(); 00338 } 00339 00340 inline bool is_type_sc_fifo(SgType *type) 00341 { 00342 return type->stripTypedefsAndModifiers() == 00343 SystemCDefinitions::get_sc_fifo() 00344 ->get_declaration()->get_type(); 00345 } 00346 00347 inline bool is_type_sc_fifo_in(SgType *type) 00348 { 00349 return type->stripTypedefsAndModifiers() == 00350 SystemCDefinitions::get_sc_fifo_in() 00351 ->get_declaration()->get_type(); 00352 } 00353 00354 inline bool is_type_sc_fifo_out(SgType *type) 00355 { 00356 return type->stripTypedefsAndModifiers() == 00357 SystemCDefinitions::get_sc_fifo_out() 00358 ->get_declaration()->get_type(); 00359 } 00360 00361 inline bool is_type_sc_simcontext(SgType *type) 00362 { 00363 return type->stripTypedefsAndModifiers() == 00364 SystemCDefinitions::get_sc_simcontext() 00365 ->get_declaration()->get_type(); 00366 } 00367 00368 inline bool is_type_sc_segid(SgType *type) 00369 { 00370 return type->stripTypedefsAndModifiers() == 00371 SystemCDefinitions::get_sc_segid() 00372 ->get_declaration()->get_type(); 00373 } 00374 00375 inline bool is_type_sc_process_b(SgType *type) 00376 { 00377 return type->stripTypedefsAndModifiers() == 00378 SystemCDefinitions::get_sc_process_b() 00379 ->get_declaration()->get_type(); 00380 } 00381 00382 inline bool is_type_sc_channel(SgType *type) 00383 { 00384 return type->stripTypedefsAndModifiers() == 00385 SystemCDefinitions::get_sc_channel() 00386 ->get_declaration()->get_type(); 00387 } 00388 00389 inline bool is_type_sc_in_clk(SgType *type) 00390 { 00391 return type->stripTypedefsAndModifiers() == 00392 SystemCDefinitions::get_sc_in_clk() 00393 ->get_declaration()->get_type(); 00394 } 00395 00396 inline bool is_type_sc_out_clk(SgType *type) 00397 { 00398 return type->stripTypedefsAndModifiers() == 00399 SystemCDefinitions::get_sc_out_clk() 00400 ->get_declaration()->get_type(); 00401 } 00402 00403 inline bool is_type_sc_inout_clk(SgType *type) 00404 { 00405 return type->stripTypedefsAndModifiers() == 00406 SystemCDefinitions::get_sc_inout_clk() 00407 ->get_declaration()->get_type(); 00408 } 00409 00410 }; // end of namespace tools 00411 00412 }; // end of namespace risc 00413 00414 #endif /* SYSTEMC_DEFINITION_H_INCLUDED_ */ 00415 00416 /* ex: set softtabstop=2 tabstop=2 shiftwidth=2 expandtab: */