sc_vector.cc revision 13271:f001f9287ba3
14479Sbinkertn@umich.edu/*****************************************************************************
24479Sbinkertn@umich.edu
34479Sbinkertn@umich.edu  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
44479Sbinkertn@umich.edu  more contributor license agreements.  See the NOTICE file distributed
54479Sbinkertn@umich.edu  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/sc_report_handler.hh"
54#include "systemc/ext/utils/sc_vector.hh"
55
56namespace sc_core
57{
58
59sc_vector_base::size_type sc_vector_base::size() const { return objs.size(); }
60
61const std::vector<sc_object *> &
62sc_vector_base::get_elements() const
63{
64    elements.clear();
65    for (auto ptr: objs) {
66        sc_object *obj_ptr = objectCast(ptr);
67        if (obj_ptr)
68            elements.push_back(obj_ptr);
69    }
70    return elements;
71}
72
73void
74sc_vector_base::checkIndex(size_type index) const
75{
76    if (index >= size()) {
77        std::ostringstream ss;
78        ccprintf(ss, "%s[%d] >= size() = %d", name(), index, size());
79        SC_REPORT_ERROR("(E5) out of bounds", ss.str().c_str());
80        sc_abort();
81    }
82}
83
84void
85sc_vector_base::forceParent() const
86{
87    sc_gem5::pushParentObj(get_parent_object());
88}
89
90void
91sc_vector_base::unforceParent() const
92{
93    sc_gem5::popParentObj();
94}
95
96void
97sc_vector_base::reportEmpty(const char *kind_, bool empty_dest) const
98{
99    std::ostringstream ss;
100
101    ss << "target `" << name() << "' " << "(" << kind_ << ") ";
102
103    if (!size())
104        ss << "not initialised yet";
105    else if (empty_dest)
106        ss << "empty range given";
107    else
108        ss << "empty destination range given";
109
110    SC_REPORT_WARNING("(W807) sc_vector::bind called with empty range",
111            ss.str().c_str());
112}
113
114} // namespace sc_core
115