File: global.cpp

package info (click to toggle)
faust 2.81.10%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 431,496 kB
  • sloc: cpp: 283,941; ansic: 116,215; javascript: 18,529; sh: 14,356; vhdl: 14,052; java: 5,900; python: 5,091; objc: 3,852; makefile: 2,725; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 111; tcl: 26
file content (2757 lines) | stat: -rw-r--r-- 93,082 bytes parent folder | download
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
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
/************************************************************************
 ************************************************************************
 FAUST compiler
 Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale
 ---------------------------------------------------------------------
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ************************************************************************
 ************************************************************************/

#include <limits.h>
#include <cstdint>

#include "absprim.hh"
#include "acosprim.hh"
#include "asinprim.hh"
#include "atan2prim.hh"
#include "atanprim.hh"
#include "binop.hh"
#include "ceilprim.hh"
#include "cosprim.hh"
#include "enrobage.hh"
#include "exepath.hh"
#include "exp10prim.hh"
#include "expprim.hh"
#include "floats.hh"
#include "floorprim.hh"
#include "fmodprim.hh"
#include "global.hh"
#include "instructions.hh"
#include "log10prim.hh"
#include "logprim.hh"
#include "maxprim.hh"
#include "minprim.hh"
#include "occur.hh"
#include "powprim.hh"
#include "remainderprim.hh"
#include "rintprim.hh"
#include "roundprim.hh"
#include "sinprim.hh"
#include "sourcereader.hh"
#include "sqrtprim.hh"
#include "tanprim.hh"
#include "timing.hh"
#include "tree.hh"

#ifdef WIN32
#pragma warning(disable : 4996)
#endif

#ifdef C_BUILD
#include "c_code_container.hh"
#endif

#ifdef CODEBOX_BUILD
#include "codebox_code_container.hh"
#endif

#ifdef CPP_BUILD
#include "cpp_code_container.hh"
#include "cpp_gpu_code_container.hh"
#endif

#ifdef CSHARP_BUILD
#include "csharp_code_container.hh"
#endif

#ifdef FIR_BUILD
#include "fir_code_container.hh"
#endif

#ifdef LLVM_BUILD
#include "llvm_dsp_aux.hh"
#endif

#ifdef INTERP_BUILD
#include "interpreter_instructions.hh"
#endif

#ifdef JAVA_BUILD
#include "java_code_container.hh"
#endif

#ifdef RUST_BUILD
#include "rust_code_container.hh"
#endif

#ifdef DLANG_BUILD
#include "dlang_code_container.hh"
#endif

#ifdef JULIA_BUILD
#include "julia_code_container.hh"
#endif

#ifdef JSFX_BUILD
#include "jsfx_code_container.hh"
#endif

#ifdef JAX_BUILD
#include "jax_code_container.hh"
#endif

#ifdef TEMPLATE_BUILD
#include "template_code_container.hh"
#endif

using namespace std;

#ifndef AP_INT_MAX_W
#define AP_INT_MAX_W 1024
#endif

// Globals for flex/bison parser
extern FILE*       FAUSTin;
extern const char* FAUSTfilename;

// Garbageable globals
list<Garbageable*> global::gRawObjectTable;
list<Garbageable*> global::gArrayObjectTable;
bool               global::gHeapCleanup = false;

// Just after gRawObjectTable/gArrayObjectTable initialisation for FaustAlgebra constructor to
// correctly work
itv::interval_algebra gAlgebra;

global::global()
    : TABBER(1), gLoopDetector(1024, 400), gStackOverflowDetector(MAX_STACK_SIZE), gNextFreeColor(1)
{
    CTree::init();
    Symbol::init();

    // Part of the state that needs to be initialized between consecutive calls to Box/Signal API
    reset();

    EVALPROPERTY   = symbol("EvalProperty");
    PMPROPERTYNODE = symbol("PMPROPERTY");

    // Fastmath mapping float version
    gFastMathLibTable["fabsf"]      = "fast_fabsf";
    gFastMathLibTable["acosf"]      = "fast_acosf";
    gFastMathLibTable["asinf"]      = "fast_asinf";
    gFastMathLibTable["atanf"]      = "fast_atanf";
    gFastMathLibTable["atan2f"]     = "fast_atan2f";
    gFastMathLibTable["ceilf"]      = "fast_ceilf";
    gFastMathLibTable["cosf"]       = "fast_cosf";
    gFastMathLibTable["expf"]       = "fast_expf";
    gFastMathLibTable["exp2f"]      = "fast_exp2f";
    gFastMathLibTable["exp10f"]     = "fast_exp10f";
    gFastMathLibTable["floorf"]     = "fast_floorf";
    gFastMathLibTable["fmodf"]      = "fast_fmodf";
    gFastMathLibTable["logf"]       = "fast_logf";
    gFastMathLibTable["log2f"]      = "fast_log2f";
    gFastMathLibTable["log10f"]     = "fast_log10f";
    gFastMathLibTable["powf"]       = "fast_powf";
    gFastMathLibTable["remainderf"] = "fast_remainderf";
    gFastMathLibTable["rintf"]      = "fast_rintf";
    gFastMathLibTable["roundf"]     = "fast_roundf";
    gFastMathLibTable["sinf"]       = "fast_sinf";
    gFastMathLibTable["sqrtf"]      = "fast_sqrtf";
    gFastMathLibTable["tanf"]       = "fast_tanf";

    // Fastmath mapping double version
    gFastMathLibTable["fabs"]      = "fast_fabs";
    gFastMathLibTable["acos"]      = "fast_acos";
    gFastMathLibTable["asin"]      = "fast_asin";
    gFastMathLibTable["atan"]      = "fast_atan";
    gFastMathLibTable["atan2"]     = "fast_atan2";
    gFastMathLibTable["ceil"]      = "fast_ceil";
    gFastMathLibTable["cos"]       = "fast_cos";
    gFastMathLibTable["exp"]       = "fast_exp";
    gFastMathLibTable["exp2"]      = "fast_exp2";
    gFastMathLibTable["exp10"]     = "fast_exp10";
    gFastMathLibTable["floor"]     = "fast_floor";
    gFastMathLibTable["fmod"]      = "fast_fmod";
    gFastMathLibTable["log"]       = "fast_log";
    gFastMathLibTable["log2"]      = "fast_log2";
    gFastMathLibTable["log10"]     = "fast_log10";
    gFastMathLibTable["pow"]       = "fast_pow";
    gFastMathLibTable["remainder"] = "fast_remainder";
    gFastMathLibTable["rint"]      = "fast_rint";
    gFastMathLibTable["round"]     = "fast_round";
    gFastMathLibTable["sin"]       = "fast_sin";
    gFastMathLibTable["sqrt"]      = "fast_sqrt";
    gFastMathLibTable["tan"]       = "fast_tan";

    // Fastmath mapping quad version
    gFastMathLibTable["fabsl"]      = "fast_fabs";
    gFastMathLibTable["acosl"]      = "fast_acos";
    gFastMathLibTable["asinl"]      = "fast_asin";
    gFastMathLibTable["atanl"]      = "fast_atan";
    gFastMathLibTable["atan2l"]     = "fast_atan2";
    gFastMathLibTable["ceill"]      = "fast_ceil";
    gFastMathLibTable["cosl"]       = "fast_cos";
    gFastMathLibTable["expl"]       = "fast_exp";
    gFastMathLibTable["exp2l"]      = "fast_exp2";
    gFastMathLibTable["exp10l"]     = "fast_exp10";
    gFastMathLibTable["floorl"]     = "fast_floor";
    gFastMathLibTable["fmodl"]      = "fast_fmod";
    gFastMathLibTable["logl"]       = "fast_log";
    gFastMathLibTable["log2l"]      = "fast_log2";
    gFastMathLibTable["log10l"]     = "fast_log10";
    gFastMathLibTable["powl"]       = "fast_pow";
    gFastMathLibTable["remainderl"] = "fast_remainder";
    gFastMathLibTable["rintl"]      = "fast_rint";
    gFastMathLibTable["roundl"]     = "fast_round";
    gFastMathLibTable["sinl"]       = "fast_sin";
    gFastMathLibTable["sqrtl"]      = "fast_sqrt";
    gFastMathLibTable["tanl"]       = "fast_tan";

    // Fastmath mapping fx version
    gFastMathLibTable["fabsfx"]      = "fast_fabs";
    gFastMathLibTable["acosfx"]      = "fast_acos";
    gFastMathLibTable["asinfx"]      = "fast_asin";
    gFastMathLibTable["atanfx"]      = "fast_atan";
    gFastMathLibTable["atan2fx"]     = "fast_atan2";
    gFastMathLibTable["ceilfx"]      = "fast_ceil";
    gFastMathLibTable["cosfx"]       = "fast_cos";
    gFastMathLibTable["expfx"]       = "fast_exp";
    gFastMathLibTable["exp2fx"]      = "fast_exp2";
    gFastMathLibTable["exp10fx"]     = "fast_exp10";
    gFastMathLibTable["floorfx"]     = "fast_floor";
    gFastMathLibTable["fmodfx"]      = "fast_fmod";
    gFastMathLibTable["logfx"]       = "fast_log";
    gFastMathLibTable["log2fx"]      = "fast_log2";
    gFastMathLibTable["log10fx"]     = "fast_log10";
    gFastMathLibTable["powfx"]       = "fast_pow";
    gFastMathLibTable["remainderfx"] = "fast_remainder";
    gFastMathLibTable["rintfx"]      = "fast_rint";
    gFastMathLibTable["roundfx"]     = "fast_round";
    gFastMathLibTable["sinfx"]       = "fast_sin";
    gFastMathLibTable["sqrtfx"]      = "fast_sqrt";
    gFastMathLibTable["tanfx"]       = "fast_tan";

    gAbsPrim       = new AbsPrim();
    gAcosPrim      = new AcosPrim();
    gTanPrim       = new TanPrim();
    gSqrtPrim      = new SqrtPrim();
    gSinPrim       = new SinPrim();
    gRintPrim      = new RintPrim();
    gRoundPrim     = new RoundPrim();
    gRemainderPrim = new RemainderPrim();
    gPowPrim       = new PowPrim();
    gMinPrim       = new MinPrim();
    gMaxPrim       = new MaxPrim();
    gLogPrim       = new LogPrim();
    gLog10Prim     = new Log10Prim();
    gFmodPrim      = new FmodPrim();
    gFloorPrim     = new FloorPrim();
    gExpPrim       = new ExpPrim();
    gExp10Prim     = new Exp10Prim();
    gCosPrim       = new CosPrim();
    gCeilPrim      = new CeilPrim();
    gAtanPrim      = new AtanPrim();
    gAtan2Prim     = new Atan2Prim();
    gAsinPrim      = new AsinPrim();

    BOXIDENT         = symbol("BoxIdent");
    BOXCUT           = symbol("BoxCut");
    BOXWAVEFORM      = symbol("BoxWaveform");
    BOXROUTE         = symbol("BoxRoute");
    BOXWIRE          = symbol("BoxWire");
    BOXSLOT          = symbol("BoxSlot");
    BOXSYMBOLIC      = symbol("BoxSymbolic");
    BOXSEQ           = symbol("BoxSeq");
    BOXPAR           = symbol("BoxPar");
    BOXREC           = symbol("BoxRec");
    BOXSPLIT         = symbol("BoxSplit");
    BOXMERGE         = symbol("BoxMerge");
    BOXIPAR          = symbol("BoxIPar");
    BOXISEQ          = symbol("BoxISeq");
    BOXISUM          = symbol("BoxISum");
    BOXIPROD         = symbol("BoxIProd");
    BOXABSTR         = symbol("BoxAbstr");
    BOXMODULATION    = symbol("BoxModulation");
    BOXAPPL          = symbol("BoxAppl");
    CLOSURE          = symbol("Closure");
    BOXERROR         = symbol("BoxError");
    BOXACCESS        = symbol("BoxAccess");
    BOXWITHLOCALDEF  = symbol("BoxWithLocalDef");
    BOXMODIFLOCALDEF = symbol("BoxModifLocalDef");
    BOXENVIRONMENT   = symbol("BoxEnvironment");
    BOXCOMPONENT     = symbol("BoxComponent");
    BOXLIBRARY       = symbol("BoxLibrary");
    IMPORTFILE       = symbol("ImportFile");
    BOXPRIM0         = symbol("BoxPrim0");
    BOXPRIM1         = symbol("BoxPrim1");
    BOXPRIM2         = symbol("BoxPrim2");
    BOXPRIM3         = symbol("BoxPrim3");
    BOXPRIM4         = symbol("BoxPrim4");
    BOXPRIM5         = symbol("BoxPrim5");
    BOXFFUN          = symbol("BoxFFun");
    BOXFCONST        = symbol("BoxFConst");
    BOXFVAR          = symbol("BoxFVar");
    BOXBUTTON        = symbol("BoxButton");
    BOXCHECKBOX      = symbol("BoxCheckbox");
    BOXHSLIDER       = symbol("BoxHSlider");
    BOXVSLIDER       = symbol("BoxVSlider");
    BOXNUMENTRY      = symbol("BoxNumEntry");
    BOXHGROUP        = symbol("BoxHGroup");
    BOXVGROUP        = symbol("BoxVGroup");
    BOXTGROUP        = symbol("BoxTGroup");
    BOXHBARGRAPH     = symbol("BoxHBargraph");
    BOXVBARGRAPH     = symbol("BoxVBargraph");
    BOXCASE          = symbol("BoxCase");
    BOXPATMATCHER    = symbol("BoxPatMatcher");
    BOXPATVAR        = symbol("BoxPatVar");
    BOXINPUTS        = symbol("BoxInputs");
    BOXOUTPUTS       = symbol("BoxOutputs");
    BOXSOUNDFILE     = symbol("boxSoundfile");
    BOXMETADATA      = symbol("boxMetadata");

    DOCEQN      = symbol("DocEqn");
    DOCDGM      = symbol("DocDgm");
    DOCNTC      = symbol("DocNtc");
    DOCLST      = symbol("DocLst");
    DOCMTD      = symbol("DocMtd");
    DOCTXT      = symbol("DocTxt");
    BARRIER     = symbol("BARRIER");
    UIFOLDER    = symbol("uiFolder");
    UIWIDGET    = symbol("uiWidget");
    PATHROOT    = symbol("/");
    PATHPARENT  = symbol("..");
    PATHCURRENT = symbol(".");
    FFUN        = symbol("ForeignFunction");

    SIGINPUT           = symbol("SigInput");
    SIGOUTPUT          = symbol("SigOutput");
    SIGDELAY1          = symbol("SigDelay1");
    SIGDELAY           = symbol("SigDelay");
    SIGPREFIX          = symbol("SigPrefix");
    SIGRDTBL           = symbol("SigRDTbl");
    SIGWRTBL           = symbol("SigWRTbl");
    SIGGEN             = symbol("SigGen");
    SIGDOCONSTANTTBL   = symbol("SigDocConstantTbl");
    SIGDOCWRITETBL     = symbol("SigDocWriteTbl");
    SIGDOCACCESSTBL    = symbol("SigDocAccessTbl");
    SIGSELECT2         = symbol("SigSelect2");
    SIGASSERTBOUNDS    = symbol("sigAssertBounds");
    SIGHIGHEST         = symbol("sigHighest");
    SIGLOWEST          = symbol("sigLowest");
    SIGBINOP           = symbol("SigBinOp");
    SIGFFUN            = symbol("SigFFun");
    SIGFCONST          = symbol("SigFConst");
    SIGFVAR            = symbol("SigFVar");
    SIGPROJ            = symbol("SigProj");
    SIGINTCAST         = symbol("SigIntCast");
    SIGBITCAST         = symbol("SigBitCast");
    SIGFLOATCAST       = symbol("SigFloatCast");
    SIGBUTTON          = symbol("SigButton");
    SIGCHECKBOX        = symbol("SigCheckbox");
    SIGWAVEFORM        = symbol("SigWaveform");
    SIGHSLIDER         = symbol("SigHSlider");
    SIGVSLIDER         = symbol("SigVSlider");
    SIGNUMENTRY        = symbol("SigNumEntry");
    SIGHBARGRAPH       = symbol("SigHBargraph");
    SIGVBARGRAPH       = symbol("SigVBargraph");
    SIGATTACH          = symbol("SigAttach");
    SIGENABLE          = symbol("SigEnable");
    SIGCONTROL         = symbol("SigControl");
    SIGSOUNDFILE       = symbol("SigSoundfile");
    SIGSOUNDFILELENGTH = symbol("SigSoundfileLength");
    SIGSOUNDFILERATE   = symbol("SigSoundfileRate");
    SIGSOUNDFILEBUFFER = symbol("SigSoundfileBuffer");
    SIGREGISTER        = symbol("SigRegister");  // for FPGA Retiming
    SIGTUPLE           = symbol("SigTuple");
    SIGTUPLEACCESS     = symbol("SigTupleAccess");
    SIMPLETYPE         = symbol("SimpleType");
    TABLETYPE          = symbol("TableType");
    TUPLETTYPE         = symbol("TupletType");

    // recursive trees
    DEBRUIJN    = symbol("DEBRUIJN");
    DEBRUIJNREF = symbol("DEBRUIJNREF");
    SUBSTITUTE  = symbol("SUBSTITUTE");

    SYMREC    = symbol("SYMREC");
    SYMRECREF = symbol("SYMRECREF");
    SYMLIFTN  = symbol("LIFTN");

    gMachineFloatSize      = sizeof(float);
    gMachineInt32Size      = sizeof(int);
    gMachineInt64Size      = sizeof(long int);
    gMachineDoubleSize     = sizeof(double);
    gMachineQuadSize       = sizeof(long double);
    gMachineFixedPointSize = gMachineFloatSize;
    gMachineBoolSize       = sizeof(bool);

    // Assuming we are compiling for a 64 bits machine
    gMachinePtrSize = sizeof(nullptr);
#if defined(ANDROID) && INTPTR_MAX == INT32_MAX
    // Hack for 32Bit Android Architectures ; sizeof(nullptr) == 4 but LLVM
    // DataLayout.GetPointerSize() == 8
    gMachinePtrSize *= 2;
#endif

    gMachineMaxStackSize = MAX_MACHINE_STACK_SIZE;

    gIntZone  = nullptr;
    gRealZone = nullptr;
}

