From 2fa4b913aefa9b23f3f7773b62d92858a6e3732b Mon Sep 17 00:00:00 2001
From: Tristan Gingold <tgingold@free.fr>
Date: Sun, 15 May 2022 17:12:23 +0200
Subject: elab-debugger: add append_info_menu, to_num

---
 src/synth/elab-debugger.adb | 39 ++++++++++++++++++++++++++++++++++-----
 src/synth/elab-debugger.ads | 16 ++++++++++++++++
 2 files changed, 50 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/synth/elab-debugger.adb b/src/synth/elab-debugger.adb
index 0ae4ef856..e9f372dc3 100644
--- a/src/synth/elab-debugger.adb
+++ b/src/synth/elab-debugger.adb
@@ -16,7 +16,6 @@
 --  You should have received a copy of the GNU General Public License
 --  along with this program.  If not, see <gnu.org/licenses>.
 
-with Types; use Types;
 with Files_Map;
 with Tables;
 with Simple_IO; use Simple_IO;
@@ -286,6 +285,20 @@ package body Elab.Debugger is
       return Get_Word (S (F .. S'Last));
    end Get_Word;
 
+   procedure To_Num (Str : String; Res : out Uns32; Valid : out Boolean) is
+   begin
+      Res := 0;
+      Valid := True;
+      for P in Str'Range loop
+         if Str (P) in '0' .. '9' then
+            Res := Res * 10 + Character'Pos (Str (P)) - Character'Pos ('0');
+         else
+            Valid := False;
+            return;
+         end if;
+      end loop;
+   end To_Num;
+
    procedure Info_Params_Proc (Line : String)
    is
       pragma Unreferenced (Line);
@@ -655,9 +668,11 @@ package body Elab.Debugger is
       Next => null,
       First => Menu_Help2'Access);
 
-   procedure Append_Menu_Command (Name : Cst_String_Acc;
-                                  Help : Cst_String_Acc;
-                                  Proc : Menu_Procedure)
+   --  Append command to MENU.
+   procedure Append_Menu (Menu : Menu_Entry;
+                          Name : Cst_String_Acc;
+                          Help : Cst_String_Acc;
+                          Proc : Menu_Procedure)
    is
       M, L : Menu_Entry_Acc;
    begin
@@ -667,13 +682,27 @@ package body Elab.Debugger is
                            Next => null,
                            Proc => Proc);
 
-      L := Menu_Top.First;
+      L := Menu.First;
       while L.Next /= null loop
          L := L.Next;
       end loop;
       L.Next := M;
+   end Append_Menu;
+
+   procedure Append_Menu_Command (Name : Cst_String_Acc;
+                                  Help : Cst_String_Acc;
+                                  Proc : Menu_Procedure) is
+   begin
+      Append_Menu (Menu_Top, Name, Help, Proc);
    end Append_Menu_Command;
 
+   procedure Append_Info_Command (Name : Cst_String_Acc;
+                                  Help : Cst_String_Acc;
+                                  Proc : Menu_Procedure) is
+   begin
+      Append_Menu (Menu_Info, Name, Help, Proc);
+   end Append_Info_Command;
+
    function Find_Menu (Menu : Menu_Entry_Acc; Cmd : String)
                       return Menu_Entry_Acc
    is
diff --git a/src/synth/elab-debugger.ads b/src/synth/elab-debugger.ads
index 5b1bda533..3376e3ba3 100644
--- a/src/synth/elab-debugger.ads
+++ b/src/synth/elab-debugger.ads
@@ -16,6 +16,8 @@
 --  You should have received a copy of the GNU General Public License
 --  along with this program.  If not, see <gnu.org/licenses>.
 
+with Types; use Types;
+
 with Vhdl.Nodes; use Vhdl.Nodes;
 
 with Elab.Vhdl_Context; use Elab.Vhdl_Context;
@@ -46,4 +48,18 @@ package Elab.Debugger is
    procedure Append_Menu_Command (Name : Cst_String_Acc;
                                   Help : Cst_String_Acc;
                                   Proc : Menu_Procedure);
+
+   --  Append a command to the info menu.
+   procedure Append_Info_Command (Name : Cst_String_Acc;
+                                  Help : Cst_String_Acc;
+                                  Proc : Menu_Procedure);
+
+
+   --  Utilities for menu commands.
+
+   --  Return the position of the first non-blank character.
+   function Skip_Blanks (S : String) return Positive;
+
+   --  Convert STR to number RES, set VALID to true iff the conversion is ok.
+   procedure To_Num (Str : String; Res : out Uns32; Valid : out Boolean);
 end Elab.Debugger;
-- 
cgit v1.2.3