// Coding Guidelines
- Restrict the code to 100 characters - Use below in your .vimrc file: " Setting the colum width highlight ColorColumn ctermbg=gray set colorcolumn=100
- Only one statement per line. // Variable definition: logic enable; logic completed; logic in_progress;
- Always use a begin-end pair to bracket conditional statements: // Both statements executed conditionally: if(i>0)begin count= current_count; target= current_target; end
- Use lowercase for names, using underscores to separate fields: axi_fabric_scoreboard_error
- Use the end label for classes, functions, tasks etc., called closing identifiers. Ex: function name () endfunction: Name
- Use prefix_ and _postfix to delineate name types: prefix/postfix Purpose _t Used for a type created via a typedef _e Used to indicate a enumerated type _h Used for a class handle _m Used for a protected class member (See guideline 2.2) _cfg Used for a configuration object handle _ap Used for an analysis port handle _group Used for a covergroup handle
- All structs, unions and enums. They should use camelCase with the following distinction: Structs end with _s Unions end with _u Enums end with _e. Additionally, enumerations should use UPPERCASE_WITH_UNDERSCORES. enum { IPV4_TCP, IPV4_UDP} packetType_e;
- Use a descriptive typedef when declaring a variable instead of a built-in type: // Descriptive typedef for a 24 bit audio sample: typedef bit[23:0] audio_sample_t;
- Declare class methods using extern: extern function new(string name); extern function results_t get_results();
- Check that $cast() has succeeded: if(!$cast(t, to_be_cloned.clone())begin `uvm_error("get_a_clone","$cast failed for to_be_cloned") end
- Use "if" rather than "assert" to check the status of method calls.
- Check that randomize() has succeeded: // Using if() to check randomization result // DON'T use assert as they can be turned-off if(!seq_item.randomize() with {addressinside{[0:32'hF000_FC00]};}) begin `uvm_error("seq_name","randomization failure, please check constraints") end
- Always declare functions/tasks to be virtual. Helps in using Polymorphism feature.
- Do not use associative arrays with a wildcard index[]: string names[];// cannot be used with foreach, find_index, ... string names[int];
- Do not use #0 procedural delays: Often, using a non-blocking assignment ( <= ) solves this class of problem.
- Do not use hard-coded values. Always use constants/parameters.
- Always use one-class definition per file.
- Keep the file name same as the class name. You can use more coding guidlines by referring the below link, however, the above mentioned guidelines must be followed!