1--  Global checks after analyze pass.
2--  Copyright (C) 2002 - 2016 Tristan Gingold
3--
4--  This program is free software: you can redistribute it and/or modify
5--  it under the terms of the GNU General Public License as published by
6--  the Free Software Foundation, either version 2 of the License, or
7--  (at your option) any later version.
8--
9--  This program is distributed in the hope that it will be useful,
10--  but WITHOUT ANY WARRANTY; without even the implied warranty of
11--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12--  GNU General Public License for more details.
13--
14--  You should have received a copy of the GNU General Public License
15--  along with this program.  If not, see <gnu.org/licenses>.
16with Types; use Types;
17with Std_Names; use Std_Names;
18with Vhdl.Sem_Specs;
19with Vhdl.Ieee.Std_Logic_1164;
20with Vhdl.Ieee.Vital_Timing;
21with Vhdl.Ieee.Numeric;
22with Vhdl.Ieee.Numeric_Std_Unsigned;
23with Vhdl.Ieee.Math_Real;
24with Vhdl.Ieee.Std_Logic_Unsigned;
25with Vhdl.Ieee.Std_Logic_Arith;
26with Vhdl.Ieee.Std_Logic_Misc;
27with Flags; use Flags;
28
29package body Vhdl.Post_Sems is
30   procedure Post_Sem_Checks (Unit : Iir_Design_Unit)
31   is
32      Lib_Unit : constant Iir := Get_Library_Unit (Unit);
33      Lib : Iir_Library_Declaration;
34      Id : Name_Id;
35
36      Value : Iir_Attribute_Value;
37      Spec : Iir_Attribute_Specification;
38      Attr_Decl : Iir_Attribute_Declaration;
39   begin
40      --  No checks on package bodies or context declaration
41      case Get_Kind (Lib_Unit) is
42         when Iir_Kind_Package_Body
43           | Iir_Kind_Context_Declaration
44           | Iir_Kinds_Verification_Unit =>
45            return;
46         when others =>
47            null;
48      end case;
49
50      Id := Get_Identifier (Lib_Unit);
51      Lib := Get_Library (Get_Design_File (Unit));
52
53      if Get_Identifier (Lib) = Name_Ieee then
54         --  This is a unit of IEEE.
55         if Get_Kind (Lib_Unit) = Iir_Kind_Package_Declaration then
56            case Id is
57               when Name_Std_Logic_1164 =>
58                  Vhdl.Ieee.Std_Logic_1164.Extract_Declarations (Lib_Unit);
59               when Name_VITAL_Timing =>
60                  Vhdl.Ieee.Vital_Timing.Extract_Declarations (Lib_Unit);
61               when Name_Numeric_Std =>
62                  Vhdl.Ieee.Numeric.Extract_Std_Declarations
63                    (Lib_Unit);
64               when Name_Numeric_Std_Unsigned =>
65                  Vhdl.Ieee.Numeric_Std_Unsigned.Extract_Declarations
66                    (Lib_Unit);
67               when Name_Math_Real =>
68                  Vhdl.Ieee.Math_Real.Extract_Declarations (Lib_Unit);
69               when Name_Std_Logic_Unsigned =>
70                  Vhdl.Ieee.Std_Logic_Unsigned.Extract_Declarations
71                    (Lib_Unit, Vhdl.Ieee.Std_Logic_Unsigned.Pkg_Unsigned);
72               when Name_Std_Logic_Signed =>
73                  Vhdl.Ieee.Std_Logic_Unsigned.Extract_Declarations
74                    (Lib_Unit, Vhdl.Ieee.Std_Logic_Unsigned.Pkg_Signed);
75               when Name_Std_Logic_Arith =>
76                  Vhdl.Ieee.Std_Logic_Arith.Extract_Declarations (Lib_Unit);
77               when Name_Std_Logic_Misc =>
78                  Vhdl.Ieee.Std_Logic_Misc.Extract_Declarations (Lib_Unit);
79               when others =>
80                  null;
81            end case;
82         end if;
83      end if;
84
85      --  Look for VITAL attributes.
86      if Flag_Vital_Checks then
87         Value := Get_Attribute_Value_Chain
88           (Vhdl.Sem_Specs.Get_Attribute_Value_Chain_Parent (Lib_Unit));
89         while Value /= Null_Iir loop
90            Spec := Get_Attribute_Specification (Value);
91            Attr_Decl := Get_Named_Entity (Get_Attribute_Designator (Spec));
92            if Attr_Decl = Vhdl.Ieee.Vital_Timing.Vital_Level0_Attribute then
93               Vhdl.Ieee.Vital_Timing.Check_Vital_Level0 (Unit);
94            elsif Attr_Decl = Vhdl.Ieee.Vital_Timing.Vital_Level1_Attribute
95            then
96               Vhdl.Ieee.Vital_Timing.Check_Vital_Level1 (Unit);
97            end if;
98
99            Value := Get_Value_Chain (Value);
100         end loop;
101      end if;
102   end Post_Sem_Checks;
103end Vhdl.Post_Sems;
104