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.

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