module.hh revision 13191
12391SN/A/* 28931Sandreas.hansson@arm.com * Copyright 2018 Google, Inc. 38931Sandreas.hansson@arm.com * 48931Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 58931Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 68931Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 78931Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 88931Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 98931Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 108931Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 118931Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 128931Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 138931Sandreas.hansson@arm.com * this software without specific prior written permission. 142391SN/A * 152391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262391SN/A * 272391SN/A * Authors: Gabe Black 282391SN/A */ 292391SN/A 302391SN/A#ifndef __SYSTEMC_CORE_MODULE_HH__ 312391SN/A#define __SYSTEMC_CORE_MODULE_HH__ 322391SN/A 332391SN/A#include <cassert> 342391SN/A#include <list> 352391SN/A#include <map> 362391SN/A#include <sstream> 372391SN/A#include <string> 382391SN/A#include <vector> 392665SN/A 402665SN/A#include "systemc/core/object.hh" 418931Sandreas.hansson@arm.com#include "systemc/ext/core/sc_module.hh" 422391SN/A 432391SN/Anamespace sc_core 448931Sandreas.hansson@arm.com{ 458931Sandreas.hansson@arm.com 468931Sandreas.hansson@arm.comclass sc_port_base; 472391SN/Aclass sc_export_base; 482391SN/A 4912492Sodanrc@yahoo.com.br} // namespace sc_core 5012492Sodanrc@yahoo.com.br 512391SN/Anamespace sc_gem5 522462SN/A{ 538931Sandreas.hansson@arm.com 548719SN/Aclass UniqueNameGen 552462SN/A{ 569053Sdam.sunwoo@arm.com private: 579053Sdam.sunwoo@arm.com std::map<std::string, int> counts; 589053Sdam.sunwoo@arm.com std::string buf; 598931Sandreas.hansson@arm.com 609293Sandreas.hansson@arm.com public: 619293Sandreas.hansson@arm.com const char * 629293Sandreas.hansson@arm.com gen(std::string seed) 639293Sandreas.hansson@arm.com { 649293Sandreas.hansson@arm.com std::ostringstream os; 659293Sandreas.hansson@arm.com os << seed << "_" << counts[seed]++; 669293Sandreas.hansson@arm.com buf = os.str(); 679293Sandreas.hansson@arm.com return buf.c_str(); 689293Sandreas.hansson@arm.com } 699293Sandreas.hansson@arm.com}; 709293Sandreas.hansson@arm.com 719293Sandreas.hansson@arm.comclass Module 729293Sandreas.hansson@arm.com{ 739293Sandreas.hansson@arm.com private: 749293Sandreas.hansson@arm.com const char *_name; 759293Sandreas.hansson@arm.com sc_core::sc_module *_sc_mod; 769293Sandreas.hansson@arm.com Object *_obj; 7711005Sandreas.sandberg@arm.com bool _ended; 789293Sandreas.hansson@arm.com bool _deprecatedConstructor; 799293Sandreas.hansson@arm.com 809293Sandreas.hansson@arm.com UniqueNameGen nameGen; 819293Sandreas.hansson@arm.com 8212749Sgiacomo.travaglini@arm.com public: 839293Sandreas.hansson@arm.com 849293Sandreas.hansson@arm.com Module(const char *name); 859293Sandreas.hansson@arm.com ~Module(); 869293Sandreas.hansson@arm.com 8712749Sgiacomo.travaglini@arm.com void finish(Object *this_obj); 8812749Sgiacomo.travaglini@arm.com 899293Sandreas.hansson@arm.com const char *name() const { return _name; } 909293Sandreas.hansson@arm.com void endModule() { _ended = true; } 919293Sandreas.hansson@arm.com void deprecatedConstructor() { _deprecatedConstructor = true; } 929293Sandreas.hansson@arm.com 939293Sandreas.hansson@arm.com sc_core::sc_module * 949293Sandreas.hansson@arm.com sc_mod() const 959293Sandreas.hansson@arm.com { 969293Sandreas.hansson@arm.com assert(_sc_mod); 978931Sandreas.hansson@arm.com return _sc_mod; 988931Sandreas.hansson@arm.com } 998931Sandreas.hansson@arm.com 1008931Sandreas.hansson@arm.com void 1018931Sandreas.hansson@arm.com sc_mod(sc_core::sc_module *sc_mod) 1028931Sandreas.hansson@arm.com { 1038931Sandreas.hansson@arm.com assert(!_sc_mod); 1042391SN/A _sc_mod = sc_mod; 1056107SN/A } 1066107SN/A 1078931Sandreas.hansson@arm.com Object * 1089235Sandreas.hansson@arm.com obj() 1092413SN/A { 1108931Sandreas.hansson@arm.com assert(_obj); 1118931Sandreas.hansson@arm.com return _obj; 1122413SN/A } 1138931Sandreas.hansson@arm.com 11411614Sdavid.j.hashe@gmail.com void pop(); 1152413SN/A 1168931Sandreas.hansson@arm.com const char *uniqueName(const char *seed) { return nameGen.gen(seed); } 11711614Sdavid.j.hashe@gmail.com 11811614Sdavid.j.hashe@gmail.com void bindPorts(std::vector<const ::sc_core::sc_bind_proxy *> &proxies); 11911614Sdavid.j.hashe@gmail.com 12011614Sdavid.j.hashe@gmail.com std::vector<::sc_core::sc_port_base *> ports; 1213170SN/A std::vector<::sc_core::sc_export_base *> exports; 1223170SN/A 1233170SN/A void beforeEndOfElaboration(); 1243170SN/A void endOfElaboration(); 1253170SN/A void startOfSimulation(); 1263170SN/A void endOfSimulation(); 1273170SN/A}; 1284626SN/A 1293170SN/AModule *currentModule(); 1303170SN/AModule *newModuleChecked(); 1313170SN/AModule *newModule(); 1323170SN/A 1334626SN/Avoid callbackModule(Module *m); 1343170SN/AModule *callbackModule(); 1353170SN/A 1363170SN/Aextern std::list<Module *> allModules; 1373170SN/A 1383170SN/A} // namespace sc_gem5 1393170SN/A 1403170SN/A#endif //__SYSTEMC_CORE_MODULE_HH__ 1413170SN/A