11 Commits

Author SHA1 Message Date
James K. Lowden
08e9df2546 cobol: Introduce vendor-compatibility layer as user-defined functions.
Install COBOL UDFs in a target directory that includes the GCC version
in its path, to permit side-by-side installation. Support compat
library with COBOL POSIX bindings; support those binding with C
functions in libgcobol as needed.

Changes to the compiler to support POSIX binding and testing.

Include developer conveniences -- Makefiles, bin/ and t/ directories --
to ensure UDFs compile and return reasonable results.  These are
not installed and do not affect how libgcobol is built.

gcc/cobol/ChangeLog:

	* cdf.y: Install literals in symbol table.
	* genapi.cc (parser_alphabet): Use std::string for currency.
	(initialize_the_data): Rely on constructor.
	(parser_file_add): Better #pragma message.
	(parser_exception_file): Return early if not generating code.
	* parse.y: Allow library programs to act as functions.
	* parse_ante.h (dialect_proscribed): Standardize message.
	(intrinsic_call_2): Correct s/fund/func/ misspelling.
	* scan.l: Comment.
	* symbols.cc (symbols_update): Add unreachable assertion.
	(symbol_field_parent_set): Reduce error to debug message.
	(cdf_literalize): Declare.
	(symbol_table_init): Insert CDF constants as literals.
	* symbols.h (cbl_dialect_str): Provide string values for enum.
	(is_working_storage): Remove function.
	(struct cbl_field_data_t): Add manhandle_initial for Numeric Edited.
	(struct cbl_field_t): Initialize name to zeros.
	(struct cbl_section_t): Delete unused attr() function.
	(symbol_unique_index): Declare.
	* token_names.h: Regenerate.
	* util.cc (cdf_literalize): Construct a cbl_field_t from a CDF literal.
	(symbol_unique_index): Supply "globally" unique number for a program.

libgcobol/ChangeLog:

	* Makefile.am: Move UDF-support to posix/shim, add install targets
	* Makefile.in: Regenerate
	* charmaps.cc (__gg__currency_signs): Use std::string.
	* charmaps.h: Include string and vector headers.
	(class charmap_t): Use std::string and vector for currency.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for libxml2.
	* intrinsic.cc (numval_c): Constify.
	* libgcobol.cc (struct program_state): Use std::string and vector.
	(__gg__inspect_format_2): Add debug messages.
	* libgcobol.h (__gg__get_default_currency_string): Constify.
	* valconv.cc (expand_picture): Use std::string and vector.
	(__gg__string_to_numeric_edited): Use std::string and vector.
	(__gg__currency_sign_init): Use std::string and vector.
	(__gg__currency_sign): Use std::string and vector.
	* xmlparse.cc (xml_push_parse): Reformat.
	* posix/stat.cc: Removed.
	* posix/stat.h: Removed.
	* .gitignore: New file.
	* compat/README.md: New file.
	* compat/lib/gnu/CBL_ALLOC_MEM.cbl: New file.
	* compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl: New file.
	* compat/lib/gnu/CBL_DELETE_FILE.cbl: New file.
	* compat/lib/gnu/CBL_FREE_MEM.cbl: New file.
	* compat/t/Makefile: New file.
	* compat/t/smoke.cbl: New file.
	* posix/README.md: New file.
	* posix/bin/Makefile: New file for UDF-developer.
	* posix/bin/headers: New file.
	* posix/bin/scrape.awk: New file.
	* posix/bin/sizeofs.c: New file.
	* posix/bin/udf-gen: New file.
	* posix/cpy/posix-errno.cbl: New file.
	* posix/cpy/statbuf.cpy: New file.
	* posix/cpy/tm.cpy: New file.
	* posix/errno.cc: Removed.
	* posix/localtime.cc: Removed.
	* posix/shim/stat.cc: New file.
	* posix/shim/stat.h: New file.
	* posix/t/Makefile: New file.
	* posix/t/errno.cbl: New file.
	* posix/t/exit.cbl: New file.
	* posix/t/localtime.cbl: New file.
	* posix/t/stat.cbl: New file.
	* posix/tm.h: Removed.
	* posix/udf/posix-exit.cbl: New file.
	* posix/udf/posix-localtime.cbl: New file.
	* posix/udf/posix-mkdir.cbl: New file.
	* posix/udf/posix-stat.cbl: New file.
	* posix/udf/posix-unlink.cbl: New file.
