Skip to content

Commit

Permalink
Merge pull request #101 from Irvise/fix-msb
Browse files Browse the repository at this point in the history
Fix MSB before LSB
  • Loading branch information
pat-rogers authored Feb 6, 2024
2 parents c732783 + 167aa9e commit 1ef42c7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 58 deletions.
129 changes: 71 additions & 58 deletions src/descriptors-field.adb
Original file line number Diff line number Diff line change
Expand Up @@ -76,70 +76,83 @@ package body Descriptors.Field is
end;
end if;

for J in 0 .. Nodes.Length (List) - 1 loop
if Nodes.Node_Type (Nodes.Item (List, J)) = Element_Node then
declare
Child : constant Element := Element (Nodes.Item (List, J));
Tag : String renames Elements.Get_Tag_Name (Child);
begin
if Tag = "name" then
Result.Name := Get_Value (Child);

elsif Tag = "description" then
Result.Description := Get_Value (Child);

elsif Tag = "bitOffset"
or else Tag = "lsb"
then
Result.LSB := Get_Value (Child);

elsif Tag = "bitWidth" then
Result.Size := Get_Value (Child);

elsif Tag = "msb" then
Result.Size := Get_Value (Child) - Result.LSB + 1;

elsif Tag = "bitRange" then
-- bitRange has the form: [XX:YY] where XX is the MSB,
-- and YY is the LSB
declare
Val : String renames Get_Value (Child);
begin
for K in Val'Range loop
if Val (K) = ':' then
Result.LSB :=
Natural'Value (Val (K + 1 .. Val'Last - 1));
Result.Size :=
Natural'Value (Val (2 .. K - 1)) - Result.LSB + 1;
end if;
end loop;
end;
declare
Size_Calculated : Boolean := False;
begin
for J in 0 .. Nodes.Length (List) - 1 loop
if Nodes.Node_Type (Nodes.Item (List, J)) = Element_Node then
declare
Child : constant Element := Element (Nodes.Item (List, J));
Tag : String renames Elements.Get_Tag_Name (Child);
begin
if Tag = "name" then
Result.Name := Get_Value (Child);

elsif Tag = "access" then
Result.Acc := Get_Value (Child);
elsif Tag = "description" then
Result.Description := Get_Value (Child);

elsif Tag = "modifiedWriteValues" then
Result.Mod_Write_Values := Get_Value (Child);
elsif Tag = "bitOffset"
or else Tag = "lsb"
then
Result.LSB := Get_Value (Child);

elsif Tag = "readAction" then
Result.Read_Action := Get_Value (Child);
elsif Tag = "bitWidth" then
Result.Size := Get_Value (Child);
Size_Calculated := True;

elsif Tag = "enumeratedValues" then
declare
Enum : constant Descriptors.Enumerate.Enumerate_T :=
Descriptors.Enumerate.Read_Enumerate
(Child, Result.Enums, Result.Acc = Write_Only);
begin
Result.Enums.Append (Enum);
end;
elsif Tag = "msb" then
Result.MSB := Get_Value (Child);

else
Ada.Text_IO.Put_Line
("*** WARNING: ignoring field element " & Tag & " at " & Full_Name (Child));
end if;
end;
elsif Tag = "bitRange" then
-- bitRange has the form: [XX:YY] where XX is the MSB,
-- and YY is the LSB
declare
Val : String renames Get_Value (Child);
begin
for K in Val'Range loop
if Val (K) = ':' then
Result.LSB :=
Natural'Value (Val (K + 1 .. Val'Last - 1));
Result.Size :=
Natural'Value (Val (2 .. K - 1)) - Result.LSB + 1;
end if;
end loop;
end;
Size_Calculated := True;

elsif Tag = "access" then
Result.Acc := Get_Value (Child);

elsif Tag = "modifiedWriteValues" then
Result.Mod_Write_Values := Get_Value (Child);

elsif Tag = "readAction" then
Result.Read_Action := Get_Value (Child);

elsif Tag = "enumeratedValues" then
declare
Enum : constant Descriptors.Enumerate.Enumerate_T :=
Descriptors.Enumerate.Read_Enumerate
(Child, Result.Enums, Result.Acc = Write_Only);
begin
Result.Enums.Append (Enum);
end;

else
Ada.Text_IO.Put_Line
("*** WARNING: ignoring field element " & Tag & " at " & Full_Name (Child));
end if;

end;
end if;
end loop;

-- Neither bitRange nor bitWidth has been used
if not Size_Calculated then
Result.Size := Result.MSB - Result.LSB + 1;
end if;
end loop;

end;

return Result;
end Read_Field;
Expand Down
2 changes: 2 additions & 0 deletions src/descriptors-field.ads
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ package Descriptors.Field is
Name : Unbounded.Unbounded_String;
Description : Unbounded.Unbounded_String;
LSB : Natural;
MSB : Natural;
Size : Natural;
Acc : Access_Type;
Mod_Write_Values : Modified_Write_Values_Type := Modify;
Expand All @@ -51,6 +52,7 @@ package Descriptors.Field is
Unbounded.Null_Unbounded_String,
0,
0,
0,
Read_Write,
others => <>);

Expand Down

0 comments on commit 1ef42c7

Please sign in to comment.