aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt/grt-rtis_types.adb
blob: f22a309bc89dd8ee60525cc54fe7976b7b8f66c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--  GHDL Run Time (GRT) -  Well known RTI types.
--  Copyright (C) 2002 - 2014 Tristan Gingold
--
--  GHDL is free software; you can redistribute it and/or modify it under
--  the terms of the GNU General Public License as published by the Free
--  Software Foundation; either version 2, or (at your option) any later
--  version.
--
--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
--  WARRANTY; without even the implied warranty of MERCHANTABILITY or
--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--  for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with GCC; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.
--
--  As a special exception, if other files instantiate generics from this
--  unit, or you link this unit with other files to produce an executable,
--  this unit does not by itself cause the resulting executable to be
--  covered by the GNU General Public License. This exception does not
--  however invalidate any other reasons why the executable file might be
--  covered by the GNU Public License.
with Grt.Astdio;
with Grt.Avhpi; use Grt.Avhpi;

package body Grt.Rtis_Types is

   procedure Avhpi_Error (Err : AvhpiErrorT)
   is
      use Grt.Astdio;
      pragma Unreferenced (Err);
   begin
      Put_Line ("grt.rtis_utils.Avhpi_Error!");
   end Avhpi_Error;

   --  Extract std_ulogic type.
   procedure Search_Types (Pack : VhpiHandleT)
   is
      Decl_It : VhpiHandleT;
      Decl : VhpiHandleT;

      Error : AvhpiErrorT;
      Name : String (1 .. 16);
      Name_Len : Natural;
      Rti : Ghdl_Rti_Access;
   begin
      Vhpi_Get_Str (VhpiLibLogicalNameP, Pack, Name, Name_Len);
      if not (Name_Len = 4 and then Name (1 .. 4)= "ieee") then
         return;
      end if;

      Vhpi_Iterator (VhpiDecls, Pack, Decl_It, Error);
      if Error /= AvhpiErrorOk then
         Avhpi_Error (Error);
         return;
      end if;

      --  Extract packages.
      loop
         Vhpi_Scan (Decl_It, Decl, Error);
         exit when Error = AvhpiErrorIteratorEnd;
         if Error /= AvhpiErrorOk then
            Avhpi_Error (Error);
            return;
         end if;

         if Vhpi_Get_Kind (Decl) = VhpiEnumTypeDeclK then
            Vhpi_Get_Str (VhpiNameP, Decl, Name, Name_Len);
            Rti := Avhpi_Get_Rti (Decl);
            if Name_Len = 10 and then Name (1 .. 10) = "std_ulogic" then
               Ieee_Std_Logic_1164_Std_Ulogic_RTI_Ptr := Rti;
            end if;
         end if;
      end loop;
   end Search_Types;

   procedure Search_Packages
   is
      Pack : VhpiHandleT;
      Pack_It : VhpiHandleT;

      Error : AvhpiErrorT;
      Name : String (1 .. 16);
      Name_Len : Natural;
   begin
      Get_Package_Inst (Pack_It);

      --  Extract packages.
      loop
         Vhpi_Scan (Pack_It, Pack, Error);
         exit when Error = AvhpiErrorIteratorEnd;
         if Error /= AvhpiErrorOk then
            Avhpi_Error (Error);
            return;
         end if;

         Vhpi_Get_Str (VhpiNameP, Pack, Name, Name_Len);
         if Name_Len = 14 and then Name (1 .. 14) = "std_logic_1164" then
            Search_Types (Pack);
         end if;
      end loop;
   end Search_Packages;

   Search_Types_RTI_Done : Boolean := False;

   procedure Search_Types_RTI is
   begin
      if Search_Types_RTI_Done then
         return;
      else
         Search_Types_RTI_Done := True;
      end if;

      Search_Packages;
   end Search_Types_RTI;
end Grt.Rtis_Types;