aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth/netlists-iterators.ads
blob: f9a4decc54f6cc903134b67a02f297d1f5e45f28 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
--  Iterators for elements of a netlist.
--  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, see <gnu.org/licenses>.

package Netlists.Iterators is
   --  Iterators.

   --  Iterate over sub-modules.
   type Modules_Cursor is private;
   type Modules_Iterator is private with
     Iterable => (First => Modules_First,
                  Next => Modules_Next,
                  Has_Element => Modules_Has_Element,
                  Element => Modules_Element);
   function Sub_Modules (M : Module) return Modules_Iterator;

   function Modules_First (It : Modules_Iterator) return Modules_Cursor
     with Inline;
   function Modules_Next (It : Modules_Iterator; Cur : Modules_Cursor)
                         return Modules_Cursor
     with Inline;
   function Modules_Has_Element (It : Modules_Iterator; Cur : Modules_Cursor)
                                return Boolean
     with Inline;
   function Modules_Element (It : Modules_Iterator; Cur : Modules_Cursor)
                            return Module
     with Inline;

   --  Iterate over ports desc of a module.
   type Ports_Desc_Cursor is private;
   type Ports_Desc_Iterator is private with
     Iterable => (First => Ports_Desc_First,
                  Next => Ports_Desc_Next,
                  Has_Element => Ports_Desc_Has_Element,
                  Element => Ports_Desc_Element);
   function Ports_Desc (M : Module) return Ports_Desc_Iterator;

   function Ports_Desc_First (It : Ports_Desc_Iterator)
                             return Ports_Desc_Cursor;
   function Ports_Desc_Next (It : Ports_Desc_Iterator; Cur : Ports_Desc_Cursor)
                            return Ports_Desc_Cursor;
   function Ports_Desc_Has_Element
     (It : Ports_Desc_Iterator; Cur : Ports_Desc_Cursor) return Boolean;
   function Ports_Desc_Element
     (It : Ports_Desc_Iterator; Cur : Ports_Desc_Cursor) return Port_Desc;

   --  Iterate over param desc of a module
   type Params_Desc_Cursor is private;
   type Params_Desc_Iterator is private with
     Iterable => (First => Params_Desc_First,
                  Next => Params_Desc_Next,
                  Has_Element => Params_Desc_Has_Element,
                  Element => Params_Desc_Element);
   function Params_Desc (M : Module) return Params_Desc_Iterator;

   function Params_Desc_First (It : Params_Desc_Iterator)
                             return Params_Desc_Cursor;
   function Params_Desc_Next
     (It : Params_Desc_Iterator; Cur : Params_Desc_Cursor)
     return Params_Desc_Cursor;
   function Params_Desc_Has_Element
     (It : Params_Desc_Iterator; Cur : Params_Desc_Cursor) return Boolean;
   function Params_Desc_Element
     (It : Params_Desc_Iterator; Cur : Params_Desc_Cursor) return Param_Desc;

   --  Iterate over instances in a module, excluding the self-instance.
   type Instances_Cursor is private;
   type Instances_Iterator is private with
     Iterable => (First => Instances_First,
                  Next => Instances_Next,
                  Has_Element => Instances_Has_Element,
                  Element => Instances_Element);
   function Instances (M : Module) return Instances_Iterator;

   function Instances_First (It : Instances_Iterator) return Instances_Cursor;
   function Instances_Next (It : Instances_Iterator; Cur : Instances_Cursor)
                           return Instances_Cursor;
   function Instances_Has_Element
     (It : Instances_Iterator; Cur : Instances_Cursor) return Boolean;
   function Instances_Element
     (It : Instances_Iterator; Cur : Instances_Cursor) return Instance;

   --  Iterate over inputs of an instance.
   type Inputs_Cursor is private;
   type Inputs_Iterator is private with
     Iterable => (First => Inputs_First,
                  Next => Inputs_Next,
                  Has_Element => Inputs_Has_Element,
                  Element => Inputs_Element);
   function Inputs (Inst : Instance) return Inputs_Iterator;

   function Inputs_First (It : Inputs_Iterator) return Inputs_Cursor;
   function Inputs_Next (It : Inputs_Iterator; Cur : Inputs_Cursor)
                        return Inputs_Cursor;
   function Inputs_Has_Element (It : Inputs_Iterator; Cur : Inputs_Cursor)
                               return Boolean;
   function Inputs_Element (It : Inputs_Iterator; Cur : Inputs_Cursor)
                           return Input;

   --  Iterate over outputs of an instance.
   type Outputs_Cursor is private;
   type Outputs_Iterator is private with
     Iterable => (First => Outputs_First,
                  Next => Outputs_Next,
                  Has_Element => Outputs_Has_Element,
                  Element => Outputs_Element);
   function Outputs (Inst : Instance) return Outputs_Iterator;

   function Outputs_First (It : Outputs_Iterator) return Outputs_Cursor;
   function Outputs_Next (It : Outputs_Iterator; Cur : Outputs_Cursor)
                        return Outputs_Cursor;
   function Outputs_Has_Element (It : Outputs_Iterator; Cur : Outputs_Cursor)
                               return Boolean;
   function Outputs_Element (It : Outputs_Iterator; Cur : Outputs_Cursor)
                           return Net;

   --  Iterate over parameters of an instance.
   type Params_Cursor is private;
   type Params_Iterator is private with
     Iterable => (First => Params_First,
                  Next => Params_Next,
                  Has_Element => Params_Has_Element);
   function Params (Inst : Instance) return Params_Iterator;
   function Get_Param_Idx (Cur : Params_Cursor) return Param_Idx;

   function Params_First (It : Params_Iterator) return Params_Cursor;
   function Params_Next (It : Params_Iterator; Cur : Params_Cursor)
                        return Params_Cursor;
   function Params_Has_Element (It : Params_Iterator; Cur : Params_Cursor)
                               return Boolean;

   --  Iterate over nets of a module.
   type Nets_Cursor is private;
   type Nets_Iterator is private with
     Iterable => (First => Nets_First,
                  Next => Nets_Next,
                  Has_Element => Nets_Has_Element,
                  Element => Nets_Element);
   function Nets (M : Module) return Nets_Iterator;

   function Nets_First (It : Nets_Iterator) return Nets_Cursor;
   function Nets_Next (It : Nets_Iterator; Cur : Nets_Cursor)
                      return Nets_Cursor;
   function Nets_Has_Element (It : Nets_Iterator; Cur : Nets_Cursor)
                             return Boolean;
   function Nets_Element (It : Nets_Iterator; Cur : Nets_Cursor)
                         return Net;

   --  Iterate over sinks of a net.
   type Sinks_Cursor is private;
   type Sinks_Iterator is private with
     Iterable => (First => Sinks_First,
                  Next => Sinks_Next,
                  Has_Element => Sinks_Has_Element,
                  Element => Sinks_Element);
   function Sinks (N : Net) return Sinks_Iterator;

   function Sinks_First (It : Sinks_Iterator) return Sinks_Cursor;
   function Sinks_Next (It : Sinks_Iterator; Cur : Sinks_Cursor)
                       return Sinks_Cursor;
   function Sinks_Has_Element (It : Sinks_Iterator; Cur : Sinks_Cursor)
                              return Boolean;
   function Sinks_Element (It : Sinks_Iterator; Cur : Sinks_Cursor)
                          return Input;

