Files
gcc/libgcobol/Makefile.am
Robert Dubner f1f0ab5d2f cobol: Reduce CFG complexity; improve PERFORM return logic; improve INSPECT performance.
Control FLow Graph complexity exploded because of indirect jumps. Those
have been replaced with SWITCH_EXPR.

A number of calls to gg_get_address_of() have been replaced with
gg_pointer_to_array() so that we properly get a pointer to the first element
of arrays, rather than a pointer to an array object.

The speed of the INSPECT (Format 1) STATEMENT has been improved by breaking
out a faster routine when the character set is single-byte-coded, like
ASCII or EBCDIC.

A number of COBOL variables were improperly allocated as executable globals.
They are now allocated as per-function static variables for top-level
COBOL program-ids.

gcc/cobol/ChangeLog:

	* cobol1.cc (cobol_langhook_handle_option): Handle OPT_Wrecording_mode.
	* gcobol.1: Documentation of pre-program registers.
	* genapi.cc (hijacker): Define new function hijacked code generation.
	(RETURN_WHEN_HIJACKED): Macro for wrapping if(hijacked)return;
	(hijacked): Either a boolean or false depending on ENABLE_HIJACKING.
	(set_exception_environment): Use gg_pointer_to_array instead of
	gg_get_address_of.
	(parser_statement_end): Formatting.
	(section_label): Change ALTER STATEMENT processing.
	(pseudo_return_push): Expand TRACE1 message.
	(pseudo_return_pop): Expand TRACE1 message; improved PERFORM processing.
	(find_procedure): Change how cbl_proc_t is allocated; improved PERFORM
	processing.
	(parser_enter_section): Changed ALTER statement processing.
	(parser_enter_paragraph): Likewise.
	(parser_goto): Use SWITCH_EXPR instead of indirect jump.
	(parser_perform): Likewise.
	(internal_perform_through): Likewise.
	(parser_enter_file): Use SWITCH_EXPR for implementing ENTRY statement.
	(parser_leave_file): Build table of values for the SWITCH_EXPR.
	(enter_program_common): Remove unused JMP *ptr.
	(parser_enter_program): Code to hijack code generation for a function
	"dubner" when ENABLE_HIJACKING is defined.
	(build_dispatch_switch): Generalize builder of SWITCH_EXPR.
	(build_alter_switch): Uses build_dispatch_switch.
	(build_entry_switch): Likewise.
	(build_perform_dispatcher): Likewise.
	(parser_end_program): Wrap build_perform_dispatcher() in if(!hijacked).
	(parser_init_list): Use RETURN_WHEN_HIJACKED; use gg_pointer_to_array()
	instead of gg_get_address_of().
	(psa_FldLiteralN): Set TREE_READONLY(var_decl) = 1.
	(parser_alphabet): use gg_pointer_to_array() instead of
	gg_get_address_of().
	(parser_assign): Formatting.
	(program_end_stuff): Call hijacking() when ENABLE_HIJACKING and the
	program-id is "hijack"; use gg_pointer_to_array().
	(parser_exit): Handle if(hijacked);
	(register_find): New static function to find XML-* COBOL variables.
	(parser_xml_parse): Updated XML PARSE statement handling.
	(initialize_the_data): Use RETURN_WHEN_HIJACKED.
	(establish_using): Change first-time-through processing.
	(parser_division): Change ENTRY statement processing.
	(parser_see_stop_run): Changed RETURN-CODE per-function variable
	processing.
	(parser_label_label): Use RETURN_WHEN_HIJACKED.
	(parser_label_goto): Likewise.
	(parser_perform_inline_times): Honor cbl_field_t offset for the count
	parameter.
	(inspect_tally): Use __gg__inspect_format_1_sbc() for SBC characters.
	(create_and_call): Use per-function RETURN-CODE.
	(parser_entry_activate): Eliminate static tree variables.
	(parser_entry): Use automatic tree variables.
	(parser_program_hierarchy): Use RETURN_WHEN_HIJACKED and
	gg_pointer_to_array().
	(build_temporaryN): New function compiled when ENABLE_HIJACKING.
	(hijack_for_development): Changed to generate minimal GENERIC.
	(actually_create_the_static_field): Use gg_structure_type_constructor
	to create the constructor for the static cblc_field_t VAR_DECL.
	(psa_FldLiteralA): Move where TREE attributes are established.
	(parser_local_add): Use gg_pointer_to_array().
	(parser_symbol_add): Use RETURN_WHEN_HIJACKED(); use gg_pointer_to_array().
	* gengen.cc (gg_append_statement): #if 0 around some debugging code.
	(gg_show_type): Expanded to display "static" and "readonly".
	(gg_find_field_in_struct): Moved and rewritten.
	(gg_get_structure_type_decl): New function.
	(gg_start_building_a_union): Eliminated.
	(gg_start_building_a_struct): Eliminated.
	(gg_add_field_to_structure): Eliminated.
	(gg_structure_type_constructor): New function.
	(gg_get_struct_type_decl): Eliminated.
	(gg_get_union_type_decl): Eliminated.
	(gg_get_local_struct_type_decl): Eliminated.
	(gg_get_filelevel_struct_type_decl): Eliminated.
	(gg_get_filelevel_union_type_decl): Eliminated.
	(gg_define_local_struct): Eliminated.
	(gg_assign_to_structure): Eliminated.
	(gg_define_array): Formatting.
	(gg_pointer_to_array): Returns ADDR_EXPR for &array[0];
	(gg_goto): Comment reflecting why we aren't using it.
	* gengen.h (SHORT_P): Alias for build_pointer_type(short_integer_type_node);
	(struct gg_function_t): Changes mostly in support of SWITCH_EXPR.
	(gg_get_local_struct_type_decl): Eliminated declaration.
	(gg_get_filelevel_struct_type_decl): Likewise.
	(gg_get_filelevel_union_type_decl): Likewise.
	(gg_define_local_struct): Likewise.
	(gg_get_structure_type_decl): New declaration.
	(gg_structure_type_constructor): New declaration.
	(gg_assign_to_structure): Eliminated declaration.
	(gg_define_uchar_star): Changed declaration.
	(gg_pointer_to_array): New declaration.
	* genutil.cc: Removed unused globals; added var_decl_entry_index.
	* genutil.h: Likewise.
	* parse.y: Change program-id and REDEFINES handling.
	* parse_ante.h: Likewise.
	* scan_ante.h (is_refmod): Rewrite.
	* structs.cc (create_cblc_field_t): Use gg_get_structure_type_decl().
	* symbols.cc (return_code_register): Use per-program COBOL registers.
	(symbol_redefines_root): New function.
	(symbols_update): Use per-program COBOL registers.
	(symbol_table_init): Implement per-program registers.
	(symbol_registers_add): Likewise.
	(cbl_field_t::encode): Loosen COBOL level requirement.
	* symbols.h (struct cbl_proc_t): SWITCH_EXPR-based PERFORM returns.
	(symbol_redefines_root): New declaration.
	(symbol_registers_add): New declaration.
	(new_alphanumeric): New comment.
	* util.cc (FOR_JIM): Remove some unused demonstration code.
	(cbl_field_t::encode_numeric): Likewise.