// Part of the state that needs to be initialized between consecutive calls to Box/Signal API
void global::reset()
{
    gAllWarning = false;
    gWarningMessages.clear();

    gResult          = nullptr;
    gExpandedDefList = nullptr;

    gDetailsSwitch    = false;
    gDrawSignals      = false;
    gDrawRetiming     = false;
    gDrawRouteFrame   = false;
    gShadowBlur       = false;  // note: svg2pdf doesn't like the blur filter
    gScaledSVG        = false;
    gStripDocSwitch   = false;  // Strip <mdoc> content from doc listings.
    gFoldThreshold    = 25;
    gFoldComplexity   = 2;
    gMaxNameSize      = 40;
    gSimpleNames      = false;
    gSimplifyDiagrams = false;
    gMaxCopyDelay     = 16;    // Maximal delay too choose a copy representation
    gMaxDenseDelay    = 1024;  // Maximal delay too choose a dense representation
    gMinDensity       = 33;    // Minimal density d/100 to choose a dense representation

    gVectorSwitch      = false;
    gDeepFirstSwitch   = false;
    gVecSize           = 32;
    gVectorLoopVariant = 0;

    gOpenMPSwitch    = false;
    gOpenMPLoop      = false;
    gSchedulerSwitch = false;
    gOpenCLSwitch    = false;
    gCUDASwitch      = false;
    gGroupTaskSwitch = false;
    gFunTaskSwitch   = false;

    gUIMacroSwitch     = false;
    gRustNoTraitSwitch = false;
    gRustNoLibm        = false;

    gDumpNorm = -1;
    gFTZMode  = 0;
    gRangeUI  = false;
    gFreezeUI = false;

    gFloatSize      = 1;             // -single by default
    gFixedPointSize = AP_INT_MAX_W;  // Special -1 value will be used to generate fixpoint_t type
    gFixedPointMSB  = 0;
    gFixedPointLSB  = 0;

    gPrintFileListSwitch = false;
    gInlineArchSwitch    = false;

    gDSPStruct  = false;
    gLightMode  = false;
    gClang      = false;
    gNoVirtual  = false;
    gCheckTable = true;

    gMathExceptions = false;

    gClassName      = "mydsp";
    gSuperClassName = "dsp";
    gProcessName    = "process";

    gDSPFactory = nullptr;

    gInputString = "";
    gInputFiles.clear();

    // Backend configuration : default values
    gAllowForeignFunction = true;
    gAllowForeignConstant = true;
    gAllowForeignVar      = true;
    gComputeIOTA          = false;
    gFAUSTFLOAT2Internal  = false;
    gInPlace              = false;
    gStrictSelect         = false;
    gHasExp10             = false;
    gLoopVarInBytes       = false;
    gUseMemmove           = false;
    gWaveformInDSP        = false;
    gUseDefaultSound      = true;
    gHasTeeLocal          = false;
    gMathApprox           = false;
    gNeedManualPow        = true;
    gRemoveVarAddress     = false;
    gOneSample            = false;
    gOneSampleIO          = false;
    gExtControl           = false;
    gInlineTable          = false;
    gComputeMix           = false;
    gBool2Int             = false;
    gFastMathLib          = "";
    gNamespace            = "";
    gFullParentheses      = false;
    gCheckIntRange        = false;
    gReprC                = true;

    gNarrowingLimit = 0;
    gWideningLimit  = 0;

    gLstDependenciesSwitch = true;  // mdoc listing management.
    gLstMdocTagsSwitch     = true;  // mdoc listing management.
    gLstDistributedSwitch  = true;  // mdoc listing management.

    gAutoDifferentiate = false;

    gLatexDocSwitch = true;  // Only LaTeX outformat is handled for the moment.

    gFileNum = 0;

    gBoxCounter    = 0;
    gSignalCounter = 0;

    gCountInferences = 0;
    gCountMaximal    = 0;

    gDummyInput = 10000;

    gBoxSlotNumber = 0;
    gMemoryManager = -1;

    gLocalCausalityCheck = false;
    gCausality           = false;

    gOccurrences = nullptr;
    gFoldingFlag = false;
    gDevSuffix   = nullptr;

    gSTEP = 1;  // unique compilation step number

    gOutputLang = "";

#ifdef WASM_BUILD
    gWASMVisitor = nullptr;  // Will be (possibly) allocated in WebAssembly backend
    gWASTVisitor = nullptr;  // Will be (possibly) allocated in WebAssembly backend
#endif

#if defined(INTERP_BUILD) || defined(INTERP_COMP_BUILD)
    gInterpreterVisitor = nullptr;  // Will be (possibly) allocated in Interp backend
#endif

#ifdef JULIA_BUILD
    gJuliaVisitor = nullptr;  // Will be (possibly) allocated in Julia backend
#endif

#ifdef JSFX_BUILD
    gJSFXVisitor = nullptr;  // Will be (possibly) allocated in JSFX backend
#endif

#ifdef CMAJOR_BUILD
    gTableSizeVisitor = nullptr;  // Will be (possibly) allocated in Cmajor backend
#endif

#ifdef JAX_BUILD
    gJAXVisitor = nullptr;  // Will be (possibly) allocated in JAX backend
#endif

#ifdef TEMPLATE_BUILD
    gTemplateVisitor = nullptr;  // Will be (possibly) allocated in Template backend
#endif

#ifdef CODEBOX_BUILD
    gCodeboxVisitor = nullptr;  // Will be (possibly) allocated in Codebox backend
#endif

    gHelpSwitch        = false;
    gVersionSwitch     = false;
    gLibDirSwitch      = false;
    gIncludeDirSwitch  = false;
    gArchDirSwitch     = false;
    gDspDirSwitch      = false;
    gPathListSwitch    = false;
    gGraphSwitch       = false;
    gDrawPSSwitch      = false;
    gDrawSVGSwitch     = false;
    gVHDLTrace         = false;
    gVHDLFloatEncoding = false;
    gFPGAMemory        = 0;
    gPrintXMLSwitch    = false;
    gPrintJSONSwitch   = false;
    gPrintDocSwitch    = false;
    gArchFile          = "";
    gExportDSP         = false;

    gTimeout = 120;  // Time out to abort compiler (in seconds)

    gErrorCount   = 0;
    gErrorMessage = "";

    // By default use "cpp" output
    gOutputLang =
        (getenv("FAUST_DEFAULT_BACKEND")) ? string(getenv("FAUST_DEFAULT_BACKEND")) : "cpp";
}