2025-11-12 19:49:39 -05:00
Robert Dubner
2e334900f4 cobol: Guard clock_gettime(). [PR119975]
This attempts to eliminate "'clock_gettime' not declared..." when
building on x86_64-apple-darwin15.6.0.  Calls to clock_gettime have been
reduced to two locations.  Both have been guarded with

gcc/cobol/ChangeLog:

	PR cobol/119975
	* genapi.cc (parser_intrinsic_call_0): Use get_time_nanoseconds().
	* genutil.cc (get_time_64): Rename to get_time_nanoseconds().
	(get_time_nanoseconds): Likewise.
	* genutil.h (get_time_64): Likewise.
	(get_time_nanoseconds): Likewise.
	* util.cc (class cbl_timespec): Timing routine uses
	get_time_nanoseconds().
	(operator-): Likewise.
	(parse_file): Likewise.

libgcobol/ChangeLog:

	PR cobol/119975
	* configure.ac: AC_CHECK_LIB(rt, clock_gettime).
	* config.h.in: Likewise.
	* configure: Likewise.
	* gfileio.cc: Remove in-line cppcheck-suppress.
	* intrinsic.cc (timespec_to_string): Use guarded clock_gettime().
	(__gg__current_date): Likewise.
	(__gg__seconds_past_midnight): Likewise.
	(__gg__formatted_current_date): Likewise.
	(__gg__random): Likewise.
	(__gg__random_next): Likewise.
	(__gg__when_compiled): Likewise.
	* libgcobol.cc (cobol_time): Likewise.
	(get_time_nanoseconds): Likewise.
	(__gg__clock_gettime): Likewise.
	(__gg__get_date_hhmmssff): Likewise.
	* libgcobol.h (__gg__clock_gettime): Likewise.
	(struct cbl_timespec): Likewise.
2025-06-05 12:30:55 -04:00
Iain Sandoe
67e79da5a3 libgcobol: Fix bootstrap for targets without program_invocation_short_name
program_invocation_short_name is not widely available, however getprogname()
appears to be a suitable replacement.

Amend the library configuration to look for both. Use program_invocation_short_name
in preference to getprogname() when it is available.  If neither is found fall
back to a constant string.

libgcobol/ChangeLog:

	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for program_invocation_short_name and
	and getprogname().
	* libgcobol.cc (default_exception_handler): When the platform
	has program_invocation_short_name, use it otherwise fall
	back to using getprogname() or a constant string (if neither
	interface is available).

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-05-06 14:37:48 +01:00
Rainer Orth
a619a128c9 libgcobol: Check for struct tm tm_zone
intrinsic.cc doesn't compile on Solaris:

/vol/gcc/src/hg/master/cobol/libgcobol/intrinsic.cc: In function ‘void
__gg__formatted_current_date(cblc_field_t*, cblc_field_t*, std::size_t,
std::size_t)’:
/vol/gcc/src/hg/master/cobol/libgcobol/intrinsic.cc:1480:6: error: ‘struct
std::tm’ has no member named ‘tm_zone’; did you mean ‘tm_mon’?
 1480 |   tm.tm_zone = "GMT";
      |      ^~~~~~~
      |      tm_mon

struct tm.tm_zone is new in POSIX.1-2024, thus cannot be assumed to be
present universally.

This patch checks for its presence and guards the use accordingly.

Bootstrapped without regressions on amd64-pc-solaris2.11,
sparcv9-sun-solaris2.11, and x86_64-pc-solaris2.11.

2025-04-08  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libgcobol:
	* configure.ac: Check for struct tm.tm_zone.
	* configure, config.h.in: Regenerate.
	* intrinsic.cc (__gg__formatted_current_date): Guard tm.tm_zone
	use with HAVE_STRUCT_TM_TM_ZONE.
2025-04-21 15:59:14 +02:00
Iain Sandoe
95f10974a9 libgcobol: Allow libgcobol to use libquadmath [PR119244].
Many of the changes are mechanical:
 1. 'GCOB_FP128' in place of _Float128.
 2. Using FP128_FUNC to represent the spelling of intrinsics.
 3. Using GCOB_FP128_LITERAL() to choose the suffix for literals.

