Skip to content

Instantly share code, notes, and snippets.

@swkeever
Created October 30, 2019 23:28
Show Gist options
  • Save swkeever/b4c53f0abc9fd84c782f820eff6c82c7 to your computer and use it in GitHub Desktop.
Save swkeever/b4c53f0abc9fd84c782f820eff6c82c7 to your computer and use it in GitHub Desktop.
SystemVerilog snippets useful for CSE/EE 469
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Test clock": {
"prefix": "mockclk",
"body": [
"logic clk;",
"parameter PERIOD = 100;",
"",
"initial begin",
" clk <= 1;",
" forever #(PERIOD/2) clk <= ~clk;",
"end"
],
"description": "Sets up clock for testbench"
},
"Generate": {
"prefix": "gen",
"body": [
"generate",
" genvar i;",
" for (i = 0; i < ${1:value}; i++) begin : each",
" ${2:moduleName} md (",
" ${3:ports}",
" );",
" end",
"endgenerate"
]
},
"Set up module": {
"prefix": "mdl",
"body": [
"`timescale 1ns/10ps",
"",
"module ${1:moduleName} ();",
" parameter delay = 0.05;",
" ",
"endmodule",
"",
"module ${moduleName}_testbench;",
" parameter delay = 50;",
"",
" ${moduleName} dut ();",
" ",
"endmodule",
""
]
},
"Output logic": {
"prefix": "ol",
"body": "output logic"
},
"Input logic": {
"prefix": "il",
"body": "input logic"
},
"Positive edge clock": {
"prefix": "tick",
"body": [
"@(posedge clk);"
]
},
"Time format": {
"prefix": "tfmt",
"body": [
"// Force %t's to print in a nice format.",
"initial \\$timeformat(-9, 2, \" ns\", 10);"
]
},
"Print": {
"prefix": "print",
"body": "\\$display(\"time: %t -- should ${1:statement}\", \\$time);"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment