{
// Pass __gg__when_compiled() the time from right now.
struct timespec tp;
- uint64_t now = get_time_64();
+ uint64_t now = get_time_nanoseconds();
tp.tv_sec = now / 1000000000;
tp.tv_nsec = now % 1000000000;
}
uint64_t
-get_time_64()
+get_time_nanoseconds()
{
// This code was unabashedly stolen from gcc/timevar.cc.
// It returns the Unix epoch with nine decimal places.
size_t N,
cbl_refer_t *refers);
void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo);
-uint64_t get_time_64();
+uint64_t get_time_nanoseconds();
#endif
#include "inspect.h"
#include "../../libgcobol/io.h"
#include "genapi.h"
+#include "genutil.h"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
return file.name;
}
+//#define TIMING_PARSE
+#ifdef TIMING_PARSE
class cbl_timespec {
- struct timespec now;
+ uint64_t now; // Nanoseconds
public:
cbl_timespec() {
- clock_gettime(CLOCK_MONOTONIC, &now);
+ now = get_time_nanoseconds();
}
double ns() const {
- return now.tv_sec * 1000000000 + now.tv_nsec;
+ return now;
}
friend double operator-( const cbl_timespec& now, const cbl_timespec& then );
};
double
-operator-( const cbl_timespec& then, const cbl_timespec& now ) {
+operator-( const cbl_timespec& now, const cbl_timespec& then ) {
return (now.ns() - then.ns()) / 1000000000;
}
+#endif
static int
parse_file( const char filename[] )
return 0;
}
+#ifdef TIMING_PARSE
cbl_timespec start;
+#endif
int erc = yyparse();
+#ifdef TIMING_PARSE
cbl_timespec finish;
double dt = finish - start;
+ printf("Overall parse & generate time is %.6f seconds\n", dt);
+#endif
+
parser_leave_file();
- //printf("Overall parse & generate time is %.6f seconds\n", dt);
fclose (yyin);
/* Define to 1 if the target assembler supports thread-local storage. */
#undef HAVE_CC_TLS
+/* Define to 1 if you have the `clock_gettime' function. */
+#undef HAVE_CLOCK_GETTIME
+
/* Define to 1 if you have the <complex.h> header file. */
#undef HAVE_COMPLEX_H
fi
+# Copied from gcc/configure.ac. 2025-06-05 R.J.Dubner
+# At least for glibc, clock_gettime is in librt. But don't pull that
+# in if it still doesn't give us the function we want.
+ac_cv_func_clock_gettime=no
+if test $ac_cv_func_clock_gettime = no; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5
+$as_echo_n "checking for clock_gettime in -lrt... " >&6; }
+if ${ac_cv_lib_rt_clock_gettime+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lrt $LIBS"
+if test x$gcc_no_link = xyes; then
+ as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char clock_gettime ();
+int
+main ()
+{
+return clock_gettime ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+ ac_cv_lib_rt_clock_gettime=yes
+else
+ ac_cv_lib_rt_clock_gettime=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5
+$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; }
+if test "x$ac_cv_lib_rt_clock_gettime" = xyes; then :
+ LIBS="-lrt $LIBS"
+
+$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
+
+fi
+
+fi
+
have_iec_60559_libc_support=no
if test "x$ac_cv_func_strtof128$ac_cv_func_strfromf128" = xyesyes \
&& test "x$libgcobol_have_sinf128$libgcobol_have_cacosf128" = xyesyes; then
libgcobol_have_cacosf128=no
AC_SEARCH_LIBS([cacosf128], [c m], libgcobol_have_cacosf128=yes)
+# Copied from gcc/configure.ac. 2025-06-05 R.J.Dubner
+# At least for glibc, clock_gettime is in librt. But don't pull that
+# in if it still doesn't give us the function we want.
+ac_cv_func_clock_gettime=no
+if test $ac_cv_func_clock_gettime = no; then
+ AC_CHECK_LIB(rt, clock_gettime,
+ [LIBS="-lrt $LIBS"
+ AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+ [Define to 1 if you have the `clock_gettime' function.])])
+fi
+
have_iec_60559_libc_support=no
if test "x$ac_cv_func_strtof128$ac_cv_func_strfromf128" = xyesyes \
&& test "x$libgcobol_have_sinf128$libgcobol_have_cacosf128" = xyesyes; then
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-// cppcheck-suppress-file postfixOperator
-
#include <err.h>
#include <fcntl.h>
#include <unistd.h>
static
char *
-timespec_to_string(char *retval, struct timespec &tp)
+timespec_to_string(char *retval, struct cbl_timespec &tp)
{
/*
Returns a 21-character string:
__gg__current_date(cblc_field_t *dest)
{
// FUNCTION CURRENT-DATE
- struct timespec tp = {};
+ struct cbl_timespec tp = {};
__gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec
char retval[DATE_STRING_BUFFER_SIZE];
__gg__seconds_past_midnight(cblc_field_t *dest)
{
// SECONDS-PAST-MIDNIGHT
- struct timespec tp = {};
+ struct cbl_timespec tp = {};
struct tm tm;
__int128 retval=0;
}
}
- struct timespec ts = {};
+ struct cbl_timespec ts = {};
__gg__clock_gettime(CLOCK_REALTIME, &ts);
struct tm tm = {};
buf->state = NULL;
state = (char *)malloc(state_len);
- struct timespec ts;
+ struct cbl_timespec ts;
__gg__clock_gettime(CLOCK_REALTIME, &ts);
initstate_r( ts.tv_nsec, state, state_len, buf);
}
buf = (random_data *)malloc(sizeof(struct random_data));
buf->state = NULL;
state = (char *)malloc(state_len);
- struct timespec ts;
+ struct cbl_timespec ts;
__gg__clock_gettime(CLOCK_REALTIME, &ts);
initstate_r( ts.tv_nsec, state, state_len, buf);
}
void
__gg__when_compiled(cblc_field_t *dest, size_t tv_sec, long tv_nsec)
{
- struct timespec tp = {};
+ struct cbl_timespec tp = {};
tp.tv_sec = tv_sec;
tp.tv_nsec = tv_nsec;
char retval[DATE_STRING_BUFFER_SIZE];
static time_t
cobol_time()
{
- struct timespec tp;
+ struct cbl_timespec tp;
__gg__clock_gettime(CLOCK_REALTIME, &tp);
return tp.tv_sec;
}
return retval;
}
+uint64_t
+get_time_nanoseconds()
+{
+ // This code was unabashedly stolen from gcc/timevar.cc.
+ // It returns the Unix epoch with nine decimal places.
+
+ uint64_t retval = 0;
+
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec ts;
+ clock_gettime (CLOCK_REALTIME, &ts);
+ retval = ts.tv_sec * 1000000000 + ts.tv_nsec;
+ return retval;
+#endif
+#ifdef HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ retval = tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+ return retval;
+#endif
+ return retval;
+}
extern "C"
void
-__gg__clock_gettime(clockid_t clk_id, struct timespec *tp)
+__gg__clock_gettime(clockid_t clk_id, struct cbl_timespec *tp)
{
const char *p = getenv("GCOBOL_CURRENT_DATE");
}
else
{
- clock_gettime(clk_id, tp);
+ timespec tm;
+ clock_gettime(clk_id, &tm);
+ uint64_t ns = get_time_nanoseconds();
+ tp->tv_sec = ns/1000000000;
+ tp->tv_nsec = ns%1000000000;
}
}
{
char ach[32];
- struct timespec tv;
+ struct cbl_timespec tv;
__gg__clock_gettime(CLOCK_REALTIME, &tv);
struct tm tm;
extern "C" char __gg__get_decimal_point();
extern "C" char * __gg__get_default_currency_string();
-extern "C" void __gg__clock_gettime(clockid_t clk_id, struct timespec *tp);
+struct cbl_timespec
+ {
+ /* You keep using that word "portability". I do not think it means what
+ you think it means. */
+ time_t tv_sec; // Seconds.
+ long tv_nsec; // Nanoseconds.
+ } ;
+
+extern "C" void __gg__clock_gettime(clockid_t clk_id, struct cbl_timespec *tp);
extern "C" GCOB_FP128 __gg__float128_from_location(
const cblc_field_t *var,