sc_export.cc revision 13268
110259SAndrew.Bardsley@arm.com/* 210259SAndrew.Bardsley@arm.com * Copyright 2018 Google, Inc. 310259SAndrew.Bardsley@arm.com * 410259SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without 510259SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are 610259SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright 710259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer; 810259SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright 910259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the 1010259SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution; 1110259SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its 1210259SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from 1310259SAndrew.Bardsley@arm.com * this software without specific prior written permission. 1410259SAndrew.Bardsley@arm.com * 1510259SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1610259SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1710259SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1810259SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1910259SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2010259SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2110259SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2210259SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2310259SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2410259SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2510259SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2610259SAndrew.Bardsley@arm.com * 2710259SAndrew.Bardsley@arm.com * Authors: Gabe Black 2810259SAndrew.Bardsley@arm.com */ 2910259SAndrew.Bardsley@arm.com 3010259SAndrew.Bardsley@arm.com#include "base/logging.hh" 3110259SAndrew.Bardsley@arm.com#include "systemc/core/module.hh" 3210259SAndrew.Bardsley@arm.com#include "systemc/core/scheduler.hh" 3310259SAndrew.Bardsley@arm.com#include "systemc/ext/core/sc_export.hh" 3410259SAndrew.Bardsley@arm.com#include "systemc/ext/core/sc_main.hh" 3510259SAndrew.Bardsley@arm.com 3610259SAndrew.Bardsley@arm.comnamespace sc_core 3710259SAndrew.Bardsley@arm.com{ 3810259SAndrew.Bardsley@arm.com 3910259SAndrew.Bardsley@arm.comnamespace 4010259SAndrew.Bardsley@arm.com{ 4110259SAndrew.Bardsley@arm.com 4210259SAndrew.Bardsley@arm.comvoid 4310259SAndrew.Bardsley@arm.comreportError(const char *id, const char *add_msg, 4410259SAndrew.Bardsley@arm.com const char *name, const char *kind) 4510259SAndrew.Bardsley@arm.com{ 4610259SAndrew.Bardsley@arm.com std::string msg; 4710259SAndrew.Bardsley@arm.com if (add_msg) 4810259SAndrew.Bardsley@arm.com msg = csprintf("%s: export '%s' (%s)", add_msg, name, kind); 4910259SAndrew.Bardsley@arm.com else 5010259SAndrew.Bardsley@arm.com msg = csprintf("export '%s' (%s)", name, kind); 5110259SAndrew.Bardsley@arm.com 5210259SAndrew.Bardsley@arm.com SC_REPORT_ERROR(id, msg.c_str()); 5311800Sbrandon.potter@amd.com} 5411800Sbrandon.potter@amd.com 5510259SAndrew.Bardsley@arm.com} 5610259SAndrew.Bardsley@arm.com 5710259SAndrew.Bardsley@arm.comsc_export_base::sc_export_base(const char *n) : sc_object(n) 5810259SAndrew.Bardsley@arm.com{ 5910259SAndrew.Bardsley@arm.com if (sc_is_running()) { 6010905Sandreas.sandberg@arm.com reportError("(E121) insert sc_export failed", "simulation running", 6110259SAndrew.Bardsley@arm.com name(), kind()); 6210259SAndrew.Bardsley@arm.com } 6310259SAndrew.Bardsley@arm.com if (::sc_gem5::scheduler.elaborationDone()) { 6410259SAndrew.Bardsley@arm.com reportError("(E121) insert sc_export failed", "elaboration done", 6510259SAndrew.Bardsley@arm.com name(), kind()); 6610259SAndrew.Bardsley@arm.com } 6710259SAndrew.Bardsley@arm.com 6810259SAndrew.Bardsley@arm.com auto m = sc_gem5::pickParentModule(); 6910259SAndrew.Bardsley@arm.com if (!m) { 7010259SAndrew.Bardsley@arm.com reportError("(E122) sc_export specified outside of module", 7110259SAndrew.Bardsley@arm.com nullptr, name(), kind()); 7210259SAndrew.Bardsley@arm.com } else { 7310259SAndrew.Bardsley@arm.com m->exports.push_back(this); 7410259SAndrew.Bardsley@arm.com } 7510259SAndrew.Bardsley@arm.com} 7610259SAndrew.Bardsley@arm.comsc_export_base::~sc_export_base() {} 7710259SAndrew.Bardsley@arm.com 7810259SAndrew.Bardsley@arm.com} // namespace sc_core 7910259SAndrew.Bardsley@arm.com