sc_isdb_trace.cpp

来自「基于4个mips核的noc设计」· C++ 代码 · 共 1,876 行 · 第 1/4 页

CPP
1,876
字号
  else if(exponent10_seconds ==   1) timescale_unit = 1e1;  else if(exponent10_seconds ==   2) timescale_unit = 1e2;    char buf[200];  sprintf(buf, "Note: ISDB trace timescale unit is set by user to 1e%d sec.\n", exponent10_seconds);  cout << buf << flush;  timescale_set_by_user = true;}void isdb_trace_file::trace(const bool& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);      sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_bool_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const sc_bit& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);      sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_sc_bit_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const sc_logic& object, const sc_string& name){  if(initialized)    isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);  sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_sc_logic_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const unsigned& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_unsigned_int_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const unsigned char& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_unsigned_char_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const unsigned short& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_unsigned_short_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const unsigned long& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_unsigned_long_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const int& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_signed_int_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const char& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_signed_char_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const short& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_signed_short_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const long& object, const sc_string& name, int width_){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_signed_long_trace(object, name, temp_isdb_name, width_));}void isdb_trace_file::trace(const float& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_float_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const double& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_double_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const sc_unsigned& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_sc_unsigned_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const sc_signed& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_sc_signed_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const sc_int_base& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_sc_int_base_trace(object, name, temp_isdb_name));}void isdb_trace_file::trace(const sc_uint_base& object, const sc_string& name){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_sc_uint_base_trace(object, name, temp_isdb_name));}#define DEFN_TRACE_METHOD(tp)                                                 \void                                                                          \isdb_trace_file::trace( const tp& object, const sc_string& name )             \{                                                                             \    if( initialized )                                                         \        isdb_put_error_message(                                               \	    "No traces can be added once simulation has started.\n"           \            "To add traces, create a new isdb trace file.", false );          \                                                                              \    sc_string temp_isdb_name;                                                 \    create_isdb_name( &temp_isdb_name );                                      \    traces.push_back( new isdb_ ## tp ## _trace( object,                      \						 name,                        \						 temp_isdb_name ) );          \}DEFN_TRACE_METHOD(sc_fxval)DEFN_TRACE_METHOD(sc_fxval_fast)DEFN_TRACE_METHOD(sc_fxnum)DEFN_TRACE_METHOD(sc_fxnum_fast)#undef DEFN_TRACE_METHODvoidisdb_trace_file::trace(const unsigned& object, const sc_string& name, const char** enum_literals){  if(initialized)      isdb_put_error_message("No traces can be added once simulation has started.\n"			   "To add traces, create a new isdb trace file.", false);    sc_string temp_isdb_name;  create_isdb_name(&temp_isdb_name);  traces.push_back(new isdb_enum_trace(object, name, temp_isdb_name, enum_literals));}voidisdb_trace_file::write_comment(const sc_string& /* comment */){  /* TBD: comments not supported */}voidisdb_trace_file::delta_cycles(bool flag){    trace_delta_cycles = flag;}voidisdb_trace_file::cycle(bool this_is_a_delta_cycle){  char message[4000];  unsigned this_time_units_high, this_time_units_low;      // Just to make g++ shut up in the optimized mode  this_time_units_high = this_time_units_low = 0;  // Trace delta cycles only when enabled  if (!trace_delta_cycles && this_is_a_delta_cycle) return;  // Check for initialization  if (!initialized) {    initialize();    initialized = true;    return;  };  // double now_units = sc_simulation_time() / timescale_unit;  double now_units = sc_time_stamp().to_double() / timescale_unit;    unsigned now_units_high, now_units_low;  double_to_special_int64(now_units, &now_units_high, &now_units_low );  bool now_later_than_previous_time = false;  if(      now_units_low > previous_time_units_low         && now_units_high == previous_time_units_high      ||   now_units_high > previous_time_units_high){    now_later_than_previous_time = true;  }  bool now_equals_previous_time = false;  if (now_later_than_previous_time) {    this_time_units_high = now_units_high;    this_time_units_low = now_units_low;  } else {     if (   now_units_low == previous_time_units_low	    && now_units_high == previous_time_units_high)       {	   now_equals_previous_time = true;       }  }  // Since ISDB does not understand 0 time progression, we have to fake  // delta cycles with progressing time by one unit    if(this_is_a_delta_cycle){        this_time_units_high = previous_time_units_high;        this_time_units_low = previous_time_units_low + 1;        if(this_time_units_low == 1000000000){            this_time_units_high++;            this_time_units_low=0;        }        static bool warned = false;        if(!warned){	    cout << "Note: VCD delta cycling with pseudo timesteps (1 unit) "		    "is performed.\n" << endl;            warned = true;        }    }    // Not a delta cycle and time has not progressed  if(!this_is_a_delta_cycle && now_equals_previous_time){    static bool warned = false;    if( ! warned && ! running_regression ) {      sprintf(message,	      "Multiple cycles found with same (%u) time units count.\n"	      "Waveform viewers will only show the states of the last one.\n"	      "Use ((isdb_trace_file*)isdbfile)->sc_set_isdb_time_unit(int exponent10_seconds)\n"	      "to increase time resolution.",	      now_units_low	      );      isdb_put_error_message(message, true);      warned = true;    }    this_time_units_high = now_units_high;    this_time_units_low = now_units_low;  }  // Not a delta cycle and time has gone backward  // This will happen with large number of delta cycles between two real advances of time  if(!this_is_a_delta_cycle && !now_equals_previous_time && !now_later_than_previous_time){    static bool warned = false;    if(!warned){      sprintf(message,	      "Cycle found with falling (%u -> %u) time units count.\n"	      "This can occur when delta cycling is activated.\n"	      "Cycles with falling time are not shown.\n"	      "Use ((isdb_trace_file*)isdbfile)->sc_set_isdb_time_unit(int exponent10_seconds)\n"	      "to increase time resolution.",	      previous_time_units_low, now_units_low);      isdb_put_error_message(message, true);      warned = true;    }    // Note that we don't set this_time_units_high/low to any value only in this case because    // we are not going to do any tracing. In the optimized mode, the compiler complains because    // of this. Therefore, we include the lines at the very beginning of this function to make the    // compiler shut up.    return;   }  //  // Now do the actual printing   //  bool time_printed = false;  isdb_trace* const* const l_traces = traces.raw_data();  for (int i = 0; i < traces.size(); i++) {    isdb_trace* t = l_traces[i];    if(t->changed()){      // Set time stamp on the fly      if(time_printed == false){	ISDB_Time time;	time.low  = this_time_units_low;	time.high = this_time_units_high;	ISDB_SetTime (database, time);	time_printed = true;      }      // Write the variable      t->write(database);    }  }  if(time_printed){    // We update previous_time_units only when we print time because    // this field stores the previous time that was printed, not the    // previous time this function was called    previous_time_units_high = this_time_units_high;    previous_time_units_low = this_time_units_low;  }}voidisdb_trace_file::create_isdb_name(sc_string* p_destination){    const char first_type_used = 'a';    const int used_types_count = 'z' - 'a' + 1;    int result;    char char4 = (char)(isdb_name_index % used_types_count);    result = isdb_name_index / used_types_count;    char char3 = (char)(result % used_types_count);    result = result / used_types_count;    char char2 = (char)(result % used_types_count);    char buf[20];    sprintf(buf, "%c%c%c",            char2 + first_type_used,            char3 + first_type_used,            char4 + first_type_used);    *p_destination = buf;     isdb_name_index++;}isdb_trace_file::~isdb_trace_file(){  int i;  for (i = 0; i < traces.size(); i++) {    isdb_trace* t = traces[i];    delete t;  }  ISDB_End (database,ISDB_DONE);}// Functions specific to ISDB tracingstaticunsigned intmap_sc_logic_state_to_isdb_binval (char val){  if      (val=='1') return ISDB_HIGH;  else if (val=='0') return ISDB_LOW;  else if (val=='Z') return ISDB_Z;  else               return ISDB_X;}staticvoidisdb_put_error_message(const char* msg, bool just_warning){    if(just_warning){	cout << "ISDB Trace Warning:\n" << msg << "\n" << endl;    }    else{	cout << "ISDB Trace ERROR:\n" << msg << "\n" << endl;    }}sc_trace_file*sc_create_isdb_trace_file(const char * name){  sc_trace_file *tf;  tf = new isdb_trace_file(name);  sc_get_curr_simcontext()->add_trace_file(tf);  return tf;}voidsc_close_isdb_trace_file( sc_trace_file* tf ){    isdb_trace_file* isdb_tf = (isdb_trace_file*)tf;    delete isdb_tf;}

⌨️ 快捷键说明

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