private
   type Modules_Cursor is record
      M : Module;
   end record;

   type Modules_Iterator is record
      M : Module;
   end record;

   type Ports_Desc_Iterator is record
      M : Module;
   end record;

   type Ports_Desc_Cursor is record
      Idx : Port_Desc_Idx;
      Num : Port_Nbr;
   end record;

   type Params_Desc_Iterator is record
      M : Module;
   end record;

   type Params_Desc_Cursor is record
      Idx : Param_Idx;
      Num : Param_Nbr;
   end record;

   type Instances_Iterator is record
      M : Module;
   end record;

   type Instances_Cursor is record
      Inst : Instance;
   end record;

   type Inputs_Cursor is record
      Idx : Port_Idx;
      Nbr : Port_Nbr;
   end record;

   type Inputs_Iterator is record
      Inst : Instance;
   end record;

   type Outputs_Cursor is record
      Idx : Port_Idx;
      Nbr : Port_Nbr;
   end record;

   type Outputs_Iterator is record
      Inst : Instance;
   end record;

   type Params_Cursor is record
      Idx : Param_Idx;
      Nbr : Param_Nbr;
   end record;

   type Params_Iterator is record
      Inst : Instance;
   end record;

   type Nets_Cursor is record
      Inst : Instance;
      N : Net;
      Num : Port_Nbr;
   end record;

   type Nets_Iterator is record
      M : Module;
   end record;

   type Sinks_Cursor is record
      S : Input;
   end record;

   type Sinks_Iterator is record
      N : Net;
   end record;
end Netlists.Iterators;