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 #ifndef TLM_CORE_TLM2_TLM_PHASE_H_INCLUDED_
21 #define TLM_CORE_TLM2_TLM_PHASE_H_INCLUDED_
22 
23 #include <string>
24 #include <iostream>
25 #include <typeinfo>
26 #include <vector>
27 
28 #include "sysc/kernel/sc_cmnhdr.h" // SC_API
29 #include "sysc/kernel/sc_macros.h" // SC_CONCAT_HELPER_, SC_STRINGIFY_HELPER_
30 
31 namespace tlm {
32 
33 enum SC_API tlm_phase_enum
34 {
35   UNINITIALIZED_PHASE=0,
36   BEGIN_REQ=1,
37   END_REQ,
38   BEGIN_RESP,
39   END_RESP
40 };
41 
42 class SC_API tlm_phase
43 {
44 public:
45   tlm_phase();
46   tlm_phase(unsigned int id); // TODO: should be dropped
47 
48   tlm_phase(tlm_phase_enum standard);
49   tlm_phase& operator=(tlm_phase_enum standard);
50 
51   operator unsigned int() const { return m_id; }
52   const char* get_name() const;
53 
54 protected:
55   // register extended phase
56   tlm_phase( const std::type_info & type, const char* name );
57 
58 private:
59   unsigned int m_id;
60 };
61 
62 inline
tlm_phase()63 tlm_phase::tlm_phase()
64   : m_id( UNINITIALIZED_PHASE )
65 {}
66 
67 inline
tlm_phase(tlm_phase_enum standard)68 tlm_phase::tlm_phase( tlm_phase_enum standard )
69   : m_id( standard )
70 {}
71 
72 inline
73 tlm_phase& tlm_phase::operator=( tlm_phase_enum standard )
74 {
75   m_id = standard;
76   return *this;
77 }
78 
79 inline
80 std::ostream& operator<<(std::ostream& s, const tlm_phase& p)
81 {
82   s << p.get_name();
83   return s;
84 }
85 
86 #define TLM_DECLARE_EXTENDED_PHASE(name_arg) \
87   static class SC_CONCAT_HELPER_(tlm_phase_, name_arg) \
88     : public ::tlm::tlm_phase \
89   { \
90     typedef SC_CONCAT_HELPER_(tlm_phase_, name_arg) this_type; \
91   public: \
92     SC_CONCAT_HELPER_(tlm_phase_, name_arg)() /* register extended phase */ \
93       : ::tlm::tlm_phase( typeid(*this), SC_STRINGIFY_HELPER_(name_arg) ) \
94     {} \
95     \
96     static const this_type& get_phase() /* needed only for IEEE 1666-2011 */ \
97       { static this_type this_; return this_; } \
98   } \
99   const name_arg
100 
101 // for backwards-compatibility
102 #define DECLARE_EXTENDED_PHASE( NameArg ) \
103     TLM_DECLARE_EXTENDED_PHASE( NameArg )
104 
105 } // namespace tlm
106 
107 #endif /* TLM_CORE_TLM2_TLM_PHASE_H_INCLUDED_ */
108 // Taf!
109