From 1c854eab4dec0141af75b2d85fd05bce31df9fac Mon Sep 17 00:00:00 2001 From: Simon Wright Date: Tue, 3 Sep 2024 14:04:46 +0100 Subject: [PATCH 1/6] CI runs on latest OSs * .github/workflows/main.yml: (gnat_version): removed. (gprbuild_version): removed. (actions/checkout): v3. (project/setup-alire): v3. (toolchain): specify gnat_native before gprbuild, to avoid picking mismatched versions. --- .github/workflows/main.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d11e97f..d6c83ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,3 @@ - - on: push: pull_request: @@ -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 From 2873046baef77e4dcd2db509ada029024df536bd Mon Sep 17 00:00:00 2001 From: Simon Wright Date: Tue, 3 Sep 2024 14:07:34 +0100 Subject: [PATCH 2/6] Install schema, SVDs. * svd2ada.gpr (Install): new. --- svd2ada.gpr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/svd2ada.gpr b/svd2ada.gpr index e17029c..da01776 100644 --- a/svd2ada.gpr +++ b/svd2ada.gpr @@ -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; From 11e0aa11d94ffb64848b38b7faa299c8d8de1ea2 Mon Sep 17 00:00:00 2001 From: Simon Wright Date: Tue, 3 Sep 2024 14:17:32 +0100 Subject: [PATCH 3/6] Fix warning: "variable is assigned but never read". This warning (treated as error) causes build failure in CI on at least Ubuntu. * src/ada_gen.adb (Get_Boolean): rename Dead, Dead2 to Dummy, Dummy2, so GNAT won't report unused warnings. --- src/ada_gen.adb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ada_gen.adb b/src/ada_gen.adb index c075e17..1daf4cb 100644 --- a/src/ada_gen.adb +++ b/src/ada_gen.adb @@ -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 -- @@ -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; From a0f8942eaabe1b435f7cce20d58cec459b8429b0 Mon Sep 17 00:00:00 2001 From: Simon Wright Date: Tue, 3 Sep 2024 14:21:03 +0100 Subject: [PATCH 4/6] Process dimensioned record fields. From the SVD, field components have an optional : specifies the number of array elements, specifies the address (?bit) offset between consecutive array elements, (optional) 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 fields, where %s in the Name translates to the first component of incremented by 1 for each field, and LSB, MSB are incremented by . * src/descriptors-field.ads (Field_T): added components Dimensions: contents of the field in the SVD, Increment: contents of the field in the SVD, Index: the first component of the field in the SVD. (Null_Field): added values for the new components, using associations. * src/descriptors-field.adb: (context): with Ada.Strings.Fixed, so we can pick out which Trim is required. (Read_Field): initialize new fields in Result. In particular, Dimensions will be set to 1. If present, process tags dim, dimIncrement, dimIndex. (Dump): add new function Insert_Dimensioned_Fields. Call this function on the input Reg_Fields, and then run the rest of Dump on the result. (Insert_Dimensioned_Fields): new. For each Field in the original, insert as many copies as indicated by its Dimensions, updating the Name, LSB and MSB. Note that if the original field from the SVD had no component, Dimensions will have been set to 1 by Read_Field, so this process will be done just once (resulting in no change). --- src/descriptors-field.adb | 83 ++++++++++++++++++++++++++++++++++++++- src/descriptors-field.ads | 34 ++++++++++++---- 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/src/descriptors-field.adb b/src/descriptors-field.adb index 5962c95..ea1f677 100644 --- a/src/descriptors-field.adb +++ b/src/descriptors-field.adb @@ -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 -- @@ -18,6 +18,7 @@ ------------------------------------------------------------------------------ with Ada.Text_IO; +with Ada.Strings.Fixed; with Interfaces; use Interfaces; with DOM.Core; use DOM.Core; @@ -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; @@ -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 @@ -250,9 +275,60 @@ 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 : Natural := D - 1; + Index : Natural := Original.Index + Addition; + LSB : Natural := Original.LSB + Original.Increment * Addition; + MSB : Natural := Original.MSB + Original.Increment * Addition; + begin + Substitute : + loop + declare + Percent_S : Natural + := Unbounded.Index (Candidate.Name, Pattern => "%s"); + begin + exit 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 -- ----------------- @@ -293,8 +369,11 @@ package body Descriptors.Field is All_RO : Boolean := True; use Descriptors.Register; + Full_Fields : 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; diff --git a/src/descriptors-field.ads b/src/descriptors-field.ads index bc1035f..11060a3 100644 --- a/src/descriptors-field.ads +++ b/src/descriptors-field.ads @@ -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 -- @@ -32,9 +32,24 @@ with Descriptors.Enumerate; -- Decodes the elements of the SVD file. package Descriptors.Field is + -- From the SVD, these components are in an optional : + -- specifies the number of array elements, + -- specifies the address (?bit) offset between consecutive + -- array elements, + -- (optional) 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 fields, where %s in the Name translates + -- to the first component of incremented by 1 for each + -- field, and LSB, MSB are incremented by . + type Field_T is record Name : Unbounded.Unbounded_String; Description : Unbounded.Unbounded_String; + Dimensions : Natural; -- + Increment : Natural; -- + Index : Natural; -- first component of LSB : Natural; MSB : Natural; Size : Natural; @@ -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); From 4c0d576bfd431e2a1336ab1b5b042a31e1103169 Mon Sep 17 00:00:00 2001 From: Simon Wright Date: Tue, 3 Sep 2024 14:31:17 +0100 Subject: [PATCH 5/6] Update manifest to 0.1.1. * alire.toml (version): updated to 0.1.1. (xmlada): updated to ">=22.0.0" (we're presently on 24.0.0). --- alire.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alire.toml b/alire.toml index a01faea..9aff075 100644 --- a/alire.toml +++ b/alire.toml @@ -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 "] @@ -9,7 +9,7 @@ maintainers-logins = ["Fabien-Chouteau"] executables = ["svd2ada"] [[depends-on]] -xmlada = "^22.0.0" +xmlada = ">=22.0.0" [configuration] disabled = true From 4e4228af54cb27adf0bde8cf6e22fe80950b6f9a Mon Sep 17 00:00:00 2001 From: Simon Wright Date: Tue, 3 Sep 2024 14:44:19 +0100 Subject: [PATCH 6/6] Fix style warnings. Warnings reported in CI by GCC 14.2.1 on Ubuntu, but not locally on macOS. * src/descriptors-field.adb: descriptors-field.adb:302:19: warning: "Addition" is not modified descriptors-field.adb:303:19: warning: "Index" is not modified descriptors-field.adb:304:19: warning: "LSB" is not modified descriptors-field.adb:305:19: warning: "MSB" is not modified descriptors-field.adb:310:25: warning: "Percent_S" is not modified descriptors-field.adb:313:25: (style) "exit Substitute" required descriptors-field.adb:372:07: warning: "Full_Fields" is not modified --- src/descriptors-field.adb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/descriptors-field.adb b/src/descriptors-field.adb index ea1f677..8b22755 100644 --- a/src/descriptors-field.adb +++ b/src/descriptors-field.adb @@ -299,18 +299,20 @@ package body Descriptors.Field is Replacement : declare Candidate : Field_T := Original; - Addition : Natural := D - 1; - Index : Natural := Original.Index + Addition; - LSB : Natural := Original.LSB + Original.Increment * Addition; - MSB : Natural := Original.MSB + Original.Increment * Addition; + 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 : Natural + Percent_S : constant Natural := Unbounded.Index (Candidate.Name, Pattern => "%s"); begin - exit when Percent_S = 0; + exit Substitute when Percent_S = 0; Unbounded.Replace_Slice (Candidate.Name, Low => Percent_S, @@ -353,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; @@ -369,7 +372,7 @@ package body Descriptors.Field is All_RO : Boolean := True; use Descriptors.Register; - Full_Fields : Field_Vectors.Vector + Full_Fields : constant Field_Vectors.Vector := Insert_Dimensioned_Fields (Reg_Fields); begin