This allows for:
  __float128 and 'q' as the suffix when libquadmath is configured.
   _Float128 / 'f128' when IEC-60559 is available in libc
 long double / 'l' when long double is ieee753 128b.

Add libquadmath to libgcobol.spec and its dependencies  where the
platform needs it.

	PR cobol/119244

libgcobol/ChangeLog:

	* Makefile.am: Add support for libquadmath.
	* Makefile.in: Regenerate.
	* acinclude.m4: Add support for libquadmath.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Configure libquadmath support.
	* gmath.cc: Use GCOB_FP128 to represent the configured
	128b floating point type.  Use FP128_FUNC to represent
	the naming of intrinsics in the configure 128b floating
	point type. Render literals with GCOB_FP128_LITERAL.
	* intrinsic.cc: Likewise.
	* libgcobol.cc: Likewise.
	* libgcobol.h: Likewise.
	* libgcobol-fp.h: New file.
	* gfileio.cc: Include libgcobol-fp.h.
	* libgcobol.spec.in: Add libquadmath configure output.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-10 11:05:07 +01:00
Iain Sandoe
b90364ee1c libgcobol: C++-ify the configuration steps.
Currently, the library is configured as if it was written in C, however
all the sources are C++, so update to use C++ as the configure language
(and check the CXX instead of CC).

Reorder the configuration steps so that we setup the tools and environment
before carrying out tests.

Remove unused configuration machinery.

Also we configured extra ld flags but never used them. There is no need
to make these extra_ldflags darwin-specific, additions could be required
by other hosts.

libgcobol/ChangeLog:

	* aclocal.m4: Regenerate.
	* config.h.in: Regenerate.
	* Makefile.am: Use the configured LIBS and extra_ldflags.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Shift configure to use c++. Order tests for tools
	and environment before other tests.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-05 14:22:53 +01:00
Iain Sandoe
b6aafe9a5b libgcobol: Provide fallbacks for C32 strfromf32/64 functions.
strfrom{f,d,l,fN) are all C23 and might not be available in general.
This uses snprintf() to provide fall-backs where the libc does not
yet have support.

libgcobol/ChangeLog:

	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for availability of strfromf32 and
	strfromf64.
	* libgcobol.cc (strfromf32, strfromf64): New.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-03 14:33:59 +01:00
Iain Sandoe
66a41a0a96 libgcobol: Only use random_r if it is available [PR119295]
We do not have a replacement at the moment, so fall back to using
regular random and friends.

	PR cobol/119295

libgcobol/ChangeLog:

	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Configure random_r and friends
	* intrinsic.cc (__gg__random): Use random_r when available.
	(__gg__random_next): Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-03 14:33:27 +01:00
Iain Sandoe
4f68873e0d libgcobol: Add configure checks for iconv.
Some targets might need to add libraries to get iconv support.

libgcobol/ChangeLog:

	* Makefile.am: Use LIBICONV.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for iconv support.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-03-20 19:50:51 +00:00
Jakub Jelinek
799ed87bcf cobol: Regenerate libgcobol/config.h.h
I forgot to regenerate config.h.in when changing configure.ac.

2025-03-11  Jakub Jelinek  <jakub@redhat.com>

	* config.h.in: Regenerate.
2025-03-11 22:47:26 +01:00
James K. Lowden
a075418727 COBOL: libgcobol
libgcobol/
	* Makefile.am: New file.
	* Makefile.in: Autogenerate.
	* acinclude.m4: Likewise.
	* aclocal.m4: Likewise.
	* configure.ac: New file.
	* configure: Autogenerate.
	* configure.tgt: New file.
	* README: New file.
	* charmaps.cc: New file.
	* config.h.in: New file.
	* constants.cc: New file.
	* gfileio.cc: New file.
	* gmath.cc: New file.
	* io.cc: New file.
	* valconv.cc: New file.
	* charmaps.h: New file.
	* common-defs.h: New file.
	* ec.h: New file.
	* exceptl.h: New file.
	* gcobolio.h: New file.
	* gfileio.h: New file.
	* gmath.h: New file.
	* io.h: New file.
	* libgcobol.h: New file.
	* valconv.h: New file.
	* libgcobol.cc: New file.
	* intrinsic.cc: New file.
2025-03-11 07:48:15 +01:00