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.

297 lines
13 KiB

6 years ago
  1. <html>
  2. <head>
  3. <title>VHDL Beautifier, Formatter Online</title>
  4. <style>
  5. body {
  6. margin: 0 auto;
  7. max-width: 960px;
  8. tab-size: 4;
  9. font-family: Helvetica, arial;
  10. }
  11. textarea {
  12. width: 100%;
  13. font-family: Consolas, Courier;
  14. }
  15. .btn {
  16. margin: 10px 10px;
  17. padding: 5px 8px;
  18. font-size: 16px;
  19. line-height: 1.33;
  20. border-radius: 3px;
  21. color: #333;
  22. border-color: #ccc;
  23. cursor: pointer;
  24. text-align: center;
  25. white-space: nowrap;
  26. border: 1px solid rgb(194, 194, 194);
  27. }
  28. .btn:hover {
  29. background-color: #afd9ee;
  30. }
  31. .show {
  32. display: none;
  33. }
  34. input[type="checkbox"]+label {
  35. display: inline-block;
  36. width: 19px;
  37. height: 19px;
  38. margin: -1px 4px 0 0;
  39. }
  40. .wordwrap {
  41. white-space: pre-wrap;
  42. white-space: -moz-pre-wrap;
  43. white-space: -pre-wrap;
  44. white-space: -o-pre-wrap;
  45. word-wrap: break-word;
  46. }
  47. label {
  48. cursor: pointer;
  49. line-height: 1.5em;
  50. }
  51. label:hover {
  52. color: #555;
  53. text-decoration: underline;
  54. }
  55. form {
  56. margin-bottom: 0px;
  57. }
  58. a {
  59. color: #4b9aff;
  60. text-decoration: none;
  61. }
  62. a:hover {
  63. text-decoration: underline;
  64. }
  65. </style>
  66. <link href="highlight.css" />
  67. <script src="highlight.js"></script>
  68. <script>
  69. function selectText(element) {
  70. var doc = document,
  71. text = element,
  72. range, selection;
  73. if (doc.body.createTextRange) { //ms
  74. range = doc.body.createTextRange();
  75. range.moveToElementText(text);
  76. range.select();
  77. } else if (window.getSelection) { //all others
  78. selection = window.getSelection();
  79. range = doc.createRange();
  80. range.selectNodeContents(text);
  81. selection.removeAllRanges();
  82. selection.addRange(range);
  83. }
  84. }
  85. </script>
  86. </head>
  87. <body>
  88. <h2>VHDL Beautifier, Formatter</h2>
  89. <h4>Beautify and format your VHDL code online</h4>
  90. <p>
  91. Proper formatting makes code easier to read and understand.
  92. <br> Please make a backup before you replace your code!
  93. <br>
  94. <a href="https://github.com/g2384/g2384.github.io/issues" target="_blank">Report bugs if your code is not properly formatted, please provide sample code which causes the failure</a>
  95. </p>
  96. <div id="lastModified"></div>
  97. <textarea id="in" rows="10" wrap="off"></textarea>
  98. <br>
  99. <form id="keyword">Keyword Case:
  100. <label>
  101. <input type="radio" name="keywordcase" value="UpperCase" checked="checked">UPPERCASE</label>
  102. |
  103. <label>
  104. <input type="radio" name="keywordcase" value="LowerCase">lowercase</label>
  105. |
  106. <label>
  107. <input type="radio" name="keywordcase" value="DefaultCase">Default</label>
  108. </form>
  109. <label>
  110. <input type="checkbox" id="no_format" onclick="noFormat()">Only highlight, don't format</label>
  111. <br> New line after
  112. <label>
  113. <input type="checkbox" checked="checked" id="new_line_after_then">THEN</label>,
  114. <label>
  115. <input type="checkbox" checked="checked" id="new_line_after_semicolon">semicolon ";"</label>,
  116. <label>
  117. <input type="checkbox" id="new_line_after_else">ELSE</label>,
  118. <label>
  119. <input type="checkbox" id="new_line_after_port">PORT</label>,
  120. <label>
  121. <input type="checkbox" id="new_line_after_generic">GENERIC</label>
  122. <br>
  123. <label>
  124. <input type="checkbox" id="remove_comments">Remove commments</label>
  125. |
  126. <label>
  127. <input type="checkbox" id="remove_lines">Remove blank lines</label>
  128. |
  129. <label>
  130. <input type="checkbox" id="remove_report">Remove REPORT</label>
  131. <br>
  132. <label>
  133. <input type="checkbox" id="check_alias">Check ALIAS (every long name is replaced with ALIAS)</label>
  134. <br>
  135. <label>
  136. <input type="checkbox" id="sign_align">Align signs in PORT()</label>
  137. <br>
  138. <label>
  139. <input type="checkbox" id="sign_align_all">Align signs in all places</label>
  140. <br>
  141. <label>
  142. <input type="checkbox" id="use_space">Customise Indentation (tab is \t): </label>
  143. <input type="text" id="cust_indent" size="8" onKeyUp="indent_decode()" value=" " /> (
  144. <span id="indent_s">four blankspace</span>)
  145. <br>
  146. <label>
  147. <input type="checkbox" id="compress">! EVIL - compress VHDL (\r\n, comments will be removed)</label>
  148. <br>
  149. <label>
  150. <input type="checkbox" id="mix_letter">! EVIL - unreadable (mix upper/lower-case letters)</label>
  151. <br>
  152. <input type="button" class="btn" onclick="f()" value="start" />
  153. <span class="show">
  154. <input type="button" class="btn " id="selectAll" value="Select All" onclick="selectText(document.getElementById('vhdl'))"
  155. />
  156. <label>
  157. <input type="checkbox" onclick="wordWrap()" id="">Word wrap</label>
  158. </span>
  159. <br>
  160. <pre id="result"><code class="vhdl" id="vhdl">
  161. <font style="background-color:#9D9D9D; color:#fff"> output sample </font>
  162. <span class="hljs-keyword">LIBRARY</span> IEEE; <span class="hljs-comment">-- declare the library</span>
  163. <span class="hljs-keyword">USE</span> IEEE.std_logic_1164.<span class="hljs-keyword">ALL</span>;
  164. <span class="hljs-keyword">USE</span> IEEE.std_logic_arith.<span class="hljs-keyword">ALL</span>;
  165. <font style="background-color:#9D9D9D; color:#fff"> (All reserved words are in capital) </font>
  166. <font style="background-color:#9D9D9D; color:#fff"> (All indents are in the right place) </font>
  167. <span class="hljs-comment">---------------------------------------------------------------</span>
  168. <span class="hljs-keyword">ENTITY</span> example <span class="hljs-keyword">IS</span>
  169. <span class="hljs-keyword">PORT</span> (
  170. rst : <span class="hljs-keyword">IN</span> <span class="hljs-typename">std_logic</span>;
  171. clk : <span class="hljs-keyword">IN</span> <span class="hljs-typename">std_logic</span>;
  172. 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>)
  173. <font style="background-color:#9D9D9D; color:#fff"> (<strong>Align signs in PORT()</strong> aligns these colons) </font>
  174. );
  175. <span class="hljs-keyword">END</span> example;
  176. <span class="hljs-keyword">ARCHITECTURE</span> EXA <span class="hljs-keyword">OF</span> example <span class="hljs-keyword">IS</span>
  177. <span class="hljs-keyword">ALIAS</span> slv <span class="hljs-keyword">IS</span> <span class="hljs-typename">std_logic_vector</span>;
  178. <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>
  179. <span class="hljs-keyword">BEGIN</span>
  180. <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>
  181. stages : <span class="hljs-keyword">PROCESS</span> (rst, clk)
  182. <span class="hljs-keyword">BEGIN</span>
  183. <span class="hljs-keyword">IF</span> (rst = <span class="hljs-literal">'0'</span>) <span class="hljs-keyword">THEN</span>
  184. <span class="hljs-keyword">CASE</span> bit4 <span class="hljs-keyword">IS</span>
  185. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0000"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0001"</span>;
  186. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0001"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0100"</span>;
  187. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0010"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0010"</span>;
  188. <span class="hljs-keyword">WHEN</span> <span class="hljs-string">"0100"</span> =&gt; bit4 &lt;= <span class="hljs-string">"0000"</span>;
  189. <span class="hljs-keyword">WHEN</span> <span class="hljs-keyword">OTHERS</span> =&gt;
  190. <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>
  191. <span class="hljs-keyword">END</span> <span class="hljs-keyword">CASE</span>;
  192. <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>
  193. <span class="hljs-keyword">IF</span> (bit4 = '<span class="hljs-number">0111</span>') <span class="hljs-keyword">THEN</span>
  194. bit4 &lt;= <span class="hljs-string">"0000"</span>;
  195. <span class="hljs-keyword">ELSE</span>
  196. bit4 &lt;= <span class="hljs-string">"1111"</span>;
  197. <span class="hljs-keyword">END</span> <span class="hljs-keyword">IF</span>;
  198. <del><span class="hljs-comment">-- Sample comments 1;</span> </del>
  199. <del> <span class="hljs-comment">-- Sample comments 2;</span></del> <font style="background-color:#9D9D9D; color:#fff"> (Remove comments) </font>
  200. <span class="hljs-keyword">END</span> <span class="hljs-keyword">IF</span>;
  201. <span class="hljs-keyword">END</span> <span class="hljs-keyword">PROCESS</span>;
  202. <span class="hljs-keyword">END</span> EXA;</code></pre>
  203. <script> var exports = {}; </script>
  204. <script src="VHDLFormatter.js"></script>
  205. <script src="VHDLFormatterUnitTests.js"></script>
  206. <script>
  207. let lastModifiedDate = fetchHeader(location.href, 'Last-Modified');
  208. if (lastModifiedDate != "") {
  209. document.getElementById("lastModified").innerHTML = "<p>Last modified: " + lastModifiedDate + "</p>";
  210. }
  211. function f() {
  212. var input = document.getElementById("in").value;
  213. var no_format = document.getElementById("no_format").checked;
  214. if (no_format) {
  215. document.getElementById("vhdl").innerHTML = input;
  216. document.querySelector(".show").style.display = "inline-block";
  217. hljs.highlightBlock(document.getElementById("vhdl"));
  218. return;
  219. }
  220. var remove_comments = document.getElementById("remove_comments").checked;
  221. var remove_lines = document.getElementById("remove_lines").checked;
  222. var remove_report = document.getElementById("remove_report").checked;
  223. var check_alias = document.getElementById("check_alias").checked;
  224. var sign_align = document.getElementById("sign_align").checked;
  225. var sign_align_all = document.getElementById("sign_align_all").checked;
  226. var new_line_after_port = document.getElementById("new_line_after_port").checked;
  227. var new_line_after_then = document.getElementById("new_line_after_then").checked;
  228. var new_line_after_semicolon = document.getElementById("new_line_after_semicolon").checked;
  229. var new_line_after_generic = document.getElementById("new_line_after_generic").checked;
  230. var use_space = document.getElementById("use_space").checked;
  231. var compress = document.getElementById("compress").checked;
  232. var cust_indent = document.getElementById("cust_indent").value;
  233. var keywordcase = document.getElementById("keyword").elements.namedItem("keywordcase").value;
  234. var mix_letter = document.getElementById("mix_letter").checked;
  235. if (compress) {
  236. remove_comments = true;
  237. }
  238. indentation = "\t";
  239. if (use_space) {
  240. cust_indent = cust_indent.replace(/\\t/, " ");
  241. indentation = cust_indent;
  242. }
  243. var newLineSettingsDict = {};
  244. newLineSettingsDict["generic"] = new_line_after_generic;
  245. newLineSettingsDict["port"] = new_line_after_port;
  246. newLineSettingsDict[";"] = new_line_after_semicolon;
  247. newLineSettingsDict["then"] = new_line_after_then;
  248. newLineSettingsDict["else"] = new_line_after_else;
  249. newLineSettings = ConstructNewLineSettings(newLineSettingsDict);
  250. beautifierSettings = BeautifierSettings(remove_comments, remove_report, check_alias, sign_align, sign_align_all,
  251. keywordcase, indentation, newLineSettings);
  252. input = beautify(input, beautifierSettings);
  253. if (remove_lines) {
  254. input = input.replace(/(\r\n)*[ \t]*\r\n/g, '\r\n');
  255. }
  256. if (compress) {
  257. input = Compress(input);
  258. }
  259. if (mix_letter) {
  260. input = MixLetters(input);
  261. }
  262. document.getElementById("vhdl").innerHTML = input;
  263. document.querySelector(".show").style.display = "inline-block";
  264. hljs.highlightBlock(document.getElementById("vhdl"));
  265. }
  266. </script>
  267. </body>
  268. </html>