Intro

  Welcome to my little website! This is my very first post. On this site I would share some interesting ‘IC-related gadgets’ that I find useful during my current work as a digital verification intern. Stay tuned for my casual scribblings if you’d like!

Overview

  As a hardware engineer, apart from mastering HDL like Verilog and VerilogA etc., understanding one or two software programming languages of personal preference is also important.

  It is agreed that when conducting engineering projects in real practice, description files of which don’t often appear in a concise format. Thus the application of file-processing programs via certain programming languages (e.g Perl) which could convert the original file into a more easy-to-read one (e.g an excel file) becomes necessary.

  Additionally, in projects of large scales, Makefile shows great significance for its ability to lessen operation repetitions and therefore facilitating workflow as well as reducing workload. I’ll elaborate on this matter along with practical operations in FPGA verification as examples in future posts, maybe after I blather a bit about useful Linux commands and gvim in my next few posts.

Perl

  Perl, short for Practical Extraction and Report Language, is a high-level, general-purpose, interpreted, dynamic programming language. When it comes to accessing files, Perl could be a choice worthy of consideration.

Original File

  To begin with, let’s take a glance at what the original description file of an FPGA chip (sensitive information hidden) assigned to me for verification operations looks like.

original description.jpg

Fig.1 Original Description File
  Simply trying to extract logic values for each pin to lay the foundation for future verification work from such abundant information in such a chaotic form would be absolutely exhausting. Let alone summarizing and collating.

Perl Codes

  Below is the code snippet of a program I wrote to process the description file.

  It is worth mentioning that the description file leaves certain numbers of rows containing different amounts of consecutive ‘#’s between the tables and sections describing corresponding contents. Such characteristic could not be fully displayed for confidentiality reasons.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use strict;                
use warnings;
use Spreadsheet::WriteExcel; # Imports the module for creating Excel files.

# The first command-line argument is taken as the source file name
# (which will be specified in the Linux command window when the program is executed).

my $src_file = $ARGV[0];

#The target output file name is generated
#by appending "_align.xls" to the source file name.

my $trgt_file = $src_file."_align.xls";

# Open the source file for reading.
# If it fails, the script dies with an error message.
open my $r_file, "<", $src_file or die "can't open file: $!";

# Create a new Excel workbook with the target file name.
my $workbook = Spreadsheet::WriteExcel->new($trgt_file);

# Add a worksheet to the workbook.
my $worksheet = $workbook->add_worksheet();

# Initialize row counter.
my $row = 0;

# Start reading the source file line by line.
while (<$r_file>) {

chomp; # Removes the newline character from the end of the line.

# Replace '==' and '--' with '*'
# They serve the same purpose in this case, indicating 'default').
s/==|\-\-/*/g;

# Checks if the line starts with '#' and contains a "Section" keyword at the specified location.
# This is for identifying as well as distinguishing each section of the description file
# so that the Excel file could be generated accordingly with clarity.

if (/^#/ && length($_) >= 13 && substr($_, 2, 7) =~ /Section/) {
my $extracted = substr($_, 10, 3);
# Extracts specific characters from the line.
# In this case, the label number of each module which could later be used to locate the table
$worksheet->write($row, 0, $extracted);
# Writes the extracted part into the first column of the current row.
$row++; # Move to the next row.
next; # Skip the rest of the loop and start the next iteration.
}

# If the line starts with '#', skip this line by moving to the next row.
# This consequently creates a blank row in the Excel file for every 'non-table-element' detected,
# ensuring at least one vacant row between tables and several more between sections.
if (/^#/) {
$row++;
next;
}

# Split the line into words separated by whitespace.
my @line = split(/\s+/, $_);

# Iterate over each element in the @line array.
for (my $col = 0; $col < @line; $col++) {
# Write the current element to the corresponding cell in the Excel worksheet.
$worksheet->write($row, $col, $line[$col]);
}
}

# Close the source file after reading.
close $r_file;

# Close the workbook to finish writing to the Excel file.
$workbook->close();

  As annotated, this perl program takes in a file specified by Linux command as input, filters and aligns its contents and outputs an Excel file correspondingly.

Output

  Feed it with the description file we’re given, and this is what we get.

pAVXuKH.png

Fig.2 Processed Excel File
  It's a lot more concise and visually appealing compared to the original one. Moreover, we could directly copy the stats from the file in rows/columns, and transpose/select them in any way we find necessary. This could save us a lot of trouble when we try to write programs based on these batches of numbers in the future.