00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "sysc/datatypes/fx/scfx_utils.h"
00047
00048
00049 namespace sc_dt
00050 {
00051
00052 void
00053 scfx_tc2csd( scfx_string& s, int w_prefix )
00054 {
00055 if( w_prefix != 0 ) {
00056 SC_ASSERT_( s[0] == '0' && s[1] == 'c' &&
00057 s[2] == 's' && s[3] == 'd', "invalid prefix" );
00058 }
00059
00060 scfx_string csd;
00061
00062
00063 int i = 0;
00064 int j = (w_prefix != 0 ? 4 : 0);
00065 while( s[j] )
00066 {
00067 if( s[j] == '0' || s[j] == '1' )
00068 csd[i ++] = s[j];
00069 else if( s[j] != '.' )
00070 break;
00071 ++ j;
00072 }
00073 csd[i] = '\0';
00074
00075
00076 -- i;
00077 while( i >= 0 )
00078 {
00079 if( csd[i] == '0' )
00080 -- i;
00081 else
00082 {
00083 if( i > 0 && csd[i - 1] == '0' )
00084 -- i;
00085 else if( i == 0 )
00086 csd[i --] = '-';
00087 else
00088 {
00089 csd[i --] = '-';
00090 while( i >= 0 && csd[i] == '1' )
00091 csd[i --] = '0';
00092 if( i > 0 )
00093 csd[i] = '1';
00094 else if( i == 0 )
00095 csd[i --] = '1';
00096 }
00097 }
00098 }
00099
00100
00101 i = 0;
00102 j = (w_prefix != 0 ? 4 : 0);
00103 while( csd[i] )
00104 {
00105 if( s[j] == '.' )
00106 ++ j;
00107 s[j ++] = csd[i ++];
00108 }
00109 }
00110
00111
00112 void
00113 scfx_csd2tc( scfx_string& csd )
00114 {
00115 SC_ASSERT_( csd[0] == '0' && csd[1] == 'c' &&
00116 csd[2] == 's' && csd[3] == 'd', "invalid prefix" );
00117
00118 scfx_string s;
00119
00120
00121 int i = 0;
00122 s[i ++] = '0';
00123 int j = 4;
00124 while( csd[j] )
00125 {
00126 if( csd[j] == '-' || csd[j] == '0' || csd[j] == '1' )
00127 s[i ++] = csd[j];
00128 else if( csd[j] != '.' )
00129 break;
00130 ++ j;
00131 }
00132 s[i] = '\0';
00133
00134
00135 int len = i;
00136 i = 1;
00137 while( i < len )
00138 {
00139 while( i < len && s[i] != '-' )
00140 i ++;
00141 if( i < len )
00142 {
00143 j = i ++;
00144 s[j --] = '1';
00145 while( j >= 0 && s[j] == '0' )
00146 s[j --] = '1';
00147 if( j >= 0 )
00148 s[j] = '0';
00149 }
00150 }
00151
00152
00153 j = csd.length();
00154 csd[j + 1] = '\0';
00155 while( j > 4 )
00156 {
00157 csd[j] = csd[j - 1];
00158 -- j;
00159 }
00160
00161 i = 0;
00162 j = 4;
00163 while( s[i] )
00164 {
00165 if( csd[j] == '.' )
00166 ++ j;
00167 csd[j ++] = s[i ++];
00168 }
00169 }
00170
00171 }
00172
00173
00174