Commit Graph

15 Commits

Author SHA1 Message Date
James K. Lowden
c48c6c0a50 cobol: Correct Makefile.am from 809b32660990867052132c706a9c9fdef1766e8f
Update lagging libgcobol/Makefile.am to match libgcobol/Makefile.in.

libgcobol/ChangeLog:
	PR cobol/122702
	* Makefile.am: Include posix/udf/posix-open.cbl.
2025-11-18 13:10:03 -05:00
James K. Lowden
d8e3ddc319 cobol: Correct libgcobol install directory and add components.
Set libgcobol/Makefile.am to define libdir and libsubdir the way libada does.
Reorganize libgcobol/compat directory to group by emulation, not component.
Move orphan gcc/udf/stored-char-length.cbl to the compat directory.
Introduce new POSIX bindings.

gcc/cobol/ChangeLog:
	PR cobol/122702
	* Make-lang.in: Move stored-char-length.cbl to libgcobol.

libgcobol/ChangeLog:
	PR cobol/122702
	* Makefile.am: Set libdir and libsubdir per libada example.
	* Makefile.in: Regenerate.
	* compat/README.md: Revise per new directory structure.
	* compat/gnu/lib/CBL_ALLOC_MEM.cbl: Moved from compat/lib/gnu.
	* compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl: Moved from compat/lib/gnu.
	* compat/gnu/lib/CBL_DELETE_FILE.cbl: Moved from compat/lib/gnu.
	* compat/gnu/lib/CBL_FREE_MEM.cbl: Moved from compat/lib/gnu.
	* compat/gnu/udf/stored-char-length.cbl: New file.
	* compat/lib/gnu/CBL_ALLOC_MEM.cbl: Moved to compat/gnu/lib.
	* compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl: Moved to compat/gnu/lib.
	* compat/lib/gnu/CBL_DELETE_FILE.cbl: Moved to compat/gnu/lib.
	* compat/lib/gnu/CBL_FREE_MEM.cbl: Moved to compat/gnu/lib.
	* posix/cpy/psx-open.cpy: New file.
	* posix/shim/open.cc: New file.
	* posix/shim/stat.h: Add mode & flag bits for open.cc
	* posix/udf/posix-lseek.cbl: New file.
	* posix/udf/posix-open.cbl: New file.
	* posix/udf/posix-read.cbl: New file.
	* posix/udf/posix-write.cbl: New file.
	* xmlparse.cc: Quell context_t initialization-order warning.
2025-11-17 18:25:50 -05:00
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
b20c6458fa cobol: Implement the XML PARSE statement.
These changes implement the XML PARSE statement as described in the IBM
specification.

A repair to exception handling is included.  Up until now, an exception
after a successful file operation wasn't handled properly.

A repair to value declarations for BINARY / COMP / COMP-4 / COMP-5
values now allows them to have digits to the right of the implied
decimal point.  Processing of the "S" PICTURE character has been
normalized as well.

Co-Authored-By: James K. Lowden <jklowden@cobolworx.com>
Co-Authored-By: Robert Dubner <rdubner@symas.com>

gcc/cobol/ChangeLog:

	* Make-lang.in: Incorporate new token_names.h file.
	* cdf.y: Modify tokens.
	* gcobol.1: Document XML PARSE statement
	* genapi.cc (parser_enter_program): Verify that every goto has a
	matching label.
	(parser_end_program): Likewise.
	(parser_alphabet): Refine handling codeset encodings.
	(parser_alphabet_use): Likewise.
	(label_fetch): Moved from later in the source code.
	(parser_xml_parse): New routine for XML PARSE.
	(parser_xml_on_exception): Likewise.
	(parser_xml_not_exception): Likewise.
	(parser_xml_end): Likewise.
	(parser_label_label): Verify goto/label matching.
	(parser_label_goto): Likewise.
	(parser_entry): Minor change to SHOW_PARSE report.
	* genapi.h (parser_alphabet): Set parameter to const.
	(parser_xml_parse): Declare new function.
	(parser_xml_on_exception): Likewise.
	(parser_xml_not_exception): Likewise.
	(parser_xml_end): Likewise.
	(parser_label_addr): Likewise.
	* parse.y: label_pair_t structure; locale processing; new token
	processing for alphabets and XML PARSE.
	* parse_ante.h (name_of): Return field->name when initial is NULL.
	(new_tempnumeric): Make signable_e optional.
	(ast_save_locale): New function.
	(data_division_ready): Warning for "no alphabet".
	* scan.l: Repair interpretation of BINARY, COMP, COMP-4, and
	COMP-5.
	* scan_ante.h (struct bint_t): Likewise.
	* scan_post.h (current_tokens_t::tokenset_t::tokenset_t):
	Include token_names.h.
	* symbols.cc (symbols_alphabet_set): Revert to prior alphabet
	determination.
	(symbol_table_init): New XML special registers.
	(new_temporary): Make signable_e controllable, not fixed.
	* symbols.h (__gg__encoding_iconv_valid): New declaration.
	(enum cbl_label_type_t): New LblXml label type.
	(struct cbl_xml_parse_t):
	(struct cbl_label_t): Implement XML PARSE.
	(new_temporary): Incorporate boolean for signable_e.
	(symbol_elem_of): Change label field type handling.
	(cbl_section_of): Likewise.
	(cbl_field_of): Likewise.
	(cbl_label_of): Likewise.
	(cbl_special_name_of):  Likewise.
	(cbl_alphabet_of):  Likewise.
	(cbl_file_of):  Likewise.
	* token_names.h: New file.
	* util.cc (gcc_location_set_impl): Improve location_t calculations
	when entering and leaving COPYBOOKs.

