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 #include "scv/scv_config.h"
00041
00042 #include "systemc.h"
00043
00044 #include "scv/scv_util.h"
00045 #include "scv/_scv_associative_array.h"
00046 #include "scv/scv_report.h"
00047
00048
00049
00050
00051
00052 #include "scv/scv_kit_date.h"
00053
00054 #ifndef SCV_VERSION
00055 #define SCV_VERSION "<SCV_VERSION undefined>"
00056 #endif
00057
00058 #ifndef SCV_KIT_DATE
00059 #define SCV_KIT_DATE "<SCV_KIT_DATE undefined>"
00060 #endif
00061
00062
00063 static struct {
00064 const char* strP;
00065 const char** strPP;
00066 } scvVersionIdent = { "@(#)$CDS: libscv.so " SCV_VERSION " " SCV_KIT_DATE " $",
00067 &scvVersionIdent.strP };
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 bool _scv_startup_called = false;
00078
00079 extern void scv_constraint_startup();
00080
00081 bool scv_startup()
00082 {
00083 static bool first = true;
00084 if ( first ) {
00085 scv_constraint_startup();
00086 first = false;
00087 }
00088 return true;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 int _scv_make_unique_id(const string& name, const string& kind)
00098 {
00099 typedef _scv_associative_array<string,int> xref;
00100 static xref table("NameList",0);
00101 static const string delim = ":::";
00102 return table[kind+delim+name]++;
00103 }
00104
00105 const string _scv_make_unique_name(const string& name, int id)
00106 {
00107 static char *image = 0;
00108 static int len = 0;
00109 if ( id == 0 ) return name;
00110 int tmp = strlen(name.c_str()) + 36;
00111 if ( tmp > len ) {
00112 delete [] image;
00113 image = new char[tmp];
00114 len = tmp;
00115 }
00116 sprintf(image,"%s(%d)",name.c_str(),id);
00117 return image;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 _scv_process_name_server_t *_scv_process_name_server = 0;
00127
00128 void _scv_set_process_name_server(_scv_process_name_server_t *server)
00129 { _scv_process_name_server = server; }
00130
00131 const char *_scv_get_process_name(const sc_process_b *proc_p)
00132
00133
00134 { return proc_p->name(); }
00135
00136 const char *scv_get_process_name(sc_process_b *proc_p)
00137 {
00138 if ( ! proc_p ) return "<main>";
00139 if ( _scv_process_name_server ) {
00140 return _scv_process_name_server(proc_p);
00141 }
00142 return _scv_get_process_name(proc_p);
00143 }
00144
00145
00146
00147
00148
00149 class _scv_out_buf_t : public streambuf {
00150 public:
00151 int sync();
00152 int overflow(int ch);
00153 int flush();
00154 };
00155
00156 _scv_out_buf_t *_scv_out_buf_p = new _scv_out_buf_t;
00157 ostream *_scv_out_p = new ostream(_scv_out_buf_p);
00158 static int _scv_out_buffer_index = 0;
00159 static char _scv_out_buffer[3000];
00160 static bool _add_scv_prefix = true;
00161 static char *_scv_prefix = getenv("SCV_REG");
00162
00163 int _scv_out_buf_t::sync() {
00164 if (_scv_out_buffer_index == 0) {
00165 return 0;
00166 }
00167 _scv_out_buffer[_scv_out_buffer_index] = '\0';
00168 if (_scv_prefix == NULL || strlen(_scv_prefix) == 0) {
00169 _scv_out_buffer_index = 0;
00170 cout << _scv_out_buffer;
00171 return 0;
00172 }
00173 char scv_prefix[10];
00174 if (_add_scv_prefix) {
00175 strcpy(scv_prefix, _scv_prefix);
00176 } else {
00177 scv_prefix[0] = '\0';
00178 }
00179 char scv_spare_buffer[3000];
00180 char *begin_line = &_scv_out_buffer[0];
00181 char *spare_buffer = &scv_spare_buffer[0];
00182 char *chr;
00183 for (chr = &_scv_out_buffer[0]; *chr != '\0'; chr++) {
00184 if (*chr == '\n') {
00185 strcpy(spare_buffer, scv_prefix);
00186 spare_buffer += strlen(scv_prefix);
00187 while (begin_line != chr) {
00188 *spare_buffer++ = *begin_line++;
00189 }
00190 }
00191 }
00192 if (begin_line < chr) {
00193 while (begin_line <= chr) {
00194 *spare_buffer++ = *begin_line++;
00195 }
00196 }
00197 if (*(chr-1) == '\n') {
00198 *(spare_buffer-2) = '\0';
00199 }
00200 strcpy(_scv_out_buffer, scv_spare_buffer);
00201 _scv_out_buffer_index = 0;
00202 cout << _scv_out_buffer << endl;
00203 return 0;
00204 }
00205
00206 int _scv_out_buf_t::flush() {
00207 _scv_out_buf_p->sync();
00208 return 0;
00209 }
00210
00211 int _scv_out_buf_t::overflow(int ch) {
00212
00213 char c;
00214 c = (char) ch;
00215 _scv_out_buffer[_scv_out_buffer_index] = c;
00216 _scv_out_buffer_index++;
00217 if ( (_scv_out_buffer_index > 2000) || (c == '\n') ) {
00218 _scv_out_buf_p->sync();
00219 }
00220 return ch;
00221 }
00222
00223
00224
00225
00226 int _scv_data_structure::_debug = -1;
00227
00228 const char *_scv_data_structure::_kind = "_scv_data_structure";
00229
00230 void scv_object_if::set_debug_level(const char *facility, int level)
00231 { scv_debug::set_level(facility,level); }