module.hh revision 13291
17405SAli.Saidi@ARM.com/* 212667Schuan.zhu@arm.com * Copyright 2018 Google, Inc. 37405SAli.Saidi@ARM.com * 47405SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 57405SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 67405SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 77405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 87405SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 97405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 107405SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 117405SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 127405SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 137405SAli.Saidi@ARM.com * this software without specific prior written permission. 147405SAli.Saidi@ARM.com * 157405SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 167405SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 177405SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 187405SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 197405SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 207405SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 217405SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 227405SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 237405SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 247405SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 257405SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 267405SAli.Saidi@ARM.com * 277405SAli.Saidi@ARM.com * Authors: Gabe Black 287405SAli.Saidi@ARM.com */ 297405SAli.Saidi@ARM.com 307405SAli.Saidi@ARM.com#ifndef __SYSTEMC_CORE_MODULE_HH__ 317405SAli.Saidi@ARM.com#define __SYSTEMC_CORE_MODULE_HH__ 327405SAli.Saidi@ARM.com 337405SAli.Saidi@ARM.com#include <cassert> 347405SAli.Saidi@ARM.com#include <list> 357405SAli.Saidi@ARM.com#include <map> 367405SAli.Saidi@ARM.com#include <sstream> 377405SAli.Saidi@ARM.com#include <string> 387405SAli.Saidi@ARM.com#include <vector> 397405SAli.Saidi@ARM.com 407405SAli.Saidi@ARM.com#include "systemc/core/object.hh" 417405SAli.Saidi@ARM.com#include "systemc/ext/core/sc_module.hh" 4210461SAndreas.Sandberg@ARM.com 439050Schander.sudanthi@arm.comnamespace sc_core 4412406Sgabeblack@google.com{ 4512605Sgiacomo.travaglini@arm.com 4611793Sbrandon.potter@amd.comclass sc_port_base; 478887Sgeoffrey.blake@arm.comclass sc_export_base; 488232Snate@binkert.org 498232Snate@binkert.org} // namespace sc_core 5010844Sandreas.sandberg@arm.com 5113531Sjairo.balart@metempsy.comnamespace sc_gem5 5213531Sjairo.balart@metempsy.com{ 539384SAndreas.Sandberg@arm.com 547678Sgblack@eecs.umich.educlass UniqueNameGen 558059SAli.Saidi@ARM.com{ 568284SAli.Saidi@ARM.com private: 577405SAli.Saidi@ARM.com std::map<std::string, int> counts; 587405SAli.Saidi@ARM.com std::string buf; 597405SAli.Saidi@ARM.com 607405SAli.Saidi@ARM.com public: 619384SAndreas.Sandberg@arm.com const char * 6210461SAndreas.Sandberg@ARM.com gen(std::string seed) 6310461SAndreas.Sandberg@ARM.com { 6411165SRekai.GonzalezAlberquilla@arm.com std::ostringstream os; 6513599Sgiacomo.travaglini@arm.com os << seed << "_" << counts[seed]++; 6612714Sgiacomo.travaglini@arm.com buf = os.str(); 6713691Sgiacomo.travaglini@arm.com return buf.c_str(); 6812714Sgiacomo.travaglini@arm.com } 699384SAndreas.Sandberg@arm.com}; 7011770SCurtis.Dunham@arm.com 7110037SARM gem5 Developersclass Module 7210461SAndreas.Sandberg@ARM.com{ 7310461SAndreas.Sandberg@ARM.com private: 7410461SAndreas.Sandberg@ARM.com const char *_name; 7510461SAndreas.Sandberg@ARM.com sc_core::sc_module *_sc_mod; 7610461SAndreas.Sandberg@ARM.com Object *_obj; 7710461SAndreas.Sandberg@ARM.com bool _ended; 7810609Sandreas.sandberg@arm.com bool _deprecatedConstructor; 7910609Sandreas.sandberg@arm.com 8010609Sandreas.sandberg@arm.com UniqueNameGen nameGen; 8110037SARM gem5 Developers 8210037SARM gem5 Developers public: 8310037SARM gem5 Developers Module(const char *name); 8410037SARM gem5 Developers ~Module(); 8511771SCurtis.Dunham@arm.com 8610037SARM gem5 Developers static Module * 8710037SARM gem5 Developers fromScModule(::sc_core::sc_module *mod) 8813173Sgiacomo.travaglini@arm.com { 8910037SARM gem5 Developers return mod->_gem5_module; 9010037SARM gem5 Developers } 9113114Sgiacomo.travaglini@arm.com 9213759Sgiacomo.gabrielli@arm.com void finish(Object *this_obj); 9313759Sgiacomo.gabrielli@arm.com 9410037SARM gem5 Developers const char *name() const { return _name; } 9511771SCurtis.Dunham@arm.com void endModule() { _ended = true; } 9610037SARM gem5 Developers void deprecatedConstructor() { _deprecatedConstructor = true; } 9713499Sgiacomo.travaglini@arm.com 9810037SARM gem5 Developers sc_core::sc_module * 9913114Sgiacomo.travaglini@arm.com sc_mod() const 10013759Sgiacomo.gabrielli@arm.com { 10113759Sgiacomo.gabrielli@arm.com assert(_sc_mod); 10210037SARM gem5 Developers return _sc_mod; 10310037SARM gem5 Developers } 10413599Sgiacomo.travaglini@arm.com 10513599Sgiacomo.travaglini@arm.com void 10613599Sgiacomo.travaglini@arm.com sc_mod(sc_core::sc_module *sc_mod) 10713599Sgiacomo.travaglini@arm.com { 10812477SCurtis.Dunham@arm.com assert(!_sc_mod); 10910037SARM gem5 Developers _sc_mod = sc_mod; 11010037SARM gem5 Developers } 1119384SAndreas.Sandberg@arm.com 1129384SAndreas.Sandberg@arm.com Object * 1139384SAndreas.Sandberg@arm.com obj() 11412479SCurtis.Dunham@arm.com { 11512479SCurtis.Dunham@arm.com assert(_obj); 1169384SAndreas.Sandberg@arm.com return _obj; 1179384SAndreas.Sandberg@arm.com } 1189384SAndreas.Sandberg@arm.com 1199384SAndreas.Sandberg@arm.com void pop(); 1209384SAndreas.Sandberg@arm.com 1219384SAndreas.Sandberg@arm.com const char *uniqueName(const char *seed) { return nameGen.gen(seed); } 1227427Sgblack@eecs.umich.edu 1237427Sgblack@eecs.umich.edu void bindPorts(std::vector<const ::sc_core::sc_bind_proxy *> &proxies); 1247427Sgblack@eecs.umich.edu 1259385SAndreas.Sandberg@arm.com std::vector<::sc_core::sc_port_base *> ports; 1269385SAndreas.Sandberg@arm.com std::vector<::sc_core::sc_export_base *> exports; 1277427Sgblack@eecs.umich.edu 1287427Sgblack@eecs.umich.edu int bindingIndex; 12910037SARM gem5 Developers 13013114Sgiacomo.travaglini@arm.com void beforeEndOfElaboration(); 13110037SARM gem5 Developers void endOfElaboration(); 13213114Sgiacomo.travaglini@arm.com void startOfSimulation(); 13313114Sgiacomo.travaglini@arm.com void endOfSimulation(); 13413114Sgiacomo.travaglini@arm.com}; 13513114Sgiacomo.travaglini@arm.com 13613114Sgiacomo.travaglini@arm.comModule *currentModule(); 13712690Sgiacomo.travaglini@arm.comModule *newModuleChecked(); 13810037SARM gem5 DevelopersModule *newModule(); 1397427Sgblack@eecs.umich.edu 1407427Sgblack@eecs.umich.edustatic inline Module * 14110037SARM gem5 DeveloperspickParentModule() 1427427Sgblack@eecs.umich.edu{ 1437427Sgblack@eecs.umich.edu ::sc_core::sc_object *obj = pickParentObj(); 1447427Sgblack@eecs.umich.edu auto mod = dynamic_cast<::sc_core::sc_module *>(obj); 1457427Sgblack@eecs.umich.edu if (!mod) 1467427Sgblack@eecs.umich.edu return nullptr; 1477427Sgblack@eecs.umich.edu return Module::fromScModule(mod); 1487427Sgblack@eecs.umich.edu} 1497427Sgblack@eecs.umich.edustatic inline void 1507427Sgblack@eecs.umich.edupushParentModule(Module *m) 1517427Sgblack@eecs.umich.edu{ 1527427Sgblack@eecs.umich.edu pushParentObj(m->obj()->sc_obj()); 1537427Sgblack@eecs.umich.edu} 1547427Sgblack@eecs.umich.edustatic inline void 1557427Sgblack@eecs.umich.edupopParentModule() 1567427Sgblack@eecs.umich.edu{ 1577427Sgblack@eecs.umich.edu assert(pickParentModule()); 1587427Sgblack@eecs.umich.edu popParentObj(); 1597427Sgblack@eecs.umich.edu} 1607427Sgblack@eecs.umich.edu 1617427Sgblack@eecs.umich.eduextern std::list<Module *> allModules; 1627427Sgblack@eecs.umich.edu 1637427Sgblack@eecs.umich.edu} // namespace sc_gem5 1647427Sgblack@eecs.umich.edu 1657436Sdam.sunwoo@arm.com#endif //__SYSTEMC_CORE_MODULE_HH__ 1667436Sdam.sunwoo@arm.com