libgcobol/ChangeLog:

	* Makefile.am: Include new libgcobol/inspect.cc file.
	* Makefile.in: Likewise.
	* charmaps.h: Remove global RETURN-CODE
	* constants.cc (struct cblc_field_t): Eliminate various globals.
	* gcobolio.h: Eliminate cblc_field_t::dummy member.
	* libgcobol.cc (funky_find): Moved to inspect.cc.
	(funky_find_wide): Likewise.
	(funky_find_backward): Likewise.
	(funky_find_wide_backward): Likewise.
	(normalize_id): Likewise.
	(match_lengths): Likewise.
	(the_alpha_and_omega): Likewise.
	(the_alpha_and_omega_backward): Likewise.
	(inspect_backward_format_1): Likewise.
	(__gg__inspect_format_1): Likewise.
	(inspect_backward_format_2): Likewise.
	(__gg__inspect_format_2): Likewise.
	(normalize_for_inspect_format_4): Likewise.
	(__gg__inspect_format_4): Likewise.
	(__gg__is_canceled): Simplify establishing the function return code.
	(__gg__pseudo_return_push): Work with integer indexes rather than
	addresses.
	(__gg__set_data_member): New function.
	* xmlparse.cc (xml_event): Use passed variables rather than globals.
	(__gg__xml_parse): Likewise.
	* inspect.cc: New file.
