phase.hh revision 13521
113521Sgabeblack@google.com/***************************************************************************** 213521Sgabeblack@google.com 313521Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 413521Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 513521Sgabeblack@google.com with this work for additional information regarding copyright ownership. 613521Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 713521Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 813521Sgabeblack@google.com License. You may obtain a copy of the License at 913521Sgabeblack@google.com 1013521Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1113521Sgabeblack@google.com 1213521Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1313521Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1413521Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1513521Sgabeblack@google.com implied. See the License for the specific language governing 1613521Sgabeblack@google.com permissions and limitations under the License. 1713521Sgabeblack@google.com 1813521Sgabeblack@google.com *****************************************************************************/ 1913521Sgabeblack@google.com 2013521Sgabeblack@google.com#ifndef __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_PHASE_HH__ 2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_PHASE_HH__ 2213521Sgabeblack@google.com 2313521Sgabeblack@google.com#include <iostream> 2413521Sgabeblack@google.com#include <typeinfo> 2513521Sgabeblack@google.com#include <vector> 2613521Sgabeblack@google.com 2713521Sgabeblack@google.com#define SC_CONCAT_HELPER_(a, b) SC_CONCAT_HELPER_DEFERRED_(a, b) 2813521Sgabeblack@google.com#define SC_CONCAT_HELPER_DEFERRED_(a, b) SC_CONCAT_HELPER_MORE_DEFERRED_(a, b) 2913521Sgabeblack@google.com#define SC_CONCAT_HELPER_MORE_DEFERRED_(a, b) a ## b 3013521Sgabeblack@google.com 3113521Sgabeblack@google.com#define SC_STRINGIFY_HELPER_(a) SC_STRINGIFY_HELPER_DEFERRED_(a) 3213521Sgabeblack@google.com#define SC_STRINGIFY_HELPER_DEFERRED_(a) SC_STRINGIFY_HELPER_MORE_DEFERRED_(a) 3313521Sgabeblack@google.com#define SC_STRINGIFY_HELPER_MORE_DEFERRED_(a) #a 3413521Sgabeblack@google.com 3513521Sgabeblack@google.comnamespace tlm 3613521Sgabeblack@google.com{ 3713521Sgabeblack@google.com 3813521Sgabeblack@google.comenum tlm_phase_enum 3913521Sgabeblack@google.com{ 4013521Sgabeblack@google.com UNINITIALIZED_PHASE = 0, 4113521Sgabeblack@google.com BEGIN_REQ = 1, 4213521Sgabeblack@google.com END_REQ, 4313521Sgabeblack@google.com BEGIN_RESP, 4413521Sgabeblack@google.com END_RESP 4513521Sgabeblack@google.com}; 4613521Sgabeblack@google.com 4713521Sgabeblack@google.comclass tlm_phase 4813521Sgabeblack@google.com{ 4913521Sgabeblack@google.com public: 5013521Sgabeblack@google.com tlm_phase(); 5113521Sgabeblack@google.com tlm_phase(unsigned int id); 5213521Sgabeblack@google.com 5313521Sgabeblack@google.com tlm_phase(tlm_phase_enum standard); 5413521Sgabeblack@google.com tlm_phase &operator = (tlm_phase_enum standard); 5513521Sgabeblack@google.com 5613521Sgabeblack@google.com operator unsigned int() const { return m_id; } 5713521Sgabeblack@google.com const char *get_name() const; 5813521Sgabeblack@google.com 5913521Sgabeblack@google.com protected: 6013521Sgabeblack@google.com // Register extended phase. 6113521Sgabeblack@google.com tlm_phase(const std::type_info &type, const char *name); 6213521Sgabeblack@google.com 6313521Sgabeblack@google.com private: 6413521Sgabeblack@google.com unsigned int m_id; 6513521Sgabeblack@google.com}; 6613521Sgabeblack@google.com 6713521Sgabeblack@google.cominline tlm_phase::tlm_phase() : m_id(UNINITIALIZED_PHASE) {} 6813521Sgabeblack@google.com 6913521Sgabeblack@google.cominline tlm_phase::tlm_phase(tlm_phase_enum standard) : m_id(standard) {} 7013521Sgabeblack@google.com 7113521Sgabeblack@google.cominline tlm_phase & 7213521Sgabeblack@google.comtlm_phase::operator = (tlm_phase_enum standard) 7313521Sgabeblack@google.com{ 7413521Sgabeblack@google.com m_id = standard; 7513521Sgabeblack@google.com return *this; 7613521Sgabeblack@google.com} 7713521Sgabeblack@google.com 7813521Sgabeblack@google.cominline std::ostream & 7913521Sgabeblack@google.comoperator << (std::ostream &s, const tlm_phase &p) 8013521Sgabeblack@google.com{ 8113521Sgabeblack@google.com s << p.get_name(); 8213521Sgabeblack@google.com return s; 8313521Sgabeblack@google.com} 8413521Sgabeblack@google.com 8513521Sgabeblack@google.com#define TLM_DECLARE_EXTENDED_PHASE(name_arg) \ 8613521Sgabeblack@google.comstatic class SC_CONCAT_HELPER_(tlm_phase_, name_arg) : \ 8713521Sgabeblack@google.com public ::tlm::tlm_phase \ 8813521Sgabeblack@google.com{ \ 8913521Sgabeblack@google.com typedef SC_CONCAT_HELPER_(tlm_phase_, name_arg) this_type; \ 9013521Sgabeblack@google.com public: \ 9113521Sgabeblack@google.com SC_CONCAT_HELPER_(tlm_phase_, name_arg)() : \ 9213521Sgabeblack@google.com /* register extended phase */ \ 9313521Sgabeblack@google.com ::tlm::tlm_phase(typeid(*this), SC_STRINGIFY_HELPER_(name_arg)) \ 9413521Sgabeblack@google.com {} \ 9513521Sgabeblack@google.com \ 9613521Sgabeblack@google.com static const this_type &get_phase() \ 9713521Sgabeblack@google.com /* needed only for IEEE 1666-2011 */ \ 9813521Sgabeblack@google.com { \ 9913521Sgabeblack@google.com static this_type this_; \ 10013521Sgabeblack@google.com return this_; \ 10113521Sgabeblack@google.com } \ 10213521Sgabeblack@google.com} const name_arg 10313521Sgabeblack@google.com 10413521Sgabeblack@google.com// for backwards-compatibility 10513521Sgabeblack@google.com#define DECLARE_EXTENDED_PHASE(NameArg) TLM_DECLARE_EXTENDED_PHASE(NameArg) 10613521Sgabeblack@google.com 10713521Sgabeblack@google.com} // namespace tlm 10813521Sgabeblack@google.com 10913521Sgabeblack@google.com#undef SC_CONCAT_HELPER_ 11013521Sgabeblack@google.com#undef SC_CONCAT_HELPER_DEFERRED_ 11113521Sgabeblack@google.com#undef SC_CONCAT_HELPER_MORE_DEFERRED_ 11213521Sgabeblack@google.com 11313521Sgabeblack@google.com#undef SC_STRINGIFY_HELPER_ 11413521Sgabeblack@google.com#undef SC_STRINGIFY_HELPER_DEFERRED_ 11513521Sgabeblack@google.com#undef SC_STRINGIFY_HELPER_MORE_DEFERRED_ 11613521Sgabeblack@google.com 11713521Sgabeblack@google.com#endif /* __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_PHASE_HH__ */ 118