From ea8d2686efd3a8474eb5beef8aa25b5e2e5c0bd5 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 7 Sep 2021 20:10:50 +0200 Subject: ghdllocal: generalize top level unit extraction --- src/ghdldrv/ghdlcomp.adb | 10 +++++++--- src/ghdldrv/ghdldrv.adb | 4 ++-- src/ghdldrv/ghdllocal.adb | 42 ++++++++++++++++++++++++++++++++++++++---- src/ghdldrv/ghdllocal.ads | 3 +++ src/ghdldrv/ghdlsynth.adb | 38 +++++++++----------------------------- 5 files changed, 59 insertions(+), 38 deletions(-) (limited to 'src/ghdldrv') diff --git a/src/ghdldrv/ghdlcomp.adb b/src/ghdldrv/ghdlcomp.adb index c778ecfb5..541e8b7cb 100644 --- a/src/ghdldrv/ghdlcomp.adb +++ b/src/ghdldrv/ghdlcomp.adb @@ -331,7 +331,11 @@ package body Ghdlcomp is Prim_Id : Name_Id; Sec_Id : Name_Id; begin - Extract_Elab_Unit (Cmd_Name, Args, Opt_Arg, Lib_Id, Prim_Id, Sec_Id); + Extract_Elab_Unit + (Cmd_Name, True, Args, Opt_Arg, Lib_Id, Prim_Id, Sec_Id); + if Prim_Id = Null_Identifier then + raise Option_Error; + end if; Flags.Flag_Elaborate := True; @@ -743,7 +747,7 @@ package body Ghdlcomp is Unit : Iir_Design_Unit; Lib : Iir_Library_Declaration; begin - Extract_Elab_Unit ("-m", Args, Next_Arg, Lib_Id, Prim_Id, Sec_Id); + Extract_Elab_Unit ("-m", False, Args, Next_Arg, Lib_Id, Prim_Id, Sec_Id); if not Setup_Libraries (True) then return; end if; @@ -889,7 +893,7 @@ package body Ghdlcomp is Next_Arg : Natural; begin Extract_Elab_Unit - ("--gen-makefile", Args, Next_Arg, Lib_Id, Prim_Id, Sec_Id); + ("--gen-makefile", False, Args, Next_Arg, Lib_Id, Prim_Id, Sec_Id); if not Setup_Libraries (True) then return; end if; diff --git a/src/ghdldrv/ghdldrv.adb b/src/ghdldrv/ghdldrv.adb index 6b49a8df2..a06acd402 100644 --- a/src/ghdldrv/ghdldrv.adb +++ b/src/ghdldrv/ghdldrv.adb @@ -978,7 +978,7 @@ package body Ghdldrv is end Arch_Suffix_Image; begin Library_Id := Null_Identifier; - Extract_Elab_Unit (Cmd_Name, Args, Run_Arg, + Extract_Elab_Unit (Cmd_Name, False, Args, Run_Arg, Library_Id, Primary_Id, Secondary_Id); if Secondary_Id = Null_Identifier then Base_Name := new String'(Image (Primary_Id)); @@ -1249,7 +1249,7 @@ package body Ghdldrv is Sec_Id : Name_Id; Opt_Arg : Natural; begin - Extract_Elab_Unit ("-r", Args, Opt_Arg, Lib_Id, Prim_Id, Sec_Id); + Extract_Elab_Unit ("-r", False, Args, Opt_Arg, Lib_Id, Prim_Id, Sec_Id); if Sec_Id = Null_Identifier then Base_Name := new String' (Image (Prim_Id) & Suffix.all); diff --git a/src/ghdldrv/ghdllocal.adb b/src/ghdldrv/ghdllocal.adb index 5ed6d3431..47758d2d1 100644 --- a/src/ghdldrv/ghdllocal.adb +++ b/src/ghdldrv/ghdllocal.adb @@ -33,6 +33,7 @@ with Vhdl.Scanner; with Vhdl.Configuration; with Vhdl.Utils; use Vhdl.Utils; with Vhdl.Prints; +with Vhdl.Errors; package body Ghdllocal is -- Version of the IEEE library to use. This just change paths. @@ -1744,15 +1745,46 @@ package body Ghdllocal is end Convert_Name; procedure Extract_Elab_Unit (Cmd_Name : String; + Auto : Boolean; Args : Argument_List; Next_Arg : out Natural; Lib_Id : out Name_Id; Prim_Id : out Name_Id; Sec_Id : out Name_Id) is begin + Next_Arg := Args'First; + Lib_Id := Null_Identifier; + Prim_Id := Null_Identifier; + Sec_Id := Null_Identifier; + if Args'Length = 0 then - Error ("command '" & Cmd_Name & "' requires an unit name"); - raise Option_Error; + -- No unit on the command line. + if not Auto then + Error ("command '" & Cmd_Name & "' requires an unit name"); + raise Option_Error; + end if; + + -- Find the top-level unit. + declare + use Errorout; + use Vhdl.Errors; + Top : Iir; + begin + Top := Vhdl.Configuration.Find_Top_Entity + (Libraries.Work_Library, Libraries.Command_Line_Location); + if Top = Null_Node then + Ghdlmain.Error ("no top unit found"); + return; + end if; + Errorout.Report_Msg (Msgid_Note, Option, No_Source_Coord, + "top entity is %i", (1 => +Top)); + if Nbr_Errors > 0 then + -- No need to configure if there are missing units. + return; + end if; + Prim_Id := Get_Identifier (Top); + end; + return; end if; declare @@ -1875,8 +1907,10 @@ package body Ghdllocal is Next_Arg : Natural; begin Extract_Elab_Unit - ("--elab-order", Args, Next_Arg, Lib_Id, Prim_Id, Sec_Id); - if not Setup_Libraries (True) then + ("--elab-order", True, Args, Next_Arg, Lib_Id, Prim_Id, Sec_Id); + if Prim_Id = Null_Identifier + or else not Setup_Libraries (True) + then return; end if; Files_List := Build_Dependence (Lib_Id, Prim_Id, Sec_Id); diff --git a/src/ghdldrv/ghdllocal.ads b/src/ghdldrv/ghdllocal.ads index c182f6c0e..f476ae24c 100644 --- a/src/ghdldrv/ghdllocal.ads +++ b/src/ghdldrv/ghdllocal.ads @@ -142,7 +142,10 @@ package Ghdllocal is function Is_File_Outdated (File : Iir_Design_File) return Boolean; -- Extract PRIM_ID and SEC_ID from ARGS. + -- If AUTO is true, the top unit is deduced from the existing one, + -- otherwise it must be present. procedure Extract_Elab_Unit (Cmd_Name : String; + Auto : Boolean; Args : Argument_List; Next_Arg : out Natural; Lib_Id : out Name_Id; diff --git a/src/ghdldrv/ghdlsynth.adb b/src/ghdldrv/ghdlsynth.adb index bffe86bff..6266e984c 100644 --- a/src/ghdldrv/ghdlsynth.adb +++ b/src/ghdldrv/ghdlsynth.adb @@ -33,7 +33,6 @@ with Simple_IO; with Libraries; with Flags; with Vhdl.Nodes; use Vhdl.Nodes; -with Vhdl.Errors; with Vhdl.Scanner; with Vhdl.Std_Package; with Vhdl.Canon; @@ -245,14 +244,12 @@ package body Ghdlsynth is function Ghdl_Synth_Configure (Init : Boolean; Cmd : Command_Synth; Args : Argument_List) return Node is - use Vhdl.Errors; use Vhdl.Configuration; use Errorout; E_Opt : Integer; Opt_Arg : Natural; Design_File : Iir; Config : Iir; - Top : Iir; Lib_Id : Name_Id; Prim_Id : Name_Id; Sec_Id : Name_Id; @@ -352,32 +349,15 @@ package body Ghdlsynth is end if; -- Elaborate - if E_Opt = Args'Last then - -- No unit on the command line. - - -- Find the top-level unit. - Top := Vhdl.Configuration.Find_Top_Entity - (Libraries.Work_Library, Libraries.Command_Line_Location); - if Top = Null_Node then - Ghdlmain.Error ("no top unit found"); - return Null_Iir; - end if; - Errorout.Report_Msg (Msgid_Note, Option, No_Source_Coord, - "top entity is %i", (1 => +Top)); - if Nbr_Errors > 0 then - -- No need to configure if there are missing units. - return Null_Iir; - end if; - Lib_Id := Null_Identifier; - Prim_Id := Get_Identifier (Top); - Sec_Id := Null_Identifier; - else - Extract_Elab_Unit ("--synth", Args (E_Opt + 1 .. Args'Last), Opt_Arg, - Lib_Id, Prim_Id, Sec_Id); - if Opt_Arg <= Args'Last then - Ghdlmain.Error ("extra options ignored"); - return Null_Iir; - end if; + Extract_Elab_Unit + ("--synth", True, Args (E_Opt + 1 .. Args'Last), Opt_Arg, + Lib_Id, Prim_Id, Sec_Id); + if Prim_Id = Null_Identifier then + return Null_Iir; + end if; + if Opt_Arg <= Args'Last then + Ghdlmain.Error ("extra options ignored"); + return Null_Iir; end if; Config := Vhdl.Configuration.Configure (Lib_Id, Prim_Id, Sec_Id); -- cgit v1.2.3