aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDoug Rupp <rupp@adacore.com>2018-05-29 09:38:17 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-29 09:38:17 +0000
commit35f5e2c14ae1b0959292312ef6c0eb23554e025d (patch)
tree7190e555afe38348cd300ce84d057a2ae51a67ba /gcc
parent0f9ca0303ed932c4c2df9b3439aac6b6566a6728 (diff)
downloadgcc-35f5e2c14ae1b0959292312ef6c0eb23554e025d.zip
gcc-35f5e2c14ae1b0959292312ef6c0eb23554e025d.tar.gz
gcc-35f5e2c14ae1b0959292312ef6c0eb23554e025d.tar.bz2
[Ada] New function to return nanoseconds from Unix Epoch
2018-05-29 Doug Rupp <rupp@adacore.com> 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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/libgnat/a-calcon.adb15
-rw-r--r--gcc/ada/libgnat/a-calcon.ads8
-rw-r--r--gcc/ada/libgnat/a-calend.adb4
-rw-r--r--gcc/ada/libgnat/a-calend.ads4
5 files changed, 34 insertions, 4 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 21d1324..d5cd871 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-29 Doug Rupp <rupp@adacore.com>
+
+ * 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 <ebotcazou@adacore.com>
* 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 82ed24d..1c8e8cc 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 c7b16c5..e2b3ad3 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 89f64c3..8299b74 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 69b6563..4371e11 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