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
119
120
|
-- Heap for 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 Tables;
with Vhdl.Nodes; use Vhdl.Nodes;
package body Synth.Heap is
package Heap_Table is new Tables
(Table_Component_Type => Value_Acc,
Table_Index_Type => Heap_Index,
Table_Low_Bound => 1,
Table_Initial => 16);
function Allocate_By_Type (T : Type_Acc) return Value_Acc is
begin
case T.Kind is
when Type_Bit
| Type_Logic =>
return new Value_Type'
(Kind => Value_Discrete, Typ => T, Scal => 0);
when Type_Discrete =>
return new Value_Type'
(Kind => Value_Discrete, Typ => T, Scal => T.Drange.Left);
when Type_Array =>
declare
Len : constant Uns32 := Get_Array_Flat_Length (T);
El_Typ : constant Type_Acc := Get_Array_Element (T);
Arr : Value_Array_Acc;
begin
Arr := new Value_Array_Type (Iir_Index32 (Len));
for I in Arr.V'Range loop
Arr.V (I) := Allocate_By_Type (El_Typ);
end loop;
return new Value_Type'
(Kind => Value_Const_Array, Typ => T, Arr => Arr);
end;
when others =>
raise Internal_Error;
end case;
end Allocate_By_Type;
function Allocate_By_Type (T : Type_Acc) return Heap_Index is
begin
-- FIXME: allocate type.
Heap_Table.Append (Allocate_By_Type (T));
return Heap_Table.Last;
end Allocate_By_Type;
function Allocate_By_Value (V : Value_Acc) return Value_Acc is
begin
case V.Kind is
when Value_Net
| Value_Wire =>
raise Internal_Error;
when Value_Discrete =>
return new Value_Type'
(Kind => Value_Discrete, Typ => V.Typ, Scal => V.Scal);
when Value_Array
| Value_Const_Array =>
declare
Arr : Value_Array_Acc;
begin
Arr := new Value_Array_Type (V.Arr.Len);
for I in Arr.V'Range loop
Arr.V (I) := Allocate_By_Value (V.Arr.V (I));
end loop;
return new Value_Type'
(Kind => Value_Const_Array, Typ => V.Typ, Arr => Arr);
end;
when others =>
raise Internal_Error;
end case;
end Allocate_By_Value;
function Allocate_By_Value (V : Value_Acc) return Heap_Index is
begin
Heap_Table.Append (Allocate_By_Value (V));
return Heap_Table.Last;
end Allocate_By_Value;
function Synth_Dereference (Idx : Heap_Index) return Value_Acc is
begin
return Heap_Table.Table (Idx);
end Synth_Dereference;
procedure Free (Obj : in out Value_Acc) is
begin
-- TODO
Obj := null;
end Free;
procedure Synth_Deallocate (Idx : Heap_Index) is
begin
if Heap_Table.Table (Idx) = null then
return;
end if;
Free (Heap_Table.Table (Idx));
end Synth_Deallocate;
end Synth.Heap;
|