Skip to content

Commit 5b8ce2c

Browse files
author
1138-4EB
committed
add jsonGetBooleanArray and jsonGetRealArray
1 parent 00609d2 commit 5b8ce2c

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

Data/Boards0.json

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

Examples/Boards_VUnit.vhdl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ 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");
19+
constant arr_bool : boolean_vector := jsonGetBooleanArray(JSONContent, "1");
20+
constant arr_int : integer_vector := jsonGetIntegerArray(JSONContent, "2");
21+
constant arr_real : real_vector := jsonGetRealArray(JSONContent, "5");
2022
begin
2123
main: process
2224
begin
@@ -33,9 +35,19 @@ begin
3335
info("tb_cfg: " & tb_cfg);
3436
info("JSONContent: " & lf & JSONContent.Content);
3537

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)));
38+
info("Boolean array length: " & integer'image(arr_bool'length));
39+
for i in 0 to arr_bool'length-1 loop
40+
info("Boolean array [" & integer'image(i) & "]: " & boolean'image(arr_bool(i)));
41+
end loop;
42+
43+
info("Integer array length: " & integer'image(arr_int'length));
44+
for i in 0 to arr_int'length-1 loop
45+
info("Integer array [" & integer'image(i) & "]: " & integer'image(arr_int(i)));
46+
end loop;
47+
48+
info("Real array length: " & integer'image(arr_real'length));
49+
for i in 0 to arr_real'length-1 loop
50+
info("Real array [" & integer'image(i) & "]: " & real'image(arr_real(i)));
3951
end loop;
4052
end if;
4153
end loop;

vhdl/JSON.ctx.vhdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ context json_ctx is
4444
use JSON.json.jsonGetContent;
4545
use JSON.json.jsonGetBoolean;
4646
use JSON.json.jsonGetString;
47+
use JSON.json.jsonGetBooleanArray;
4748
use JSON.json.jsonGetIntegerArray;
49+
use JSON.json.jsonGetRealArray;
4850
use JSON.json.jsonIsBoolean;
4951
use JSON.json.jsonIsNull;
5052
use JSON.json.jsonIsString;

vhdl/JSON.pkg.vhdl

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ 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+
107+
function jsonGetBooleanArray(JSONContext : T_JSON; Path : string) return boolean_vector;
108+
function jsonGetBooleanArray(JSONContext : T_JSON; Path : string; Len : positive) return boolean_vector;
106109
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector;
107110
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string; Len : positive) return integer_vector;
108-
-- function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector;
111+
function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector;
112+
function jsonGetRealArray(JSONContext : T_JSON; Path : string; Len : positive) return real_vector;
109113

114+
function jsonGetNumberArrayLength(JSONContext : T_JSON; Path : string) return natural;
110115
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
111116
function jsonIsNull(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
112117
function jsonIsString(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
@@ -1622,14 +1627,31 @@ package body JSON is
16221627
return (Element.ElementType = ELEM_TRUE);
16231628
end function;
16241629

1625-
-- function to get a integer_vector from the compressed content extracted from a JSON input
1626-
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector is
1630+
-- function to get a boolean_vector from the compressed content extracted from a JSON input
1631+
function jsonGetBooleanArray(JSONContext : T_JSON; Path : string) return boolean_vector is
16271632
variable len: natural:=0;
16281633
begin
1629-
while jsonIsNumber(JSONContext, Path & "/" & to_string(len)) loop
1634+
while jsonIsBoolean(JSONContext, Path & "/" & to_string(len)) loop
16301635
len := len+1;
16311636
end loop;
1632-
return jsonGetIntegerArray(JSONContext, Path, len);
1637+
return jsonGetBooleanArray(JSONContext, Path, len);
1638+
end;
1639+
1640+
-- function to get a boolean_vector of a fixed length from the compressed content extracted from a JSON input
1641+
function jsonGetBooleanArray(JSONContext : T_JSON; Path : string; Len : positive) return boolean_vector is
1642+
variable return_value : boolean_vector(Len-1 downto 0);
1643+
begin
1644+
for i in 0 to Len-1 loop
1645+
return_value(i) := boolean'value(jsonGetString(JSONContext, Path & "/" & to_string(i)));
1646+
end loop;
1647+
return return_value;
1648+
end function;
1649+
1650+
-- function to get a integer_vector from the compressed content extracted from a JSON input
1651+
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector is
1652+
variable len: natural:=0;
1653+
begin
1654+
return jsonGetIntegerArray(JSONContext, Path, jsonGetNumberArrayLength(JSONContext, Path));
16331655
end;
16341656

16351657
-- function to get a integer_vector of a fixed length from the compressed content extracted from a JSON input
@@ -1642,6 +1664,32 @@ package body JSON is
16421664
return return_value;
16431665
end function;
16441666

1667+
-- function to get a real_vector from the compressed content extracted from a JSON input
1668+
function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector is
1669+
variable len: natural:=0;
1670+
begin
1671+
return jsonGetRealArray(JSONContext, Path, jsonGetNumberArrayLength(JSONContext, Path));
1672+
end;
1673+
1674+
-- function to get a real_vector of a fixed length from the compressed content extracted from a JSON input
1675+
function jsonGetRealArray(JSONContext : T_JSON; Path : string; Len : positive) return real_vector is
1676+
variable return_value : real_vector(Len-1 downto 0);
1677+
begin
1678+
for i in 0 to Len-1 loop
1679+
return_value(i) := real'value(jsonGetString(JSONContext, Path & "/" & to_string(i)));
1680+
end loop;
1681+
return return_value;
1682+
end function;
1683+
1684+
function jsonGetNumberArrayLength(JSONContext : T_JSON; Path : string) return natural is
1685+
variable len: natural:=0;
1686+
begin
1687+
while jsonIsNumber(JSONContext, Path & "/" & to_string(len)) loop
1688+
len := len+1;
1689+
end loop;
1690+
return len;
1691+
end;
1692+
16451693
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN is
16461694
constant ElementIndex : T_UINT16 := jsonGetElementIndex(JSONContext, Path);
16471695
constant Element : T_JSON_INDEX_ELEMENT := JSONContext.Index(ElementIndex);

0 commit comments

Comments
 (0)