Skip to content

Commit

Permalink
Add option to use No_Elaboration_Code_All pragma.
Browse files Browse the repository at this point in the history
  • Loading branch information
godunko committed Nov 30, 2024
1 parent 1ef42c7 commit 576884b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 28 deletions.
6 changes: 3 additions & 3 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 @@ -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
Expand Down Expand Up @@ -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;
Expand Down
36 changes: 22 additions & 14 deletions src/svd2ada.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 @@ -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;

Expand Down Expand Up @@ -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;

------------------------
Expand All @@ -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);
Expand Down
39 changes: 29 additions & 10 deletions src/svd2ada_utils.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand All @@ -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
Expand Down Expand Up @@ -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;
6 changes: 5 additions & 1 deletion src/svd2ada_utils.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 @@ -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;
Expand Down

0 comments on commit 576884b

Please sign in to comment.