You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

443 lines
12 KiB

7 months ago
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/LICENSE
  3. (function() {
  4. var mode = CodeMirror.getMode({indentUnit: 4}, "verilog");
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  6. MT("binary_literals",
  7. "[number 1'b0]",
  8. "[number 1'b1]",
  9. "[number 1'bx]",
  10. "[number 1'bz]",
  11. "[number 1'bX]",
  12. "[number 1'bZ]",
  13. "[number 1'B0]",
  14. "[number 1'B1]",
  15. "[number 1'Bx]",
  16. "[number 1'Bz]",
  17. "[number 1'BX]",
  18. "[number 1'BZ]",
  19. "[number 1'b0]",
  20. "[number 1'b1]",
  21. "[number 2'b01]",
  22. "[number 2'bxz]",
  23. "[number 2'b11]",
  24. "[number 2'b10]",
  25. "[number 2'b1Z]",
  26. "[number 12'b0101_0101_0101]",
  27. "[number 1'b 0]",
  28. "[number 'b0101]"
  29. );
  30. MT("octal_literals",
  31. "[number 3'o7]",
  32. "[number 3'O7]",
  33. "[number 3'so7]",
  34. "[number 3'SO7]"
  35. );
  36. MT("decimal_literals",
  37. "[number 0]",
  38. "[number 1]",
  39. "[number 7]",
  40. "[number 123_456]",
  41. "[number 'd33]",
  42. "[number 8'd255]",
  43. "[number 8'D255]",
  44. "[number 8'sd255]",
  45. "[number 8'SD255]",
  46. "[number 32'd123]",
  47. "[number 32 'd123]",
  48. "[number 32 'd 123]"
  49. );
  50. MT("hex_literals",
  51. "[number 4'h0]",
  52. "[number 4'ha]",
  53. "[number 4'hF]",
  54. "[number 4'hx]",
  55. "[number 4'hz]",
  56. "[number 4'hX]",
  57. "[number 4'hZ]",
  58. "[number 32'hdc78]",
  59. "[number 32'hDC78]",
  60. "[number 32 'hDC78]",
  61. "[number 32'h DC78]",
  62. "[number 32 'h DC78]",
  63. "[number 32'h44x7]",
  64. "[number 32'hFFF?]"
  65. );
  66. MT("real_number_literals",
  67. "[number 1.2]",
  68. "[number 0.1]",
  69. "[number 2394.26331]",
  70. "[number 1.2E12]",
  71. "[number 1.2e12]",
  72. "[number 1.30e-2]",
  73. "[number 0.1e-0]",
  74. "[number 23E10]",
  75. "[number 29E-2]",
  76. "[number 236.123_763_e-12]"
  77. );
  78. MT("operators",
  79. "[meta ^]"
  80. );
  81. MT("keywords",
  82. "[keyword logic]",
  83. "[keyword logic] [variable foo]",
  84. "[keyword reg] [variable abc]"
  85. );
  86. MT("variables",
  87. "[variable _leading_underscore]",
  88. "[variable _if]",
  89. "[number 12] [variable foo]",
  90. "[variable foo] [number 14]"
  91. );
  92. MT("tick_defines",
  93. "[def `FOO]",
  94. "[def `foo]",
  95. "[def `FOO_bar]"
  96. );
  97. MT("system_calls",
  98. "[meta $display]",
  99. "[meta $vpi_printf]"
  100. );
  101. MT("line_comment", "[comment // Hello world]");
  102. // Alignment tests
  103. MT("align_port_map_style1",
  104. /**
  105. * mod mod(.a(a),
  106. * .b(b)
  107. * );
  108. */
  109. "[variable mod] [variable mod][bracket (].[variable a][bracket (][variable a][bracket )],",
  110. " .[variable b][bracket (][variable b][bracket )]",
  111. " [bracket )];",
  112. ""
  113. );
  114. MT("align_port_map_style2",
  115. /**
  116. * mod mod(
  117. * .a(a),
  118. * .b(b)
  119. * );
  120. */
  121. "[variable mod] [variable mod][bracket (]",
  122. " .[variable a][bracket (][variable a][bracket )],",
  123. " .[variable b][bracket (][variable b][bracket )]",
  124. "[bracket )];",
  125. ""
  126. );
  127. MT("align_assignments",
  128. /**
  129. * always @(posedge clk) begin
  130. * if (rst)
  131. * data_out <= 8'b0 +
  132. * 8'b1;
  133. * else
  134. * data_out = 8'b0 +
  135. * 8'b1;
  136. * data_out =
  137. * 8'b0 + 8'b1;
  138. * end
  139. */
  140. "[keyword always] [def @][bracket (][keyword posedge] [variable clk][bracket )] [keyword begin]",
  141. " [keyword if] [bracket (][variable rst][bracket )]",
  142. " [variable data_out] [meta <=] [number 8'b0] [meta +]",
  143. " [number 8'b1];",
  144. " [keyword else]",
  145. " [variable data_out] [meta =] [number 8'b0] [meta +]",
  146. " [number 8'b1];",
  147. " [variable data_out] [meta =] [number 8'b0] [meta +]",
  148. " [number 8'b1];",
  149. "[keyword end]",
  150. ""
  151. );
  152. // Indentation tests
  153. MT("indent_single_statement_if",
  154. "[keyword if] [bracket (][variable foo][bracket )]",
  155. " [keyword break];",
  156. ""
  157. );
  158. MT("no_indent_after_single_line_if",
  159. "[keyword if] [bracket (][variable foo][bracket )] [keyword break];",
  160. ""
  161. );
  162. MT("indent_after_if_begin_same_line",
  163. "[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
  164. " [keyword break];",
  165. " [keyword break];",
  166. "[keyword end]",
  167. ""
  168. );
  169. MT("indent_after_if_begin_next_line",
  170. "[keyword if] [bracket (][variable foo][bracket )]",
  171. " [keyword begin]",
  172. " [keyword break];",
  173. " [keyword break];",
  174. " [keyword end]",
  175. ""
  176. );
  177. MT("indent_single_statement_if_else",
  178. "[keyword if] [bracket (][variable foo][bracket )]",
  179. " [keyword break];",
  180. "[keyword else]",
  181. " [keyword break];",
  182. ""
  183. );
  184. MT("indent_if_else_begin_same_line",
  185. "[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
  186. " [keyword break];",
  187. " [keyword break];",
  188. "[keyword end] [keyword else] [keyword begin]",
  189. " [keyword break];",
  190. " [keyword break];",
  191. "[keyword end]",
  192. ""
  193. );
  194. MT("indent_if_else_begin_next_line",
  195. "[keyword if] [bracket (][variable foo][bracket )]",
  196. " [keyword begin]",
  197. " [keyword break];",
  198. " [keyword break];",
  199. " [keyword end]",
  200. "[keyword else]",
  201. " [keyword begin]",
  202. " [keyword break];",
  203. " [keyword break];",
  204. " [keyword end]",
  205. ""
  206. );
  207. MT("indent_if_nested_without_begin",
  208. "[keyword if] [bracket (][variable foo][bracket )]",
  209. " [keyword if] [bracket (][variable foo][bracket )]",
  210. " [keyword if] [bracket (][variable foo][bracket )]",
  211. " [keyword break];",
  212. ""
  213. );
  214. MT("indent_case",
  215. "[keyword case] [bracket (][variable state][bracket )]",
  216. " [variable FOO]:",
  217. " [keyword break];",
  218. " [variable BAR]:",
  219. " [keyword break];",
  220. "[keyword endcase]",
  221. ""
  222. );
  223. MT("unindent_after_end_with_preceding_text",
  224. "[keyword begin]",
  225. " [keyword break]; [keyword end]",
  226. ""
  227. );
  228. MT("export_function_one_line_does_not_indent",
  229. "[keyword export] [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
  230. ""
  231. );
  232. MT("export_task_one_line_does_not_indent",
  233. "[keyword export] [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
  234. ""
  235. );
  236. MT("export_function_two_lines_indents_properly",
  237. "[keyword export]",
  238. " [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
  239. ""
  240. );
  241. MT("export_task_two_lines_indents_properly",
  242. "[keyword export]",
  243. " [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
  244. ""
  245. );
  246. MT("import_function_one_line_does_not_indent",
  247. "[keyword import] [string \"DPI-C\"] [keyword function] [variable helloFromC];",
  248. ""
  249. );
  250. MT("import_task_one_line_does_not_indent",
  251. "[keyword import] [string \"DPI-C\"] [keyword task] [variable helloFromC];",
  252. ""
  253. );
  254. MT("import_package_single_line_does_not_indent",
  255. "[keyword import] [variable p]::[variable x];",
  256. "[keyword import] [variable p]::[variable y];",
  257. ""
  258. );
  259. MT("covergroup_with_function_indents_properly",
  260. "[keyword covergroup] [variable cg] [keyword with] [keyword function] [variable sample][bracket (][keyword bit] [variable b][bracket )];",
  261. " [variable c] : [keyword coverpoint] [variable c];",
  262. "[keyword endgroup]: [variable cg]",
  263. ""
  264. );
  265. MT("indent_uvm_macros",
  266. /**
  267. * `uvm_object_utils_begin(foo)
  268. * `uvm_field_event(foo, UVM_ALL_ON)
  269. * `uvm_object_utils_end
  270. */
  271. "[def `uvm_object_utils_begin][bracket (][variable foo][bracket )]",
  272. " [def `uvm_field_event][bracket (][variable foo], [variable UVM_ALL_ON][bracket )]",
  273. "[def `uvm_object_utils_end]",
  274. ""
  275. );
  276. MT("indent_uvm_macros2",
  277. /**
  278. * `uvm_do_with(mem_read,{
  279. * bar_nb == 0;
  280. * })
  281. */
  282. "[def `uvm_do_with][bracket (][variable mem_read],[bracket {]",
  283. " [variable bar_nb] [meta ==] [number 0];",
  284. "[bracket })]",
  285. ""
  286. );
  287. MT("indent_wait_disable_fork",
  288. /**
  289. * virtual task body();
  290. * repeat (20) begin
  291. * fork
  292. * `uvm_create_on(t,p_seq)
  293. * join_none
  294. * end
  295. * wait fork;
  296. * disable fork;
  297. * endtask : body
  298. */
  299. "[keyword virtual] [keyword task] [variable body][bracket ()];",
  300. " [keyword repeat] [bracket (][number 20][bracket )] [keyword begin]",
  301. " [keyword fork]",
  302. " [def `uvm_create_on][bracket (][variable t],[variable p_seq][bracket )]",
  303. " [keyword join_none]",
  304. " [keyword end]",
  305. " [keyword wait] [keyword fork];",
  306. " [keyword disable] [keyword fork];",
  307. "[keyword endtask] : [variable body]",
  308. ""
  309. );
  310. MT("indent_typedef_class",
  311. /**
  312. * typedef class asdf;
  313. * typedef p p_t[];
  314. * typedef enum {
  315. * ASDF
  316. * } t;
  317. */
  318. "[keyword typedef] [keyword class] [variable asdf];",
  319. "[keyword typedef] [variable p] [variable p_t][bracket [[]]];",
  320. "[keyword typedef] [keyword enum] [bracket {]",
  321. " [variable ASDF]",
  322. "[bracket }] [variable t];",
  323. ""
  324. );
  325. MT("indent_case_with_macro",
  326. /**
  327. * // It should be assumed that Macros can have ';' inside, or 'begin'/'end' blocks.
  328. * // As such, 'case' statement should indent correctly with macros inside.
  329. * case(foo)
  330. * ASDF : this.foo = seqNum;
  331. * ABCD : `update(f)
  332. * EFGH : `update(g)
  333. * endcase
  334. */
  335. "[keyword case][bracket (][variable foo][bracket )]",
  336. " [variable ASDF] : [keyword this].[variable foo] [meta =] [variable seqNum];",
  337. " [variable ABCD] : [def `update][bracket (][variable f][bracket )]",
  338. " [variable EFGH] : [def `update][bracket (][variable g][bracket )]",
  339. "[keyword endcase]",
  340. ""
  341. );
  342. MT("indent_extern_function",
  343. /**
  344. * extern virtual function void do(ref packet trans);
  345. * extern virtual function void do2(ref packet trans);
  346. */
  347. "[keyword extern] [keyword virtual] [keyword function] [keyword void] [variable do1][bracket (][keyword ref] [variable packet] [variable trans][bracket )];",
  348. "[keyword extern] [keyword virtual] [keyword function] [keyword void] [variable do2][bracket (][keyword ref] [variable packet] [variable trans][bracket )];",
  349. ""
  350. );
  351. MT("indent_assignment",
  352. /**
  353. * for (int i=1;i < fun;i++) begin
  354. * foo = 2 << asdf || 11'h35 >> abcd
  355. * && 8'h6 | 1'b1;
  356. * end
  357. */
  358. "[keyword for] [bracket (][keyword int] [variable i][meta =][number 1];[variable i] [meta <] [variable fun];[variable i][meta ++][bracket )] [keyword begin]",
  359. " [variable foo] [meta =] [number 2] [meta <<] [variable asdf] [meta ||] [number 11'h35] [meta >>] [variable abcd]",
  360. " [meta &&] [number 8'h6] [meta |] [number 1'b1];",
  361. "[keyword end]",
  362. ""
  363. );
  364. MT("indent_foreach_constraint",
  365. /**
  366. * `uvm_rand_send_with(wrTlp, {
  367. * length ==1;
  368. * foreach (Data[i]) {
  369. * payload[i] == Data[i];
  370. * }
  371. * })
  372. */
  373. "[def `uvm_rand_send_with][bracket (][variable wrTlp], [bracket {]",
  374. " [variable length] [meta ==][number 1];",
  375. " [keyword foreach] [bracket (][variable Data][bracket [[][variable i][bracket ]])] [bracket {]",
  376. " [variable payload][bracket [[][variable i][bracket ]]] [meta ==] [variable Data][bracket [[][variable i][bracket ]]];",
  377. " [bracket }]",
  378. "[bracket })]",
  379. ""
  380. );
  381. MT("indent_compiler_directives",
  382. /**
  383. * `ifdef DUT
  384. * `else
  385. * `ifndef FOO
  386. * `define FOO
  387. * `endif
  388. * `endif
  389. * `timescale 1ns/1ns
  390. */
  391. "[def `ifdef] [variable DUT]",
  392. "[def `else]",
  393. " [def `ifndef] [variable FOO]",
  394. " [def `define] [variable FOO]",
  395. " [def `endif]",
  396. "[def `endif]",
  397. "[def `timescale] [number 1][variable ns][meta /][number 1][variable ns]",
  398. ""
  399. );
  400. })();