Search code examples
syntaxvhdlfpgaebnf

Entity syntax in VHDL


I'm confused about the syntax for an entity in VHDL. Here is the rule in the EBN form how the entity should be declared:

enter image description here

Source: Peter J. Ashenden, "The Designers Guide to VHDL", 3rd ed., Morgan Kaufmann, 2008.

What I'm confused about is the end of the declaration. According to this, I don't need to include entity or identifier at the end, and everything would work just the same. For example, are the two declarations below just the same?

Declaration 1

entity identifier is
    ...
begin
    ...
end ;

Declaration 2

entity identifier is
    ...
begin
    ...
end entity identifier ;

If yes, why would anyone opt for the latter declaration? Is there a recommendation which of the two variants should I use? I'm asking this because I usually see the latter declaration in examples, and I can't explain myself why would anyone prefer the second declaration over the first one.


Solution

  • I would nearly always use the latter declaration because it results in better-documented code. With the former, if the reader comes across a simple end;, it is not crystal clear what is being ended.

    When using less verbose languages than VHDL, programmers (in general) often add comments to constructs that close something off in order to show the reader what is being closed off, eg in C++:

    } // if (enable) 
    

    or in Verilog

    end // if (enable) 
    

    SystemVerilog adds a facility of doing the same thing in the language proper:

    if (enable)
        begin : enable_block
        ...
        end : enable_block
    

    The reason why you can say all these in VHDL

    end ;
    end entity ;
    end identifier ;
    end entity identifier ;
    

    is to make VHDL-93 backwards compatible with VHDL-87, in which only these are legal:

    end ;
    end identifier ;
    

    "Nearly always"? Yes. Were I writing executable code, I would always write the latter. However, I have created some PowerPoint slides about VHDL this week where I deliberately wrote just end; because I thought the whole end entity identifier ; distracted the reader. You can make of that what you will.