From 576884b6461164e16dd4186f535df5c727a81b2d Mon Sep 17 00:00:00 2001 From: Vadim Godunko Date: Sat, 30 Nov 2024 18:50:37 +0400 Subject: [PATCH] Add option to use `No_Elaboration_Code_All` pragma. --- src/ada_gen.adb | 6 +++--- src/svd2ada.adb | 36 ++++++++++++++++++++++-------------- src/svd2ada_utils.adb | 39 +++++++++++++++++++++++++++++---------- src/svd2ada_utils.ads | 6 +++++- 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/src/ada_gen.adb b/src/ada_gen.adb index c075e17..eb8a6b7 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 -- @@ -1116,7 +1116,7 @@ package body Ada_Gen is G_Empty_Line := True; if Spec.Preelaborated then - if not SVD2Ada_Utils.In_Runtime then + if not SVD2Ada_Utils.No_Elaboration_Code_All then -- When part of the runtime, we need the more strict -- No_Elaboration_Code_All Ada.Text_IO.Put_Line @@ -1172,7 +1172,7 @@ package body Ada_Gen is if Spec.Preelaborated then Ada.Text_IO.Put_Line (F, " pragma Preelaborate;"); - if SVD2Ada_Utils.In_Runtime then + if SVD2Ada_Utils.No_Elaboration_Code_All then Ada.Text_IO.Put_Line (F, " pragma No_Elaboration_Code_All;"); end if; diff --git a/src/svd2ada.adb b/src/svd2ada.adb index cf7202a..3468398 100644 --- a/src/svd2ada.adb +++ b/src/svd2ada.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 -- @@ -67,21 +67,22 @@ procedure SVD2Ada is Executable_Location); -- The generated Device - Device : Descriptors.Device.Device_T; - SVD_File_Name : Unbounded_String; + Device : Descriptors.Device.Device_T; + SVD_File_Name : Unbounded_String; -- Command line parser and switches/arguments - Cmd_Line_Cfg : GNAT.Command_Line.Command_Line_Configuration; - Root_Pkg_Name : aliased GNAT.Strings.String_Access; - Output_Dir : aliased GNAT.Strings.String_Access; - Base_Types_Pkg : aliased GNAT.Strings.String_Access; - Gen_Booleans : aliased Boolean := False; - Gen_UInt_Always : aliased Boolean := False; - No_UInt_Subtype : aliased Boolean := False; - No_Arrays : aliased Boolean := False; - No_Defaults : aliased Boolean := False; - No_VFA_On_Types : aliased Boolean := False; - Gen_IRQ_Support : aliased Boolean := False; + Cmd_Line_Cfg : GNAT.Command_Line.Command_Line_Configuration; + Root_Pkg_Name : aliased GNAT.Strings.String_Access; + Output_Dir : aliased GNAT.Strings.String_Access; + Base_Types_Pkg : aliased GNAT.Strings.String_Access; + Gen_Booleans : aliased Boolean := False; + Gen_UInt_Always : aliased Boolean := False; + No_UInt_Subtype : aliased Boolean := False; + No_Arrays : aliased Boolean := False; + No_Defaults : aliased Boolean := False; + No_VFA_On_Types : aliased Boolean := False; + Gen_IRQ_Support : aliased Boolean := False; + No_Elab_Code_All : aliased Boolean := False; use type GNAT.Strings.String_Access; @@ -177,6 +178,12 @@ procedure SVD2Ada is -- register record type when those fields are -- themselves represented as register types Value => True); + Define_Switch + (Cmd_Line_Cfg, + Output => No_Elab_Code_All'Access, + Long_Switch => "--no-elaboration-code-all", + Help => "use pragma No_Elaboration_Code_All", + Value => True); end Configure_Command_Line; ------------------------ @@ -202,6 +209,7 @@ procedure SVD2Ada is Set_No_Defaults (No_Defaults); Set_No_UInt_Subtype (No_UInt_Subtype); Set_No_VFA_On_Reg_Types (No_VFA_On_Types); + Set_No_Elaboration_Code_All (No_Elab_Code_All); if Base_Types_Pkg.all /= "" then Set_Base_Types_Package (Base_Types_Pkg.all); diff --git a/src/svd2ada_utils.adb b/src/svd2ada_utils.adb index 9ca9982..f645abd 100644 --- a/src/svd2ada_utils.adb +++ b/src/svd2ada_utils.adb @@ -2,7 +2,7 @@ -- -- -- SVD Binding Generator -- -- -- --- Copyright (C) 2015-200, AdaCore -- +-- Copyright (C) 2015-2004, 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 -- @@ -25,15 +25,16 @@ with GNAT.OS_Lib; use GNAT.OS_Lib; package body SVD2Ada_Utils is - G_Use_Boolean : Boolean := False; - G_Types_Pkg : Unbounded_String := Null_Unbounded_String; - G_Root_Pkg : Unbounded_String := Null_Unbounded_String; - G_Use_UInt : Boolean := False; - G_Gen_Arrays : Boolean := True; - G_No_VFA_On_Reg_Types : Boolean := False; - G_Gen_IRQ_Support : Boolean := False; - G_Gen_UInt_Subtype : Boolean := True; - G_Gen_Fields_Default : Boolean := True; + G_Use_Boolean : Boolean := False; + G_Types_Pkg : Unbounded_String := Null_Unbounded_String; + G_Root_Pkg : Unbounded_String := Null_Unbounded_String; + G_Use_UInt : Boolean := False; + G_Gen_Arrays : Boolean := True; + G_No_VFA_On_Reg_Types : Boolean := False; + G_Gen_IRQ_Support : Boolean := False; + G_Gen_UInt_Subtype : Boolean := True; + G_Gen_Fields_Default : Boolean := True; + G_No_Elaboration_Code_All : Boolean := False; function Installation_Dir (Exec_with_Path : String) return String; -- Exec_with_Path is the executable name preceeded by the absolute or @@ -383,4 +384,22 @@ package body SVD2Ada_Utils is or else Word = "with" or else Word = "xor"); + ----------------------------- + -- No_Elaboration_Code_All -- + ----------------------------- + + function No_Elaboration_Code_All return Boolean is + begin + return In_Runtime or G_No_Elaboration_Code_All; + end No_Elaboration_Code_All; + + --------------------------------- + -- Set_No_Elaboration_Code_All -- + --------------------------------- + + procedure Set_No_Elaboration_Code_All (Value : Boolean) is + begin + G_No_Elaboration_Code_All := Value; + end Set_No_Elaboration_Code_All; + end SVD2Ada_Utils; diff --git a/src/svd2ada_utils.ads b/src/svd2ada_utils.ads index a2df8e0..df17906 100644 --- a/src/svd2ada_utils.ads +++ b/src/svd2ada_utils.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 -- @@ -49,6 +49,10 @@ package SVD2Ada_Utils is function In_Runtime return Boolean; + function No_Elaboration_Code_All return Boolean; + + procedure Set_No_Elaboration_Code_All (Value : Boolean); + procedure Set_No_VFA_On_Reg_Types (Value : Boolean); function No_VFA_On_Reg_Types return Boolean;