libgcobol/ChangeLog:

	* Makefile.am: Changes for XML PARSE and POSIX functions.
	* Makefile.in: Likewise.
	* charmaps.cc: Augment encodings[] table with "supported" boolean.
	(__gg__encoding_iconv_name): Modify how encodings are identified.
	(encoding_descr): Likewise.
	(__gg__encoding_iconv_valid): Likewise.
	* common-defs.h (callback_t): Define function pointer.
	* constants.cc: Use named cbl_attr_e constants instead of magic
	numbers.; New definitions for XML special registers.
	* encodings.h (struct encodings_t): Declare "supported" boolean.
	* libgcobol.cc (format_for_display_internal): Use std::ptrdiff_t.
	(__gg__alphabet_use): Add case for iconv_CP1252_e.
	(default_exception_handler): Repair exception handling after a
	successful file operation.
	* posix/errno.cc: New file.
	* posix/localtime.cc: New file.
	* posix/stat.cc: New file.
	* posix/stat.h: New file.
	* posix/tm.h: New file.
	* xmlparse.cc: New file to support XML PARSE statement.

gcc/testsuite/ChangeLog:

	* cobol.dg/typo-1.cob: New test for squiggles and carets.
2025-10-23 11:28:53 -04:00
Robert Dubner
c684053fc0 cobol: Improve binary-to-string conversion.
COBOL often requires the conversion of binary integers to string of characters.
These changes replace a naive routine that peels decimal digits from a binary
value one digit at a time, with a divide-and-conquer algorithm that is twice as
fast even for a couple of digits, and is about eight times faster past ten
digits.

Included here are some minor fixes to the lexer and parser.

gcc/cobol/ChangeLog:

	* cbldiag.h (location_dump): Source code formatting.
	* parse.y: error_msg formatting.
	* scan.l: Remove UTF-8 character from regex pattern.
	* scan_ante.h (numstr_of): error_msg formatting.
	* show_parse.h (class ANALYZE): Suppress cppcheck error.
	* util.cc (cbl_field_t::report_invalid_initial_value):
	error_msg formatting.

libgcobol/ChangeLog:

	* Makefile.am: Include new stringbin.cc file.
	* Makefile.in: Regenerated.
	* libgcobol.cc (__gg__power_of_ten): Improve error message.
	(__gg__binary_to_string): Deleted.
	(__gg__binary_to_string_internal): Deleted.
	(int128_to_field): Use new conversion routine.
	(__gg__move): Use new conversion routine.
	* stringbin.cc: New file. Implements new conversion routine.
	* stringbin.h: New file. Likewise.
2025-08-07 16:12:32 -04: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
63f7285e76 cobol, driver, libgcobol: Add support for libgcobol.spec.
Ads support for using a library spec file (e.g. to include the
target requirements for non-standard libraries - or even libm
which we can now configure at the target side).

gcc/cobol/ChangeLog:

	* gcobolspec.cc (SPEC_FILE): New.
	(lang_specific_driver): Make the 'need libgcobol' flag global
	so that the prelink callback can use it. Libm use is now handled
	via the library spec.
	(lang_specific_pre_link): Include libgcobol.spec where needed.

