CSE260 VHDL Style Guide

Getting the computer to understand your code is no guarantee that people will be able to follow it. Just as you would edit an English composition, you should spend time revising your VHDL code to make it elegant and readable. The following guidelines will help you write code that is easy to read and modify.

1. Include a header comment at the top of each file.

The file header should include some standard information, followed by a brief description of the contents of the file and any special assumptions you have made.

2. Write self-documenting code.

3. Follow standard formatting conventions.

code inside begin/end
indent one level for each level inside a par of begin/end statements
example:
		architecture behavioral of fullAdder is
begin
S <= A xor B xor Ci;
Co <= (A and B) or ((A xor B) and Ci);
end behavioral;
continued lines
when a statement continues across two or more lines, indent the second and remaining lines an equal amount past the start of the first line of the statement.
example:
		architecture behavioral of fullAdder is
begin
S <= A xor B xor Ci;
Co <= (A and B) or
((A xor B) and Ci);
end behavioral;
end
            the end off a block of code goes on a line all its own indented to the level of the begin it is associated with. 

if-elsif-else
the statement(s) following an if, elsif, or else should be indented one level. The else and elsif lines should be at the same level as the initial if that initiated the statement
example:
if select = "00" then
nextValue = "00";
...
elsif select = "01" then
nextValue = "01";
...
else
nextValue = "11";
...
end if;

4. Use inline comments sparingly but whenever necessary.

5. Present your test cases clearly and methodically.

Many of the VHDL problems ask you to prepare a series of test cases to demonstrate that your design behaves in accordance with the specification in the assignment. The following guidelines should be followed in preparing test cases.

6. Use common sense.

Remember that the this VHDL style guide is only a guide. Your primary concern should be making sure that others can read and understand the text of your code. If you think an additional comment or particular organization will get your ideas across more effectively, do it. However, if you are considering deviating significantly from the guidelines or if you are in doubt about something, please discuss it with us first.

Portions stolen from CS101/CS102 style guides.
prepared by David M. Zar, June 20, 2003