Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI; add dimensioned register fields #108

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


on:
push:
pull_request:
Expand All @@ -14,12 +12,10 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
gnat_version: [^11]
gprbuild_version: [^21]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: alire-project/setup-alire@v1
- uses: actions/checkout@v3
- uses: alire-project/setup-alire@v3
with:
toolchain: gprbuild${{ matrix.gprbuild_version }} gnat_native${{ matrix.gnat_version }} --disable-assistant
toolchain: gnat_native${{ matrix.gnat_version }} gprbuild${{ matrix.gprbuild_version }} --disable-assistant
- run: alr build
4 changes: 2 additions & 2 deletions alire.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "svd2ada"
description = "Ada binding generator from CMSIS-SVD hardware descriptions files"
version = "0.1.0"
version = "0.1.1"

authors = ["AdaCore"]
maintainers = ["Fabien Chouteau <[email protected]>"]
Expand All @@ -9,7 +9,7 @@ maintainers-logins = ["Fabien-Chouteau"]
executables = ["svd2ada"]

[[depends-on]]
xmlada = "^22.0.0"
xmlada = ">=22.0.0"

[configuration]
disabled = true
12 changes: 6 additions & 6 deletions src/ada_gen.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- SVD Binding Generator --
-- --
-- Copyright (C) 2015-2020, AdaCore --
-- Copyright (C) 2015-2024, AdaCore --
-- --
-- SVD2Ada is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
Expand Down Expand Up @@ -1757,16 +1757,16 @@ package body Ada_Gen is

function Get_Boolean return Ada_Type_Enum
is
Result : Ada_Type_Enum;
Dead : Ada_Enum_Value;
Dead2 : constant Ada_Spec := New_Spec ("Standard", "", False);
Result : Ada_Type_Enum;
Dummy : Ada_Enum_Value;
Dummy_2 : constant Ada_Spec := New_Spec ("Standard", "", False);
begin
Result := (Id => To_Unbounded_String ("Boolean"),
Comment => New_Comment ("", False),
Aspects => <>,
Values => <>);
Dead := Add_Enum_Id (Dead2, Result, "False", 0);
Dead := Add_Enum_Id (Dead2, Result, "True", 0);
Dummy := Add_Enum_Id (Dummy_2, Result, "False", 0);
Dummy := Add_Enum_Id (Dummy_2, Result, "True", 0);

return Result;
end Get_Boolean;
Expand Down
88 changes: 85 additions & 3 deletions src/descriptors-field.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- SVD Binding Generator --
-- --
-- Copyright (C) 2015-2020, AdaCore --
-- Copyright (C) 2015-2024, AdaCore --
-- --
-- SVD2Ada is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
Expand All @@ -18,6 +18,7 @@
------------------------------------------------------------------------------

with Ada.Text_IO;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;

with DOM.Core; use DOM.Core;
Expand Down Expand Up @@ -54,6 +55,9 @@ package body Descriptors.Field is
Derived_From : constant String := Elements.Get_Attribute (Elt, "derivedFrom");

begin
Result.Dimensions := 1;
Result.Increment := 0;
Result.Index := 0;
Result.Acc := Default_Access;
Result.Read_Action := Default_Read;

Expand Down Expand Up @@ -91,6 +95,27 @@ package body Descriptors.Field is
elsif Tag = "description" then
Result.Description := Get_Value (Child);

elsif Tag = "dim" then
Result.Dimensions := Get_Value (Child);

elsif Tag = "dimIncrement" then
Result.Increment := Get_Value (Child);

