sc_writer_policy.h revision 12027
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_writer_policy.h -- The sc_signal<T> writer policy definition 23 24 Original Author: Philipp A: Hartmann, OFFIS 25 26 CHANGE LOG IS AT THE END OF THE FILE 27 *****************************************************************************/ 28 29 30#ifndef SC_WRITER_POLICY_H_INCLUDED_ 31#define SC_WRITER_POLICY_H_INCLUDED_ 32 33#if !defined(SC_DEFAULT_WRITER_POLICY) 34# if defined(SC_NO_WRITE_CHECK) 35# define SC_DEFAULT_WRITER_POLICY SC_UNCHECKED_WRITERS 36# else 37# define SC_DEFAULT_WRITER_POLICY SC_ONE_WRITER 38# endif 39#endif 40 41namespace sc_core { 42 43class sc_object; 44class sc_port_base; 45extern 46void 47sc_signal_invalid_writer( sc_object* target, sc_object* first_writer, 48 sc_object* second_writer, bool check_delta ); 49 50// SIGNAL WRITING POLICIES 51// 52// Note: if you add a new policy to the enum below you will need to add 53// an additional overload of sc_reset::reset_signal_is() for the sc_signal<bool> 54// instance. That will require changes to sysc/kernel/sc_reset.cpp and 55// sysc/kernel/sc_reset.h 56 57enum sc_writer_policy 58{ 59 SC_ONE_WRITER = 0, ///< unique writer (from a unique port) 60 SC_MANY_WRITERS = 1, ///< allow multiple writers (with different ports) 61 SC_UNCHECKED_WRITERS = 3 ///< even allow delta cycle conflicts (non-standard) 62}; 63 64// signal forward declaration 65template< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY > 66class sc_signal; 67 68template< sc_writer_policy > 69struct sc_writer_policy_check; 70 71struct sc_writer_policy_nocheck_write 72{ 73 bool check_write( sc_object* /* target */, bool /* value_changed */ ) 74 { return true; } 75 void update(){} 76}; 77 78struct sc_writer_policy_check_write 79{ 80 bool check_write( sc_object* target, bool value_changed ); 81 void update(){} 82protected: 83 sc_writer_policy_check_write( bool check_delta = false ) 84 : m_check_delta( check_delta ), m_writer_p(NULL) {} 85 const bool m_check_delta; 86 sc_object* m_writer_p; 87}; 88 89struct sc_writer_policy_check_delta 90 : sc_writer_policy_check_write 91{ 92 93 sc_writer_policy_check_delta() 94 : sc_writer_policy_check_write(true) {} 95 96 bool check_write( sc_object* target, bool value_changed ) 97 { 98 if( value_changed ) 99 return sc_writer_policy_check_write::check_write( target, true ); 100 return true; 101 } 102 103 void update(){ m_writer_p = NULL; } 104}; 105 106struct sc_writer_policy_nocheck_port 107{ 108 bool check_port( sc_object*, sc_port_base*, bool ) 109 { return true; } 110}; 111 112struct sc_writer_policy_check_port 113{ 114 bool check_port( sc_object* target, sc_port_base* port, bool is_output ); 115 116protected: 117 sc_writer_policy_check_port() : m_output(0) {} 118 sc_port_base* m_output; 119}; 120 121template<> 122struct sc_writer_policy_check<SC_ONE_WRITER> 123 : sc_writer_policy_check_port 124 , sc_writer_policy_check_write 125{}; 126 127template<> 128struct sc_writer_policy_check<SC_MANY_WRITERS> 129 : sc_writer_policy_nocheck_port 130 , sc_writer_policy_check_delta 131{}; 132 133template<> 134struct sc_writer_policy_check<SC_UNCHECKED_WRITERS> 135 : sc_writer_policy_nocheck_port 136 , sc_writer_policy_nocheck_write 137{}; 138 139} // namespace sc_core 140 141#endif 142 143// Taf! 144