I have this VHDL code, it should work as a sine generator with lookup table.
I keep getting error "Missing EOF at function", or just "syntax error" in modelsim.
I have the syntax from some online tutorial, and it seems to be correct. What is wrong?
function WAVE(X : integer) -- here is the error marker
return integer is
variable foo: integer;
begin
WITH X SELECT
foo := 0 WHEN 0, 4 WHEN 1, 7 WHEN 2, 11 WHEN 3, 14 WHEN 4, 18 WHEN 5, 21 WHEN 6, 25 WHEN 7,
28 WHEN 8, 32 WHEN 9, 35 WHEN 10, 38 WHEN 11, 42 WHEN 12, 45 WHEN 13, 49 WHEN 14,
52 WHEN 15, 55 WHEN 16, 58 WHEN 17, 62 WHEN 18, 65 WHEN 19, 68 WHEN 20, 71 WHEN 21,
74 WHEN 22, 77 WHEN 23, 80 WHEN 24, 83 WHEN 25, 86 WHEN 26, 89 WHEN 27, 91 WHEN 28,
94 WHEN 29, 97 WHEN 30, 99 WHEN 31, 102 WHEN 32, 104 WHEN 33, 107 WHEN 34, 109 WHEN 35,
111 WHEN 36, 114 WHEN 37, 116 WHEN 38, 118 WHEN 39, 120 WHEN 40, 122 WHEN 41, 124 WHEN 42,
125 WHEN 43, 127 WHEN 44, 129 WHEN 45, 130 WHEN 46, 132 WHEN 47, 133 WHEN 48, 134 WHEN 49,
136 WHEN 50, 137 WHEN 51, 138 WHEN 52, 139 WHEN 53, 140 WHEN 54, 141 WHEN 55, 141 WHEN 56,
142 WHEN 57, 142 WHEN 58, 143 WHEN 59, 143 WHEN 60, 144 WHEN 61, 144 WHEN 62, 144 WHEN 63,
144 WHEN 64, 144 WHEN 65, 144 WHEN 66, 144 WHEN 67, 143 WHEN 68, 143 WHEN 69, 142 WHEN 70,
142 WHEN 71, 141 WHEN 72, 141 WHEN 73, 140 WHEN 74, 139 WHEN 75, 138 WHEN 76, 137 WHEN 77,
136 WHEN 78, 134 WHEN 79, 133 WHEN 80, 132 WHEN 81, 130 WHEN 82, 129 WHEN 83, 127 WHEN 84,
125 WHEN 85, 124 WHEN 86, 122 WHEN 87, 120 WHEN 88, 118 WHEN 89, 116 WHEN 90, 114 WHEN 91,
111 WHEN 92, 109 WHEN 93, 107 WHEN 94, 104 WHEN 95, 102 WHEN 96, 99 WHEN 97, 97 WHEN 98,
94 WHEN 99, 91 WHEN 100, 89 WHEN 101, 86 WHEN 102, 83 WHEN 103, 80 WHEN 104, 77 WHEN 105,
74 WHEN 106, 71 WHEN 107, 68 WHEN 108, 65 WHEN 109, 62 WHEN 110, 58 WHEN 111, 55 WHEN 112,
52 WHEN 113, 49 WHEN 114, 45 WHEN 115, 42 WHEN 116, 38 WHEN 117, 35 WHEN 118, 32 WHEN 119,
28 WHEN 120, 25 WHEN 121, 21 WHEN 122, 18 WHEN 123, 14 WHEN 124, 11 WHEN 125, 7 WHEN 126,
4 WHEN 127, 0 WHEN 128, -4 WHEN 129, -7 WHEN 130, -11 WHEN 131, -14 WHEN 132, -18 WHEN 133,
-21 WHEN 134, -25 WHEN 135, -28 WHEN 136, -32 WHEN 137, -35 WHEN 138, -38 WHEN 139, -42 WHEN 140,
-45 WHEN 141, -49 WHEN 142, -52 WHEN 143, -55 WHEN 144, -58 WHEN 145, -62 WHEN 146, -65 WHEN 147,
-68 WHEN 148, -71 WHEN 149, -74 WHEN 150, -77 WHEN 151, -80 WHEN 152, -83 WHEN 153, -86 WHEN 154,
-89 WHEN 155, -91 WHEN 156, -94 WHEN 157, -97 WHEN 158, -99 WHEN 159, -102 WHEN 160, -104 WHEN 161,
-107 WHEN 162, -109 WHEN 163, -111 WHEN 164, -114 WHEN 165, -116 WHEN 166, -118 WHEN 167,
-120 WHEN 168, -122 WHEN 169, -124 WHEN 170, -125 WHEN 171, -127 WHEN 172, -129 WHEN 173,
-130 WHEN 174, -132 WHEN 175, -133 WHEN 176, -134 WHEN 177, -136 WHEN 178, -137 WHEN 179,
-138 WHEN 180, -139 WHEN 181, -140 WHEN 182, -141 WHEN 183, -141 WHEN 184, -142 WHEN 185,
-142 WHEN 186, -143 WHEN 187, -143 WHEN 188, -144 WHEN 189, -144 WHEN 190, -144 WHEN 191,
-144 WHEN 192, -144 WHEN 193, -144 WHEN 194, -144 WHEN 195, -143 WHEN 196, -143 WHEN 197,
-142 WHEN 198, -142 WHEN 199, -141 WHEN 200, -141 WHEN 201, -140 WHEN 202, -139 WHEN 203,
-138 WHEN 204, -137 WHEN 205, -136 WHEN 206, -134 WHEN 207, -133 WHEN 208, -132 WHEN 209,
-130 WHEN 210, -129 WHEN 211, -127 WHEN 212, -125 WHEN 213, -124 WHEN 214, -122 WHEN 215,
-120 WHEN 216, -118 WHEN 217, -116 WHEN 218, -114 WHEN 219, -111 WHEN 220, -109 WHEN 221,
-107 WHEN 222, -104 WHEN 223, -102 WHEN 224, -99 WHEN 225, -97 WHEN 226, -94 WHEN 227,
-91 WHEN 228, -89 WHEN 229, -86 WHEN 230, -83 WHEN 231, -80 WHEN 232, -77 WHEN 233,
-74 WHEN 234, -71 WHEN 235, -68 WHEN 236, -65 WHEN 237, -62 WHEN 238, -58 WHEN 239,
-55 WHEN 240, -52 WHEN 241, -49 WHEN 242, -45 WHEN 243, -42 WHEN 244, -38 WHEN 245,
-35 WHEN 246, -32 WHEN 247, -28 WHEN 248, -25 WHEN 249, -21 WHEN 250, -18 WHEN 251,
-14 WHEN 252, -11 WHEN 253, -7 WHEN 254, -4 WHEN 255, 0 WHEN others;
return foo;
end WAVE;
WITH-SELECT construction is a concurrent statement, it is only applicable directly in the architecture, outside of processes or functions. Inside a function you can use the CASE construct.