From: Doug Rupp Date: Tue, 29 May 2018 09:38:17 +0000 (+0000) Subject: [Ada] New function to return nanoseconds from Unix Epoch X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35f5e2c14ae1b0959292312ef6c0eb23554e025d;p=gcc.git [Ada] New function to return nanoseconds from Unix Epoch 2018-05-29 Doug Rupp gcc/ada/ * libgnat/a-calend.adb (Epoch_Offset): Move from body to ... * libgnat/a-calend.ads (Epoch_Offset): to private part of spec * libgnat/a-calcon.ads (To_Unix_Nano_Time): New function spec. * libgnat/a-calcon.adb (To_Unix_Nano_Time): New function body. From-SVN: r260870 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 21d1324aea3..d5cd8715ea7 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2018-05-29 Doug Rupp + + * libgnat/a-calend.adb (Epoch_Offset): Move from body to ... + * libgnat/a-calend.ads (Epoch_Offset): to private part of spec + * libgnat/a-calcon.ads (To_Unix_Nano_Time): New function spec. + * libgnat/a-calcon.adb (To_Unix_Nano_Time): New function body. + 2018-05-29 Eric Botcazou * repinfo.ads (JSON format): Document new pair for components. diff --git a/gcc/ada/libgnat/a-calcon.adb b/gcc/ada/libgnat/a-calcon.adb index 82ed24d485e..1c8e8cc7eee 100644 --- a/gcc/ada/libgnat/a-calcon.adb +++ b/gcc/ada/libgnat/a-calcon.adb @@ -30,6 +30,7 @@ ------------------------------------------------------------------------------ with Interfaces.C; use Interfaces.C; +with Interfaces.C.Extensions; use Interfaces.C.Extensions; package body Ada.Calendar.Conversions is @@ -145,4 +146,18 @@ package body Ada.Calendar.Conversions is return long (Val); end To_Unix_Time; + ----------------------- + -- To_Unix_Nano_Time -- + ----------------------- + + function To_Unix_Nano_Time (Ada_Time : Time) return long_long is + pragma Unsuppress (Overflow_Check); + Ada_Rep : constant Time_Rep := Time_Rep (Ada_Time); + begin + return long_long (Ada_Rep + Epoch_Offset); + exception + when Constraint_Error => + raise Time_Error; + end To_Unix_Nano_Time; + end Ada.Calendar.Conversions; diff --git a/gcc/ada/libgnat/a-calcon.ads b/gcc/ada/libgnat/a-calcon.ads index c7b16c59929..e2b3ad3b4dc 100644 --- a/gcc/ada/libgnat/a-calcon.ads +++ b/gcc/ada/libgnat/a-calcon.ads @@ -33,6 +33,7 @@ -- time models - Time, Duration, struct tm and struct timespec. with Interfaces.C; +with Interfaces.C.Extensions; package Ada.Calendar.Conversions is @@ -110,4 +111,11 @@ package Ada.Calendar.Conversions is -- units of the result are seconds. Raises Time_Error if the result cannot -- fit into a Time value. + function To_Unix_Nano_Time (Ada_Time : Time) return + Interfaces.C.Extensions.long_long; + -- Convert a time value represented as number of time units since the Ada + -- implementation-defined Epoch to a value relative to the Unix Epoch. The + -- units of the result are nanoseconds. Raises Time_Error if the result + -- cannot fit into a Time value. + end Ada.Calendar.Conversions; diff --git a/gcc/ada/libgnat/a-calend.adb b/gcc/ada/libgnat/a-calend.adb index 89f64c3fcb9..8299b74bc98 100644 --- a/gcc/ada/libgnat/a-calend.adb +++ b/gcc/ada/libgnat/a-calend.adb @@ -203,10 +203,6 @@ is Ada_Low + Time_Rep (34 * 366 + 102 * 365) * Nanos_In_Day + Time_Rep (Leap_Seconds_Count) * Nano; - Epoch_Offset : constant Time_Rep := (136 * 365 + 44 * 366) * Nanos_In_Day; - -- The difference between 2150-1-1 UTC and 1970-1-1 UTC expressed in - -- nanoseconds. Note that year 2100 is non-leap. - Cumulative_Days_Before_Month : constant array (Month_Number) of Natural := (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334); diff --git a/gcc/ada/libgnat/a-calend.ads b/gcc/ada/libgnat/a-calend.ads index 69b65637618..4371e110a1e 100644 --- a/gcc/ada/libgnat/a-calend.ads +++ b/gcc/ada/libgnat/a-calend.ads @@ -221,6 +221,10 @@ private -- with overloading ambiguities in the body if we tried to use Time as an -- internal computational type. + Epoch_Offset : constant Time_Rep := (136 * 365 + 44 * 366) * Nanos_In_Day; + -- The difference between 2150-1-1 UTC and 1970-1-1 UTC expressed in + -- nanoseconds. Note that year 2100 is non-leap. + Days_In_Month : constant array (Month_Number) of Day_Number := (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); -- Days in month for non-leap year, leap year case is adjusted in code