TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_phase.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 #ifndef __TLM_PHASE_H__
19 #define __TLM_PHASE_H__
20 
21 #include <string>
22 #include <iostream>
23 #include <vector>
24 
25 namespace tlm {
26 
27 //enum tlm_phase { BEGIN_REQ, END_REQ, BEGIN_RESP, END_RESP };
28 
30 
31 inline unsigned int create_phase_number(){
32  static unsigned int number=END_RESP+1;
33  return number++;
34 }
35 
36 inline std::vector<const char*>& get_phase_name_vec(){
37  static std::vector<const char*> phase_name_vec(END_RESP+1, (const char*)NULL);
38  return phase_name_vec;
39 }
40 
41 class tlm_phase{
42 public:
43  tlm_phase(): m_id(0) {}
44  tlm_phase(unsigned int id): m_id(id){}
45  tlm_phase(const tlm_phase_enum& standard): m_id((unsigned int) standard){}
46  tlm_phase& operator=(const tlm_phase_enum& standard){m_id=(unsigned int)standard; return *this;}
47  operator unsigned int() const{return m_id;}
48 
49 private:
50  unsigned int m_id;
51 };
52 
53 inline
54 std::ostream& operator<<(std::ostream& s, const tlm_phase& p){
55  switch ((unsigned int)p){
56  case UNINITIALIZED_PHASE: s<<"UNINITIALIZED_PHASE"; break;
57  case BEGIN_REQ: s<<"BEGIN_REQ"; break;
58  case END_REQ: s<<"END_REQ"; break;
59  case BEGIN_RESP: s<<"BEGIN_RESP"; break;
60  case END_RESP: s<<"END_RESP"; break;
61  default:
62  s<<get_phase_name_vec()[(unsigned int)p]; return s;
63  }
64  return s;
65 }
66 
67 #define TLM_DECLARE_EXTENDED_PHASE(name_arg) \
68 class tlm_phase_##name_arg:public tlm::tlm_phase{ \
69 public:\
70 static const tlm_phase_##name_arg& get_phase(){static tlm_phase_##name_arg tmp; return tmp;}\
71 private:\
72 tlm_phase_##name_arg():tlm::tlm_phase(tlm::create_phase_number()){tlm::get_phase_name_vec().push_back(get_char_##name_arg());};\
73 tlm_phase_##name_arg(const tlm_phase_##name_arg&); \
74 tlm_phase_##name_arg& operator=(const tlm_phase_##name_arg&); \
75 static inline const char* get_char_##name_arg(){static const char* tmp=#name_arg; return tmp;} \
76 }; \
77 static const tlm_phase_##name_arg& name_arg=tlm_phase_##name_arg::get_phase()
78 
79 // for backwards-compatibility
80 #define DECLARE_EXTENDED_PHASE(NameArg) \
81  TLM_DECLARE_EXTENDED_PHASE( NameArg )
82 
83 } // namespace tlm
84 
85 #endif /* TLM_PHASE_HEADER */
tlm_phase_enum
Definition: tlm_phase.h:29
tlm_phase(unsigned int id)
Definition: tlm_phase.h:44
tlm_phase(const tlm_phase_enum &standard)
Definition: tlm_phase.h:45
tlm_phase & operator=(const tlm_phase_enum &standard)
Definition: tlm_phase.h:46
unsigned int create_phase_number()
Definition: tlm_phase.h:31
std::ostream & operator<<(std::ostream &s, const tlm_phase &p)
Definition: tlm_phase.h:54
std::vector< const char * > & get_phase_name_vec()
Definition: tlm_phase.h:36