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

scv_util.cpp

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003 
00004   The following code is derived, directly or indirectly, from the SystemC
00005   source code Copyright (c) 1996-2002 by all Contributors.
00006   All Rights reserved.
00007 
00008   The contents of this file are subject to the restrictions and limitations
00009   set forth in the SystemC Open Source License Version 2.3 (the "License");
00010   You may not use this file except in compliance with such restrictions and
00011   limitations. You may obtain instructions on how to receive a copy of the
00012   License at http://www.systemc.org/. Software distributed by Contributors
00013   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00014   ANY KIND, either express or implied. See the License for the specific
00015   language governing rights and limitations under the License.
00016 
00017  *****************************************************************************/
00018 
00019 /*****************************************************************************
00020 
00021   scv_util.cpp -- The implementation of various small facilities.
00022 
00023   Original Authors (Cadence Design Systems, Inc):
00024   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00025   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey
00026   2002-09-23
00027 
00028  *****************************************************************************/
00029 
00030 /*****************************************************************************
00031 
00032   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00033   changes you are making here.
00034 
00035       Name, Affiliation, Date:
00036   Description of Modification:
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 // For cdsIdent:
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 // scv_startup
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 // making unique names
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 // Determine process name
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 // Enhance later to return unique name that's as stable as
00133 // possible despite changes in order of execution.
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 // Class and associated methods for scv_out
00147 //
00148 
00149 class _scv_out_buf_t : public streambuf {
00150  public:
00151   int sync();
00152   int overflow(int ch); // Called with just one character
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   // Called with one char
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 // Data structure initialization
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); }

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