aboutsummaryrefslogtreecommitdiffstats
path: root/src/edif/edif-nodes.ads
blob: 7dd61f2b11ebcaec4193fb46d32e65df7f647a18 (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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
--  EDIF nodes.
--  Copyright (C) 2019 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 GHDL; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.

with Types; use Types;

package Edif.Nodes is

   type Nkind is
     (
      N_Error,

      --  Generic nodes.
      N_Keyword,
      N_Symbol,
      N_Number,
      N_String,
      N_Chain,

      --  Edif 2.0.0 nodes
      N_Edif,
      N_External,
      N_Cell,
      N_View,
      N_Port,
      N_Library,
      N_Interface,
      N_Instance,
      N_Net,
      N_Design,
      N_Port_Ref,
      N_Cell_Ref,
      N_View_Ref,
      N_Member,
      N_Property,
      N_Userdata,
      N_Port_Instance,

      N_Array,
      N_Rename,
      N_Boolean

     );

   type Node is new Nat32;
   for Node'Size use 32;

   Null_Node : constant Node := 0;

   type Direction_Type is
     (
      Dir_Input,
      Dir_Output,
      Dir_Inout
     );

   --  The next line marks the start of the node description.
   -- Start of Nkind.

   -- N_Error (X1)

   -- N_Keyword (X1)
   --   Get/Set_Keyword (Field1)
   --
   --   Get/Set_CDR (Field2)

   -- N_Chain (X1)
   --   Get/Set_CAR (Field1)
   --
   --   Get/Set_CDR (Field2)

   -- N_Symbol (X1)
   --   Get/Set_Symbol (Field1)

   -- N_Number (X1)
   --   Get/Set_Number (Field1)

   -- N_String (X1)
   --   Get/Set_String_Id (Field1)
   --
   --   Get/Set_String_Len (Field2)

   -- N_Edif (X4)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Edif_Version (Field3)
   --
   --   Get/Set_Edif_Level (Field2)
   --
   --   Get/Set_Keyword_Map (Field4)
   --
   --   Get/Set_Status (Field5)
   --
   --   Get/Set_External_Chain (Field6)
   --
   --   Get/Set_Library_Chain (Field7)
   --
   --   Get/Set_Design (Field8)

   -- N_External (X2)
   -- N_Library (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Edif_Level (Field2)
   --
   --   Get/Set_Technology (Field3)
   --
   --   Get/Set_Cells_Chain (Field4)
   --
   --   Get/Set_Chain (Field5)

   -- N_Cell (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Cell_Type (Field2)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --   Get/Set_View (Field4)
   --
   --   Get/Set_Chain (Field5)

   -- N_Interface (X2)
   --   Get/Set_Ports_Chain (Field2)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --   Get/Set_Designator (Field4)

   -- N_View (X4)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_View_Type (Field2)
   --
   --   Get/Set_Interface (Field6)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --  Instances and nets.
   --   Get/Set_Contents_Chain (Field4)
   --
   --   Get/Set_Chain (Field5)

   -- N_Port (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Direction (State1)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --   Get/Set_Designator (Field4)
   --
   --   Get/Set_Chain (Field5)

   -- N_Property (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Value (Field2)
   --
   --   Get/Set_Owner (Field3)
   --
   --   Get/Set_Unit (Field4)
   --
   --   Get/Set_Chain (Field5)

   -- N_Userdata (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_CDR (Field2)
   --
   --   Get/Set_Chain (Field5)

   -- N_Instance (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Instance_Ref (Field2)
   --
   --   Get/Set_Port_Instances_Chain (Field4)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --   Get/Set_Chain (Field5)

   -- N_Net (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Joined_Chain (Field2)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --   Get/Set_Chain (Field5)

   -- N_Design (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Cell_Ref (Field2)
   --
   --   Get/Set_Properties_Chain (Field3)

   -- N_Port_Ref (X2)
   --   Get/Set_Port (Field1)
   --
   --   Get/Set_Instance_Ref (Field2)
   --
   --   Get/Set_Chain (Field5)

   -- N_View_Ref (X1)
   --
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Cell_Ref (Field2)

   -- N_Cell_Ref (X1)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Library_Ref (Field2)

   -- N_Port_Instance (X2)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Properties_Chain (Field3)
   --
   --   Get/Set_Chain (Field5)

   -- N_Member (X1)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Index (Field2)

   -- N_Array (X1)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_Array_Length (Field2)

   -- N_Rename (X1)
   --   Get/Set_Name (Field1)
   --
   --   Get/Set_String (Field2)

   -- N_Boolean (X1)
   --   Get/Set_Boolean (Flag1)

   -- End of Nkind.

   -- General methods.

   function Create_Node (Kind : Nkind) return Node;
   procedure Free_Node (N : Node);

   --  Note: use Field0
   function Get_Location (N : Node) return Location_Type;
   procedure Set_Location (N : Node; Loc : Location_Type);

   function Get_Kind (N : Node) return Nkind;

   --  Field: Field1
   function Get_CAR (N : Node) return Node;
   procedure Set_CAR (N : Node; V : Node);

   --  Field: Field2
   function Get_CDR (N : Node) return Node;
   procedure Set_CDR (N : Node; V : Node);

   --  Field: Field1 (pos)
   function Get_Symbol (N : Node) return Name_Id;
   procedure Set_Symbol (N : Node; Id : Name_Id);

   --  Field: Field1 (pos)
   function Get_Keyword (N : Node) return Name_Id;
   procedure Set_Keyword (N : Node; Id : Name_Id);

   --  Field: Field1 (uc)
   function Get_Number (N : Node) return Int32;
   procedure Set_Number (N : Node; Val : Int32);

   --  Field: Field1 (pos)
   function Get_String_Id (N : Node) return String8_Id;
   procedure Set_String_Id (N : Node; Id : String8_Id);

   --  Field: Field2 (uc)
   function Get_String_Len (N : Node) return Uns32;
   procedure Set_String_Len (N : Node; Bn : Uns32);


   --  Field: Field1
   function Get_Name (N : Node) return Node;
   procedure Set_Name (N : Node; Name : Node);

   --  Field: Field2 (uc)
   function Get_Edif_Level (N : Node) return Int32;
   procedure Set_Edif_Level (N : Node; Level : Int32);

   --  Major*100 + Minor*10 + Release
   --  Field: Field3 (uc)
   function Get_Edif_Version (N : Node) return Int32;
   procedure Set_Edif_Version (N : Node; Version : Int32);

   --  Field: Field4
   function Get_Keyword_Map (N : Node) return Node;
   procedure Set_Keyword_Map (N : Node; Map : Node);

   --  Field: Field5
   function Get_Status (N : Node) return Node;
   procedure Set_Status (N : Node; Status : Node);

   --  Field: Field5 Chain_Next
   function Get_Chain (N : Node) return Node;
   procedure Set_Chain (N : Node; Chain : Node);

   --  Field: Field6 Chain
   function Get_External_Chain (N : Node) return Node;
   procedure Set_External_Chain (N : Node; Chain : Node);

   --  Field: Field7 Chain
   function Get_Library_Chain (N : Node) return Node;
   procedure Set_Library_Chain (N : Node; Chain : Node);

   --  Field: Field4 Chain
   function Get_Cells_Chain (N : Node) return Node;
   procedure Set_Cells_Chain (N : Node; Chain : Node);

   --  Field: Field2 Chain
   function Get_Ports_Chain (N : Node) return Node;
   procedure Set_Ports_Chain (N : Node; Chain : Node);

   --  Field: Field4 Chain
   function Get_Contents_Chain (N : Node) return Node;
   procedure Set_Contents_Chain (N : Node; Chain : Node);

   --  Field: Field3 Chain
   function Get_Properties_Chain (N : Node) return Node;
   procedure Set_Properties_Chain (N : Node; Chain : Node);

   --  Field: Field4 Chain
   function Get_Port_Instances_Chain (N : Node) return Node;
   procedure Set_Port_Instances_Chain (N : Node; Chain : Node);

   --  Field: Field2 Chain
   function Get_Joined_Chain (N : Node) return Node;
   procedure Set_Joined_Chain (N : Node; Chain : Node);

   --  Field: Field8
   function Get_Design (N : Node) return Node;
   procedure Set_Design (N : Node; Design : Node);

   --  Field: Field4
   function Get_Designator (N : Node) return Node;
   procedure Set_Designator (N : Node; Id : Node);

   --  Field: Field3
   function Get_Technology (N : Node) return Node;
   procedure Set_Technology (N : Node; Design : Node);

   --  Field: Field2 (pos)
   function Get_Cell_Type (N : Node) return Name_Id;
   procedure Set_Cell_Type (N : Node; Ctype : Name_Id);

   --  Field: Field2 (pos)
   function Get_View_Type (N : Node) return Name_Id;
   procedure Set_View_Type (N : Node; Vtype : Name_Id);

   --  Field: Field6
   function Get_Interface (N : Node) return Node;
   procedure Set_Interface (N : Node; Inter : Node);

   --  Field: Field1 (pos)
   function Get_View_Ref (N : Node) return Name_Id;
   procedure Set_View_Ref (N : Node; Ref : Name_Id);

   --  Field: Field2
   function Get_Cell_Ref (N : Node) return Node;
   procedure Set_Cell_Ref (N : Node; Ref : Node);

   --  Field: Field2
   function Get_Library_Ref (N : Node) return Node;
   procedure Set_Library_Ref (N : Node; Ref : Node);

   --  Field: Field4
   function Get_View (N : Node) return Node;
   procedure Set_View (N : Node; View : Node);

   --  Field: State1 (uc)
   function Get_Direction (N : Node) return Direction_Type;
   procedure Set_Direction (N : Node; Dir : Direction_Type);

   --  Field: Flag1
   function Get_Boolean (N : Node) return Boolean;
   procedure Set_Boolean (N : Node; Val : Boolean);

   --  Field: Field2
   function Get_Value (N : Node) return Node;
   procedure Set_Value (N : Node; Val : Node);

   --  Field: Field3
   function Get_Owner (N : Node) return Node;
   procedure Set_Owner (N : Node; Owner : Node);

   --  Field: Field2
   function Get_Instance_Ref (N : Node) return Node;
   procedure Set_Instance_Ref (N : Node; Ref : Node);

   --  Field: Field1
   function Get_Port (N : Node) return Node;
   procedure Set_Port (N : Node; Port : Node);

   --  Field: Field2 (uc)
   function Get_Index (N : Node) return Int32;
   procedure Set_Index (N : Node; Idx : Int32);

   --  Field: Field2 (uc)
   function Get_Array_Length (N : Node) return Int32;
   procedure Set_Array_Length (N : Node; Len : Int32);

   --  Field: Field4 (pos)
   function Get_Unit (N : Node) return Name_Id;
   procedure Set_Unit (N : Node; Unit : Name_Id);

   --  Field: Field2
   function Get_String (N : Node) return Node;
   procedure Set_String (N : Node; Str : Node);

end Edif.Nodes;
k">return associations @export def GetArrayConstraintsFromSubtypeIndication( subtypeIndication: Iir, ) -> List[ConstraintUnion]: constraints = [] for constraint in utils.flist_iter(nodes.Get_Index_Constraint_List(subtypeIndication)): constraintKind = GetIirKindOfNode(constraint) if constraintKind == nodes.Iir_Kind.Range_Expression: constraints.append(RangeExpression.parse(constraint)) elif constraintKind in ( nodes.Iir_Kind.Simple_Name, nodes.Iir_Kind.Parenthesis_Name, nodes.Iir_Kind.Selected_Name, nodes.Iir_Kind.Attribute_Name, ): constraints.append(GetNameFromNode(constraint)) else: position = Position.parse(constraint) raise DOMException( "Unknown constraint kind '{kind}' for constraint '{constraint}' in subtype indication '{indication}' at {file}:{line}:{column}.".format( kind=constraintKind.name, constraint=constraint, indication=subtypeIndication, file=position.Filename, line=position.Line, column=position.Column, ) ) return constraints @export def GetTypeFromNode(node: Iir) -> BaseType: typeName = GetNameOfNode(node) typeDefinition = nodes.Get_Type_Definition(node) if typeDefinition is nodes.Null_Iir: return IncompleteType(node, typeName) kind = GetIirKindOfNode(typeDefinition) if kind == nodes.Iir_Kind.Enumeration_Type_Definition: return EnumeratedType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Array_Type_Definition: return ArrayType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Record_Type_Definition: return RecordType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Access_Type_Definition: return AccessType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.File_Type_Definition: return FileType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Protected_Type_Declaration: return ProtectedType.parse(typeName, typeDefinition) else: position = Position.parse(typeDefinition) raise DOMException( "GetTypeFromNode: Unknown type definition kind '{kind}' for type '{name}' at {file}:{line}:{column}.".format( kind=kind.name, name=typeName, file=position.Filename, line=position.Line, column=position.Column, ) ) @export def GetAnonymousTypeFromNode(node: Iir) -> BaseType: typeName = GetNameOfNode(node) typeDefinition = nodes.Get_Type_Definition(node) if typeDefinition is nodes.Null_Iir: return IncompleteType(node, typeName) kind = GetIirKindOfNode(typeDefinition) if kind == nodes.Iir_Kind.Range_Expression: r = GetRangeFromNode(typeDefinition) return IntegerType(node, typeName, r) elif kind in (nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name): n = GetNameFromNode(typeDefinition) return IntegerType(node, typeName, n) elif kind == nodes.Iir_Kind.Physical_Type_Definition: return PhysicalType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Array_Subtype_Definition: print("[NOT IMPLEMENTED] Array_Subtype_Definition") return ArrayType(typeDefinition, "????", [], None) else: position = Position.parse(typeDefinition) raise DOMException( "GetAnonymousTypeFromNode: Unknown type definition kind '{kind}' for type '{name}' at {file}:{line}:{column}.".format( kind=kind.name, name=typeName, file=position.Filename, line=position.Line, column=position.Column, ) ) @export def GetSubtypeIndicationFromNode(node: Iir, entity: str, name: str) -> SubtypeOrSymbol: subtypeIndicationNode = nodes.Get_Subtype_Indication(node) return GetSubtypeIndicationFromIndicationNode(subtypeIndicationNode, entity, name) @export def GetSubtypeIndicationFromIndicationNode(subtypeIndicationNode: Iir, entity: str, name: str) -> SubtypeOrSymbol: if subtypeIndicationNode is nodes.Null_Iir: raise ValueError("Parameter 'subtypeIndicationNode' is 'Null_Iir'.") kind = GetIirKindOfNode(subtypeIndicationNode) if kind in ( nodes.Iir_Kind.Simple_Name, nodes.Iir_Kind.Selected_Name, nodes.Iir_Kind.Attribute_Name, ): return GetSimpleTypeFromNode(subtypeIndicationNode) elif kind == nodes.Iir_Kind.Subtype_Definition: return GetScalarConstrainedSubtypeFromNode(subtypeIndicationNode) elif kind == nodes.Iir_Kind.Array_Subtype_Definition: return GetCompositeConstrainedSubtypeFromNode(subtypeIndicationNode) else: raise DOMException( "Unknown kind '{kind}' for an subtype indication in a {entity} of `{name}`.".format( kind=kind.name, entity=entity, name=name ) ) @export def GetSimpleTypeFromNode(subtypeIndicationNode: Iir) -> SimpleSubtypeSymbol: subtypeName = GetNameFromNode(subtypeIndicationNode) return SimpleSubtypeSymbol(subtypeIndicationNode, subtypeName) @export def GetScalarConstrainedSubtypeFromNode( subtypeIndicationNode: Iir, ) -> ConstrainedScalarSubtypeSymbol: typeMark = nodes.Get_Subtype_Type_Mark(subtypeIndicationNode) typeMarkName = GetNameOfNode(typeMark) simpleTypeMark = SimpleName(typeMark, typeMarkName) rangeConstraint = nodes.Get_Range_Constraint(subtypeIndicationNode) r = GetRangeFromNode(rangeConstraint) return ConstrainedScalarSubtypeSymbol(subtypeIndicationNode, simpleTypeMark, r) @export def GetCompositeConstrainedSubtypeFromNode( subtypeIndicationNode: Iir, ) -> ConstrainedCompositeSubtypeSymbol: typeMark = nodes.Get_Subtype_Type_Mark(subtypeIndicationNode) typeMarkName = GetNameOfNode(typeMark) simpleTypeMark = SimpleName(typeMark, typeMarkName) constraints = GetArrayConstraintsFromSubtypeIndication(subtypeIndicationNode) return ConstrainedCompositeSubtypeSymbol(subtypeIndicationNode, simpleTypeMark, constraints) @export def GetSubtypeFromNode(subtypeNode: Iir) -> SubtypeOrSymbol: subtypeName = GetNameOfNode(subtypeNode) return Subtype(subtypeNode, subtypeName) @export def GetRangeFromNode(node: Iir) -> Range: direction = nodes.Get_Direction(node) leftBound = nodes.Get_Left_Limit_Expr(node) rightBound = nodes.Get_Right_Limit_Expr(node) return Range( GetExpressionFromNode(leftBound), GetExpressionFromNode(rightBound), Direction.DownTo if direction else Direction.To, ) __EXPRESSION_TRANSLATION = { nodes.Iir_Kind.Simple_Name: SimpleObjectOrFunctionCallSymbol, nodes.Iir_Kind.Selected_Name: IndexedObjectOrFunctionCallSymbol, nodes.Iir_Kind.Attribute_Name: IndexedObjectOrFunctionCallSymbol, nodes.Iir_Kind.Parenthesis_Name: IndexedObjectOrFunctionCallSymbol, nodes.Iir_Kind.Null_Literal: NullLiteral, nodes.Iir_Kind.Integer_Literal: IntegerLiteral, nodes.Iir_Kind.Floating_Point_Literal: FloatingPointLiteral, nodes.Iir_Kind.Physical_Int_Literal: PhysicalIntegerLiteral, nodes.Iir_Kind.Physical_Fp_Literal: PhysicalFloatingLiteral, nodes.Iir_Kind.Character_Literal: CharacterLiteral, nodes.Iir_Kind.String_Literal8: StringLiteral, nodes.Iir_Kind.Identity_Operator: IdentityExpression, nodes.Iir_Kind.Negation_Operator: NegationExpression, nodes.Iir_Kind.Absolute_Operator: AbsoluteExpression, nodes.Iir_Kind.Range_Expression: RangeExpression, nodes.Iir_Kind.Addition_Operator: AdditionExpression, nodes.Iir_Kind.Concatenation_Operator: ConcatenationExpression, nodes.Iir_Kind.Not_Operator: InverseExpression, nodes.Iir_Kind.Parenthesis_Expression: ParenthesisExpression, nodes.Iir_Kind.Substraction_Operator: SubtractionExpression, nodes.Iir_Kind.Multiplication_Operator: MultiplyExpression, nodes.Iir_Kind.Division_Operator: DivisionExpression, nodes.Iir_Kind.Modulus_Operator: ModuloExpression, nodes.Iir_Kind.Remainder_Operator: RemainderExpression, nodes.Iir_Kind.Exponentiation_Operator: ExponentiationExpression, nodes.Iir_Kind.And_Operator: AndExpression, nodes.Iir_Kind.Nand_Operator: NandExpression, nodes.Iir_Kind.Or_Operator: OrExpression, nodes.Iir_Kind.Nor_Operator: NorExpression, nodes.Iir_Kind.Xor_Operator: XorExpression, nodes.Iir_Kind.Xnor_Operator: XnorExpression, nodes.Iir_Kind.Equality_Operator: EqualExpression, nodes.Iir_Kind.Inequality_Operator: UnequalExpression, nodes.Iir_Kind.Less_Than_Operator: LessThanExpression, nodes.Iir_Kind.Less_Than_Or_Equal_Operator: LessEqualExpression, nodes.Iir_Kind.Greater_Than_Operator: GreaterThanExpression, nodes.Iir_Kind.Greater_Than_Or_Equal_Operator: GreaterEqualExpression, nodes.Iir_Kind.Match_Equality_Operator: MatchingEqualExpression, nodes.Iir_Kind.Match_Inequality_Operator: MatchingUnequalExpression, nodes.Iir_Kind.Match_Less_Than_Operator: MatchingLessThanExpression, nodes.Iir_Kind.Match_Less_Than_Or_Equal_Operator: MatchingLessEqualExpression, nodes.Iir_Kind.Match_Greater_Than_Operator: MatchingGreaterThanExpression, nodes.Iir_Kind.Match_Greater_Than_Or_Equal_Operator: MatchingGreaterEqualExpression, nodes.Iir_Kind.Sll_Operator: ShiftLeftLogicExpression, nodes.Iir_Kind.Srl_Operator: ShiftRightLogicExpression, nodes.Iir_Kind.Sla_Operator: ShiftLeftArithmeticExpression, nodes.Iir_Kind.Sra_Operator: ShiftRightArithmeticExpression, nodes.Iir_Kind.Rol_Operator: RotateLeftExpression, nodes.Iir_Kind.Ror_Operator: RotateRightExpression, nodes.Iir_Kind.Qualified_Expression: QualifiedExpression, nodes.Iir_Kind.Aggregate: Aggregate, nodes.Iir_Kind.Allocator_By_Subtype: SubtypeAllocation, nodes.Iir_Kind.Allocator_By_Expression: QualifiedExpressionAllocation, } @export def GetExpressionFromNode(node: Iir) -> ExpressionUnion: kind = GetIirKindOfNode(node) try: cls = __EXPRESSION_TRANSLATION[kind] except KeyError: position = Position.parse(node) raise DOMException( "Unknown expression kind '{kind}' in expression '{expr}' at {file}:{line}:{column}.".format( kind=kind.name, expr=node, file=position.Filename, line=position.Line, column=position.Column, ) ) return cls.parse(node) @export def GetGenericsFromChainedNodes( nodeChain: Iir, ) -> Generator[GenericInterfaceItem, None, None]: from pyGHDL.dom.InterfaceItem import ( GenericTypeInterfaceItem, GenericPackageInterfaceItem, GenericProcedureInterfaceItem, GenericFunctionInterfaceItem, ) generic = nodeChain while generic != nodes.Null_Iir: kind = GetIirKindOfNode(generic) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem genericConstant = GenericConstantInterfaceItem.parse(generic) # Lookahead for generics with multiple identifiers at once if nodes.Get_Has_Identifier_List(generic): nextNode = nodes.Get_Chain(generic) for nextGeneric in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextGeneric) == nodes.Null_Iir: genericConstant.Identifiers.append(GetNameOfNode(nextGeneric)) else: generic = nextGeneric break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextGeneric): generic = nodes.Get_Chain(nextGeneric) break else: generic = nodes.Null_Iir else: generic = nodes.Get_Chain(generic) yield genericConstant continue else: if kind == nodes.Iir_Kind.Interface_Type_Declaration: yield GenericTypeInterfaceItem.parse(generic) elif kind == nodes.Iir_Kind.Interface_Package_Declaration: yield GenericPackageInterfaceItem.parse(generic) elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration: yield GenericProcedureInterfaceItem.parse(generic) elif kind == nodes.Iir_Kind.Interface_Function_Declaration: yield GenericFunctionInterfaceItem.parse(generic) else: position = Position.parse(generic) raise DOMException( "Unknown generic kind '{kind}' in generic '{generic}' at {file}:{line}:{column}.".format( kind=kind.name, generic=generic, file=position.Filename, line=position.Line, column=position.Column, ) ) generic = nodes.Get_Chain(generic) @export def GetPortsFromChainedNodes( nodeChain: Iir, ) -> Generator[PortInterfaceItem, None, None]: port = nodeChain while port != nodes.Null_Iir: kind = GetIirKindOfNode(port) if kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import PortSignalInterfaceItem portSignal = PortSignalInterfaceItem.parse(port) # Lookahead for ports with multiple identifiers at once if nodes.Get_Has_Identifier_List(port): nextNode = nodes.Get_Chain(port) for nextPort in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextPort) == nodes.Null_Iir: portSignal.Identifiers.append(GetNameOfNode(nextPort)) else: port = nextPort break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextPort): port = nodes.Get_Chain(nextPort) break else: port = nodes.Null_Iir else: port = nodes.Get_Chain(port) yield portSignal continue else: position = Position.parse(port) raise DOMException( "Unknown port kind '{kind}' in port '{port}' at {file}:{line}:{column}.".format( kind=kind.name, port=port, file=position.Filename, line=position.Line, column=position.Column, ) ) @export def GetParameterFromChainedNodes( nodeChain: Iir, ) -> Generator[ParameterInterfaceItem, None, None]: parameter = nodeChain while parameter != nodes.Null_Iir: kind = GetIirKindOfNode(parameter) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import ParameterConstantInterfaceItem param = ParameterConstantInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_Variable_Declaration: from pyGHDL.dom.InterfaceItem import ParameterVariableInterfaceItem param = ParameterVariableInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import ParameterSignalInterfaceItem param = ParameterSignalInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_File_Declaration: from pyGHDL.dom.InterfaceItem import ParameterFileInterfaceItem param = ParameterFileInterfaceItem.parse(parameter) else: position = Position.parse(parameter) raise DOMException( "Unknown parameter kind '{kind}' in parameter '{param}' at {file}:{line}:{column}.".format( kind=kind.name, param=parameter, file=position.Filename, line=position.Line, column=position.Column, ) ) # Lookahead for parameters with multiple identifiers at once if nodes.Get_Has_Identifier_List(parameter): nextNode = nodes.Get_Chain(parameter) for nextParameter in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextParameter) == nodes.Null_Iir: param.Identifiers.append(GetNameOfNode(nextParameter)) else: parameter = nextParameter break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextParameter): parameter = nodes.Get_Chain(nextParameter) break else: parameter = nodes.Null_Iir else: parameter = nodes.Get_Chain(parameter) yield param def GetMapAspect(mapAspect: Iir, cls: Type, entity: str) -> Generator[AssociationItem, None, None]: for generic in utils.chain_iter(mapAspect): kind = GetIirKindOfNode(generic) if kind is nodes.Iir_Kind.Association_Element_By_Expression: formalNode = nodes.Get_Formal(generic) if formalNode is nodes.Null_Iir: formal = None else: formal = GetNameFromNode(formalNode) actual = GetExpressionFromNode(nodes.Get_Actual(generic)) yield cls(generic, actual, formal) elif kind is nodes.Iir_Kind.Association_Element_Open: formalNode = nodes.Get_Formal(generic) if formalNode is nodes.Null_Iir: formal = None else: formal = GetNameFromNode(formalNode) yield cls(generic, OpenName(generic), formal) else: pos = Position.parse(generic) raise DOMException( "Unknown association kind '{kind}' in {entity} map at line {line}.".format( kind=kind.name, entity=entity, line=pos.Line ) ) def GetGenericMapAspect( genericMapAspect: Iir, ) -> Generator[GenericAssociationItem, None, None]: return GetMapAspect(genericMapAspect, GenericAssociationItem, "generic") def GetPortMapAspect(portMapAspect: Iir) -> Generator[PortAssociationItem, None, None]: return GetMapAspect(portMapAspect, PortAssociationItem, "port") def GetParameterMapAspect( parameterMapAspect: Iir, ) -> Generator[ParameterAssociationItem, None, None]: return GetMapAspect(parameterMapAspect, ParameterAssociationItem, "parameter") def GetDeclaredItemsFromChainedNodes(nodeChain: Iir, entity: str, name: str) -> Generator[ModelEntity, None, None]: item = nodeChain lastKind = None while item != nodes.Null_Iir: kind = GetIirKindOfNode(item) if kind == nodes.Iir_Kind.Constant_Declaration: from pyGHDL.dom.Object import Constant obj = Constant.parse(item) elif kind == nodes.Iir_Kind.Variable_Declaration: from pyGHDL.dom.Object import SharedVariable if nodes.Get_Shared_Flag(item): obj = SharedVariable.parse(item) else: obj = Variable.parse(item) elif kind == nodes.Iir_Kind.Signal_Declaration: from pyGHDL.dom.Object import Signal obj = Signal.parse(item) elif kind == nodes.Iir_Kind.File_Declaration: from pyGHDL.dom.Object import File obj = File.parse(item) else: if kind == nodes.Iir_Kind.Type_Declaration: yield GetTypeFromNode(item) elif kind == nodes.Iir_Kind.Anonymous_Type_Declaration: yield GetAnonymousTypeFromNode(item) elif kind == nodes.Iir_Kind.Subtype_Declaration: yield GetSubtypeFromNode(item) elif kind == nodes.Iir_Kind.Function_Declaration: if nodes.Get_Has_Body(item): yield Function.parse(item) else: print("[NOT IMPLEMENTED] function declaration without body") lastKind = kind item = nodes.Get_Chain(item) continue elif kind == nodes.Iir_Kind.Function_Body: if lastKind is nodes.Iir_Kind.Function_Declaration: pass else: position = Position.parse(item) raise DOMException( "Found unexpected function body '{functionName}' in {entity} '{name}' at {file}:{line}:{column}.".format( functionName=GetNameOfNode(item), entity=entity, name=name, file=position.Filename, line=position.Line, column=position.Column, ) ) elif kind == nodes.Iir_Kind.Procedure_Declaration: if nodes.Get_Has_Body(item): yield Procedure.parse(item) else: print("[NOT IMPLEMENTED] procedure declaration without body") lastKind = kind item = nodes.Get_Chain(item) continue elif kind == nodes.Iir_Kind.Procedure_Body: if lastKind is nodes.Iir_Kind.Procedure_Declaration: pass else: position = Position.parse(item) raise DOMException( "Found unexpected procedure body '{functionName}' in {entity} '{name}' at {file}:{line}:{column}.".format( functionName=GetNameOfNode(item), entity=entity, name=name, file=position.Filename, line=position.Line, column=position.Column, ) ) elif kind == nodes.Iir_Kind.Protected_Type_Body: yield ProtectedTypeBody.parse(item) elif kind == nodes.Iir_Kind.Object_Alias_Declaration: yield GetAliasFromNode(item) elif kind == nodes.Iir_Kind.Component_Declaration: from pyGHDL.dom.DesignUnit import Component yield Component.parse(item) elif kind == nodes.Iir_Kind.Attribute_Declaration: from pyGHDL.dom.Attribute import Attribute yield Attribute.parse(item) elif kind == nodes.Iir_Kind.Attribute_Specification: from pyGHDL.dom.Attribute import AttributeSpecification yield AttributeSpecification.parse(item) elif kind == nodes.Iir_Kind.Use_Clause: from pyGHDL.dom.DesignUnit import UseClause yield UseClause.parse(item) elif kind == nodes.Iir_Kind.Package_Declaration: from pyGHDL.dom.DesignUnit import Package yield Package.parse(item, None) # TODO: Can it have a context? elif kind == nodes.Iir_Kind.Package_Instantiation_Declaration: from pyGHDL.dom.DesignUnit import PackageInstantiation yield PackageInstantiation.parse(item) elif kind == nodes.Iir_Kind.Configuration_Specification: print("[NOT IMPLEMENTED] Configuration specification in {name}".format(name=name)) elif kind == nodes.Iir_Kind.Psl_Default_Clock: yield DefaultClock.parse(item) elif kind == nodes.Iir_Kind.Group_Declaration: print("[NOT IMPLEMENTED] Group declaration in {name}".format(name=name)) elif kind == nodes.Iir_Kind.Group_Template_Declaration: print("[NOT IMPLEMENTED] Group template declaration in {name}".format(name=name)) elif kind == nodes.Iir_Kind.Disconnection_Specification: print("[NOT IMPLEMENTED] Disconnect specification in {name}".format(name=name)) else: position = Position.parse(item) raise DOMException( "Unknown declared item kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}.".format( kind=kind.name, entity=entity, name=name, file=position.Filename, line=position.Line, column=position.Column, ) ) lastKind = None item = nodes.Get_Chain(item) continue # Lookahead for objects with multiple identifiers at once if nodes.Get_Has_Identifier_List(item): nextNode = nodes.Get_Chain(item) for nextItem in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextItem) == nodes.Null_Iir: obj.Identifiers.append(GetNameOfNode(nextItem)) else: item = nextItem break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextItem): item = nodes.Get_Chain(nextItem) break else: item = nodes.Null_Iir else: item = nodes.Get_Chain(item) yield obj def GetConcurrentStatementsFromChainedNodes( nodeChain: Iir, entity: str, name: str ) -> Generator[ConcurrentStatement, None, None]: for statement in utils.chain_iter(nodeChain): label = nodes.Get_Label(statement) label = name_table.Get_Name_Ptr(label) if label != nodes.Null_Iir else None pos = Position.parse(statement) kind = GetIirKindOfNode(statement) if kind == nodes.Iir_Kind.Sensitized_Process_Statement: yield ProcessStatement.parse(statement, label, True) elif kind == nodes.Iir_Kind.Process_Statement: yield ProcessStatement.parse(statement, label, False) elif kind == nodes.Iir_Kind.Concurrent_Simple_Signal_Assignment: yield ConcurrentSimpleSignalAssignment.parse(statement, label) elif kind == nodes.Iir_Kind.Concurrent_Conditional_Signal_Assignment: print( "[NOT IMPLEMENTED] Concurrent (conditional) signal assignment (label: '{label}') at line {line}".format( label=label, line=pos.Line ) ) elif kind == nodes.Iir_Kind.Concurrent_Selected_Signal_Assignment: print( "[NOT IMPLEMENTED] Concurrent (selected) signal assignment (label: '{label}') at line {line}".format( label=label, line=pos.Line ) ) elif kind == nodes.Iir_Kind.Concurrent_Procedure_Call_Statement: yield ConcurrentProcedureCall.parse(statement, label) elif kind == nodes.Iir_Kind.Component_Instantiation_Statement: instantiatedUnit = nodes.Get_Instantiated_Unit(statement) instantiatedUnitKind = GetIirKindOfNode(instantiatedUnit) if instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Entity: yield EntityInstantiation.parse(statement, instantiatedUnit, label) elif instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Configuration: yield ConfigurationInstantiation.parse(statement, instantiatedUnit, label) elif instantiatedUnitKind == nodes.Iir_Kind.Simple_Name: yield ComponentInstantiation.parse(statement, instantiatedUnit, label) else: raise DOMException( "Unknown instantiation kind '{kind}' in instantiation of label {label} at {file}:{line}:{column}.".format( kind=instantiatedUnitKind.name, label=label, file=pos.Filename, line=pos.Line, column=pos.Column, ) ) elif kind == nodes.Iir_Kind.Block_Statement: yield ConcurrentBlockStatement.parse(statement, label) elif kind == nodes.Iir_Kind.If_Generate_Statement: yield IfGenerateStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Case_Generate_Statement: yield CaseGenerateStatement.parse(statement, label) elif kind == nodes.Iir_Kind.For_Generate_Statement: yield ForGenerateStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Psl_Assert_Directive: yield ConcurrentAssertStatement.parse(statement, label) else: raise DOMException( "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}.".format( kind=kind.name, entity=entity, name=name, file=pos.Filename, line=pos.Line, column=pos.Column, ) ) def GetSequentialStatementsFromChainedNodes( nodeChain: Iir, entity: str, name: str ) -> Generator[SequentialStatement, None, None]: for statement in utils.chain_iter(nodeChain): label = nodes.Get_Label(statement) label = name_table.Get_Name_Ptr(label) if label != nodes.Null_Iir else None pos = Position.parse(statement) kind = GetIirKindOfNode(statement) if kind == nodes.Iir_Kind.If_Statement: yield IfStatement.parse(statement, label) elif kind == nodes.Iir_Kind.For_Loop_Statement: yield ForLoopStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Case_Statement: yield CaseStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Simple_Signal_Assignment_Statement: yield SequentialSimpleSignalAssignment.parse(statement, label) elif kind in ( nodes.Iir_Kind.Variable_Assignment_Statement, nodes.Iir_Kind.Conditional_Variable_Assignment_Statement, ): print( "[NOT IMPLEMENTED] Variable assignment (label: '{label}') at line {line}".format( label=label, line=pos.Line ) ) elif kind == nodes.Iir_Kind.Wait_Statement: yield WaitStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Procedure_Call_Statement: yield SequentialProcedureCall.parse(statement, label) elif kind == nodes.Iir_Kind.Report_Statement: yield SequentialReportStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Assertion_Statement: yield SequentialAssertStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Null_Statement: yield NullStatement(statement, label) else: raise DOMException( "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}.".format( kind=kind.name, entity=entity, name=name, file=pos.Filename, line=pos.Line, column=pos.Column, ) ) def GetAliasFromNode(aliasNode: Iir): aliasName = GetNameOfNode(aliasNode) return Alias(aliasNode, aliasName)