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
22  sc_spawn_options.cpp -- Process spawning options implementation.
23
24  Original Authors: Andy Goodrich, Forte Design Systems, 17 June 2003
25                    Stuart Swan, Cadence,
26                    Bishnupriya Bhattacharya, Cadence Design Systems,
27                    25 August, 2003
28
29  CHANGE LOG AT THE END OF THE FILE
30 *****************************************************************************/
31
32#include "sysc/kernel/sc_spawn_options.h"
33#include "sysc/kernel/sc_reset.h"
34
35namespace sc_core {
36
37// +======================================================================
38// | CLASS sc_spawn_reset_base - Class to do a generic access to an
39// |                             sc_spawn_rest object instance
40// +======================================================================
41class sc_spawn_reset_base
42{
43  public:
44    sc_spawn_reset_base( bool async, bool level )
45      : m_async( async ), m_level(level)
46    {}
47    virtual ~sc_spawn_reset_base() {}
48    virtual void specify_reset() = 0;
49
50  protected:
51    bool m_async;   // = true if async reset.
52    bool m_level;   // level indicating reset.
53};
54
55// +======================================================================
56// | CLASS sc_spawn_reset<SOURCE>
57// |  - Reset specification for sc_spawn_options.
58// +======================================================================
59template<typename SOURCE>
60class sc_spawn_reset : public sc_spawn_reset_base
61{
62  public:
63    sc_spawn_reset( bool async, const SOURCE& source, bool level )
64      : sc_spawn_reset_base(async, level), m_source(source)
65    {}
66    virtual ~sc_spawn_reset() {}
67    virtual void specify_reset()
68    {
69        sc_reset::reset_signal_is( m_async, m_source, m_level );
70    }
71
72  protected:
73    const SOURCE& m_source; // source of reset signal.
74};
75
76// +======================================================================
77// | CLASS sc_spawn_options (implementation)
78// |
79// +======================================================================
80
81sc_spawn_options::~sc_spawn_options()
82{
83    std::vector<sc_spawn_reset_base*>::size_type resets_n = m_resets.size();
84    for ( std::vector<sc_spawn_reset_base*>::size_type reset_i = 0; reset_i < resets_n; reset_i++ )
85        delete m_resets[reset_i];
86}
87
88#define SC_DEFINE_RESET_SIGNALS( Port )                       \
89  /* asynchronous reset */                                    \
90  void                                                        \
91  sc_spawn_options::                                          \
92    async_reset_signal_is ( const Port & port, bool level )   \
93    {                                                         \
94        m_resets.push_back(                                   \
95            new sc_spawn_reset< Port >(true, port, level) );  \
96    }                                                         \
97  /* sync reset */                                            \
98  void                                                        \
99  sc_spawn_options::                                          \
100    reset_signal_is ( const Port & port, bool level )         \
101    {                                                         \
102        m_resets.push_back(                                   \
103            new sc_spawn_reset< Port >(false, port, level) ); \
104    }
105
106SC_DEFINE_RESET_SIGNALS( sc_in<bool> )
107SC_DEFINE_RESET_SIGNALS( sc_inout<bool> )
108SC_DEFINE_RESET_SIGNALS( sc_out<bool> )
109SC_DEFINE_RESET_SIGNALS( sc_signal_in_if<bool> )
110
111#undef SC_DEFINE_RESET_SIGNALS
112
113void
114sc_spawn_options::specify_resets() const
115{
116    std::vector<sc_spawn_reset_base*>::size_type resets_n; // number of reset specifications to process.
117    resets_n = m_resets.size();
118    for ( std::vector<sc_spawn_reset_base*>::size_type reset_i = 0; reset_i < resets_n; reset_i++ )
119        m_resets[reset_i]->specify_reset();
120}
121
122} // namespace sc_core
123
124// Taf!
125