From 05b8fe710d53d0db9c8d956bf9aa8bec526ac079 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 3 Mar 2020 21:27:27 +0100 Subject: vhdl: merge synopsys into the ieee libraries. For #980 --- src/flags.ads | 3 +++ src/ghdldrv/ghdldrv.adb | 10 ++++++++++ src/ghdldrv/ghdllocal.adb | 6 ++++-- src/options.adb | 2 ++ src/vhdl/vhdl-sem_names.adb | 48 ++++++++++++++++++++++++++------------------- 5 files changed, 47 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/flags.ads b/src/flags.ads index a90a4fea0..b05a830a3 100644 --- a/src/flags.ads +++ b/src/flags.ads @@ -148,6 +148,9 @@ package Flags is -- constant x : xtype := x; Flag_Relaxed_Rules : Boolean := False; + -- If true, allow to use synopsys packages (std_logic_arith & co). + Flag_Synopsys : Boolean := False; + -- --warn-undriven --Warn_Undriven : Boolean := False; diff --git a/src/ghdldrv/ghdldrv.adb b/src/ghdldrv/ghdldrv.adb index dd2320daf..4d4ebfa61 100644 --- a/src/ghdldrv/ghdldrv.adb +++ b/src/ghdldrv/ghdldrv.adb @@ -26,6 +26,7 @@ with Dyn_Tables; with Files_Map; with Libraries; with Default_Paths; +with Flags; with Simple_IO; use Simple_IO; with Name_Table; use Name_Table; with Vhdl.Std_Package; @@ -688,6 +689,15 @@ package body Ghdldrv is Error ("option --time-resolution not supported by back-end"); Res := Option_Err; return; + elsif Opt = "--ieee=synopsys" or else Opt = "--ieee=none" then + -- Automatically translate the option. + if Backend = Backend_Gcc then + Add_Argument (Compiler_Args, new String'("--ghdl-fsynopsys")); + else + Add_Argument (Compiler_Args, new String'("-fsynopsys")); + end if; + Flags.Flag_Synopsys := True; + Res := Option_Ok; else Res := Options.Parse_Option (Opt); if Res = Option_Ok then diff --git a/src/ghdldrv/ghdllocal.adb b/src/ghdldrv/ghdllocal.adb index 5745b2b50..40f2eb984 100644 --- a/src/ghdldrv/ghdllocal.adb +++ b/src/ghdldrv/ghdllocal.adb @@ -444,9 +444,11 @@ package body Ghdllocal is when Lib_Standard => Add_Library_Name ("ieee"); when Lib_Synopsys => - Add_Library_Name ("synopsys"); + Add_Library_Name ("ieee"); + Flag_Synopsys := True; when Lib_None => - null; + -- Allow synopsys packages. + Flag_Synopsys := True; end case; -- For std: just add the library prefix. diff --git a/src/options.adb b/src/options.adb index 65521b411..f43ee7663 100644 --- a/src/options.adb +++ b/src/options.adb @@ -180,6 +180,8 @@ package body Options is Flag_Explicit := True; elsif Opt = "-frelaxed-rules" or else Opt = "-frelaxed" then Flag_Relaxed_Rules := True; + elsif Opt = "-fsynopsys" then + Flag_Synopsys := True; elsif Opt = "--syn-binding" then Flag_Syn_Binding := True; elsif Opt = "--no-vital-checks" then diff --git a/src/vhdl/vhdl-sem_names.adb b/src/vhdl/vhdl-sem_names.adb index ebed95997..91c9475bd 100644 --- a/src/vhdl/vhdl-sem_names.adb +++ b/src/vhdl/vhdl-sem_names.adb @@ -2263,29 +2263,33 @@ package body Vhdl.Sem_Names is Error_Msg_Sem (+Name, "no method %i in %n", (+Suffix, +Prot_Type)); end Error_Protected_Item; - -- Emit an error message if unit is not found in library LIB. - procedure Error_Unit_Not_Found (Lib : Iir) + -- Check if a synopsys package can be imported. + procedure Check_Synopsys_Package (Lib : Iir) is use Std_Names; begin - Error_Msg_Sem (+Name, "unit %i not found in %n", (+Suffix, +Lib)); - - -- Give an advice for common synopsys packages. - if Get_Identifier (Lib) = Name_Ieee then - if Suffix = Name_Std_Logic_Arith - or else Suffix = Name_Std_Logic_Signed - or else Suffix = Name_Std_Logic_Unsigned - then - Error_Msg_Sem - (+Name, - " (use --ieee=synopsys for non-standard synopsys packages)"); - elsif Suffix = Name_Std_Logic_Textio then - Error_Msg_Sem - (+Name, " (use --ieee=synopsys or --std=08 for " - & "this non-standard synopsys package)"); - end if; + if Get_Identifier (Lib) /= Name_Ieee then + return; end if; - end Error_Unit_Not_Found; + + case Suffix is + when Name_Std_Logic_Arith + | Name_Std_Logic_Signed + | Name_Std_Logic_Unsigned => + -- Synopsys package. + null; + when Name_Std_Logic_Textio => + if Vhdl_Std >= Vhdl_08 then + -- Standard ieee package in vhdl-08 + return; + end if; + when others => + -- Not a synopsys package. + return; + end case; + Error_Msg_Sem + (+Name, "use of synopsys packages needs the -fsynopsys option"); + end Check_Synopsys_Package; begin -- Analyze prefix. if Soft then @@ -2368,10 +2372,14 @@ package body Vhdl.Sem_Names is -- GHDL: FIXME: error message more explicit Res := Load_Primary_Unit (Prefix, Suffix, Name); if Res /= Null_Iir then + if not Soft and then not Flag_Synopsys then + Check_Synopsys_Package (Prefix); + end if; Sem.Add_Dependence (Res); Res := Get_Library_Unit (Res); elsif not Soft then - Error_Unit_Not_Found (Prefix); + Error_Msg_Sem + (+Name, "unit %i not found in %n", (+Suffix, +Prefix)); end if; when Iir_Kind_Process_Statement | Iir_Kind_Procedure_Declaration -- cgit v1.2.3