93 #define scv_tr_TEXT_LLU "%I64u"
94 #define scv_tr_TEXT_LLX "%I64x"
96 #define scv_tr_TEXT_LLU "%llu"
97 #define scv_tr_TEXT_LLX "%llx"
104 static gzFile my_text_file_p =
nullptr;
106 static void scv_tr_db_cbf(
const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason,
void* user_data_p) {
109 static std::string my_text_file_name(
"DEFAULT_scv_tr_TEXT.txt");
113 case scv_tr_db::CREATE:
114 if((_scv_tr_db.get_name() !=
nullptr) && (strlen(_scv_tr_db.get_name()) != 0)) {
115 my_text_file_name = _scv_tr_db.get_name();
118 my_text_file_p = gzopen(my_text_file_name.c_str(),
"wb1");
120 if(my_text_file_p ==
nullptr) {
121 _scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL,
"Can't open text recording file");
123 std::stringstream ss;
124 ss <<
"opening file " << my_text_file_name;
125 _scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL_INFO, ss.str().c_str());
129 case scv_tr_db::DELETE:
130 if(my_text_file_p !=
nullptr) {
131 std::stringstream ss;
132 ss <<
"closing file " << my_text_file_name;
133 _scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL_INFO, ss.str().c_str());
134 gzclose(my_text_file_p);
135 my_text_file_p =
nullptr;
140 _scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL,
"Unknown reason in scv_tr_db callback");
146 static void scv_tr_stream_cbf(
const scv_tr_stream& s, scv_tr_stream::callback_reason reason,
void* user_data_p) {
147 if(reason == scv_tr_stream::CREATE) {
149 if(my_text_file_p ==
nullptr)
152 gzprintf(my_text_file_p,
"scv_tr_stream (ID " scv_tr_TEXT_LLU
", name \"%s\", kind \"%s\")\n", s.get_id(), s.get_name(),
153 s.get_stream_kind() ? s.get_stream_kind() :
"<no_stream_kind>");
161 static void do_attributes(
bool declare_attributes,
162 bool undefined_values,
bool is_record_attribute, std::string& prefix_name,
const std::string& exts_kind,
163 const scv_extensions_if* my_exts_p,
167 if(my_exts_p ==
nullptr)
170 std::string full_name;
172 if(prefix_name ==
"") {
173 full_name = my_exts_p->get_name();
175 if((my_exts_p->get_name() ==
nullptr) || (strlen(my_exts_p->get_name()) == 0)) {
176 full_name = prefix_name;
178 full_name = prefix_name +
"." + my_exts_p->get_name();
182 if(full_name ==
"") {
183 full_name =
"<anonymous>";
186 switch(my_exts_p->get_type()) {
188 case scv_extensions_if::RECORD: {
189 int num_fields = my_exts_p->get_num_fields();
193 for(field_counter = 0; field_counter < num_fields; field_counter++) {
195 const scv_extensions_if* field_data_p = my_exts_p->get_field(field_counter);
197 do_attributes(declare_attributes, undefined_values, is_record_attribute, prefix_name, exts_kind, field_data_p, index);
202 case scv_extensions_if::ENUMERATION: {
203 if(declare_attributes) {
204 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"ENUMERATION\")\n",
206 *index, full_name.c_str());
208 }
else if(undefined_values) {
209 gzprintf(my_text_file_p,
"a UNDEFINED\n");
211 if(is_record_attribute) {
212 gzprintf(my_text_file_p, R
"(%s "%s" ENUMERATION = )", exts_kind.c_str(), full_name.c_str());
214 gzprintf(my_text_file_p,
"a ");
216 gzprintf(my_text_file_p,
"\"%s\"\n", my_exts_p->get_enum_string((
int)my_exts_p->get_integer()));
220 case scv_extensions_if::BOOLEAN: {
221 if(declare_attributes) {
222 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"BOOLEAN\")\n",
224 *index, full_name.c_str());
226 }
else if(undefined_values) {
227 gzprintf(my_text_file_p,
"a UNDEFINED\n");
229 if(is_record_attribute) {
230 gzprintf(my_text_file_p, R
"(%s "%s" BOOLEAN = )", exts_kind.c_str(), full_name.c_str());
232 gzprintf(my_text_file_p,
"a ");
234 gzprintf(my_text_file_p,
"%s\n", my_exts_p->get_bool() ?
"true" :
"false");
238 case scv_extensions_if::INTEGER:
239 case scv_extensions_if::FIXED_POINT_INTEGER: {
240 if(declare_attributes) {
241 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"INTEGER\")\n",
243 *index, full_name.c_str());
245 }
else if(undefined_values) {
246 gzprintf(my_text_file_p,
"a UNDEFINED\n");
248 if(is_record_attribute) {
249 gzprintf(my_text_file_p, R
"(%s "%s" INTEGER = )", exts_kind.c_str(), full_name.c_str());
251 gzprintf(my_text_file_p,
"a ");
253 if(my_exts_p->get_bitwidth() == 64) {
254 gzprintf(my_text_file_p, scv_tr_TEXT_LLU
"\n", my_exts_p->get_integer());
256 auto tmp_int = (int)my_exts_p->get_integer();
257 gzprintf(my_text_file_p,
"%d\n", tmp_int);
262 case scv_extensions_if::UNSIGNED: {
263 if(declare_attributes) {
264 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"UNSIGNED\")\n",
266 *index, full_name.c_str());
268 }
else if(undefined_values) {
269 gzprintf(my_text_file_p,
"a UNDEFINED\n");
271 if(is_record_attribute) {
272 gzprintf(my_text_file_p, R
"(%s "%s" UNSIGNED = )", exts_kind.c_str(), full_name.c_str());
274 gzprintf(my_text_file_p,
"a ");
276 gzprintf(my_text_file_p, scv_tr_TEXT_LLU
"\n", my_exts_p->get_unsigned());
280 case scv_extensions_if::POINTER: {
281 const scv_extensions_if* field_data_p = my_exts_p->get_pointer();
286 if(declare_attributes) {
287 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"POINTER\")\n",
289 *index, full_name.c_str());
291 }
else if(undefined_values) {
292 gzprintf(my_text_file_p,
"a UNDEFINED\n");
294 if(is_record_attribute) {
295 gzprintf(my_text_file_p, R
"(%s "%s" POINTER = )", exts_kind.c_str(), full_name.c_str());
297 gzprintf(my_text_file_p,
"a ");
299 gzprintf(my_text_file_p,
"%ld\n", (
long)field_data_p);
303 case scv_extensions_if::STRING: {
304 if(declare_attributes) {
305 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"STRING\")\n",
307 *index, full_name.c_str());
309 }
else if(undefined_values) {
310 gzprintf(my_text_file_p,
"a UNDEFINED\n");
312 if(is_record_attribute) {
313 gzprintf(my_text_file_p, R
"(%s "%s" STRING = )", exts_kind.c_str(), full_name.c_str());
315 gzprintf(my_text_file_p,
"a ");
317 gzprintf(my_text_file_p,
"\"%s\"\n", my_exts_p->get_string().c_str());
321 case scv_extensions_if::FLOATING_POINT_NUMBER: {
322 if(declare_attributes) {
323 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"FLOATING_POINT_NUMBER\")\n",
325 *index, full_name.c_str());
327 }
else if(undefined_values) {
328 gzprintf(my_text_file_p,
"a UNDEFINED\n");
330 if(is_record_attribute) {
331 gzprintf(my_text_file_p, R
"(%s "%s" FLOATING_POINT_NUMBER = )", exts_kind.c_str(), full_name.c_str());
333 gzprintf(my_text_file_p,
"a ");
335 gzprintf(my_text_file_p,
"%f\n", my_exts_p->get_double());
339 case scv_extensions_if::BIT_VECTOR: {
340 if(declare_attributes) {
341 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"BIT_VECTOR[%d]\")\n",
343 *index, full_name.c_str(), my_exts_p->get_bitwidth());
345 }
else if(undefined_values) {
346 gzprintf(my_text_file_p,
"a UNDEFINED\n");
348 if(is_record_attribute) {
349 gzprintf(my_text_file_p, R
"(%s "%s" BIT_VECTOR = )", exts_kind.c_str(), full_name.c_str());
351 gzprintf(my_text_file_p,
"a ");
353 sc_bv_base tmp_bv(my_exts_p->get_bitwidth());
354 my_exts_p->get_value(tmp_bv);
355 gzprintf(my_text_file_p,
"\"%s\"\n", tmp_bv.to_string().c_str());
359 case scv_extensions_if::LOGIC_VECTOR: {
360 if(declare_attributes) {
361 gzprintf(my_text_file_p,
"%s (ID %d, name \"%s\", type \"LOGIC_VECTOR[%d]\")\n",
363 *index, full_name.c_str(), my_exts_p->get_bitwidth());
365 }
else if(undefined_values) {
366 gzprintf(my_text_file_p,
"a UNDEFINED\n");
368 if(is_record_attribute) {
369 gzprintf(my_text_file_p, R
"(%s "%s" LOGIC_VECTOR = )", exts_kind.c_str(), full_name.c_str());
371 gzprintf(my_text_file_p,
"a ");
373 sc_lv_base tmp_lv(my_exts_p->get_bitwidth());
374 my_exts_p->get_value(tmp_lv);
376 gzprintf(my_text_file_p,
"\"%s\"\n", tmp_lv.to_string().c_str());
380 case scv_extensions_if::ARRAY: {
381 int array_elt_index = 0;
383 for(; array_elt_index < my_exts_p->get_array_size(); array_elt_index++) {
385 const scv_extensions_if* field_data_p = my_exts_p->get_array_elt(array_elt_index);
387 do_attributes(declare_attributes, undefined_values, is_record_attribute, prefix_name, exts_kind, field_data_p, index);
392 std::array<char, 100> tmpString{};
393 sprintf(tmpString.data(),
"Unsupported attribute type = %d", my_exts_p->get_type());
395 _scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL, tmpString.data());
402 static void scv_tr_generator_cbf(
const scv_tr_generator_base& g, scv_tr_generator_base::callback_reason reason,
void* user_data_p) {
403 if(reason != scv_tr_generator_base::CREATE) {
407 if(my_text_file_p ==
nullptr)
410 gzprintf(my_text_file_p,
"scv_tr_generator (ID " scv_tr_TEXT_LLU
", name \"%s\", scv_tr_stream " scv_tr_TEXT_LLU
",\n", g.get_id(),
411 g.get_name(), g.get_scv_tr_stream().get_id());
413 std::string exts_kind;
416 const scv_extensions_if* my_begin_exts_p = g.get_begin_exts_p();
417 if(my_begin_exts_p !=
nullptr) {
418 exts_kind =
"begin_attribute";
419 std::string tmp_str = g.get_begin_attribute_name() ? g.get_begin_attribute_name() :
"";
420 do_attributes(
true,
false,
false, tmp_str, exts_kind, my_begin_exts_p, &index);
423 const scv_extensions_if* my_end_exts_p = g.get_end_exts_p();
424 if(my_end_exts_p !=
nullptr) {
425 exts_kind =
"end_attribute";
426 std::string tmp_str = g.get_end_attribute_name() ? g.get_end_attribute_name() :
"";
427 do_attributes(
true,
false,
false, tmp_str, exts_kind, my_end_exts_p, &index);
430 gzprintf(my_text_file_p,
")\n");
435 static void scv_tr_handle_cbf(
const scv_tr_handle& t, scv_tr_handle::callback_reason reason,
void* user_data_p) {
436 if(my_text_file_p ==
nullptr)
446 if(t.get_scv_tr_stream().get_scv_tr_db() ==
nullptr)
448 if(t.get_scv_tr_stream().get_scv_tr_db()->get_recording() ==
false)
451 const scv_extensions_if* my_exts_p;
455 case scv_tr_handle::BEGIN: {
457 gzprintf(my_text_file_p,
"tx_begin " scv_tr_TEXT_LLU
" " scv_tr_TEXT_LLU
" %s\n", t.get_id(),
458 t.get_scv_tr_generator_base().get_id(), t.get_begin_sc_time().to_string().c_str());
460 my_exts_p = t.get_begin_exts_p();
462 std::string exts_kind =
"begin_attributes";
463 bool default_values =
false;
465 if(my_exts_p ==
nullptr) {
467 my_exts_p = t.get_scv_tr_generator_base().get_begin_exts_p();
468 default_values =
true;
471 std::string tmp_str =
472 t.get_scv_tr_generator_base().get_begin_attribute_name() ? t.get_scv_tr_generator_base().get_begin_attribute_name() :
"";
474 do_attributes(
false, default_values,
false, tmp_str, exts_kind, my_exts_p, &i);
478 case scv_tr_handle::END: {
480 gzprintf(my_text_file_p,
"tx_end " scv_tr_TEXT_LLU
" " scv_tr_TEXT_LLU
" %s\n", t.get_id(), t.get_scv_tr_generator_base().get_id(),
481 t.get_end_sc_time().to_string().c_str());
483 my_exts_p = t.get_end_exts_p();
485 std::string exts_kind =
"end_attributes";
486 bool default_values =
false;
488 if(my_exts_p ==
nullptr) {
490 my_exts_p = t.get_scv_tr_generator_base().get_end_exts_p();
491 default_values =
true;
494 std::string tmp_str =
495 t.get_scv_tr_generator_base().get_end_attribute_name() ? t.get_scv_tr_generator_base().get_end_attribute_name() :
"";
497 do_attributes(
false, default_values,
false, tmp_str, exts_kind, my_exts_p, &i);
506 static void scv_tr_handle_record_attribute_cbf(
const scv_tr_handle& t,
const char* attribute_name,
const scv_extensions_if* my_exts_p,
510 if(t.get_scv_tr_stream().get_scv_tr_db() ==
nullptr)
512 if(t.get_scv_tr_stream().get_scv_tr_db()->get_recording() ==
false)
515 if(my_text_file_p ==
nullptr)
520 if(attribute_name ==
nullptr) {
523 tmp_str = attribute_name;
526 std::array<char, 100> tmp_str2{};
527 sprintf(tmp_str2.data(),
"tx_record_attribute " scv_tr_TEXT_LLU, t.get_id());
528 std::string exts_kind = tmp_str2.data();
530 do_attributes(
false,
false,
true, tmp_str, exts_kind, my_exts_p,
nullptr);
535 static void scv_tr_handle_relation_cbf(
const scv_tr_handle& tr_1,
const scv_tr_handle& tr_2,
void* user_data_p,
536 scv_tr_relation_handle_t relation_handle) {
539 if(tr_1.get_scv_tr_stream().get_scv_tr_db() ==
nullptr)
541 if(tr_1.get_scv_tr_stream().get_scv_tr_db()->get_recording() ==
false)
544 if(my_text_file_p ==
nullptr)
548 gzprintf(my_text_file_p,
"tx_relation \"%s\" " scv_tr_TEXT_LLU
" " scv_tr_TEXT_LLU
"\n",
549 tr_1.get_scv_tr_stream().get_scv_tr_db()->get_relation_name(relation_handle), tr_1.get_id(), tr_2.get_id());
557 scv_tr_db::register_class_cb(scv_tr_db_cbf);
558 scv_tr_stream::register_class_cb(scv_tr_stream_cbf);
559 scv_tr_generator_base::register_class_cb(scv_tr_generator_cbf);
560 scv_tr_handle::register_class_cb(scv_tr_handle_cbf);
561 scv_tr_handle::register_record_attribute_cb(scv_tr_handle_record_attribute_cbf);
562 scv_tr_handle::register_relation_cb(scv_tr_handle_relation_cbf);
SystemC Verification Library (SCV) Transaction Recording.
void scv_tr_compressed_init()
initializes the infrastructure to use a gzip compressed text based transaction recording database