2026-04-02 14:35:25 -04:00

111 lines
3.2 KiB
Makefile

# Copyright (C) 2026 Free Software Foundation, Inc.
# Contributed by the Symas Corporation, 2025
# This file is part of GCC.
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# Written de novo for libgcobol.
# Standard autoconf-set variables.
SHELL = @SHELL@
srcdir = @srcdir@
libdir = @libdir@
build = @build@
target = @target@
prefix = @prefix@
target_noncanonical = @target_noncanonical@
version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
AUTOMAKE_OPTIONS = 1.8 foreign subdir-objects
ACLOCAL_AMFLAGS = -I .. -I ../config
# May be used by various substitution variables.
gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
# Skip the whole process if we are not building libgcobol.
if BUILD_LIBGCOBOL
toolexeclib_LTLIBRARIES = libgcobol.la
toolexeclib_DATA = libgcobol.spec
libsubdir := $(libdir)/gcc/$(target_noncanonical)/$(version)$(MULTISUBDIR)/cobol
libsubincludedir = $(libsubdir)
##
## 2.2.12 Automatic Dependency Tracking
## Automake generates code for automatic dependency tracking by default
##
libgcobol_la_SOURCES = \
charmaps.cc \
constants.cc \
gfileio.cc \
gmath.cc \
inspect.cc \
intrinsic.cc \
io.cc \
libgcobol.cc \
posix/shim/errno.cc \
posix/shim/localtime.cc \
posix/shim/open.cc \
posix/shim/stat.cc \
stringbin.cc \
valconv.cc \
xmlparse.cc
libgcobol_la_LIBADD = -lxml2
nobase_libsubinclude_HEADERS = \
posix/cpy/posix-errno.cbl \
posix/cpy/statbuf.cpy \
posix/udf/posix-exit.cbl \
posix/udf/posix-localtime.cbl \
posix/udf/posix-mkdir.cbl \
posix/udf/posix-open.cbl \
posix/udf/posix-stat.cbl \
posix/udf/posix-unlink.cbl \
compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl \
compat/gnu/lib/CBL_ALLOC_MEM.cbl \
compat/gnu/lib/CBL_DELETE_FILE.cbl \
compat/gnu/lib/CBL_FREE_MEM.cbl \
compat/gnu/udf/stored-char-length.cbl
WARN_CFLAGS = -W -Wall -Wwrite-strings
AM_CPPFLAGS = -I. -I posix/shim $(LIBQUADINCLUDE)
AM_CPPFLAGS += $(LIBXML2_CPPFLAGS)
AM_CFLAGS = $(XCFLAGS)
AM_CXXFLAGS = $(XCFLAGS)
AM_CXXFLAGS += $(WARN_CFLAGS)
AM_CXXFLAGS += -DIN_TARGET_LIBS
AM_CXXFLAGS += -fstrict-aliasing -Wstrict-aliasing -Wstrict-aliasing=3
if ENABLE_DARWIN_AT_RPATH
# Handle embedded rpaths for Darwin.
extra_ldflags_libgcobol += -Wc,-nodefaultrpaths
extra_ldflags_libgcobol += -Wl,-rpath,@loader_path
endif
# We want to link with the c++ runtime.
libgcobol_la_LINK = $(CXXLINK) $(libgcobol_la_LDFLAGS)
version_arg = -version-info $(LIBGCOBOL_VERSION)
libgcobol_la_LDFLAGS = $(LTLDFLAGS) $(LIBQUADLIB) $(LTLIBICONV) \
$(extra_ldflags_libgcobol) $(LIBS) $(LIBXML2_LIBS) $(version_arg)
libgcobol_la_DEPENDENCIES = libgcobol.spec $(LIBQUADLIB_DEP)
endif BUILD_LIBGCOBOL