module.hh revision 13053
16145SN/A/* 26145SN/A * Copyright 2018 Google, Inc. 36145SN/A * 46145SN/A * Redistribution and use in source and binary forms, with or without 56145SN/A * modification, are permitted provided that the following conditions are 66145SN/A * met: redistributions of source code must retain the above copyright 76145SN/A * notice, this list of conditions and the following disclaimer; 86145SN/A * redistributions in binary form must reproduce the above copyright 96145SN/A * notice, this list of conditions and the following disclaimer in the 106145SN/A * documentation and/or other materials provided with the distribution; 116145SN/A * neither the name of the copyright holders nor the names of its 126145SN/A * contributors may be used to endorse or promote products derived from 136145SN/A * this software without specific prior written permission. 146145SN/A * 156145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 166145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 176145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 186145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 196145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 206145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 216145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 256145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266145SN/A * 276145SN/A * Authors: Gabe Black 286145SN/A */ 2910441Snilay@cs.wisc.edu 3010441Snilay@cs.wisc.edu#ifndef __SYSTEMC_CORE_MODULE_HH__ 316145SN/A#define __SYSTEMC_CORE_MODULE_HH__ 327039SN/A 337055SN/A#include <cassert> 349171SN/A#include <list> 357055SN/A#include <map> 366145SN/A#include <sstream> 376154SN/A#include <string> 389171SN/A#include <vector> 396145SN/A 407039SN/A#include "systemc/core/object.hh" 417039SN/A#include "systemc/ext/core/sc_module.hh" 427039SN/A 437039SN/Anamespace sc_core 446145SN/A{ 457039SN/A 467039SN/Aclass sc_port_base; 477039SN/A 487039SN/A} // namespace sc_core 497039SN/A 507039SN/Anamespace sc_gem5 516145SN/A{ 529465SN/A 539465SN/Aclass UniqueNameGen 549465SN/A{ 559465SN/A private: 569465SN/A std::map<std::string, int> counts; 579465SN/A std::string buf; 587039SN/A 597055SN/A public: 607039SN/A const char * 617039SN/A gen(std::string seed) 627039SN/A { 636145SN/A std::ostringstream os; 647039SN/A os << seed << "_" << counts[seed]++; 657039SN/A buf = os.str(); 667455SN/A return buf.c_str(); 679499SN/A } 689499SN/A}; 699499SN/A 709499SN/Aclass Module 717039SN/A{ 727055SN/A private: 736145SN/A const char *_name; 747039SN/A sc_core::sc_module *_sc_mod; 757039SN/A Object *_obj; 766145SN/A 777039SN/A UniqueNameGen nameGen; 787039SN/A 797039SN/A public: 806145SN/A 817039SN/A Module(const char *name); 828943SN/A ~Module(); 838943SN/A 848943SN/A void finish(Object *this_obj); 859499SN/A 867455SN/A const char *name() const { return _name; } 877039SN/A 889507SN/A sc_core::sc_module * 897039SN/A sc_mod() const 909465SN/A { 919465SN/A assert(_sc_mod); 929465SN/A return _sc_mod; 939465SN/A } 949465SN/A 959465SN/A void 967055SN/A sc_mod(sc_core::sc_module *sc_mod) 976145SN/A { 986145SN/A assert(!_sc_mod); 997055SN/A _sc_mod = sc_mod; 1007055SN/A } 1016145SN/A 1027039SN/A Object * 1037055SN/A obj() 1047039SN/A { 1056145SN/A assert(_obj); 1067039SN/A return _obj; 10710441Snilay@cs.wisc.edu } 108 109 void pop(); 110 111 const char *uniqueName(const char *seed) { return nameGen.gen(seed); } 112 113 std::vector<::sc_core::sc_port_base *> ports; 114}; 115 116Module *currentModule(); 117Module *newModule(); 118 119void callbackModule(Module *m); 120Module *callbackModule(); 121 122extern std::list<Module *> allModules; 123 124} // namespace sc_gem5 125 126#endif //__SYSTEMC_CORE_MODULE_HH__ 127