Skip to content

Commit 346c4fe

Browse files
author
1138-4EB
committed
add jsonGetIntegerArray
1 parent 59d849d commit 346c4fe

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

Data/Boards0.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
["test",[true,false,18,null,"hello"],3324.34,832432,"world"]
2-
1+
["test",[true,false,18,null,"hello"],[9,8],3324.34,832432,"world"]

Examples/Boards_VUnit.vhdl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ end entity;
1616
architecture tb of tb_boards is
1717
constant JSONContent : T_JSON := jsonLoad(tb_cfg);
1818
constant JSONFileContent : T_JSON := jsonLoad(tb_cfg_file);
19+
constant tb_imga : integer_vector := jsonGetIntegerArray(JSONContent, "2");
1920
begin
2021
main: process
2122
begin
2223
test_runner_setup(runner, runner_cfg);
2324
while test_suite loop
2425
if run("test") then
26+
info("tb_path & tb_cfg_file: " & tb_path & tb_cfg_file);
27+
info("JSONFileContent: " & lf & JSONFileContent.Content);
28+
info("ML505/FPGA: " & jsonGetString(JSONFileContent, "ML505/FPGA"));
29+
info("ML505/Eth/0/PHY-Int: " & jsonGetString(JSONFileContent, "ML505/Eth/0/PHY-Int"));
30+
info("KC705/FPGA: " & jsonGetString(JSONFileContent, "KC705/FPGA"));
31+
info("KC705/IIC/0/Devices/0/Name: " & jsonGetString(JSONFileContent, "KC705/IIC/0/Devices/0/Name"));
32+
2533
info("tb_cfg: " & tb_cfg);
2634
info("JSONContent: " & lf & JSONContent.Content);
27-
info("ML505/FPGA: " & jsonGetString(JSONContent, "ML505/FPGA"));
28-
info("ML505/Eth/0/PHY-Int: " & jsonGetString(JSONContent, "ML505/Eth/0/PHY-Int"));
29-
info("KC705/FPGA: " & jsonGetString(JSONContent, "KC705/FPGA"));
30-
info("KC705/IIC/0/Devices/0/Name: " & jsonGetString(JSONContent, "KC705/IIC/0/Devices/0/Name"));
3135

32-
info("tb_path & tb_cfg_file: " & tb_path & tb_cfg_file);
33-
info("JSONFileContent: " & lf & JSONFileContent.Content);
34-
info("ML505/FPGADevice: " & jsonGetString(JSONFileContent, "ML505/FPGADevice"));
35-
info("ML505/Ethernet/0/PHY_Device: " & jsonGetString(JSONFileContent, "ML505/Ethernet/0/PHY_Device"));
36-
info("KC705/FPGADevice: " & jsonGetString(JSONFileContent, "KC705/FPGADevice"));
37-
info("KC705/IIC/0/Devices/0/Type: " & jsonGetString(JSONFileContent, "KC705/IIC/0/Devices/0/Type"));
36+
info("Integer array length: " & jsonGetString(JSONContent, "2/1"));
37+
for i in 0 to tb_imga'length-1 loop
38+
info("Integer array [" & integer'image(i) & "]: " & integer'image(tb_imga(i)));
39+
end loop;
3840
end if;
3941
end loop;
4042
test_runner_cleanup(runner);

VUnit/run.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@
1010
lib = vu.add_library("lib")
1111
lib.add_source_files(join(root, "..", "Examples", "Boards_VUnit.vhdl"))
1212

13-
vu.set_generic('tb_cfg_file', '../Data/Boards2.json')
13+
vu.set_generic('tb_cfg_file', '../Data/Boards1.json')
14+
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
1427

1528
import json
16-
file = open('../Data/Boards1.json', 'r')
17-
generics = json.loads(file.read())
18-
vu.set_generic("tb_cfg", json.dumps(generics, separators=(',', ':')))
29+
generics = json.loads(open('../Data/Boards0.json', 'r').read())
30+
vu.set_generic("tb_cfg", json.dumps(add_array_lens(generics), separators=(',', ':')))
1931

2032
vu.main()

vhdl/JSON.ctx.vhdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ context json_ctx is
4242
use JSON.json.jsonNoParserError;
4343
use JSON.json.jsonGetErrorMessage;
4444
use JSON.json.jsonGetContent;
45-
use JSON.json.jsonGetString;
4645
use JSON.json.jsonGetBoolean;
46+
use JSON.json.jsonGetString;
47+
use JSON.json.jsonGetIntegerArray;
4748
use JSON.json.jsonIsBoolean;
4849
use JSON.json.jsonIsNull;
4950
use JSON.json.jsonIsString;
5051
use JSON.json.jsonIsNumber;
51-
-- use JSON.json.jsonGetIntArray;
5252
end context;

vhdl/JSON.pkg.vhdl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ package JSON is
103103

104104
function jsonGetBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
105105
function jsonGetString(JSONContext : T_JSON; Path : STRING) return STRING;
106+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector;
106107

107108
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
108109
function jsonIsNull(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
@@ -1619,6 +1620,17 @@ package body JSON is
16191620
return (Element.ElementType = ELEM_TRUE);
16201621
end function;
16211622

1623+
-- function to get a integer_vector from the compressed content extracted from a JSON input
1624+
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+
begin
1628+
for i in 1 to len loop
1629+
return_value(i-1) := to_natural_dec(jsonGetString(JSONContext, Path & "/" & to_string(i)));
1630+
end loop;
1631+
return return_value;
1632+
end;
1633+
16221634
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN is
16231635
constant ElementIndex : T_UINT16 := jsonGetElementIndex(JSONContext, Path);
16241636
constant Element : T_JSON_INDEX_ELEMENT := JSONContext.Index(ElementIndex);

0 commit comments

Comments
 (0)