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.

684 lines
30 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>VHDL Beautifier, Formatter Online</title>
  5. <style>
  6. body {
  7. margin: 0 auto;
  8. max-width: 960px;
  9. tab-size: 4;
  10. font-family: arial, sans-serif;
  11. }
  12. textarea {
  13. width: 100%;
  14. font-family: Consolas, Courier;
  15. }
  16. fieldset {
  17. width: fit-content;
  18. border: 1px solid #9a9a9a;
  19. margin: 25px 0 5px 0;
  20. padding-left: 0;
  21. }
  22. legend {
  23. padding: 2px 5px;
  24. background-color: #e0e0e0;
  25. border-radius: 2px;
  26. margin: -27px 0 0 -1px;
  27. position: absolute;
  28. }
  29. .subtitle {
  30. font-weight: normal;
  31. }
  32. .btn {
  33. margin: 10px 10px;
  34. padding: 5px 8px;
  35. font-size: 16px;
  36. line-height: 1.33;
  37. border-radius: 3px;
  38. color: #333;
  39. border-color: #ccc;
  40. cursor: pointer;
  41. text-align: center;
  42. white-space: nowrap;
  43. border: 1px solid rgb(194, 194, 194);
  44. background-color: #fff;
  45. }
  46. .btn:hover {
  47. background-color: #eee;
  48. }
  49. .show {
  50. display: none;
  51. }
  52. .wordwrap {
  53. white-space: pre-wrap;
  54. white-space: -moz-pre-wrap;
  55. white-space: -pre-wrap;
  56. white-space: -o-pre-wrap;
  57. word-wrap: break-word;
  58. }
  59. label {
  60. cursor: pointer;
  61. line-height: 1.5em;
  62. }
  63. label:hover {
  64. color: #555;
  65. text-decoration: underline;
  66. }
  67. form {
  68. margin-bottom: 0px;
  69. }
  70. form span {
  71. width: 170px;
  72. display: inline-block;
  73. text-align: right;
  74. }
  75. a {
  76. color: #4b9aff;
  77. text-decoration: none;
  78. background: #f0f8ff;
  79. padding: 2px 5px;
  80. border-radius: 3px;
  81. font-size: 0.8em;
  82. cursor: pointer;
  83. }
  84. a:hover {
  85. text-decoration: none;
  86. background: #d6e8ff;
  87. }
  88. p {
  89. line-height: 1em;
  90. margin: 0.5em 0em;
  91. }
  92. .code {
  93. font-family: 'Consolas', Courier, monospace;
  94. }
  95. .inline {
  96. display: inline-block;
  97. }
  98. .disabled {
  99. color: #ccc;
  100. cursor: default;
  101. }
  102. .disabled label:hover {
  103. color: #ccc;
  104. text-decoration: none;
  105. cursor: default;
  106. }
  107. .checkbox input[type="checkbox"] {
  108. opacity: 0;
  109. display: none;
  110. }
  111. .checkbox label {
  112. position: relative;
  113. display: inline-block;
  114. /*16px width of fake checkbox + 6px distance between fake checkbox and text*/
  115. padding-left: 22px;
  116. }
  117. .checkbox label::before,
  118. .checkbox label::after {
  119. position: absolute;
  120. content: "";
  121. /*Needed for the line-height to take effect*/
  122. display: inline-block;
  123. }
  124. /*Outer box of the fake checkbox*/
  125. .checkbox label::before {
  126. height: 16px;
  127. width: 16px;
  128. border: 1px solid #9A9A9A;
  129. left: 0px;
  130. /*(24px line-height - 16px height of fake checkbox) / 2 - 1px for the border to vertically center it.*/
  131. top: 3px;
  132. }
  133. /*Checkmark of the fake checkbox*/
  134. .checkbox label::after {
  135. height: 5px;
  136. width: 9px;
  137. border-left: 2px solid;
  138. border-bottom: 2px solid;
  139. transform: rotate(-45deg);
  140. left: 4px;
  141. top: 7px;
  142. color: #333;
  143. }
  144. /*Hide the checkmark by default*/
  145. .checkbox input[type="checkbox"]+label::after {
  146. content: none;
  147. }
  148. /*Unhide on the checked state*/
  149. .checkbox input[type="checkbox"]:checked+label::after {
  150. content: "";
  151. }
  152. /*Adding focus styles on the outer-box of the fake checkbox*/
  153. .checkbox input[type="checkbox"]:hover+label::after {
  154. border-color: #888;
  155. outline: #ccc;
  156. }
  157. .checkbox input[type="checkbox"]:hover+label::before {
  158. outline: #888;
  159. border-color: #888;
  160. background-color: #eee;
  161. }
  162. .checkbox input[type="checkbox"]:disabled+label::before {
  163. outline: #ccc;
  164. border-color: #ccc;
  165. background-color: #fff;
  166. color: #ccc;
  167. }
  168. .checkbox input[type="checkbox"]:disabled+label::after {
  169. color: #888;
  170. }
  171. .checkbox input[type="checkbox"]:focus+label::before {
  172. outline: #333 auto 5px;
  173. }
  174. .inline-note {
  175. color: #888;
  176. margin-left: 10px;
  177. display: inline-block;
  178. }
  179. .hide {
  180. display: none;
  181. }
  182. #settings_control {
  183. margin: 10px 0px;
  184. display: inline-block;
  185. }
  186. </style>
  187. <link href="highlight.css" rel="stylesheet" />
  188. <script src="highlight.js"></script>
  189. <script>
  190. function selectText(element) {
  191. var doc = document,
  192. text = element,
  193. range, selection;
  194. if (doc.body.createTextRange) { //ms
  195. range = doc.body.createTextRange();
  196. range.moveToElementText(text);
  197. range.select();
  198. } else if (window.getSelection) { //all others
  199. selection = window.getSelection();
  200. range = doc.createRange();
  201. range.selectNodeContents(text);
  202. selection.removeAllRanges();
  203. selection.addRange(range);
  204. }
  205. }
  206. </script>
  207. </head>
  208. <body>
  209. <h2>VHDL Beautifier, Formatter</h2>
  210. <h4 class="subtitle">Beautify and format your VHDL code online</h4>
  211. <p>Proper formatting makes code easier to read and understand.</p>
  212. <p>Please make a backup before you replace your code!</p>
  213. <p style="color:#888">
  214. <a href="https://github.com/g2384/VHDLFormatter#release-notes">Release notes</a>
  215. <a href="https://github.com/g2384/VHDLFormatter/issues/new" target="_blank">Report <span>&#x1f41e;</span> bug</a>
  216. <a href="https://github.com/g2384/VHDLFormatter">Source code</a>
  217. </p>
  218. <textarea id="in" rows="10" wrap="off"></textarea>
  219. <br>
  220. <div class="checkbox">
  221. <input type="checkbox" id="no_format" onclick="noFormat()">
  222. <label for="no_format">Only highlight, don't format</label>
  223. </div>
  224. <form id="keyword_div">Keyword case:
  225. <label>
  226. <input type="radio" name="keywordcase" value="UpperCase" checked="checked">UPPERCASE</label> |
  227. <label>
  228. <input type="radio" name="keywordcase" value="LowerCase">lowercase</label> |
  229. <label>
  230. <input type="radio" name="keywordcase" value="DefaultCase">Default</label>
  231. <div class="inline-note">
  232. e.g. begin, case, when
  233. </div>
  234. </form>
  235. <form id="typename_div">Type name case:
  236. <label>
  237. <input type="radio" name="typenamecase" value="UpperCase" checked="checked">UPPERCASE</label> |
  238. <label>
  239. <input type="radio" name="typenamecase" value="LowerCase">lowercase</label> |
  240. <label>
  241. <input type="radio" name="typenamecase" value="DefaultCase">Default</label>
  242. <div class="inline-note">
  243. e.g. boolean, natural, string
  244. </div>
  245. </form>
  246. <div class="hide" id="settings_div">
  247. <fieldset id="new_line_after_div">
  248. <legend>New line after</legend>
  249. <form id="new_line_after_then">
  250. <span class="code">THEN</span>
  251. <label>
  252. <input type="radio" name="new_line_after_thencase" value="NewLine" checked="checked">New Line</label>
  253. <label>
  254. <input type="radio" name="new_line_after_thencase" value="NoNewLine">No New Line</label>
  255. <label>
  256. <input type="radio" name="new_line_after_thencase" value="None">None</label>
  257. </form>
  258. <form id="new_line_after_semicolon">
  259. <span class="code">semicolon ";"</span>
  260. <label>
  261. <input type="radio" name="new_line_after_semicoloncase" value="NewLine" checked="checked">New Line</label>
  262. <label>
  263. <input type="radio" name="new_line_after_semicoloncase" value="NoNewLine">No New Line</label>
  264. <label>
  265. <input type="radio" name="new_line_after_semicoloncase" value="None">None</label>
  266. </form>
  267. <form id="new_line_after_else">
  268. <span class="code">ELSE</span>
  269. <label>
  270. <input type="radio" name="new_line_after_elsecase" value="NewLine">New Line</label>
  271. <label>
  272. <input type="radio" name="new_line_after_elsecase" value="NoNewLine">No New Line</label>
  273. <label>
  274. <input type="radio" name="new_line_after_elsecase" value="None" checked="checked">None</label>
  275. </form>
  276. <form id="new_line_after_port">
  277. <span class="code">PORT | PORT MAP</span>
  278. <label>
  279. <input type="radio" name="new_line_after_portcase" value="NewLine">New Line</label>
  280. <label>
  281. <input type="radio" name="new_line_after_portcase" value="NoNewLine">No New Line</label>
  282. <label>
  283. <input type="radio" name="new_line_after_portcase" value="None" checked="checked">None</label>
  284. </form>
  285. <form id="new_line_after_generic">
  286. <span class="code">GENERIC</span>
  287. <label>
  288. <input type="radio" name="new_line_after_genericcase" value="NewLine">New Line</label>
  289. <label>
  290. <input type="radio" name="new_line_after_genericcase" value="NoNewLine">No New Line</label>
  291. <label>
  292. <input type="radio" name="new_line_after_genericcase" value="None" checked="checked">None</label>
  293. </form>
  294. </fieldset>
  295. <div class="checkbox inline" id="remove_comments_div">
  296. <input type="checkbox" id="remove_comments">
  297. <label for="remove_comments">Remove commments</label> |
  298. </div>
  299. <div class="checkbox inline" id="remove_lines_div">
  300. <input type="checkbox" id="remove_lines">
  301. <label for="remove_lines">Remove blank lines</label> |
  302. </div>
  303. <div class="checkbox inline" id="remove_report_div">
  304. <input type="checkbox" id="remove_report">
  305. <label for="remove_report">Remove REPORT</label>
  306. </div>
  307. <br>
  308. <div class="checkbox" id="check_alias_div">
  309. <input type="checkbox" id="check_alias">
  310. <label for="check_alias">Check ALIAS (all long names will be replaced by ALIAS names)</label>
  311. </div>
  312. <div id="sign_align_in_div">
  313. Align signs in
  314. <div class="checkbox inline" id="sign_align_port_div">
  315. <input type="checkbox" id="sign_align_port">
  316. <label for="sign_align_port" class="code">PORT()</label>
  317. </div>
  318. <div class="checkbox inline" id="sign_align_generic_div">
  319. <input type="checkbox" id="sign_align_generic">
  320. <label for="sign_align_generic" class="code">GENERIC()</label></div>
  321. <div class="checkbox inline" id="sign_align_procedure_div">
  322. <input type="checkbox" id="sign_align_procedure">
  323. <label for="sign_align_procedure" class="code">PROCEDURE()</label>
  324. </div>
  325. <div class="checkbox inline" id="sign_align_function_div">
  326. <input type="checkbox" id="sign_align_function">
  327. <label for="sign_align_function" class="code">FUNCTION()</label>
  328. </div>
  329. </div>
  330. <div class="checkbox inline" id="sign_align_all_div">
  331. <input type="checkbox" id="sign_align_all">
  332. <label for="sign_align_all">Align signs in all places</label>
  333. </div>
  334. <form class="inline" id="sign_align_mode_div">
  335. <span>Mode: </span>
  336. <label>
  337. <input type="radio" name="sign_align_modecase" value="local">Local</label>
  338. <label>
  339. <input type="radio" name="sign_align_modecase" value="global">Global</label>
  340. </form>
  341. <div id="customise_indentation_div">
  342. <div class="checkbox inline" id="use_space_div">
  343. <input type="checkbox" id="use_space">
  344. <label for="use_space">Customise Indentation: </label>
  345. </div>(tab is \t)
  346. <input type="text" id="customise_indentation" size="8" onKeyUp="counterDecode('customise_indentation', 'indent_s')" value=" " /> (
  347. <span id="indent_s">four blankspaces</span>)
  348. </div>
  349. <div id="cust_eol_div">
  350. End of line:
  351. <input type="text" id="cust_eol" size="8" onKeyUp="counterDecode('cust_eol', 'eol_s')" value="\r\n" /> (
  352. <span id="eol_s">one \r & one \n</span>)
  353. </div>
  354. <div class="checkbox" id="compress_div">
  355. <input type="checkbox" id="compress">
  356. <label for="compress">! EVIL - compress VHDL (\r\n, comments will be removed)</label>
  357. </div>
  358. <div class="checkbox" id="mix_letter_div">
  359. <input type="checkbox" id="mix_letter">
  360. <label for="mix_letter">! EVIL - unreadable (mix upper/lower-case letters)</label>
  361. </div>
  362. </div>
  363. <div>
  364. <a id="settings_control" onclick="showHideSettings();">Show More Settings ▼</a>
  365. </div>
  366. <input type="button" class="btn" onclick="f()" value="start" />
  367. <span class="show">
  368. <input type="button" class="btn " id="selectAll" value="Select All" onclick="selectText(document.getElementById('vhdl'))" />
  369. <div class="checkbox inline">
  370. <input type="checkbox" onclick="wordWrap()" id="word_wrap">
  371. <label for="word_wrap">Word wrap</label>
  372. </div>
  373. </span>
  374. <br>
  375. <pre id="result"><code class="vhdl" id="vhdl">
  376. <font style="background-color:#9D9D9D; color:#fff"> output sample </font>
  377. <span class="hljs-keyword">LIBRARY</span> IEEE; <span class="hljs-comment">-- declare the library</span>
  378. <span class="hljs-keyword">USE</span> IEEE.std_logic_1164.<span class="hljs-keyword">ALL</span>;
  379. <span class="hljs-keyword">USE</span> IEEE.std_logic_arith.<span class="hljs-keyword">ALL</span>;
  380. <font style="background-color:#9D9D9D; color:#fff"> (All reserved words are in capital) </font>
  381. <font style="background-color:#9D9D9D; color:#fff"> (All indents are in the right place) </font>
  382. <span class="hljs-comment">---------------------------------------------------------------</span>
  383. <span class="hljs-keyword">ENTITY</span> example <span class="hljs-keyword">IS</span>
  384. <span class="hljs-keyword">PORT</span> (
  385. rst : <span class="hljs-keyword">IN</span> <span class="hljs-typename">std_logic</span>;
  386. clk : <span class="hljs-keyword">IN</span> <span class="hljs-typename">std_logic</span>;
  387. example_of_long_words : <span class="hljs-keyword">OUT</span> <span class="hljs-typename">std_logic_vector</span>(<span class="hljs-number">3</span> <span class="hljs-keyword">DOWNTO</span> <span class="hljs-number">0</span>)
  388. <font style="background-color:#9D9D9D; color:#fff"> (<strong>Align signs in PORT()</strong> aligns these colons) </font>
  389. );
  390. <span class="hljs-keyword">END</span> example;
  391. <span class="hljs-keyword">ARCHITECTURE</span> EXA <span class="hljs-keyword">OF</span> example <span class="hljs-keyword">IS</span>
  392. <span class="hljs-keyword">ALIAS</span> slv <span class="hljs-keyword">IS</span> <span class="hljs-typename">std_logic_vector</span>;
  393. <span class="hljs-keyword">SUBTYPE</span> bit4 <span class="hljs-keyword">IS</span> slv(<span class="hljs-number">3</span> <span class="hljs-keyword">DOWNTO</span> <span class="hljs-number">0</span>); <font style="background-color:#9D9D9D; color:#fff"> (<strong>Check ALIAS</strong> replaces all "<strong>std_logic_vector</strong>" with "<strong>slv</strong>") </font>
  394. <span class="hljs-keyword">BEGIN</span>
  395. <del><span class="hljs-keyword">REPORT</span> <span class="hljs-string">"Hello World"</span></del>; <font style="background-color:#9D9D9D; color:#fff"> (Remove REPORT) </font>
  396. stages : <span class="hljs-keyword">PROCESS</span> (rst, clk)
  397. <span class="hljs-keyword">BEGIN</span>
  398. <span class="hljs-keyword">IF</span> (rst = <span class="hljs-literal">'0'</span>) <span class="hljs-keyword">THEN</span>
  399. <span class="hljs-keyword">CASE</span> bit4 <span class="hljs-keyword">IS</span>
  400. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0000"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0001"</span>;
  401. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0001"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0100"</span>;
  402. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0010"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0010"</span>;
  403. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0100"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0000"</span>;
  404. <span class="hljs-keyword">WHEN</span> <span class="hljs-keyword">OTHERS</span> =&gt;
  405. <del><span class="hljs-keyword">REPORT</span> <span class="hljs-string">"Are there any more cases?"</span></del>; <font style="background-color:#9D9D9D; color:#fff"> (Remove REPORT) </font>
  406. <span class="hljs-keyword">END</span> <span class="hljs-keyword">CASE</span>;
  407. <span class="hljs-keyword">ELSIF</span> (clk<span class="hljs-attribute">'event</span> <span class="hljs-keyword">AND</span> clk = <span class="hljs-literal">'1'</span>) <span class="hljs-keyword">THEN</span>
  408. <span class="hljs-keyword">IF</span> (bit4 = '<span class="hljs-number">0111</span>') <span class="hljs-keyword">THEN</span>
  409. bit4 &lt;= <span class="hljs-string">"0000"</span>;
  410. <span class="hljs-keyword">ELSE</span>
  411. bit4 &lt;= <span class="hljs-string">"1111"</span>;
  412. <span class="hljs-keyword">END</span> <span class="hljs-keyword">IF</span>;
  413. <del><span class="hljs-comment">-- Sample comments 1;</span> </del>
  414. <del> <span class="hljs-comment">-- Sample comments 2;</span></del> <font style="background-color:#9D9D9D; color:#fff"> (Remove comments) </font>
  415. <span class="hljs-keyword">END</span> <span class="hljs-keyword">IF</span>;
  416. <span class="hljs-keyword">END</span> <span class="hljs-keyword">PROCESS</span>;
  417. <span class="hljs-keyword">END</span> EXA;</code></pre>
  418. <script>
  419. var exports = {};
  420. </script>
  421. <script src="VHDLFormatter.js"></script>
  422. <script src="descriptiveCounter.js"></script>
  423. <script src="main.js"></script>
  424. <script>
  425. const localStorageSettingKey = "settings";
  426. const localStorageNoFormatKey = "noFormat";
  427. function showHideSettings() {
  428. var settingsDiv = document.getElementById("settings_div");
  429. var control = document.getElementById("settings_control");
  430. if (settingsDiv.className.indexOf("hide") >= 0) {
  431. settingsDiv.className = settingsDiv.className.replace(/\s*hide/, "");
  432. control.innerHTML = "Show Less ▲";
  433. }
  434. else {
  435. settingsDiv.className += "hide";
  436. control.innerHTML = "Show More Settings ▼";
  437. }
  438. }
  439. function onLoad() {
  440. let global_endOfLine = navigator.platform === 'Win32' ? '\\r\\n' : '\\n';
  441. document.getElementById("cust_eol").value = global_endOfLine;
  442. var setting = loadSetting();
  443. if (setting == null) {
  444. return;
  445. }
  446. var beautifierSettings = setting.setting;
  447. document.getElementById("remove_comments").checked = beautifierSettings.RemoveComments;
  448. document.getElementById("remove_lines").checked = setting.removeLines;
  449. document.getElementById("remove_report").checked = beautifierSettings.RemoveAsserts;
  450. document.getElementById("check_alias").checked = beautifierSettings.CheckAlias;
  451. var alignSettings = beautifierSettings.SignAlignSettings;
  452. if (alignSettings != null) {
  453. var signAlignKeywords = alignSettings.keyWords;
  454. if (signAlignKeywords != null && signAlignKeywords.length > 0) {
  455. document.getElementById("sign_align_port").checked = signAlignKeywords.indexOf("PORT") >= 0;
  456. document.getElementById("sign_align_function").checked = signAlignKeywords.indexOf("FUNCTION") >= 0;
  457. document.getElementById("sign_align_procedure").checked = signAlignKeywords.indexOf("PROCEDURE") >= 0;
  458. document.getElementById("sign_align_generic").checked = signAlignKeywords.indexOf("GENERIC") >= 0;
  459. }
  460. document.getElementById("sign_align_all").checked = alignSettings.isAll;
  461. document.getElementById("sign_align_mode_div").elements.namedItem("sign_align_modecase").value = alignSettings.mode;
  462. }
  463. var newLineSettings = beautifierSettings.NewLineSettings;
  464. var newLineAfter = newLineSettings.newLineAfter;
  465. var noNewLineAfter = newLineSettings.noNewLineAfter;
  466. document.getElementById("new_line_after_port").elements.namedItem("new_line_after_portcase").value = decodeNewLineSetting(newLineAfter, noNewLineAfter, "port");
  467. document.getElementById("new_line_after_then").elements.namedItem("new_line_after_thencase").value = decodeNewLineSetting(newLineAfter, noNewLineAfter, "then");
  468. document.getElementById("new_line_after_semicolon").elements.namedItem("new_line_after_semicoloncase").value = decodeNewLineSetting(newLineAfter, noNewLineAfter, ";");
  469. document.getElementById("new_line_after_else").elements.namedItem("new_line_after_elsecase").value = decodeNewLineSetting(newLineAfter, noNewLineAfter, "else");
  470. document.getElementById("new_line_after_generic").elements.namedItem("new_line_after_genericcase").value = decodeNewLineSetting(newLineAfter, noNewLineAfter, "generic");
  471. document.getElementById("compress").checked = setting.compress;
  472. var indentation = beautifierSettings.Indentation;
  473. document.getElementById("use_space").checked = indentation != "\t";
  474. document.getElementById("customise_indentation").value = indentation;
  475. document.getElementById("keyword_div").elements.namedItem("keywordcase").value = beautifierSettings.KeywordCase;
  476. document.getElementById("typename_div").elements.namedItem("typenamecase").value = beautifierSettings.TypeNameCase;
  477. document.getElementById("mix_letter").checked = setting.mixLetter;
  478. var eof = beautifierSettings.EndOfLine
  479. eof = eof.replace(/\r/g, "\\r");
  480. eof = eof.replace(/\n/g, "\\n");
  481. eof = eof.replace(/\t/g, "\\t");
  482. document.getElementById("cust_eol").value = eof;
  483. var noFormatBool = loadNoFormatSetting();
  484. if (noFormatBool) {
  485. document.getElementById("no_format").checked = true;
  486. noFormat();
  487. }
  488. counterDecode('customise_indentation', 'indent_s');
  489. counterDecode('cust_eol', 'eol_s');
  490. }
  491. function decodeNewLineSetting(hasNewLine, noNewLine, str) {
  492. if (hasNewLine.indexOf(str) >= 0) {
  493. return "NewLine";
  494. }
  495. if (noNewLine.indexOf(str) >= 0) {
  496. return "NoNewLine";
  497. }
  498. return "None";
  499. }
  500. onLoad();
  501. function f() {
  502. var input = document.getElementById("in").value;
  503. var no_format = document.getElementById("no_format").checked;
  504. saveNoFormatSetting(no_format);
  505. if (no_format) {
  506. document.getElementById("vhdl").innerHTML = input;
  507. document.querySelector(".show").style.display = "inline-block";
  508. hljs.highlightBlock(document.getElementById("vhdl"));
  509. return;
  510. }
  511. var remove_comments = document.getElementById("remove_comments").checked;
  512. var remove_lines = document.getElementById("remove_lines").checked;
  513. var remove_report = document.getElementById("remove_report").checked;
  514. var check_alias = document.getElementById("check_alias").checked;
  515. var sign_align_port = document.getElementById("sign_align_port").checked;
  516. var sign_align_function = document.getElementById("sign_align_function").checked;
  517. var sign_align_procedure = document.getElementById("sign_align_procedure").checked;
  518. var sign_align_generic = document.getElementById("sign_align_generic").checked;
  519. var sign_align_all = document.getElementById("sign_align_all").checked;
  520. var sign_align_mode = document.getElementById("sign_align_mode_div").elements.namedItem("sign_align_modecase").value;
  521. var new_line_after_port = document.getElementById("new_line_after_port").elements.namedItem("new_line_after_portcase").value;
  522. var new_line_after_then = document.getElementById("new_line_after_then").elements.namedItem("new_line_after_thencase").value;
  523. var new_line_after_semicolon = document.getElementById("new_line_after_semicolon").elements.namedItem("new_line_after_semicoloncase").value;
  524. var new_line_after_else = document.getElementById("new_line_after_else").elements.namedItem("new_line_after_elsecase").value;
  525. var new_line_after_generic = document.getElementById("new_line_after_generic").elements.namedItem("new_line_after_genericcase").value;
  526. var use_space = document.getElementById("use_space").checked;
  527. var compress = document.getElementById("compress").checked;
  528. var cust_indent = document.getElementById("customise_indentation").value;
  529. var keywordcase = document.getElementById("keyword_div").elements.namedItem("keywordcase").value;
  530. var typenamecase = document.getElementById("typename_div").elements.namedItem("typenamecase").value;
  531. var mix_letter = document.getElementById("mix_letter").checked;
  532. var endOfLine = document.getElementById("cust_eol").value;
  533. endOfLine = endOfLine.replace(/\\r/g, "\r");
  534. endOfLine = endOfLine.replace(/\\n/g, "\n");
  535. if (compress) {
  536. remove_comments = true;
  537. }
  538. indentation = "\t";
  539. if (use_space) {
  540. cust_indent = cust_indent.replace(/\\t/, " ");
  541. indentation = cust_indent;
  542. }
  543. var newLineSettingsDict = {};
  544. newLineSettingsDict["generic"] = new_line_after_generic;
  545. newLineSettingsDict["generic map"] = new_line_after_generic;
  546. newLineSettingsDict["port"] = new_line_after_port;
  547. newLineSettingsDict["port map"] = new_line_after_port;
  548. newLineSettingsDict[";"] = new_line_after_semicolon;
  549. newLineSettingsDict["then"] = new_line_after_then;
  550. newLineSettingsDict["else"] = new_line_after_else;
  551. newLineSettings = ConstructNewLineSettings(newLineSettingsDict);
  552. var signAlignKeywords = [];
  553. if (sign_align_function) {
  554. signAlignKeywords.push("FUNCTION");
  555. signAlignKeywords.push("IMPURE FUNCTION");
  556. }
  557. if (sign_align_generic) {
  558. signAlignKeywords.push("GENERIC");
  559. }
  560. if (sign_align_port) {
  561. signAlignKeywords.push("PORT");
  562. }
  563. if (sign_align_procedure) {
  564. signAlignKeywords.push("PROCEDURE");
  565. }
  566. sign_align = signAlignKeywords.length > 0;
  567. let alignSettings = new signAlignSettings(sign_align, sign_align_all, sign_align_mode, signAlignKeywords)
  568. beautifierSettings = new BeautifierSettings(remove_comments, remove_report, check_alias,
  569. alignSettings,
  570. keywordcase,
  571. typenamecase,
  572. indentation,
  573. newLineSettings,
  574. endOfLine);
  575. vhdlSettings = new VhdlSettings(beautifierSettings, remove_lines, compress, mix_letter);
  576. saveSetting(vhdlSettings);
  577. input = beautify(input, beautifierSettings);
  578. if (remove_lines) {
  579. input = input.replace(/(\r\n)*[ \t]*\r\n/g, '\r\n');
  580. }
  581. if (compress) {
  582. input = Compress(input);
  583. }
  584. if (mix_letter) {
  585. input = MixLetters(input);
  586. }
  587. document.getElementById("vhdl").innerHTML = input;
  588. document.querySelector(".show").style.display = "inline-block";
  589. hljs.highlightBlock(document.getElementById("vhdl"));
  590. }
  591. function saveSetting(setting) {
  592. var json = JSON.stringify(setting);
  593. json = json.replace(/\r/g, "\\r");
  594. json = json.replace(/\n/g, "\\n");
  595. json = json.replace(/\t/g, "\\t");
  596. localStorage.setItem(localStorageSettingKey, json);
  597. }
  598. function loadSetting() {
  599. var json = localStorage.getItem(localStorageSettingKey);
  600. if (json == null) {
  601. return null;
  602. }
  603. return JSON.parse(json);
  604. }
  605. function saveNoFormatSetting(no_format) {
  606. localStorage.setItem(localStorageNoFormatKey, no_format);
  607. }
  608. function loadNoFormatSetting() {
  609. return JSON.parse(localStorage.getItem(localStorageNoFormatKey));
  610. }
  611. class VhdlSettings {
  612. constructor(setting, removeLines, compress, mixLetter) {
  613. this.setting = setting;
  614. this.removeLines = removeLines;
  615. this.compress = compress;
  616. this.mixLetter = mixLetter;
  617. }
  618. }
  619. </script>
  620. </body>
  621. </html>