113271Sgabeblack@google.com/*****************************************************************************
213271Sgabeblack@google.com
313271Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
413271Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
513271Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
613271Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
713271Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
813271Sgabeblack@google.com  License.  You may obtain a copy of the License at
913271Sgabeblack@google.com
1013271Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1113271Sgabeblack@google.com
1213271Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1313271Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1413271Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1513271Sgabeblack@google.com  implied.  See the License for the specific language governing
1613271Sgabeblack@google.com  permissions and limitations under the License.
1713271Sgabeblack@google.com
1813271Sgabeblack@google.com *****************************************************************************/
1913271Sgabeblack@google.com
2012852Sgabeblack@google.com/*
2112852Sgabeblack@google.com * Copyright 2018 Google, Inc.
2212852Sgabeblack@google.com *
2312852Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
2412852Sgabeblack@google.com * modification, are permitted provided that the following conditions are
2512852Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
2612852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
2712852Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
2812852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2912852Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
3012852Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
3112852Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
3212852Sgabeblack@google.com * this software without specific prior written permission.
3312852Sgabeblack@google.com *
3412852Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3512852Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3612852Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3712852Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3812852Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3912852Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4012852Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4112852Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4212852Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4312852Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4412852Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4512852Sgabeblack@google.com *
4612852Sgabeblack@google.com * Authors: Gabe Black
4712852Sgabeblack@google.com */
4812852Sgabeblack@google.com
4913271Sgabeblack@google.com#include <sstream>
5013271Sgabeblack@google.com
5113271Sgabeblack@google.com#include "base/cprintf.hh"
5213271Sgabeblack@google.com#include "systemc/core/object.hh"
5313322Sgabeblack@google.com#include "systemc/ext/utils/messages.hh"
5413271Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
5512852Sgabeblack@google.com#include "systemc/ext/utils/sc_vector.hh"
5612852Sgabeblack@google.com
5712852Sgabeblack@google.comnamespace sc_core
5812852Sgabeblack@google.com{
5912852Sgabeblack@google.com
6013271Sgabeblack@google.comsc_vector_base::size_type sc_vector_base::size() const { return objs.size(); }
6112852Sgabeblack@google.com
6212852Sgabeblack@google.comconst std::vector<sc_object *> &
6312852Sgabeblack@google.comsc_vector_base::get_elements() const
6412852Sgabeblack@google.com{
6513271Sgabeblack@google.com    elements.clear();
6613271Sgabeblack@google.com    for (auto ptr: objs) {
6713271Sgabeblack@google.com        sc_object *obj_ptr = objectCast(ptr);
6813271Sgabeblack@google.com        if (obj_ptr)
6913271Sgabeblack@google.com            elements.push_back(obj_ptr);
7013271Sgabeblack@google.com    }
7113271Sgabeblack@google.com    return elements;
7213271Sgabeblack@google.com}
7313271Sgabeblack@google.com
7413271Sgabeblack@google.comvoid
7513271Sgabeblack@google.comsc_vector_base::checkIndex(size_type index) const
7613271Sgabeblack@google.com{
7713271Sgabeblack@google.com    if (index >= size()) {
7813271Sgabeblack@google.com        std::ostringstream ss;
7913271Sgabeblack@google.com        ccprintf(ss, "%s[%d] >= size() = %d", name(), index, size());
8013322Sgabeblack@google.com        SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, ss.str().c_str());
8113271Sgabeblack@google.com        sc_abort();
8213271Sgabeblack@google.com    }
8313271Sgabeblack@google.com}
8413271Sgabeblack@google.com
8513271Sgabeblack@google.comvoid
8613271Sgabeblack@google.comsc_vector_base::forceParent() const
8713271Sgabeblack@google.com{
8813271Sgabeblack@google.com    sc_gem5::pushParentObj(get_parent_object());
8913271Sgabeblack@google.com}
9013271Sgabeblack@google.com
9113271Sgabeblack@google.comvoid
9213271Sgabeblack@google.comsc_vector_base::unforceParent() const
9313271Sgabeblack@google.com{
9413271Sgabeblack@google.com    sc_gem5::popParentObj();
9513271Sgabeblack@google.com}
9613271Sgabeblack@google.com
9713271Sgabeblack@google.comvoid
9813271Sgabeblack@google.comsc_vector_base::reportEmpty(const char *kind_, bool empty_dest) const
9913271Sgabeblack@google.com{
10013271Sgabeblack@google.com    std::ostringstream ss;
10113271Sgabeblack@google.com
10213271Sgabeblack@google.com    ss << "target `" << name() << "' " << "(" << kind_ << ") ";
10313271Sgabeblack@google.com
10413271Sgabeblack@google.com    if (!size())
10513271Sgabeblack@google.com        ss << "not initialised yet";
10613271Sgabeblack@google.com    else if (empty_dest)
10713271Sgabeblack@google.com        ss << "empty range given";
10813271Sgabeblack@google.com    else
10913271Sgabeblack@google.com        ss << "empty destination range given";
11013271Sgabeblack@google.com
11113322Sgabeblack@google.com    SC_REPORT_WARNING(SC_ID_VECTOR_BIND_EMPTY_, ss.str().c_str());
11212852Sgabeblack@google.com}
11312852Sgabeblack@google.com
11412852Sgabeblack@google.com} // namespace sc_core
115