Last active
June 7, 2024 14:03
-
-
Save varunhuliyar/ec3c575771887195e1c38686935ca7c3 to your computer and use it in GitHub Desktop.
Parsing file in Systemverilog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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