sc_writer_policy.h revision 12027
12817Sksewell@umich.edu/***************************************************************************** 22817Sksewell@umich.edu 32817Sksewell@umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 42817Sksewell@umich.edu more contributor license agreements. See the NOTICE file distributed 52817Sksewell@umich.edu with this work for additional information regarding copyright ownership. 62817Sksewell@umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 72817Sksewell@umich.edu (the "License"); you may not use this file except in compliance with the 82817Sksewell@umich.edu License. You may obtain a copy of the License at 92817Sksewell@umich.edu 102817Sksewell@umich.edu http://www.apache.org/licenses/LICENSE-2.0 112817Sksewell@umich.edu 122817Sksewell@umich.edu Unless required by applicable law or agreed to in writing, software 132817Sksewell@umich.edu distributed under the License is distributed on an "AS IS" BASIS, 142817Sksewell@umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 152817Sksewell@umich.edu implied. See the License for the specific language governing 162817Sksewell@umich.edu permissions and limitations under the License. 172817Sksewell@umich.edu 182817Sksewell@umich.edu *****************************************************************************/ 192817Sksewell@umich.edu 202817Sksewell@umich.edu/***************************************************************************** 212817Sksewell@umich.edu 222817Sksewell@umich.edu sc_writer_policy.h -- The sc_signal<T> writer policy definition 232817Sksewell@umich.edu 242817Sksewell@umich.edu Original Author: Philipp A: Hartmann, OFFIS 252817Sksewell@umich.edu 262817Sksewell@umich.edu CHANGE LOG IS AT THE END OF THE FILE 272817Sksewell@umich.edu *****************************************************************************/ 282817Sksewell@umich.edu 292817Sksewell@umich.edu 302817Sksewell@umich.edu#ifndef SC_WRITER_POLICY_H_INCLUDED_ 312817Sksewell@umich.edu#define SC_WRITER_POLICY_H_INCLUDED_ 322817Sksewell@umich.edu 332817Sksewell@umich.edu#if !defined(SC_DEFAULT_WRITER_POLICY) 342817Sksewell@umich.edu# if defined(SC_NO_WRITE_CHECK) 352817Sksewell@umich.edu# define SC_DEFAULT_WRITER_POLICY SC_UNCHECKED_WRITERS 362817Sksewell@umich.edu# else 372817Sksewell@umich.edu# define SC_DEFAULT_WRITER_POLICY SC_ONE_WRITER 382817Sksewell@umich.edu# endif 392817Sksewell@umich.edu#endif 402817Sksewell@umich.edu 412817Sksewell@umich.edunamespace sc_core { 422817Sksewell@umich.edu 432817Sksewell@umich.educlass sc_object; 442817Sksewell@umich.educlass sc_port_base; 452817Sksewell@umich.eduextern 462817Sksewell@umich.eduvoid 472817Sksewell@umich.edusc_signal_invalid_writer( sc_object* target, sc_object* first_writer, 482817Sksewell@umich.edu sc_object* second_writer, bool check_delta ); 492817Sksewell@umich.edu 502817Sksewell@umich.edu// SIGNAL WRITING POLICIES 512817Sksewell@umich.edu// 522817Sksewell@umich.edu// Note: if you add a new policy to the enum below you will need to add 532817Sksewell@umich.edu// an additional overload of sc_reset::reset_signal_is() for the sc_signal<bool> 542817Sksewell@umich.edu// instance. That will require changes to sysc/kernel/sc_reset.cpp and 552935Sksewell@umich.edu// sysc/kernel/sc_reset.h 562935Sksewell@umich.edu 572935Sksewell@umich.eduenum sc_writer_policy 582935Sksewell@umich.edu{ 592935Sksewell@umich.edu SC_ONE_WRITER = 0, ///< unique writer (from a unique port) 602935Sksewell@umich.edu SC_MANY_WRITERS = 1, ///< allow multiple writers (with different ports) 612817Sksewell@umich.edu SC_UNCHECKED_WRITERS = 3 ///< even allow delta cycle conflicts (non-standard) 622935Sksewell@umich.edu}; 632817Sksewell@umich.edu 642817Sksewell@umich.edu// signal forward declaration 652817Sksewell@umich.edutemplate< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY > 662817Sksewell@umich.educlass sc_signal; 672817Sksewell@umich.edu 682817Sksewell@umich.edutemplate< sc_writer_policy > 692817Sksewell@umich.edustruct sc_writer_policy_check; 702817Sksewell@umich.edu 712817Sksewell@umich.edustruct sc_writer_policy_nocheck_write 722817Sksewell@umich.edu{ 732817Sksewell@umich.edu bool check_write( sc_object* /* target */, bool /* value_changed */ ) 742817Sksewell@umich.edu { return true; } 752817Sksewell@umich.edu void update(){} 762817Sksewell@umich.edu}; 772817Sksewell@umich.edu 782817Sksewell@umich.edustruct 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