Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21602 Discussions

LOC Program for VHDL

Altera_Forum
Honored Contributor II
1,826 Views

Hey Guys. I've been asked to count the number of lines of code (LOC) for VHDL. I need to count the physicial lines of code, logical lines of code, and also the number of commented lines. 

 

Anyone have any ideas on an algorithm I can use for this?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
1,185 Views

 

--- Quote Start ---  

I've been asked to count the number of lines of code (LOC) for VHDL. I need to count the physicial lines of code, logical lines of code, and also the number of commented lines. 

 

Anyone have any ideas on an algorithm I can use for this? 

--- Quote End ---  

There is likely a unix tool that already does most of this, eg. awk or sed. 

 

Alternatively write a Perl/Tcl/bash script that parses a file a line at a time, and decides whether the line is a comment, space, or code. 

 

However, distinguishing the lines of VHDL code as being logical might be a little difficult or meaningless, since the following line of code: 

 

c <= a and b; can also be written as 

 

process(a,b) begin if ((a = '1') and (b = '1')) then c <= '1'; else c <= '0'; end if; end process;  

 

Ideally you should 'count' the second form as one line of 'logical' code right? 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,185 Views

The limited significance of LLOC measures isn't specific to VHDL. Counting executable statements gives some information about the code's complexity, it can't take account for different levels of verbosity that exist in all programming languages.

0 Kudos
Altera_Forum
Honored Contributor II
1,185 Views

 

--- Quote Start ---  

The limited significance of LLOC measures isn't specific to VHDL. Counting executable statements gives some information about the code's complexity, it can't take account for different levels of verbosity that exist in all programming languages. 

--- Quote End ---  

Yes, valid point.  

 

The comment: 

 

 

--- Quote Start ---  

 

I need to count the physicial lines of code, logical lines of code 

 

--- Quote End ---  

led me to write the two code snippets of identical code, as I think this is an example of the type of code that has a different number of physical lines than logic lines.  

 

In this case, could he count the number of lines in the RTL code generated by Quartus after synthesis? Probably not, since there is often a lot of redundant connections in the Altera code (where signals are simply renamed). 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,185 Views

I'm not very familiar with LLOC calculation algorithms, but as a first guess, I would assume 1 for the first and 4 for the second example. Counting terminating ';' may be sufficient. 

 

Logical lines of code aren't related to generated number of machine instructions for a processor or FPGA gate level net lists, I think.
0 Kudos
Reply