verilog.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Language: Verilog
  3. Author: Jon Evans <jon@craftyjon.com>
  4. Contributors: Boone Severson <boone.severson@gmail.com>
  5. Description: Verilog is a hardware description language used in electronic design automation to describe digital and mixed-signal systems. This highlighter supports Verilog and SystemVerilog through IEEE 1800-2012.
  6. Website: http://www.verilog.com
  7. */
  8. function verilog(hljs) {
  9. const SV_KEYWORDS = {
  10. $pattern: /[\w\$]+/,
  11. keyword:
  12. 'accept_on alias always always_comb always_ff always_latch and assert assign ' +
  13. 'assume automatic before begin bind bins binsof bit break buf|0 bufif0 bufif1 ' +
  14. 'byte case casex casez cell chandle checker class clocking cmos config const ' +
  15. 'constraint context continue cover covergroup coverpoint cross deassign default ' +
  16. 'defparam design disable dist do edge else end endcase endchecker endclass ' +
  17. 'endclocking endconfig endfunction endgenerate endgroup endinterface endmodule ' +
  18. 'endpackage endprimitive endprogram endproperty endspecify endsequence endtable ' +
  19. 'endtask enum event eventually expect export extends extern final first_match for ' +
  20. 'force foreach forever fork forkjoin function generate|5 genvar global highz0 highz1 ' +
  21. 'if iff ifnone ignore_bins illegal_bins implements implies import incdir include ' +
  22. 'initial inout input inside instance int integer interconnect interface intersect ' +
  23. 'join join_any join_none large let liblist library local localparam logic longint ' +
  24. 'macromodule matches medium modport module nand negedge nettype new nexttime nmos ' +
  25. 'nor noshowcancelled not notif0 notif1 or output package packed parameter pmos ' +
  26. 'posedge primitive priority program property protected pull0 pull1 pulldown pullup ' +
  27. 'pulsestyle_ondetect pulsestyle_onevent pure rand randc randcase randsequence rcmos ' +
  28. 'real realtime ref reg reject_on release repeat restrict return rnmos rpmos rtran ' +
  29. 'rtranif0 rtranif1 s_always s_eventually s_nexttime s_until s_until_with scalared ' +
  30. 'sequence shortint shortreal showcancelled signed small soft solve specify specparam ' +
  31. 'static string strong strong0 strong1 struct super supply0 supply1 sync_accept_on ' +
  32. 'sync_reject_on table tagged task this throughout time timeprecision timeunit tran ' +
  33. 'tranif0 tranif1 tri tri0 tri1 triand trior trireg type typedef union unique unique0 ' +
  34. 'unsigned until until_with untyped use uwire var vectored virtual void wait wait_order ' +
  35. 'wand weak weak0 weak1 while wildcard wire with within wor xnor xor',
  36. literal:
  37. 'null',
  38. built_in:
  39. '$finish $stop $exit $fatal $error $warning $info $realtime $time $printtimescale ' +
  40. '$bitstoreal $bitstoshortreal $itor $signed $cast $bits $stime $timeformat ' +
  41. '$realtobits $shortrealtobits $rtoi $unsigned $asserton $assertkill $assertpasson ' +
  42. '$assertfailon $assertnonvacuouson $assertoff $assertcontrol $assertpassoff ' +
  43. '$assertfailoff $assertvacuousoff $isunbounded $sampled $fell $changed $past_gclk ' +
  44. '$fell_gclk $changed_gclk $rising_gclk $steady_gclk $coverage_control ' +
  45. '$coverage_get $coverage_save $set_coverage_db_name $rose $stable $past ' +
  46. '$rose_gclk $stable_gclk $future_gclk $falling_gclk $changing_gclk $display ' +
  47. '$coverage_get_max $coverage_merge $get_coverage $load_coverage_db $typename ' +
  48. '$unpacked_dimensions $left $low $increment $clog2 $ln $log10 $exp $sqrt $pow ' +
  49. '$floor $ceil $sin $cos $tan $countbits $onehot $isunknown $fatal $warning ' +
  50. '$dimensions $right $high $size $asin $acos $atan $atan2 $hypot $sinh $cosh ' +
  51. '$tanh $asinh $acosh $atanh $countones $onehot0 $error $info $random ' +
  52. '$dist_chi_square $dist_erlang $dist_exponential $dist_normal $dist_poisson ' +
  53. '$dist_t $dist_uniform $q_initialize $q_remove $q_exam $async$and$array ' +
  54. '$async$nand$array $async$or$array $async$nor$array $sync$and$array ' +
  55. '$sync$nand$array $sync$or$array $sync$nor$array $q_add $q_full $psprintf ' +
  56. '$async$and$plane $async$nand$plane $async$or$plane $async$nor$plane ' +
  57. '$sync$and$plane $sync$nand$plane $sync$or$plane $sync$nor$plane $system ' +
  58. '$display $displayb $displayh $displayo $strobe $strobeb $strobeh $strobeo ' +
  59. '$write $readmemb $readmemh $writememh $value$plusargs ' +
  60. '$dumpvars $dumpon $dumplimit $dumpports $dumpportson $dumpportslimit ' +
  61. '$writeb $writeh $writeo $monitor $monitorb $monitorh $monitoro $writememb ' +
  62. '$dumpfile $dumpoff $dumpall $dumpflush $dumpportsoff $dumpportsall ' +
  63. '$dumpportsflush $fclose $fdisplay $fdisplayb $fdisplayh $fdisplayo ' +
  64. '$fstrobe $fstrobeb $fstrobeh $fstrobeo $swrite $swriteb $swriteh ' +
  65. '$swriteo $fscanf $fread $fseek $fflush $feof $fopen $fwrite $fwriteb ' +
  66. '$fwriteh $fwriteo $fmonitor $fmonitorb $fmonitorh $fmonitoro $sformat ' +
  67. '$sformatf $fgetc $ungetc $fgets $sscanf $rewind $ftell $ferror'
  68. };
  69. return {
  70. name: 'Verilog',
  71. aliases: [
  72. 'v',
  73. 'sv',
  74. 'svh'
  75. ],
  76. case_insensitive: false,
  77. keywords: SV_KEYWORDS,
  78. contains: [
  79. hljs.C_BLOCK_COMMENT_MODE,
  80. hljs.C_LINE_COMMENT_MODE,
  81. hljs.QUOTE_STRING_MODE,
  82. {
  83. className: 'number',
  84. contains: [ hljs.BACKSLASH_ESCAPE ],
  85. variants: [
  86. {
  87. begin: '\\b((\\d+\'(b|h|o|d|B|H|O|D))[0-9xzXZa-fA-F_]+)'
  88. },
  89. {
  90. begin: '\\B((\'(b|h|o|d|B|H|O|D))[0-9xzXZa-fA-F_]+)'
  91. },
  92. {
  93. begin: '\\b([0-9_])+',
  94. relevance: 0
  95. }
  96. ]
  97. },
  98. /* parameters to instances */
  99. {
  100. className: 'variable',
  101. variants: [
  102. {
  103. begin: '#\\((?!parameter).+\\)'
  104. },
  105. {
  106. begin: '\\.\\w+',
  107. relevance: 0
  108. }
  109. ]
  110. },
  111. {
  112. className: 'meta',
  113. begin: '`',
  114. end: '$',
  115. keywords: {
  116. 'meta-keyword':
  117. 'define __FILE__ ' +
  118. '__LINE__ begin_keywords celldefine default_nettype define ' +
  119. 'else elsif end_keywords endcelldefine endif ifdef ifndef ' +
  120. 'include line nounconnected_drive pragma resetall timescale ' +
  121. 'unconnected_drive undef undefineall'
  122. },
  123. relevance: 0
  124. }
  125. ]
  126. };
  127. }
  128. module.exports = verilog;