sc_proxy.h

来自「基于4个mips核的noc设计」· C头文件 代码 · 共 1,337 行 · 第 1/3 页

H
1,337
字号
/*****************************************************************************  The following code is derived, directly or indirectly, from the SystemC  source code Copyright (c) 1996-2002 by all Contributors.  All Rights reserved.  The contents of this file are subject to the restrictions and limitations  set forth in the SystemC Open Source License Version 2.3 (the "License");  You may not use this file except in compliance with such restrictions and  limitations. You may obtain instructions on how to receive a copy of the  License at http://www.systemc.org/. Software distributed by Contributors  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF  ANY KIND, either express or implied. See the License for the specific  language governing rights and limitations under the License. *****************************************************************************//*****************************************************************************  sc_proxy.h -- Proxy base class for vector data types.                This class is created for several purposes:                1) hiding operators from the global namespace that would be		   otherwise found by Koenig lookup                2) avoiding repeating the same operations in every class		   including proxies that could also be achieved by common		   base class, but this method allows                3) improve performance by using non-virtual functions  Original Author: Gene Bushuyev, Synopsys, Inc. *****************************************************************************//*****************************************************************************  MODIFICATION LOG - modifiers, enter your name, affiliation, date and  changes you are making here.      Name, Affiliation, Date:  Description of Modification: *****************************************************************************/#ifndef SC_PROXY_H#define SC_PROXY_H#include "systemc/kernel/sc_cmnhdr.h"#include "systemc/utils/sc_iostream.h"#include "systemc/datatypes/int/sc_signed.h"#include "systemc/datatypes/int/sc_unsigned.h"#include "systemc/datatypes/int/sc_int_base.h"#include "systemc/datatypes/int/sc_uint_base.h"#include "systemc/utils/sc_string.h"#include "systemc/datatypes/bit/sc_bit.h"#include "systemc/datatypes/bit/sc_bit_ids.h"#include "systemc/datatypes/bit/sc_logic.h"#include "systemc/kernel/sc_macros.h"namespace sc_dt{// classes defined in this moduletemplate <class X> class sc_proxy;// forward class declarationsclass sc_bv_base;class sc_lv_base;template <class X> class sc_bitref_r;template <class X> class sc_bitref;template <class X> class sc_subref_r;template <class X> class sc_subref;template <class X, class Y> class sc_concref_r;template <class X, class Y> class sc_concref;const int UL_SIZE = BITS_PER_BYTE * sizeof( unsigned long );const unsigned long UL_ZERO = 0ul;const unsigned long UL_ONE  = 1ul;const unsigned long UL_TWO  = 2ul;// assignment functions; forward declarationstemplate <class X, class Y>inlinevoidassign_p_( sc_proxy<X>& px, const sc_proxy<Y>& py );// Vector types that are not derived from sc_proxy must have a length()// function and an operator []. The vector argument type must support// accessing bits that are beyond the msb. The vector argument type// decides what to do there (e.g. sign extension or zero padding).template <class X, class T>inlinevoidassign_v_( sc_proxy<X>& px, const T& a );// other functions; forward declarationsconst sc_string convert_to_bin( const char* s );const sc_string convert_to_fmt( const sc_string& s, sc_numrep numrep, bool );// ----------------------------------------------------------------------------//  CLASS TEMPLATE : sc_proxy////  Base class template for bit/logic vector classes.//  (Barton/Nackmann implementation)// ----------------------------------------------------------------------------template <class X>class sc_proxy{public:    // virtual destructor    virtual ~sc_proxy() {}    // casts    X& back_cast()	{ return SCAST<X&>( *this ); }    const X& back_cast() const	{ return SCAST<const X&>( *this ); }    // assignment operators    template <class Y>    X& assign_( const sc_proxy<Y>& a )	{ assign_p_( *this, a ); return back_cast(); }    X& assign_( const char* a );    X& assign_( const bool* a );    X& assign_( const sc_logic* a );    X& assign_( const sc_unsigned& a )	{ assign_v_( *this, a ); return back_cast(); }    X& assign_( const sc_signed& a )	{ assign_v_( *this, a ); return back_cast(); }    X& assign_( const sc_uint_base& a )	{ return assign_( (uint64) a ); }    X& assign_( const sc_int_base& a )	{ return assign_( (int64) a ); }    X& assign_( unsigned long a );    X& assign_( long a );    X& assign_( unsigned int a )	{ return assign_( (unsigned long) a ); }    X& assign_( int a )	{ return assign_( (long) a ); }    X& assign_( uint64 a );    X& assign_( int64 a );    // bitwise operators and functions    // bitwise complement    X& b_not();    const sc_lv_base operator ~ () const;    // bitwise and    X& operator &= ( const char* b );    X& operator &= ( const bool* b );    X& operator &= ( const sc_logic* b );    X& operator &= ( const sc_unsigned& b );    X& operator &= ( const sc_signed& b );    X& operator &= ( const sc_uint_base& b )	{ return operator &= ( (uint64) b ); }    X& operator &= ( const sc_int_base& b )	{ return operator &= ( (int64) b ); }    X& operator &= ( unsigned long b );    X& operator &= ( long b );    X& operator &= ( unsigned int b )	{ return operator &= ( (unsigned long) b ); }    X& operator &= ( int b )	{ return operator &= ( (long) b ); }    X& operator &= ( uint64 b );    X& operator &= ( int64 b );    const sc_lv_base operator & ( const char* b ) const;    const sc_lv_base operator & ( const bool* b ) const;    const sc_lv_base operator & ( const sc_logic* b ) const;    const sc_lv_base operator & ( const sc_unsigned& b ) const;    const sc_lv_base operator & ( const sc_signed& b ) const;    const sc_lv_base operator & ( const sc_uint_base& b ) const;    const sc_lv_base operator & ( const sc_int_base& b ) const;    const sc_lv_base operator & ( unsigned long b ) const;    const sc_lv_base operator & ( long b ) const;    const sc_lv_base operator & ( unsigned int b ) const;    const sc_lv_base operator & ( int b ) const;    const sc_lv_base operator & ( uint64 b ) const;    const sc_lv_base operator & ( int64 b ) const;    // bitwise or    X& operator |= ( const char* b );    X& operator |= ( const bool* b );    X& operator |= ( const sc_logic* b );    X& operator |= ( const sc_unsigned& b );    X& operator |= ( const sc_signed& b );    X& operator |= ( const sc_uint_base& b )	{ return operator |= ( (uint64) b ); }    X& operator |= ( const sc_int_base& b )	{ return operator |= ( (int64) b ); }    X& operator |= ( unsigned long b );    X& operator |= ( long b );    X& operator |= ( unsigned int b )	{ return operator |= ( (unsigned long) b ); }    X& operator |= ( int b )	{ return operator |= ( (long) b ); }    X& operator |= ( uint64 b );    X& operator |= ( int64 b );    const sc_lv_base operator | ( const char* b ) const;    const sc_lv_base operator | ( const bool* b ) const;    const sc_lv_base operator | ( const sc_logic* b ) const;    const sc_lv_base operator | ( const sc_unsigned& b ) const;    const sc_lv_base operator | ( const sc_signed& b ) const;    const sc_lv_base operator | ( const sc_uint_base& b ) const;    const sc_lv_base operator | ( const sc_int_base& b ) const;    const sc_lv_base operator | ( unsigned long b ) const;    const sc_lv_base operator | ( long b ) const;    const sc_lv_base operator | ( unsigned int b ) const;    const sc_lv_base operator | ( int b ) const;    const sc_lv_base operator | ( uint64 b ) const;    const sc_lv_base operator | ( int64 b ) const;    // bitwise xor    X& operator ^= ( const char* b );    X& operator ^= ( const bool* b );    X& operator ^= ( const sc_logic* b );    X& operator ^= ( const sc_unsigned& b );    X& operator ^= ( const sc_signed& b );    X& operator ^= ( const sc_uint_base& b )	{ return operator ^= ( (uint64) b ); }    X& operator ^= ( const sc_int_base& b )	{ return operator ^= ( (int64) b ); }    X& operator ^= ( unsigned long b );    X& operator ^= ( long b );    X& operator ^= ( unsigned int b )	{ return operator ^= ( (unsigned long) b ); }    X& operator ^= ( int b )	{ return operator ^= ( (long) b ); }    X& operator ^= ( uint64 b );    X& operator ^= ( int64 b );    const sc_lv_base operator ^ ( const char* b ) const;    const sc_lv_base operator ^ ( const bool* b ) const;    const sc_lv_base operator ^ ( const sc_logic* b ) const;    const sc_lv_base operator ^ ( const sc_unsigned& b ) const;    const sc_lv_base operator ^ ( const sc_signed& b ) const;    const sc_lv_base operator ^ ( const sc_uint_base& b ) const;    const sc_lv_base operator ^ ( const sc_int_base& b ) const;    const sc_lv_base operator ^ ( unsigned long b ) const;    const sc_lv_base operator ^ ( long b ) const;    const sc_lv_base operator ^ ( unsigned int b ) const;    const sc_lv_base operator ^ ( int b ) const;    const sc_lv_base operator ^ ( uint64 b ) const;    const sc_lv_base operator ^ ( int64 b ) const;    // bitwise left shift    X& operator <<= ( int n );    const sc_lv_base operator << ( int n ) const;    // bitwise right shift    X& operator >>= ( int n );    const sc_lv_base operator >> ( int n ) const;    // bitwise left rotate    X& lrotate( int n );    // bitwise right rotate    X& rrotate( int n );    // bitwise reverse    X& reverse();    // bit selection    sc_bitref<X> operator [] ( int i )	{ return sc_bitref<X>( back_cast(), i ); }    sc_bitref_r<X> operator [] ( int i ) const	{ return sc_bitref_r<X>( back_cast(), i ); }    sc_bitref<X> bit( int i )	{ return sc_bitref<X>( back_cast(), i ); }    sc_bitref_r<X> bit( int i ) const	{ return sc_bitref_r<X>( back_cast(), i ); }    // part selection    sc_subref<X> operator () ( int hi, int lo )	{ return sc_subref<X>( back_cast(), hi, lo ); }    sc_subref_r<X> operator () ( int hi, int lo ) const	{ return sc_subref_r<X>( back_cast(), hi, lo ); }    sc_subref<X> range( int hi, int lo )	{ return sc_subref<X>( back_cast(), hi, lo ); }    sc_subref_r<X> range( int hi, int lo ) const	{ return sc_subref_r<X>( back_cast(), hi, lo ); }    // reduce functions    sc_logic_value_t and_reduce() const;    sc_logic_value_t nand_reduce() const	{ return sc_logic::not_table[and_reduce()]; }    sc_logic_value_t or_reduce() const;    sc_logic_value_t nor_reduce() const	{ return sc_logic::not_table[or_reduce()]; }    sc_logic_value_t xor_reduce() const;    sc_logic_value_t xnor_reduce() const	{ return sc_logic::not_table[xor_reduce()]; }    // relational operators    bool operator == ( const char* b ) const;    bool operator == ( const bool* b ) const;    bool operator == ( const sc_logic* b ) const;    bool operator == ( const sc_unsigned& b ) const;    bool operator == ( const sc_signed& b ) const;    bool operator == ( const sc_uint_base& b ) const;    bool operator == ( const sc_int_base& b ) const;    bool operator == ( unsigned long b ) const;    bool operator == ( long b ) const;    bool operator == ( unsigned int b ) const;    bool operator == ( int b ) const;    bool operator == ( uint64 b ) const;    bool operator == ( int64 b ) const;    // explicit conversions to character string    const sc_string to_string() const;    const sc_string to_string( sc_numrep ) const;    const sc_string to_string( sc_numrep, bool ) const;    // explicit conversions    int to_int() const	{ return to_anything_signed(); }    unsigned int to_uint() const	{ return to_anything_unsigned(); }    long to_long() const	{ return to_anything_signed(); }    unsigned long to_ulong() const	{ return to_anything_unsigned(); }#ifdef SC_DT_DEPRECATED    int to_signed() const	{ return to_int(); }    unsigned to_unsigned() const	{ return to_uint(); }#endif    // other methods    void print( ostream& os = cout ) const	{ os << to_string(); }    void scan( istream& is = cin );protected:    void check_bounds( int n ) const;  // check if bit n accessible    void check_wbounds( int n ) const; // check if word n accessible    unsigned long to_anything_unsigned() const;    long to_anything_signed() const;};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?