Skip to content

Commit 43e6157

Browse files
committed
Merge pull request #595 from a-rey/add-vhdl
adding vhdl language
2 parents 6f2cd4e + 3d39891 commit 43e6157

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

components.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ var components = {
326326
"require": "javascript",
327327
"owner": "vkbansal"
328328
},
329+
"vhdl": {
330+
"title": "VHDL",
331+
"owner": "a-rey"
332+
},
329333
"wiki": {
330334
"title": "Wiki markup",
331335
"require": "markup",

components/prism-vhdl.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Prism.languages.vhdl = {
2+
'comment': /--.+/,
3+
// support for all logic vectors
4+
'vhdl-vectors': {
5+
'pattern': /\b[oxb]"[\da-f_]+"|"[01uxzwlh-]+"/i,
6+
'alias': 'number'
7+
},
8+
'string': /"(\\\n|\\?.)*?"/,
9+
'constant': /\b(use|library)\b/i,
10+
// support for predefined attributes included
11+
'keyword': /\b('active|'ascending|'base|'delayed|'driving|'driving_value|'event|'high|'image|'instance_name|'last_active|'last_event|'last_value|'left|'leftof|'length|'low|'path_name|'pos|'pred|'quiet|'range|'reverse_range|'right|'rightof|'simple_name|'stable|'succ|'transaction|'val|'value|access|after|alias|all|architecture|array|assert|attribute|begin|block|body|buffer|bus|case|component|configuration|constant|disconnect|downto|else|elsif|end|entity|exit|file|for|function|generate|generic|group|guarded|if|impure|in|inertial|inout|is|label|library|linkage|literal|loop|map|new|next|null|of|on|open|others|out|package|port|postponed|procedure|process|pure|range|record|register|reject|report|return|select|severity|shared|signal|subtype|then|to|transport|type|unaffected|units|until|use|variable|wait|when|while|with)\b/i,
12+
'boolean': /\b(true|false)\b/i,
13+
'function': {
14+
// support for operator overloading included
15+
pattern: /([a-z0-9_]+|"\S+")\(/i,
16+
inside: {
17+
punctuation: /\(/
18+
}
19+
},
20+
// decimal, based, physical, and exponential numbers supported
21+
'number': /'[01uxzwlh-]'|\b\d+[_.]*(#[\da-f_.]+#)?(e[-+]?\d+)?/i,
22+
'operator': /<=?|>=?|:=|[-+*/&=]|\b(abs|not|mod|rem|sll|srl|sla|sra|rol|ror|and|or|nand|xnor|xor|nor)\b/i,
23+
'punctuation': /[{}[\];(),.:]/
24+
};

components/prism-vhdl.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-vhdl.html

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<h1>VHDL</h1>
2+
<p>To use this language, use the class "language-vhdl".</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code>-- I am a comment
6+
I am not</code></pre>
7+
8+
<h2>Literals</h2>
9+
<pre><code>constant FREEZE : integer := 32;
10+
constant TEMP : real := 32.0;
11+
A_INT <= 16#FF#;
12+
B_INT <= 2#1010_1010#;
13+
MONEY := 1_000_000.0;
14+
FACTOR := 2.2E-6;
15+
constant DEL1 :time := 10 ns;
16+
constant DEL2 :time := 2.27 us;
17+
type MY_LOGIC is ('X','0','1','Z');
18+
type T_STATE is (IDLE, READ, END_CYC);
19+
signal CLK : MY_LOGIC := '0';
20+
signal STATE : T_STATE := IDLE;
21+
constant FLAG :bit_vector(0 to 7) := "11111111";
22+
constant MSG : string := "Hello";
23+
BIT_8_BUS <= B"1111_1111";
24+
BIT_9_BUS <= O"353";
25+
BIT_16_BUS <= X"AA55";
26+
constant TWO_LINE_MSG : string := "Hello" & CR & "World";</code></pre>
27+
28+
<h2>Full example</h2>
29+
<pre><code>-- example code from: http://www.csee.umbc.edu/portal/help/VHDL/samples/samples.html
30+
library IEEE;
31+
use IEEE.std_logic_1164.all;
32+
33+
entity fadd is -- full adder stage, interface
34+
port(a : in std_logic;
35+
b : in std_logic;
36+
cin : in std_logic;
37+
s : out std_logic;
38+
cout : out std_logic);
39+
end entity fadd;
40+
41+
architecture circuits of fadd is -- full adder stage, body
42+
begin -- circuits of fadd
43+
s <= a xor b xor cin after 1 ns;
44+
cout <= (a and b) or (a and cin) or (b and cin) after 1 ns;
45+
end architecture circuits; -- of fadd
46+
47+
library IEEE;
48+
use IEEE.std_logic_1164.all;
49+
entity add32 is -- simple 32 bit ripple carry adder
50+
port(a : in std_logic_vector(31 downto 0);
51+
b : in std_logic_vector(31 downto 0);
52+
cin : in std_logic;
53+
sum : out std_logic_vector(31 downto 0);
54+
cout : out std_logic);
55+
end entity add32;
56+
57+
architecture circuits of add32 is
58+
signal c : std_logic_vector(0 to 30); -- internal carry signals
59+
begin -- circuits of add32
60+
a0: entity WORK.fadd port map(a(0), b(0), cin, sum(0), c(0));
61+
stage: for I in 1 to 30 generate
62+
as: entity WORK.fadd port map(a(I), b(I), c(I-1) , sum(I), c(I));
63+
end generate stage;
64+
a31: entity WORK.fadd port map(a(31), b(31), c(30) , sum(31), cout);
65+
end architecture circuits; -- of add32
66+
67+
use STD.textio.all;
68+
library IEEE;
69+
use IEEE.std_logic_1164.all;
70+
use IEEE.std_logic_textio.all;
71+
72+
entity signal_trace is
73+
end signal_trace;
74+
75+
architecture circuits of signal_trace is
76+
signal a: std_logic_vector(31 downto 0) := x"00000000";
77+
signal b: std_logic_vector(31 downto 0) := x"FFFFFFFF";
78+
signal cin: std_logic := '1';
79+
signal cout: std_logic;
80+
signal sum: std_logic_vector(31 downto 0);
81+
begin -- circuits of signal_trace
82+
adder: entity WORK.add32 port map(a, b, cin, sum, cout); -- parallel circuit
83+
84+
prtsum: process (sum)
85+
variable my_line : LINE;
86+
alias swrite is write [line, string, side, width] ;
87+
begin
88+
swrite(my_line, "sum=");
89+
write(my_line, sum);
90+
swrite(my_line, ", at=");
91+
write(my_line, now);
92+
writeline(output, my_line);
93+
end process prtsum;
94+
95+
end architecture circuits; -- of signal_trace</code></pre>

0 commit comments

Comments
 (0)