From 66335e7a44dc449e99706c26d51f6da11b01a7f7 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 15 Oct 2019 06:48:45 +0200 Subject: Use Decode_Work_Option in options. Factorize code. --- src/ghdldrv/ghdlsynth.adb | 4 +++- src/libraries.adb | 6 +----- src/libraries.ads | 10 ++++------ src/options.adb | 16 +++------------- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/ghdldrv/ghdlsynth.adb b/src/ghdldrv/ghdlsynth.adb index 448a248be..f22174e0e 100644 --- a/src/ghdldrv/ghdlsynth.adb +++ b/src/ghdldrv/ghdlsynth.adb @@ -160,7 +160,9 @@ package body Ghdlsynth is pragma Assert (Arg'First = 1); begin if Arg'Last > 7 and then Arg (1 .. 7) = "--work=" then - if not Libraries.Decode_Work_Option (Arg, True, False) then + if Libraries.Decode_Work_Option (Arg) then + Libraries.Load_Work_Library (True); + else return Null_Iir; end if; else diff --git a/src/libraries.adb b/src/libraries.adb index d4e809b63..c1d06c7eb 100644 --- a/src/libraries.adb +++ b/src/libraries.adb @@ -1642,8 +1642,7 @@ package body Libraries is return Libraries_Chain; end Get_Libraries_Chain; - function Decode_Work_Option - (Opt : String; Immediate : Boolean; Load_Lib : Boolean) return Boolean + function Decode_Work_Option (Opt : String) return Boolean is pragma Assert (Opt'First = 1); Name : String (1 .. Opt'Last - 8 + 1); @@ -1655,9 +1654,6 @@ package body Libraries is return False; end if; Libraries.Work_Library_Name := Get_Identifier (Name); - if Immediate then - Libraries.Load_Work_Library (not Load_Lib); - end if; return True; end Decode_Work_Option; end Libraries; diff --git a/src/libraries.ads b/src/libraries.ads index 99dcca393..1c954c938 100644 --- a/src/libraries.ads +++ b/src/libraries.ads @@ -167,13 +167,11 @@ package Libraries is -- If there are severals entities, return NULL_IIR; function Find_Entity_For_Component (Name: Name_Id) return Iir_Design_Unit; - -- Decode '--work=NAME' command line option. + -- Decode '--work=NAME' command line option and set the name of the + -- work library. The library has to be loaded later by calling + -- Load_Work_Library. -- Return false if NAME is not a valid name. - -- If IMMEDIATE is true, the library is created and loaded from disk - -- iff LOAD_LIB is true. If IMMEDIATE is false, the name of the work - -- library is simply set to NAME and Load_Work_Library has to be called. - function Decode_Work_Option - (Opt : String; Immediate : Boolean; Load_Lib : Boolean) return Boolean; + function Decode_Work_Option (Opt : String) return Boolean; -- Get the chain of libraries. Can be used only to read (it musn't be -- modified). diff --git a/src/options.adb b/src/options.adb index 3db68ba25..65521b411 100644 --- a/src/options.adb +++ b/src/options.adb @@ -17,7 +17,6 @@ -- 02111-1307, USA. with Simple_IO; -with Name_Table; with Errorout; use Errorout; with Libraries; with Std_Names; @@ -139,18 +138,9 @@ package body Options is elsif Opt'Length > 2 and then Opt (1 .. 2) = "-W" then return Option_Warning (Opt (3 .. Opt'Last), True); elsif Opt'Length > 7 and then Opt (1 .. 7) = "--work=" then - declare - use Name_Table; - Name : String (1 .. Opt'Last - 8 + 1); - Err : Boolean; - begin - Name := Opt (8 .. Opt'Last); - Vhdl.Scanner.Convert_Identifier (Name, Err); - if Err then - return Option_Err; - end if; - Libraries.Work_Library_Name := Get_Identifier (Name); - end; + if not Libraries.Decode_Work_Option (Opt) then + return Option_Err; + end if; elsif Opt = "-C" or else Opt = "--mb-comments" then Mb_Comment := True; elsif Opt = "--force-analysis" then -- cgit v1.2.3