verilog.js 10 KB

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