text
stringlengths
0
234
--
f64: constant IEEE_LF.Float_64:= IEEE_LF.To_IEEE(x);
begin
for i in d'Range loop
d(i):= f64(9-i); -- Order is reversed
end loop;
-- Fully tested in Test_IEEE.adb
return d;
end IEEE_Double_Intel_Portable;
-- Just spit the bytes of the long float - fast way.
-- Of course this will work only on an Intel(-like) machine. We check this later.
subtype Byte_buffer_8 is Byte_buffer(0..7);
function IEEE_Double_Intel_Native is new
Ada.Unchecked_Conversion(Long_Float, Byte_buffer_8);
x_test: constant Long_Float:= -12345.0e-67;
Can_use_native_IEEE: constant Boolean:=
IEEE_Double_Intel_Portable(x_test) = IEEE_Double_Intel_Native(x_test);
function IEEE_Double_Intel(x: Long_Float) return Byte_buffer is
pragma Inline(IEEE_Double_Intel);
begin
if Can_use_native_IEEE then
return IEEE_Double_Intel_Native(x); -- Fast, non-portable
else
return IEEE_Double_Intel_Portable(x); -- Slower but portable
end if;
end IEEE_Double_Intel;
-- Workaround for the severe xxx'Read xxx'Write performance
-- problems in the GNAT and ObjectAda compilers (as in 2009)
-- This is possible if and only if Byte = Stream_Element and
-- arrays types are both packed and aligned the same way.
--
subtype Size_test_a is Byte_buffer(1..19);
subtype Size_test_b is Ada.Streams.Stream_Element_Array(1..19);
workaround_possible: constant Boolean:=
Size_test_a'Size = Size_test_b'Size and
Size_test_a'Alignment = Size_test_b'Alignment;
procedure Block_Write(
stream : in out Ada.Streams.Root_Stream_Type'Class;
buffer : in Byte_buffer
)
is
pragma Inline(Block_Write);
SE_Buffer : Stream_Element_Array (1 .. buffer'Length);
for SE_Buffer'Address use buffer'Address;
pragma Import (Ada, SE_Buffer);
begin
if workaround_possible then
Ada.Streams.Write(stream, SE_Buffer);
else
Byte_buffer'Write(stream'Access, buffer);
-- ^ This was 30x to 70x slower on GNAT 2009
-- Test in the Zip-Ada project.
end if;
end Block_Write;
----------------
-- Excel BIFF --
----------------
-- The original Modula-2 code counted on certain assumptions about
-- record packing & endianess. We write data without these assumptions.
procedure WriteBiff(
xl : Excel_Out_Stream'Class;
biff_id: Unsigned_16;
data : Byte_buffer
)
is
pragma Inline(WriteBiff);
begin
Block_Write(xl.xl_stream.all, Intel_16(biff_id));
Block_Write(xl.xl_stream.all, Intel_16(Unsigned_16(data'Length)));
Block_Write(xl.xl_stream.all, data);
end WriteBiff;
-- 5.8 BOF: Beginning of File, p.135
procedure Write_BOF(xl : Excel_Out_Stream'Class) is
function BOF_suffix return Byte_buffer is -- 5.8.1 Record BOF
begin
case xl.format is
when BIFF2 =>
return empty_buffer;
when BIFF3 | BIFF4 =>
return (0,0); -- Not used
-- when BIFF8 =>
-- return (1,1,1,1);
end case;
end BOF_suffix;
-- 0005H = Workbook globals
-- 0006H = Visual Basic module
-- 0010H = Sheet or dialogue (see SHEETPR, S5.97)
Sheet_or_dialogue: constant:= 16#10#;
-- 0020H = Chart