diff mbox series

Add 'cobol' to Makefile.def, take 2

Message ID 20241013204454.e8430201c02fcaf5c60b906b@schemamania.org
State New
Headers show
Series Add 'cobol' to Makefile.def, take 2 | expand

Commit Message

James K. Lowden Oct. 14, 2024, 12:44 a.m. UTC
Consequent to advice, I'm preparing the Cobol front-end patches as a
small number of hopefully meaningful patches covering many files.  

1.  meta files used by autotools etc.
2.  gcc/cobol/*.h
3.  gcc/cobol/*.{y,l,cc}
4.  libgcobol
5.  documentation
6.  tests

The patch below is step #1.  It comprises all the "meta files" needed
for the Cobol front end, including every existing file that we modified.  

1.  It does not interfere with --languages=c,c++, etc
2.  It does not work with --languages=cobol because the source files
are missing.  

If this looks OK, I'll continue on the same path. I can have the next
set ready tomorrow afternoon.  

The next message would be a set of 3 patches, steps 2-4 above.  That
will build with --languages=cobol, but not install or test.  Test &
documentation files would comprise the remaining patches. 

In testing the patch with "git am", I got a warning about a blank line
at EOF, but I couldn't figure out where it was, or if it mattered.  

--jkl

From 06a93d00f4433fb61ff9611c6e945a3a11c89479bld.patch 4 Oct 2024 12:01:22 -0400
From: "James K. Lowden" <jklowden@symas.com>
Date: Mon 14 Oct 2024 03:25:23 PM EDT
Subject: [PATCH]  Add 'cobol' to 9 files

	* Makefile.def: Add libgcobol module and cobol language.
	* configure: Add libgcobol module and cobol language.
	* configure.ac: Add libgcobol module and cobol language.
	* gcc/cobol/LICENSE: Add gcc/cobol/LICENSE
	* gcc/cobol/Make-lang.in: Add libgcobol module and cobol language.
	* gcc/cobol/config-lang.in: Add libgcobol module and cobol language.
	* gcc/cobol/lang.opt: Add libgcobol module and cobol language.
	* gcc/common.opt: Add libgcobol module and cobol language.

---
Makefile.def | ++++++-
configure | +-
configure.ac | +-
gcc/cobol/LICENSE | +++++++++++++++++++++++++++++-
gcc/cobol/Make-lang.in | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
gcc/cobol/config-lang.in | ++++++++++++++++++-
gcc/cobol/lang.opt | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
gcc/common.opt | ++++++++
8 files changed, 439 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/Makefile.def b/Makefile.def
index 19954e7d731..1192e852c7a 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -209,6 +209,7 @@  target_modules = { module= libgomp; bootstrap= true; lib_path=.libs; };
 target_modules = { module= libitm; lib_path=.libs; };
 target_modules = { module= libatomic; bootstrap=true; lib_path=.libs; };
 target_modules = { module= libgrust; };
+target_modules = { module= libgcobol; };
 
 // These are (some of) the make targets to be done in each subdirectory.
 // Not all; these are the ones which don't have special options.
@@ -324,6 +325,7 @@  flags_to_pass = { flag= CXXFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= DLLTOOL_FOR_TARGET ; };
 flags_to_pass = { flag= DSYMUTIL_FOR_TARGET ; };
 flags_to_pass = { flag= FLAGS_FOR_TARGET ; };
+flags_to_pass = { flag= GCOBOL_FOR_TARGET ; };
 flags_to_pass = { flag= GFORTRAN_FOR_TARGET ; };
 flags_to_pass = { flag= GOC_FOR_TARGET ; };
 flags_to_pass = { flag= GOCFLAGS_FOR_TARGET ; };
@@ -655,6 +657,7 @@  lang_env_dependencies = { module=libgcc; no_gcc=true; no_c=true; };
 // built newlib on some targets (e.g. Cygwin).  It still needs
 // a dependency on libgcc for native targets to configure.
 lang_env_dependencies = { module=libiberty; no_c=true; };
+lang_env_dependencies = { module=libgcobol; cxx=true; };
 
 dependencies = { module=configure-target-fastjar; on=configure-target-zlib; };
 dependencies = { module=all-target-fastjar; on=all-target-zlib; };
@@ -690,6 +693,7 @@  dependencies = { module=install-target-libvtv; on=install-target-libgcc; };
 dependencies = { module=install-target-libitm; on=install-target-libgcc; };
 dependencies = { module=install-target-libobjc; on=install-target-libgcc; };
 dependencies = { module=install-target-libstdc++-v3; on=install-target-libgcc; };
+dependencies = { module=install-target-libgcobol; on=install-target-libstdc++-v3; };
 
 // Target modules in the 'src' repository.
 lang_env_dependencies = { module=libtermcap; };
@@ -727,6 +731,8 @@  languages = { language=d;	gcc-check-target=check-d;
 				lib-check-target=check-target-libphobos; };
 languages = { language=jit;	gcc-check-target=check-jit; };
 languages = { language=rust;	gcc-check-target=check-rust; };
+languages = { language=cobol;	gcc-check-target=check-cobol;
+				lib-check-target=check-target-libgcobol; };
 
 // Toplevel bootstrap
 bootstrap_stage = { id=1 ; };
diff --git a/configure b/configure
index 51bf1d1add1..a64b884be6d 100755
--- a/configure
+++ b/configure
@@ -2859,6 +2859,7 @@  target_libraries="target-libgcc \
 		target-libgfortran \
 		target-libffi \
 		target-libobjc \
+		target-libgcobol \
 		target-libada \
 		target-libgm2 \
 		target-libgo \
diff --git a/configure.ac b/configure.ac
index 20457005e29..7ae3b5128ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -161,6 +161,7 @@  target_libraries="target-libgcc \
 		target-libgfortran \
 		target-libffi \
 		target-libobjc \
+		target-libgcobol \
 		target-libada \
 		target-libgm2 \
 		target-libgo \
diff --git a/gcc/cobol/LICENSE b/gcc/cobol/LICENSE
new file mode 100644
index 00000000000..6cb64d44790
--- /dev/null
+++ b/gcc/cobol/LICENSE
@@ -0,0 +1,29 @@ 
+#########################################################################
+#
+# Copyright (c) 2019-2022 Symas Corporation
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the following disclaimer
+#   in the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of the Symas Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived from
+#   this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in
new file mode 100644
index 00000000000..6a57585a729
--- /dev/null
+++ b/gcc/cobol/Make-lang.in
@@ -0,0 +1,232 @@ 
+# Top level -*- makefile -*- fragment for Cobol
+#   Copyright (C) 2016 Free Software Foundation, Inc.
+
+# 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/>.
+
+# This file provides the language dependent support in the main Makefile.
+# Each language makefile fragment must provide the following targets:
+#
+# foo.all.cross, foo.start.encap, foo.rest.encap,
+# foo.install-common, foo.install-man, foo.install-info, foo.install-pdf,
+# foo.install-html, foo.info, foo.dvi, foo.pdf, foo.html, foo.uninstall,
+# foo.mostlyclean, foo.clean, foo.distclean,
+# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
+#
+# where `foo' is the name of the language.
+#
+# It should also provide rules for:
+#
+# - making any compiler driver (eg: g++)
+# - the compiler proper (eg: cc1plus)
+# - define the names for selecting the language in LANGUAGES.
+
+ifeq ("$(USER)","bob")
+	MAX_ERRORS := -fmax-errors=1
+endif
+
+gcobol_INSTALL_NAME := $(shell echo gcobol|sed '$(program_transform_name)')
+gcobol_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcobol|sed '$(program_transform_name)')
+
+cobol: cobol1$(exeext)
+
+.PHONY: cobol
+
+BINCLUDE ?= ./gcc
+
+#
+# At this point, as of 2022-10-21, CPPFLAGS is an empty string and can be
+# altered.  CFLAGS and CXXFLAGS are being established upstream, and thus
+# cannot, at this point, be changed.
+#
+
+CPPFLAGS =					\
+ -std=c++17 					\
+ $(MAX_ERRORS)					\
+ -Iinclude					\
+ -I$(BINCLUDE)					\
+ -Wno-cpp					\
+ -Wno-missing-field-initializers		\
+ -DEXEC_LIB=\"$(DESTDIR)$(libdir)\"
+ $(END)
+
+YACC = bison
+YFLAGS = -Werror -Wmidrule-values -Wno-yacc \
+	--debug --token-table  --verbose
+
+LEX = flex
+LFLAGS = -d -Ca
+
+#
+# These are the object files for creating the cobol1.exe compiler:
+#
+
+cobol_one_OBJS =    \
+ cobol/cdf.o        \
+ cobol/cdf-copy.o   \
+ cobol/cobol1.o     \
+ cobol/convert.o    \
+ cobol/except.o     \
+ cobol/genutil.o    \
+ cobol/genapi.o     \
+ cobol/genmath.o    \
+ cobol/gengen.o     \
+ cobol/lexio.o      \
+ cobol/parse.o      \
+ cobol/scan.o       \
+ cobol/structs.o    \
+ cobol/symbols.o    \
+ cobol/symfind.o    \
+ cobol/util.o       \
+ cobol/valconv.o    \
+ cobol/charmaps.o   \
+ $(END)
+
+# cobol/charutf8.o   \
+
+#
+# These are the object files for creating the gcobol.exe "driver"
+#
+GCOBOL_D_OBJS = $(GCC_OBJS) cobol/gcobolspec.o
+
+#
+# These get combined to provide a dependency relationship that ensures all
+# of the "generated-files" are generated before we need them.  See the root
+# Makefile.in code that looks like this:
+#       ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
+#
+
+cobol_OBJS = \
+   $(cobol_one_OBJS) \
+   cobol/gcobolspec.o \
+   $(END)
+
+#
+# Frankly, I can't figure out what this does:
+#
+
+CFLAGS-cobol/gcobolspec.o += $(DRIVER_DEFINES)
+
+#
+# This controls the build of the gcobol.exe "driver"
+#
+
+gcobol$(exeext): \
+	 $(GCOBOL_D_OBJS) \
+	 $(EXTRA_GCC_OBJS) \
+     libcommon-target.a \
+     $(LIBDEPS)
+	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@		\
+	 $(GCOBOL_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a	\
+	 $(EXTRA_GCC_LIBS) $(LIBS)
+
+#
+# These control the build of the cobol1.exe source-to-GENERIC converter
+#
+
+# First, files needed for parsing:
+
+cobol/parse.c: cobol/parse.y cobol/genapi.h cobol/parse_ante.h
+	$(YACC) -o $@ $(YFLAGS)				\
+		--defines=cobol/parse.h			\
+		--report-file=cobol/parser.out $<
+
+cobol/cdf.c: cobol/cdf.y cobol/genapi.h
+	$(YACC) -o $@ $(YFLAGS)						\
+		--defines=cobol/cdf.h --report-file=cobol/cdf.out $<
+
+cobol/scan.c: cobol/scan.l cobol/scan_ante.h cobol/scan_post.h
+	$(LEX) -o$@ $(LFLAGS) $<
+
+cobol/scan.o: cobol/parse.c # cobol/parse.h # parse.h gets built along with parse.c
+
+# And the cobol1.exe front end
+
+cobol1$(exeext): $(cobol_one_OBJS) $(BACKEND) $(LIBDEPS) attribs.o
+	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) attribs.o -o $@	\
+	      $(cobol_one_OBJS) $(BACKEND) $(LIBS) $(BACKENDLIBS)
+
+## Other dependencies
+# mkdep cobol/*.cc; grep -E '^[[:alnum:]_][.]o|cobol/' .depend |
+# awk '{gsub(/[/]usr[^ \n]+ ?/, ""); gsub(/cobol[^ ]+[.]cc/, ""); } 1' \
+#     > /tmp/depends && rm .depend
+
+cdf-copy.o:  cobol/copybook.h
+symbols.o:   cobol/genapi.h cobol/symbols.h cobol/inspect.h cobol/io.h
+
+# FIXME
+cobol.all.cross:
+
+cobol.start.encap: gcobol$(exeext)
+
+cobol.rest.encap:
+
+cobol.install-common: installdirs
+	$(INSTALL_PROGRAM) -v gcobol$(exeext)				\
+		$(DESTDIR)$(bindir)/$(gcobol_INSTALL_NAME)$(exeext)
+	$(INSTALL_PROGRAM) -v $(srcdir)/cobol/gcobc $(DESTDIR)$(bindir)/
+	$(INSTALL_DATA) -v $(srcdir)/cobol/udf/* $(udfdir)/
+
+cobol.install-man: installdirs
+	$(INSTALL_DATA) -v $(srcdir)/cobol/gcobol.1 $(DESTDIR)$(man1dir)/
+	$(INSTALL_DATA) -v $(srcdir)/cobol/gcobol.3 $(DESTDIR)$(man3dir)/
+
+cobol.install-info:
+
+cobol.install-pdf:
+
+cobol.install-plugin:
+
+cobol.install-html:
+
+cobol.info:
+
+cobol.dvi:
+
+cobol.pdf:
+
+cobol.html:
+
+cobol.uninstall:
+	-rm -f gcobol$(exeext) cobol1$(exeext)
+	-rm -f $(cobol_OBJS)
+
+cobol.man:
+
+cobol.mostlyclean:
+
+cobol.clean:
+	rm -fr cobol1 cobol/* ../*/libgcobol/*
+
+cobol.distclean:
+
+cobol.maintainer-clean:
+
+# The main makefile has already created stage?/cobol.
+cobol.stage1: stage1-start
+	-mv cobol/*$(objext) stage1/cobol
+cobol.stage2: stage2-start
+	-mv cobol/*$(objext) stage2/cobol
+cobol.stage3: stage3-start
+	-mv cobol/*$(objext) stage3/cobol
+cobol.stage4: stage4-start
+	-mv cobol/*$(objext) stage4/cobol
+cobol.stageprofile: stageprofile-start
+	-mv cobol/*$(objext) stageprofile/cobol
+cobol.stagefeedback: stagefeedback-start
+	-mv cobol/*$(objext) stagefeedback/cobol
+
+selftest-cobol:
diff --git a/gcc/cobol/config-lang.in b/gcc/cobol/config-lang.in
new file mode 100644
index 00000000000..4098105135f
--- /dev/null
+++ b/gcc/cobol/config-lang.in
@@ -0,0 +1,18 @@ 
+language="cobol"
+
+compilers="cobol1\$(exeext)"
+
+target_libs="libgcobol.a"
+
+# Files that should be scanned by gengtype.c to generate the garbage
+# collection tables.  Not obviously needed.
+
+gtfiles="\$(srcdir)/cobol/cobol1.cc"
+
+# We might write (some of) the cobol FE in C++
+#### lang_requires_boot_languages=c++
+
+# Do not build by default
+build_by_default="no"
+
+
diff --git a/gcc/cobol/lang.opt b/gcc/cobol/lang.opt
new file mode 100644
index 00000000000..3917bdb3182
--- /dev/null
+++ b/gcc/cobol/lang.opt
@@ -0,0 +1,144 @@ 
+; lang.opt -- Options for the gcc Cobol front end.
+
+; Copyright (C) 2009-2020 Free Software Foundation, Inc.
+;
+; 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/>.
+
+; See the GCC internals manual for a description of this file's format.
+
+; Please try to keep this file in ASCII collating order.
+
+Language
+Cobol
+
+D
+Cobol Joined Separate
+; Documented in c.opt
+
+E
+Cobol
+; Documented in c.opt
+
+I
+Cobol Joined Separate
+;;  -I <dir>	Add copybook search directory
+; Documented in c.opt
+
+dialect
+Cobol Joined Separate Enum(dialect_type) EnumBitSet Var(cobol_dialect)
+Accept COBOL constructs used by non-ISO compilers
+
+Enum
+Name(dialect_type) Type(int) UnknownError(Unrecognized COBOL dialect name: %qs)
+
+EnumValue
+Enum(dialect_type) String(gcc) Value(0x04) Canonical
+
+EnumValue
+Enum(dialect_type) String(ibm) Value(0x01)
+
+EnumValue
+Enum(dialect_type) String(mf)  Value(0x02)
+
+EnumValue
+Enum(dialect_type) String(gnu) Value(0x04)
+
+fcobol-exceptions
+Cobol Joined Separate Var(cobol_exceptions)
+-fcobol-exceptions=<n>	Enable some exceptions by default
+
+copyext
+Cobol Joined Separate Var(cobol_copyext) Init(0)
+Define alternative implicit copybook filename extension
+
+fdefaultbyte
+Cobol RejectNegative Joined Separate UInteger Var(cobol_default_byte)
+Set Working-Storage data items to the supplied value
+
+fflex-debug
+Cobol Var(yy_flex_debug, 1) Init(0)
+Enable Cobol lex debugging
+
+ffixed-form
+Cobol RejectNegative
+Assume that the source file is fixed form.
+
+fsyntax-only
+Cobol RejectNegative
+; Documented in c.opt
+
+ffree-form
+Cobol RejectNegative
+Assume that the source file is free form.
+
+findicator-column
+Cobol RejectNegative Joined Separate UInteger Var(indicator_column) Init(0) IntegerRange(0, 8)
+-findicator-column=<n>	Column after which Region A begins
+
+finternal-ebcdic
+Cobol Var(cobol_ebcdic, 1) Init(0)
+-finternal-ebcdic	Internal processing is in EBCDIC Code Page 1140
+
+fmax-errors
+Cobol Joined Separate
+; Documented in C
+
+fstatic-call
+Cobol Var(cobol_static_call, 1) Init(1)
+Enable/disable static linkage for CALL literals
+
+ftrace-debug
+Cobol Var(cobol_trace_debug, 1) Init(0)
+Enable Cobol parser debugging
+
+fyacc-debug
+Cobol Var(yy_debug, 1) Init(0)
+Enable Cobol yacc debugging
+
+preprocess
+Cobol Joined Separate Var(cobol_preprocess)
+preprocess <source_filter> before compiling
+
+iprefix
+Cobol Joined Separate
+; Documented in C
+
+include
+Cobol Joined Separate Var(cobol_include)
+; Documented in C
+
+isysroot
+Cobol Joined Separate
+; Documented in C
+
+isystem
+Cobol Joined Separate
+; Documented in C
+
+main
+Cobol
+-main	The first program-id in the next source file is called by a generated main() entry point
+
+main=
+Cobol Joined Var(cobol_main_string)
+-main=<source_file> source_file/PROGRAM-ID is called by the generated main()
+
+nomain
+Cobol
+-nomain	No main() function is created from COBOL source files
+
+; This comment is to ensure we retain the blank line above.
diff --git a/gcc/common.opt b/gcc/common.opt
index ea39f87ae71..bb941d76a05 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1602,6 +1602,10 @@  fdump-passes
 Common Var(flag_dump_passes) Init(0)
 Dump optimization passes.
 
+fdump-generic-nodes
+Common Var(flag_dump_generic_nodes) Init(0)
+Dump GENERIC trees for each function in three files: <funcname>.nodes, <funcname>.nodes.html, and <funcname>.nodes.html
+
 fdump-unnumbered
 Common Var(flag_dump_unnumbered)
 Suppress output of instruction numbers, line number notes and addresses in debugging dumps.
@@ -3829,6 +3833,10 @@  static-libgfortran
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libgcobol
+Driver
+; Documented for COBOL, but always accepted by driver.
+
 static-libgm2
 Driver
 ; Documented for Modula-2, but always accepted by driver.