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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
|
-- Debug utilities on elaborated design
-- Copyright (C) 2019 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>.
with Types; use Types;
with Name_Table; use Name_Table;
with Simple_IO; use Simple_IO;
with Utils_IO; use Utils_IO;
with Libraries;
with Elab.Memtype; use Elab.Memtype;
with Elab.Vhdl_Values; use Elab.Vhdl_Values;
with Vhdl.Utils; use Vhdl.Utils;
with Vhdl.Errors;
package body Elab.Vhdl_Debug is
procedure Disp_Discrete_Value (Val : Int64; Btype : Node) is
begin
case Get_Kind (Btype) is
when Iir_Kind_Integer_Type_Definition
| Iir_Kind_Integer_Subtype_Definition =>
Put_Int64 (Val);
when Iir_Kind_Enumeration_Type_Definition
| Iir_Kind_Enumeration_Subtype_Definition =>
declare
Pos : constant Natural := Natural (Val);
Enums : constant Node_Flist :=
Get_Enumeration_Literal_List (Btype);
Id : constant Name_Id :=
Get_Identifier (Get_Nth_Element (Enums, Pos));
begin
Put (Name_Table.Image (Id));
end;
when others =>
Vhdl.Errors.Error_Kind ("disp_discrete_value", Btype);
end case;
end Disp_Discrete_Value;
procedure Disp_Value_Vector (Mem : Memtyp; A_Type: Node; Bound : Bound_Type)
is
El_Type : constant Node := Get_Base_Type (Get_Element_Subtype (A_Type));
El_Typ : constant Type_Acc := Get_Array_Element (Mem.Typ);
type Last_Enum_Type is (None, Char, Identifier);
Last_Enum : Last_Enum_Type;
Enum_List : Node_Flist;
El_Id : Name_Id;
El_Pos : Natural;
begin
-- Pretty print vectors of enumerated types
if Get_Kind (El_Type) = Iir_Kind_Enumeration_Type_Definition then
Last_Enum := None;
Enum_List := Get_Enumeration_Literal_List (El_Type);
for I in 1 .. Bound.Len loop
El_Pos := Natural
(Read_Discrete
(Memtyp'(El_Typ, Mem.Mem + Size_Type (I - 1) * El_Typ.Sz)));
El_Id := Get_Identifier (Get_Nth_Element (Enum_List, El_Pos));
if Name_Table.Is_Character (El_Id) then
case Last_Enum is
when None =>
Put ("""");
when Identifier =>
Put (" & """);
when Char =>
null;
end case;
Put (Name_Table.Get_Character (El_Id));
Last_Enum := Char;
else
case Last_Enum is
when None =>
null;
when Identifier =>
Put (" & ");
when Char =>
Put (""" & ");
end case;
Put (Name_Table.Image (El_Id));
Last_Enum := Identifier;
end if;
end loop;
case Last_Enum is
when None =>
Put (""""""); -- Simply ""
when Identifier =>
null;
when Char =>
Put ("""");
end case;
else
Put ("(");
for I in 1 .. Bound.Len loop
if I /= 1 then
Put (", ");
end if;
Disp_Memtyp ((El_Typ, Mem.Mem + Size_Type (I - 1) * El_Typ.Sz),
El_Type);
end loop;
Put (")");
end if;
end Disp_Value_Vector;
procedure Disp_Value_Array (Mem : Memtyp; A_Type: Node; Dim: Dim_Type)
is
Stride : Size_Type;
begin
if Dim = Mem.Typ.Abounds.Ndim then
-- Last dimension
Disp_Value_Vector (Mem, A_Type, Mem.Typ.Abounds.D (Dim));
else
Stride := Mem.Typ.Arr_El.Sz;
for I in Dim + 1 .. Mem.Typ.Abounds.Ndim loop
Stride := Stride * Size_Type (Mem.Typ.Abounds.D (I).Len);
end loop;
Put ("(");
for I in 1 .. Mem.Typ.Abounds.D (Dim).Len loop
if I /= 1 then
Put (", ");
end if;
Disp_Value_Array ((Mem.Typ, Mem.Mem + Stride), A_Type, Dim + 1);
end loop;
Put (")");
end if;
end Disp_Value_Array;
procedure Disp_Memtyp (M : Memtyp; Vtype : Node) is
begin
if M.Mem = null then
Put ("*NULL*");
return;
end if;
case M.Typ.Kind is
when Type_Discrete
| Type_Bit
| Type_Logic =>
Disp_Discrete_Value (Read_Discrete (M), Get_Base_Type (Vtype));
when Type_Vector =>
Disp_Value_Vector (M, Vtype, M.Typ.Vbound);
when Type_Array =>
Disp_Value_Array (M, Vtype, 1);
when Type_Float =>
Put ("*float*");
when Type_Slice =>
Put ("*slice*");
when Type_File =>
Put ("*file*");
when Type_Record =>
Put ("*record*");
when Type_Access =>
Put ("*access*");
when Type_Protected =>
Put ("*protected*");
when Type_Unbounded_Array
| Type_Unbounded_Record
| Type_Unbounded_Vector =>
Put ("*unbounded*");
end case;
end Disp_Memtyp;
procedure Disp_Value (Vt : Valtyp; Vtype : Node) is
begin
if Vt.Val = null then
Put ("*NULL*");
return;
end if;
case Vt.Val.Kind is
when Value_Net =>
Put ("net");
when Value_Wire =>
Put ("wire");
when Value_Signal =>
Put ("signal");
Put (' ');
Put_Uns32 (Vt.Val.S);
when Value_File =>
Put ("file");
when Value_Const =>
Put ("const: ");
Disp_Memtyp (Get_Memtyp (Vt), Vtype);
when Value_Alias =>
Put ("alias");
Disp_Memtyp (Get_Memtyp (Vt), Vtype);
when Value_Memory =>
Disp_Memtyp (Get_Memtyp (Vt), Vtype);
end case;
end Disp_Value;
procedure Disp_Direction (Dir : Direction_Type) is
begin
case Dir is
when Dir_To =>
Put ("to");
when Dir_Downto =>
Put ("downto");
end case;
end Disp_Direction;
procedure Disp_Bound_Type (Bound : Bound_Type) is
begin
Put_Int32 (Bound.Left);
Put (' ');
Disp_Direction (Bound.Dir);
Put (' ');
Put_Int32 (Bound.Right);
end Disp_Bound_Type;
procedure Disp_Discrete_Range (Rng : Discrete_Range_Type; Vtype : Node) is
begin
Disp_Discrete_Value (Rng.Left, Vtype);
Put (' ');
Disp_Direction (Rng.Dir);
Put (' ');
Disp_Discrete_Value (Rng.Right, Vtype);
end Disp_Discrete_Range;
procedure Disp_Type (Typ : Type_Acc; Vtype : Node)
is
pragma Unreferenced (Vtype);
begin
case Typ.Kind is
when Type_Bit =>
Put ("bit");
when Type_Logic =>
Put ("logic");
when Type_Discrete =>
Put ("discrete");
when Type_Float =>
Put ("float");
when Type_Vector =>
Put ("vector (");
Disp_Bound_Type (Typ.Vbound);
Put (')');
when Type_Unbounded_Vector =>
Put ("unbounded_vector");
when Type_Array =>
Put ("array");
when Type_Unbounded_Array =>
Put ("unbounded_array");
when Type_Unbounded_Record =>
Put ("unbounded_record");
when Type_Record =>
Put ("record");
when Type_Slice =>
Put ("slice");
when Type_Access =>
Put ("access");
when Type_File =>
Put ("file");
when Type_Protected =>
Put ("protected");
end case;
end Disp_Type;
procedure Disp_Declaration_Object
(Instance : Synth_Instance_Acc; Decl : Iir; Indent : Natural) is
begin
case Get_Kind (Decl) is
when Iir_Kind_Constant_Declaration
| Iir_Kind_Variable_Declaration
| Iir_Kind_Interface_Variable_Declaration
| Iir_Kind_Interface_Constant_Declaration
| Iir_Kind_Interface_File_Declaration
| Iir_Kind_Object_Alias_Declaration
| Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Signal_Declaration
| Iir_Kind_File_Declaration =>
declare
Val : constant Valtyp := Get_Value (Instance, Decl);
Dtype : constant Node := Get_Type (Decl);
begin
Put_Indent (Indent);
Put (Vhdl.Errors.Disp_Node (Decl));
Put (": ");
Disp_Type (Val.Typ, Dtype);
Put (" = ");
Disp_Value (Val, Dtype);
New_Line;
end;
when Iir_Kinds_Signal_Attribute
| Iir_Kind_Attribute_Declaration
| Iir_Kind_Attribute_Specification =>
-- FIXME: todo ?
null;
when Iir_Kind_Type_Declaration
| Iir_Kind_Anonymous_Type_Declaration
| Iir_Kind_Subtype_Declaration =>
-- FIXME: disp ranges
null;
when Iir_Kind_Function_Declaration
| Iir_Kind_Function_Body
| Iir_Kind_Procedure_Declaration
| Iir_Kind_Procedure_Body
| Iir_Kind_Component_Declaration =>
null;
when others =>
Vhdl.Errors.Error_Kind ("disp_declaration_object", Decl);
end case;
end Disp_Declaration_Object;
procedure Disp_Declaration_Objects
(Instance : Synth_Instance_Acc; Decl_Chain : Iir; Indent : Natural := 0)
is
El : Iir;
begin
El := Decl_Chain;
while El /= Null_Iir loop
Disp_Declaration_Object (Instance, El, Indent);
El := Get_Chain (El);
end loop;
end Disp_Declaration_Objects;
package Hierarchy_Pkg is
type Config_Type is record
With_Objs : Boolean;
Recurse : Boolean;
Indent : Natural;
end record;
procedure Disp_Hierarchy (Inst : Synth_Instance_Acc; Cfg : Config_Type);
procedure Disp_Hierarchy_Statements
(Inst : Synth_Instance_Acc; Stmts : Node; Cfg : Config_Type);
end Hierarchy_Pkg;
package body Hierarchy_Pkg is
function Inc_Indent (Cfg : Config_Type) return Config_Type
is
Res : Config_Type;
begin
Res := Cfg;
Res.Indent := Res.Indent + 1;
return Res;
end Inc_Indent;
procedure Disp_Hierarchy_Statement
(Inst : Synth_Instance_Acc; Stmt : Node; Cfg : Config_Type) is
begin
case Get_Kind (Stmt) is
when Iir_Kind_Component_Instantiation_Statement =>
declare
Sub : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
Sub_Node : constant Node := Get_Source_Scope (Sub);
Comp_Inst : Synth_Instance_Acc;
begin
Put_Indent (Cfg.Indent);
Put (Image (Get_Label (Stmt)));
case Get_Kind (Sub_Node) is
when Iir_Kind_Component_Declaration =>
Put (": component ");
Put (Image (Get_Identifier (Sub_Node)));
Comp_Inst := Get_Component_Instance (Sub);
if Comp_Inst = null then
Put_Line (" [not bound]");
else
New_Line;
end if;
if Cfg.With_Objs then
Disp_Declaration_Objects
(Sub, Get_Generic_Chain (Sub_Node),
Cfg.Indent);
Disp_Declaration_Objects
(Sub, Get_Port_Chain (Sub_Node),
Cfg.Indent);
end if;
if Cfg.Recurse and then Comp_Inst /= null then
Disp_Hierarchy (Comp_Inst, Inc_Indent (Cfg));
end if;
when Iir_Kind_Architecture_Body =>
Put (": entity ");
Put (Image (Get_Identifier
(Get_Entity (Sub_Node))));
Put ('(');
Put (Image (Get_Identifier (Sub_Node)));
Put (')');
New_Line;
if Cfg.Recurse then
Disp_Hierarchy (Sub, Inc_Indent (Cfg));
end if;
when others =>
raise Internal_Error;
end case;
end;
when Iir_Kind_If_Generate_Statement =>
declare
Sub : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
begin
if Sub = null then
return;
end if;
Put_Indent (Cfg.Indent);
Put (Image (Get_Label (Stmt)));
Put (": if-generate");
if Sub = null then
Put_Line (" [false]");
else
Put_Line (" [true]");
if Cfg.Recurse then
Disp_Hierarchy (Sub, Inc_Indent (Cfg));
end if;
end if;
end;
when Iir_Kind_For_Generate_Statement =>
declare
It : constant Node := Get_Parameter_Specification (Stmt);
It_Type : constant Node := Get_Type (It);
It_Rng : Type_Acc;
It_Len : Natural;
Gen_Inst : Synth_Instance_Acc;
begin
Put_Indent (Cfg.Indent);
Put (Image (Get_Label (Stmt)));
Put (": for-generate");
Put (" (");
It_Rng := Get_Subtype_Object (Inst, It_Type);
Disp_Discrete_Range (It_Rng.Drange, It_Type);
Put_Line (")");
if Cfg.Recurse then
It_Len := Natural (Get_Range_Length (It_Rng.Drange));
Gen_Inst := Get_Sub_Instance (Inst, Stmt);
for I in 1 .. It_Len loop
Disp_Hierarchy
(Get_Generate_Sub_Instance (Gen_Inst, I),
Inc_Indent (Cfg));
end loop;
end if;
end;
when Iir_Kind_Block_Statement =>
declare
Sub : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
begin
Put_Indent (Cfg.Indent);
Put (Image (Get_Label (Stmt)));
Put_Line (": block");
if Cfg.Recurse then
Disp_Hierarchy_Statements
(Sub, Get_Concurrent_Statement_Chain (Stmt),
Inc_Indent (Cfg));
end if;
end;
when Iir_Kinds_Concurrent_Signal_Assignment
| Iir_Kind_Concurrent_Assertion_Statement
| Iir_Kind_Concurrent_Procedure_Call_Statement =>
null;
when Iir_Kinds_Process_Statement =>
-- Note: processes are not elaborated.
if Cfg.With_Objs then
Put_Indent (Cfg.Indent);
Put (Image (Get_Label (Stmt)));
Put_Line (": process");
end if;
when others =>
Vhdl.Errors.Error_Kind ("disp_hierarchy_statement", Stmt);
end case;
end Disp_Hierarchy_Statement;
procedure Disp_Hierarchy_Statements
(Inst : Synth_Instance_Acc; Stmts : Node; Cfg : Config_Type)
is
Stmt : Node;
begin
Stmt := Stmts;
while Stmt /= Null_Node loop
Disp_Hierarchy_Statement (Inst, Stmt, Cfg);
Stmt := Get_Chain (Stmt);
end loop;
end Disp_Hierarchy_Statements;
procedure Disp_Hierarchy
(Inst : Synth_Instance_Acc; Cfg : Config_Type)
is
N : constant Node := Get_Source_Scope (Inst);
begin
case Get_Kind (N) is
when Iir_Kind_Architecture_Body =>
declare
Ent : constant Node := Get_Entity (N);
begin
Put_Indent (Cfg.Indent);
Put ("architecture ");
Put (Image (Get_Identifier (N)));
Put (" of ");
Put (Image (Get_Identifier (Ent)));
New_Line;
if Cfg.With_Objs then
Put_Indent (Cfg.Indent);
Put_Line ("[entity]");
Disp_Declaration_Objects
(Inst, Get_Generic_Chain (Ent), Cfg.Indent);
Disp_Declaration_Objects
(Inst, Get_Port_Chain (Ent), Cfg.Indent);
Put_Indent (Cfg.Indent);
Put_Line ("[architecture]");
Disp_Declaration_Objects
(Inst, Get_Declaration_Chain (Ent), Cfg.Indent);
Disp_Declaration_Objects
(Inst, Get_Declaration_Chain (N), Cfg.Indent);
end if;
Disp_Hierarchy_Statements
(Inst, Get_Concurrent_Statement_Chain (N),
Inc_Indent (Cfg));
end;
when Iir_Kind_Component_Declaration =>
Put_Indent (Cfg.Indent);
Put ("component ");
Put (Image (Get_Identifier (N)));
New_Line;
Disp_Hierarchy
(Get_Component_Instance (Inst), Inc_Indent (Cfg));
when Iir_Kind_Generate_Statement_Body =>
Put_Indent (Cfg.Indent);
Put ("generate statement body");
-- TODO: disp label or index ?
New_Line;
Disp_Hierarchy_Statements
(Inst, Get_Concurrent_Statement_Chain (N), Cfg);
when Iir_Kind_Block_Statement =>
Put_Indent (Cfg.Indent);
Put ("block statement ");
Put (Image (Get_Identifier (N)));
New_Line;
Disp_Hierarchy_Statements
(Inst, Get_Concurrent_Statement_Chain (N), Cfg);
when others =>
Vhdl.Errors.Error_Kind ("disp_hierarchy", N);
end case;
end Disp_Hierarchy;
end Hierarchy_Pkg;
procedure Disp_Hierarchy (Inst : Synth_Instance_Acc;
Recurse : Boolean;
With_Objs : Boolean)
is
use Hierarchy_Pkg;
Cfg : Config_Type;
begin
Cfg := (With_Objs => With_Objs,
Recurse => Recurse,
Indent => 0);
Hierarchy_Pkg.Disp_Hierarchy (Inst, Cfg);
end Disp_Hierarchy;
function Walk_Files (Cb : Walk_Cb) return Walk_Status
is
Lib : Iir_Library_Declaration := Libraries.Get_Libraries_Chain;
File : Iir_Design_File;
begin
while Lib /= Null_Iir loop
File := Get_Design_File_Chain (Lib);
while File /= Null_Iir loop
case Cb.all (File) is
when Walk_Continue =>
null;
when Walk_Up =>
exit;
when Walk_Abort =>
return Walk_Abort;
end case;
File := Get_Chain (File);
end loop;
Lib := Get_Chain (Lib);
end loop;
return Walk_Continue;
end Walk_Files;
Walk_Units_Cb : Walk_Cb;
function Cb_Walk_Units (Design_File : Iir) return Walk_Status
is
Unit : Iir_Design_Unit;
begin
Unit := Get_First_Design_Unit (Design_File);
while Unit /= Null_Iir loop
case Walk_Units_Cb.all (Get_Library_Unit (Unit)) is
when Walk_Continue =>
null;
when Walk_Abort =>
return Walk_Abort;
when Walk_Up =>
exit;
end case;
Unit := Get_Chain (Unit);
end loop;
return Walk_Continue;
end Cb_Walk_Units;
function Walk_Units (Cb : Walk_Cb) return Walk_Status is
begin
Walk_Units_Cb := Cb;
return Walk_Files (Cb_Walk_Units'Access);
end Walk_Units;
Walk_Declarations_Cb : Walk_Cb;
function Cb_Walk_Declarations (Unit : Iir) return Walk_Status
is
function Walk_Decl_Chain (Chain : Iir) return Walk_Status
is
Decl : Iir;
begin
Decl := Chain;
while Decl /= Null_Iir loop
case Walk_Declarations_Cb.all (Decl) is
when Walk_Abort =>
return Walk_Abort;
when Walk_Up =>
return Walk_Continue;
when Walk_Continue =>
null;
end case;
Decl := Get_Chain (Decl);
end loop;
return Walk_Continue;
end Walk_Decl_Chain;
function Walk_Conc_Chain (Chain : Iir) return Walk_Status;
function Walk_Generate_Statement_Body (Bod : Iir) return Walk_Status is
begin
if Walk_Decl_Chain (Get_Declaration_Chain (Bod)) = Walk_Abort then
return Walk_Abort;
end if;
if Walk_Conc_Chain (Get_Concurrent_Statement_Chain (Bod)) = Walk_Abort
then
return Walk_Abort;
end if;
return Walk_Continue;
end Walk_Generate_Statement_Body;
function Walk_Conc_Chain (Chain : Iir) return Walk_Status
is
Stmt : Iir := Chain;
begin
while Stmt /= Null_Iir loop
case Get_Kind (Stmt) is
when Iir_Kinds_Process_Statement =>
if Walk_Decl_Chain (Get_Declaration_Chain (Stmt))
= Walk_Abort
then
return Walk_Abort;
end if;
when Iir_Kind_For_Generate_Statement =>
if Walk_Declarations_Cb.all
(Get_Parameter_Specification (Stmt)) = Walk_Abort
or else Walk_Generate_Statement_Body
(Get_Generate_Statement_Body (Stmt)) = Walk_Abort
then
return Walk_Abort;
end if;
when Iir_Kind_If_Generate_Statement =>
declare
Stmt1 : Iir;
begin
Stmt1 := Stmt;
while Stmt1 /= Null_Iir loop
if Walk_Generate_Statement_Body
(Get_Generate_Statement_Body (Stmt)) = Walk_Abort
then
return Walk_Abort;
end if;
Stmt1 := Get_Generate_Else_Clause (Stmt1);
end loop;
end;
when Iir_Kind_Component_Instantiation_Statement
| Iir_Kind_Concurrent_Simple_Signal_Assignment =>
null;
when Iir_Kind_Block_Statement =>
-- FIXME: header
if (Walk_Decl_Chain
(Get_Declaration_Chain (Stmt)) = Walk_Abort)
or else
(Walk_Conc_Chain
(Get_Concurrent_Statement_Chain (Stmt)) = Walk_Abort)
then
return Walk_Abort;
end if;
when others =>
Vhdl.Errors.Error_Kind ("walk_conc_chain", Stmt);
end case;
Stmt := Get_Chain (Stmt);
end loop;
return Walk_Continue;
end Walk_Conc_Chain;
begin
case Get_Kind (Unit) is
when Iir_Kind_Entity_Declaration =>
if Walk_Decl_Chain (Get_Generic_Chain (Unit)) = Walk_Abort
or else Walk_Decl_Chain (Get_Port_Chain (Unit)) = Walk_Abort
or else (Walk_Decl_Chain
(Get_Declaration_Chain (Unit)) = Walk_Abort)
or else (Walk_Conc_Chain
(Get_Concurrent_Statement_Chain (Unit)) = Walk_Abort)
then
return Walk_Abort;
end if;
when Iir_Kind_Architecture_Body =>
if (Walk_Decl_Chain
(Get_Declaration_Chain (Unit)) = Walk_Abort)
or else (Walk_Conc_Chain
(Get_Concurrent_Statement_Chain (Unit)) = Walk_Abort)
then
return Walk_Abort;
end if;
when Iir_Kind_Package_Declaration
| Iir_Kind_Package_Body =>
if Walk_Decl_Chain (Get_Declaration_Chain (Unit)) = Walk_Abort
then
return Walk_Abort;
end if;
when Iir_Kind_Configuration_Declaration =>
if Walk_Decl_Chain (Get_Declaration_Chain (Unit)) = Walk_Abort
then
return Walk_Abort;
end if;
-- FIXME: block configuration ?
when Iir_Kind_Context_Declaration =>
null;
when others =>
Vhdl.Errors.Error_Kind ("Cb_Walk_Declarations", Unit);
end case;
return Walk_Continue;
end Cb_Walk_Declarations;
function Walk_Declarations (Cb : Walk_Cb) return Walk_Status is
begin
Walk_Declarations_Cb := Cb;
return Walk_Units (Cb_Walk_Declarations'Access);
end Walk_Declarations;
function Find_Concurrent_Statement_By_Name (Stmts : Node; Id : Name_Id)
return Node
is
Stmt : Node;
begin
Stmt := Stmts;
while Stmt /= Null_Node loop
if Get_Label (Stmt) = Id then
return Stmt;
end if;
Stmt := Get_Chain (Stmt);
end loop;
return Null_Node;
end Find_Concurrent_Statement_By_Name;
function Get_Sub_Instance_By_Name (Inst : Synth_Instance_Acc; Name : String)
return Synth_Instance_Acc
is
Scope : constant Node := Get_Source_Scope (Inst);
Has_Index : Boolean;
End_Id : Natural;
Index : Int64;
Stmt : Node;
Id : Name_Id;
begin
End_Id := Name'Last;
Has_Index := Name (End_Id) = ')';
Index := 0;
if Has_Index then
-- There is a loop-generate index.
-- Search for '('.
for I in Name'Range loop
if Name (I) = '(' then
End_Id := I - 1;
exit;
end if;
end loop;
if End_Id = Name'Last or End_Id = Name'First then
return null;
end if;
-- Decode index (assume int).
for P in End_Id + 2 .. Name'Last - 1 loop
if Name (P) in '0' .. '9' then
Index := Index * 10
+ Character'Pos (Name (P)) - Character'Pos ('0');
else
return null;
end if;
end loop;
end if;
Id := Get_Identifier_No_Create (Name (Name'First .. End_Id));
if Id = Null_Identifier then
-- All the identifiers are known, so this name cannot exist.
return null;
end if;
case Get_Kind (Scope) is
when Iir_Kind_Architecture_Body
| Iir_Kind_Generate_Statement_Body
| Iir_Kind_Block_Statement =>
Stmt := Find_Concurrent_Statement_By_Name
(Get_Concurrent_Statement_Chain (Scope), Id);
when others =>
Vhdl.Errors.Error_Kind ("get_sub_instance(1)", Scope);
end case;
if Stmt = Null_Node then
return null;
end if;
case Get_Kind (Stmt) is
when Iir_Kind_Component_Instantiation_Statement =>
if Has_Index then
return null;
end if;
declare
Sub_Inst : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
Sub_Node : constant Node := Get_Source_Scope (Sub_Inst);
begin
case Get_Kind (Sub_Node) is
when Iir_Kind_Component_Declaration =>
return Get_Component_Instance (Sub_Inst);
when Iir_Kind_Architecture_Body =>
return Sub_Inst;
when others =>
raise Internal_Error;
end case;
end;
when Iir_Kind_If_Generate_Statement
| Iir_Kind_Block_Statement =>
if Has_Index then
return null;
end if;
return Get_Sub_Instance (Inst, Stmt);
when Iir_Kind_For_Generate_Statement =>
if not Has_Index then
return null;
end if;
declare
Iterator : constant Node :=
Get_Parameter_Specification (Stmt);
It_Rng : constant Type_Acc :=
Get_Subtype_Object (Inst, Get_Type (Iterator));
Gen_Inst : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
Off : Int64;
begin
case It_Rng.Drange.Dir is
when Dir_To =>
if Index < It_Rng.Drange.Left
or else Index > It_Rng.Drange.Right
then
return null;
end if;
Off := Index - It_Rng.Drange.Left + 1;
when Dir_Downto =>
if Index > It_Rng.Drange.Left
or else Index < It_Rng.Drange.Right
then
return null;
end if;
Off := Index - It_Rng.Drange.Right + 1;
end case;
return Get_Generate_Sub_Instance (Gen_Inst, Positive (Off));
end;
when Iir_Kinds_Concurrent_Signal_Assignment
| Iir_Kind_Concurrent_Assertion_Statement
| Iir_Kind_Concurrent_Procedure_Call_Statement =>
return null;
when others =>
Vhdl.Errors.Error_Kind ("get_sub_instance(2)", Stmt);
end case;
end Get_Sub_Instance_By_Name;
function Find_Concurrent_Statement_By_Instance
(Inst : Synth_Instance_Acc;
Stmts : Node;
Sub_Inst : Synth_Instance_Acc) return Node
is
Stmt : Node;
begin
Stmt := Stmts;
while Stmt /= Null_Node loop
case Get_Kind (Stmt) is
when Iir_Kind_Component_Instantiation_Statement
| Iir_Kind_If_Generate_Statement
| Iir_Kind_Block_Statement =>
declare
Sub : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
begin
if Sub = Sub_Inst then
return Stmt;
end if;
end;
when Iir_Kind_For_Generate_Statement =>
declare
Sub : constant Synth_Instance_Acc :=
Get_Sub_Instance (Inst, Stmt);
begin
if Sub = Sub_Inst then -- Get_Instance_Parent (Sub_Inst) then
return Stmt;
end if;
end;
when others =>
null;
end case;
Stmt := Get_Chain (Stmt);
end loop;
raise Internal_Error;
end Find_Concurrent_Statement_By_Instance;
function Skip_Instance_Parent (Inst : Synth_Instance_Acc)
return Synth_Instance_Acc
is
Parent : constant Synth_Instance_Acc := Get_Instance_Parent (Inst);
Parent_Scope : constant Node := Get_Source_Scope (Parent);
begin
if Parent_Scope = Null_Node then
-- The root.
return null;
end if;
case Get_Kind (Parent_Scope) is
when Iir_Kind_Architecture_Body
| Iir_Kind_Block_Statement =>
return Inst;
when Iir_Kind_Component_Declaration =>
return Parent;
when Iir_Kind_For_Generate_Statement =>
return Parent;
when Iir_Kind_Generate_Statement_Body =>
-- For an if-generate, the parent is really the parent.
return Inst;
when others =>
Vhdl.Errors.Error_Kind ("skip_instance_parent", Parent_Scope);
end case;
end Skip_Instance_Parent;
function Get_Instance_Path_Parent (Inst : Synth_Instance_Acc)
return Synth_Instance_Acc
is
Pre_Parent : constant Synth_Instance_Acc := Skip_Instance_Parent (Inst);
begin
if Pre_Parent = null then
-- The root.
return null;
end if;
return Get_Instance_Parent (Pre_Parent);
end Get_Instance_Path_Parent;
procedure Disp_Instance_Path_1 (Inst : Synth_Instance_Acc)
is
Pre_Parent_Inst : constant Synth_Instance_Acc :=
Skip_Instance_Parent (Inst);
Parent_Inst : Synth_Instance_Acc;
Parent_Scope : Node;
Stmt : Node;
begin
if Pre_Parent_Inst = null then
return;
end if;
Parent_Inst := Get_Instance_Parent (Pre_Parent_Inst);
Parent_Scope := Get_Source_Scope (Parent_Inst);
Disp_Instance_Path (Parent_Inst);
Put ('/');
Stmt := Find_Concurrent_Statement_By_Instance
(Parent_Inst, Get_Concurrent_Statement_Chain (Parent_Scope),
Pre_Parent_Inst);
Put (Image (Get_Identifier (Stmt)));
if Get_Kind (Stmt) = Iir_Kind_For_Generate_Statement then
declare
It : constant Node := Get_Parameter_Specification (Stmt);
It_Type : constant Node := Get_Type (It);
Val : constant Valtyp := Get_Value (Inst, It);
begin
Put ("(");
Disp_Discrete_Value (Read_Discrete (Val), It_Type);
Put (")");
end;
end if;
end Disp_Instance_Path_1;
procedure Disp_Instance_Path (Inst : Synth_Instance_Acc)
is
Parent : constant Synth_Instance_Acc := Get_Instance_Parent (Inst);
begin
if Parent = null then
-- The root.
Put ('/');
else
Disp_Instance_Path_1 (Inst);
end if;
end Disp_Instance_Path;
end Elab.Vhdl_Debug;
|