libgcobol/ChangeLog:

	* Makefile.am: Add libgcobol.spec and dependency.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Add libgcobol.spec handling.
	* libgcobol.spec.in: New file.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-05 14:24:33 +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
8f1f35f1cb libgcobol: Check if the target needs libm.
Use the libtool config check and $(LIBM).

libgcobol/ChangeLog:

	* Makefile.am: Use $(LIBM) to add the math lib when
	it is needed.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check if the target wants libm.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-04 19:38:16 +01:00
Bob Dubner
438e82b8aa cobol: Make CXXFLAGS_FOR_TARGET available to the libgcobol build.
By setting "CXXFLAGS_FOR_TARGET=-ggdb -O0", a debuggable version
of libgcobol.so is created.

libgcobol

	* Makefile.am: Incorporate AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET).
	* Makefile.in: Regenerated.
2025-03-23 00:00:52 -04: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
Richard Biener
ddcb471e76 cobol/119281 - make sure $(gcc_version) is set for libgcobol install
When using --enable-version-specific-runtime-libs at least it's
required that $(gcc_version) is set to be able to expand
toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'

The following fixes this by adjusting configure.ac to call GCC_BASE_VER
and Makefile.am to include a definition for gcc_version.

libgcobol/
	* Makefile.am: Define gcc_version.
	* configure.ac: Execute GCC_BASE_VER.
	* Makefile.in: Regenerated.
	* configure: Likewise.
2025-03-14 13:32:15 +01:00
Jakub Jelinek
09c2a0ab94 cobol: Fix up libgcobol configure [PR119216]
Sorry, seems I've screwed up the earlier libgcobol/configure.tgt change.
Looking in more detail, the way e.g. libsanitizer/configure.tgt works is
that it is sourced twice, once at toplevel and there it just sets
UNSUPPORTED=1 for fully unsupported triplets, and then inside of
libsanitizer/configure where it decides to include or not include the
various sublibraries depending on the *_SUPPORTED flags.

So, the following patch attempts to do the same for libgcobol as well.

The BIULD_LIBGCOBOL automake conditional was unused, this patch guards it
on LIBGCOBOL_SUPPORTED as well and guards with it
toolexeclib_LTLIBRARIES  = libgcobol.la

Also, AM_CFLAGS has been changed to AM_CXXFLAGS as there are just C++
sources in the library.

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

	PR cobol/119216
	* configure.ac: Check for UNSUPPORTED set by libgcobol/configure.tgt
	rather than LIBGCOBOL_SUPPORTED.
	* configure: Regenerate.
libgcobol/
	* configure.tgt: On fully unsupported targets set UNSUPPORTED=1.
	* configure.ac: Add AC_CHECK_SIZEOF([void *]), source in
	configure.tgt and set BUILD_LIBGCOBOL also based on
	LIBGCOBOL_SUPPORTED.
	* Makefile.am (toolexeclib_LTLIBRARIES): Conditionalize on
	BUILD_LIBGCOBOL.
	(AM_CFLAGS): Rename to ...
	(AM_CXXFLAGS): ... this.
	(%.lo: %.cc): Use $(AM_CXXFLAGS) rather than $(AM_CFLAGS).
	* configure: Regenerate.
	* Makefile.in: Regenerate.
2025-03-11 14:36:53 +01:00
Jakub Jelinek
30efe7c5a0 cobol: libgcobol/Makefile.am cleanups
Looking at libgcobol.la, I see a lot of cruft, stuff that just shouldn't
be there because automake generates it otherwise right, but also stuff
using undefined variables etc.
libgcobol.{a,so*} seems to build and install the same as before.

Note, I stull see DT_RUNPATH in the installed libgcobol.so.1 before/after
this patch and I'd prefer not to see it, not seeing it in other libraries
like libstdc++.so.6 etc.  Dunno if that is because of the dependency on
libstdc++ (but e.g. libstdc++ has dependency on libgcc_s and doesn't do
that).

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

	* Makefile.am: Remove tons of VAR = @VAR@ style lines.
	(libgcobol.la): Remove.
	(libgcobol_la_LFLAGS): Remove.
	(all): Remove.
	(.PHONY): Remove.
	(install): Remove.
	(%.lo: %.c): Remove.
	(doc): Remove.
	(install-html install-pdf install-info): Remove.
	* Makefile.in: Regenerate.
2025-03-11 14:25:19 +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