Skip to content

Instantly share code, notes, and snippets.

@varunhuliyar
Last active June 7, 2024 14:03
Show Gist options
  • Select an option

  • Save varunhuliyar/ec3c575771887195e1c38686935ca7c3 to your computer and use it in GitHub Desktop.

Select an option

Save varunhuliyar/ec3c575771887195e1c38686935ca7c3 to your computer and use it in GitHub Desktop.
Parsing file in Systemverilog
task parse_file_sv();
int samplefile;
string line_from_file, sub1;
real sub2;
string srcdir;
if($value$plusargs("SRCDIR=%s", srcdir))
`uvm_info(get_name(), $sformatf("+SRCDIR:%s",srcdir),UVM_MEDIUM)
else
`uvm_error(get_name(), $sformatf("+SRCDIR is not passed"));
samplefile=$fopen({srcdir,"/log.txt"},"r");
//check if path of logfile path is valid
if(!samplefile)
`uvm_error(get_name(),{srcdir,"/log.txt missing"})
while(!$feof(samplefile) && $fgets(line_from_file, samplefile)) begin
void'($sscanf(line_from_file, "%s %f\n", sub1, sub2));
`uvm_info(get_name(), $sformatf("sub1=%s,sub2=%0f",sub1,sub2),UVM_MEDIUM)
//operate on collected data or store in stack here
end
$fclose(samplefile);
endtask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment