Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sc_lv_base.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2004 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.3 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_lv_base.cpp -- Arbitrary size logic vector class.
00021 
00022   Original Author: Gene Bushuyev, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 
00037 #include "systemc/datatypes/bit/sc_bit_ids.h"
00038 #include "systemc/datatypes/bit/sc_lv_base.h"
00039 
00040 
00041 namespace sc_dt
00042 {
00043 
00044 // ----------------------------------------------------------------------------
00045 //  CLASS : sc_lv_base
00046 //
00047 //  Arbitrary size logic vector base class.
00048 // ----------------------------------------------------------------------------
00049 
00050 static const unsigned long data_array[] =
00051     { UL_ZERO, ~UL_ZERO, UL_ZERO, ~UL_ZERO };
00052 
00053 static const unsigned long ctrl_array[] =
00054     { UL_ZERO, UL_ZERO, ~UL_ZERO, ~UL_ZERO };
00055 
00056 
00057 void
00058 sc_lv_base::init( int length_, const sc_logic& init_value )
00059 {
00060     // check the length
00061     if( length_ <= 0 ) {
00062   SC_REPORT_ERROR( SC_ID_ZERO_LENGTH_, 0 );
00063     }
00064     // allocate memory for the data and control words
00065     m_len = length_;
00066     m_size = (m_len - 1) / UL_SIZE + 1;
00067     m_data = new unsigned long[m_size * 2];
00068     m_ctrl = m_data + m_size;
00069     // initialize the bits to 'init_value'
00070     unsigned long dw = data_array[init_value.value()];
00071     unsigned long cw = ctrl_array[init_value.value()];
00072     int sz = m_size;
00073     for( int i = 0; i < sz; ++ i ) {
00074   m_data[i] = dw;
00075   m_ctrl[i] = cw;
00076     }
00077     clean_tail();
00078 }
00079 
00080 
00081 void
00082 sc_lv_base::assign_from_string( const sc_string& s )
00083 {
00084     // s must have been converted to bin
00085     int len = m_len;
00086     int s_len = s.length() - 1;
00087     int min_len = sc_min( len, s_len );
00088     int i = 0;
00089     for( ; i < min_len; ++ i ) {
00090   char c = s[s_len - i - 1];
00091   set_bit( i, sc_logic::char_to_logic[(int)c] );
00092     }
00093     // if formatted, fill the rest with sign(s), otherwise fill with zeros
00094     sc_logic_value_t fill = (s[s_len] == 'F' ? sc_logic_value_t( s[0] - '0' )
00095                                  : sc_logic_value_t( 0 ));
00096     for( ; i < len; ++ i ) {
00097   set_bit( i, fill );
00098     }
00099 }
00100 
00101 
00102 // constructors
00103 
00104 sc_lv_base::sc_lv_base( const char* a )
00105     : m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )
00106 {
00107     sc_string s = convert_to_bin( a );
00108     init( s.length() - 1 );
00109     assign_from_string( s );
00110 }
00111 
00112 sc_lv_base::sc_lv_base( const char* a, int length_ )
00113     : m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )
00114 {
00115     init( length_ );
00116     assign_from_string( convert_to_bin( a ) );
00117 }
00118 
00119 sc_lv_base::sc_lv_base( const sc_lv_base& a )
00120     : m_len( a.m_len ),
00121       m_size( a.m_size ),
00122       m_data( new unsigned long[m_size * 2] ),
00123       m_ctrl( m_data + m_size )
00124 {
00125     // copy the bits
00126     int sz = m_size;
00127     for( int i = 0; i < sz; ++ i ) {
00128   m_data[i] = a.m_data[i];
00129   m_ctrl[i] = a.m_ctrl[i];
00130     }
00131 }
00132 
00133 
00134 // assignment operators
00135 
00136 sc_lv_base&
00137 sc_lv_base::operator = ( const char* a )
00138 {
00139     assign_from_string( convert_to_bin( a ) );
00140     return *this;
00141 }
00142 
00143 
00144 // returns true if logic vector contains only 0's and 1's
00145 
00146 bool
00147 sc_lv_base::is_01() const
00148 {
00149     int sz = m_size;
00150     for( int i = 0; i < sz; ++ i ) {
00151   if( m_ctrl[i] != 0 ) {
00152       return false;
00153   }
00154     }
00155     return true;
00156 }
00157 
00158 } // namespace sc_dt

Generated on Fri Jan 14 08:29:03 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18