⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_proxy.h

📁 system C源码 一种替代verilog的语言
💻 H
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************  The following code is derived, directly or indirectly, from the SystemC  source code Copyright (c) 1996-2006 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.4 (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: *****************************************************************************/// $Log: sc_proxy.h,v $// Revision 1.1.1.1  2006/12/15 20:31:36  acg// SystemC 2.2//// Revision 1.3  2006/01/13 18:53:53  acg// Andy Goodrich: added $Log command so that CVS comments are reproduced in// the source.//#ifndef SC_PROXY_H#define SC_PROXY_H#include "sysc/kernel/sc_cmnhdr.h"#include "sysc/utils/sc_iostream.h"#include "sysc/datatypes/int/sc_signed.h"#include "sysc/datatypes/int/sc_unsigned.h"#include "sysc/datatypes/int/sc_int_base.h"#include "sysc/datatypes/int/sc_uint_base.h"#include "sysc/utils/sc_string.h"#include "sysc/datatypes/bit/sc_bit.h"#include "sysc/datatypes/bit/sc_bit_ids.h"#include "sysc/datatypes/bit/sc_logic.h"#include "sysc/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 SC_DIGIT_SIZE = BITS_PER_BYTE * sizeof( sc_digit );const sc_digit SC_DIGIT_ZERO = (sc_digit)0;const sc_digit SC_DIGIT_ONE  = (sc_digit)1;const sc_digit SC_DIGIT_TWO  = (sc_digit)2;// 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 []. template <class X, class T>inlinevoidassign_v_( sc_proxy<X>& px, const T& a );// other functions; forward declarationsconst std::string convert_to_bin( const char* s );const std::string convert_to_fmt( const std::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 sc_value_base{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 int a );    X& assign_( int a );    X& assign_( unsigned long a );    X& 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 std::string to_string() const;    const std::string to_string( sc_numrep ) const;    const std::string to_string( sc_numrep, bool ) const;    // explicit conversions    inline int64 to_int64() const	{ return to_anything_signed(); }    inline uint64 to_uint64() const;    int to_int() const	{ return (int)to_anything_signed(); }    unsigned int to_uint() const	{ return (unsigned int)to_anything_unsigned(); }    long to_long() const	{ return (long)to_anything_signed(); }    unsigned long to_ulong() const	{ return (unsigned long)to_anything_unsigned(); }#ifdef SC_DT_DEPRECATED    int to_signed() const	{ return to_int(); }    sc_digit to_unsigned() const	{ return to_uint(); }#endif    // other methods    void print( ::std::ostream& os = ::std::cout ) const	{ 	    // the test below will force printing in binary if decimal is 	    // specified.	    if ( sc_io_base(os, SC_DEC) == SC_DEC )	        os << to_string();	    else	        os << to_string(sc_io_base(os,SC_BIN),sc_io_show_base(os)); 	}    void scan( ::std::istream& is = ::std::cin );protected:    void check_bounds( int n ) const;  // check if bit n accessible    void check_wbounds( int n ) const; // check if word n accessible    sc_digit to_anything_unsigned() const;    int64 to_anything_signed() const;};// ----------------------------------------------------------------------------// bitwise operators and functions// bitwise andtemplate <class X, class Y>inlineX&operator &= ( sc_proxy<X>& px, const sc_proxy<Y>& py );template <class X, class Y>inlineconst sc_lv_baseoperator & ( const sc_proxy<X>& px, const sc_proxy<Y>& py );#define DECL_BITWISE_AND_OP_T(tp)                                             \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \operator & ( tp b, const sc_proxy<X>& px );DECL_BITWISE_AND_OP_T(const char*)DECL_BITWISE_AND_OP_T(const bool*)DECL_BITWISE_AND_OP_T(const sc_logic*)DECL_BITWISE_AND_OP_T(const sc_unsigned&)DECL_BITWISE_AND_OP_T(const sc_signed&)DECL_BITWISE_AND_OP_T(const sc_uint_base&)DECL_BITWISE_AND_OP_T(const sc_int_base&)DECL_BITWISE_AND_OP_T(unsigned long)DECL_BITWISE_AND_OP_T(long)DECL_BITWISE_AND_OP_T(unsigned int)DECL_BITWISE_AND_OP_T(int)DECL_BITWISE_AND_OP_T(uint64)DECL_BITWISE_AND_OP_T(int64)#undef DECL_BITWISE_AND_OP_T// bitwise ortemplate <class X, class Y>inlineX&operator |= ( sc_proxy<X>& px, const sc_proxy<Y>& py );

⌨️ 快捷键说明

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