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
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
|
-- Debugger for interpreter
-- Copyright (C) 2014 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 System;
-- with Ada.Text_IO; use Ada.Text_IO;
with Tables;
with Types; use Types;
with Name_Table;
with Str_Table;
with Files_Map;
with Parse;
with Vhdl.Scanner;
with Tokens;
with Sem_Expr;
with Sem_Scopes;
with Canon;
with Std_Names;
with Libraries;
with Std_Package;
with Simul.Annotations; use Simul.Annotations;
with Simul.Elaboration; use Simul.Elaboration;
with Simul.Execution; use Simul.Execution;
with Iirs_Utils; use Iirs_Utils;
with Errorout; use Errorout;
with Disp_Vhdl;
with Iirs_Walk; use Iirs_Walk;
with Areapools; use Areapools;
with Grt.Types; use Grt.Types;
with Grt.Disp;
with Grt.Readline;
with Grt.Errors;
with Grt.Disp_Signals;
with Grt.Signals; use Grt.Signals;
with Grt.Processes;
with Grt.Options;
with Grt.Stdio; use Grt.Stdio;
with Grt.Astdio; use Grt.Astdio;
with Grt.Astdio.Vhdl; use Grt.Astdio.Vhdl;
package body Simul.Debugger is
-- This exception can be raised by a debugger command to directly return
-- to the prompt.
Command_Error : exception;
type Menu_Procedure is access procedure (Line : String);
-- If set (by commands), call this procedure on empty line to repeat
-- last command.
Cmd_Repeat : Menu_Procedure;
-- For the list command: current file and current line.
List_Current_File : Source_File_Entry := No_Source_File_Entry;
List_Current_Line : Natural := 0;
List_Current_Line_Pos : Source_Ptr := 0;
-- Set List_Current_* from a location. To be called after program break
-- to indicate current location.
procedure Set_List_Current (Loc : Location_Type)
is
Offset : Natural;
begin
Files_Map.Location_To_Coord
(Loc, List_Current_File, List_Current_Line_Pos,
List_Current_Line, Offset);
end Set_List_Current;
Dbg_Top_Frame : Block_Instance_Acc;
Dbg_Cur_Frame : Block_Instance_Acc;
procedure Set_Cur_Frame (Frame : Block_Instance_Acc) is
begin
Dbg_Cur_Frame := Frame;
end Set_Cur_Frame;
procedure Set_Top_Frame (Frame : Block_Instance_Acc) is
begin
Dbg_Top_Frame := Frame;
Set_Cur_Frame (Frame);
end Set_Top_Frame;
type Breakpoint_Entry is record
Stmt : Iir;
end record;
package Breakpoints is new Tables
(Table_Index_Type => Natural,
Table_Component_Type => Breakpoint_Entry,
Table_Low_Bound => 1,
Table_Initial => 16);
-- Current execution state, or reason to stop execution (set by the
-- last debugger command).
type Exec_State_Type is
(-- Execution should continue until a breakpoint is reached or assertion
-- failure.
Exec_Run,
-- Execution will stop at the next statement.
Exec_Single_Step,
-- Execution will stop at the next simple statement in the same frame.
Exec_Next,
-- Execution will stop at the next statement in the same frame. In
-- case of compound statement, stop after the compound statement.
Exec_Next_Stmt);
Exec_State : Exec_State_Type := Exec_Run;
-- Current frame for next.
Exec_Instance : Block_Instance_Acc;
-- Current statement for next_stmt.
Exec_Statement : Iir;
procedure Disp_Iir_Location (N : Iir) is
begin
if N = Null_Iir then
Put (stderr, "??:??:??");
else
Put (stderr, Disp_Location (N));
end if;
Put (stderr, ": ");
end Disp_Iir_Location;
-- Disp a message during execution.
procedure Error_Msg_Exec (Msg: String; Loc: in Iir) is
begin
Disp_Iir_Location (Loc);
Put_Line (stderr, Msg);
Grt.Errors.Fatal_Error;
end Error_Msg_Exec;
procedure Warning_Msg_Exec (Msg: String; Loc: Iir) is
begin
Disp_Iir_Location (Loc);
Put (stderr, "warning: ");
Put_Line (stderr, Msg);
end Warning_Msg_Exec;
-- Disp a message for a constraint error.
procedure Error_Msg_Constraint (Expr: in Iir) is
begin
if Expr /= Null_Iir then
Disp_Iir_Location (Expr);
end if;
Put (stderr, "constraint violation");
if Expr /= Null_Iir then
case Get_Kind (Expr) is
when Iir_Kind_Addition_Operator =>
Put_Line (stderr, " in the ""+"" operation");
when Iir_Kind_Substraction_Operator =>
Put_Line (stderr, " in the ""-"" operation");
when Iir_Kind_Integer_Literal =>
Put_Line (stderr, ", literal out of range");
when Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Signal_Declaration =>
Put_Line (stderr, " for " & Disp_Node (Expr));
when others =>
New_Line (stderr);
end case;
end if;
Grt.Errors.Fatal_Error;
end Error_Msg_Constraint;
function Get_Instance_Local_Name (Instance : Block_Instance_Acc;
Short : Boolean := False)
return String
is
Name : constant Iir := Instance.Label;
begin
if Name = Null_Iir then
return "<anon>";
end if;
case Get_Kind (Name) is
when Iir_Kind_Block_Statement
| Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement
| Iir_Kind_Component_Instantiation_Statement
| Iir_Kind_Procedure_Declaration
| Iir_Kinds_Process_Statement
| Iir_Kind_Package_Declaration
| Iir_Kind_Configuration_Declaration =>
return Image_Identifier (Name);
when Iir_Kind_Generate_Statement_Body =>
return Image_Identifier (Get_Parent (Name))
& '(' & Image_Identifier (Name) & ')';
when Iir_Kind_Iterator_Declaration =>
return Image_Identifier (Get_Parent (Name)) & '('
& Execute_Image_Attribute
(Instance.Objects (Get_Info (Name).Slot), Get_Type (Name))
& ')';
when Iir_Kind_Architecture_Body =>
if Short then
return Image_Identifier (Get_Entity (Name));
else
return Image_Identifier (Get_Entity (Name))
& '(' & Image_Identifier (Name) & ')';
end if;
when others =>
Error_Kind ("disp_instance_local_name", Name);
end case;
end Get_Instance_Local_Name;
-- Disp the name of an instance, without newline.
procedure Disp_Instance_Name (Instance: Block_Instance_Acc;
Short : Boolean := False) is
begin
if Instance.Parent /= null then
Disp_Instance_Name (Instance.Parent);
Put ('.');
end if;
Put (Get_Instance_Local_Name (Instance, Short));
end Disp_Instance_Name;
function Get_Instance_Name (Instance: Block_Instance_Acc) return String
is
function Parent_Name return String is
begin
if Instance.Parent /= null then
return Get_Instance_Name (Instance.Parent) & '.';
else
return "";
end if;
end Parent_Name;
begin
return Parent_Name & Get_Instance_Local_Name (Instance);
end Get_Instance_Name;
procedure Disp_Instances_Tree_Name (Inst : Block_Instance_Acc) is
begin
if Inst = null then
Put ("*null*");
New_Line;
return;
end if;
Put (Get_Instance_Local_Name (Inst));
Put (" ");
case Get_Kind (Inst.Label) is
when Iir_Kind_Block_Statement =>
Put ("[block]");
when Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement
| Iir_Kind_Generate_Statement_Body =>
Put ("[generate]");
when Iir_Kind_Iterator_Declaration =>
Put ("[iterator]");
when Iir_Kind_Component_Instantiation_Statement =>
Put ("[component]");
when Iir_Kinds_Process_Statement =>
Put ("[process]");
when Iir_Kind_Architecture_Body =>
Put ("[entity]");
when Iir_Kind_Package_Declaration =>
Put ("[package]");
when Iir_Kind_Configuration_Declaration =>
Put ("[configuration]");
when others =>
Error_Kind ("disp_instances_tree_name", Inst.Label);
end case;
New_Line;
end Disp_Instances_Tree_Name;
procedure Disp_Instances_Tree1 (Inst : Block_Instance_Acc; Pfx : String)
is
Child : Block_Instance_Acc;
begin
Child := Inst.Children;
if Child = null then
return;
end if;
loop
if Child.Brother /= null then
Put (Pfx & "+-");
Disp_Instances_Tree_Name (Child);
Disp_Instances_Tree1 (Child, Pfx & "| ");
Child := Child.Brother;
else
Put (Pfx & "`-");
Disp_Instances_Tree_Name (Child);
Disp_Instances_Tree1 (Child, Pfx & " ");
exit;
end if;
end loop;
end Disp_Instances_Tree1;
procedure Disp_Instances_Tree is
begin
for I in Global_Instances.Objects'Range loop
if Global_Instances.Objects (I) /= null then
Disp_Instances_Tree_Name (Global_Instances.Objects (I).Instance);
end if;
end loop;
Disp_Instances_Tree_Name (Top_Instance);
Disp_Instances_Tree1 (Top_Instance, "");
end Disp_Instances_Tree;
-- Disp a block instance, in a human readable way.
-- Used to debug.
procedure Disp_Block_Instance (Instance: Block_Instance_Acc) is
begin
Put_Line ("Objects:");
for I in Instance.Objects'Range loop
Put (Object_Slot_Type'Image (I) & ": ");
Disp_Value_Tab (Instance.Objects (I), 3);
New_Line;
end loop;
end Disp_Block_Instance;
procedure Disp_Signal (Value : Iir_Value_Literal_Acc; A_Type : Iir);
procedure Disp_Signal_Array (Value : Iir_Value_Literal_Acc;
A_Type : Iir;
Dim : Natural)
is
begin
if Dim = Get_Nbr_Elements (Get_Index_Subtype_List (A_Type)) then
Put ("(");
for I in Value.Val_Array.V'Range loop
if I /= 1 then
Put (", ");
end if;
Disp_Signal (Value.Val_Array.V (I), Get_Element_Subtype (A_Type));
end loop;
Put (")");
else
Put ("(");
Disp_Signal_Array (Value, A_Type, Dim + 1);
Put (")");
end if;
end Disp_Signal_Array;
procedure Disp_Signal_Record (Value : Iir_Value_Literal_Acc; A_Type : Iir)
is
List : constant Iir_Flist :=
Get_Elements_Declaration_List (Get_Base_Type (A_Type));
El : Iir_Element_Declaration;
begin
Put ("(");
for I in Value.Val_Record.V'Range loop
El := Get_Nth_Element (List, Natural (I - 1));
if I /= 1 then
Put (", ");
end if;
Put (Name_Table.Image (Get_Identifier (El)));
Put (" => ");
Disp_Signal (Value.Val_Record.V (I), Get_Type (El));
end loop;
Put (")");
end Disp_Signal_Record;
procedure Disp_Signal_Value
(Val : Value_Union; Mode : Mode_Type; Sig_Type : Iir) is
begin
case Mode is
when Mode_I64 =>
Put (Ghdl_I64'Image (Val.I64));
when Mode_I32 =>
Put (Ghdl_I32'Image (Val.I32));
when Mode_F64 =>
Put (Ghdl_F64'Image (Val.F64));
when Mode_E32 =>
Disp_Iir_Value_Enum (Ghdl_E32'Pos (Val.E32), Sig_Type);
when Mode_E8 =>
Disp_Iir_Value_Enum (Ghdl_E8'Pos (Val.E8), Sig_Type);
when Mode_B1 =>
Disp_Iir_Value_Enum (Ghdl_B1'Pos (Val.B1), Sig_Type);
end case;
end Disp_Signal_Value;
procedure Disp_Transaction
(Head : Transaction_Acc; Mode : Mode_Type; Sig_Type : Iir)
is
Trans : Transaction_Acc;
begin
Trans := Head;
loop
case Trans.Kind is
when Trans_Value =>
Disp_Signal_Value (Trans.Val, Mode, Sig_Type);
when Trans_Direct =>
Disp_Signal_Value (Trans.Val_Ptr.all, Mode, Sig_Type);
when Trans_Null =>
Put ("NULL");
when Trans_Error =>
Put ("ERROR");
end case;
if Trans.Kind = Trans_Direct then
Put ("[DIRECT]");
else
Put ("@");
Put_Time (stdout, Trans.Time);
end if;
Trans := Trans.Next;
exit when Trans = null;
Put (", ");
end loop;
end Disp_Transaction;
procedure Disp_Signal (Value : Iir_Value_Literal_Acc; A_Type : Iir) is
begin
if Value = null then
Put ("!NULL!");
return;
end if;
case Value.Kind is
when Iir_Value_Scalars
| Iir_Value_Access =>
Disp_Iir_Value (Value, A_Type);
when Iir_Value_Array =>
Disp_Signal_Array (Value, A_Type, 1);
when Iir_Value_Record =>
Disp_Signal_Record (Value, A_Type);
when Iir_Value_Range =>
-- FIXME.
raise Internal_Error;
when Iir_Value_Signal =>
declare
Sig : constant Ghdl_Signal_Ptr := Value.Sig;
begin
Disp_Signal_Value (Sig.Value_Ptr.all, Sig.Mode, A_Type);
Grt.Disp_Signals.Disp_Single_Signal_Attributes (Value.Sig);
New_Line;
if Sig.S.Mode_Sig in Mode_Signal_User then
for I in 1 .. Sig.S.Nbr_Drivers loop
Put (" ");
Disp_Transaction (Sig.S.Drivers (I - 1).First_Trans,
Sig.Mode, A_Type);
New_Line;
end loop;
end if;
end;
when Iir_Value_File
| Iir_Value_Protected
| Iir_Value_Quantity
| Iir_Value_Terminal
| Iir_Value_Instance =>
raise Internal_Error;
end case;
end Disp_Signal;
procedure Disp_Instance_Signal (Instance: Block_Instance_Acc; Decl : Iir)
is
Info : constant Sim_Info_Acc := Get_Info (Decl);
begin
Put (" ");
Put (Name_Table.Image (Get_Identifier (Decl)));
Put (" = ");
Disp_Signal (Instance.Objects (Info.Slot), Get_Type (Decl));
end Disp_Instance_Signal;
procedure Disp_Instance_Signals_Of_Chain (Instance: Block_Instance_Acc;
Chain : Iir)
is
El : Iir;
begin
El := Chain;
while El /= Null_Iir loop
case Get_Kind (El) is
when Iir_Kind_Signal_Declaration
| Iir_Kind_Interface_Signal_Declaration =>
Disp_Instance_Signal (Instance, El);
when others =>
null;
end case;
El := Get_Chain (El);
end loop;
end Disp_Instance_Signals_Of_Chain;
procedure Disp_Instance_Signals (Instance: Block_Instance_Acc)
is
Blk : constant Iir := Instance.Label;
Child: Block_Instance_Acc;
begin
case Get_Kind (Blk) is
when Iir_Kind_Architecture_Body =>
declare
Ent : constant Iir := Get_Entity (Blk);
begin
Disp_Instance_Name (Instance);
Put_Line (" [architecture]:");
Disp_Instance_Signals_Of_Chain
(Instance, Get_Port_Chain (Ent));
Disp_Instance_Signals_Of_Chain
(Instance, Get_Declaration_Chain (Ent));
Disp_Instance_Signals_Of_Chain
(Instance, Get_Declaration_Chain (Blk));
end;
when Iir_Kind_Block_Statement =>
Disp_Instance_Name (Instance);
Put_Line (" [block]:");
declare
Header : constant Iir := Get_Block_Header (Blk);
begin
if Header /= Null_Iir then
Disp_Instance_Signals_Of_Chain
(Instance, Get_Port_Chain (Header));
end if;
end;
Disp_Instance_Signals_Of_Chain
(Instance, Get_Declaration_Chain (Blk));
when Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement =>
Disp_Instance_Name (Instance);
Put_Line (" [generate]:");
when Iir_Kind_Generate_Statement_Body =>
Disp_Instance_Signals_Of_Chain
(Instance, Get_Declaration_Chain (Blk));
when Iir_Kind_Component_Instantiation_Statement =>
Disp_Instance_Name (Instance);
Put_Line (" [component]:");
Disp_Instance_Signals_Of_Chain
(Instance, Get_Port_Chain (Instance.Stmt));
when Iir_Kinds_Process_Statement =>
null;
when Iir_Kind_Iterator_Declaration =>
null;
when others =>
Error_Kind ("disp_instance_signals", Instance.Label);
end case;
Child := Instance.Children;
while Child /= null loop
Disp_Instance_Signals (Child);
Child := Child.Brother;
end loop;
end Disp_Instance_Signals;
-- Disp all signals name and values.
procedure Disp_Signals_Value is
begin
if Disp_Time_Before_Values then
Grt.Disp.Disp_Now;
end if;
Disp_Instance_Signals (Top_Instance);
end Disp_Signals_Value;
procedure Disp_Label (Process : Iir)
is
Label : Name_Id;
begin
Label := Get_Label (Process);
if Label = Null_Identifier then
Put ("<unlabeled>");
else
Put (Name_Table.Image (Label));
end if;
end Disp_Label;
procedure Disp_Declaration_Object
(Instance : Block_Instance_Acc; Decl : Iir) 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 =>
Put (Disp_Node (Decl));
Put (" = ");
Disp_Value_Tab (Instance.Objects (Get_Info (Decl).Slot), 3);
when Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Signal_Declaration =>
declare
Sig : Iir_Value_Literal_Acc;
begin
Sig := Instance.Objects (Get_Info (Decl).Slot);
Put (Disp_Node (Decl));
Put (" = ");
Disp_Signal (Sig, Get_Type (Decl));
New_Line;
end;
when Iir_Kinds_Signal_Attribute =>
-- FIXME: todo ?
null;
when Iir_Kind_Type_Declaration
| Iir_Kind_Anonymous_Type_Declaration
| Iir_Kind_Subtype_Declaration =>
-- FIXME: disp ranges
null;
when others =>
Error_Kind ("disp_declaration_object", Decl);
end case;
end Disp_Declaration_Object;
procedure Disp_Declaration_Objects
(Instance : Block_Instance_Acc; Decl_Chain : Iir)
is
El : Iir;
begin
El := Decl_Chain;
while El /= Null_Iir loop
Disp_Declaration_Object (Instance, El);
El := Get_Chain (El);
end loop;
end Disp_Declaration_Objects;
procedure Disp_Objects (Instance : Block_Instance_Acc)
is
Decl : constant Iir := Instance.Label;
begin
Disp_Instance_Name (Instance);
New_Line;
case Get_Kind (Decl) is
when Iir_Kind_Procedure_Declaration
| Iir_Kind_Function_Declaration =>
Disp_Declaration_Objects
(Instance, Get_Interface_Declaration_Chain (Decl));
Disp_Declaration_Objects
(Instance,
Get_Declaration_Chain (Get_Subprogram_Body (Decl)));
when Iir_Kind_Architecture_Body =>
declare
Entity : constant Iir_Entity_Declaration := Get_Entity (Decl);
begin
Disp_Declaration_Objects
(Instance, Get_Generic_Chain (Entity));
Disp_Declaration_Objects
(Instance, Get_Port_Chain (Entity));
Disp_Declaration_Objects
(Instance, Get_Declaration_Chain (Entity));
Disp_Declaration_Objects
(Instance, Get_Declaration_Chain (Decl));
-- FIXME: processes.
end;
when Iir_Kind_Component_Instantiation_Statement =>
null;
when others =>
Error_Kind ("disp_objects", Decl);
end case;
end Disp_Objects;
pragma Unreferenced (Disp_Objects);
procedure Disp_Process_Stats
is
Proc : Iir;
Stmt : Iir;
Nbr_User_Sensitized_Processes : Natural := 0;
Nbr_User_If_Sensitized_Processes : Natural := 0;
Nbr_Conc_Sensitized_Processes : Natural := 0;
Nbr_User_Non_Sensitized_Processes : Natural := 0;
Nbr_Conc_Non_Sensitized_Processes : Natural := 0;
begin
for I in Processes_Table.First .. Processes_Table.Last loop
Proc := Processes_Table.Table (I).Label;
case Get_Kind (Proc) is
when Iir_Kind_Sensitized_Process_Statement =>
if Get_Process_Origin (Proc) = Null_Iir then
Stmt := Get_Sequential_Statement_Chain (Proc);
if Stmt /= Null_Iir
and then Get_Kind (Stmt) = Iir_Kind_If_Statement
and then Get_Chain (Stmt) = Null_Iir
then
Nbr_User_If_Sensitized_Processes :=
Nbr_User_If_Sensitized_Processes + 1;
else
Nbr_User_Sensitized_Processes :=
Nbr_User_Sensitized_Processes + 1;
end if;
else
Nbr_Conc_Sensitized_Processes :=
Nbr_Conc_Sensitized_Processes + 1;
end if;
when Iir_Kind_Process_Statement =>
if Get_Process_Origin (Proc) = Null_Iir then
Nbr_User_Non_Sensitized_Processes :=
Nbr_User_Non_Sensitized_Processes + 1;
else
Nbr_Conc_Non_Sensitized_Processes :=
Nbr_Conc_Non_Sensitized_Processes + 1;
end if;
when others =>
raise Internal_Error;
end case;
end loop;
Put (Natural'Image (Nbr_User_If_Sensitized_Processes));
Put_Line (" user sensitized processes with only a if stmt");
Put (Natural'Image (Nbr_User_Sensitized_Processes));
Put_Line (" user sensitized processes (others)");
Put (Natural'Image (Nbr_User_Non_Sensitized_Processes));
Put_Line (" user non sensitized processes");
Put (Natural'Image (Nbr_Conc_Sensitized_Processes));
Put_Line (" sensitized concurrent statements");
Put (Natural'Image (Nbr_Conc_Non_Sensitized_Processes));
Put_Line (" non sensitized concurrent statements");
Put (Process_Index_Type'Image (Processes_Table.Last));
Put_Line (" processes (total)");
end Disp_Process_Stats;
procedure Disp_Signals_Stats
is
type Counters_Type is array (Mode_Signal_Type) of Natural;
Counters : Counters_Type := (others => 0);
Nbr_User_Signals : Natural := 0;
Nbr_Signal_Elements : Natural := 0;
begin
for I in Signals_Table.First .. Signals_Table.Last loop
declare
Ent : Signal_Entry renames Signals_Table.Table (I);
begin
if Ent.Kind in Mode_Signal_User then
Nbr_User_Signals := Nbr_User_Signals + 1;
Nbr_Signal_Elements := Nbr_Signal_Elements +
Get_Nbr_Of_Scalars (Signals_Table.Table (I).Sig);
end if;
Counters (Ent.Kind) := Counters (Ent.Kind) + 1;
end;
end loop;
Put (Integer'Image (Nbr_User_Signals));
Put_Line (" declared user signals or ports");
Put (Integer'Image (Nbr_Signal_Elements));
Put_Line (" user signals sub-elements");
Put (Integer'Image (Counters (Mode_Quiet)));
Put_Line (" 'quiet implicit signals");
Put (Integer'Image (Counters (Mode_Stable)));
Put_Line (" 'stable implicit signals");
Put (Integer'Image (Counters (Mode_Delayed)));
Put_Line (" 'delayed implicit signals");
Put (Integer'Image (Counters (Mode_Transaction)));
Put_Line (" 'transaction implicit signals");
Put (Integer'Image (Counters (Mode_Guard)));
Put_Line (" guard signals");
end Disp_Signals_Stats;
procedure Disp_Design_Stats is
begin
Disp_Process_Stats;
New_Line;
Disp_Signals_Stats;
New_Line;
Put (Integer'Image (Connect_Table.Last));
Put_Line (" connections");
end Disp_Design_Stats;
procedure Disp_Design_Non_Sensitized
is
Instance : Block_Instance_Acc;
Proc : Iir;
begin
for I in Processes_Table.First .. Processes_Table.Last loop
Instance := Processes_Table.Table (I);
Proc := Processes_Table.Table (I).Label;
if Get_Kind (Proc) = Iir_Kind_Process_Statement then
Disp_Instance_Name (Instance);
New_Line;
Put_Line (" at " & Disp_Location (Proc));
end if;
end loop;
end Disp_Design_Non_Sensitized;
procedure Disp_Design_Connections is
begin
for I in Connect_Table.First .. Connect_Table.Last loop
declare
Conn : Connect_Entry renames Connect_Table.Table (I);
begin
Disp_Iir_Location (Conn.Assoc);
New_Line;
end;
end loop;
end Disp_Design_Connections;
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 =>
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 =>
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 =>
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 Is_Blank (C : Character) return Boolean is
begin
return C = ' ' or else C = ASCII.HT;
end Is_Blank;
function Skip_Blanks (S : String) return Positive
is
P : Positive := S'First;
begin
while P <= S'Last and then Is_Blank (S (P)) loop
P := P + 1;
end loop;
return P;
end Skip_Blanks;
-- Return the position of the last character of the word (the last
-- non-blank character).
function Get_Word (S : String) return Positive
is
P : Positive := S'First;
begin
while P <= S'Last and then not Is_Blank (S (P)) loop
P := P + 1;
end loop;
return P - 1;
end Get_Word;
procedure Disp_A_Frame (Instance: Block_Instance_Acc) is
begin
if Instance = Global_Instances then
pragma Assert (Instance.Label = Null_Iir);
Put_Line ("global instances");
return;
end if;
Put (Disp_Node (Instance.Label));
if Instance.Stmt /= Null_Iir then
Put (" at ");
Put (Files_Map.Image (Get_Location (Instance.Stmt)));
end if;
New_Line;
end Disp_A_Frame;
procedure Debug_Bt (Instance : Block_Instance_Acc)
is
Inst : Block_Instance_Acc;
begin
Inst := Instance;
while Inst /= null loop
Disp_A_Frame (Inst);
Inst := Inst.Parent;
end loop;
end Debug_Bt;
pragma Unreferenced (Debug_Bt);
procedure Debug_Upblock (Instance : Block_Instance_Acc)
is
Inst : Block_Instance_Acc;
begin
Inst := Instance;
while Inst /= null loop
Disp_A_Frame (Inst);
Inst := Inst.Up_Block;
end loop;
end Debug_Upblock;
pragma Unreferenced (Debug_Upblock);
procedure Disp_Current_Lines
is
use Files_Map;
-- Number of lines to display before and after the current line.
Radius : constant := 5;
Buf : File_Buffer_Acc;
Pos : Source_Ptr;
Line : Natural;
Len : Source_Ptr;
C : Character;
begin
if List_Current_Line > Radius then
Line := List_Current_Line - Radius;
else
Line := 1;
end if;
Pos := File_Line_To_Position (List_Current_File, Line);
Buf := Get_File_Source (List_Current_File);
while Line < List_Current_Line + Radius loop
-- Compute line length.
Len := 0;
loop
C := Buf (Pos + Len);
exit when C = ASCII.CR or C = ASCII.LF or C = ASCII.EOT;
Len := Len + 1;
end loop;
-- Disp line number.
declare
Str : constant String := Natural'Image (Line);
begin
if Line = List_Current_Line then
Put ('*');
else
Put (' ');
end if;
Put ((Str'Length .. 5 => ' '));
Put (Str (Str'First + 1 .. Str'Last));
Put (' ');
end;
-- Disp line.
Put_Line (String (Buf (Pos .. Pos + Len - 1)));
-- Skip EOL.
exit when C = ASCII.EOT;
Pos := Pos + Len + 1;
if C = ASCII.CR then
if Buf (Pos) = ASCII.LF then
Pos := Pos + 1;
end if;
else
pragma Assert (C = ASCII.LF);
if Buf (Pos) = ASCII.CR then
Pos := Pos + 1;
end if;
end if;
Line := Line + 1;
end loop;
end Disp_Current_Lines;
procedure Disp_Source_Line (Loc : Location_Type)
is
use Files_Map;
File : Source_File_Entry;
Line_Pos : Source_Ptr;
Line : Natural;
Offset : Natural;
Buf : File_Buffer_Acc;
Next_Line_Pos : Source_Ptr;
begin
Location_To_Coord (Loc, File, Line_Pos, Line, Offset);
Buf := Get_File_Source (File);
Next_Line_Pos := File_Line_To_Position (File, Line + 1);
Put (String (Buf (Line_Pos .. Next_Line_Pos - 1)));
end Disp_Source_Line;
type Menu_Kind is (Menu_Command, Menu_Submenu);
type Menu_Entry (Kind : Menu_Kind);
type Menu_Entry_Acc is access all Menu_Entry;
type Cst_String_Acc is access constant String;
type Menu_Entry (Kind : Menu_Kind) is record
Name : Cst_String_Acc;
Next : Menu_Entry_Acc;
case Kind is
when Menu_Command =>
Proc : Menu_Procedure;
when Menu_Submenu =>
First, Last : Menu_Entry_Acc := null;
end case;
end record;
-- Check there is a current process.
procedure Check_Current_Process is
begin
if Current_Process = null then
Put_Line ("no current process");
raise Command_Error;
end if;
end Check_Current_Process;
-- The status of the debugger. This status can be modified by a command
-- as a side effect to resume or quit the debugger.
type Command_Status_Type is (Status_Default, Status_Quit);
Command_Status : Command_Status_Type;
procedure Help_Proc (Line : String);
procedure Disp_Process_Loc (Proc : Process_State_Type) is
begin
Disp_Instance_Name (Proc.Top_Instance);
Put (" (" & Files_Map.Image (Get_Location (Proc.Proc)) & ")");
New_Line;
end Disp_Process_Loc;
-- Disp the list of processes (and its state)
procedure Ps_Proc (Line : String) is
pragma Unreferenced (Line);
Process : Iir;
begin
if Processes_State = null then
Put_Line ("no processes");
return;
end if;
for I in Processes_State'Range loop
Put (Process_Index_Type'Image (I) & ": ");
Process := Processes_State (I).Proc;
if Process /= Null_Iir then
Disp_Process_Loc (Processes_State (I));
Disp_A_Frame (Processes_State (I).Instance);
else
Put_Line ("not yet elaborated");
end if;
end loop;
end Ps_Proc;
procedure List_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
Disp_Current_Lines;
end List_Proc;
procedure Up_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
Check_Current_Process;
if Dbg_Cur_Frame.Parent = null then
Put_Line ("top of frames reached");
else
Set_Cur_Frame (Dbg_Cur_Frame.Parent);
end if;
end Up_Proc;
procedure Down_Proc (Line : String)
is
pragma Unreferenced (Line);
Inst : Block_Instance_Acc;
begin
Check_Current_Process;
if Dbg_Cur_Frame = Dbg_Top_Frame then
Put_Line ("bottom of frames reached");
else
Inst := Dbg_Top_Frame;
while Inst.Parent /= Dbg_Cur_Frame loop
Inst := Inst.Parent;
end loop;
Set_Cur_Frame (Inst);
end if;
end Down_Proc;
procedure Set_Breakpoint (Stmt : Iir) is
begin
Put_Line ("set breakpoint at: " & Files_Map.Image (Get_Location (Stmt)));
Breakpoints.Append (Breakpoint_Entry'(Stmt => Stmt));
Flag_Need_Debug := True;
end Set_Breakpoint;
function Is_Within_Statement (Stmt : Iir; Cur : Iir) return Boolean
is
Parent : Iir;
begin
Parent := Cur;
loop
if Parent = Stmt then
return True;
end if;
case Get_Kind (Parent) is
when Iir_Kinds_Sequential_Statement =>
Parent := Get_Parent (Parent);
when others =>
return False;
end case;
end loop;
end Is_Within_Statement;
-- Next statement in the same frame, but handle compound statements as
-- one statement.
procedure Next_Stmt_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
Exec_State := Exec_Next_Stmt;
Exec_Instance := Dbg_Top_Frame;
Exec_Statement := Dbg_Top_Frame.Stmt;
Flag_Need_Debug := True;
Command_Status := Status_Quit;
end Next_Stmt_Proc;
-- Finish parent statement.
procedure Finish_Stmt_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
Exec_State := Exec_Next_Stmt;
Exec_Instance := Dbg_Top_Frame;
Exec_Statement := Get_Parent (Dbg_Top_Frame.Stmt);
Flag_Need_Debug := True;
Command_Status := Status_Quit;
end Finish_Stmt_Proc;
procedure Next_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
Exec_State := Exec_Next;
Exec_Instance := Dbg_Top_Frame;
Flag_Need_Debug := True;
Command_Status := Status_Quit;
Cmd_Repeat := Next_Proc'Access;
end Next_Proc;
procedure Step_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
Exec_State := Exec_Single_Step;
Flag_Need_Debug := True;
Command_Status := Status_Quit;
Cmd_Repeat := Step_Proc'Access;
end Step_Proc;
Break_Id : Name_Id;
function Cb_Set_Break (El : Iir) return Walk_Status is
begin
case Get_Kind (El) is
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
if Get_Identifier (El) = Break_Id
and then
Get_Implicit_Definition (El) not in Iir_Predefined_Implicit
then
Set_Breakpoint
(Get_Sequential_Statement_Chain (Get_Subprogram_Body (El)));
end if;
when others =>
null;
end case;
return Walk_Continue;
end Cb_Set_Break;
procedure Break_Proc (Line : String)
is
Status : Walk_Status;
P : Natural;
begin
P := Skip_Blanks (Line);
if Line (P) = '"' then
-- An operator name.
declare
use Str_Table;
Str : String8_Id;
Len : Nat32;
begin
Str := Create_String8;
Len := 0;
P := P + 1;
while Line (P) /= '"' loop
Append_String8_Char (Line (P));
Len := Len + 1;
P := P + 1;
end loop;
Break_Id := Parse.Str_To_Operator_Name (Str, Len, No_Location);
-- FIXME: free string.
-- FIXME: catch error.
end;
else
Break_Id := Name_Table.Get_Identifier (Line (P .. Line'Last));
end if;
Status := Walk_Declarations (Cb_Set_Break'Access);
pragma Assert (Status = Walk_Continue);
end Break_Proc;
procedure Where_Proc (Line : String) is
pragma Unreferenced (Line);
Frame : Block_Instance_Acc;
begin
Check_Current_Process;
Frame := Dbg_Top_Frame;
while Frame /= null loop
if Frame = Dbg_Cur_Frame then
Put ("* ");
else
Put (" ");
end if;
Disp_A_Frame (Frame);
Frame := Frame.Parent;
end loop;
end Where_Proc;
procedure Info_Tree_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
if Top_Instance = null then
Put_Line ("design not yet fully elaborated");
else
Disp_Instances_Tree;
end if;
end Info_Tree_Proc;
procedure Info_Instances_Proc (Line : String)
is
pragma Unreferenced (Line);
procedure Disp_Instances (Inst : Block_Instance_Acc)
is
Child : Block_Instance_Acc;
begin
case Get_Kind (Inst.Label) is
when Iir_Kind_Architecture_Body =>
Disp_Instances_Tree_Name (Inst);
when others =>
null;
end case;
Child := Inst.Children;
while Child /= null loop
if Get_Kind (Child.Label) not in Iir_Kinds_Process_Statement then
Disp_Instances (Child);
end if;
Child := Child.Brother;
end loop;
end Disp_Instances;
begin
if Top_Instance = null then
Put_Line ("design not yet fully elaborated");
return;
end if;
for I in Global_Instances.Objects'Range loop
if Global_Instances.Objects (I) /= null then
Put (Get_Instance_Local_Name
(Global_Instances.Objects (I).Instance));
Put_Line (" [package]");
end if;
end loop;
Disp_Instances (Top_Instance);
end Info_Instances_Proc;
procedure Info_Params_Proc (Line : String)
is
pragma Unreferenced (Line);
Decl : Iir;
Params : Iir;
begin
Check_Current_Process;
if Dbg_Cur_Frame = null then
Put_Line ("not in a subprogram");
return;
end if;
Decl := Dbg_Cur_Frame.Label;
if Decl = Null_Iir
or else Get_Kind (Decl) not in Iir_Kinds_Subprogram_Declaration
then
Put_Line ("current frame is not a subprogram");
return;
end if;
Params := Get_Interface_Declaration_Chain (Decl);
Disp_Declaration_Objects (Dbg_Cur_Frame, Params);
end Info_Params_Proc;
procedure Info_Proc_Proc (Line : String) is
pragma Unreferenced (Line);
begin
Check_Current_Process;
Disp_Process_Loc (Current_Process.all);
end Info_Proc_Proc;
function Cb_Disp_Subprograms (El : Iir) return Walk_Status is
begin
case Get_Kind (El) is
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
Put_Line (Name_Table.Image (Get_Identifier (El)));
when others =>
null;
end case;
return Walk_Continue;
end Cb_Disp_Subprograms;
procedure Info_Subprograms_Proc (Line : String) is
pragma Unreferenced (Line);
Status : Walk_Status;
begin
Status := Walk_Declarations (Cb_Disp_Subprograms'Access);
pragma Assert (Status = Walk_Continue);
end Info_Subprograms_Proc;
function Cb_Disp_Units (El : Iir) return Walk_Status is
begin
case Get_Kind (El) is
when Iir_Kind_Package_Declaration =>
Put ("package ");
Put_Line (Name_Table.Image (Get_Identifier (El)));
when Iir_Kind_Entity_Declaration =>
Put ("entity ");
Put_Line (Name_Table.Image (Get_Identifier (El)));
when Iir_Kind_Architecture_Body =>
Put ("architecture ");
Put (Name_Table.Image (Get_Identifier (El)));
Put (" of ");
Put_Line (Name_Table.Image (Get_Identifier
(Get_Entity_Name (El))));
when Iir_Kind_Configuration_Declaration =>
Put ("configuration ");
Put_Line (Name_Table.Image (Get_Identifier (El)));
when Iir_Kind_Package_Body =>
null;
when others =>
Error_Kind ("cb_disp_units", El);
end case;
return Walk_Continue;
end Cb_Disp_Units;
procedure Info_Units_Proc (Line : String) is
pragma Unreferenced (Line);
Status : Walk_Status;
begin
Status := Walk_Units (Cb_Disp_Units'Access);
pragma Assert (Status = Walk_Continue);
end Info_Units_Proc;
function Cb_Disp_File (El : Iir) return Walk_Status is
begin
Put_Line (Name_Table.Image (Get_Design_File_Filename (El)));
return Walk_Continue;
end Cb_Disp_File;
procedure Info_PSL_Proc (Line : String)
is
pragma Unreferenced (Line);
begin
if PSL_Table.Last < PSL_Table.First then
Put_Line ("no PSL directive");
return;
end if;
for I in PSL_Table.First .. PSL_Table.Last loop
declare
E : PSL_Entry renames PSL_Table.Table (I);
begin
Disp_Instance_Name (E.Instance);
Put ('.');
Put (Name_Table.Image (Get_Identifier (E.Stmt)));
New_Line;
Disp_Vhdl.Disp_PSL_NFA (Get_PSL_NFA (E.Stmt));
Put (" 01234567890123456789012345678901234567890123456789");
for I in E.States'Range loop
if I mod 50 = 0 then
New_Line;
Put (Int32'Image (I / 10));
Put (": ");
end if;
if E.States (I) then
Put ('*');
else
Put ('.');
end if;
end loop;
New_Line;
end;
end loop;
end Info_PSL_Proc;
procedure Info_Stats_Proc (Line : String) is
P : Natural := Line'First;
E : Natural;
begin
P := Skip_Blanks (Line (P .. Line'Last));
if P > Line'Last then
-- No parameters.
Disp_Design_Stats;
return;
end if;
E := Get_Word (Line (P .. Line'Last));
if Line (P .. E) = "global" then
Disp_Design_Stats;
elsif Line (P .. E) = "non-sensitized" then
Disp_Design_Non_Sensitized;
null;
elsif Line (P .. E) = "connections" then
Disp_Design_Connections;
-- TODO: nbr of conversions
else
Put_Line ("options are: global, non-sensitized, connections");
-- TODO: signals: nbr of scalars, nbr of non-user...
end if;
end Info_Stats_Proc;
procedure Info_Files_Proc (Line : String)
is
pragma Unreferenced (Line);
Status : Walk_Status;
begin
Status := Walk_Files (Cb_Disp_File'Access);
pragma Assert (Status = Walk_Continue);
end Info_Files_Proc;
procedure Info_Libraries_Proc (Line : String) is
pragma Unreferenced (Line);
Lib : Iir_Library_Declaration := Libraries.Get_Libraries_Chain;
begin
while Lib /= Null_Iir loop
Put_Line (Name_Table.Image (Get_Identifier (Lib)));
Lib := Get_Chain (Lib);
end loop;
end Info_Libraries_Proc;
procedure Disp_Declared_Signals_Chain
(Chain : Iir; Instance : Block_Instance_Acc)
is
pragma Unreferenced (Instance);
Decl : Iir;
begin
Decl := Chain;
while Decl /= Null_Iir loop
case Get_Kind (Decl) is
when Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Signal_Declaration =>
Put_Line (" " & Name_Table.Image (Get_Identifier (Decl)));
when others =>
null;
end case;
Decl := Get_Chain (Decl);
end loop;
end Disp_Declared_Signals_Chain;
procedure Disp_Declared_Signals (Decl : Iir; Instance : Block_Instance_Acc)
is
begin
case Get_Kind (Decl) is
when Iir_Kind_Sensitized_Process_Statement
| Iir_Kind_Process_Statement =>
Disp_Declared_Signals (Get_Parent (Decl), Instance);
when Iir_Kind_Architecture_Body =>
Disp_Declared_Signals (Get_Entity (Decl), Instance);
when Iir_Kind_Entity_Declaration =>
null;
when others =>
Error_Kind ("disp_declared_signals", Decl);
end case;
case Get_Kind (Decl) is
when Iir_Kind_Sensitized_Process_Statement
| Iir_Kind_Process_Statement =>
-- No signal declaration in a process (FIXME: implicit signals)
null;
when Iir_Kind_Architecture_Body =>
Put_Line ("Signals of architecture "
& Name_Table.Image (Get_Identifier (Decl)) & ':');
Disp_Declared_Signals_Chain
(Get_Declaration_Chain (Decl), Instance);
when Iir_Kind_Entity_Declaration =>
Put_Line ("Ports of entity "
& Name_Table.Image (Get_Identifier (Decl)) & ':');
Disp_Declared_Signals_Chain
(Get_Port_Chain (Decl), Instance);
when others =>
Error_Kind ("disp_declared_signals (2)", Decl);
end case;
end Disp_Declared_Signals;
procedure Info_Signals_Proc (Line : String)
is
Verbose : Boolean;
P : Natural;
E : Natural;
begin
Verbose := False;
P := Skip_Blanks (Line);
loop
E := Get_Word (Line (P .. Line'Last));
exit when P > Line'Last;
if Line (P .. E) = "-v" then
Verbose := True;
elsif Line (P .. E) = "-l" then
-- Local signals
Check_Current_Process;
Disp_Declared_Signals
(Current_Process.Proc, Current_Process.Top_Instance);
return;
elsif Line (P .. E) = "-t" then
Disp_Signals_Value;
return;
elsif Line (P .. E) = "-T" then
Grt.Disp_Signals.Disp_Signals_Table;
return;
else
Put_Line ("options: -v(erbose) -l(ocal) -t(ree) -T(able)");
return;
end if;
P := E + 1;
end loop;
for I in Signals_Table.First .. Signals_Table.Last loop
declare
S : Signal_Entry renames Signals_Table.Table (I);
begin
Disp_Instance_Name (S.Instance, False);
Put ('.');
if S.Kind in Grt.Types.Mode_Signal_User then
Put (Name_Table.Image (Get_Identifier (S.Decl)));
New_Line;
Put (" sig: ");
Disp_Value (S.Sig);
Put (" val: ");
Disp_Value (S.Val);
if Verbose then
-- Dummy to keep compiler happy.
Verbose := False;
end if;
else
Disp_Declaration_Object (S.Instance, S.Decl);
end if;
end;
end loop;
end Info_Signals_Proc;
type Handle_Scope_Type is access procedure (N : Iir);
procedure Foreach_Scopes (N : Iir; Handler : Handle_Scope_Type) is
begin
case Get_Kind (N) is
when Iir_Kind_Process_Statement
| Iir_Kind_Sensitized_Process_Statement =>
Foreach_Scopes (Get_Parent (N), Handler);
Handler.all (N);
when Iir_Kind_Architecture_Body =>
Foreach_Scopes (Get_Entity (N), Handler);
Handler.all (N);
when Iir_Kind_Entity_Declaration =>
-- Top of scopes.
Handler.all (N);
when Iir_Kind_Function_Body
| Iir_Kind_Procedure_Body =>
Foreach_Scopes (Get_Parent (N), Handler);
Handler.all (N);
when Iir_Kind_Package_Body =>
Handler.all (N);
when Iir_Kind_Variable_Assignment_Statement
| Iir_Kind_Simple_Signal_Assignment_Statement
| Iir_Kind_Null_Statement
| Iir_Kind_Assertion_Statement
| Iir_Kind_Report_Statement
| Iir_Kind_Wait_Statement
| Iir_Kind_Return_Statement
| Iir_Kind_Next_Statement
| Iir_Kind_Exit_Statement
| Iir_Kind_Procedure_Call_Statement
| Iir_Kind_If_Statement
| Iir_Kind_While_Loop_Statement
| Iir_Kind_Case_Statement =>
Foreach_Scopes (Get_Parent (N), Handler);
when Iir_Kind_For_Loop_Statement
| Iir_Kind_Block_Statement
| Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement
| Iir_Kind_Generate_Statement_Body =>
Foreach_Scopes (Get_Parent (N), Handler);
Handler.all (N);
when others =>
Error_Kind ("foreach_scopes", N);
end case;
end Foreach_Scopes;
procedure Add_Decls_For (N : Iir)
is
use Sem_Scopes;
begin
case Get_Kind (N) is
when Iir_Kind_Entity_Declaration =>
declare
Unit : constant Iir := Get_Design_Unit (N);
begin
Add_Context_Clauses (Unit);
-- Add_Name (Unit, Get_Identifier (N), False);
Add_Entity_Declarations (N);
end;
when Iir_Kind_Architecture_Body =>
Open_Declarative_Region;
Add_Context_Clauses (Get_Design_Unit (N));
Add_Declarations (Get_Declaration_Chain (N), False);
Add_Declarations_Of_Concurrent_Statement (N);
when Iir_Kind_Package_Body =>
declare
Package_Decl : constant Iir := Get_Package (N);
Package_Unit : constant Iir := Get_Design_Unit (Package_Decl);
begin
Add_Name (Package_Unit);
Add_Context_Clauses (Package_Unit);
Open_Declarative_Region;
Add_Declarations (Get_Declaration_Chain (Package_Decl), False);
Add_Declarations (Get_Declaration_Chain (N), False);
end;
when Iir_Kind_Procedure_Body
| Iir_Kind_Function_Body =>
declare
Spec : constant Iir := Get_Subprogram_Specification (N);
begin
Open_Declarative_Region;
Add_Declarations
(Get_Interface_Declaration_Chain (Spec), False);
Add_Declarations
(Get_Declaration_Chain (N), False);
end;
when Iir_Kind_Process_Statement
| Iir_Kind_Sensitized_Process_Statement =>
Open_Declarative_Region;
Add_Declarations (Get_Declaration_Chain (N), False);
when Iir_Kind_For_Loop_Statement
| Iir_Kind_For_Generate_Statement =>
Open_Declarative_Region;
Add_Name (Get_Parameter_Specification (N));
when Iir_Kind_Block_Statement =>
declare
Header : constant Iir := Get_Block_Header (N);
begin
Open_Declarative_Region;
if Header /= Null_Iir then
Add_Declarations (Get_Generic_Chain (Header), False);
Add_Declarations (Get_Port_Chain (Header), False);
end if;
Add_Declarations (Get_Declaration_Chain (N), False);
Add_Declarations_Of_Concurrent_Statement (N);
end;
when Iir_Kind_Generate_Statement_Body =>
Open_Declarative_Region;
Add_Declarations (Get_Declaration_Chain (N), False);
Add_Declarations_Of_Concurrent_Statement (N);
when others =>
Error_Kind ("enter_scope(2)", N);
end case;
end Add_Decls_For;
procedure Enter_Scope (Node : Iir)
is
use Sem_Scopes;
begin
Push_Interpretations;
Open_Declarative_Region;
-- Add STD
Add_Name (Libraries.Std_Library, Std_Names.Name_Std, False);
Use_All_Names (Std_Package.Standard_Package);
Foreach_Scopes (Node, Add_Decls_For'Access);
end Enter_Scope;
procedure Del_Decls_For (N : Iir)
is
use Sem_Scopes;
begin
case Get_Kind (N) is
when Iir_Kind_Entity_Declaration =>
null;
when Iir_Kind_Architecture_Body =>
Close_Declarative_Region;
when Iir_Kind_Process_Statement
| Iir_Kind_Sensitized_Process_Statement
| Iir_Kind_Package_Body
| Iir_Kind_Procedure_Body
| Iir_Kind_Function_Body
| Iir_Kind_For_Loop_Statement
| Iir_Kind_Block_Statement
| Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement
| Iir_Kind_Generate_Statement_Body =>
Close_Declarative_Region;
when others =>
Error_Kind ("Decl_Decls_For", N);
end case;
end Del_Decls_For;
procedure Leave_Scope (Node : Iir)
is
use Sem_Scopes;
begin
Foreach_Scopes (Node, Del_Decls_For'Access);
Close_Declarative_Region;
Pop_Interpretations;
end Leave_Scope;
Buffer_Index : Natural := 1;
procedure Print_Proc (Line : String)
is
use Tokens;
Index_Str : String := Natural'Image (Buffer_Index);
File : Source_File_Entry;
Expr : Iir;
Res : Iir_Value_Literal_Acc;
P : Natural;
Opt_Value : Boolean := False;
Opt_Name : Boolean := False;
Marker : Mark_Type;
begin
-- Decode options: /v
P := Line'First;
loop
P := Skip_Blanks (Line (P .. Line'Last));
if P + 2 < Line'Last and then Line (P .. P + 1) = "/v" then
Opt_Value := True;
P := P + 2;
elsif P + 2 < Line'Last and then Line (P .. P + 1) = "/n" then
Opt_Name := True;
P := P + 2;
else
exit;
end if;
end loop;
Buffer_Index := Buffer_Index + 1;
Index_Str (Index_Str'First) := '*';
File := Files_Map.Create_Source_File_From_String
(Name_Table.Get_Identifier ("*debug" & Index_Str & '*'),
Line (P .. Line'Last));
Vhdl.Scanner.Set_File (File);
Vhdl.Scanner.Scan;
Expr := Parse.Parse_Expression;
if Vhdl.Scanner.Current_Token /= Tok_Eof then
Put_Line ("garbage at end of expression ignored");
end if;
Vhdl.Scanner.Close_File;
if Nbr_Errors /= 0 then
Put_Line ("error while parsing expression, evaluation aborted");
Nbr_Errors := 0;
return;
end if;
Enter_Scope (Dbg_Cur_Frame.Stmt);
Expr := Sem_Expr.Sem_Expression_Universal (Expr);
Leave_Scope (Dbg_Cur_Frame.Stmt);
if Expr = Null_Iir
or else Nbr_Errors /= 0
then
Put_Line ("error while analyzing expression, evaluation aborted");
Nbr_Errors := 0;
return;
end if;
Disp_Vhdl.Disp_Expression (Expr);
New_Line;
Annotate_Expand_Table;
Canon.Canon_Expression (Expr);
Mark (Marker, Expr_Pool);
if Opt_Name then
case Get_Kind (Expr) is
when Iir_Kind_Simple_Name =>
null;
when others =>
Put_Line ("expression is not a name");
Opt_Name := False;
end case;
end if;
if Opt_Name then
Res := Execute_Name (Dbg_Cur_Frame, Expr, True);
else
Res := Execute_Expression (Dbg_Cur_Frame, Expr);
end if;
if Opt_Value then
Disp_Value (Res);
else
Disp_Iir_Value (Res, Get_Type (Expr));
end if;
New_Line;
-- Free value
Release (Marker, Expr_Pool);
end Print_Proc;
procedure Quit_Proc (Line : String) is
pragma Unreferenced (Line);
begin
Command_Status := Status_Quit;
raise Debugger_Quit;
end Quit_Proc;
procedure Prepare_Continue is
begin
Command_Status := Status_Quit;
-- Set Flag_Need_Debug only if there is at least one enabled breakpoint.
Flag_Need_Debug := False;
for I in Breakpoints.First .. Breakpoints.Last loop
Flag_Need_Debug := True;
exit;
end loop;
end Prepare_Continue;
procedure Run_Proc (Line : String)
is
Delta_Time : Std_Time;
P : Positive;
begin
P := Skip_Blanks (Line);
if P <= Line'Last then
Delta_Time := Grt.Options.Parse_Time (Line (P .. Line'Last));
if Delta_Time = -1 then
return;
end if;
Break_Time := Grt.Processes.Next_Time + Delta_Time;
end if;
Prepare_Continue;
end Run_Proc;
procedure Cont_Proc (Line : String) is
pragma Unreferenced (Line);
begin
Prepare_Continue;
end Cont_Proc;
Menu_Info_Instances : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("instances"),
Next => null,
Proc => Info_Instances_Proc'Access);
Menu_Info_Psl : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("psl"),
Next => Menu_Info_Instances'Access,
Proc => Info_PSL_Proc'Access);
Menu_Info_Stats : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("stats"),
Next => Menu_Info_Psl'Access,
Proc => Info_Stats_Proc'Access);
Menu_Info_Tree : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("tree"),
Next => Menu_Info_Stats'Access,
Proc => Info_Tree_Proc'Access);
Menu_Info_Params : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("param*eters"),
Next => Menu_Info_Tree'Access,
Proc => Info_Params_Proc'Access);
Menu_Info_Subprograms : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("subp*rograms"),
Next => Menu_Info_Params'Access,
Proc => Info_Subprograms_Proc'Access);
Menu_Info_Units : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("units"),
Next => Menu_Info_Subprograms'Access,
Proc => Info_Units_Proc'Access);
Menu_Info_Files : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("files"),
Next => Menu_Info_Units'Access,
Proc => Info_Files_Proc'Access);
Menu_Info_Libraries : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("lib*raries"),
Next => Menu_Info_Files'Access,
Proc => Info_Libraries_Proc'Access);
Menu_Info_Signals : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("sig*nals"),
Next => Menu_Info_Libraries'Access,
Proc => Info_Signals_Proc'Access);
Menu_Info_Proc : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("proc*esses"),
Next => Menu_Info_Signals'Access,
Proc => Info_Proc_Proc'Access);
Menu_List : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("l*list"),
Next => null,
Proc => List_Proc'Access);
Menu_Down : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("down"),
Next => Menu_List'Access,
Proc => Down_Proc'Access);
Menu_Up : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("up"),
Next => Menu_Down'Access,
Proc => Up_Proc'Access);
Menu_Nstmt : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("ns*tmt"),
Next => Menu_Up'Access,
Proc => Next_Stmt_Proc'Access);
Menu_Fstmt : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("fs*tmt"),
Next => Menu_Nstmt'Access,
Proc => Finish_Stmt_Proc'Access);
Menu_Next : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("n*ext"),
Next => Menu_Fstmt'Access,
Proc => Next_Proc'Access);
Menu_Step : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("s*tep"),
Next => Menu_Next'Access,
Proc => Step_Proc'Access);
Menu_Break : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("b*reak"),
Next => Menu_Step'Access,
Proc => Break_Proc'Access);
Menu_Where : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("where"),
Next => Menu_Break'Access,
Proc => Where_Proc'Access);
Menu_Ps : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("ps"),
Next => Menu_Where'Access,
Proc => Ps_Proc'Access);
Menu_Info : aliased Menu_Entry :=
(Kind => Menu_Submenu,
Name => new String'("i*nfo"),
Next => Menu_Ps'Access,
First | Last => Menu_Info_Proc'Access);
Menu_Print : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("pr*int"),
Next => Menu_Info'Access,
Proc => Print_Proc'Access);
Menu_Cont : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("c*ont"),
Next => Menu_Print'Access,
Proc => Cont_Proc'Access);
Menu_Run : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("r*un"),
Next => Menu_Cont'Access,
Proc => Run_Proc'Access);
Menu_Quit : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("q*uit"),
Next => Menu_Run'Access,
Proc => Quit_Proc'Access);
Menu_Help1 : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("help"),
Next => Menu_Quit'Access,
Proc => Help_Proc'Access);
Menu_Help2 : aliased Menu_Entry :=
(Kind => Menu_Command,
Name => new String'("?"),
Next => Menu_Help1'Access,
Proc => Help_Proc'Access);
Menu_Top : aliased Menu_Entry :=
(Kind => Menu_Submenu,
Name => null,
Next => null,
First | Last => Menu_Help2'Access);
function Find_Menu (Menu : Menu_Entry_Acc; Cmd : String)
return Menu_Entry_Acc
is
function Is_Cmd (Cmd_Name : String; Str : String) return Boolean
is
-- Number of characters that were compared.
P : Natural;
begin
P := 0;
-- Prefix (before the '*').
loop
if P = Cmd_Name'Length then
-- Full match.
return P = Str'Length;
end if;
exit when Cmd_Name (Cmd_Name'First + P) = '*';
if P = Str'Length then
-- Command is too short
return False;
end if;
if Cmd_Name (Cmd_Name'First + P) /= Str (Str'First + P) then
return False;
end if;
P := P + 1;
end loop;
-- Suffix (after the '*')
loop
if P = Str'Length then
return True;
end if;
if P + 1 = Cmd_Name'Length then
-- String is too long
return False;
end if;
if Cmd_Name (Cmd_Name'First + P + 1) /= Str (Str'First + P) then
return False;
end if;
P := P + 1;
end loop;
end Is_Cmd;
Ent : Menu_Entry_Acc;
begin
Ent := Menu.First;
while Ent /= null loop
if Is_Cmd (Ent.Name.all, Cmd) then
return Ent;
end if;
Ent := Ent.Next;
end loop;
return null;
end Find_Menu;
procedure Parse_Command (Line : String;
P : in out Natural;
Menu : out Menu_Entry_Acc)
is
E : Natural;
begin
P := Skip_Blanks (Line (P .. Line'Last));
if P > Line'Last then
return;
end if;
E := Get_Word (Line (P .. Line'Last));
Menu := Find_Menu (Menu, Line (P .. E));
if Menu = null then
Put_Line ("command '" & Line (P .. E) & "' not found");
end if;
P := E + 1;
end Parse_Command;
procedure Help_Proc (Line : String)
is
P : Natural;
Root : Menu_Entry_Acc := Menu_Top'access;
begin
Put_Line ("This is the help command");
P := Line'First;
while P < Line'Last loop
Parse_Command (Line, P, Root);
if Root = null then
return;
elsif Root.Kind /= Menu_Submenu then
Put_Line ("Menu entry " & Root.Name.all & " is not a submenu");
return;
end if;
end loop;
Root := Root.First;
while Root /= null loop
Put (Root.Name.all);
if Root.Kind = Menu_Submenu then
Put (" (menu)");
end if;
New_Line;
Root := Root.Next;
end loop;
end Help_Proc;
function Breakpoint_Hit return Natural
is
Stmt : constant Iir := Current_Process.Instance.Stmt;
begin
for I in Breakpoints.First .. Breakpoints.Last loop
if Stmt = Breakpoints.Table (I).Stmt then
return I;
end if;
end loop;
return 0;
end Breakpoint_Hit;
Prompt_Debug : constant String := "debug> " & ASCII.NUL;
Prompt_Error : constant String := "error> " & ASCII.NUL;
Prompt_Init : constant String := "init> " & ASCII.NUL;
Prompt_Elab : constant String := "elab> " & ASCII.NUL;
procedure Debug (Reason: Debug_Reason)
is
use Grt.Readline;
Raw_Line : Char_Ptr;
Prompt : System.Address;
begin
-- Unless interractive, do not use the debugger.
case Reason is
when Reason_Internal_Debug =>
null;
when Reason_Assert
| Reason_Error =>
if not Flag_Debugger then
return;
end if;
when Reason_Start
| Reason_Elab =>
if not Flag_Interractive then
return;
end if;
when Reason_Break
| Reason_Time =>
null;
end case;
Prompt := Prompt_Debug'Address;
case Reason is
when Reason_Start =>
Set_Top_Frame (null);
Prompt := Prompt_Init'Address;
when Reason_Elab =>
Set_Top_Frame (null);
Prompt := Prompt_Elab'Address;
when Reason_Internal_Debug =>
if Current_Process = null then
Set_Top_Frame (null);
else
Set_Top_Frame (Current_Process.Instance);
end if;
when Reason_Time =>
Break_Time := Grt.Types.Std_Time'Last;
Exec_State := Exec_Run;
when Reason_Break =>
case Exec_State is
when Exec_Run =>
if Breakpoint_Hit /= 0 then
Put_Line ("breakpoint hit");
else
return;
end if;
when Exec_Single_Step =>
null;
when Exec_Next =>
if Current_Process.Instance /= Exec_Instance then
return;
end if;
when Exec_Next_Stmt =>
if Current_Process.Instance /= Exec_Instance
or else Is_Within_Statement (Exec_Statement,
Current_Process.Instance.Stmt)
then
return;
end if;
end case;
-- Default state.
Exec_State := Exec_Run;
Set_Top_Frame (Current_Process.Instance);
declare
Stmt : constant Iir := Dbg_Cur_Frame.Stmt;
begin
Put ("stopped at: ");
Disp_Iir_Location (Stmt);
New_Line;
Disp_Source_Line (Get_Location (Stmt));
end;
when Reason_Assert =>
Set_Top_Frame (Current_Process.Instance);
Prompt := Prompt_Error'Address;
Put_Line ("assertion failure, enterring in debugger");
when Reason_Error =>
Set_Top_Frame (Current_Process.Instance);
Prompt := Prompt_Error'Address;
Put_Line ("error occurred, enterring in debugger");
end case;
if Dbg_Cur_Frame /= null then
Set_List_Current (Get_Location (Dbg_Cur_Frame.Stmt));
end if;
Command_Status := Status_Default;
loop
loop
Raw_Line := Readline (Prompt);
-- Skip empty lines
if Raw_Line = null or else Raw_Line (1) = ASCII.NUL then
if Cmd_Repeat /= null then
Cmd_Repeat.all ("");
case Command_Status is
when Status_Default =>
null;
when Status_Quit =>
return;
end case;
end if;
else
Cmd_Repeat := null;
exit;
end if;
end loop;
declare
Line_Last : constant Natural := Strlen (Raw_Line);
Line : String renames Raw_Line (1 .. Line_Last);
P, E : Positive;
Cmd : Menu_Entry_Acc := Menu_Top'Access;
begin
-- Find command
P := 1;
loop
E := P;
Parse_Command (Line, E, Cmd);
exit when Cmd = null;
case Cmd.Kind is
when Menu_Submenu =>
if E > Line_Last then
Put_Line ("missing command for submenu "
& Line (P .. E - 1));
Cmd := null;
exit;
end if;
P := E;
when Menu_Command =>
exit;
end case;
end loop;
if Cmd /= null then
Cmd.Proc.all (Line (E .. Line_Last));
case Command_Status is
when Status_Default =>
null;
when Status_Quit =>
exit;
end case;
end if;
exception
when Command_Error =>
null;
end;
end loop;
-- Put ("resuming");
end Debug;
procedure Debug_Error is
begin
Debug (Reason_Error);
end Debug_Error;
end Simul.Debugger;
|