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