// Done after contructor since part of the following allocations need the "global" object to be
// fully built
void global::init()
{
    // Default init
    initFaustFloat();

    gPureRoutingProperty   = new property<bool>();
    gSymbolicBoxProperty   = new property<Tree>();
    gSimplifiedBoxProperty = new property<Tree>();
    gSymListProp           = new property<Tree>();

    // Essential predefined types
    gMemoizedTypes          = new property<AudioType*>();
    gAllocationCount        = 0;
    gMaskDelayLineThreshold = INT_MAX;

    // True by default but only usable with -lang ocpp backend
    gEnableFlag = true;

    // Essential predefined types
    TINPUT = makeSimpleType(kReal, kSamp, kExec, kVect, kNum, interval(-1, 1));
    TGUI   = makeSimpleType(kReal, kBlock, kExec, kVect, kNum, interval());

    TREC = makeSimpleType(kInt, kSamp, kInit, kScal, kNum, interval(0, 0));
    // !!! TRECMAX Maximal only in the last component of the type lattice
    TRECMAX = makeSimpleType(kInt, kSamp, kInit, kScal, kNum, interval(-HUGE_VAL, HUGE_VAL));

    // Predefined symbols CONS and NIL
    CONS = symbol("cons");
    NIL  = symbol("nil");
    // Predefined nil tree
    nil = tree(NIL);

    PROCESS = symbol("process");

    BOXTYPEPROP      = tree(symbol("boxTypeProp"));
    NUMERICPROPERTY  = tree(symbol("NUMERICPROPERTY"));
    DEFLINEPROP      = tree(symbol("DefLineProp"));
    USELINEPROP      = tree(symbol("UseLineProp"));
    SIMPLIFIED       = tree(symbol("sigSimplifiedProp"));
    DOCTABLES        = tree(symbol("DocTablesProp"));
    NULLENV          = tree(symbol("NullRenameEnv"));
    COLORPROPERTY    = tree(symbol("ColorProperty"));
    ORDERPROP        = tree(symbol("OrderProp"));
    RECURSIVNESS     = tree(symbol("RecursivnessProp"));
    NULLTYPEENV      = tree(symbol("NullTypeEnv"));
    RECDEF           = tree(symbol("RECDEF"));
    DEBRUIJN2SYM     = tree(symbol("deBruijn2Sym"));
    NORMALFORM       = tree(symbol("NormalForm"));
    DEFNAMEPROPERTY  = tree(symbol("DEFNAMEPROPERTY"));
    NICKNAMEPROPERTY = tree(symbol("NICKNAMEPROPERTY"));
    BCOMPLEXITY      = tree("BCOMPLEXITY");
    LETRECBODY       = boxIdent("RECURSIVEBODY");

    PROPAGATEPROPERTY = symbol("PropagateProperty");

    // FAUSTfilename is defined in errormsg.cpp but must be redefined at each compilation.
    FAUSTfilename = "";
    FAUSTin       = nullptr;

    gLatexheaderfilename = "latexheader.tex";
    gDocTextsDefaultFile = "mathdoctexts-default.txt";

    gCurrentLocal = setlocale(LC_ALL, NULL);
    if (gCurrentLocal != NULL) {
        gCurrentLocal = strdup(gCurrentLocal);
    }

    // Setup standard "C" local
    // (workaround for a bug in bitcode generation :
    // http://lists.cs.uiuc.edu/pipermail/llvmbugs/2012-May/023530.html)
    setlocale(LC_ALL, "C");

    // Source file injection
    gInjectFlag = false;  // inject an external source file into the architecture file
    gInjectFile = "";     // instead of a compiled dsp file

    // Create type declaration for external 'soundfile' type
    vector<NamedTyped*> sf_type_fields;
    sf_type_fields.push_back(IB::genNamedTyped("fBuffers", IB::genBasicTyped(Typed::kVoid_ptr)));
    sf_type_fields.push_back(IB::genNamedTyped("fLength", IB::genBasicTyped(Typed::kInt32_ptr)));
    sf_type_fields.push_back(IB::genNamedTyped("fSR", IB::genBasicTyped(Typed::kInt32_ptr)));
    sf_type_fields.push_back(IB::genNamedTyped("fOffset", IB::genBasicTyped(Typed::kInt32_ptr)));
    sf_type_fields.push_back(IB::genNamedTyped("fChannels", IB::genInt32Typed()));
    sf_type_fields.push_back(IB::genNamedTyped("fParts", IB::genInt32Typed()));
    sf_type_fields.push_back(IB::genNamedTyped("fIsDouble", IB::genInt32Typed()));
    gExternalStructTypes[Typed::kSound] =
        IB::genDeclareStructTypeInst(IB::genStructTyped("Soundfile", sf_type_fields));

    // Foreign math functions supported by the Interp, Cmajor, codebox, wasm/wast backends
    gMathForeignFunctions["acoshf"] = true;
    gMathForeignFunctions["acosh"]  = true;
    gMathForeignFunctions["acoshl"] = true;

    gMathForeignFunctions["asinhf"] = true;
    gMathForeignFunctions["asinh"]  = true;
    gMathForeignFunctions["asinhl"] = true;

    gMathForeignFunctions["atanhf"] = true;
    gMathForeignFunctions["atanh"]  = true;
    gMathForeignFunctions["atanhl"] = true;

    gMathForeignFunctions["coshf"] = true;
    gMathForeignFunctions["cosh"]  = true;
    gMathForeignFunctions["coshl"] = true;

    gMathForeignFunctions["sinhf"] = true;
    gMathForeignFunctions["sinh"]  = true;
    gMathForeignFunctions["sinhl"] = true;

    gMathForeignFunctions["tanhf"] = true;
    gMathForeignFunctions["tanh"]  = true;
    gMathForeignFunctions["tanhl"] = true;

    gMathForeignFunctions["isnanf"] = true;
    gMathForeignFunctions["isnan"]  = true;
    gMathForeignFunctions["isnanl"] = true;

    gMathForeignFunctions["isinff"] = true;
    gMathForeignFunctions["isinf"]  = true;
    gMathForeignFunctions["isinfl"] = true;

    gMathForeignFunctions["copysignf"] = true;
    gMathForeignFunctions["copysign"]  = true;
    gMathForeignFunctions["copysignl"] = true;

    // internal state during drawing
    gInverter[0] = boxSeq(boxPar(boxWire(), boxInt(-1)), boxPrim2(sigMul));
    gInverter[1] = boxSeq(boxPar(boxInt(-1), boxWire()), boxPrim2(sigMul));
    gInverter[2] = boxSeq(boxPar(boxWire(), boxReal(-1.0)), boxPrim2(sigMul));
    gInverter[3] = boxSeq(boxPar(boxReal(-1.0), boxWire()), boxPrim2(sigMul));
    gInverter[4] = boxSeq(boxPar(boxInt(0), boxWire()), boxPrim2(sigSub));
    gInverter[5] = boxSeq(boxPar(boxReal(0.0), boxWire()), boxPrim2(sigSub));
}

string global::printFloat()
{
    switch (gFloatSize) {
        case 1:
            return "-single ";
        case 2:
            return "-double ";
        case 3:
            return "-quad ";
        case 4:
            return "-fx -fx-size " + std::to_string(gFixedPointSize) + " ";
        default:
            faustassert(false);
            return "";
    }
}

void global::printCompilationOptions(stringstream& dst, bool backend)
{
    if (gAutoDifferentiate) {
        dst << "-diff ";
    }
    if (gArchFile != "") {
        dst << "-a " << gArchFile << " ";
    }
    if (backend) {
#ifdef LLVM_BUILD
        if (gOutputLang == "llvm") {
            dst << "-lang " << gOutputLang << " " << LLVM_VERSION << " ";
        } else {
            dst << "-lang " << gOutputLang << " ";
        }
#else
        dst << "-lang " << gOutputLang << " ";
#endif
    }
    if (gInlineArchSwitch) {
        dst << "-i ";
    }
    if (gInPlace) {
        dst << "-inpl ";
    }
    if (gStrictSelect) {
        dst << "-sts ";
    }
    if (gFPGAMemory > 0) {
        dst << "-fpga-mem " << gFPGAMemory << " ";
    }
    if (gOneSample) {
        dst << "-os ";
    }
    if (gLightMode) {
        dst << "-light ";
    }
    if (gMemoryManager >= 0) {
        dst << "-mem" << gMemoryManager << " ";
    }
    if (gComputeMix) {
        dst << "-cm ";
    }
    if (gInlineTable) {
        dst << "-it ";
    }
    if (gRangeUI) {
        dst << "-rui ";
    }
    if (gNoVirtual) {
        dst << "-nvi ";
    }
    if (gFullParentheses) {
        dst << "-fp ";
    }
    if (gCheckIntRange) {
        dst << "-cir ";
    }
    if (gExtControl) {
        dst << "-ec ";
    }
    dst << "-ct " << gCheckTable << " ";
    if (gMathApprox) {
        dst << "-mapp ";
    }
    if (gMathExceptions) {
        dst << "-me ";
    }
    if (gFastMathLib != "") {
        dst << "-fm " << gFastMathLib << " ";
    }
    if (gVHDLTrace) {
        dst << "-vhdl-trace";
    }
    if (gVHDLFloatEncoding) {
        dst << "-vhdl-float";
    }
    if (gClassName != "mydsp") {
        dst << "-cn " << gClassName << " ";
    }
    if (gSuperClassName != "dsp") {
        dst << "-scn " << gSuperClassName << " ";
    }
    if (gProcessName != "process") {
        dst << "-pn " << gProcessName << " ";
    }
    if (gMaskDelayLineThreshold != INT_MAX) {
        dst << "-dtl " << gMaskDelayLineThreshold << " ";
    }
    dst << "-es " << gEnableFlag << " ";
    if (gHasExp10) {
        dst << "-exp10 ";
    }
    if (gSchedulerSwitch) {
        dst << "-sch ";
    }
    if (gOpenMPSwitch) {
        dst << "-omp " << ((gOpenMPLoop) ? "-pl " : "");
    }
    dst << "-mcd " << gMaxCopyDelay << " ";
    dst << "-mdd " << gMaxDenseDelay << " ";
    dst << "-mdy " << gMinDensity << " ";
    if (gUIMacroSwitch) {
        dst << "-uim ";
    }
    dst << printFloat();
    dst << "-ftz " << gFTZMode << " ";
    if (gVectorSwitch) {
        dst << "-vec "
            << "-lv " << gVectorLoopVariant << " "
            << "-vs " << gVecSize << " " << ((gFunTaskSwitch) ? "-fun " : "")
            << ((gGroupTaskSwitch) ? "-g " : "") << ((gDeepFirstSwitch) ? "-dfs " : "");
    }

    // Add 'compile_options' metadata
    string res = dst.str();
    gMetaDataSet[tree("compile_options")].insert(tree("\"" + res.substr(0, res.size() - 1) + "\""));
}

string global::printCompilationOptions1()
{
    stringstream dst;
    printCompilationOptions(dst, true);
    string res = dst.str();
    return res.substr(0, res.size() - 1);
}

void global::initTypeSizeMap()
{
    // Init type size table (in bytes)
    gTypeSizeMap[Typed::kFloat]         = gMachineFloatSize;
    gTypeSizeMap[Typed::kFloat_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kFloat_ptr_ptr] = gMachinePtrSize;
    gTypeSizeMap[Typed::kFloat_vec]     = gMachineFloatSize * gVecSize;
    gTypeSizeMap[Typed::kFloat_vec_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kDouble]         = gMachineDoubleSize;
    gTypeSizeMap[Typed::kDouble_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kDouble_ptr_ptr] = gMachinePtrSize;
    gTypeSizeMap[Typed::kDouble_vec]     = gMachineDoubleSize * gVecSize;
    gTypeSizeMap[Typed::kDouble_vec_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kQuad]         = gMachineQuadSize;
    gTypeSizeMap[Typed::kQuad_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kQuad_ptr_ptr] = gMachinePtrSize;
    gTypeSizeMap[Typed::kQuad_vec]     = gMachineQuadSize * gVecSize;
    gTypeSizeMap[Typed::kQuad_vec_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kFixedPoint]         = gMachineFixedPointSize;
    gTypeSizeMap[Typed::kFixedPoint_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kFixedPoint_ptr_ptr] = gMachinePtrSize;
    gTypeSizeMap[Typed::kFixedPoint_vec]     = gMachineFixedPointSize * gVecSize;
    gTypeSizeMap[Typed::kFixedPoint_vec_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kInt32]         = gMachineInt32Size;
    gTypeSizeMap[Typed::kInt32_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kInt32_vec]     = gMachineInt32Size * gVecSize;
    gTypeSizeMap[Typed::kInt32_vec_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kInt64]         = gMachineInt64Size;
    gTypeSizeMap[Typed::kInt64_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kInt64_vec]     = gMachineInt64Size * gVecSize;
    gTypeSizeMap[Typed::kInt64_vec_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kBool]         = gMachineBoolSize;
    gTypeSizeMap[Typed::kBool_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kBool_vec]     = gMachineBoolSize * gVecSize;
    gTypeSizeMap[Typed::kBool_vec_ptr] = gMachinePtrSize;

    // Takes the type of internal real
    gTypeSizeMap[Typed::kFloatMacro]         = gTypeSizeMap[itfloat()];
    gTypeSizeMap[Typed::kFloatMacro_ptr]     = gMachinePtrSize;
    gTypeSizeMap[Typed::kFloatMacro_ptr_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kVoid_ptr] = gMachinePtrSize;

    gTypeSizeMap[Typed::kObj_ptr]   = gMachinePtrSize;
    gTypeSizeMap[Typed::kSound_ptr] = gMachinePtrSize;
    gTypeSizeMap[Typed::kUint_ptr]  = gMachinePtrSize;
}

int global::audioSampleSize()
{
    return int(pow(2.f, float(gFloatSize + 1)));
}

bool global::hasForeignFunction(const string& name, const string& inc_file)
{
#ifdef LLVM_BUILD
    // LLVM backend can use 'standard' foreign linked functions
    static vector<string> inc_list = {"<math.h>", "<cmath>", "<stdlib.h>"};
    bool                  is_inc = find(begin(inc_list), end(inc_list), inc_file) != inc_list.end();
    // or custom added ones
    bool is_ff       = llvm_dsp_factory_aux::gForeignFunctions.count(name) > 0;
    bool is_linkable = (gOutputLang == "llvm") && (is_inc || is_ff);
#else
    bool is_linkable = false;
#endif
    bool internal_math_ff =
        ((gOutputLang == "llvm") || startWith(gOutputLang, "wast") ||
         startWith(gOutputLang, "wasm") || (gOutputLang == "interp") ||
         startWith(gOutputLang, "cmajor") || startWith(gOutputLang, "codebox") ||
         (gOutputLang == "dlang") || (gOutputLang == "csharp") || (gOutputLang == "rust") ||
         (gOutputLang == "julia") || startWith(gOutputLang, "jsfx") || (gOutputLang == "jax"));

    return (internal_math_ff &&
            (gMathForeignFunctions.find(name) != gMathForeignFunctions.end())) ||
           is_linkable;
}

BasicTyped* global::genBasicTyped(Typed::VarType type)
{
    // Possibly force FAUSTFLOAT type (= kFloatMacro) to internal real
    Typed::VarType new_type =
        ((type == Typed::kFloatMacro) && gFAUSTFLOAT2Internal) ? itfloat() : type;

    // If not defined, add the type in the table
    if (gTypeTable.find(new_type) == gTypeTable.end()) {
        gTypeTable[new_type] = new BasicTyped(new_type);
    }
    return gTypeTable[new_type];
}

void global::setVarType(const string& name, Typed::VarType type)
{
    gVarTypeTable[name] = genBasicTyped(type);
}

Typed::VarType global::getVarType(const string& name)
{
    return gVarTypeTable[name]->getType();
}

global::~global()
{
    Garbageable::cleanup();
    BasicTyped::cleanup();
    DeclareVarInst::cleanup();
    setlocale(LC_ALL, gCurrentLocal);
    free(gCurrentLocal);

    // Cleanup
#ifdef C_BUILD
    CInstVisitor::cleanup();
#endif
#ifdef CPP_BUILD
    CPPInstVisitor::cleanup();
#endif
#ifdef CODEBOX_BUILD
    CodeboxInstVisitor::cleanup();
#endif
#ifdef CSHARP_BUILD
    CSharpInstVisitor::cleanup();
#endif
#ifdef DLANG_BUILD
    DLangInstVisitor::cleanup();
#endif
#ifdef FIR_BUILD
    FIRInstVisitor::cleanup();
#endif
#ifdef JAVA_BUILD
    JAVAInstVisitor::cleanup();
#endif
#ifdef JULIA_BUILD
    JuliaInstVisitor::cleanup();
#endif
#ifdef JSFX_BUILD
    JSFXInstVisitor::cleanup();
#endif
#ifdef JAX_BUILD
    JAXInstVisitor::cleanup();
#endif
#ifdef TEMPLATE_BUILD
    TemplateInstVisitor::cleanup();
#endif
#ifdef RUST_BUILD
    RustInstVisitor::cleanup();
#endif
}

void global::allocate()
{
    gGlobal = new global();
    gGlobal->init();
}

void global::destroy()
{
#ifdef EMCC
    if (faustexception::gJSExceptionMsg) {
        free((void*)faustexception::gJSExceptionMsg);
        faustexception::gJSExceptionMsg = nullptr;
    }
#endif
    delete gGlobal;
    gGlobal = nullptr;
}

string global::makeDrawPath()
{
    if (gOutputDir != "") {
        return gOutputDir + "/" + gMasterName + ".dsp";
    } else {
        return gMasterDocument;
    }
}

string global::makeDrawPathNoExt()
{
    if (gOutputDir != "") {
        return gOutputDir + "/" + gMasterName;
    } else if (gMasterDocument.length() >= 4 &&
               gMasterDocument.substr(gMasterDocument.length() - 4) == ".dsp") {
        return gMasterDocument.substr(0, gMasterDocument.length() - 4);
    } else {
        return gMasterDocument;
    }
}

/*****************************************************************************
                        getFreshID
*****************************************************************************/

string global::getFreshID(const string& prefix)
{
    if (gIDCounters.find(prefix) == gIDCounters.end()) {
        gIDCounters[prefix] = 0;
    }
    int n               = gIDCounters[prefix];
    gIDCounters[prefix] = n + 1;
    return subst("$0$1", prefix, T(n));
}

bool global::isDebug(const string& debug_val)
{
    string debug_var = (getenv("FAUST_DEBUG")) ? string(getenv("FAUST_DEBUG")) : "";
    return debug_var == debug_val;
}

int global::getDebug(const string& debug_var, int def_val)
{
    if (getenv(debug_var.c_str())) {
        return std::stoi(getenv(debug_var.c_str()));
    } else {
        return def_val;
    }
}

bool global::isOpt(const string& opt_val)
{
    string opt_var = (getenv("FAUST_OPT")) ? string(getenv("FAUST_OPT")) : "";
    return opt_var == opt_val;
}

/****************************************************************
 Command line tools and arguments
 *****************************************************************/

// Timing can be used outside of the scope of 'gGlobal'
extern bool gTimingSwitch;

static bool isCmd(const char* cmd, const char* kw1)
{
    return (strcmp(cmd, kw1) == 0);
}

static bool isCmd(const char* cmd, const char* kw1, const char* kw2)
{
    return (strcmp(cmd, kw1) == 0) || (strcmp(cmd, kw2) == 0);
}

bool global::processCmdline(int argc, const char* argv[])
{
    int          i   = 1;
    int          err = 0;
    stringstream parse_error;
    bool         float_size = false;

    /*
        for (int i = 0; i < argc; i++) {
        cerr << "processCmdline i = " << i << " cmd = " << argv[i] << "\n";
     }
    */

    while (i < argc) {
        if (isCmd(argv[i], "-h", "--help")) {
            gHelpSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-lang", "--language") && (i + 1 < argc)) {
            gOutputLang = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-v", "--version")) {
            gVersionSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-libdir", "--libdir")) {
            gLibDirSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-includedir", "--includedir")) {
            gIncludeDirSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-archdir", "--archdir")) {
            gArchDirSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-dspdir", "--dspdir")) {
            gDspDirSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-pathslist", "--pathslist")) {
            gPathListSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-d", "--details")) {
            gDetailsSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-a", "--architecture") && (i + 1 < argc)) {
            gArchFile = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-inj", "--inject") && (i + 1 < argc)) {
            gInjectFlag = true;
            gInjectFile = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-o") && (i + 1 < argc)) {
            gOutputFile = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-wi", "--widening-iterations") && (i + 1 < argc)) {
            gWideningLimit = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-ni", "--narrowing-iterations") && (i + 1 < argc)) {
            gNarrowingLimit = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-ps", "--postscript")) {
            gDrawPSSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-xml", "--xml")) {
            gPrintXMLSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-json", "--json")) {
            gPrintJSONSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-tg", "--task-graph")) {
            gGraphSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-sg", "--signal-graph")) {
            gDrawSignals = true;
            i += 1;

        } else if (isCmd(argv[i], "-rg", "--retiming-graph")) {
            gDrawRetiming = true;
            i += 1;

        } else if (isCmd(argv[i], "-drf", "--draw-route-frame")) {
            gDrawRouteFrame = true;
            i += 1;

        } else if (isCmd(argv[i], "-blur", "--shadow-blur")) {
            gShadowBlur = true;
            i += 1;

        } else if (isCmd(argv[i], "-sc", "--scaled-svg")) {
            gScaledSVG = true;
            i += 1;

        } else if (isCmd(argv[i], "-svg", "--svg")) {
            gDrawSVGSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-vhdl-trace", "--vhdl-trace")) {
            gVHDLTrace = true;
            i += 1;

        } else if (isCmd(argv[i], "-vhdl-float", "--vhdl-float")) {
            gVHDLFloatEncoding = true;
            i += 1;

        } else if (isCmd(argv[i], "-vhdl-components", "--vhdl-components") && (i + 1 < argc)) {
            gVHDLComponentsFile = std::string(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-fpga-mem", "-fpga-mem") && (i + 1 < argc)) {
            gFPGAMemory = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-style", "--svgstyle")) {
            gStyleFile = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-f", "--fold") && (i + 1 < argc)) {
            gFoldThreshold = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-fc", "--fold-complexity") && (i + 1 < argc)) {
            gFoldComplexity = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-mns", "--max-name-size") && (i + 1 < argc)) {
            gMaxNameSize = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-sn", "--simple-names")) {
            gSimpleNames = true;
            i += 1;

        } else if (isCmd(argv[i], "-mcd", "--max-copy-delay") && (i + 1 < argc)) {
            gMaxCopyDelay = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-mdd", "--max-dense-delay") && (i + 1 < argc)) {
            gMaxDenseDelay = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-mdy", "--min-density") && (i + 1 < argc)) {
            gMinDensity = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-dlt", "-delay-line-threshold") && (i + 1 < argc)) {
            gMaskDelayLineThreshold = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-mem", "--memory-manager") ||
                   isCmd(argv[i], "-mem0", "--memory-manager0")) {
            gMemoryManager = 0;
            i += 1;

        } else if (isCmd(argv[i], "-mem1", "--memory-manager1")) {
            gMemoryManager = 1;
            i += 1;

        } else if (isCmd(argv[i], "-mem2", "--memory-manager2")) {
            gMemoryManager = 2;
            i += 1;

        } else if (isCmd(argv[i], "-mem3", "--memory-manager3")) {
            gMemoryManager = 3;
            i += 1;

        } else if (isCmd(argv[i], "-sd", "--simplify-diagrams")) {
            gSimplifyDiagrams = true;
            i += 1;

        } else if (isCmd(argv[i], "-vec", "--vectorize")) {
            gVectorSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-scal", "--scalar")) {
            gVectorSwitch = false;
            i += 1;

        } else if (isCmd(argv[i], "-dfs", "--deepFirstScheduling")) {
            gDeepFirstSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-vs", "--vec-size") && (i + 1 < argc)) {
            gVecSize = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-lv", "--loop-variant") && (i + 1 < argc)) {
            gVectorLoopVariant = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-omp", "--openmp")) {
            gOpenMPSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-pl", "--par-loop")) {
            gOpenMPLoop = true;
            i += 1;

        } else if (isCmd(argv[i], "-sch", "--scheduler")) {
            gSchedulerSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-ocl", "--openCL")) {
            gOpenCLSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-cuda", "--CUDA")) {
            gCUDASwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-g", "--groupTasks")) {
            gGroupTaskSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-fun", "--funTasks")) {
            gFunTaskSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-uim", "--user-interface-macros")) {
            gUIMacroSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-rnt", "--rust-no-faustdsp-trait")) {
            gRustNoTraitSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-rnlm", "--rust-no-libm")) {
            gRustNoLibm = true;
            i += 1;

        } else if (isCmd(argv[i], "-t", "--timeout") && (i + 1 < argc)) {
            gTimeout = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-time", "--compilation-time")) {
            gTimingSwitch = true;
            i += 1;

            // 'real' options
        } else if (isCmd(argv[i], "-single", "--single-precision-floats")) {
            if (float_size && gFloatSize != 1) {
                throw faustexception(
                    "ERROR : cannot using -single, -double, -quad or -fx at the same time\n");
            } else {
                float_size = true;
            }
            gFloatSize = 1;
            i += 1;

        } else if (isCmd(argv[i], "-double", "--double-precision-floats")) {
            if (float_size && gFloatSize != 2) {
                throw faustexception(
                    "ERROR : cannot using -single, -double, -quad or -fx at the same time\n");
            } else {
                float_size = true;
            }
            gFloatSize = 2;
            i += 1;

        } else if (isCmd(argv[i], "-quad", "--quad-precision-floats")) {
            if (float_size && gFloatSize != 3) {
                throw faustexception(
                    "ERROR : cannot using -single, -double, -quad or -fx at the same time\n");
            } else {
                float_size = true;
            }
            gFloatSize = 3;
            i += 1;

        } else if (isCmd(argv[i], "-fx", "--fixed-point")) {
            if (float_size && gFloatSize != 4) {
                throw faustexception(
                    "ERROR : cannot using -single, -double, -quad or -fx at the same time\n");
            } else {
                float_size = true;
            }
            gFloatSize = 4;
            i += 1;

        } else if (isCmd(argv[i], "-fx-size", "--fixed-point-size")) {
            gFixedPointSize = std::atoi(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-mdoc", "--mathdoc")) {
            gPrintDocSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-mdlang", "--mathdoc-lang") && (i + 1 < argc)) {
            gDocLang = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-stripmdoc", "--strip-mdoc-tags")) {
            gStripDocSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-flist", "--file-list")) {
            gPrintFileListSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-norm", "--normalized-form")) {
            gDumpNorm = 0;
            i += 1;

        } else if (isCmd(argv[i], "-norm1", "--normalized-form1")) {
            gDumpNorm = 1;
            i += 1;

        } else if (isCmd(argv[i], "-norm2", "--normalized-form2")) {
            gDumpNorm = 2;
            i += 1;

        } else if (isCmd(argv[i], "-norm3", "--normalized-form3")) {
            gDumpNorm = 3;
            i += 1;

        } else if (isCmd(argv[i], "-cn", "--class-name") && (i + 1 < argc)) {
            vector<char> rep = {'@', ' ', '(', ')', '/', '\\', '.'};
            gClassName       = replaceCharList(argv[i + 1], rep, '_');
            i += 2;

        } else if (isCmd(argv[i], "-scn", "--super-class-name") && (i + 1 < argc)) {
            gSuperClassName = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-pn", "--process-name") && (i + 1 < argc)) {
            gProcessName = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-i", "--inline-architecture-files")) {
            gInlineArchSwitch = true;
            i += 1;

        } else if (isCmd(argv[i], "-e", "--export-dsp")) {
            gExportDSP = true;
            i += 1;

        } else if (isCmd(argv[i], "-exp10", "--generate-exp10")) {
            gHasExp10 = true;
            i += 1;

        } else if (isCmd(argv[i], "-os", "--one-sample")) {
            gOneSample = true;
            i += 1;

        } else if (isCmd(argv[i], "-ec", "--external-control")) {
            gExtControl = true;
            i += 1;

        } else if (isCmd(argv[i], "-it", "--inline-table")) {
            gInlineTable = true;
            i += 1;

        } else if (isCmd(argv[i], "-cm", "--compute-mix")) {
            gComputeMix = true;
            i += 1;

        } else if (isCmd(argv[i], "-ftz", "--flush-to-zero")) {
            gFTZMode = std::atoi(argv[i + 1]);
            if ((gFTZMode > 2) || (gFTZMode < 0)) {
                stringstream error;
                error << "ERROR : invalid -ftz option: " << gFTZMode << endl;
                throw faustexception(error.str());
            }
            i += 2;

        } else if (isCmd(argv[i], "-rui", "--range-ui")) {
            gRangeUI = true;
            i += 1;

        } else if (isCmd(argv[i], "-fui", "--freeze-ui")) {
            gFreezeUI = true;
            i += 1;

        } else if (isCmd(argv[i], "-fm", "--fast-math")) {
            gFastMathLib = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-mapp", "--math-approximation")) {
            gMathApprox = true;
            i += 1;

        } else if (isCmd(argv[i], "-ns", "--namespace")) {
            gNamespace = argv[i + 1];
            i += 2;

        } else if (isCmd(argv[i], "-fp", "--full-parentheses")) {
            gFullParentheses = true;
            i += 1;

        } else if (isCmd(argv[i], "-cir", "--check-integer-range")) {
            gCheckIntRange = true;
            i += 1;
        } else if (isCmd(argv[i], "-noreprc", "--no-reprc")) {
            gReprC = false;
            i += 1;
        } else if (isCmd(argv[i], "-I", "--import-dir") && (i + 1 < argc)) {
            if ((strstr(argv[i + 1], "http://") != 0) || (strstr(argv[i + 1], "https://") != 0)) {
                // We want to search user given directories *before* the standard ones, so insert at
                // the beginning
                gImportDirList.insert(gImportDirList.begin(), argv[i + 1]);
            } else {
                char  temp[PATH_MAX + 1];
                char* path = realpath(argv[i + 1], temp);
                if (path) {
                    // We want to search user given directories *before* the standard ones, so
                    // insert at the beginning
                    gImportDirList.insert(gImportDirList.begin(), path);
                }
            }
            i += 2;

        } else if (isCmd(argv[i], "-A", "--architecture-dir") && (i + 1 < argc)) {
            if ((strstr(argv[i + 1], "http://") != 0) || (strstr(argv[i + 1], "https://") != 0)) {
                gArchitectureDirList.push_back(argv[i + 1]);
            } else {
                char  temp[PATH_MAX + 1];
                char* path = realpath(argv[i + 1], temp);
                if (path) {
                    gArchitectureDirList.push_back(path);
                }
            }
            i += 2;

        } else if (isCmd(argv[i], "-L", "--library") && (i + 1 < argc)) {
            gLibraryList.push_back(argv[i + 1]);
            i += 2;

        } else if (isCmd(argv[i], "-O", "--output-dir") && (i + 1 < argc)) {
            char  temp[PATH_MAX + 1];
            char* path = realpath(argv[i + 1], temp);
            if (path == 0) {
                stringstream error;
                error << "ERROR : invalid directory path " << argv[i + 1] << endl;
                throw faustexception(error.str());
            } else {
                gOutputDir = path;
            }
            i += 2;

        } else if (isCmd(argv[i], "-inpl", "--in-place")) {
            gInPlace = true;
            i += 1;

        } else if (isCmd(argv[i], "-sts", "--strict-select")) {
            gStrictSelect = true;
            i += 1;

        } else if (isCmd(argv[i], "-es", "--enable-semantics")) {
            gEnableFlag = (std::atoi(argv[i + 1]) == 1);
            i += 2;

        } else if (isCmd(argv[i], "-lcc", "--local-causality-check")) {
            gLocalCausalityCheck = true;
            i += 1;

        } else if (isCmd(argv[i], "-light", "--light-mode")) {
            gLightMode = true;
            i += 1;

        } else if (isCmd(argv[i], "-clang", "--clang")) {
            gClang = true;
            i += 1;

        } else if (isCmd(argv[i], "-nvi", "--no-virtual")) {
            gNoVirtual = true;
            i += 1;

        } else if (isCmd(argv[i], "-ct", "--check-table")) {
            gCheckTable = (std::atoi(argv[i + 1]) == 1);
            i += 2;

        } else if (isCmd(argv[i], "-wall", "--warning-all")) {
            gAllWarning = true;
            i += 1;

        } else if (isCmd(argv[i], "-me", "--math-exceptions")) {
            gMathExceptions = true;
            i += 1;

        } else if (isCmd(argv[i], "-diff", "--auto-differentiate")) {
            gAutoDifferentiate = true;
            i += 1;

        } else if (isCmd(argv[i], "-lm", "--local-machine") ||
                   isCmd(argv[i], "-rm", "--remote-machine") ||
                   isCmd(argv[i], "-poly", "--polyphonic-mode") ||
                   isCmd(argv[i], "-voices", "--polyphonic-voices") ||
                   isCmd(argv[i], "-group", "--polyphonic-group")) {
            // Ignore arg
            i += 2;

        } else if (argv[i][0] != '-') {
            const char* url = argv[i];
            if (checkURL(url)) {
                gInputFiles.push_back(url);
            }
            i++;

        } else {
            if (err == 0) {
                parse_error << "unrecognized option(s) : \"" << argv[i] << "\"";
            } else {
                parse_error << ",\"" << argv[i] << "\"";
            }
            i++;
            err++;
        }
    }

    // ========================
    // Adjust related options
    // ========================

    if (gOpenMPSwitch || gSchedulerSwitch) {
        gVectorSwitch = true;
    }

    if (gMemoryManager >= 1) {
        gWaveformInDSP = true;
    }

    // ========================
    // Check options coherency
    // ========================

    if (gRustNoTraitSwitch && gOutputLang != "rust") {
        throw faustexception("ERROR : '-rnt' option can only be used with 'rust' backend\n");
    }

    if (gRustNoLibm && gOutputLang != "rust") {
        throw faustexception("ERROR : '-rnlm' option can only be used with 'rust' backend\n");
    }

    if (!gRustNoTraitSwitch && gInPlace && gOutputLang == "rust") {
        throw faustexception(
            "ERROR : for 'rust' the '-inpl' flag must be combined with '-rnt' flag\n");
    }

    if (gInPlace && gVectorSwitch) {
        throw faustexception("ERROR : '-inpl' option can only be used in scalar mode\n");
    }

#if 0
    if (gOutputLang == "ocpp" && gVectorSwitch) {
        throw faustexception("ERROR : 'ocpp' backend can only be used in scalar mode\n");
    }
#endif
    if (gOneSample && gOutputLang != "cpp" && gOutputLang != "c" && gOutputLang != "dlang" &&
        !startWith(gOutputLang, "cmajor") && gOutputLang != "fir" && gOutputLang != "rust") {
        throw faustexception(
            "ERROR : '-os' option can only be used with 'cpp', 'c', 'cmajor', 'dlang', 'fir' or "
            "'rust'"
            "backends\n");
    }

    if (gExtControl && gOutputLang != "cpp" && gOutputLang != "c" && gOutputLang != "cmajor" &&
        gOutputLang != "rust") {
        throw faustexception(
            "ERROR : '-ec' option can only be used with 'cpp', 'c', 'cmajor' or 'rust' "
            "backends\n");
    }

    if (gOneSample && gVectorSwitch) {
        throw faustexception("ERROR : '-os' option can only be used in scalar mode\n");
    }

    if (gVectorLoopVariant < 0 || gVectorLoopVariant > 2) {
        stringstream error;
        error << "ERROR : invalid loop variant [-lv = " << gVectorLoopVariant
              << "] should be 0 or 1" << endl;
        throw faustexception(error.str());
    }

    if (gVecSize < 4) {
        stringstream error;
        error << "ERROR : invalid vector size [-vs = " << gVecSize << "] should be at least 4"
              << endl;
        throw faustexception(error.str());
    }

    if (gFunTaskSwitch) {
        if (!(gOutputLang == "c" || gOutputLang == "cpp" || gOutputLang == "llvm" ||
              gOutputLang == "fir")) {
            throw faustexception(
                "ERROR : -fun can only be used with 'c', 'cpp', 'llvm' or 'fir' backends\n");
        }
    }

    if (gFastMathLib != "") {
        if (!(gOutputLang == "c" || gOutputLang == "cpp" || gOutputLang == "llvm" ||
              startWith(gOutputLang, "wast") || startWith(gOutputLang, "wasm"))) {
            throw faustexception(
                "ERROR : -fm can only be used with 'c', 'cpp', 'llvm' or 'wast/wast' backends\n");
        }
    }

    if (gNamespace != "" && gOutputLang != "cpp" && gOutputLang != "dlang") {
        throw faustexception("ERROR : -ns can only be used with the 'cpp' or 'dlang' backend\n");
    }

    if (gMaskDelayLineThreshold < INT_MAX && (gVectorSwitch || (gOutputLang == "ocpp"))) {
        throw faustexception(
            "ERROR : '-dlt < INT_MAX' option can only be used in scalar mode and not with the "
            "'ocpp' backend\n");
    }

    // gInlinetable check
    if (gInlineTable && (gOutputLang != "cpp" && gOutputLang != "c" && gOutputLang != "llvm")) {
        throw faustexception("ERROR : -it can only be used with 'cpp', 'c' and 'llvm' backends\n");
    }

    // gMemoryManager check
    if (gMemoryManager == 0 && gInlineTable) {
        throw faustexception("ERROR : '-it' and '-mem' cannot be used together\n");
    }

    if ((gMemoryManager >= 1) && !gInlineTable) {
        throw faustexception("ERROR : -mem1/-mem2/-mem3 has to be used with -it\n");
    }

    if ((gMemoryManager == 3) && gOutputLang != "c") {
        throw faustexception("ERROR : -mem3 can only be used with 'c' backend\n");
    }

    if ((gMemoryManager == 3) && !gExtControl) {
        throw faustexception("ERROR : -mem3 has to be used with -ec\n");
    }

    if ((gMemoryManager == 3) && gVectorSwitch && gVectorLoopVariant != 2) {
        throw faustexception("ERROR : -mem3 and -vec has to be used with -lv 2\n");
    }

    if ((gMemoryManager == 0 || gMemoryManager == 1) && (gOutputLang == "c")) {
        throw faustexception("ERROR : -mem0/-mem1 cannot be used with 'c' backend\n");
    }

    // gComputeMix check
    if (gComputeMix && gOutputLang == "ocpp") {
        throw faustexception("ERROR : -cm cannot be used with the 'ocpp' backend\n");
    }

    if (gComputeMix && gOutputLang == "interp") {
        throw faustexception("ERROR : -cm cannot be used with the 'interp' backend\n");
    }

    if (gComputeMix && gOutputLang == "cmajor") {
        throw faustexception("ERROR : -cm cannot be used with the 'cmajor' backend\n");
    }

    if (gFloatSize == 4 && gOutputLang != "cpp" && gOutputLang != "ocpp" && gOutputLang != "c" &&
        gOutputLang != "fir") {
        throw faustexception(
            "ERROR : -fx can only be used with 'c', 'cpp', 'ocpp' or 'fir' backends\n");
    }

    if (gFTZMode == 2 && gOutputLang != "cpp" && gOutputLang != "ocpp" && gOutputLang != "c" &&
        gOutputLang != "llvm" && startWith(gOutputLang, "wast") && startWith(gOutputLang, "wasm")) {
        throw faustexception(
            "ERROR : -ftz 2 can only be used with 'c', 'cpp', 'ocpp', 'llvm' or wast/wasm "
            "backends\n");
    }

    if (gClang && gOutputLang != "cpp" && gOutputLang != "ocpp" && gOutputLang != "c") {
        throw faustexception(
            "ERROR : -clang can only be used with 'c', 'cpp' or 'ocpp' backends\n");
    }

    if (gNoVirtual && gOutputLang != "cpp" && gOutputLang != "ocpp" && gOutputLang != "c") {
        throw faustexception("ERROR : -nvi can only be used with 'c', 'cpp' or 'ocpp' backends\n");
    }

    if (gMemoryManager >= 0 && gOutputLang != "cpp" && gOutputLang != "ocpp" &&
        gOutputLang != "c") {
        throw faustexception("ERROR : -mem can only be used with 'cpp', 'c', or 'ocpp' backends\n");
    }

    if (gArchFile != "" &&
        ((gOutputLang == "wast") || (gOutputLang == "wasm") || (gOutputLang == "interp") ||
         (gOutputLang == "llvm") || (gOutputLang == "fir"))) {
        throw faustexception(
            "ERROR : -a can only be used with 'c', 'cpp', 'ocpp', 'rust' and 'cmajor' backends\n");
    }

    if (gClassName == "") {
        throw faustexception("ERROR : -cn used with empty string \n");
    }

    if (err != 0) {
        stringstream error;
        error << "WARNING : " << parse_error.str() << endl;
        gErrorMessage = error.str();
    }

    // When -lang has been set
    initFaustFloat();

    return (err == 0);
}

/**
 * transform a filename "faust/example/noise.dsp" into
 * the corresponding fx name "noise"
 */
static string fxName(const string& filename)
{
    // determine position right after the last '/' or 0
    size_t p1 = 0;
    for (size_t i = 0; i < filename.size(); i++) {
        if (filename[i] == '/') {
            p1 = i + 1;
        }
    }

    // determine position of the last '.'
    size_t p2 = filename.size();
    for (size_t i = p1; i < filename.size(); i++) {
        if (filename[i] == '.') {
            p2 = i;
        }
    }

    return filename.substr(p1, p2 - p1);
}

void global::initDocumentNames()
{
    if (gInputFiles.empty()) {
        gMasterDocument  = "Unknown";
        gMasterDirectory = ".";
        gMasterName      = "faustfx";
        gDocName         = "faustdoc";
    } else {
        gMasterDocument  = *gInputFiles.begin();
        gMasterDirectory = fileDirname(gMasterDocument);
        gMasterName      = fxName(gMasterDocument);
        gDocName         = fxName(gMasterDocument);
    }

    // Add gMasterDirectory in gImportDirList and gArchitectureDirList
    gImportDirList.push_back(gMasterDirectory);
    gArchitectureDirList.push_back(gMasterDirectory);
}

void global::initDirectories(int argc, const char* argv[])
{
#if !defined(FAUST_SELF_CONTAINED_LIB)
    char s[1024];
    getFaustPathname(s, 1024);

    gFaustExeDir              = exepath::get(argv[0]);
    gFaustRootDir             = exepath::dirup(gFaustExeDir);
    gFaustDirectory           = fileDirname(s);
    gFaustSuperDirectory      = fileDirname(gFaustDirectory);
    gFaustSuperSuperDirectory = fileDirname(gFaustSuperDirectory);

    //-------------------------------------------------------------------------------------
    // init gImportDirList : a list of path where to search .lib files
    //-------------------------------------------------------------------------------------
    if (char* envpath = getenv("FAUST_LIB_PATH")) {
        gImportDirList.push_back(envpath);
    }
#ifdef INSTALL_PREFIX
    gImportDirList.push_back(INSTALL_PREFIX "/share/faust");
#endif

    gImportDirList.push_back(exepath::dirup(gFaustExeDir) + "/share/faust");
    gImportDirList.push_back("/usr/local/share/faust");
    gImportDirList.push_back("/usr/share/faust");

    //-------------------------------------------------------------------------------------
    // init gArchitectureDirList : a list of path where to search architectures files
    //-------------------------------------------------------------------------------------
    if (char* envpath = getenv("FAUST_ARCH_PATH")) {
        gArchitectureDirList.push_back(envpath);
    }
    gArchitectureDirList.push_back(gFaustDirectory + "/architecture");
    gArchitectureDirList.push_back(gFaustSuperDirectory + "/architecture");
    gArchitectureDirList.push_back(gFaustSuperSuperDirectory + "/architecture");
#ifdef INSTALL_PREFIX
    gArchitectureDirList.push_back(INSTALL_PREFIX "/share/faust");
    gArchitectureDirList.push_back(INSTALL_PREFIX "/include");
#endif
    gArchitectureDirList.push_back(exepath::dirup(gFaustExeDir) + "/share/faust");
    gArchitectureDirList.push_back(exepath::dirup(gFaustExeDir) + "/include");
    gArchitectureDirList.push_back("/usr/local/share/faust");
    gArchitectureDirList.push_back("/usr/share/faust");
    gArchitectureDirList.push_back("/usr/local/include");
    gArchitectureDirList.push_back("/usr/include");

    // for debugging purposes
    //    cerr << "gArchitectureDirList:\n";
    //    for (const auto& d : gArchitectureDirList) {
    //        cerr << "\t" << d << "\n";
    //    }
    //    cerr << endl;
#endif
}

void global::printDeclareHeader(ostream& dst)
{
    for (const auto& i : gMetaDataSet) {
        if (i.first != tree("author")) {
            dst << "declare ";
            stringstream key;
            key << *(i.first);
            vector<char> rep{'.', ':', '/'};
            dst << replaceCharList(key.str(), rep, '_');
            dst << " " << **(i.second.begin()) << ";" << endl;
        } else {
            for (set<Tree>::iterator j = i.second.begin(); j != i.second.end(); ++j) {
                if (j == i.second.begin()) {
                    dst << "declare " << *(i.first) << " " << **j << ";" << endl;
                } else {
                    dst << "declare contributor " << **j << ";" << endl;
                }
            }
        }
    }
}

void global::parseSourceFiles()
{
    startTiming("parser");
    list<string>::iterator s;
    Tree                   result = nil;
    gReader.init();

    if (!gInjectFlag && gInputFiles.begin() == gInputFiles.end()) {
        throw faustexception("ERROR : no files specified; for help type \"faust --help\"\n");
    }
    for (s = gInputFiles.begin(); s != gInputFiles.end(); s++) {
        if (s == gInputFiles.begin()) {
            gMasterDocument = *s;
        }
        result = cons(importFile(tree(s->c_str())), result);
    }

    gExpandedDefList = gReader.expandList(result);
    endTiming("parser");
}

/****************************************************************
 Faust directories information
 *****************************************************************/
#ifdef WIN32
#define kPSEP '\\'
#else
#define kPSEP '/'
#endif

#ifndef LIBDIR
#define LIBDIR "lib"
#endif

static void enumBackends(ostream& out)
{
    const char* dspto = "   DSP to ";
#ifdef C_BUILD
    out << dspto << "C" << endl;
#endif

#ifdef CPP_BUILD
    out << dspto << "C++" << endl;
#endif

#ifdef CMAJOR_BUILD
    out << dspto << "Cmajor" << endl;
#endif

#ifdef CODEBOX_BUILD
    out << dspto << "Codebox" << endl;
#endif

#ifdef CSHARP_BUILD
    out << dspto << "CSharp" << endl;
#endif

#ifdef DLANG_BUILD
    out << dspto << "DLang" << endl;
#endif

#ifdef FIR_BUILD
    out << dspto << "FIR" << endl;
#endif

#if defined(INTERP_BUILD) || defined(INTERP_COMP_BUILD)
    out << dspto << "Interpreter" << endl;
#endif

#ifdef JAVA_BUILD
    out << dspto << "Java" << endl;
#endif

#ifdef JAX_BUILD
    out << dspto << "JAX" << endl;
#endif

#ifdef JULIA_BUILD
    out << dspto << "Julia" << endl;
#endif

#ifdef JSFX_BUILD
    out << dspto << "JSFX" << endl;
#endif

#ifdef LLVM_BUILD
    out << dspto << "LLVM IR" << endl;
#endif

#ifdef OCPP_BUILD
    out << dspto << "old C++" << endl;
#endif

#ifdef RUST_BUILD
    out << dspto << "Rust" << endl;
#endif

#ifdef SDF3_BUILD
    out << dspto << "SDF3" << endl;
#endif

#ifdef TEMPLATE_BUILD
    out << dspto << "Template" << endl;
#endif

#ifdef VHDL_BUILD
    out << dspto << "VHDL" << endl;
#endif

#ifdef WASM_BUILD
    out << dspto << "WebAssembly (wast/wasm)" << endl;
#endif
}

/****************************************************************
 Help and Version information
 *****************************************************************/

string global::printVersion()
{
    stringstream sstr;
    sstr << "FAUST Version " << FAUSTVERSION << "\n";
    sstr << "Embedded backends: \n";
    enumBackends(sstr);
#ifdef LLVM_BUILD
    sstr << "Build with LLVM version " << LLVM_VERSION << "\n";
#endif
    sstr << "Copyright (C) 2002-2025, GRAME - Centre National de Creation Musicale. All rights "
            "reserved. \n";
    return sstr.str();
}

string global::printHelp()
{
    stringstream sstr;
    const char*  tab  = "  ";
    const char*  line = "\n---------------------------------------\n";

    sstr << "FAUST compiler version " << FAUSTVERSION << "\n";
    sstr << "usage : faust [options] file1 [file2 ...]." << endl;
#ifndef EMCC
    sstr << "        where options represent zero or more compiler options \n\tand fileN "
            "represents a Faust source "
            "file (.dsp extension)."
         << endl;
#endif
    sstr << endl << "Input options:" << line;
#ifndef EMCC
    sstr << tab << "-a <file>                               wrapper architecture file." << endl;
    sstr << tab << "-i        --inline-architecture-files   inline architecture files." << endl;
    sstr << tab
         << "-A <dir>  --architecture-dir <dir>      add the directory <dir> to the architecture "
            "search path."
         << endl;
    sstr << tab
         << "-I <dir>  --import-dir <dir>            add the directory <dir> to the libraries "
            "search path."
         << endl;
    sstr << tab << "-L <file> --library <file>              link with the LLVM module <file>."
         << endl;
#endif
#ifndef EMCC
    sstr << endl << "Output options:" << line;
    sstr << tab << "-o <file>                               the output file." << endl;
    sstr << tab
         << "-e        --export-dsp                  export expanded DSP (with all included "
            "libraries)."
         << endl;
    sstr << tab
         << "-uim      --user-interface-macros       add user interface macro definitions to the "
            "output code."
         << endl;
    sstr << tab << "-xml                                    generate an XML description file."
         << endl;
    sstr << tab << "-json                                   generate a JSON description file."
         << endl;
    sstr << tab
         << "-O <dir>  --output-dir <dir>            specify the relative directory of the "
            "generated output code and "
            "of additional generated files (SVG, XML...)."
         << endl;
#endif
    sstr << endl << "Code generation options:" << line;
#ifndef EMCC
    sstr << tab << "-lang <lang> --language                 select output language," << endl;
    sstr << tab
         << "                                        'lang' should be c, cpp (default), cmajor, "
            "codebox, csharp, "
            "dlang, fir, interp, java, jax, jsfx, julia, llvm, "
            "ocpp, rust, sdf3, vhdl or wast/wasm."
         << endl;
#endif
    sstr << tab
         << "-single     --single-precision-floats   use single precision floats for internal "
            "computations (default)."
         << endl;
    sstr << tab
         << "-double     --double-precision-floats   use double precision floats for internal "
            "computations."
         << endl;
#ifndef EMCC
    sstr << tab
         << "-quad       --quad-precision-floats     use quad precision floats for internal "
            "computations."
         << endl;
#endif
    sstr << tab
         << "-fx         --fixed-point               use fixed-point for internal computations."
         << endl;
    sstr << tab
         << "-fx-size    --fixed-point-size          fixed-point number total size in bits (-1 is "
            "used to generate a unique fixpoint_t type)."
         << endl;
    sstr << tab
         << "-es 1|0     --enable-semantics 1|0      use enable semantics when 1 (default), and "
            "simple multiplication "
            "otherwise."
         << endl;
    sstr << tab << "-lcc        --local-causality-check     check causality also at local level."
         << endl;
#ifndef EMCC
    sstr << tab << "-light      --light-mode                do not generate the entire DSP API."
         << endl;
    sstr << tab
         << "-clang      --clang                     when compiled with clang/clang++, adds "
            "specific #pragma for "
            "auto-vectorization."
         << endl;
    sstr << tab
         << "-nvi        --no-virtual                when compiled with the C++ backend, does not "
            "add the 'virtual' "
            "keyword."
         << endl;
    sstr << tab << "-fp         --full-parentheses          always add parentheses around binops."
         << endl;
    sstr << tab
         << "-cir        --check-integer-range       check float to integer range conversion."
         << endl;
    sstr
        << tab
        << "-exp10      --generate-exp10            pow(10,x) replaced by possibly faster exp10(x)."
        << endl;
    sstr << tab << "-os         --one-sample                generate one sample computation."
         << endl;
    sstr << tab
         << "-ec         --external-control          separated 'control' and 'compute' functions."
         << endl;
    sstr << tab
         << "-it         --inline-table              inline rdtable/rwtable code in the main class."
         << endl;
    sstr << tab << "-cm         --compute-mix               mix in outputs buffers." << endl;
    sstr << tab
         << "-ct         --check-table               check rtable/rwtable index range and generate "
            "safe access code "
            "[0/1: 1 by default]."
         << endl;
    sstr << tab
         << "-cn <name>  --class-name <name>         specify the name of the dsp class to be used "
            "instead of mydsp."
         << endl;
    sstr << tab
         << "-scn <name> --super-class-name <name>   specify the name of the super class to be "
            "used instead of dsp."
         << endl;
    sstr << tab
         << "-pn <name>  --process-name <name>       specify the name of the dsp entry-point "
            "instead of process."
         << endl;
    sstr << tab
         << "-mcd <n>    --max-copy-delay <n>        use a copy delay up to max delay <n> and a "
            "dense delay above "
            "(ocpp only) "
            "or a ring buffer (default 16 samples)."
         << endl;
    sstr << tab
         << "-mdd <n>    --max-dense-delay <n>       use a dense delay up to max delay <n> (if "
            "enough density) and a "
            "ring "
            "buffer delay above (ocpp only, default 1024)."
         << endl;
    sstr << tab
         << "-mdy <n>    --min-density <n>           minimal density (100*number of delays/max "
            "delay) to use a dense "
            "delays "
            "(ocpp only, default 33)."
         << endl;
    sstr << tab
         << "-dlt <n>    --delay-line-threshold <n>  use a mask-based ring buffer delays up to max "
            "delay <n> and a "
            "select based ring buffers above (default INT_MAX samples)."
         << endl;
#endif
#ifndef EMCC
    sstr
        << tab
        << "-mem        --memory-manager            allocations done using a custom memory manager."
        << endl;
    sstr
        << tab
        << "-mem1       --memory-manager1           allocations done using a custom memory manager,"
           " using the iControl/fControl and iZone/fZone model."
        << endl;
    sstr << tab
         << "-mem2       --memory-manager2           use iControl/fControl, iZone/fZone model and "
            "no explicit memory manager."
         << endl;
    sstr << tab
         << "-mem3       --memory-manager3           use iControl/fControl, iZone/fZone model and "
            "no explicit memory manager with access as function parameters."
         << endl;
#endif
    sstr << tab
         << "-ftz <n>    --flush-to-zero <n>         code added to recursive signals [0:no "
            "(default), 1:fabs based, "
            "2:mask based (fastest)]."
         << endl;
#ifndef EMCC
    sstr << tab
         << "-rui        --range-ui                  whether to generate code to constraint "
            "vslider/hslider/nentry "
            "values "
            "in [min..max] range."
         << endl;
    sstr << tab
         << "-fui        --freeze-ui                 whether to freeze vslider/hslider/nentry to a "
            "given value (init "
            "value by default)."
         << endl;
    sstr << tab
         << "-inj <f>    --inject <f>                inject source file <f> into architecture file "
            "instead of compiling "
            "a dsp file."
         << endl;
    sstr << tab << "-scal       --scalar                    generate non-vectorized code (default)."
         << endl;
    sstr << tab
         << "-inpl       --in-place                  generates code working when input and output "
            "buffers are the same "
            "(scalar mode only)."
         << endl;
    sstr << tab << "-vec        --vectorize                 generate easier to vectorize code."
         << endl;
    sstr << tab
         << "-vs <n>     --vec-size <n>              size of the vector (default 32 samples)."
         << endl;
    sstr << tab
         << "-lv <n>     --loop-variant <n>          [0:fastest, fixed vector size and a remaining "
            "loop (default), "
            "1:simple, variable vector size, 2:fixed, fixed vector size]."
         << endl;
    sstr << tab
         << "-omp        --openmp                    generate OpenMP pragmas, activates "
            "--vectorize option."
         << endl;
    sstr << tab
         << "-pl         --par-loop                  generate parallel loops in --openmp mode."
         << endl;
    sstr << tab
         << "-sch        --scheduler                 generate tasks and use a Work Stealing "
            "scheduler, activates "
            "--vectorize option."
         << endl;
    sstr << tab
         << "-ocl        --opencl                    generate tasks with OpenCL (experimental)."
         << endl;
    sstr << tab
         << "-cuda       --cuda                      generate tasks with CUDA (experimental)."
         << endl;
    sstr << tab
         << "-dfs        --deep-first-scheduling     schedule vector loops in deep first order."
         << endl;
    sstr << tab
         << "-g          --group-tasks               group single-threaded sequential tasks "
            "together when -omp or -sch "
            "is used."
         << endl;
    sstr << tab
         << "-fun        --fun-tasks                 separate tasks code as separated functions "
            "(in -vec, -sch, or "
            "-omp mode)."
         << endl;
    sstr << tab
         << "-fm <file>  --fast-math <file>          use optimized versions of mathematical "
            "functions implemented in "
            "<file>, use 'faust/dsp/fastmath.cpp' when file is 'def', assume functions are defined "
            "in the architecture "
            "file when file is 'arch'."
         << endl;
    sstr << tab
         << "-mapp       --math-approximation        simpler/faster versions of "
            "'floor/ceil/fmod/remainder' functions."
         << endl;
    sstr << tab
         << "-noreprc    --no-reprc                  (Rust only) Don't force dsp struct layout to "
            "follow C ABI."
         << endl;
    sstr << tab
         << "-ns <name>  --namespace <name>          generate C++ or D code in a namespace <name>."
         << endl;

    sstr << tab << "-vhdl-trace    --vhdl-trace             activate trace." << endl;
    sstr << tab
         << "-vhdl-float    --vhdl-float             uses IEEE-754 format for samples instead of "
            "fixed point."
         << endl;
    sstr << tab
         << "-vhdl-components <file> --vhdl-components <file>    path to a file describing custom "
            "components for the "
            "VHDL backend."
         << endl;
    sstr << tab
         << "-fpga-mem <n>  --fpga-mem <n>           FPGA block ram max size, used in -mem1/-mem2 "
            "mode."
         << endl;

    sstr << tab
         << "-wi <n>     --widening-iterations <n>   number of iterations before widening in "
            "signal bounding."
         << endl;

    sstr << tab
         << "-ni <n>     --narrowing-iterations <n>  number of iterations before stopping "
            "narrowing in signal bounding."
         << endl;
    sstr << tab
         << "-rnt        --rust-no-faustdsp-trait    (Rust only) Don't generate FaustDsp trait "
            "implmentation."
         << endl;
    sstr << tab
         << "-rnlm       --rust-no-libm              (Rust only) Don't generate FFI calls to libm."
         << endl;

#endif
#ifndef EMCC
    sstr << endl << "Block diagram options:" << line;
    sstr << tab
         << "-ps        --postscript                 print block-diagram to a postscript file."
         << endl;
    sstr << tab << "-svg       --svg                        print block-diagram to a svg file."
         << endl;
    sstr << tab
         << "-sd        --simplify-diagrams          try to further simplify diagrams before "
            "drawing."
         << endl;
    sstr << tab
         << "-drf       --draw-route-frame           draw route frames instead of simple cables."
         << endl;
    sstr << tab
         << "-f <n>     --fold <n>                   threshold to activate folding mode during "
            "block-diagram "
            "generation (default 25 elements)."
         << endl;
    sstr << tab
         << "-fc <n>    --fold-complexity <n>        complexity threshold to fold an expression in "
            "folding mode "
            "(default 2)."
         << endl;
    sstr << tab
         << "-mns <n>   --max-name-size <n>          threshold during block-diagram generation "
            "(default 40 char)."
         << endl;
    sstr << tab
         << "-sn        --simple-names               use simple names (without arguments) during "
            "block-diagram "
            "generation."
         << endl;
    sstr << tab << "-blur      --shadow-blur                add a shadow blur to SVG boxes."
         << endl;
    sstr << tab << "-sc        --scaled-svg                 automatic scalable SVG." << endl;

    sstr << endl << "Math doc options:" << line;
    sstr << tab
         << "-mdoc       --mathdoc                   print math documentation of the Faust program "
            "in LaTeX format in "
            "a -mdoc folder."
         << endl;
    sstr
        << tab
        << "-mdlang <l> --mathdoc-lang <l>          if translation file exists (<l> = en, fr, ...)."
        << endl;
    sstr << tab
         << "-stripmdoc  --strip-mdoc-tags           strip mdoc tags when printing Faust -mdoc "
            "listings."
         << endl;

    sstr << endl << "Debug options:" << line;
    sstr << tab << "-d          --details                   print compilation details." << endl;
    sstr << tab
         << "-time       --compilation-time          display compilation phases timing information."
         << endl;
    sstr << tab
         << "-flist      --file-list                 print file list (including libraries) used to "
            "eval process."
         << endl;
    sstr << tab
         << "-tg         --task-graph                print the internal task graph in dot format."
         << endl;
    sstr << tab
         << "-sg         --signal-graph              print the internal signal graph in dot format."
         << endl;
    sstr << tab
         << "-rg         --retiming-graph            print the internal signal graph after "
            "retiming in dot format."
         << endl;
    sstr << tab
         << "-norm       --normalized-form           print signals in normalized form and exit."
         << endl;
    sstr << tab
         << "-norm1      --normalized-form1          print signals in normalized form with IDs for "
            "shared sub-expressions and exit."
         << endl;
    sstr << tab
         << "-me         --math-exceptions           check / for 0 as denominator and remainder, "
            "fmod, sqrt, log10, "
            "log, acos, asin functions domain."
         << endl;
    sstr << tab
         << "-sts        --strict-select             generate strict code for 'selectX' even for "
            "stateless branches "
            "(both are computed)."
         << endl;
    sstr << tab << "-wall       --warning-all               print all warnings." << endl;
    sstr << tab
         << "-t <sec>    --timeout <sec>             abort compilation after <sec> seconds "
            "(default 120)."
         << endl;

    sstr << endl << "Information options:" << line;
    sstr << tab << "-h          --help                      print this help message." << endl;
    sstr << tab
         << "-v          --version                   print version information and embedded "
            "backends list."
         << endl;
    sstr
        << tab
        << "-libdir     --libdir                    print directory containing the Faust libraries."
        << endl;
    sstr << tab
         << "-includedir --includedir                print directory containing the Faust headers."
         << endl;
    sstr << tab
         << "-archdir    --archdir                   print directory containing the Faust "
            "architectures."
         << endl;
    sstr << tab
         << "-dspdir     --dspdir                    print directory containing the Faust dsp "
            "libraries."
         << endl;
    sstr << tab
         << "-pathslist  --pathslist                 print the architectures and dsp library paths."
         << endl;

    sstr << endl << "Environment variables:" << line;
    sstr << tab << "FAUST_DEBUG      = FAUST_LLVM1          print LLVM IR before optimisation."
         << endl;
    sstr << tab << "FAUST_DEBUG      = FAUST_LLVM2          print LLVM IR after optimisation."
         << endl;
    sstr << tab << "FAUST_DEBUG      = FIR_PRINTER          print FIR after generation." << endl;
    sstr << tab
         << "FAUST_DEBUG      = FAUST_LLVM_NO_FM     deactivate fast-math optimisation in LLVM IR."
         << endl;
    sstr << tab << "FAUST_OPT        = FAUST_SIG_NO_NORM    deactivate signal normalisation."
         << endl;

    sstr << endl << "Example:" << line;
    sstr << "faust -a jack-gtk.cpp -o myfx.cpp myfx.dsp" << endl;
#endif
    return sstr.str();
}

string global::printLibDir()
{
    stringstream sstr;
    sstr << gFaustRootDir << kPSEP << LIBDIR << endl;
    return sstr.str();
}
string global::printIncludeDir()
{
    stringstream sstr;
    sstr << gFaustRootDir << kPSEP << "include" << endl;
    return sstr.str();
}
string global::printArchDir()
{
    stringstream sstr;
    sstr << gFaustRootDir << kPSEP << "share" << kPSEP << "faust" << endl;
    return sstr.str();
}
string global::printDspDir()
{
    stringstream sstr;
    sstr << gFaustRootDir << kPSEP << "share" << kPSEP << "faust" << endl;
    return sstr.str();
}
string global::printPaths()
{
    stringstream sstr;
    sstr << "FAUST dsp library paths:" << endl;
    for (const auto& path : gImportDirList) {
        sstr << path << endl;
    }
    sstr << "\nFAUST architectures paths:" << endl;
    for (const auto& path : gArchitectureDirList) {
        sstr << path << endl;
    }
    sstr << endl;
    return sstr.str();
}

void global::printDirectories()
{
    if (gHelpSwitch) {
        cout << printHelp();
        throw faustexception();
    }
    if (gVersionSwitch) {
        cout << printVersion();
        throw faustexception();
    }
    if (gLibDirSwitch) {
        cout << printLibDir();
        throw faustexception();
    }
    if (gIncludeDirSwitch) {
        cout << printIncludeDir();
        throw faustexception();
    }
    if (gArchDirSwitch) {
        cout << printArchDir();
        throw faustexception();
    }
    if (gDspDirSwitch) {
        cout << printDspDir();
        throw faustexception();
    }
    if (gPathListSwitch) {
        cout << printPaths();
        throw faustexception();
    }
}

// For box/sig generation
void global::clear()
{
    gBoxCounter = 0;
    gBoxTable.clear();
    gBoxTrace.clear();

    gSignalCounter = 0;
    gSignalTable.clear();
    gSignalTrace.clear();
}

// Memory management

#ifdef _WIN32
void Garbageable::cleanup()
{
    list<Garbageable*>::iterator it;

    // Here removing the deleted pointer from the list is pointless
    // and takes time, thus we don't do it.
    global::gHeapCleanup = true;
    for (it = global::gRawObjectTable.begin(); it != global::gRawObjectTable.end(); it++) {
        // Hack : "this" and actual pointer are not the same: destructor cannot be called...
        Garbageable::operator delete(*it);
    }

    // Reset to default state
    global::gRawObjectTable.clear();
    global::gHeapCleanup = false;
}

void* Garbageable::operator new(size_t size)
{
    // HACK : add 16 bytes to avoid unsolved memory smashing bug...
    Garbageable* res = (Garbageable*)malloc(size + 16);
    global::gRawObjectTable.push_front(res);
    return res;
}

void Garbageable::operator delete(void* ptr)
{
    // We may have cases when a pointer will be deleted during
    // a compilation, thus the pointer has to be removed from the list.
    if (!global::gHeapCleanup) {
        global::gRawObjectTable.remove(static_cast<Garbageable*>(ptr));
    }
    free(ptr);
}

void* Garbageable::operator new[](size_t size)
{
    // HACK : add 16 bytes to avoid unsolved memory smashing bug...
    Garbageable* res = (Garbageable*)malloc(size + 16);
    global::gRawObjectTable.push_front(res);
    return res;
}

void Garbageable::operator delete[](void* ptr)
{
    // We may have cases when a pointer will be deleted during
    // a compilation, thus the pointer has to be removed from the list.
    if (!global::gHeapCleanup) {
        global::gRawObjectTable.remove(static_cast<Garbageable*>(ptr));
    }
    free(ptr);
}

#else

void Garbageable::cleanup()
{
    // Here removing the deleted pointer from the list is pointless
    // and takes time, thus we don't do it.
    global::gHeapCleanup = true;

    for (Garbageable* obj : global::gRawObjectTable) {
        delete obj;
    }
    global::gRawObjectTable.clear();

    for (Garbageable* obj : global::gArrayObjectTable) {
        delete[] obj;
    }
    global::gArrayObjectTable.clear();

    // Reset to default state
    global::gHeapCleanup = false;
}

void* Garbageable::operator new(size_t size)
{
    Garbageable* res = static_cast<Garbageable*>(::operator new(size));
    global::gRawObjectTable.push_front(res);
    return res;
}

void Garbageable::operator delete(void* ptr)
{
    if (!global::gHeapCleanup) {
        global::gRawObjectTable.remove(static_cast<Garbageable*>(ptr));
    }
    ::operator delete(ptr);
}

void* Garbageable::operator new[](size_t size)
{
    Garbageable* res = static_cast<Garbageable*>(::operator new[](size));
    global::gArrayObjectTable.push_front(res);
    return res;
}

void Garbageable::operator delete[](void* ptr)
{
    if (!global::gHeapCleanup) {
        global::gArrayObjectTable.remove(static_cast<Garbageable*>(ptr));
    }
    ::operator delete[](ptr);
}

#endif

/*
    Threaded calls API: the compilation code is executed in a separate
    thread so that the stack size can be raised to MAX_STACK_SIZE.
 */
void callFun(threaded_fun fun, void* arg)
{
#if defined(EMCC)
    // No thread support in JavaScript
    fun(arg);
#elif defined(_WIN32)
    DWORD  id;
    HANDLE thread = CreateThread(NULL, MAX_STACK_SIZE, LPTHREAD_START_ROUTINE(fun), arg, 0, &id);
    faustassert(thread != NULL);
    WaitForSingleObject(thread, INFINITE);
#else
    pthread_t      thread;
    pthread_attr_t attr;
    faustassert(pthread_attr_init(&attr) == 0);
    faustassert(pthread_attr_setstacksize(&attr, MAX_STACK_SIZE) == 0);
    faustassert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == 0);
    faustassert(pthread_create(&thread, &attr, fun, arg) == 0);
    faustassert(pthread_join(thread, nullptr) == 0);
    faustassert(pthread_attr_destroy(&attr) == 0);
#endif
}