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
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . S T R E A M _ A T T R I B U T E S . X D R --
-- --
-- B o d y --
-- --
-- Copyright (C) 1996-2022, Free Software Foundation, Inc. --
-- --
-- GARLIC is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.IO_Exceptions;
with Ada.Streams; use Ada.Streams;
with Ada.Unchecked_Conversion;
package body System.Stream_Attributes.XDR is
pragma Suppress (Range_Check);
pragma Suppress (Overflow_Check);
use UST;
Data_Error : exception renames Ada.IO_Exceptions.End_Error;
-- Exception raised if insufficient data read (End_Error is mandated by
-- AI95-00132).
SU : constant := System.Storage_Unit;
-- The code in this body assumes that SU = 8
BB : constant := 2 ** SU; -- Byte base
BL : constant := 2 ** SU - 1; -- Byte last
BS : constant := 2 ** (SU - 1); -- Byte sign
US : constant := Unsigned'Size; -- Unsigned size
UB : constant := (US - 1) / SU + 1; -- Unsigned byte
UL : constant := 2 ** US - 1; -- Unsigned last
subtype SE is Ada.Streams.Stream_Element;
subtype SEA is Ada.Streams.Stream_Element_Array;
subtype SEO is Ada.Streams.Stream_Element_Offset;
type Field_Type is record
E_Size : Integer; -- Exponent bit size
E_Bias : Integer; -- Exponent bias
F_Size : Integer; -- Fraction bit size
E_Last : Integer; -- Max exponent value
F_Mask : SE; -- Mask to apply on first fraction byte
E_Bytes : SEO; -- N. of exponent bytes completely used
F_Bytes : SEO; -- N. of fraction bytes completely used
F_Bits : Integer; -- N. of bits used on first fraction word
end record;
type Precision is (Single, Double, Quadruple);
Fields : constant array (Precision) of Field_Type := [
-- Single precision
[E_Size => 8,
E_Bias => 127,
F_Size => 23,
E_Last => 2 ** 8 - 1,
F_Mask => 16#7F#, -- 2 ** 7 - 1,
E_Bytes => 2,
F_Bytes => 3,
F_Bits => 23 mod US],
-- Double precision
[E_Size => 11,
E_Bias => 1023,
F_Size => 52,
E_Last => 2 ** 11 - 1,
F_Mask => 16#0F#, -- 2 ** 4 - 1,
E_Bytes => 2,
F_Bytes => 7,
F_Bits => 52 mod US],
-- Quadruple precision
[E_Size => 15,
E_Bias => 16383,
F_Size => 112,
E_Last => 2 ** 8 - 1,
F_Mask => 16#FF#, -- 2 ** 8 - 1,
E_Bytes => 2,
F_Bytes => 14,
F_Bits => 112 mod US]];
-- The representation of all items requires a multiple of four bytes
-- (or 32 bits) of data. The bytes are numbered 0 through n-1. The bytes
-- are read or written to some byte stream such that byte m always
-- precedes byte m+1. If the n bytes needed to contain the data are not
-- a multiple of four, then the n bytes are followed by enough (0 to 3)
-- residual zero bytes, r, to make the total byte count a multiple of 4.
-- An XDR signed integer is a 32-bit datum that encodes an integer
-- in the range [-2147483648,2147483647]. The integer is represented
-- in two's complement notation. The most and least significant bytes
-- are 0 and 3, respectively. Integers are declared as follows:
-- (MSB) (LSB)
-- +-------+-------+-------+-------+
-- |byte 0 |byte 1 |byte 2 |byte 3 |
-- +-------+-------+-------+-------+
-- <------------32 bits------------>
SSI_L : constant := 1;
SI_L : constant := 2;
I24_L : constant := 3;
I_L : constant := 4;
LI_L : constant := 8;
LLI_L : constant := 8;
subtype XDR_S_SSI is SEA (1 .. SSI_L);
subtype XDR_S_SI is SEA (1 .. SI_L);
subtype XDR_S_I24 is SEA (1 .. I24_L);
subtype XDR_S_I is SEA (1 .. I_L);
subtype XDR_S_LI is SEA (1 .. LI_L);
subtype XDR_S_LLI is SEA (1 .. LLI_L);
function Short_Short_Integer_To_XDR_S_SSI is
new Ada.Unchecked_Conversion (Short_Short_Integer, XDR_S_SSI);
function XDR_S_SSI_To_Short_Short_Integer is
new Ada.Unchecked_Conversion (XDR_S_SSI, Short_Short_Integer);
function Short_Integer_To_XDR_S_SI is
new Ada.Unchecked_Conversion (Short_Integer, XDR_S_SI);
function XDR_S_SI_To_Short_Integer is
new Ada.Unchecked_Conversion (XDR_S_SI, Short_Integer);
function Integer_To_XDR_S_I24 is
new Ada.Unchecked_Conversion (Integer_24, XDR_S_I24);
function XDR_S_I24_To_Integer is
new Ada.Unchecked_Conversion (XDR_S_I24, Integer_24);
function Integer_To_XDR_S_I is
new Ada.Unchecked_Conversion (Integer, XDR_S_I);
function XDR_S_I_To_Integer is
new Ada.Unchecked_Conversion (XDR_S_I, Integer);
function Long_Long_Integer_To_XDR_S_LI is
new Ada.Unchecked_Conversion (Long_Long_Integer, XDR_S_LI);
function XDR_S_LI_To_Long_Long_Integer is
new Ada.Unchecked_Conversion (XDR_S_LI, Long_Long_Integer);
function Long_Long_Integer_To_XDR_S_LLI is
new Ada.Unchecked_Conversion (Long_Long_Integer, XDR_S_LLI);
function XDR_S_LLI_To_Long_Long_Integer is
new Ada.Unchecked_Conversion (XDR_S_LLI, Long_Long_Integer);
-- An XDR unsigned integer is a 32-bit datum that encodes a nonnegative
-- integer in the range [0,4294967295]. It is represented by an unsigned
-- binary number whose most and least significant bytes are 0 and 3,
-- respectively. An unsigned integer is declared as follows:
-- (MSB) (LSB)
-- +-------+-------+-------+-------+
-- |byte 0 |byte 1 |byte 2 |byte 3 |
-- +-------+-------+-------+-------+
-- <------------32 bits------------>
SSU_L : constant := 1;
SU_L : constant := 2;
U24_L : constant := 3;
U_L : constant := 4;
LU_L : constant := 8;
LLU_L : constant := 8;
subtype XDR_S_SSU is SEA (1 .. SSU_L);
subtype XDR_S_SU is SEA (1 .. SU_L);
subtype XDR_S_U24 is SEA (1 .. U24_L);
subtype XDR_S_U is SEA (1 .. U_L);
subtype XDR_S_LU is SEA (1 .. LU_L);
subtype XDR_S_LLU is SEA (1 .. LLU_L);
type XDR_SSU is mod BB ** SSU_L;
type XDR_SU is mod BB ** SU_L;
type XDR_U is mod BB ** U_L;
type XDR_U24 is mod BB ** U24_L;
function Short_Unsigned_To_XDR_S_SU is
new Ada.Unchecked_Conversion (Short_Unsigned, XDR_S_SU);
function XDR_S_SU_To_Short_Unsigned is
new Ada.Unchecked_Conversion (XDR_S_SU, Short_Unsigned);
function Unsigned_To_XDR_S_U24 is
new Ada.Unchecked_Conversion (Unsigned_24, XDR_S_U24);
function XDR_S_U24_To_Unsigned is
new Ada.Unchecked_Conversion (XDR_S_U24, Unsigned_24);
function Unsigned_To_XDR_S_U is
new Ada.Unchecked_Conversion (Unsigned, XDR_S_U);
function XDR_S_U_To_Unsigned is
new Ada.Unchecked_Conversion (XDR_S_U, Unsigned);
function Long_Long_Unsigned_To_XDR_S_LU is
new Ada.Unchecked_Conversion (Long_Long_Unsigned, XDR_S_LU);
function XDR_S_LU_To_Long_Long_Unsigned is
new Ada.Unchecked_Conversion (XDR_S_LU, Long_Long_Unsigned);
function Long_Long_Unsigned_To_XDR_S_LLU is
new Ada.Unchecked_Conversion (Long_Long_Unsigned, XDR_S_LLU);
function XDR_S_LLU_To_Long_Long_Unsigned is
new Ada.Unchecked_Conversion (XDR_S_LLU, Long_Long_Unsigned);
-- The standard defines the floating-point data type "float" (32 bits
-- or 4 bytes). The encoding used is the IEEE standard for normalized
-- single-precision floating-point numbers.
-- The standard defines the encoding used for the double-precision
-- floating-point data type "double" (64 bits or 8 bytes). The encoding
-- used is the IEEE standard for normalized double-precision floating-point
-- numbers.
SF_L : constant := 4; -- Single precision
F_L : constant := 4; -- Single precision
LF_L : constant := 8; -- Double precision
LLF_L : constant := 16; -- Quadruple precision
TM_L : constant := 8;
subtype XDR_S_TM is SEA (1 .. TM_L);
type XDR_TM is mod BB ** TM_L;
type XDR_SA is mod 2 ** Standard'Address_Size;
function To_XDR_SA is new Ada.Unchecked_Conversion (System.Address, XDR_SA);
function To_XDR_SA is new Ada.Unchecked_Conversion (XDR_SA, System.Address);
-- Enumerations have the same representation as signed integers.
-- Enumerations are handy for describing subsets of the integers.
-- Booleans are important enough and occur frequently enough to warrant
-- their own explicit type in the standard. Booleans are declared as
-- an enumeration, with FALSE = 0 and TRUE = 1.
-- The standard defines a string of n (numbered 0 through n-1) ASCII
-- bytes to be the number n encoded as an unsigned integer (as described
-- above), and followed by the n bytes of the string. Byte m of the string
-- always precedes byte m+1 of the string, and byte 0 of the string always
-- follows the string's length. If n is not a multiple of four, then the
-- n bytes are followed by enough (0 to 3) residual zero bytes, r, to make
-- the total byte count a multiple of four.
-- To fit with XDR string, do not consider character as an enumeration
-- type.
C_L : constant := 1;
subtype XDR_S_C is SEA (1 .. C_L);
-- Consider Wide_Character as an enumeration type
WC_L : constant := 4;
subtype XDR_S_WC is SEA (1 .. WC_L);
type XDR_WC is mod BB ** WC_L;
-- Consider Wide_Wide_Character as an enumeration type
WWC_L : constant := 8;
subtype XDR_S_WWC is SEA (1 .. WWC_L);
type XDR_WWC is mod BB ** WWC_L;
-- Optimization: if we already have the correct Bit_Order, then some
-- computations can be avoided since the source and the target will be
-- identical anyway. They will be replaced by direct unchecked
-- conversions.
Optimize_Integers : constant Boolean :=
Default_Bit_Order = High_Order_First;
----------
-- I_AD --
----------
function I_AD (Stream : not null access RST) return Fat_Pointer is
FP : Fat_Pointer;
begin
FP.P1 := I_AS (Stream).P1;
FP.P2 := I_AS (Stream).P1;
return FP;
end I_AD;
----------
-- I_AS --
----------
function I_AS (Stream : not null access RST) return Thin_Pointer is
S : XDR_S_TM;
L : SEO;
U : XDR_TM := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
else
for N in S'Range loop
U := U * BB + XDR_TM (S (N));
end loop;
return (P1 => To_XDR_SA (XDR_SA (U)));
end if;
end I_AS;
---------
-- I_B --
---------
function I_B (Stream : not null access RST) return Boolean is
begin
case I_SSU (Stream) is
when 0 => return False;
when 1 => return True;
when others => raise Data_Error;
end case;
end I_B;
---------
-- I_C --
---------
function I_C (Stream : not null access RST) return Character is
S : XDR_S_C;
L : SEO;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
else
-- Use Ada requirements on Character representation clause
return Character'Val (S (1));
end if;
end I_C;
---------
-- I_F --
---------
function I_F (Stream : not null access RST) return Float is
I : constant Precision := Single;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Last : Integer renames Fields (I).E_Last;
F_Mask : SE renames Fields (I).F_Mask;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
Is_Positive : Boolean;
Exponent : Long_Unsigned;
Fraction : Long_Unsigned;
Result : Float;
S : SEA (1 .. F_L);
L : SEO;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
end if;
-- Extract Fraction, Sign and Exponent
Fraction := Long_Unsigned (S (F_L + 1 - F_Bytes) and F_Mask);
for N in F_L + 2 - F_Bytes .. F_L loop
Fraction := Fraction * BB + Long_Unsigned (S (N));
end loop;
Result := Float'Scaling (Float (Fraction), -F_Size);
if BS <= S (1) then
Is_Positive := False;
Exponent := Long_Unsigned (S (1) - BS);
else
Is_Positive := True;
Exponent := Long_Unsigned (S (1));
end if;
for N in 2 .. E_Bytes loop
Exponent := Exponent * BB + Long_Unsigned (S (N));
end loop;
Exponent := Shift_Right (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
-- NaN or Infinities
if Integer (Exponent) = E_Last then
raise Constraint_Error;
elsif Exponent = 0 then
-- Signed zeros
if Fraction = 0 then
null;
-- Denormalized float
else
Result := Float'Scaling (Result, 1 - E_Bias);
end if;
-- Normalized float
else
Result := Float'Scaling
(1.0 + Result, Integer (Exponent) - E_Bias);
end if;
if not Is_Positive then
Result := -Result;
end if;
return Result;
end I_F;
---------
-- I_I --
---------
function I_I (Stream : not null access RST) return Integer is
S : XDR_S_I;
L : SEO;
U : XDR_U := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_I_To_Integer (S);
else
for N in S'Range loop
U := U * BB + XDR_U (S (N));
end loop;
-- Test sign and apply two complement notation
if S (1) < BL then
return Integer (U);
else
return Integer (-((XDR_U'Last xor U) + 1));
end if;
end if;
end I_I;
-----------
-- I_I24 --
-----------
function I_I24 (Stream : not null access RST) return Integer_24 is
S : XDR_S_I24;
L : SEO;
U : XDR_U24 := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_I24_To_Integer (S);
else
for N in S'Range loop
U := U * BB + XDR_U24 (S (N));
end loop;
-- Test sign and apply two complement notation
if S (1) < BL then
return Integer_24 (U);
else
return Integer_24 (-((XDR_U24'Last xor U) + 1));
end if;
end if;
end I_I24;
----------
-- I_LF --
----------
function I_LF (Stream : not null access RST) return Long_Float is
I : constant Precision := Double;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Last : Integer renames Fields (I).E_Last;
F_Mask : SE renames Fields (I).F_Mask;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
Is_Positive : Boolean;
Exponent : Long_Unsigned;
Fraction : Long_Long_Unsigned;
Result : Long_Float;
S : SEA (1 .. LF_L);
L : SEO;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
end if;
-- Extract Fraction, Sign and Exponent
Fraction := Long_Long_Unsigned (S (LF_L + 1 - F_Bytes) and F_Mask);
for N in LF_L + 2 - F_Bytes .. LF_L loop
Fraction := Fraction * BB + Long_Long_Unsigned (S (N));
end loop;
Result := Long_Float'Scaling (Long_Float (Fraction), -F_Size);
if BS <= S (1) then
Is_Positive := False;
Exponent := Long_Unsigned (S (1) - BS);
else
Is_Positive := True;
Exponent := Long_Unsigned (S (1));
end if;
for N in 2 .. E_Bytes loop
Exponent := Exponent * BB + Long_Unsigned (S (N));
end loop;
Exponent := Shift_Right (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
-- NaN or Infinities
if Integer (Exponent) = E_Last then
raise Constraint_Error;
elsif Exponent = 0 then
-- Signed zeros
if Fraction = 0 then
null;
-- Denormalized float
else
Result := Long_Float'Scaling (Result, 1 - E_Bias);
end if;
-- Normalized float
else
Result := Long_Float'Scaling
(1.0 + Result, Integer (Exponent) - E_Bias);
end if;
if not Is_Positive then
Result := -Result;
end if;
return Result;
end I_LF;
----------
-- I_LI --
----------
function I_LI (Stream : not null access RST) return Long_Integer is
S : XDR_S_LI;
L : SEO;
U : Unsigned := 0;
X : Long_Unsigned := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return Long_Integer (XDR_S_LI_To_Long_Long_Integer (S));
else
-- Compute using machine unsigned
-- rather than long_long_unsigned
for N in S'Range loop
U := U * BB + Unsigned (S (N));
-- We have filled an unsigned
if N mod UB = 0 then
X := Shift_Left (X, US) + Long_Unsigned (U);
U := 0;
end if;
end loop;
-- Test sign and apply two complement notation
if S (1) < BL then
return Long_Integer (X);
else
return Long_Integer (-((Long_Unsigned'Last xor X) + 1));
end if;
end if;
end I_LI;
-----------
-- I_LLF --
-----------
function I_LLF (Stream : not null access RST) return Long_Long_Float is
I : constant Precision := Quadruple;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Last : Integer renames Fields (I).E_Last;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
Is_Positive : Boolean;
Exponent : Long_Unsigned;
Fraction_1 : Long_Long_Unsigned := 0;
Fraction_2 : Long_Long_Unsigned := 0;
Result : Long_Long_Float;
HF : constant Natural := F_Size / 2;
S : SEA (1 .. LLF_L);
L : SEO;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
end if;
-- Extract Fraction, Sign and Exponent
for I in LLF_L - F_Bytes + 1 .. LLF_L - 7 loop
Fraction_1 := Fraction_1 * BB + Long_Long_Unsigned (S (I));
end loop;
for I in SEO (LLF_L - 6) .. SEO (LLF_L) loop
Fraction_2 := Fraction_2 * BB + Long_Long_Unsigned (S (I));
end loop;
Result := Long_Long_Float'Scaling (Long_Long_Float (Fraction_2), -HF);
Result := Long_Long_Float (Fraction_1) + Result;
Result := Long_Long_Float'Scaling (Result, HF - F_Size);
if BS <= S (1) then
Is_Positive := False;
Exponent := Long_Unsigned (S (1) - BS);
else
Is_Positive := True;
Exponent := Long_Unsigned (S (1));
end if;
for N in 2 .. E_Bytes loop
Exponent := Exponent * BB + Long_Unsigned (S (N));
end loop;
Exponent := Shift_Right (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
-- NaN or Infinities
if Integer (Exponent) = E_Last then
raise Constraint_Error;
elsif Exponent = 0 then
-- Signed zeros
if Fraction_1 = 0 and then Fraction_2 = 0 then
null;
-- Denormalized float
else
Result := Long_Long_Float'Scaling (Result, 1 - E_Bias);
end if;
-- Normalized float
else
Result := Long_Long_Float'Scaling
(1.0 + Result, Integer (Exponent) - E_Bias);
end if;
if not Is_Positive then
Result := -Result;
end if;
return Result;
end I_LLF;
-----------
-- I_LLI --
-----------
function I_LLI (Stream : not null access RST) return Long_Long_Integer is
S : XDR_S_LLI;
L : SEO;
U : Unsigned := 0;
X : Long_Long_Unsigned := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_LLI_To_Long_Long_Integer (S);
else
-- Compute using machine unsigned for computing
-- rather than long_long_unsigned.
for N in S'Range loop
U := U * BB + Unsigned (S (N));
-- We have filled an unsigned
if N mod UB = 0 then
X := Shift_Left (X, US) + Long_Long_Unsigned (U);
U := 0;
end if;
end loop;
-- Test sign and apply two complement notation
if S (1) < BL then
return Long_Long_Integer (X);
else
return Long_Long_Integer (-((Long_Long_Unsigned'Last xor X) + 1));
end if;
end if;
end I_LLI;
-----------
-- I_LLU --
-----------
function I_LLU (Stream : not null access RST) return Long_Long_Unsigned is
S : XDR_S_LLU;
L : SEO;
U : Unsigned := 0;
X : Long_Long_Unsigned := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_LLU_To_Long_Long_Unsigned (S);
else
-- Compute using machine unsigned
-- rather than long_long_unsigned.
for N in S'Range loop
U := U * BB + Unsigned (S (N));
-- We have filled an unsigned
if N mod UB = 0 then
X := Shift_Left (X, US) + Long_Long_Unsigned (U);
U := 0;
end if;
end loop;
return X;
end if;
end I_LLU;
----------
-- I_LU --
----------
function I_LU (Stream : not null access RST) return Long_Unsigned is
S : XDR_S_LU;
L : SEO;
U : Unsigned := 0;
X : Long_Unsigned := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return Long_Unsigned (XDR_S_LU_To_Long_Long_Unsigned (S));
else
-- Compute using machine unsigned
-- rather than long_unsigned.
for N in S'Range loop
U := U * BB + Unsigned (S (N));
-- We have filled an unsigned
if N mod UB = 0 then
X := Shift_Left (X, US) + Long_Unsigned (U);
U := 0;
end if;
end loop;
return X;
end if;
end I_LU;
----------
-- I_SF --
----------
function I_SF (Stream : not null access RST) return Short_Float is
I : constant Precision := Single;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Last : Integer renames Fields (I).E_Last;
F_Mask : SE renames Fields (I).F_Mask;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
Exponent : Long_Unsigned;
Fraction : Long_Unsigned;
Is_Positive : Boolean;
Result : Short_Float;
S : SEA (1 .. SF_L);
L : SEO;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
end if;
-- Extract Fraction, Sign and Exponent
Fraction := Long_Unsigned (S (SF_L + 1 - F_Bytes) and F_Mask);
for N in SF_L + 2 - F_Bytes .. SF_L loop
Fraction := Fraction * BB + Long_Unsigned (S (N));
end loop;
Result := Short_Float'Scaling (Short_Float (Fraction), -F_Size);
if BS <= S (1) then
Is_Positive := False;
Exponent := Long_Unsigned (S (1) - BS);
else
Is_Positive := True;
Exponent := Long_Unsigned (S (1));
end if;
for N in 2 .. E_Bytes loop
Exponent := Exponent * BB + Long_Unsigned (S (N));
end loop;
Exponent := Shift_Right (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
-- NaN or Infinities
if Integer (Exponent) = E_Last then
raise Constraint_Error;
elsif Exponent = 0 then
-- Signed zeros
if Fraction = 0 then
null;
-- Denormalized float
else
Result := Short_Float'Scaling (Result, 1 - E_Bias);
end if;
-- Normalized float
else
Result := Short_Float'Scaling
(1.0 + Result, Integer (Exponent) - E_Bias);
end if;
if not Is_Positive then
Result := -Result;
end if;
return Result;
end I_SF;
----------
-- I_SI --
----------
function I_SI (Stream : not null access RST) return Short_Integer is
S : XDR_S_SI;
L : SEO;
U : XDR_SU := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_SI_To_Short_Integer (S);
else
for N in S'Range loop
U := U * BB + XDR_SU (S (N));
end loop;
-- Test sign and apply two complement notation
if S (1) < BL then
return Short_Integer (U);
else
return Short_Integer (-((XDR_SU'Last xor U) + 1));
end if;
end if;
end I_SI;
-----------
-- I_SSI --
-----------
function I_SSI (Stream : not null access RST) return Short_Short_Integer is
S : XDR_S_SSI;
L : SEO;
U : XDR_SSU;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_SSI_To_Short_Short_Integer (S);
else
U := XDR_SSU (S (1));
-- Test sign and apply two complement notation
if S (1) < BL then
return Short_Short_Integer (U);
else
return Short_Short_Integer (-((XDR_SSU'Last xor U) + 1));
end if;
end if;
end I_SSI;
-----------
-- I_SSU --
-----------
function I_SSU (Stream : not null access RST) return Short_Short_Unsigned is
S : XDR_S_SSU;
L : SEO;
U : XDR_SSU := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
else
U := XDR_SSU (S (1));
return Short_Short_Unsigned (U);
end if;
end I_SSU;
----------
-- I_SU --
----------
function I_SU (Stream : not null access RST) return Short_Unsigned is
S : XDR_S_SU;
L : SEO;
U : XDR_SU := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_SU_To_Short_Unsigned (S);
else
for N in S'Range loop
U := U * BB + XDR_SU (S (N));
end loop;
return Short_Unsigned (U);
end if;
end I_SU;
---------
-- I_U --
---------
function I_U (Stream : not null access RST) return Unsigned is
S : XDR_S_U;
L : SEO;
U : XDR_U := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_U_To_Unsigned (S);
else
for N in S'Range loop
U := U * BB + XDR_U (S (N));
end loop;
return Unsigned (U);
end if;
end I_U;
-----------
-- I_U24 --
-----------
function I_U24 (Stream : not null access RST) return Unsigned_24 is
S : XDR_S_U24;
L : SEO;
U : XDR_U24 := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
elsif Optimize_Integers then
return XDR_S_U24_To_Unsigned (S);
else
for N in S'Range loop
U := U * BB + XDR_U24 (S (N));
end loop;
return Unsigned_24 (U);
end if;
end I_U24;
----------
-- I_WC --
----------
function I_WC (Stream : not null access RST) return Wide_Character is
S : XDR_S_WC;
L : SEO;
U : XDR_WC := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
else
for N in S'Range loop
U := U * BB + XDR_WC (S (N));
end loop;
-- Use Ada requirements on Wide_Character representation clause
return Wide_Character'Val (U);
end if;
end I_WC;
-----------
-- I_WWC --
-----------
function I_WWC (Stream : not null access RST) return Wide_Wide_Character is
S : XDR_S_WWC;
L : SEO;
U : XDR_WWC := 0;
begin
Ada.Streams.Read (Stream.all, S, L);
if L /= S'Last then
raise Data_Error;
else
for N in S'Range loop
U := U * BB + XDR_WWC (S (N));
end loop;
-- Use Ada requirements on Wide_Wide_Character representation clause
return Wide_Wide_Character'Val (U);
end if;
end I_WWC;
----------
-- W_AD --
----------
procedure W_AD (Stream : not null access RST; Item : Fat_Pointer) is
S : XDR_S_TM;
U : XDR_TM;
begin
U := XDR_TM (To_XDR_SA (Item.P1));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
Ada.Streams.Write (Stream.all, S);
U := XDR_TM (To_XDR_SA (Item.P2));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
Ada.Streams.Write (Stream.all, S);
if U /= 0 then
raise Data_Error;
end if;
end W_AD;
----------
-- W_AS --
----------
procedure W_AS (Stream : not null access RST; Item : Thin_Pointer) is
S : XDR_S_TM;
U : XDR_TM := XDR_TM (To_XDR_SA (Item.P1));
begin
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
Ada.Streams.Write (Stream.all, S);
if U /= 0 then
raise Data_Error;
end if;
end W_AS;
---------
-- W_B --
---------
procedure W_B (Stream : not null access RST; Item : Boolean) is
begin
if Item then
W_SSU (Stream, 1);
else
W_SSU (Stream, 0);
end if;
end W_B;
---------
-- W_C --
---------
procedure W_C (Stream : not null access RST; Item : Character) is
S : XDR_S_C;
pragma Assert (C_L = 1);
begin
-- Use Ada requirements on Character representation clause
S (1) := SE (Character'Pos (Item));
Ada.Streams.Write (Stream.all, S);
end W_C;
---------
-- W_F --
---------
procedure W_F (Stream : not null access RST; Item : Float) is
I : constant Precision := Single;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
F_Mask : SE renames Fields (I).F_Mask;
Exponent : Long_Unsigned;
Fraction : Long_Unsigned;
Is_Positive : Boolean;
E : Integer;
F : Float;
S : SEA (1 .. F_L) := [others => 0];
begin
if not Item'Valid then
raise Constraint_Error;
end if;
-- Compute Sign
Is_Positive := (0.0 <= Item);
F := abs (Item);
-- Signed zero
if F = 0.0 then
Exponent := 0;
Fraction := 0;
else
E := Float'Exponent (F) - 1;
-- Denormalized float
if E <= -E_Bias then
F := Float'Scaling (F, F_Size + E_Bias - 1);
E := -E_Bias;
else
F := Float'Scaling (Float'Fraction (F), F_Size + 1);
end if;
-- Compute Exponent and Fraction
Exponent := Long_Unsigned (E + E_Bias);
Fraction := Long_Unsigned (F * 2.0) / 2;
end if;
-- Store Fraction
for I in reverse F_L - F_Bytes + 1 .. F_L loop
S (I) := SE (Fraction mod BB);
Fraction := Fraction / BB;
end loop;
-- Remove implicit bit
S (F_L - F_Bytes + 1) := S (F_L - F_Bytes + 1) and F_Mask;
-- Store Exponent (not always at the beginning of a byte)
Exponent := Shift_Left (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
for N in reverse 1 .. E_Bytes loop
S (N) := SE (Exponent mod BB) + S (N);
Exponent := Exponent / BB;
end loop;
-- Store Sign
if not Is_Positive then
S (1) := S (1) + BS;
end if;
Ada.Streams.Write (Stream.all, S);
end W_F;
---------
-- W_I --
---------
procedure W_I (Stream : not null access RST; Item : Integer) is
S : XDR_S_I;
U : XDR_U;
begin
if Optimize_Integers then
S := Integer_To_XDR_S_I (Item);
else
-- Test sign and apply two complement notation
U := (if Item < 0
then XDR_U'Last xor XDR_U (-(Item + 1))
else XDR_U (Item));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_I;
-----------
-- W_I24 --
-----------
procedure W_I24 (Stream : not null access RST; Item : Integer_24) is
S : XDR_S_I24;
U : XDR_U24;
begin
if Optimize_Integers then
S := Integer_To_XDR_S_I24 (Item);
else
-- Test sign and apply two complement notation
U := (if Item < 0
then XDR_U24'Last xor XDR_U24 (-(Item + 1))
else XDR_U24 (Item));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_I24;
----------
-- W_LF --
----------
procedure W_LF (Stream : not null access RST; Item : Long_Float) is
I : constant Precision := Double;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
F_Mask : SE renames Fields (I).F_Mask;
Exponent : Long_Unsigned;
Fraction : Long_Long_Unsigned;
Is_Positive : Boolean;
E : Integer;
F : Long_Float;
S : SEA (1 .. LF_L) := [others => 0];
begin
if not Item'Valid then
raise Constraint_Error;
end if;
-- Compute Sign
Is_Positive := (0.0 <= Item);
F := abs (Item);
-- Signed zero
if F = 0.0 then
Exponent := 0;
Fraction := 0;
else
E := Long_Float'Exponent (F) - 1;
-- Denormalized float
if E <= -E_Bias then
E := -E_Bias;
F := Long_Float'Scaling (F, F_Size + E_Bias - 1);
else
F := Long_Float'Scaling (F, F_Size - E);
end if;
-- Compute Exponent and Fraction
Exponent := Long_Unsigned (E + E_Bias);
Fraction := Long_Long_Unsigned (F * 2.0) / 2;
end if;
-- Store Fraction
for I in reverse LF_L - F_Bytes + 1 .. LF_L loop
S (I) := SE (Fraction mod BB);
Fraction := Fraction / BB;
end loop;
-- Remove implicit bit
S (LF_L - F_Bytes + 1) := S (LF_L - F_Bytes + 1) and F_Mask;
-- Store Exponent (not always at the beginning of a byte)
Exponent := Shift_Left (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
for N in reverse 1 .. E_Bytes loop
S (N) := SE (Exponent mod BB) + S (N);
Exponent := Exponent / BB;
end loop;
-- Store Sign
if not Is_Positive then
S (1) := S (1) + BS;
end if;
Ada.Streams.Write (Stream.all, S);
end W_LF;
----------
-- W_LI --
----------
procedure W_LI (Stream : not null access RST; Item : Long_Integer) is
S : XDR_S_LI;
U : Unsigned := 0;
X : Long_Unsigned;
begin
if Optimize_Integers then
S := Long_Long_Integer_To_XDR_S_LI (Long_Long_Integer (Item));
else
-- Test sign and apply two complement notation
if Item < 0 then
X := Long_Unsigned'Last xor Long_Unsigned (-(Item + 1));
else
X := Long_Unsigned (Item);
end if;
-- Compute using machine unsigned rather than long_unsigned
for N in reverse S'Range loop
-- We have filled an unsigned
if (LU_L - N) mod UB = 0 then
U := Unsigned (X and UL);
X := Shift_Right (X, US);
end if;
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_LI;
-----------
-- W_LLF --
-----------
procedure W_LLF (Stream : not null access RST; Item : Long_Long_Float) is
I : constant Precision := Quadruple;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
HFS : constant Integer := F_Size / 2;
Exponent : Long_Unsigned;
Fraction_1 : Long_Long_Unsigned;
Fraction_2 : Long_Long_Unsigned;
Is_Positive : Boolean;
E : Integer;
F : Long_Long_Float := Item;
S : SEA (1 .. LLF_L) := [others => 0];
begin
if not Item'Valid then
raise Constraint_Error;
end if;
-- Compute Sign
Is_Positive := (0.0 <= Item);
if F < 0.0 then
F := -Item;
end if;
-- Signed zero
if F = 0.0 then
Exponent := 0;
Fraction_1 := 0;
Fraction_2 := 0;
else
E := Long_Long_Float'Exponent (F) - 1;
-- Denormalized float
if E <= -E_Bias then
F := Long_Long_Float'Scaling (F, E_Bias - 1);
E := -E_Bias;
else
F := Long_Long_Float'Scaling
(Long_Long_Float'Fraction (F), 1);
end if;
-- Compute Exponent and Fraction
Exponent := Long_Unsigned (E + E_Bias);
F := Long_Long_Float'Scaling (F, F_Size - HFS);
Fraction_1 := Long_Long_Unsigned (Long_Long_Float'Floor (F));
F := F - Long_Long_Float (Fraction_1);
F := Long_Long_Float'Scaling (F, HFS);
Fraction_2 := Long_Long_Unsigned (Long_Long_Float'Floor (F));
end if;
-- Store Fraction_1
for I in reverse LLF_L - F_Bytes + 1 .. LLF_L - 7 loop
S (I) := SE (Fraction_1 mod BB);
Fraction_1 := Fraction_1 / BB;
end loop;
-- Store Fraction_2
for I in reverse LLF_L - 6 .. LLF_L loop
S (SEO (I)) := SE (Fraction_2 mod BB);
Fraction_2 := Fraction_2 / BB;
end loop;
-- Store Exponent (not always at the beginning of a byte)
Exponent := Shift_Left (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
for N in reverse 1 .. E_Bytes loop
S (N) := SE (Exponent mod BB) + S (N);
Exponent := Exponent / BB;
end loop;
-- Store Sign
if not Is_Positive then
S (1) := S (1) + BS;
end if;
Ada.Streams.Write (Stream.all, S);
end W_LLF;
-----------
-- W_LLI --
-----------
procedure W_LLI
(Stream : not null access RST;
Item : Long_Long_Integer)
is
S : XDR_S_LLI;
U : Unsigned := 0;
X : Long_Long_Unsigned;
begin
if Optimize_Integers then
S := Long_Long_Integer_To_XDR_S_LLI (Item);
else
-- Test sign and apply two complement notation
if Item < 0 then
X := Long_Long_Unsigned'Last xor Long_Long_Unsigned (-(Item + 1));
else
X := Long_Long_Unsigned (Item);
end if;
-- Compute using machine unsigned rather than long_long_unsigned
for N in reverse S'Range loop
-- We have filled an unsigned
if (LLU_L - N) mod UB = 0 then
U := Unsigned (X and UL);
X := Shift_Right (X, US);
end if;
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_LLI;
-----------
-- W_LLU --
-----------
procedure W_LLU
(Stream : not null access RST;
Item : Long_Long_Unsigned)
is
S : XDR_S_LLU;
U : Unsigned := 0;
X : Long_Long_Unsigned := Item;
begin
if Optimize_Integers then
S := Long_Long_Unsigned_To_XDR_S_LLU (Item);
else
-- Compute using machine unsigned rather than long_long_unsigned
for N in reverse S'Range loop
-- We have filled an unsigned
if (LLU_L - N) mod UB = 0 then
U := Unsigned (X and UL);
X := Shift_Right (X, US);
end if;
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_LLU;
----------
-- W_LU --
----------
procedure W_LU (Stream : not null access RST; Item : Long_Unsigned) is
S : XDR_S_LU;
U : Unsigned := 0;
X : Long_Unsigned := Item;
begin
if Optimize_Integers then
S := Long_Long_Unsigned_To_XDR_S_LU (Long_Long_Unsigned (Item));
else
-- Compute using machine unsigned rather than long_unsigned
for N in reverse S'Range loop
-- We have filled an unsigned
if (LU_L - N) mod UB = 0 then
U := Unsigned (X and UL);
X := Shift_Right (X, US);
end if;
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_LU;
----------
-- W_SF --
----------
procedure W_SF (Stream : not null access RST; Item : Short_Float) is
I : constant Precision := Single;
E_Size : Integer renames Fields (I).E_Size;
E_Bias : Integer renames Fields (I).E_Bias;
E_Bytes : SEO renames Fields (I).E_Bytes;
F_Bytes : SEO renames Fields (I).F_Bytes;
F_Size : Integer renames Fields (I).F_Size;
F_Mask : SE renames Fields (I).F_Mask;
Exponent : Long_Unsigned;
Fraction : Long_Unsigned;
Is_Positive : Boolean;
E : Integer;
F : Short_Float;
S : SEA (1 .. SF_L) := [others => 0];
begin
if not Item'Valid then
raise Constraint_Error;
end if;
-- Compute Sign
Is_Positive := (0.0 <= Item);
F := abs (Item);
-- Signed zero
if F = 0.0 then
Exponent := 0;
Fraction := 0;
else
E := Short_Float'Exponent (F) - 1;
-- Denormalized float
if E <= -E_Bias then
E := -E_Bias;
F := Short_Float'Scaling (F, F_Size + E_Bias - 1);
else
F := Short_Float'Scaling (F, F_Size - E);
end if;
-- Compute Exponent and Fraction
Exponent := Long_Unsigned (E + E_Bias);
Fraction := Long_Unsigned (F * 2.0) / 2;
end if;
-- Store Fraction
for I in reverse SF_L - F_Bytes + 1 .. SF_L loop
S (I) := SE (Fraction mod BB);
Fraction := Fraction / BB;
end loop;
-- Remove implicit bit
S (SF_L - F_Bytes + 1) := S (SF_L - F_Bytes + 1) and F_Mask;
-- Store Exponent (not always at the beginning of a byte)
Exponent := Shift_Left (Exponent, Integer (E_Bytes) * SU - E_Size - 1);
for N in reverse 1 .. E_Bytes loop
S (N) := SE (Exponent mod BB) + S (N);
Exponent := Exponent / BB;
end loop;
-- Store Sign
if not Is_Positive then
S (1) := S (1) + BS;
end if;
Ada.Streams.Write (Stream.all, S);
end W_SF;
----------
-- W_SI --
----------
procedure W_SI (Stream : not null access RST; Item : Short_Integer) is
S : XDR_S_SI;
U : XDR_SU;
begin
if Optimize_Integers then
S := Short_Integer_To_XDR_S_SI (Item);
else
-- Test sign and apply two complement's notation
U := (if Item < 0
then XDR_SU'Last xor XDR_SU (-(Item + 1))
else XDR_SU (Item));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_SI;
-----------
-- W_SSI --
-----------
procedure W_SSI
(Stream : not null access RST;
Item : Short_Short_Integer)
is
S : XDR_S_SSI;
U : XDR_SSU;
begin
if Optimize_Integers then
S := Short_Short_Integer_To_XDR_S_SSI (Item);
else
-- Test sign and apply two complement's notation
U := (if Item < 0
then XDR_SSU'Last xor XDR_SSU (-(Item + 1))
else XDR_SSU (Item));
S (1) := SE (U);
end if;
Ada.Streams.Write (Stream.all, S);
end W_SSI;
-----------
-- W_SSU --
-----------
procedure W_SSU
(Stream : not null access RST;
Item : Short_Short_Unsigned)
is
U : constant XDR_SSU := XDR_SSU (Item);
S : XDR_S_SSU;
begin
S (1) := SE (U);
Ada.Streams.Write (Stream.all, S);
end W_SSU;
----------
-- W_SU --
----------
procedure W_SU (Stream : not null access RST; Item : Short_Unsigned) is
S : XDR_S_SU;
U : XDR_SU := XDR_SU (Item);
begin
if Optimize_Integers then
S := Short_Unsigned_To_XDR_S_SU (Item);
else
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_SU;
---------
-- W_U --
---------
procedure W_U (Stream : not null access RST; Item : Unsigned) is
S : XDR_S_U;
U : XDR_U := XDR_U (Item);
begin
if Optimize_Integers then
S := Unsigned_To_XDR_S_U (Item);
else
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_U;
-----------
-- W_U24 --
-----------
procedure W_U24 (Stream : not null access RST; Item : Unsigned_24) is
S : XDR_S_U24;
U : XDR_U24 := XDR_U24 (Item);
begin
if Optimize_Integers then
S := Unsigned_To_XDR_S_U24 (Item);
else
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
if U /= 0 then
raise Data_Error;
end if;
end if;
Ada.Streams.Write (Stream.all, S);
end W_U24;
----------
-- W_WC --
----------
procedure W_WC (Stream : not null access RST; Item : Wide_Character) is
S : XDR_S_WC;
U : XDR_WC;
begin
-- Use Ada requirements on Wide_Character representation clause
U := XDR_WC (Wide_Character'Pos (Item));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
Ada.Streams.Write (Stream.all, S);
if U /= 0 then
raise Data_Error;
end if;
end W_WC;
-----------
-- W_WWC --
-----------
procedure W_WWC
(Stream : not null access RST; Item : Wide_Wide_Character)
is
S : XDR_S_WWC;
U : XDR_WWC;
begin
-- Use Ada requirements on Wide_Wide_Character representation clause
U := XDR_WWC (Wide_Wide_Character'Pos (Item));
for N in reverse S'Range loop
S (N) := SE (U mod BB);
U := U / BB;
end loop;
Ada.Streams.Write (Stream.all, S);
if U /= 0 then
raise Data_Error;
end if;
end W_WWC;
end System.Stream_Attributes.XDR;
|