elsif Tag = "dimIndex" then
declare
Content : constant String := Get_Value (Child);
begin
for J in Content'Range loop
if Content (J) = '-' then
Result.Index := Natural'Value
(Content (Content'First .. J - 1));
goto End_Getting_Index;
end if;
end loop;
Result.Index := 1;
<< End_Getting_Index >>
end;

elsif Tag = "bitOffset"
or else Tag = "lsb"
then
Expand Down Expand Up @@ -250,9 +275,62 @@ package body Descriptors.Field is
is
use Unbounded, Ada_Gen;

function Insert_Dimensioned_Fields (Reg_Fields : Field_Vectors.Vector)
return Field_Vectors.Vector;

function Get_Default (Index : Natural; Size : Natural) return Unsigned;
-- Retrieves the field default value from the Register's reset value

-------------------------------
-- Insert_Dimensioned_Fields --
-------------------------------

function Insert_Dimensioned_Fields (Reg_Fields : Field_Vectors.Vector)
return Field_Vectors.Vector
is
Result : Field_Vectors.Vector;
begin
Each_Field :
for Original of Reg_Fields loop

Dimensions :
for D in 1 .. Original.Dimensions loop

Replacement :
declare
Candidate : Field_T := Original;
Addition : constant Natural := D - 1;
Index : constant Natural := Original.Index + Addition;
LSB : constant Natural
:= Original.LSB + Original.Increment * Addition;
MSB : constant Natural
:= Original.MSB + Original.Increment * Addition;
begin
Substitute :
loop
declare
Percent_S : constant Natural
:= Unbounded.Index (Candidate.Name, Pattern => "%s");
begin
exit Substitute when Percent_S = 0;
Unbounded.Replace_Slice
(Candidate.Name,
Low => Percent_S,
High => Percent_S + 1,
By => Fixed.Trim (Index'Image, Side => Both));
end;
Candidate.LSB := LSB;
Candidate.MSB := MSB;
end loop Substitute;
Result.Append (Candidate);
end Replacement;

end loop Dimensions;

end loop Each_Field;
return Result;
end Insert_Dimensioned_Fields;

-----------------
-- Get_Default --
-----------------
Expand All @@ -277,7 +355,8 @@ package body Descriptors.Field is
end if;
end Get_Default;

Fields : array (0 .. Properties.Size - 1) of Field_T := (others => Null_Field);
Fields : array (0 .. Properties.Size - 1) of Field_T
:= (others => Null_Field);
Index : Natural;
Index2 : Natural;
Length : Natural;
Expand All @@ -293,8 +372,11 @@ package body Descriptors.Field is
All_RO : Boolean := True;
use Descriptors.Register;

Full_Fields : constant Field_Vectors.Vector
:= Insert_Dimensioned_Fields (Reg_Fields);

begin
for Field of Reg_Fields loop
for Field of Full_Fields loop
Fields (Field.LSB) := Field;
end loop;

Expand Down
34 changes: 26 additions & 8 deletions src/descriptors-field.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- SVD Binding Generator --
-- --
-- Copyright (C) 2015-2020, AdaCore --
-- Copyright (C) 2015-2024, AdaCore --
-- --
-- SVD2Ada is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
Expand Down Expand Up @@ -32,9 +32,24 @@ with Descriptors.Enumerate;
-- Decodes the <field> elements of the SVD file.
package Descriptors.Field is

-- From the SVD, these components are in an optional <dimElementGroup>:
-- <dim> specifies the number of array elements,
-- <dimIncrement> specifies the address (?bit) offset between consecutive
-- array elements,
-- (optional) <dimIndex> specifies "a comma seperated list of
-- strings being used for identifying each element in the array",
-- but we only see r'[0-9]+\-[0-9]+'.
--
-- We will produce <dim> fields, where %s in the Name translates
-- to the first component of <dimIndex> incremented by 1 for each
-- field, and LSB, MSB are incremented by <dimIncrement>.

type Field_T is record
Name : Unbounded.Unbounded_String;
Description : Unbounded.Unbounded_String;
Dimensions : Natural; -- <dim/>
Increment : Natural; -- <dimIncrement/>
Index : Natural; -- first component of <dimIndex/>
LSB : Natural;
MSB : Natural;
Size : Natural;
Expand All @@ -48,13 +63,16 @@ package Descriptors.Field is
function "=" (F1, F2 : Field_T) return Boolean;

Null_Field : constant Field_T :=
(Unbounded.Null_Unbounded_String,
Unbounded.Null_Unbounded_String,
0,
0,
0,
Read_Write,
others => <>);
(Name => Unbounded.Null_Unbounded_String,
Description => Unbounded.Null_Unbounded_String,
Dimensions => 0,
Increment => 0,
Index => 0,
LSB => 0,
MSB => 0,
Size => 0,
Acc => Read_Write,
others => <>);

package Field_Vectors is new Ada.Containers.Vectors
(Positive, Field_T);
Expand Down
6 changes: 6 additions & 0 deletions svd2ada.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ project SVD2ada is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;

package Install is
for Mode use "usage";
for Required_Artifacts ("schema") use ("schema/");
for Required_Artifacts ("share/CMSIS-SVD") use ("CMSIS-SVD/");
end Install;

end SVD2ada;
Loading