Skip to content

Commit 00609d2

Browse files
author
1138-4EB
committed
move add_array_lens to VHDL
1 parent 346c4fe commit 00609d2

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

VUnit/run.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,8 @@
1212

1313
vu.set_generic('tb_cfg_file', '../Data/Boards1.json')
1414

15-
def add_array_lens(obj):
16-
if isinstance(obj, list):
17-
if isinstance(obj[0], int) and not isinstance(obj[0], bool):
18-
obj = [len(obj)] + obj
19-
else:
20-
for i in range(len(obj)):
21-
obj[i] = add_array_lens(obj[i])
22-
else:
23-
if isinstance(obj, dict):
24-
for key, val in obj.items():
25-
obj[key] = add_array_lens(val)
26-
return obj
27-
2815
import json
2916
generics = json.loads(open('../Data/Boards0.json', 'r').read())
30-
vu.set_generic("tb_cfg", json.dumps(add_array_lens(generics), separators=(',', ':')))
17+
vu.set_generic("tb_cfg", json.dumps(generics, separators=(',', ':')))
3118

3219
vu.main()

vhdl/JSON.pkg.vhdl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ package JSON is
104104
function jsonGetBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
105105
function jsonGetString(JSONContext : T_JSON; Path : STRING) return STRING;
106106
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector;
107+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string; Len : positive) return integer_vector;
108+
-- function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector;
107109

108110
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
109111
function jsonIsNull(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
@@ -1486,7 +1488,7 @@ package body JSON is
14861488
end if; -- Index = 0
14871489
for j in 1 to Index loop
14881490
if (IndexElement.NextIndex = 0) then
1489-
report "jsonGetElementIndex: Reached last element in chain." severity FAILURE;
1491+
report "jsonGetElementIndex: Reached last element in chain." severity NOTE; --FAILURE
14901492
return 0;
14911493
end if;
14921494
IndexElement := JSONContext.Index(IndexElement.NextIndex);
@@ -1622,15 +1624,24 @@ package body JSON is
16221624

16231625
-- function to get a integer_vector from the compressed content extracted from a JSON input
16241626
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector is
1625-
constant len: positive:=to_natural_dec( jsonGetString(JSONContext, Path & "/0") );
1626-
variable return_value : integer_vector(len-1 downto 0);
1627+
variable len: natural:=0;
16271628
begin
1628-
for i in 1 to len loop
1629-
return_value(i-1) := to_natural_dec(jsonGetString(JSONContext, Path & "/" & to_string(i)));
1629+
while jsonIsNumber(JSONContext, Path & "/" & to_string(len)) loop
1630+
len := len+1;
16301631
end loop;
1631-
return return_value;
1632+
return jsonGetIntegerArray(JSONContext, Path, len);
16321633
end;
16331634

1635+
-- function to get a integer_vector of a fixed length from the compressed content extracted from a JSON input
1636+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string; Len : positive) return integer_vector is
1637+
variable return_value : integer_vector(Len-1 downto 0);
1638+
begin
1639+
for i in 0 to Len-1 loop
1640+
return_value(i) := to_natural_dec(jsonGetString(JSONContext, Path & "/" & to_string(i)));
1641+
end loop;
1642+
return return_value;
1643+
end function;
1644+
16341645
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN is
16351646
constant ElementIndex : T_UINT16 := jsonGetElementIndex(JSONContext, Path);
16361647
constant Element : T_JSON_INDEX_ELEMENT := JSONContext.Index(ElementIndex);

0 commit comments

Comments
 (0)