112950Sgabeblack@google.com/*
212950Sgabeblack@google.com * Copyright 2018 Google, Inc.
312950Sgabeblack@google.com *
412950Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512950Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612950Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712950Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812950Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912950Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012950Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112950Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212950Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312950Sgabeblack@google.com * this software without specific prior written permission.
1412950Sgabeblack@google.com *
1512950Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612950Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712950Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812950Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912950Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012950Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112950Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212950Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312950Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412950Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512950Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612950Sgabeblack@google.com *
2712950Sgabeblack@google.com * Authors: Gabe Black
2812950Sgabeblack@google.com */
2912950Sgabeblack@google.com
3012950Sgabeblack@google.com#ifndef __SYSTEMC_CORE_OBJECT_HH__
3112950Sgabeblack@google.com#define __SYSTEMC_CORE_OBJECT_HH__
3212950Sgabeblack@google.com
3312950Sgabeblack@google.com#include <string>
3412950Sgabeblack@google.com#include <vector>
3512950Sgabeblack@google.com
3612950Sgabeblack@google.com#include "systemc/ext/core/sc_attr.hh"
3712950Sgabeblack@google.com#include "systemc/ext/core/sc_object.hh"
3812950Sgabeblack@google.com
3912950Sgabeblack@google.comnamespace sc_gem5
4012950Sgabeblack@google.com{
4112950Sgabeblack@google.com
4212950Sgabeblack@google.comclass Object;
4312950Sgabeblack@google.com
4412950Sgabeblack@google.comtypedef std::vector<sc_core::sc_object *> Objects;
4512950Sgabeblack@google.comtypedef std::vector<sc_core::sc_event *> Events;
4612950Sgabeblack@google.comtypedef Objects::iterator ObjectsIt;
4712955Sgabeblack@google.comtypedef Events::iterator EventsIt;
4812950Sgabeblack@google.com
4912950Sgabeblack@google.comclass Object
5012950Sgabeblack@google.com{
5112950Sgabeblack@google.com  public:
5212955Sgabeblack@google.com    Object(sc_core::sc_object *_sc_obj);
5312955Sgabeblack@google.com    Object(sc_core::sc_object *_sc_obj, const char *);
5412955Sgabeblack@google.com    Object(sc_core::sc_object *_sc_obj, const Object &);
5512950Sgabeblack@google.com    Object &operator = (const Object &);
5612950Sgabeblack@google.com
5712950Sgabeblack@google.com    virtual ~Object();
5812950Sgabeblack@google.com
5912950Sgabeblack@google.com    /*
6012950Sgabeblack@google.com     * sc_object methods.
6112950Sgabeblack@google.com     */
6212950Sgabeblack@google.com    const char *name() const;
6312950Sgabeblack@google.com    const char *basename() const;
6412950Sgabeblack@google.com
6512950Sgabeblack@google.com    void print(std::ostream & =std::cout) const;
6612950Sgabeblack@google.com    void dump(std::ostream & =std::cout) const;
6712950Sgabeblack@google.com
6812950Sgabeblack@google.com    const std::vector<sc_core::sc_object *> &get_child_objects() const;
6912950Sgabeblack@google.com    const std::vector<sc_core::sc_event *> &get_child_events() const;
7012950Sgabeblack@google.com    sc_core::sc_object *get_parent_object() const;
7112950Sgabeblack@google.com
7212950Sgabeblack@google.com    bool add_attribute(sc_core::sc_attr_base &);
7312950Sgabeblack@google.com    sc_core::sc_attr_base *get_attribute(const std::string &);
7412950Sgabeblack@google.com    sc_core::sc_attr_base *remove_attribute(const std::string &);
7512950Sgabeblack@google.com    void remove_all_attributes();
7612950Sgabeblack@google.com    int num_attributes() const;
7712950Sgabeblack@google.com    sc_core::sc_attr_cltn &attr_cltn();
7812950Sgabeblack@google.com    const sc_core::sc_attr_cltn &attr_cltn() const;
7912950Sgabeblack@google.com
8012950Sgabeblack@google.com    sc_core::sc_simcontext *simcontext() const;
8112950Sgabeblack@google.com
8212955Sgabeblack@google.com    static Object *
8312955Sgabeblack@google.com    getFromScObject(sc_core::sc_object *sc_obj)
8412955Sgabeblack@google.com    {
8512955Sgabeblack@google.com        return sc_obj->_gem5_object;
8612955Sgabeblack@google.com    }
8712955Sgabeblack@google.com
8812955Sgabeblack@google.com    sc_core::sc_object *sc_obj() { return _sc_obj; }
8912955Sgabeblack@google.com
9012955Sgabeblack@google.com    EventsIt addChildEvent(sc_core::sc_event *e);
9112988Sgabeblack@google.com    void delChildEvent(sc_core::sc_event *e);
9212955Sgabeblack@google.com
9313179Sgabeblack@google.com    std::string pickUniqueName(std::string name);
9413127Sgabeblack@google.com
9512950Sgabeblack@google.com  private:
9612955Sgabeblack@google.com    sc_core::sc_object *_sc_obj;
9712950Sgabeblack@google.com
9812950Sgabeblack@google.com    std::string _basename;
9912950Sgabeblack@google.com    std::string _name;
10012950Sgabeblack@google.com
10112950Sgabeblack@google.com    Objects children;
10212950Sgabeblack@google.com    Events events;
10312950Sgabeblack@google.com    sc_core::sc_object *parent;
10412950Sgabeblack@google.com
10512950Sgabeblack@google.com    sc_core::sc_attr_cltn cltn;
10612950Sgabeblack@google.com};
10712950Sgabeblack@google.com
10813179Sgabeblack@google.comstd::string pickUniqueName(::sc_core::sc_object *parent, std::string name);
10913127Sgabeblack@google.com
11012950Sgabeblack@google.comextern Objects topLevelObjects;
11112950Sgabeblack@google.comextern Objects allObjects;
11212950Sgabeblack@google.com
11312950Sgabeblack@google.comsc_core::sc_object *findObject(
11412950Sgabeblack@google.com        const char *name, const Objects &objects=topLevelObjects);
11512950Sgabeblack@google.com
11613268Sgabeblack@google.comsc_core::sc_object *pickParentObj();
11713268Sgabeblack@google.comvoid pushParentObj(sc_core::sc_object *obj);
11813268Sgabeblack@google.comvoid popParentObj();
11913268Sgabeblack@google.com
12012950Sgabeblack@google.com} // namespace sc_gem5
12112950Sgabeblack@google.com
12212950Sgabeblack@google.com#endif  //__SYSTEMC_CORE_OBJECT_HH__
123