Skip to content

Instantly share code, notes, and snippets.

@dvtalk
Last active May 30, 2022 08:05
Show Gist options
  • Select an option

  • Save dvtalk/d600440b083e79b1f7dce7faba56d60d to your computer and use it in GitHub Desktop.

Select an option

Save dvtalk/d600440b083e79b1f7dce7faba56d60d to your computer and use it in GitHub Desktop.
Example of using UVM convert2string() and do_print();
// https://dvtalk.me
// Example of using UVM convert2string() and do_print();
//
// convert2string() prints only the variables information
// do_print() adds decorative information for log file
//
// Especially useful when extending base class and adding new variables
//
class aes_data;
int m_aes_key_length;
aes_enc_mode m_aes_enc_mode;
int m_enc_data_size;
...
//
// print only the variables information
virtual function string convert2string();
string s;
s = super.convert2string();
$sformat(s, "%s m_aes_key_length : %0d bits\n", s, m_aes_key_length);
$sformat(s, "%s m_aes_enc_mode : %0d\n", s, m_aes_enc_mode.name());
$sformat(s, "%s m_enc_data_size : %0d bytes\n", s, m_enc_data_size);
return s;
endfunction: convert2string
//
// adding decorative information
virtual function void do_print(uvm_printer printer);
string s;
s = "";
$sformat(s, "%s----------------------\n", s);
$sformat(s, "%sAES ENCRYPTION DATA\n", s);
$sformat(s, "%s%s",s, convert2string());
$sformat(s, "%s----------------------\n", s);
$display(s);
endfunction: do_print
endclass: aes_data
// Extend class
class aes_nist_kat_vector_data extends aes_data;
int m_test_vector_idx;
//
// adding information for new variable m_test_vector_idx
virtual function string convert2string();
string s;
s = super.convert2string();
$sformat(s, "%s m_test_vector_idx : %0d \n", s, m_test_vector_idx);
return s;
endfunction: convert2string
//
// re use parent class do_print()
virtual function void do_print(uvm_printer printer);
super.do_print(printer);
endfunction: do_print
endclass: aes_nist_kat_vector_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment