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
use std::fmt::Display;

use crate::tag::Tag;

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum CpuName<'a> {
    #[default]
    None,
    /// ARM7EJ-S
    Arm7TejS,
    /// ARM7TM
    Arm7Tm,
    /// ARM7TDM
    Arm7Tdm,
    /// ARM7TDMI
    Arm7Tdmi,
    /// ARM710T
    Arm710T,
    /// ARM720T
    Arm720T,
    /// ARM740T
    Arm740T,
    /// ARM7TM-S
    Arm7TmS,
    /// ARM7TDMI-S
    Arm7TdmiS,
    /// ARM810
    Arm810,
    /// ARM9TDMI
    Arm9Tdmi,
    /// ARM920T
    Arm920T,
    /// ARM922T
    Arm922T,
    /// ARM940T
    Arm940T,
    /// ARM9E-S
    Arm9ES,
    /// ARM9EJ-S
    Arm9EjS,
    /// ARM926EJ-S
    Arm926EjS,
    /// ARM946E-S
    Arm946ES,
    /// ARM966E-S
    Arm966ES,
    /// ARM968E-S
    Arm968ES,
    /// ARM1020E
    Arm1020E,
    /// ARM1026EJ-S
    Arm1026EjS,
    /// ARM1136J-S
    Arm1136JS,
    /// ARM1136JF-S
    Arm1136JfS,
    /// ARM1156T2-S
    Arm1156T2S,
    /// ARM1156T2F-S
    Arm1156T2FS,
    /// ARM1176JZ-S
    Arm1176JzS,
    /// ARM1176JZF-S
    Arm1176JzfS,
    /// MPCore
    MpCore,
    /// Cortex-M0
    CortexM0,
    /// Cortex-M0plus
    CortexM0Plus,
    /// Cortex-M1
    CortexM1,
    /// Cortex-M3
    CortexM3,
    /// Cortex-M4
    CortexM4,
    /// SC000
    Sc000,
    /// SC300
    Sc300,
    /// Cortex-R4
    CortexR4,
    /// Cortex-R4F
    CortexR4F,
    /// Cortex-R5
    CortexR5,
    /// Cortex-R7
    CortexR7,
    /// Cortex-A5
    CortexA5,
    /// Cortex-A7
    CortexA7,
    /// Cortex-A8
    CortexA8,
    /// Cortex-A9
    CortexA9,
    /// Cortex-A16
    CortexA15,
    Other(&'a str),
}

impl<'a> From<&'a str> for CpuName<'a> {
    fn from(value: &'a str) -> Self {
        match value {
            "" => Self::None,
            "ARM7EJ-S" => Self::Arm7TejS,
            "ARM7TM" => Self::Arm7Tm,
            "ARM7TDM" => Self::Arm7Tdm,
            "ARM7TDMI" => Self::Arm7Tdmi,
            "ARM710T" => Self::Arm710T,
            "ARM720T" => Self::Arm720T,
            "ARM740T" => Self::Arm740T,
            "ARM7TM-S" => Self::Arm7TmS,
            "ARM7TDMI-S" => Self::Arm7TdmiS,
            "ARM810" => Self::Arm810,
            "ARM9TDMI" => Self::Arm9Tdmi,
            "ARM920T" => Self::Arm920T,
            "ARM922T" => Self::Arm922T,
            "ARM940T" => Self::Arm940T,
            "ARM9E-S" => Self::Arm9ES,
            "ARM9EJ-S" => Self::Arm9EjS,
            "ARM926EJ-S" => Self::Arm926EjS,
            "ARM946E-S" => Self::Arm946ES,
            "ARM966E-S" => Self::Arm966ES,
            "ARM968E-S" => Self::Arm968ES,
            "ARM1020E" => Self::Arm1020E,
            "ARM1026EJ-S" => Self::Arm1026EjS,
            "ARM1136J-S" => Self::Arm1136JS,
            "ARM1136JF-S" => Self::Arm1136JfS,
            "ARM1156T2-S" => Self::Arm1156T2S,
            "ARM1156T2F-S" => Self::Arm1156T2FS,
            "ARM1176JZ-S" => Self::Arm1176JzS,
            "ARM1176JZF-S" => Self::Arm1176JzfS,
            "MPCore" => Self::MpCore,
            "Cortex-M0" => Self::CortexM0,
            "Cortex-M0plus" => Self::CortexM0Plus,
            "Cortex-M1" => Self::CortexM1,
            "Cortex-M3" => Self::CortexM3,
            "Cortex-M4" => Self::CortexM4,
            "SC000" => Self::Sc000,
            "SC300" => Self::Sc300,
            "Cortex-R4" => Self::CortexR4,
            "Cortex-R4F" => Self::CortexR4F,
            "Cortex-R5" => Self::CortexR5,
            "Cortex-R7" => Self::CortexR7,
            "Cortex-A5" => Self::CortexA5,
            "Cortex-A7" => Self::CortexA7,
            "Cortex-A8" => Self::CortexA8,
            "Cortex-A9" => Self::CortexA9,
            "Cortex-A16" => Self::CortexA15,
            _ => Self::Other(value),
        }
    }
}

impl<'a> Display for CpuName<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => Ok(()),
            Self::Arm7TejS => write!(f, "ARM7EJ-S"),
            Self::Arm7Tm => write!(f, "ARM7TM"),
            Self::Arm7Tdm => write!(f, "ARM7TDM"),
            Self::Arm7Tdmi => write!(f, "ARM7TDMI"),
            Self::Arm710T => write!(f, "ARM710T"),
            Self::Arm720T => write!(f, "ARM720T"),
            Self::Arm740T => write!(f, "ARM740T"),
            Self::Arm7TmS => write!(f, "ARM7TM-S"),
            Self::Arm7TdmiS => write!(f, "ARM7TDMI-S"),
            Self::Arm810 => write!(f, "ARM810"),
            Self::Arm9Tdmi => write!(f, "ARM9TDMI"),
            Self::Arm920T => write!(f, "ARM920T"),
            Self::Arm922T => write!(f, "ARM922T"),
            Self::Arm940T => write!(f, "ARM940T"),
            Self::Arm9ES => write!(f, "ARM9E-S"),
            Self::Arm9EjS => write!(f, "ARM9EJ-S"),
            Self::Arm926EjS => write!(f, "ARM926EJ-S"),
            Self::Arm946ES => write!(f, "ARM946E-S"),
            Self::Arm966ES => write!(f, "ARM966E-S"),
            Self::Arm968ES => write!(f, "ARM968E-S"),
            Self::Arm1020E => write!(f, "ARM1020E"),
            Self::Arm1026EjS => write!(f, "ARM1026EJ-S"),
            Self::Arm1136JS => write!(f, "ARM1136J-S"),
            Self::Arm1136JfS => write!(f, "ARM1136JF-S"),
            Self::Arm1156T2S => write!(f, "ARM1156T2-S"),
            Self::Arm1156T2FS => write!(f, "ARM1156T2F-S"),
            Self::Arm1176JzS => write!(f, "ARM1176JZ-S"),
            Self::Arm1176JzfS => write!(f, "ARM1176JZF-S"),
            Self::MpCore => write!(f, "MPCore"),
            Self::CortexM0 => write!(f, "Cortex-M0"),
            Self::CortexM0Plus => write!(f, "Cortex-M0plus"),
            Self::CortexM1 => write!(f, "Cortex-M1"),
            Self::CortexM3 => write!(f, "Cortex-M3"),
            Self::CortexM4 => write!(f, "Cortex-M4"),
            Self::Sc000 => write!(f, "SC000"),
            Self::Sc300 => write!(f, "SC300"),
            Self::CortexR4 => write!(f, "Cortex-R4"),
            Self::CortexR4F => write!(f, "Cortex-R4F"),
            Self::CortexR5 => write!(f, "Cortex-R5"),
            Self::CortexR7 => write!(f, "Cortex-R7"),
            Self::CortexA5 => write!(f, "Cortex-A5"),
            Self::CortexA7 => write!(f, "Cortex-A7"),
            Self::CortexA8 => write!(f, "Cortex-A8"),
            Self::CortexA9 => write!(f, "Cortex-A9"),
            Self::CortexA15 => write!(f, "Cortex-A16"),
            Self::Other(name) => write!(f, "\"{name}\""),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum CpuArch {
    /// Pre-ARMv4
    #[default]
    PreV4,
    /// ARMv4
    V4,
    /// ARMv4T
    V4T,
    /// ARMv5T
    V5T,
    /// ARMv5TE
    V5TE,
    /// ARMv5TEJ
    V5TEJ,
    /// ARMv6
    V6,
    /// ARMv6KZ
    V6KZ,
    /// ARMv6T2
    V6T2,
    /// ARMv6K
    V6K,
    /// ARMv7
    V7,
    /// ARMv6-M
    V6M,
    /// ARMv6S-M
    V6SM,
    /// ARMv7E-M
    V7EM,
    /// ARMv8-A
    V8A,
    /// ARMv8-R
    V8R,
    /// ARMv8M.baseline
    V8MBaseline,
    /// ARMv8M.mainline
    V8MMainline,
    /// ARMv8.1-A
    V8_1A,
    /// ARMv8.2-A
    V8_2A,
    /// ARMv8.3-A
    V8_3A,
    /// ARMv8.1-M.mainline
    V8_1MMainline,
    /// ARMv9A
    V9A,
    Unknown(u8),
}

impl CpuArch {
    pub fn value(self) -> u8 {
        match self {
            Self::PreV4 => 0,
            Self::V4 => 1,
            Self::V4T => 2,
            Self::V5T => 3,
            Self::V5TE => 4,
            Self::V5TEJ => 5,
            Self::V6 => 6,
            Self::V6KZ => 7,
            Self::V6T2 => 8,
            Self::V6K => 9,
            Self::V7 => 10,
            Self::V6M => 11,
            Self::V6SM => 12,
            Self::V7EM => 13,
            Self::V8A => 14,
            Self::V8R => 15,
            Self::V8MBaseline => 16,
            Self::V8MMainline => 17,
            Self::V8_1A => 18,
            Self::V8_2A => 19,
            Self::V8_3A => 20,
            Self::V8_1MMainline => 21,
            Self::V9A => 22,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for CpuArch {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::PreV4,
            1 => Self::V4,
            2 => Self::V4T,
            3 => Self::V5T,
            4 => Self::V5TE,
            5 => Self::V5TEJ,
            6 => Self::V6,
            7 => Self::V6KZ,
            8 => Self::V6T2,
            9 => Self::V6K,
            10 => Self::V7,
            11 => Self::V6M,
            12 => Self::V6SM,
            13 => Self::V7EM,
            14 => Self::V8A,
            15 => Self::V8R,
            16 => Self::V8MBaseline,
            17 => Self::V8MMainline,
            18 => Self::V8_1A,
            19 => Self::V8_2A,
            20 => Self::V8_3A,
            21 => Self::V8_1MMainline,
            22 => Self::V9A,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for CpuArch {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::PreV4 => write!(f, "Pre-v4"),
            Self::V4 => write!(f, "ARMv4"),
            Self::V4T => write!(f, "ARMv4T"),
            Self::V5T => write!(f, "ARMv5T"),
            Self::V5TE => write!(f, "ARMv5TE"),
            Self::V5TEJ => write!(f, "ARMv5TEJ"),
            Self::V6 => write!(f, "ARMv6"),
            Self::V6KZ => write!(f, "ARMv6KZ"),
            Self::V6T2 => write!(f, "ARMv6T2"),
            Self::V6K => write!(f, "ARMv6K"),
            Self::V7 => write!(f, "ARMv7"),
            Self::V6M => write!(f, "ARMv6-M"),
            Self::V6SM => write!(f, "ARMv6S-M"),
            Self::V7EM => write!(f, "ARMv7E-M"),
            Self::V8A => write!(f, "ARMv8-A"),
            Self::V8R => write!(f, "ARMv8-R"),
            Self::V8MBaseline => write!(f, "ARMv8-M.baseline"),
            Self::V8MMainline => write!(f, "ARMv8-M.mainline"),
            Self::V8_1A => write!(f, "ARMv8.1-A"),
            Self::V8_2A => write!(f, "ARMv8.2-A"),
            Self::V8_3A => write!(f, "ARMv8.3-A"),
            Self::V8_1MMainline => write!(f, "ARMv8.1-M.mainline"),
            Self::V9A => write!(f, "ARMv9-A"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum CpuArchProfile {
    /// Architecture profile not applicable
    #[default]
    NotApplicable,
    /// Application profile (A)
    Application,
    /// Real-time profile (R)
    RealTime,
    /// Microcontroller profile (M)
    Microcontroller,
    /// Application or real-time profile (S)
    Classic,
    Unknown(u8),
}

impl CpuArchProfile {
    pub fn value(self) -> u8 {
        match self {
            Self::NotApplicable => 0,
            Self::Application => b'A',
            Self::RealTime => b'R',
            Self::Microcontroller => b'M',
            Self::Classic => b'S',
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for CpuArchProfile {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::NotApplicable,
            b'A' => Self::Application,
            b'R' => Self::RealTime,
            b'M' => Self::Microcontroller,
            b'S' => Self::Classic,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for CpuArchProfile {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::NotApplicable => write!(f, "N/A"),
            Self::Application => write!(f, "A"),
            Self::RealTime => write!(f, "R"),
            Self::Microcontroller => write!(f, "M"),
            Self::Classic => write!(f, "S"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum ArmIsaUse {
    /// ARM code is not allowed.
    #[default]
    None,
    /// ARM code is allowed.
    Allowed,
    Unknown(u8),
}

impl ArmIsaUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Allowed => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for ArmIsaUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for ArmIsaUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ArmIsaUse::None => write!(f, "None"),
            ArmIsaUse::Allowed => write!(f, "Allowed"),
            ArmIsaUse::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum ThumbIsaUse {
    /// Thumb code is not allowed.
    #[default]
    None,
    /// Deprecated since ARMv8-M.baseline, use Allowed instead.
    ///
    /// 16-bit Thumb instructions are allowed, including 32-bit BL.
    Allowed16Bit,
    /// Deprecated since ARMv8-M.baseline, use Allowed instead.
    ///
    /// 32-bit and 16-bit Thumb instructions are allowed.
    Allowed32Bit,
    /// Thumb code is allowed. The set of permitted instructions can be inferred from CPU arch and CPU arch profile.
    Allowed,
    Unknown(u8),
}

impl ThumbIsaUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Allowed16Bit => 1,
            Self::Allowed32Bit => 2,
            Self::Allowed => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for ThumbIsaUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Allowed16Bit,
            2 => Self::Allowed32Bit,
            3 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for ThumbIsaUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Allowed16Bit => write!(f, "16-bit allowed, including BL"),
            Self::Allowed32Bit => write!(f, "32-bit allowed"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum FpArch {
    /// No instructions requiring FP hardware.
    #[default]
    None,
    /// v1 FP ISA is allowed.
    V1,
    /// v2 FP ISA is allowed. Implies use of v1.
    V2,
    /// v3 FP ISA is allowed. Implies use of v2.
    V3,
    /// v3 FP ISA is allowed, but only registers D0-D15 and S0-S31
    V3Light,
    /// v4 FP ISA is allowed. Implies use of v3.
    V4,
    /// v4 FP ISA is allowed, but only registers D0-D15 and S0-S31
    V4Light,
    /// ARMv8-A FP ISA is allowed.
    V8A,
    /// ARMv8-A FP ISA is allowed, but only registers D0-D15 and S0-S31
    V8ALight,
    Unknown(u8),
}

impl FpArch {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::V1 => 1,
            Self::V2 => 2,
            Self::V3 => 3,
            Self::V3Light => 4,
            Self::V4 => 5,
            Self::V4Light => 6,
            Self::V8A => 7,
            Self::V8ALight => 8,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for FpArch {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::V1,
            2 => Self::V2,
            3 => Self::V3,
            4 => Self::V3Light,
            5 => Self::V4,
            6 => Self::V4Light,
            7 => Self::V8A,
            8 => Self::V8ALight,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for FpArch {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::V1 => write!(f, "v1"),
            Self::V2 => write!(f, "v2"),
            Self::V3 => write!(f, "v3"),
            Self::V3Light => write!(f, "v3 light"),
            Self::V4 => write!(f, "v4"),
            Self::V4Light => write!(f, "v4 light"),
            Self::V8A => write!(f, "ARMv8-A"),
            Self::V8ALight => write!(f, "ARMv8-A light"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum WmmxArch {
    /// Not allowed.
    #[default]
    None,
    /// WMMX v1 allowed.
    V1,
    /// WMMX v2 allowed.
    V2,
    Unknown(u8),
}

impl WmmxArch {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::V1 => 1,
            Self::V2 => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for WmmxArch {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::V1,
            2 => Self::V2,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for WmmxArch {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::V1 => write!(f, "v1"),
            Self::V2 => write!(f, "v2"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AsimdArch {
    /// Not allowed.
    #[default]
    None,
    /// Advanced SIMDv1 (Neon) allowed.
    V1,
    /// Advanced SIMDv2 (Neon) allowed.
    V2,
    /// ARMv8-A Advanced SIMD (Neon) allowed.
    V8A,
    /// ARMv8.1-A Advanced SIMD (Neon) allowed.
    V8_1A,
    Unknown(u8),
}

impl AsimdArch {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::V1 => 1,
            Self::V2 => 2,
            Self::V8A => 3,
            Self::V8_1A => 4,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AsimdArch {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::V1,
            2 => Self::V2,
            3 => Self::V8A,
            4 => Self::V8_1A,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AsimdArch {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::V1 => write!(f, "SIMDv1"),
            Self::V2 => write!(f, "SIMDv2"),
            Self::V8A => write!(f, "ARMv8-A"),
            Self::V8_1A => write!(f, "ARMv8.1-A"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum MveArch {
    /// Not allowed.
    #[default]
    None,
    /// Integer M-profile Vector Extension allowed.
    Int,
    /// Integer and Floating Point M-profile Vector Extension allowed.
    IntFloat,
    Unknown(u8),
}

impl MveArch {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Int => 1,
            Self::IntFloat => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for MveArch {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Int,
            2 => Self::IntFloat,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for MveArch {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Int => write!(f, "Integer"),
            Self::IntFloat => write!(f, "Integer and Float"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum FpHpExt {
    /// Half-precision allowed if they exist in the instructions sets indicated by `FpArch` and `AsimdArch`.
    #[default]
    IfExists,
    /// Half-precision allowed as an extension to VFPv3 and ASIMDv1, in addition to those indicated by `FpArch` and
    /// `AsimdArch`.
    VfpV3,
    /// Half-precision allowed as an extension to ARMv8.2-A and ASIMD, in addition to those indicated by `FpArch` and
    /// `AsimdArch`.
    ArmV8_2A,
    Unknown(u8),
}

impl FpHpExt {
    pub fn value(self) -> u8 {
        match self {
            Self::IfExists => 0,
            Self::VfpV3 => 1,
            Self::ArmV8_2A => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for FpHpExt {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::IfExists,
            1 => Self::VfpV3,
            2 => Self::ArmV8_2A,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for FpHpExt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::IfExists => write!(f, "If exists"),
            Self::VfpV3 => write!(f, "VFPv3"),
            Self::ArmV8_2A => write!(f, "ARMv8.2-A"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum CpuUnalignedAccess {
    /// Not allowed.
    #[default]
    None,
    /// v6-style unaligned data accesses allowed.
    Allowed,
    Unknown(u8),
}

impl CpuUnalignedAccess {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Allowed => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for CpuUnalignedAccess {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for CpuUnalignedAccess {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum T2EeUse {
    /// Not allowed.
    #[default]
    None,
    /// The T2EE extension is allowed.
    Allowed,
    Unknown(u8),
}

impl T2EeUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Allowed => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for T2EeUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for T2EeUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum VirtualUse {
    /// Not allowed.
    #[default]
    None,
    /// The TrustZone extension is allowed.
    TrustZone,
    /// Virtualization extensions (HVC, ERET) are allowed.
    VExts,
    /// The TrustZone and virtualization extensions are allowed.
    TrustZoneVExts,
    Unknown(u8),
}

impl VirtualUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::TrustZone => 1,
            Self::VExts => 2,
            Self::TrustZoneVExts => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for VirtualUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::TrustZone,
            2 => Self::VExts,
            3 => Self::TrustZoneVExts,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for VirtualUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::TrustZone => write!(f, "TrustZone"),
            Self::VExts => write!(f, "Virtual exts"),
            Self::TrustZoneVExts => write!(f, "TrustZone and virtual exts"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum MpExtUse {
    // Not allowed.
    #[default]
    None,
    // Use of the ARMv7 MP extension is allowed.
    Allowed,
    Unknown(u8),
}

impl MpExtUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Allowed => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for MpExtUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for MpExtUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum DivUse {
    /// Divide instructions may be used if they exist in the architecture, as indicated by `CpuArch` and `CpuArchProfile`.
    #[default]
    IfExists,
    /// Not allowed.
    None,
    /// Allowed.
    Allowed,
    Unknown(u8),
}

impl DivUse {
    pub fn value(self) -> u8 {
        match self {
            Self::IfExists => 0,
            Self::None => 1,
            Self::Allowed => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for DivUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::IfExists,
            1 => Self::None,
            2 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for DivUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::IfExists => write!(f, "If exists"),
            Self::None => write!(f, "None"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum DspExt {
    /// DSP instructions may be used if they exist in the architecture, as indicated by `CpuArch`.
    #[default]
    IfExists,
    /// DSP instructions are allowed.
    Allowed,
    Unknown(u8),
}

impl DspExt {
    pub fn value(self) -> u8 {
        match self {
            Self::IfExists => 0,
            Self::Allowed => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for DspExt {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::IfExists,
            1 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for DspExt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::IfExists => write!(f, "If exists"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum PacExt {
    /// Not allowed.
    #[default]
    None,
    /// PAC/AUT instructions are allowed in the NOP space.
    OnlyNopSpace,
    /// PAC/AUT instructions are allowed.
    Allowed,
    Unknown(u8),
}

impl PacExt {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::OnlyNopSpace => 1,
            Self::Allowed => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for PacExt {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::OnlyNopSpace,
            2 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for PacExt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::OnlyNopSpace => write!(f, "Only NOP space"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum BtiExt {
    /// Not allowed.
    #[default]
    None,
    /// BTI instructions are allowed in the NOP space.
    OnlyNopSpace,
    /// BTI instructions are allowed.
    Allowed,
    Unknown(u8),
}

impl BtiExt {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::OnlyNopSpace => 1,
            Self::Allowed => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for BtiExt {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::OnlyNopSpace,
            2 => Self::Allowed,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for BtiExt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::OnlyNopSpace => write!(f, "Only NOP space"),
            Self::Allowed => write!(f, "Allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

/// Procedure-call standard (PCS) configuration
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum PcsConfig {
    /// No standard configuration used.
    #[default]
    None,
    BarePlatform,
    LinuxApplication,
    LinuxDso,
    PalmOs2004,
    /// Reserved for future Palm OS configuration.
    PalmOsFuture,
    SymbianOs2004,
    /// Reserved for future Symbian OS configuration.
    SymbianOsFuture,
    Unknown(u8),
}

impl PcsConfig {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::BarePlatform => 1,
            Self::LinuxApplication => 2,
            Self::LinuxDso => 3,
            Self::PalmOs2004 => 4,
            Self::PalmOsFuture => 5,
            Self::SymbianOs2004 => 6,
            Self::SymbianOsFuture => 7,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for PcsConfig {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::BarePlatform,
            2 => Self::LinuxApplication,
            3 => Self::LinuxDso,
            4 => Self::PalmOs2004,
            5 => Self::PalmOsFuture,
            6 => Self::SymbianOs2004,
            7 => Self::SymbianOsFuture,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for PcsConfig {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::BarePlatform => write!(f, "Bare platform"),
            Self::LinuxApplication => write!(f, "Linux application"),
            Self::LinuxDso => write!(f, "Linux DSO"),
            Self::PalmOs2004 => write!(f, "Palm OS 2004"),
            Self::PalmOsFuture => write!(f, "Future Palm OS"),
            Self::SymbianOs2004 => write!(f, "Symbian OS 2004"),
            Self::SymbianOsFuture => write!(f, "Future Symbian OS"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiPcsR9Use {
    /// R9 used as V6, a callee-saved register.
    #[default]
    V6,
    /// R9 used as SB, a global Static Base register.
    Sb,
    /// R9 used as a Thread Local Storage (TLS) pointer.
    TlsPointer,
    /// R9 not used.
    None,
    Unknown(u8),
}

impl AbiPcsR9Use {
    pub fn value(self) -> u8 {
        match self {
            Self::V6 => 0,
            Self::Sb => 1,
            Self::TlsPointer => 2,
            Self::None => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiPcsR9Use {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::V6,
            1 => Self::Sb,
            2 => Self::TlsPointer,
            3 => Self::None,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiPcsR9Use {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::V6 => write!(f, "V6"),
            Self::Sb => write!(f, "SB"),
            Self::TlsPointer => write!(f, "TLS pointer"),
            Self::None => write!(f, "None"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiPcsRwData {
    /// RW static data is allowed to be addressed absolutely.
    #[default]
    Abs,
    /// RW static data is allowed to be addressed PC-relative.
    PcRel,
    /// RW static data is allowed to be addressed SB-relative.
    SbRel,
    /// Not allowed.
    None,
    Unknown(u8),
}

impl AbiPcsRwData {
    pub fn value(self) -> u8 {
        match self {
            Self::Abs => 0,
            Self::PcRel => 1,
            Self::SbRel => 2,
            Self::None => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiPcsRwData {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::Abs,
            1 => Self::PcRel,
            2 => Self::SbRel,
            3 => Self::None,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiPcsRwData {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Abs => write!(f, "Absolute"),
            Self::PcRel => write!(f, "PC-relative"),
            Self::SbRel => write!(f, "SB-relative"),
            Self::None => write!(f, "Not allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiPcsRoData {
    /// RO static data is allowed to be addressed absolutely.
    #[default]
    Abs,
    /// RO static data is allowed to be addressed PC-relative.
    PcRel,
    /// Not allowed.
    None,
    Unknown(u8),
}

impl AbiPcsRoData {
    pub fn value(self) -> u8 {
        match self {
            Self::Abs => 0,
            Self::PcRel => 1,
            Self::None => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiPcsRoData {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::Abs,
            1 => Self::PcRel,
            2 => Self::None,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiPcsRoData {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Abs => write!(f, "Absolute"),
            Self::PcRel => write!(f, "PC-relative"),
            Self::None => write!(f, "Not allowed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiPcsGotUse {
    /// Not allowed.
    #[default]
    None,
    /// Imported data is allowed to be addressed directly.
    Direct,
    /// Imported data is allowed to be addressed indirectly.
    Indirect,
    Unknown(u8),
}

impl AbiPcsGotUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Direct => 1,
            Self::Indirect => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiPcsGotUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Direct,
            2 => Self::Indirect,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiPcsGotUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "Not allowed"),
            Self::Direct => write!(f, "Direct"),
            Self::Indirect => write!(f, "Indirect"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiPcsWcharT {
    /// Not allowed.
    #[default]
    None,
    /// wchar_t of size 2 allowed.
    Size2,
    /// wchar_T of size 4 allowed.
    Size4,
    Unknown(u8),
}

impl AbiPcsWcharT {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Size2 => 2,
            Self::Size4 => 4,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiPcsWcharT {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            2 => Self::Size2,
            4 => Self::Size4,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiPcsWcharT {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "Not allowed"),
            Self::Size2 => write!(f, "16-bit"),
            Self::Size4 => write!(f, "32-bit"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiEnumSize {
    /// Not allowed.
    #[default]
    None,
    /// Enums are as small as possible while big enough to contain all values.
    SmallestSize,
    /// Enums are always 32-bits.
    Always32,
    /// Enums visible across an ABI-complying interface are 32-bits.
    Visible32,
    Unknown(u8),
}

impl AbiEnumSize {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::SmallestSize => 1,
            Self::Always32 => 2,
            Self::Visible32 => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiEnumSize {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::SmallestSize,
            2 => Self::Always32,
            3 => Self::Visible32,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiEnumSize {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "Not allowed"),
            Self::SmallestSize => write!(f, "Smallest size"),
            Self::Always32 => write!(f, "32-bit"),
            Self::Visible32 => write!(f, "32-bit when exposed"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiAlignNeeded {
    /// Code does not depend on alignment of 8-byte data or data with extended alignment (> 8-byte).
    #[default]
    None,
    /// Code depends on 8-byte alignment of 8-byte data.
    Align8,
    /// Code depends on 4-byte alignment of 8-byte data.
    Align4,
    /// Reserved.
    Reserved,
    /// Code depends on 8-byte alignment of 8-byte data and alignment of data having up to 2n-byte extended alignment, where n
    /// is in \[4..12\].
    Align2n(u8),
    Unknown(u8),
}

impl AbiAlignNeeded {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Align8 => 1,
            Self::Align4 => 2,
            Self::Reserved => 3,
            Self::Align2n(value) => value,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiAlignNeeded {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Align8,
            2 => Self::Align4,
            3 => Self::Reserved,
            4..=12 => Self::Align2n(value),
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiAlignNeeded {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Align8 => write!(f, "8-byte"),
            Self::Align4 => write!(f, "4-byte"),
            Self::Reserved => write!(f, "Reserved"),
            Self::Align2n(value) => write!(f, "8-byte, {}-byte extended", 2 * value),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiAlignPreserved {
    /// Code does not preserve alignment of 8-byte data or data with extended alignment (> 8-byte).
    #[default]
    None,
    /// Code preserves 8-byte alignment of 8-byte data.
    Align8,
    /// Code preserves 4-byte alignment of 8-byte data.
    Align4,
    /// Reserved.
    Reserved,
    /// Code preserves 8-byte alignment of 8-byte data and alignmentt of data having up to 2n-byte extended alignment, where n
    /// is in \[4..12\].
    Align2n(u8),
    Unknown(u8),
}

impl AbiAlignPreserved {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Align8 => 1,
            Self::Align4 => 2,
            Self::Reserved => 3,
            Self::Align2n(value) => value,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiAlignPreserved {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Align8,
            2 => Self::Align4,
            3 => Self::Reserved,
            4..=12 => Self::Align2n(value),
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiAlignPreserved {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Align8 => write!(f, "8-byte"),
            Self::Align4 => write!(f, "4-byte"),
            Self::Reserved => write!(f, "Reserved"),
            Self::Align2n(value) => write!(f, "8-byte, {}-byte extended", 2 * value),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFpRounding {
    /// The code uses IEEE-754 round-to-nearest rounding mode.
    #[default]
    Nearest,
    /// The code decides IEEE-754 rounding modea at run-time.
    RunTime,
    Unknown(u8),
}

impl AbiFpRounding {
    pub fn value(self) -> u8 {
        match self {
            Self::Nearest => 0,
            Self::RunTime => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFpRounding {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::Nearest,
            1 => Self::RunTime,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFpRounding {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Nearest => write!(f, "Nearest"),
            Self::RunTime => write!(f, "Decides at run-time"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFpDenormal {
    /// Denormal numbers might be flushed to (+) zero.
    #[default]
    DontCare,
    /// The code depends on IEEE-754 denormal numbers.
    Ieee754,
    /// The code depends on the sign being preserved when flushed to zero.
    PreserveSign,
    Unknown(u8),
}

impl AbiFpDenormal {
    pub fn value(self) -> u8 {
        match self {
            Self::DontCare => 0,
            Self::Ieee754 => 1,
            Self::PreserveSign => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFpDenormal {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::DontCare,
            1 => Self::Ieee754,
            2 => Self::PreserveSign,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFpDenormal {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::DontCare => write!(f, "Don't care"),
            Self::Ieee754 => write!(f, "Depends on IEEE-754 denormal numbers"),
            Self::PreserveSign => write!(f, "Preserve sign"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFpExceptions {
    /// The code should not check for inexact results.
    #[default]
    None,
    /// The code checks for the IEEE-754 inexact exception.
    CheckInexact,
    Unknown(u8),
}

impl AbiFpExceptions {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::CheckInexact => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFpExceptions {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::CheckInexact,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFpExceptions {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::CheckInexact => write!(f, "IEEE-754 inexact exception"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFpUserExceptions {
    /// The code should not enable or use IEEE-754 user exceptions.
    #[default]
    None,
    /// The code uses IEEE-754 user exceptions.
    Enabled,
    Unknown(u8),
}

impl AbiFpUserExceptions {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Enabled => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFpUserExceptions {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Enabled,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFpUserExceptions {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Enabled => write!(f, "Enabled"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFpNumberModel {
    /// The code does not use floating point numbers.
    #[default]
    None,
    /// The code allows the IEEE-754 normal numbers only.
    Normal,
    /// The code allows normal numbers, infinities, and one quiet NaN.
    InfNaN,
    /// The code allows all float encodings defined by IEEE-754.
    All,
    Unknown(u8),
}

impl AbiFpNumberModel {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Normal => 1,
            Self::InfNaN => 2,
            Self::All => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFpNumberModel {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Normal,
            2 => Self::InfNaN,
            3 => Self::All,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFpNumberModel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Normal => write!(f, "Normal numbers"),
            Self::InfNaN => write!(f, "Normal numbers, infinities and NaN"),
            Self::All => write!(f, "All numbers"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFp16BitFormat {
    /// The code does not use 16-bit floats.
    #[default]
    None,
    /// The code uses the IEEE-754 format for 16-bit floats.
    Ieee754,
    /// The code uses the VFPv3/ASIMD alternative format for 16-bit floats.
    Alternative,
    Unknown(u8),
}

impl AbiFp16BitFormat {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Ieee754 => 1,
            Self::Alternative => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFp16BitFormat {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Ieee754,
            2 => Self::Alternative,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFp16BitFormat {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Ieee754 => write!(f, "IEEE-754 format"),
            Self::Alternative => write!(f, "Alternative format"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiHardFpUse {
    /// Floating point use is implied by `FpArch`.
    #[default]
    Implied,
    /// The code executes on the single-precision variant derived from `FpArch`.
    DerivedSingle,
    /// Reserved.
    Reserved,
    /// Deprecated: Use `Implied` instead.
    ImpliedOld,
    Unknown(u8),
}

impl AbiHardFpUse {
    pub fn value(self) -> u8 {
        match self {
            Self::Implied => 0,
            Self::DerivedSingle => 1,
            Self::Reserved => 2,
            Self::ImpliedOld => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiHardFpUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::Implied,
            1 => Self::DerivedSingle,
            2 => Self::Reserved,
            3 => Self::ImpliedOld,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiHardFpUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Implied => write!(f, "Implied"),
            Self::DerivedSingle => write!(f, "Derived single-precision"),
            Self::Reserved => write!(f, "Reserved"),
            Self::ImpliedOld => write!(f, "Implied (deprecated)"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiVfpArgs {
    /// Float parameter/result passing conforms to AAPCS, base variant.
    #[default]
    Base,
    /// Float parameter/result passing conforms to AAPCS, VFP variant.
    Vfp,
    /// Float parameter/result passing conforms to toolchain-specific conventions.
    Toolchain,
    /// Code is compatible with both the base and VFP variants. Non-variadic functions are not allowed to pass float
    /// parameters/results.
    BaseVfp,
    Unknown(u8),
}

impl AbiVfpArgs {
    pub fn value(self) -> u8 {
        match self {
            Self::Base => 0,
            Self::Vfp => 1,
            Self::Toolchain => 2,
            Self::BaseVfp => 3,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiVfpArgs {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::Base,
            1 => Self::Vfp,
            2 => Self::Toolchain,
            3 => Self::BaseVfp,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiVfpArgs {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Base => write!(f, "Base variant"),
            Self::Vfp => write!(f, "VFP variant"),
            Self::Toolchain => write!(f, "Toolchain-specific"),
            Self::BaseVfp => write!(f, "Base and VFP variants"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiWmmxArgs {
    /// WMMX parameter/result passing conforms to AAPCS, base variant.
    #[default]
    Base,
    /// WMMX parameter/result passing conforms to Intel's WMMX conventions.
    Intel,
    /// WMMX parameter/result passing conforms to toolchain-specific conventions.
    Toolchain,
    Unknown(u8),
}

impl AbiWmmxArgs {
    pub fn value(self) -> u8 {
        match self {
            Self::Base => 0,
            Self::Intel => 1,
            Self::Toolchain => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiWmmxArgs {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::Base,
            1 => Self::Intel,
            2 => Self::Toolchain,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiWmmxArgs {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Base => write!(f, "Base variant"),
            Self::Intel => write!(f, "Intel conventions"),
            Self::Toolchain => write!(f, "Toolchain-specific"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum FramePointerUse {
    /// The code does not conform to the rules of using the frame pointer.
    #[default]
    None,
    /// The code creates a frame record for all functions that can modify the link register (LR).
    WithRecords,
    /// The codes does not create records, but preserves the frame pointer register (FP) value.
    WithoutRecords,
    Unknown(u8),
}

impl FramePointerUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::WithRecords => 1,
            Self::WithoutRecords => 2,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for FramePointerUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::WithRecords,
            2 => Self::WithoutRecords,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for FramePointerUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::WithRecords => write!(f, "With frame records"),
            Self::WithoutRecords => write!(f, "Without frame records"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum BtiUse {
    /// The code is compiled without branch target enforcement.
    #[default]
    None,
    /// The code is compiled with branch target enforcement.
    Enabled,
    Unknown(u8),
}

impl BtiUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Enabled => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for BtiUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Enabled,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for BtiUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Enabled => write!(f, "Enabled"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum PacretUse {
    /// The code is compiled without return address signing and authentication.
    #[default]
    None,
    /// The code is compiled with return address signing and authentication.
    Enabled,
    Unknown(u8),
}

impl PacretUse {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::Enabled => 1,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for PacretUse {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Enabled,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for PacretUse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::Enabled => write!(f, "Enabled"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiOptGoals {
    /// The code has no optimization goals.
    #[default]
    None,
    /// Favor speed, preserve small size and debug experience.
    FavorSpeed,
    /// Optimize aggressively for speed, sacrifice small size and debug experience.
    OptimizeSpeed,
    /// Favor size, preserve for speed and debug experience.
    FavorSize,
    /// Optimize aggressively for size, sacrifice speed and debug experience.
    OptimizeSize,
    /// Favor debug experience, preserve speed and small size.
    FavorDebug,
    /// Optimize aggressively for debug experience, but sacrifice speed and small size.
    OptimizeDebug,
    Unknown(u8),
}

impl AbiOptGoals {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::FavorSpeed => 1,
            Self::OptimizeSpeed => 2,
            Self::FavorSize => 3,
            Self::OptimizeSize => 4,
            Self::FavorDebug => 5,
            Self::OptimizeDebug => 6,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiOptGoals {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::FavorSpeed,
            2 => Self::OptimizeSpeed,
            3 => Self::FavorSize,
            4 => Self::OptimizeSize,
            5 => Self::FavorDebug,
            6 => Self::OptimizeDebug,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiOptGoals {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::FavorSpeed => write!(f, "Favor speed, preserve size and debug"),
            Self::OptimizeSpeed => write!(f, "Optimize speed, sacrifice size and debug"),
            Self::FavorSize => write!(f, "Favor size, preserve speed and debug"),
            Self::OptimizeSize => write!(f, "Optimize size, sacrifice size and debug"),
            Self::FavorDebug => write!(f, "Favor debug, preserve speed and size"),
            Self::OptimizeDebug => write!(f, "Optimize debug, sacrifice speed and size"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum AbiFpOptGoals {
    /// The code has no FP optimization goals.
    #[default]
    None,
    /// Favor speed, preserve small size and accuracy.
    FavorSpeed,
    /// Optimize aggressively for speed, sacrifice small size and accuracy.
    OptimizeSpeed,
    /// Favor size, preserve for speed and accuracy.
    FavorSize,
    /// Optimize aggressively for size, sacrifice speed and accuracy.
    OptimizeSize,
    /// Favor accuracy, preserve speed and small size.
    FavorAccuracy,
    /// Optimize aggressively for accuracy, but sacrifice speed and small size.
    OptimizeAccuracy,
    Unknown(u8),
}

impl AbiFpOptGoals {
    pub fn value(self) -> u8 {
        match self {
            Self::None => 0,
            Self::FavorSpeed => 1,
            Self::OptimizeSpeed => 2,
            Self::FavorSize => 3,
            Self::OptimizeSize => 4,
            Self::FavorAccuracy => 5,
            Self::OptimizeAccuracy => 6,
            Self::Unknown(value) => value,
        }
    }
}

impl From<u8> for AbiFpOptGoals {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::None,
            1 => Self::FavorSpeed,
            2 => Self::OptimizeSpeed,
            3 => Self::FavorSize,
            4 => Self::OptimizeSize,
            5 => Self::FavorAccuracy,
            6 => Self::OptimizeAccuracy,
            _ => Self::Unknown(value),
        }
    }
}

impl Display for AbiFpOptGoals {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::FavorSpeed => write!(f, "Favor speed, preserve size and accuracy"),
            Self::OptimizeSpeed => write!(f, "Optimize speed, sacrifice size and accuracy"),
            Self::FavorSize => write!(f, "Favor size, preserve speed and accuracy"),
            Self::OptimizeSize => write!(f, "Optimize size, sacrifice size and accuracy"),
            Self::FavorAccuracy => write!(f, "Favor accuracy, preserve speed and size"),
            Self::OptimizeAccuracy => write!(f, "Optimize accuracy, sacrifice speed and size"),
            Self::Unknown(value) => write!(f, "<unknown: {:#x}>", value),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum Compat<'a> {
    /// This entity has no toolchain-specific requirements.
    #[default]
    Always,
    /// This entity conforms to the ABI when built by the given toolchain.
    ByToolchain(&'a str),
    /// This entity does not conform to the ABI, but can be used privately by given flag and vendor name.
    Private { flag: u8, vendor: &'a str },
}

impl<'a> Compat<'a> {
    pub fn new(flag: u8, vendor: &'a str) -> Self {
        match flag {
            0 => Self::Always,
            1 => Self::ByToolchain(vendor),
            _ => Self::Private { flag, vendor },
        }
    }

    pub fn value(&self) -> u8 {
        match self {
            Self::Always => 0,
            Self::ByToolchain(_) => 1,
            Self::Private { flag, vendor: _ } => *flag,
        }
    }
}

impl<'a> Display for Compat<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Always => write!(f, "Always"),
            Self::ByToolchain(toolchain) => write!(f, "By toolchain '{}'", toolchain),
            Self::Private { flag, vendor } => write!(f, "Private, flag = {}, vendor = '{}'", flag, vendor),
        }
    }
}

#[derive(Clone, PartialEq, Eq, Debug, Hash, Default)]
pub enum AlsoCompatWith<'a> {
    #[default]
    None,
    Arch(CpuArch),
    Reserved(Box<Tag<'a>>),
}

impl<'a> AlsoCompatWith<'a> {
    pub fn new(tag: Tag<'a>) -> Self {
        match tag {
            Tag::CpuArch(arch) => Self::Arch(arch),
            _ => Self::Reserved(Box::new(tag)),
        }
    }
}

impl<'a> Display for AlsoCompatWith<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "Nothing"),
            Self::Arch(arch) => write!(f, "{}", arch),
            Self::Reserved(tag) => write!(f, "<reserved: {:?}>", tag),
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
pub enum Conform<'a> {
    #[default]
    None,
    V2023Q3,
    Unknown(&'a str),
}

impl<'a> From<&'a str> for Conform<'a> {
    fn from(value: &'a str) -> Self {
        match value {
            "2023Q3" => Self::V2023Q3,
            _ => Self::Unknown(value),
        }
    }
}

impl<'a> Display for Conform<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::None => write!(f, "None"),
            Self::V2023Q3 => write!(f, "2023Q3"),
            Self::Unknown(value) => write!(f, "<unknown: {}>", value),
        }
    }
}