diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-10-15 06:41:36 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-10-15 06:41:36 +0200 |
commit | acf68c6a935edaf9cd3f575a5606e8fc6bd0fecb (patch) | |
tree | 9bc90b9c564e3bc20cadf8516f4854de0587ed70 | |
parent | 2485c247d5eae5f88c37708c2346c015caf22dbc (diff) | |
download | ghdl-acf68c6a935edaf9cd3f575a5606e8fc6bd0fecb.tar.gz ghdl-acf68c6a935edaf9cd3f575a5606e8fc6bd0fecb.tar.bz2 ghdl-acf68c6a935edaf9cd3f575a5606e8fc6bd0fecb.zip |
ghdlsynth: allow --work= option in the middle of files.
-rw-r--r-- | src/ghdldrv/ghdlsynth.adb | 14 | ||||
-rw-r--r-- | src/libraries.adb | 27 | ||||
-rw-r--r-- | src/libraries.ads | 8 |
3 files changed, 48 insertions, 1 deletions
diff --git a/src/ghdldrv/ghdlsynth.adb b/src/ghdldrv/ghdlsynth.adb index 041b00528..448a248be 100644 --- a/src/ghdldrv/ghdlsynth.adb +++ b/src/ghdldrv/ghdlsynth.adb @@ -147,6 +147,7 @@ package body Ghdlsynth is Flags.Flag_Elaborate_With_Outdated := E_Opt >= Args'First; Flags.Flag_Only_Elab_Warnings := True; + -- Load content only if there are no files. Libraries.Load_Work_Library (E_Opt >= Args'First); -- Do not canon concurrent statements. @@ -154,7 +155,18 @@ package body Ghdlsynth is -- Analyze files (if any) for I in Args'First .. E_Opt - 1 loop - Design_File := Ghdlcomp.Compile_Analyze_File2 (Args (I).all); + declare + Arg : String renames Args (I).all; + 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 + return Null_Iir; + end if; + else + Design_File := Ghdlcomp.Compile_Analyze_File2 (Arg); + end if; + end; end loop; pragma Unreferenced (Design_File); diff --git a/src/libraries.adb b/src/libraries.adb index 93f3f772c..d4e809b63 100644 --- a/src/libraries.adb +++ b/src/libraries.adb @@ -694,6 +694,14 @@ package body Libraries is end if; Work_Library := Std_Library; else + -- If the library is already known, just switch to it. This is used + -- for --work= option in the middle of files. + Work_Library := Vhdl.Utils.Find_Name_In_Chain + (Libraries_Chain, Work_Library_Name); + if Work_Library /= Null_Iir then + return; + end if; + Work_Library := Create_Iir (Iir_Kind_Library_Declaration); Set_Location (Work_Library, Library_Location); Set_Library_Directory (Work_Library, Work_Directory); @@ -1633,4 +1641,23 @@ package body Libraries is begin return Libraries_Chain; end Get_Libraries_Chain; + + function Decode_Work_Option + (Opt : String; Immediate : Boolean; Load_Lib : Boolean) return Boolean + is + pragma Assert (Opt'First = 1); + 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 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 396ba8885..99dcca393 100644 --- a/src/libraries.ads +++ b/src/libraries.ads @@ -167,6 +167,14 @@ 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. + -- 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; + -- Get the chain of libraries. Can be used only to read (it musn't be -- modified). function Get_Libraries_Chain return Iir_Library_Declaration; |