定制UVM Messages(参考)
UVM的Messages机制有些时候很繁琐,很多时候希望能够在UVM messages的基础上做一些个人化的订制,这里给出来一个找到的例子作为参考。
my_macros.sv:
`define my_info(MSG, VERBOSITY) \
begin \
if(uvm_report_enabled(VERBOSITY,UVM_INFO,get_full_name())) \
uvm_report_info(get_full_name(), $sformatf MSG, 0, `uvm_file, `uvm_line); \
end
`define my_err(MSG) \
begin \
if(uvm_report_enabled(UVM_NONE,UVM_ERROR,get_full_name())) \
uvm_report_error(get_full_name(), $sformatf MSG, UVM_NONE, `uvm_file, `uvm_line); \
end
`define my_warn(MSG) \
begin \
if(uvm_report_enabled(UVM_NONE,UVM_WARNING,get_full_name())) \
uvm_report_warning(get_full_name(), $sformatf MSG, UVM_NONE, `uvm_file, `uvm_line); \
end
`define my_fatal(MSG) \
begin \
if(uvm_report_enabled(UVM_NONE,UVM_FATAL,get_full_name())) \
uvm_report_fatal(get_full_name(), $sformatf MSG, UVM_NONE, `uvm_file, `uvm_line); \
end
my_init.sv:
initial begin
my_report_server_c report_server = new("my_report_server");
if($value$plusargs("fname_width=%d", fwidth)) begin
report_server.file_name_width = fwidth;
end
if($value$plusargs("hier_width=%d", hwidth)) begin
report_server.hier_width = hwidth;
end
uvm_pkg::uvm_report_server::set_server(report_server);
// all "%t" shall print out in ns format with 8 digit field width
$timeformat(-9,0,"ns",8);
end
my_report_server.sv:
class my_report_server_c extends uvm_report_server;
`uvm_object_utils(my_report_server_c)
string filename_cache[string];
string hier_cache[string];
int unsigned file_name_width = 28;
int unsigned hier_width = 60;
uvm_severity_type sev_type;
string prefix, time_str, code_str, fill_char, file_str, hier_str;
int last_slash, flen, hier_len;
function new(string name="my_report_server");
super.new();
endfunction : new
virtual function string compose_message(uvm_severity severity, string name, string id, string message,
string filename, int line);
// format filename & line-number
last_slash = filename.len() - 1;
if(file_name_width > 0) begin
if(filename_cache.exists(filename))
file_str = filename_cache[filename];
else begin
while(filename[last_slash] != "/" && last_slash != 0)
last_slash--;
file_str = (filename[last_slash] == "/")?
filename.substr(last_slash+1, filename.len()-1) :
filename;
flen = file_str.len();
file_str = (flen > file_name_width)?
file_str.substr((flen - file_name_width), flen-1) :
{{(file_name_width-flen){" "}}, file_str};
filename_cache[filename] = file_str;
end
$swrite(file_str, "(%s:%6d) ", file_str, line);
end else
file_str = "";
// format hier
hier_len = id.len();
if(hier_width > 0) begin
if(hier_cache.exists(id))
hier_str = hier_cache[id];
else begin
if(hier_len > 13 && id.substr(0,12) == "uvm_test_top.") begin
id = id.substr(13, hier_len-1);
hier_len -= 13;
end
if(hier_len < hier_width)
hier_str = {id, {(hier_width - hier_len){" "}}};
else if(hier_len > hier_width)
hier_str = id.substr(hier_len - hier_width, hier_len - 1);
else
hier_str = id;
hier_str = {"[", hier_str, "]"};
hier_cache[id] = hier_str;
end
end else
hier_str = "";
// format time
$swrite(time_str, " {%t}", $time);
// determine fill character
sev_type = uvm_severity_type'(severity);
case(sev_type)
UVM_INFO: begin code_str = "%I"; fill_char = " "; end
UVM_ERROR: begin code_str = "%E"; fill_char = "_"; end
UVM_WARNING: begin code_str = "%W"; fill_char = "."; end
UVM_FATAL: begin code_str = "%F"; fill_char = "*"; end
default: begin code_str = "%?"; fill_char = "?"; end
endcase
// create line's prefix (everything up to time)
$swrite(prefix, "%s-%s%s%s", code_str, file_str, hier_str, time_str);
if(fill_char != " ") begin
for(int x = 0; x < prefix.len(); x++)
if(prefix[x] == " ")
prefix.putc(x, fill_char);
end
// append message
return {prefix, " ", message};
endfunction : compose_message
endclass : my_report_server_c