blob: 955e5c9e0528f297f811fffcae80bfddfb1fa8b6 (
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
|
-- Types synthesis.
-- Copyright (C) 2017 Tristan Gingold
--
-- This file is part of GHDL.
--
-- This program 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 of the License, or
-- (at your option) any later version.
--
-- This program 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 this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-- MA 02110-1301, USA.
with Types; use Types;
with Vhdl.Std_Package;
with Vhdl.Ieee.Std_Logic_1164;
with Vhdl.Utils; use Vhdl.Utils;
with Simul.Environments; use Simul.Environments;
with Simul.Annotations; use Simul.Annotations;
with Simul.Execution;
with Vhdl.Errors; use Vhdl.Errors;
package body Synth.Types is
function Is_Bit_Type (Atype : Iir) return Boolean is
begin
return Atype = Vhdl.Ieee.Std_Logic_1164.Std_Ulogic_Type
or else Atype = Vhdl.Ieee.Std_Logic_1164.Std_Logic_Type
or else Atype = Vhdl.Std_Package.Boolean_Type_Definition
or else Atype = Vhdl.Std_Package.Bit_Type_Definition;
end Is_Bit_Type;
function Is_Vector_Type (Atype : Iir) return Boolean is
begin
return Is_Bit_Type (Get_Element_Subtype (Atype))
and then Get_Nbr_Dimensions (Atype) = 1;
end Is_Vector_Type;
function Get_Width (Syn_Inst : Synth_Instance_Acc; Atype : Iir)
return Width
is
Btype : constant Iir := Get_Base_Type (Atype);
begin
case Get_Kind (Atype) is
when Iir_Kind_Enumeration_Type_Definition =>
return Width (Get_Info (Atype).Width);
when Iir_Kind_Enumeration_Subtype_Definition =>
-- Tail call
return Get_Width (Syn_Inst, Btype);
when Iir_Kind_Array_Subtype_Definition =>
if Is_Vector_Type (Btype) then
declare
Bnd : Iir_Value_Literal_Acc;
begin
Bnd := Simul.Execution.Execute_Bounds
(Syn_Inst.Sim,
Get_Nth_Element (Get_Index_Subtype_List (Atype), 0));
return Width (Bnd.Length);
end;
else
raise Internal_Error;
end if;
when others =>
Error_Kind ("get_width", Atype);
end case;
end Get_Width;
end Synth.Types;
|