1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/* 21 * Copyright 2018 Google, Inc. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions are 25 * met: redistributions of source code must retain the above copyright 26 * notice, this list of conditions and the following disclaimer; 27 * redistributions in binary form must reproduce the above copyright 28 * notice, this list of conditions and the following disclaimer in the 29 * documentation and/or other materials provided with the distribution; 30 * neither the name of the copyright holders nor the names of its 31 * contributors may be used to endorse or promote products derived from 32 * this software without specific prior written permission. 33 * 34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 * 46 * Authors: Gabe Black 47 */ 48 49#include <sstream> 50 51#include "base/cprintf.hh" 52#include "systemc/core/object.hh" 53#include "systemc/ext/utils/messages.hh" 54#include "systemc/ext/utils/sc_report_handler.hh" 55#include "systemc/ext/utils/sc_vector.hh" 56 57namespace sc_core 58{ 59 60sc_vector_base::size_type sc_vector_base::size() const { return objs.size(); } 61 62const std::vector<sc_object *> & 63sc_vector_base::get_elements() const 64{ 65 elements.clear(); 66 for (auto ptr: objs) { 67 sc_object *obj_ptr = objectCast(ptr); 68 if (obj_ptr) 69 elements.push_back(obj_ptr); 70 } 71 return elements; 72} 73 74void 75sc_vector_base::checkIndex(size_type index) const 76{ 77 if (index >= size()) { 78 std::ostringstream ss; 79 ccprintf(ss, "%s[%d] >= size() = %d", name(), index, size()); 80 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, ss.str().c_str()); 81 sc_abort(); 82 } 83} 84 85void 86sc_vector_base::forceParent() const 87{ 88 sc_gem5::pushParentObj(get_parent_object()); 89} 90 91void 92sc_vector_base::unforceParent() const 93{ 94 sc_gem5::popParentObj(); 95} 96 97void 98sc_vector_base::reportEmpty(const char *kind_, bool empty_dest) const 99{ 100 std::ostringstream ss; 101 102 ss << "target `" << name() << "' " << "(" << kind_ << ") "; 103 104 if (!size()) 105 ss << "not initialised yet"; 106 else if (empty_dest) 107 ss << "empty range given"; 108 else 109 ss << "empty destination range given"; 110 111 SC_REPORT_WARNING(SC_ID_VECTOR_BIND_EMPTY_, ss.str().c_str()); 112} 113 114} // namespace sc_core 115