verilog.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 regex = hljs.regex;
  10. const KEYWORDS = {
  11. $pattern: /\$?[\w]+(\$[\w]+)*/,
  12. keyword: [
  13. "accept_on",
  14. "alias",
  15. "always",
  16. "always_comb",
  17. "always_ff",
  18. "always_latch",
  19. "and",
  20. "assert",
  21. "assign",
  22. "assume",
  23. "automatic",
  24. "before",
  25. "begin",
  26. "bind",
  27. "bins",
  28. "binsof",
  29. "bit",
  30. "break",
  31. "buf|0",
  32. "bufif0",
  33. "bufif1",
  34. "byte",
  35. "case",
  36. "casex",
  37. "casez",
  38. "cell",
  39. "chandle",
  40. "checker",
  41. "class",
  42. "clocking",
  43. "cmos",
  44. "config",
  45. "const",
  46. "constraint",
  47. "context",
  48. "continue",
  49. "cover",
  50. "covergroup",
  51. "coverpoint",
  52. "cross",
  53. "deassign",
  54. "default",
  55. "defparam",
  56. "design",
  57. "disable",
  58. "dist",
  59. "do",
  60. "edge",
  61. "else",
  62. "end",
  63. "endcase",
  64. "endchecker",
  65. "endclass",
  66. "endclocking",
  67. "endconfig",
  68. "endfunction",
  69. "endgenerate",
  70. "endgroup",
  71. "endinterface",
  72. "endmodule",
  73. "endpackage",
  74. "endprimitive",
  75. "endprogram",
  76. "endproperty",
  77. "endspecify",
  78. "endsequence",
  79. "endtable",
  80. "endtask",
  81. "enum",
  82. "event",
  83. "eventually",
  84. "expect",
  85. "export",
  86. "extends",
  87. "extern",
  88. "final",
  89. "first_match",
  90. "for",
  91. "force",
  92. "foreach",
  93. "forever",
  94. "fork",
  95. "forkjoin",
  96. "function",
  97. "generate|5",
  98. "genvar",
  99. "global",
  100. "highz0",
  101. "highz1",
  102. "if",
  103. "iff",
  104. "ifnone",
  105. "ignore_bins",
  106. "illegal_bins",
  107. "implements",
  108. "implies",
  109. "import",
  110. "incdir",
  111. "include",
  112. "initial",
  113. "inout",
  114. "input",
  115. "inside",
  116. "instance",
  117. "int",
  118. "integer",
  119. "interconnect",
  120. "interface",
  121. "intersect",
  122. "join",
  123. "join_any",
  124. "join_none",
  125. "large",
  126. "let",
  127. "liblist",
  128. "library",
  129. "local",
  130. "localparam",
  131. "logic",
  132. "longint",
  133. "macromodule",
  134. "matches",
  135. "medium",
  136. "modport",
  137. "module",
  138. "nand",
  139. "negedge",
  140. "nettype",
  141. "new",
  142. "nexttime",
  143. "nmos",
  144. "nor",
  145. "noshowcancelled",
  146. "not",
  147. "notif0",
  148. "notif1",
  149. "or",
  150. "output",
  151. "package",
  152. "packed",
  153. "parameter",
  154. "pmos",
  155. "posedge",
  156. "primitive",
  157. "priority",
  158. "program",
  159. "property",
  160. "protected",
  161. "pull0",
  162. "pull1",
  163. "pulldown",
  164. "pullup",
  165. "pulsestyle_ondetect",
  166. "pulsestyle_onevent",
  167. "pure",
  168. "rand",
  169. "randc",
  170. "randcase",
  171. "randsequence",
  172. "rcmos",
  173. "real",
  174. "realtime",
  175. "ref",
  176. "reg",
  177. "reject_on",
  178. "release",
  179. "repeat",
  180. "restrict",
  181. "return",
  182. "rnmos",
  183. "rpmos",
  184. "rtran",
  185. "rtranif0",
  186. "rtranif1",
  187. "s_always",
  188. "s_eventually",
  189. "s_nexttime",
  190. "s_until",
  191. "s_until_with",
  192. "scalared",
  193. "sequence",
  194. "shortint",
  195. "shortreal",
  196. "showcancelled",
  197. "signed",
  198. "small",
  199. "soft",
  200. "solve",
  201. "specify",
  202. "specparam",
  203. "static",
  204. "string",
  205. "strong",
  206. "strong0",
  207. "strong1",
  208. "struct",
  209. "super",
  210. "supply0",
  211. "supply1",
  212. "sync_accept_on",
  213. "sync_reject_on",
  214. "table",
  215. "tagged",
  216. "task",
  217. "this",
  218. "throughout",
  219. "time",
  220. "timeprecision",
  221. "timeunit",
  222. "tran",
  223. "tranif0",
  224. "tranif1",
  225. "tri",
  226. "tri0",
  227. "tri1",
  228. "triand",
  229. "trior",
  230. "trireg",
  231. "type",
  232. "typedef",
  233. "union",
  234. "unique",
  235. "unique0",
  236. "unsigned",
  237. "until",
  238. "until_with",
  239. "untyped",
  240. "use",
  241. "uwire",
  242. "var",
  243. "vectored",
  244. "virtual",
  245. "void",
  246. "wait",
  247. "wait_order",
  248. "wand",
  249. "weak",
  250. "weak0",
  251. "weak1",
  252. "while",
  253. "wildcard",
  254. "wire",
  255. "with",
  256. "within",
  257. "wor",
  258. "xnor",
  259. "xor"
  260. ],
  261. literal: [ 'null' ],
  262. built_in: [
  263. "$finish",
  264. "$stop",
  265. "$exit",
  266. "$fatal",
  267. "$error",
  268. "$warning",
  269. "$info",
  270. "$realtime",
  271. "$time",
  272. "$printtimescale",
  273. "$bitstoreal",
  274. "$bitstoshortreal",
  275. "$itor",
  276. "$signed",
  277. "$cast",
  278. "$bits",
  279. "$stime",
  280. "$timeformat",
  281. "$realtobits",
  282. "$shortrealtobits",
  283. "$rtoi",
  284. "$unsigned",
  285. "$asserton",
  286. "$assertkill",
  287. "$assertpasson",
  288. "$assertfailon",
  289. "$assertnonvacuouson",
  290. "$assertoff",
  291. "$assertcontrol",
  292. "$assertpassoff",
  293. "$assertfailoff",
  294. "$assertvacuousoff",
  295. "$isunbounded",
  296. "$sampled",
  297. "$fell",
  298. "$changed",
  299. "$past_gclk",
  300. "$fell_gclk",
  301. "$changed_gclk",
  302. "$rising_gclk",
  303. "$steady_gclk",
  304. "$coverage_control",
  305. "$coverage_get",
  306. "$coverage_save",
  307. "$set_coverage_db_name",
  308. "$rose",
  309. "$stable",
  310. "$past",
  311. "$rose_gclk",
  312. "$stable_gclk",
  313. "$future_gclk",
  314. "$falling_gclk",
  315. "$changing_gclk",
  316. "$display",
  317. "$coverage_get_max",
  318. "$coverage_merge",
  319. "$get_coverage",
  320. "$load_coverage_db",
  321. "$typename",
  322. "$unpacked_dimensions",
  323. "$left",
  324. "$low",
  325. "$increment",
  326. "$clog2",
  327. "$ln",
  328. "$log10",
  329. "$exp",
  330. "$sqrt",
  331. "$pow",
  332. "$floor",
  333. "$ceil",
  334. "$sin",
  335. "$cos",
  336. "$tan",
  337. "$countbits",
  338. "$onehot",
  339. "$isunknown",
  340. "$fatal",
  341. "$warning",
  342. "$dimensions",
  343. "$right",
  344. "$high",
  345. "$size",
  346. "$asin",
  347. "$acos",
  348. "$atan",
  349. "$atan2",
  350. "$hypot",
  351. "$sinh",
  352. "$cosh",
  353. "$tanh",
  354. "$asinh",
  355. "$acosh",
  356. "$atanh",
  357. "$countones",
  358. "$onehot0",
  359. "$error",
  360. "$info",
  361. "$random",
  362. "$dist_chi_square",
  363. "$dist_erlang",
  364. "$dist_exponential",
  365. "$dist_normal",
  366. "$dist_poisson",
  367. "$dist_t",
  368. "$dist_uniform",
  369. "$q_initialize",
  370. "$q_remove",
  371. "$q_exam",
  372. "$async$and$array",
  373. "$async$nand$array",
  374. "$async$or$array",
  375. "$async$nor$array",
  376. "$sync$and$array",
  377. "$sync$nand$array",
  378. "$sync$or$array",
  379. "$sync$nor$array",
  380. "$q_add",
  381. "$q_full",
  382. "$psprintf",
  383. "$async$and$plane",
  384. "$async$nand$plane",
  385. "$async$or$plane",
  386. "$async$nor$plane",
  387. "$sync$and$plane",
  388. "$sync$nand$plane",
  389. "$sync$or$plane",
  390. "$sync$nor$plane",
  391. "$system",
  392. "$display",
  393. "$displayb",
  394. "$displayh",
  395. "$displayo",
  396. "$strobe",
  397. "$strobeb",
  398. "$strobeh",
  399. "$strobeo",
  400. "$write",
  401. "$readmemb",
  402. "$readmemh",
  403. "$writememh",
  404. "$value$plusargs",
  405. "$dumpvars",
  406. "$dumpon",
  407. "$dumplimit",
  408. "$dumpports",
  409. "$dumpportson",
  410. "$dumpportslimit",
  411. "$writeb",
  412. "$writeh",
  413. "$writeo",
  414. "$monitor",
  415. "$monitorb",
  416. "$monitorh",
  417. "$monitoro",
  418. "$writememb",
  419. "$dumpfile",
  420. "$dumpoff",
  421. "$dumpall",
  422. "$dumpflush",
  423. "$dumpportsoff",
  424. "$dumpportsall",
  425. "$dumpportsflush",
  426. "$fclose",
  427. "$fdisplay",
  428. "$fdisplayb",
  429. "$fdisplayh",
  430. "$fdisplayo",
  431. "$fstrobe",
  432. "$fstrobeb",
  433. "$fstrobeh",
  434. "$fstrobeo",
  435. "$swrite",
  436. "$swriteb",
  437. "$swriteh",
  438. "$swriteo",
  439. "$fscanf",
  440. "$fread",
  441. "$fseek",
  442. "$fflush",
  443. "$feof",
  444. "$fopen",
  445. "$fwrite",
  446. "$fwriteb",
  447. "$fwriteh",
  448. "$fwriteo",
  449. "$fmonitor",
  450. "$fmonitorb",
  451. "$fmonitorh",
  452. "$fmonitoro",
  453. "$sformat",
  454. "$sformatf",
  455. "$fgetc",
  456. "$ungetc",
  457. "$fgets",
  458. "$sscanf",
  459. "$rewind",
  460. "$ftell",
  461. "$ferror"
  462. ]
  463. };
  464. const BUILT_IN_CONSTANTS = [
  465. "__FILE__",
  466. "__LINE__"
  467. ];
  468. const DIRECTIVES = [
  469. "begin_keywords",
  470. "celldefine",
  471. "default_nettype",
  472. "default_decay_time",
  473. "default_trireg_strength",
  474. "define",
  475. "delay_mode_distributed",
  476. "delay_mode_path",
  477. "delay_mode_unit",
  478. "delay_mode_zero",
  479. "else",
  480. "elsif",
  481. "end_keywords",
  482. "endcelldefine",
  483. "endif",
  484. "ifdef",
  485. "ifndef",
  486. "include",
  487. "line",
  488. "nounconnected_drive",
  489. "pragma",
  490. "resetall",
  491. "timescale",
  492. "unconnected_drive",
  493. "undef",
  494. "undefineall"
  495. ];
  496. return {
  497. name: 'Verilog',
  498. aliases: [
  499. 'v',
  500. 'sv',
  501. 'svh'
  502. ],
  503. case_insensitive: false,
  504. keywords: KEYWORDS,
  505. contains: [
  506. hljs.C_BLOCK_COMMENT_MODE,
  507. hljs.C_LINE_COMMENT_MODE,
  508. hljs.QUOTE_STRING_MODE,
  509. {
  510. scope: 'number',
  511. contains: [ hljs.BACKSLASH_ESCAPE ],
  512. variants: [
  513. { begin: /\b((\d+'([bhodBHOD]))[0-9xzXZa-fA-F_]+)/ },
  514. { begin: /\B(('([bhodBHOD]))[0-9xzXZa-fA-F_]+)/ },
  515. { // decimal
  516. begin: /\b[0-9][0-9_]*/,
  517. relevance: 0
  518. }
  519. ]
  520. },
  521. /* parameters to instances */
  522. {
  523. scope: 'variable',
  524. variants: [
  525. { begin: '#\\((?!parameter).+\\)' },
  526. {
  527. begin: '\\.\\w+',
  528. relevance: 0
  529. }
  530. ]
  531. },
  532. {
  533. scope: 'variable.constant',
  534. match: regex.concat(/`/, regex.either(...BUILT_IN_CONSTANTS)),
  535. },
  536. {
  537. scope: 'meta',
  538. begin: regex.concat(/`/, regex.either(...DIRECTIVES)),
  539. end: /$|\/\/|\/\*/,
  540. returnEnd: true,
  541. keywords: DIRECTIVES
  542. }
  543. ]
  544. };
  545. }
  546. module.exports = verilog;