Re: [PATCH] m2, build: Use LDLFAGS for mklink

2023-07-13 Thread Gaius Mulley via Gcc-patches
Rainer Orth  writes:

> When trying to bootstrap current trunk on macOS 14.0 beta 3 with Xcode
> 15 beta 4, the build failed running mklink in stage 2:
>
> unset CC ; m2/boot-bin/mklink -s --langc++ --exit --name m2/mc-boot/main.cc 
> /vol/gcc/src/hg/master/darwin/gcc/m2/init/mcinit
> dyld[55825]: Library not loaded: /vol/gcc/lib/libstdc++.6.dylib
>
> While it's unclear to me why this only happens on macOS 14, the problem
> is clear: unlike other C++ executables, mklink isn't linked with
> -static-libstdc++ which is passed in from toplevel in LDFLAGS.
>
> This patch fixes that and allows the build to continue.
>
> Bootstrapped on x86_64-apple-darwin23.0.0, i386-pc-solaris2.11, and
> sparc-sun-solaris2.11.
>
> Ok for trunk?
>
>   Rainer

sure yes - and thanks for the fix,

regards,
Gaius


Re: [PATCH] modula-2: Amend the handling of failed select() calls in RTint [PR108835].

2023-06-28 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on various affected Darwin versions and on x86_64-linux-gnu
> OK for trunk?
> OK for 13.2?
> thanks
> Iain

lgtm - many thanks,

regards,
Gaius


Re: [PATCH] modula2: Fix bootstrap

2023-06-06 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> Hi!
>
> internal-fn.h since yesterday includes insn-opinit.h, which is a generated
> header.
> One of my bootstraps today failed because some m2 sources started compiling
> before insn-opinit.h has been generated.
>
> Normally, gcc/Makefile.in has
> # In order for parallel make to really start compiling the expensive
> # objects from $(OBJS) as early as possible, build all their
> # prerequisites strictly before all objects.
> $(ALL_HOST_OBJS) : | $(generated_files)
>
> rule which ensures that all the generated files are generated before
> any $(ALL_HOST_OBJS) objects start, but use order-only dependency for
> this because we don't want to rebuild most of the objects whenever one
> generated header is regenerated.  After the initial build in an empty
> directory we'll have .deps/ files contain the detailed dependencies.
>
> $(ALL_HOST_OBJS) includes even some FE files, I think in the m2 case
> would be m2_OBJS, but m2/Make-lang.in doesn't define those.
>
> The following patch just adds a similar rule to m2/Make-lang.in.
> Another option would be to set m2_OBJS variable in m2/Make-lang.in to
> something, but not really sure to which exactly and why it isn't
> done.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


> 2023-06-06  Jakub Jelinek  
>
>   * Make-lang.in: Build $(generated_files) before building
>   all $(GM2_C_OBJS).
>
> --- gcc/m2/Make-lang.in.jj2023-05-04 09:31:27.289948109 +0200
> +++ gcc/m2/Make-lang.in   2023-06-06 21:38:26.655336041 +0200
> @@ -511,6 +511,8 @@ GM2_LIBS_BOOT = m2/gm2-compiler-boot
>  m2/gm2-libs-boot/libgm2.a \
>  $(GM2-BOOT-O)
>  
> +$(GM2_C_OBJS) : | $(generated_files)
> +
>  cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
>   cp -p $< $@
>  
>
>
>   Jakub

Hi Jakub,

sure looks good to me - thanks for the patch,

regards,
Gaius


Re: [PATCH 05/14] m2: use _P() defines from tree.h

2023-05-13 Thread Gaius Mulley via Gcc-patches
Bernhard Reutner-Fischer via Gcc-patches 
writes:

> From: Bernhard Reutner-Fischer 
>
> gcc/m2/ChangeLog:
>
>   * gm2-gcc/m2builtins.cc (doradix): Use _P defines from tree.h.
>   (doplaces): Ditto.
>   (doexponentmin): Ditto.
>   (doexponentmax): Ditto.
>   (dolarge): Ditto.
>   (dosmall): Ditto.
>   (dogUnderflow): Ditto.
>   * gm2-gcc/m2convert.cc (unsafe_conversion_p): Ditto.
>   * gm2-gcc/m2expr.cc (m2expr_build_unary_op_check): Ditto.
>   (m2expr_build_binary_op_check): Ditto.
>   * gm2-gcc/m2tree.cc (m2tree_is_var): Ditto.
>   * gm2-gcc/m2treelib.cc (build_modify_expr): Ditto.
>   * gm2-gcc/m2type.cc (gm2_finish_decl): Ditto.
>   * m2pp.cc (hextree): Ditto.
>   (m2pp_call_expr): Ditto.
> ---
>  gcc/m2/gm2-gcc/m2builtins.cc | 14 +++---
>  gcc/m2/gm2-gcc/m2convert.cc  |  8 
>  gcc/m2/gm2-gcc/m2expr.cc |  4 ++--
>  gcc/m2/gm2-gcc/m2tree.cc |  2 +-
>  gcc/m2/gm2-gcc/m2treelib.cc  |  2 +-
>  gcc/m2/gm2-gcc/m2type.cc |  4 ++--
>  gcc/m2/m2pp.cc   |  4 ++--
>  7 files changed, 19 insertions(+), 19 deletions(-)

Hi Bernhard,

from the m2 perspective - lgtm - thanks for the patch!

regards,
Gaius


Re: [PATCH 05/14] m2: use _P() defines from tree.h

2023-05-13 Thread Gaius Mulley via Gcc-patches
Bernhard Reutner-Fischer via Gcc-patches 
writes:

> From: Bernhard Reutner-Fischer 
>
> gcc/m2/ChangeLog:
>
>   * gm2-gcc/m2builtins.cc (doradix): Use _P defines from tree.h.
>   (doplaces): Ditto.
>   (doexponentmin): Ditto.
>   (doexponentmax): Ditto.
>   (dolarge): Ditto.
>   (dosmall): Ditto.
>   (dogUnderflow): Ditto.
>   * gm2-gcc/m2convert.cc (unsafe_conversion_p): Ditto.
>   * gm2-gcc/m2expr.cc (m2expr_build_unary_op_check): Ditto.
>   (m2expr_build_binary_op_check): Ditto.
>   * gm2-gcc/m2tree.cc (m2tree_is_var): Ditto.
>   * gm2-gcc/m2treelib.cc (build_modify_expr): Ditto.
>   * gm2-gcc/m2type.cc (gm2_finish_decl): Ditto.
>   * m2pp.cc (hextree): Ditto.
>   (m2pp_call_expr): Ditto.

Hi Bernhard,

from the m2 perspective - all looks good to me - thanks for the patch,

regards,
Gaius


Re: libgm2: Remove 'autogen.sh'

2023-05-11 Thread Gaius Mulley via Gcc-patches
Thomas Schwinge  writes:

> Hi!
>
> On 2023-04-14T13:49:20+0100, Gaius Mulley via Gcc-patches 
>  wrote:
>> Thomas Schwinge  writes:
>>> Separately, given that plain 'autoreconf' works, why have 'autogen.sh' at
>>> all?
>>
>> If autoreconf does the same as autogen.sh then yes this can be removed
>
> Pushed to master branch commit bd6dbdb196da5aa5c7354e0fc7b0a146237bcf8a
> "libgm2: Remove 'autogen.sh'".
>
>
>> (or its contents replaced with a call to autoreconf perhaps?),
>
> I didn't see any advantage in that.
>
>
> Grüße
>  Thomas

thank you!

regards,
Gaius


Re: [PATCH] gcc/m2: Drop references to $(P)

2023-04-21 Thread Gaius Mulley via Gcc-patches
Arsen Arsenović  writes:

> $(P) seems to have been a workaround for some old, proprietary make
> implementations that we no longer support.  It was removed in
> r0-31149-gb8dad04b688e9c.
>
> gcc/m2/ChangeLog:
>
>   * Make-lang.in: Remove references to $(P).
>   * Make-maintainer.in: Ditto.
> ---
> Hi,
>
> We spotted that the m2 makefile includes some long-gone compatibility
> variable $(P), presumably left over from when m2 was not in the tree
> yet.  This induced a build failure on our end:
> https://bugs.gentoo.org/904714
>
> Build-tested on x86_64-pc-linux-gnu.  I haven't finished running the
> testsuite.  I believe this only ever expands to an empty string (if not
> set by the env) in the current build system, so in theory, it should be
> safe.
>
> OK for gcc-13 and trunk (with a priority on the former)?
>
>  gcc/m2/Make-lang.in   | 4 ++--
>  gcc/m2/Make-maintainer.in | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
> index b34db0d9156..d0fa692e5b8 100644
> --- a/gcc/m2/Make-lang.in
> +++ b/gcc/m2/Make-lang.in
> @@ -514,7 +514,7 @@ GM2_LIBS_BOOT = m2/gm2-compiler-boot/gm2.a \
>  cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
>   cp -p $< $@
>  
> -m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) 
> m2/gm2-compiler/m2flex.o $(P) \
> +m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) 
> m2/gm2-compiler/m2flex.o \
>  $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS) \
>  m2/gm2-gcc/rtegraph.o plugin/m2rte$(soext)
>   -test -d $(@D) || $(mkinstalldirs) $(@D)
> @@ -527,7 +527,7 @@ m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) 
> m2/gm2-compiler/m2flex.o $(
>   @$(call LINK_PROGRESS,$(INDEX.m2),end)
>  
>  m2/stage1/cc1gm2$(exeext): gm2$(exeext) m2/gm2-compiler-boot/m2flex.o \
> -$(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) \
> +$(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) \
>  $(GM2_LIBS_BOOT) $(MC_LIBS) \
>  m2/gm2-gcc/rtegraph.o plugin/m2rte$(soext) \
>  $(m2.prev)
> diff --git a/gcc/m2/Make-maintainer.in b/gcc/m2/Make-maintainer.in
> index 17bd9a2d37e..a70682673cd 100644
> --- a/gcc/m2/Make-maintainer.in
> +++ b/gcc/m2/Make-maintainer.in
> @@ -753,7 +753,7 @@ GM2_LIBS_PARANOID = m2/gm2-compiler-paranoid/gm2.a \
>  gm2.paranoid: m2/m2obj3/cc1gm2$(exeext) gm2.verifyparanoid
>  
>  m2/m2obj3/cc1gm2$(exeext): m2/m2obj2/cc1gm2$(exeext) 
> m2/gm2-compiler-paranoid/m2flex.o \
> -$(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) 
> $(GM2_LIBS_PARANOID) \
> +$(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) 
> $(GM2_LIBS_PARANOID) \
>  m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so 
> m2/gm2-libs-boot/M2LINK.o
>   -test -d m2/m2obj3 || $(mkinstalldirs) m2/m2obj3
>   @$(call LINK_PROGRESS,$(INDEX.m2),start)

Hi,

yes certainly this is fine.  lgtm.  Thanks for spotting and the patch

regards,
Gaius


Re: libgm2: Adjust 'autogen.sh' to 'ACLOCAL_AMFLAGS', and simplify

2023-04-14 Thread Gaius Mulley via Gcc-patches
Thomas Schwinge  writes:

> Hi!
>
> On 2022-12-06T14:47:26+0000, Gaius Mulley via Gcc-patches 
>  wrote:
>> This patch set consists of the libgm2 makefile, autoconf sources
>> necessary to build the libm2pim, libm2iso, libm2min, libm2cor
>> and libm2log.
>
> Notice:
>
>> --- /dev/null 2022-08-24 16:22:16.88870 +0100
>> +++ gcc-git-devel-modula2/libgm2/Makefile.am  2022-12-06 02:56:51.428775868 
>> +
>
>> +ACLOCAL_AMFLAGS = -I . -I .. -I ../config
>
> ... this vs.:
>
>> --- /dev/null 2022-08-24 16:22:16.88870 +0100
>> +++ gcc-git-devel-modula2/libgm2/autogen.sh   2022-12-06 02:56:51.432775922 
>> +
>
>> +aclocal -I . -I ../config
>> +autoreconf -I . -I ../config
>
> ... this: for the latter, no explicit '-I ..' before '-I ../config'.
> This means that 'autogen.sh' vs. plain 'autoreconf' don't produce
> identical results: different order of files found via search paths.
> OK to align (and simplify) that as per the attached
> "libgm2: Adjust 'autogen.sh' to 'ACLOCAL_AMFLAGS', and simplify"?

Hi Thomas,

thanks for detecting the bug and the patch - yes looks good to me - feel
free to apply.

> Separately, given that plain 'autoreconf' works, why have 'autogen.sh' at
> all?

If autoreconf does the same as autogen.sh then yes this can be removed
(or its contents replaced with a call to autoreconf perhaps?),

regards,
Gaius

>
>
> Grüße
>  Thomas
>
>
> -
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße
> 201, 80634 München; Gesellschaft mit beschränkter Haftung;
> Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft:
> München; Registergericht München, HRB 106955
>
>>From 8fd7ff138c83200ab83df7f08f773e33961550b4 Mon Sep 17 00:00:00 2001
> From: Thomas Schwinge 
> Date: Tue, 11 Apr 2023 21:40:14 +0200
> Subject: [PATCH] libgm2: Adjust 'autogen.sh' to 'ACLOCAL_AMFLAGS', and
>  simplify
>
> Specifying explicit '-I ..' before '-I ../config' is what (most) other GCC
> components do.  Specifying '-I .' is not necessary.
>
> With the order of '-I's aligned, 'autogen.sh' and plain 'autoreconf' then
> produce identical results.
>
>   libgm2/
>   * autogen.sh: For 'aclocal', 'autoreconf', remove '-I .',
>   add '-I ..'.
>   * Makefile.am (ACLOCAL_AMFLAGS): Remove '-I .'.
>   * libm2cor/Makefile.am (ACLOCAL_AMFLAGS): Likewise.
>   * libm2iso/Makefile.am (ACLOCAL_AMFLAGS): Likewise.
>   * libm2log/Makefile.am (ACLOCAL_AMFLAGS): Likewise.
>   * libm2min/Makefile.am (ACLOCAL_AMFLAGS): Likewise.
>   * libm2pim/Makefile.am (ACLOCAL_AMFLAGS): Likewise.
>   * aclocal.m4: Regenerate.
>   * Makefile.in: Likewise.
>   * libm2cor/Makefile.in: Likewise.
>   * libm2iso/Makefile.in: Likewise.
>   * libm2log/Makefile.in: Likewise.
>   * libm2min/Makefile.in: Likewise.
>   * libm2pim/Makefile.in: Likewise.
> ---
>  libgm2/Makefile.am  |  2 +-
>  libgm2/Makefile.in  | 12 ++--
>  libgm2/aclocal.m4   | 10 +-
>  libgm2/autogen.sh   |  5 ++---
>  libgm2/libm2cor/Makefile.am |  2 +-
>  libgm2/libm2cor/Makefile.in | 12 ++--
>  libgm2/libm2iso/Makefile.am |  2 +-
>  libgm2/libm2iso/Makefile.in | 12 ++--
>  libgm2/libm2log/Makefile.am |  2 +-
>  libgm2/libm2log/Makefile.in | 12 ++--
>  libgm2/libm2min/Makefile.am |  2 +-
>  libgm2/libm2min/Makefile.in | 12 ++--
>  libgm2/libm2pim/Makefile.am |  2 +-
>  libgm2/libm2pim/Makefile.in | 12 ++--
>  14 files changed, 49 insertions(+), 50 deletions(-)
>
> diff --git a/libgm2/Makefile.am b/libgm2/Makefile.am
> index 0b593f6ff216..95df3ed7a301 100644
> --- a/libgm2/Makefile.am
> +++ b/libgm2/Makefile.am
> @@ -25,7 +25,7 @@ AUTOMAKE_OPTIONS = 1.8 foreign
>  
>  SUFFIXES = .c .mod .def .o .obj .lo .a
>  
> -ACLOCAL_AMFLAGS = -I . -I .. -I ../config
> +ACLOCAL_AMFLAGS = -I .. -I ../config
>  
>  # Multilib support.
>  MAKEOVERRIDES=
> diff --git a/libgm2/Makefile.in b/libgm2/Makefile.in
> index da2ec7c2a098..d9950065de19 100644
> --- a/libgm2/Makefile.in
> +++ b/libgm2/Makefile.in
> @@ -90,15 +90,15 @@ host_triplet = @host@
>  target_triplet = @target@
>  subdir = .
>  ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
> -am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
> - $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
> - $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
> - $(top_srcdir)/../config/acx.m4 \
> +am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
>   $(top_srcdir)/../config/depstand.m4 \
>   $(top_srcdir)/../config/lead-dot.m4 \
>   $(t

Re: [PATCH] Modula-2: fix documentation layout

2023-03-27 Thread Gaius Mulley via Gcc-patches
Eric Botcazou  writes:

> Hi Gaius,
>
>> yes indeed and thanks for the patch!
>
> You're welcome.  The documentation was slightly broken again in the meantime, 
> but nothing really serious this time.
>
> Again tested with a modern and an old version of Makeinfo.  OK for mainline?
>
>
> 2023-03-27  Eric Botcazou  
>
>   * doc/gm2.texi: Add missing Next, Previous and Top fields to most
>   top-level sections.

Hi Eric,

yes certainly - thanks again!

regards,
Gaius


Re: [wwwdocs] document modula-2 in gcc-13/changes.html (and index.html)

2023-03-15 Thread Gaius Mulley via Gcc-patches
Gerald Pfeifer  writes:

> The patch is now in, alas all the GNU M2 manual links now point to 
> non-existant locations.
>
> Does maintainer-scripts/update_web_docs_git require an update to cover 
> Modula-2 and actually build the manual we are now linking to (or rather
> trying to)?
>
> Gerald

Apologies I was going to ask about these links.  I've updated the m2
subtree with target documentation independent sections.  Attached is a
proposed patch for maintainer-scripts/update_web_docs_git feel free to
apply or adapt in any way.

regards,
Gaius


--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o--->o

Add modula-2 documentation to be built

Update the online documentation build script to include modula-2.

maintainer-scripts/ChangeLog:

* update_web_docs_git (MANUALS): Add gm2.
Add include path for m2 target independent sections.


diff --git a/maintainer-scripts/update_web_docs_git 
b/maintainer-scripts/update_web_docs_git
index 1c6a993cafd..c678fc29155 100755
--- a/maintainer-scripts/update_web_docs_git
+++ b/maintainer-scripts/update_web_docs_git
@@ -24,6 +24,7 @@ MANUALS="cpp
   gdc
   gfortran
   gfc-internals
+  gm2
   gnat_ugn
   gnat-style
   gnat_rm
@@ -169,6 +170,9 @@ for file in $MANUALS; do
 includes="-I ${includedir} -I `dirname ${filename}`"
 if [ "$file" = "gnat_ugn" ]; then
   includes="$includes -I gcc/gcc/ada -I gcc/gcc/ada/doc/gnat_ugn"
+elif [ "$file" = "gm2" ]; then
+  includes="$includes -I gcc/gcc/m2/target-independent"
+  includes="$includes -I gcc/gcc/m2/target-independent/m2"
 fi
 makeinfo --html --css-ref $CSS $includes -o ${file} ${filename}
 tar cf ${file}-html.tar ${file}/*.html


Re: [pushed] wwwdocs: gcc-13: Escape < and > as and

2023-03-12 Thread Gaius Mulley via Gcc-patches
Gerald Pfeifer  writes:

> Note that in HTML < and > have a special meaning, so we cannot simply 
> write "<* noreturn *>", but need to escape it as "* noreturn *".
>
> Pushed.
>
> Gerald

apologies and thanks for correcting this bug

regards,
Gaius


Re: [wwwdocs] document modula-2 in gcc-13/changes.html (and index.html)

2023-03-06 Thread Gaius Mulley via Gcc-patches
Gerald Pfeifer  writes:

> Hi Gaius,
>
> apologies, I thought you had pushed the updated patch and only now 
> realized it's not in yet.
>
> Please look into the few bits below and then go ahead and push.
>
> On Mon, 6 Feb 2023, Gaius Mulley wrote:
>>  * htdocs/frontends.html: An update to say the front end is now in
>>  the development trunk.
>
> Here we'd usually simply say
>
>   * frontends: The Modula-2 front end is now on the 
>   development trunk.
>
> skiping "An update to say", or at least "An update to" and the "htdocs/" 
> port (and adding which front end).
>
>>  * htdocs/gcc-13/changes.html: A description of which dialects are
>>  supported and the user level front end changes so far.
>
>   * gcc-13: Note which Modula-2 dialects are...
>
>>  * htdocs/index.html: Proposed news entry.
>
>   * index: Announce Modula-2 inclusion 
>
> (or something like that).
>
>>  * htdocs/onlinedocs/index.html: PDF, PS and HTML documentation
>>  links.
>   * onlinedocs: Add links to Modula-2 documentation
>
>
>> +The compiler is operational with GCC 10, GCC 11 GCC 12 (on
>
> ...GCC 11, and GCC 12...
>
>> +GNU/Linux x86 systems).  The front end is now in the GCC development
>> +trunk (GCC 13).  The front end is mostly written in Modula-2 and it
>>  includes a bootstrap tool which translates Modula-2 into C/C++.
>
> How about "It is mostly written in Modula-2 and includes..." to avoid
> repetition of "the front end"?
>
>
> Thank you,
> Gerald

Hi Gerald,

no problem at all and many thanks for the advice.  I'll push the changes
shortly,

regards,
Gaius


[PATCH] Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]

2023-02-20 Thread Gaius Mulley via Gcc-patches


Hello,

bootstrapped on gcc master x86_64 and no extra failures generated on all
front ends.

Would this be ok for trunc?

regards,
Gaius


Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]

This patch allows front ends to register spec functions.  It is motivated
by PR108261 which needs to retain the order of search path related
options in the modula-2 front end.

gcc/ChangeLog:

* gcc.cc (add_spec_function):
* gcc.h (add_spec_function):

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index becc56051a8..93e4e38389d 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -46,6 +46,7 @@ compilation is specified by a string called a "spec".  */
 #include "spellcheck.h"
 #include "opts-jobserver.h"
 #include "common/common-target.h"
+#include 
 
 
 
@@ -1774,6 +1775,8 @@ static const struct spec_function static_spec_functions[] 
=
   { 0, 0 }
 };
 
+static std::vectorlang_spec_functions;
+
 static int processing_spec_function;
 
 /* Add appropriate libgcc specs to OBSTACK, taking into account
@@ -6825,9 +6828,25 @@ lookup_spec_function (const char *name)
 if (strcmp (sf->name, name) == 0)
   return sf;
 
+  for (auto *sf : lang_spec_functions)
+if (strcmp (sf->name, name) == 0)
+  return sf;
+
   return NULL;
 }
 
+/* Add a new spec function.  */
+
+void
+add_spec_function (const char *name,
+  const char *(*func) (int, const char **))
+{
+  struct spec_function *sf = XNEW (struct spec_function);
+  sf->name = name;
+  sf->func = func;
+  lang_spec_functions.push_back (sf);
+}
+
 /* Evaluate a spec function.  */
 
 static const char *
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 19a61b373ee..f40de0f5520 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -73,6 +73,8 @@ struct spec_function
 extern int do_spec (const char *);
 extern void record_temp_file (const char *, int, int);
 extern void set_input (const char *);
+extern void add_spec_function (const char *name,
+  const char *(*func) (int, const char **));
 
 /* Spec files linked with gcc.cc must provide definitions for these.  */
 


[PATCH] Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]

2023-02-20 Thread Gaius Mulley via Gcc-patches


Hello,

bootstrapped on gcc master x86_64 and no extra failures generated on all
front ends.

Would this be ok for trunc?

regards,
Gaius


Allow front ends to register spec functions gcc/{gcc.cc,gcc.h} [PR108261]

This patch allows front ends to register spec functions.  It is motivated
by PR108261 which needs to retain the order of search path related
options in the modula-2 front end.

gcc/ChangeLog:

* gcc.cc (add_spec_function):
* gcc.h (add_spec_function):

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index becc56051a8..93e4e38389d 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -46,6 +46,7 @@ compilation is specified by a string called a "spec".  */
 #include "spellcheck.h"
 #include "opts-jobserver.h"
 #include "common/common-target.h"
+#include 
 
 
 
@@ -1774,6 +1775,8 @@ static const struct spec_function static_spec_functions[] 
=
   { 0, 0 }
 };
 
+static std::vectorlang_spec_functions;
+
 static int processing_spec_function;
 
 /* Add appropriate libgcc specs to OBSTACK, taking into account
@@ -6825,9 +6828,25 @@ lookup_spec_function (const char *name)
 if (strcmp (sf->name, name) == 0)
   return sf;
 
+  for (auto *sf : lang_spec_functions)
+if (strcmp (sf->name, name) == 0)
+  return sf;
+
   return NULL;
 }
 
+/* Add a new spec function.  */
+
+void
+add_spec_function (const char *name,
+  const char *(*func) (int, const char **))
+{
+  struct spec_function *sf = XNEW (struct spec_function);
+  sf->name = name;
+  sf->func = func;
+  lang_spec_functions.push_back (sf);
+}
+
 /* Evaluate a spec function.  */
 
 static const char *
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 19a61b373ee..f40de0f5520 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -73,6 +73,8 @@ struct spec_function
 extern int do_spec (const char *);
 extern void record_temp_file (const char *, int, int);
 extern void set_input (const char *);
+extern void add_spec_function (const char *name,
+  const char *(*func) (int, const char **));
 
 /* Spec files linked with gcc.cc must provide definitions for these.  */
 


Re: [wwwdocs] document modula-2 in gcc-13/changes.html (and index.html)

2023-02-06 Thread Gaius Mulley via Gcc-patches
Gerald Pfeifer  writes:

> On Fri, 3 Feb 2023, Gaius Mulley wrote:
>> The following patch provides a summary of the modula-2 front end
>> and also contains links to the online modula-2 documentation in
>> index.html.
>
>> +Modula-2
>> +
>> +  Support for the language Modula-2 has been added.  The dialects
>> +  supported are PIM2, PIM3, PIM4 and ISO/IEC 10514-1.  Also included
>> +  are a complete set of ISO/IEC 10514-1 libraries and PIM
>> +libraries.
>
> I wonder whether we can this a bit more active. 
>
> Maybe something like "This includes support for the ... dialects, a 
> complete set of ...and ..."?
>
>> +  https://gcc.gnu.org/onlinedocs/m2/Compiler-options.html;>
>> +  Compiler options.
>
> Maybe put this in parenthesis since it's not an update as such and more 
> relatives to the previous item?
>
>> +  Linking has been redesigned.
>
> What are we saying here? I.e., what is the change we are announcing? As a 
> user, what might I notice? Why do I care?
>

Thanks for spotting this - agreed.

> The above are questions to possibly improve this for our users. Please 
> adjust as you see fit, or push as is, if you prefer.
>
>
> On a somewhat related note: This is definitely big enough to warrant an 
> entry in the News section on our main page. :-)  Do you want to propose
> something?
>
> Gerald

Ah yes thank you for the advice - here is an improved proposed patch
containing:

* htdocs/frontends.html: An update to say the front end is now in
the development trunk.
* htdocs/gcc-13/changes.html: A description of which dialects are
supported and the user level front end changes so far.
* htdocs/index.html: Proposed news entry.
* htdocs/onlinedocs/index.html: PDF, PS and HTML documentation
links.

regards,
Gaius


diff --git a/htdocs/frontends.html b/htdocs/frontends.html
index 12af359b..75be4658 100644
--- a/htdocs/frontends.html
+++ b/htdocs/frontends.html
@@ -41,10 +41,10 @@ has a back end that generates assembler directly, using the 
GCC back end.
 (at an early stage of development).
 
 http://www.nongnu.org/gm2/;>GNU Modula-2 implements
-the PIM2, PIM3, PIM4 and ISO dialects of the language.  The compiler
-is fully operational with GCC 10 and GCC 11 (on
-GNU/Linux x86 systems).  Work is in progress to move the front end to
-the GCC trunk.  The front end is mostly written in Modula-2 and it
+the ISO/IEC 10514-1, PIM2, PIM3 and PIM4 dialects of the language.
+The compiler is operational with GCC 10, GCC 11 GCC 12 (on
+GNU/Linux x86 systems).  The front end is now in the GCC development
+trunk (GCC 13).  The front end is mostly written in Modula-2 and it
 includes a bootstrap tool which translates Modula-2 into C/C++.
 
 Modula-3 (for links see 
 
 
 
+Modula-2
+
+  Support for the language Modula-2 has been added.  This includes
+support for the ISO/IEC 10514-1, PIM2, PIM3, PIM4 dialects
+together with a complete set of ISO/IEC 10514-1 and PIM
+libraries.
+  The <* noreturn *> attribute is supported
+with the -Wreturn-type
+https://gcc.gnu.org/onlinedocs/m2/Compiler-options.html;>
+  option.
+
+
 
 
 
diff --git a/htdocs/index.html b/htdocs/index.html
index 80730c06..3d03ef46 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -61,6 +61,11 @@ mission statement.
   has been contributed to Compiler Explorer (aka godbolt.org) by Marc
   Poulhiès
 
+Modula-2 front end 
added
+  [2022-12-14]
+The Modula-2 programming language front end has been added to GCC.
+  This front end was contributed by Gaius Mulley.
+
 https://gcc.gnu.org/wiki/cauldron2022;>GNU Tools Cauldron 
2022
 [2022-09-02]
 Prague, Czech Republic and online, September 16-18 2022
diff --git a/htdocs/onlinedocs/index.html b/htdocs/onlinedocs/index.html
index 343ff9f5..27a8a505 100644
--- a/htdocs/onlinedocs/index.html
+++ b/htdocs/onlinedocs/index.html
@@ -1647,6 +1647,12 @@ existing release.
href="https://gcc.gnu.org/onlinedocs/gdc.ps.gz;>PostScript or https://gcc.gnu.org/onlinedocs/gdc-html.tar.gz;>an
HTML tarball)
+https://gcc.gnu.org/onlinedocs/m2/;>GNU M2 Manual (https://gcc.gnu.org/onlinedocs/m2.pdf;>also in
+   PDF or https://gcc.gnu.org/onlinedocs/m2.ps.gz;>PostScript or https://gcc.gnu.org/onlinedocs/m2-html.tar.gz;>an
+   HTML tarball)
 https://gcc.gnu.org/onlinedocs/libgomp/;>GNU Offloading and
Multi Processing Runtime Library Manual (https://gcc.gnu.org/onlinedocs/libgomp.pdf;>also in


[wwwdocs] document modula-2 in gcc-13/changes.html (and index.html)

2023-02-03 Thread Gaius Mulley via Gcc-patches


Hello,

The following patch provides a summary of the modula-2 front end
and also contains links to the online modula-2 documentation in
index.html.

[I'm just about to git push fixes so that modula-2 builds html, info and
 pdf documentation into the standard directories.]

regards,
Gaius




diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
index 9ecd115c..fa13369f 100644
--- a/htdocs/gcc-13/changes.html
+++ b/htdocs/gcc-13/changes.html
@@ -283,6 +283,18 @@ a work-in-progress.
 
 
 
+Modula-2
+
+  Support for the language Modula-2 has been added.  The dialects
+  supported are PIM2, PIM3, PIM4 and ISO/IEC 10514-1.  Also included
+  are a complete set of ISO/IEC 10514-1 libraries and PIM
+libraries.
+  https://gcc.gnu.org/onlinedocs/m2/Compiler-options.html;>
+  Compiler options.
+  The <* noreturn *> attribute is supported.
+  Linking has been redesigned.
+
+
 
 
 
diff --git a/htdocs/onlinedocs/index.html b/htdocs/onlinedocs/index.html
index 343ff9f5..27a8a505 100644
--- a/htdocs/onlinedocs/index.html
+++ b/htdocs/onlinedocs/index.html
@@ -1647,6 +1647,12 @@ existing release.
href="https://gcc.gnu.org/onlinedocs/gdc.ps.gz;>PostScript or https://gcc.gnu.org/onlinedocs/gdc-html.tar.gz;>an
HTML tarball)
+https://gcc.gnu.org/onlinedocs/m2/;>GNU M2 Manual (https://gcc.gnu.org/onlinedocs/m2.pdf;>also in
+   PDF or https://gcc.gnu.org/onlinedocs/m2.ps.gz;>PostScript or https://gcc.gnu.org/onlinedocs/m2-html.tar.gz;>an
+   HTML tarball)
 https://gcc.gnu.org/onlinedocs/libgomp/;>GNU Offloading and
Multi Processing Runtime Library Manual (https://gcc.gnu.org/onlinedocs/libgomp.pdf;>also in


Re: For Modula-2 build-tree testing, also set up paths to compiler libraries

2023-01-31 Thread Gaius Mulley via Gcc-patches
Thomas Schwinge  writes:

> Hi!
>
> On 2022-10-10T16:31:26+0100, Gaius Mulley via Gcc-patches 
>  wrote:
>> Here are the dejagnu expect library scripts for the gm2
>> testsuite.
>
> This (or some variant thereof; haven't checked), became part of
> commit r13-4704-g1eee94d351774cdc2efc8ee508b82d065184c6ee
> "Merge modula-2 front end onto gcc".
>
>
> For build-tree testing ('$gccpath != ""'; such as standard 'make check'),
> 'gm2_link_flags' takes care to set up paths to a number of libraries that
> may be necessary:
>
>> --- /dev/null 2022-08-24 16:22:16.88870 +0100
>> +++ gcc-git-devel-modula2/gcc/testsuite/lib/gm2.exp   2022-10-07 
>> 20:21:18.718097775 +0100
>
>> +set gm2_link_libraries "m2pim m2iso";
>
>> +#  gm2_link_flags - detects the whereabouts of libraries (-lstdc++).
>> +#
>> +
>> +proc gm2_link_flags { paths } {
>> +global srcdir;
>> +global ld_library_path;
>> +global gccpath;
>> +global gm2_link_libraries;
>> +
>> +set gccpath ${paths}
>> +set libio_dir ""
>> +set flags ""
>> +set ld_library_path "."
>> +
>> +set shlib_ext [get_shlib_extension]
>> +verbose "shared lib extension: $shlib_ext"
>> +
>> +if { $gccpath == "" } {
>> +  global tool_root_dir
>> +
>> +  set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
>> +  if { $libstdcpp != "" } {
>> +  append flags "-L${libstdcpp} "
>> +  append ld_library_path ":${libstdcpp}"
>> +  }
>> +} else {
>> + if [file exists "${gccpath}/lib/libstdc++.a"] {
>> + append ld_library_path ":${gccpath}/lib"
>> + }
>> + if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
>> + append flags "-L${gccpath}/libstdc++ "
>> + append ld_library_path ":${gccpath}/libstdc++"
>> + }
>> + if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
>> + append flags " -L${gccpath}/libstdc++-v3/src/.libs "
>> + append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
>> + }
>> + # Look for libstdc++.${shlib_ext}.
>> + if [file exists 
>> "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
>> + append flags " -L${gccpath}/libstdc++-v3/src/.libs "
>> + append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
>> + }
>> +
>> + # puts stderr "${gm2_link_libraries}  before foreach"
>> + foreach d [list {*}${gm2_link_libraries}] {
>> + # puts stderr "${d}  "
>> + send_log "ld_library_path was ${ld_library_path}\n"
>> + send_log "looking for ${gccpath}/lib${d}/.libs/lib${d}.a\n"
>> + if [file exists "${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"] {
>> + send_log "good found 
>> ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a\n"
>> + # append flags " -L${gccpath}/libgm2/lib${d}/.libs -l${d}"
>> + append flags " ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"
>> + append ld_library_path ":${gccpath}/libgm2/lib${d}/.libs"
>> + }
>> + send_log "ld_library_path is ${ld_library_path}\n"
>> + }
>> +}
>> +
>> +set_ld_library_path_env_vars
>> +return "$flags"
>> +}
>
> However, this misses compiler libraries (such as libgcc, which libstdc++
> may depend on).  For example, I see my x86_64-pc-linux-gnu '-m32' testing
> not pick up the build-tree libgcc, but instead some random system one,
> which (expectedly) doesn't satisfy requirements of other build-tree
> libraries:
>
> [...]/build-gcc/gcc/testsuite/gm225/m.x0: 
> /lib/i386-linux-gnu/libgcc_s.so.1: version `GCC_7.0.0' not found (required by 
> [...]/build-gcc/x86_64-pc-linux-gnu/32/libstdc++-v3/src/.libs/libstdc++.so.6)
>
> ..., and thus a lot of execution FAILs.
>
> To cure that, OK to push the attached
> "For Modula-2 build-tree testing, also set up paths to compiler libraries"?
>
>
> Grüße
>  Thomas
>
>
> -
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
&g

Re: [PATCH] modula2/108462 - duplicate install of static modula2 target libs

2023-01-31 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Mon, 23 Jan 2023, Richard Biener wrote:
>
>> The following addresses the fact that libgm2 installs static libraries
>> into two places, one performed by
>> 
>> toolexeclib_LTLIBRARIES = libm2cor.la
>> 
>> and one performed as part of the install-data-local rule to a
>> m2/m2cor subdirectory alongside Modula-2 .def and .mod files.
>> 
>> This patch opts to keep the copy installed by libtool and removes
>> the extra installs in the install-data-local rules.
>> 
>> I've built and installed both with and without
>> --enable-version-specific-runtime-libs and compiled and linked
>> a Modula-2 testcase with the installed compiler with the two
>> multilibs and with and without static successfully.
>> 
>> OK for trunk?
>
> Ping.

yes sure, LGTM

A heads up that I've just renamed the gcc/m2/gm2-libs-pim directory to
gcc/m2/gm2-libs-log for consistency.  I've just tried the patch (post
rename changes) and the patch builds and installs fine (non bootstrap
test build though),

regards,
Gaius


Re: [COMMITTED] testsuite: Restore TORTURE_OPTIONS in gm2/warnings/returntype/fail/warnings-returntype-fail.exp

2023-01-30 Thread Gaius Mulley via Gcc-patches
Rainer Orth  writes:

> Between 20230126 and 20230127, 1100+ gm2 tests started to FAIL for the
> non-default multilib, e.g.
>
> FAIL: gm2/calling-c/datatypes/unbounded/run/pass/m.mod compilation, 
> {additional_flags= -O0 -g -Werror=return-type } timeout=10
> UNRESOLVED: gm2/calling-c/datatypes/unbounded/run/pass/m.mod execution, 
> {additional_flags= -O0 -g -Werror=return-type } timeout=10
> FAIL: gm2/case/pass/testcase1.mod,  -O0 -g -Werror=return-type  
> [...]
> cc1gm2: warning: '-Werror=' argument '-Werror=return-type' is not valid for 
> Modula-2
>
> I'm seeing this on all of Solaris/x86, Solaris/SPARC, and Linux/x86_64.
>
> I could trace this to
> gm2/warnings/returntype/fail/warnings-returntype-fail.exp not properly
> restoring TORTURE_OPTIONS.
>
> Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11.  Installed on
> trunk.
>
>   Rainer

apologies and many thanks for detecting and fixing this bug

regards,
Gaius


Re: [PATCH] modula-2: Fixes for preprocessing [PR102343, PR108182]

2023-01-25 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86_64, powerpc64 - linux-gnu (with 32b multilibs),
> i686, powerpc darwin (with 64b multilibs) x86_64 darwin (with and without
> 32b multilib).
> OK for trunk?
> thanks
> Iain
>
> --- 8< ---
>
> Modula-2 uses the C preprocessor to implement handling for conditional
> code and macros.  However, this is not done directly, because the process
> is applied recursively to imported definitions and modules.
>
> The cc1gm2 executable records the parameters as a template command line
> needed to create a composite 'cc1 -E' for each file to be preprocessed
> starting with the main file from the original command line.
>
> This patch fixes the capture of the C preprocessor template to include
> the target information needed for correct multilib operation.
>
> In order to match the existing semantics of '-E, -M and -MM' these have
> to be handled as a 'pre-processor only' job (i.e. the recursion is omitted
> and only the main file is processed).
>
> Whereas C-family front ends always pre-process, Modula-2 only does so
> when specifically requested (via the -fcpp option).
>
> '-MD, -MMD and -MQ' also require special handling, since (in principle)
> these options can be applied to any command line (with -fcpp) providing
> dependency information as a by-product.
>
> TODO: the preprocessor is not able to determine def and mod dependencies
> for Modula-2 and so the output of this only shows the object to module
> dep.  We should be able to append the .def and .mod dependencies.
>
> The patch amends save-temps handling to cater for the preprocessor
> recursion and to avoid writing saved files into the source directories.
>
> The patch changes the extension for Modula-2 preprocessed source to .m2i
> to avoid clashes with .i.
>
> The main driver code is amended to add default handlers for .mod and .m2i
> so that a useful error message will be emitted if the Modula-2 compiler
> is not built-in.
>
> The compiler will now also handle code generation from a .m2i preprocessed
> source.
>
> TODO: We should not need to pass the '-c' option to the compiler to alter
> the processing of init code.
>
> Signed-off-by: Iain Sandoe 
>
>   PR modula2/102343
>   PR modula2/108182
>
> gcc/ChangeLog:
>
>   * gcc.cc: Provide default specs for Modula-2 so that when the
>   language is not built-in better diagnostics are emitted for
>   attempts to use .mod or .m2i file extensions.
>
> gcc/m2/ChangeLog:
>
>   * gm2-compiler/M2Comp.mod: Early exit for pre-processor-only jobs.
>   * gm2-compiler/M2Options.def (SetPPOnly, GetPPOnly, SetMD, GetMD,
>   SetMMD, GetMMD, SetMQ, GetMQ, SetObj, GetObj, SetDumpDir,
>   GetDumpDir):New.
>   * gm2-compiler/M2Options.mod:(SetPPOnly, GetPPOnly, SetMD, GetMD,
>   SetMMD, GetMMD, SetMQ, GetMQ, SetObj, GetObj, SetDumpDir,
>   GetDumpDir):New.
>   * gm2-compiler/M2Preprocess.def (PreprocessModule): Add flag to
>   indicate the main file.
>   * gm2-compiler/M2Preprocess.mod: Handle Preprocess-only jobs,
>   handle MD, MMD and MQ options.
>   * gm2-gcc/m2options.h (M2Options_SetPPOnly, M2Options_GetPPOnly,
>   M2Options_SetDumpDir, M2Options_SetMD, M2Options_GetMD,
>   M2Options_SetMMD, M2Options_GetMMD, M2Options_SetMQ, M2Options_GetMQ,
>   M2Options_SetObj, M2Options_GetObj): New.
>   * gm2-gcc/m2type.cc (m2type_InitBaseTypes): Early exit for pre-
>   processor-only jobs.
>   * gm2-lang.cc (gm2_langhook_init): Handle preprocess-only commands.
>   (gm2_langhook_option_lang_mask): Claim C and Driver options so that
>   we can intercept them for building pre-processor commands.
>   (gm2_langhook_init_options): Collect the preprocessor line here.
>   Save options that have different actions for preprocessor and compile
>   commands.
>   (gm2_langhook_handle_option): Only handle the modula-2 options here.
>   (gm2_langhook_post_options): Do not create a back-end for pre-
>   processor-only jobs.
>   * gm2spec.cc (lang_specific_driver): Ignore PCH options, append a
>   scaffold-main for cases where we are building a main module with
>   -c.
>   * lang-specs.h: Revise to handle preprocessor-only jobs and to
>   consume pre-processed files.
>   * lang.opt: Remove Driver and C options copies (we claim these
>   separately).


Hi Iain,

yes LGTM - thanks for the fixes and it is great to have the ability for
gm2 to handle preprocessed source

regards,
Gaius


Re: [PATCH] modula-2: Fix stack size request in initPreemptive [PR108405]

2023-01-23 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Given that, currently, this value is not configurable per target the
> short-term solution is to avoid a bad request.
>
> Tested on x86_64-darwin21, OK for trunk?
> thanks
> Iain

Hi Iain,

yes this is fine.  LGTM - thanks

regards,
Gaius


Re: [PATCH] modula-2, driver, Front end: Revise handling of I and L paths [PR108182].

2023-01-23 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86_64-linux-gnu (with a 32b multilib), powerpc, i686 and
> x86_64-darwin.  OK for trunk?
> thanks,
> Iain
>
> --- 8< ---
>
> The adds the includes in the FE as done in other GCC languages.
> It also revises the library handling to avoid additional -L options
> from hiding LIBDIR.
>
> For the include/import paths as presented to the front end initialisation,
> we capture them and then arrange to emit the 'standard library' paths in
> the same order as specified for C.
>
> The specs are tidied up.

yes LGTM - apologies for the delay

thank you!
Gaius


Re: [PATCH] Modula-2, testsuite: Remove use of concatenated paths.

2023-01-22 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> tested on x86_64-darwin21 with an updated compiler that does not support
> the path concatentation and on an unpatched trunk.
> OK for trunk?
> thanks
> Iain
>
> --- 8< ---
>
> The original implementation for Modula-2 search paths allows things like
> '-I/path/a:/path/b'.  Such paths are not compatible with the rest of the
> compiler (in particular, the preprocessor, which Modula-2 uses).  In
> preparation for removing that idiom, this patch rewrites the cases in the
> testsuite and removes string processing where possible from lists of paths.
>
> TODO: There are some apparent discrepancies and/or extraneous insertions
> of partial include paths (especially in gm2_init_log, gm2_init_iso and
> gm2_init_pim) - to be handled in some future patch.
>
> Signed-off-by: Iain Sandoe 
>
> gcc/testsuite/ChangeLog:
>
>   * gm2/case/pass/case-pass.exp: Update for removal of concatenated
>   paths.
>   * gm2/complex/pass/complex-pass.exp: Likewise.
>   * gm2/coroutines/pim/run/pass/coroutines-pim-run-pass.exp: Likewise.
>   * gm2/iso/analysis/fail/iso-analysis-fail.xp: Likewise.
>   * gm2/iso/check/fail/iso-check-fail.exp: Likewise.
>   * gm2/iso/fail/iso-fail.exp: Likewise.
>   * gm2/iso/pass/iso-pass.exp: Likewise.
>   * gm2/isolib/run/pass/isolib-run-pass.exp: Likewise.
>   * gm2/pim/fail/pim-fail.exp: Likewise.
>   * gm2/pim/pass/pim-pass.exp: Likewise.
>   * gm2/pimlib/logitech/run/pass/pimlib-logitech-run-pass.exp: Likewise.
>   * gm2/pimlib/pass/pimlib-pass.exp: Likewise.
>   * gm2/pimlib/run/pass/pimlib-run-pass.exp: Likewise.
>   * gm2/projects/iso/run/pass/halma/projects-iso-run-pass-halma.exp: 
> Likewise.
>   * gm2/projects/iso/run/pass/hello/projects-iso-run-pass-hello.exp: 
> Likewise.
>   * gm2/projects/log/run/pass/hello/projects-log-run-pass-hello.exp: 
> Likewise.
>   * gm2/projects/pim/run/pass/hello/projects-pim-run-pass-hello.exp: 
> Likewise.
>   * gm2/recover/pass/recover-pass.exp: Likewise.
>   * gm2/switches/makeall/fail/switches-makeall-fail.exp: Likewise.
>   * gm2/switches/makeall/pass/switches-makeall-pass.exp: Likewise.
>   * gm2/switches/none/run/pass/gm2-none.exp: Likewise.
>   * gm2/switches/pim2/run/pass/switches-pim2-run-pass.exp: Likewise.
>   * gm2/ulmlib/pass/ulmlib-pass.exp: Likewise.
>   * gm2/ulmlib/std/pass/ulmlib-std-pass.exp: Likewise.
>   * gm2/ulmlib/sys/pass/ulmlib-sys-pass.exp: Likewise.
>   * lib/gm2.exp: Make the paths list a mandatory entry for each 
> gm2_init_xxx
>   function. Remove the use of concatenated include and library paths.
>   Remove string processing where possible.

LGTM - many thanks,

regards,
Gaius


Re: [PATCH] modula2/108144 - Fix multilib install of libgm2

2023-01-20 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> The following adjusts libgm2 to properly use the multilib build
> infrastructure, thereby fixing the install with
> --enable-version-specific-runtime-libs
>
> In particular config-ml.pl needs to be applied to generated Makefiles
> as documented in the manual and we have to avoid clobbering the
> variables via make arguments.  The explicit install rules used different
> ways to construct the multilib dir which isn't necessary and breaks
> when MUTLIDIR is now finally set correctly.  Instead use
> $(toolexeclibdir).
>
> This results in some dead variables in the Makefile.am (and there were
> some before), I refrained from doing even more changes here.
>
> Verified with an install with and without 
> --enable-version-specific-runtime-libs
> and checking the result.
>
> OK?
>
> Thanks,
> Richard.

Many thanks for this fix - and the deep magic AC_FOREACH config-ml.in
recursion rhunes.  LGTM

regards,
Gaius


Re: [PATCH] modula-2, testsuite: Make libs and interfaces consistent.

2023-01-19 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86_64-linux-gnu (with a 32b multilib), powerpc, i686 and
> x86_64-darwin.  OK for trunk?
> thanks,
> Iain

LGTM, thank you

regards,
Gaius


Re: [PATCH] modula2/108144 - fix --enable-version-specific-runtime-libs

2023-01-19 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> The following fixes --enable-version-specific-runtime-libs for
> the modula2 target libraries.  The issue is that the install
> happens via for example
>
> toolexeclib_LTLIBRARIES = libm2cor.la
>
> and toolexeclibdir is set to $(toolexecdir)/$(gcc_version)$(MULTISUBDIR)
> but the Makefile.am do not define $(gcc_version) but instead
> $(version) which is used locally to define libsubdir.  The fix
> is to consistently define and use $(gcc_version), also properly
> supporting --with-gcc-major-version-only
>
> Built and installed on x86_64-unknown-linux-gnu with
> --enable-version-specific-runtime-libs and --with-gcc-major-version-only.
>
> OK?
>
> Thanks,
> Richard. 

yes LGTM and thanks for the fix!

regards,
Gaius


Re: [PATCH] contrib: Partial fix for failed update-copyright --this year [PR108413]

2023-01-17 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> Hi!
>
> As mentioned on IRC or in PR108413, the last update-copyright.py --this year
> failed and that is why we are in a strange state where some copyrights have
> been updated and others have not.
> The full list of errors I got was I think:
> gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char 
> *) "Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
> gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char 
> *) "Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
> gcc/testsuite/gm2/switches/pedantic-params/pass/Strings.mod: unrecognised 
> copyright holder: Faculty of Information Technology,
> gcc/testsuite/gm2/switches/pedantic-params/pass/Strings2.mod: unrecognised 
> copyright holder: Faculty of Information Technology,
> libphobos/libdruntime/__builtins.di: unrecognised copyright: * Copyright: 
> Copyright Digital Mars 2022
> libstdc++-v3/src/c++17/fast_float/fast_float.h: unrecognised copyright 
> holder: The fast_float authors
> libstdc++-v3/include/c_compatibility/stdatomic.h: unrecognised copyright 
> holder: The GCC developers
>
> The following patch deals with the gcc/testsuite/gm2 ones and
> with the fast_float.h one, ok for trunk?
>
> Not really sure what we should do in the GmcOptions.c case
> (perhaps obfuscate it in the source somehow by splitting
> the string literals into different substrings
> Perhaps "Copy" "right (" "C) ''..." would do it?  Or do we want
> to bump there each year (manually or by the script)?
> E.g. in gcc.cc we have
>   printf ("Copyright %s 2023 Free Software Foundation, Inc.\n",
>   _("(C)"));
> which also prints (C) nicer in Unicode if possible and is updated
> by hand each year.
>

Hi,

I've git pushed some fixes for gcc/m2/mc/mcOptions.mod to obfuscate the
copyright text.  The change to mcOptions.mod also includes the removal
of the 'YEAR' constant and it queries the system for the year.  A
summary of the ChangeLog:

gcc/m2/ChangeLog:

* mc-boot/GmcOptions.c: Rebuilt.
* mc/mcOptions.mod (displayVersion):
Split first printf into three components
* mc/mcOptions.mod (YEAR): Remove.
(getYear): New procedure function.
(displayVersion): Use result from getYear instead of YEAR.
Emit boilerplate for GPL v3.
(gplBody): Use result from getYear instead of YEAR.
(glplBody): Use result from getYear instead of YEAR.

regards,
Gaius


Re: [PATCH] modula-2: Handle pass '-v' option to the compiler.

2023-01-12 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86-64-darwin21.
> OK for trunk?
> Iain

yes LGTM,

thanks,
Gaius

> --- 8< ---
>
> Somehow this setting had been missed, and we really need the verbose
> flag to enable useful debug output.
>
> Signed-off-by: Iain Sandoe 
>
> gcc/m2/ChangeLog:
>
>   * gm2-gcc/m2options.h (M2Options_SetVerbose): Export the
>   function.
>   * gm2-lang.cc: Handle OPT_v, passing it to the compiler.
>   * lang-specs.h: Pass -v to cc1gm2.
> ---
>  gcc/m2/gm2-gcc/m2options.h | 1 +
>  gcc/m2/gm2-lang.cc | 3 +++
>  gcc/m2/lang-specs.h| 2 +-
>  3 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/m2/gm2-gcc/m2options.h b/gcc/m2/gm2-gcc/m2options.h
> index 4b32c911b09..beaa460ffa9 100644
> --- a/gcc/m2/gm2-gcc/m2options.h
> +++ b/gcc/m2/gm2-gcc/m2options.h
> @@ -106,6 +106,7 @@ EXTERN int M2Options_GetCpp (void);
>  EXTERN int M2Options_GetM2g (void);
>  EXTERN void M2Options_SetM2g (int value);
>  EXTERN void M2Options_SetLowerCaseKeywords (int value);
> +EXTERN void M2Options_SetVerbose (int value);
>  EXTERN void M2Options_SetUnusedVariableChecking (int value);
>  EXTERN void M2Options_SetUnusedParameterChecking (int value);
>  EXTERN void M2Options_SetStrictTypeChecking (int value);
> diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
> index 49f93901d3c..073d1dd55db 100644
> --- a/gcc/m2/gm2-lang.cc
> +++ b/gcc/m2/gm2-lang.cc
> @@ -451,6 +451,9 @@ gm2_langhook_handle_option (
>  case OPT_save_temps_:
>M2Options_SetSaveTempsDir (arg);
>return 1;
> +case OPT_v:
> +  M2Options_SetVerbose (value);
> +  return 1;
>  default:
>if (insideCppArgs)
>   {
> diff --git a/gcc/m2/lang-specs.h b/gcc/m2/lang-specs.h
> index 0a34b0bc6d7..bf882649b21 100644
> --- a/gcc/m2/lang-specs.h
> +++ b/gcc/m2/lang-specs.h
> @@ -34,6 +34,6 @@ along with GCC; see the file COPYING3.  If not see
>{"@modula-2",
>"cc1gm2 " M2CPP
>"  %(cc1_options) %{B*} %{c*} %{+e*} %{I*} "
> -  "  %{i*} %{save-temps*} "
> +  "  %{i*} %{save-temps*} %{v} "
>"  %i %{!fsyntax-only:%(invoke_as)}",
>0, 0, 0},


Re: [PATCH v3 17/19] modula2 front end: dejagnu expect library scripts

2023-01-10 Thread Gaius Mulley via Gcc-patches
Jason Merrill  writes:

> On 12/6/22 09:47, Gaius Mulley via Gcc-patches wrote:
>> Here are the dejagnu expect library scripts for the gm2
>> testsuite.
>
> A couple of weeks ago I noticed on a testrun that the modula tests
> didn't seem to be timing out properly, so I made this change.  It
> looks like they didn't run at all in the bootstrap/test I did just
> now, so I don't know if this change is actually helpful, but here it
> is if you think it makes sense:

awesome, many thanks for the patch - it certainly looks as if the
timeout library was absent from lib/gm2.exp (and also gm2-torture.exp).
I've also applied this fix to gm2-torture.exp and will git commit/git
push your patch

regards,
Gaius


Re: [PATCH, Modula2] PR-108142 Many empty directories created in the build directory

2023-01-10 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> On Tue, Jan 10, 2023 at 11:16:28AM +0100, Richard Biener via Gcc-patches 
> wrote:
>> > @@ -424,7 +388,7 @@ override PLUGINCFLAGS := $(filter-out 
>> > -mdynamic-no-pic,$(PLUGINCFLAGS))
>> >
>> >  plugin/m2rte$(soext): $(srcdir)/m2/plugin/m2rte.cc 
>> > $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
>> >  insn-attr-common.h insn-flags.h $(generated_files)
>> > -   test -d plugin || mkdir plugin
>> > +   -test -d plugin || $(mkinstalldirs) plugin
>> 
>> I wonder if that's possibly racy (that's why you use mkinstalldirs?)?
>
> Using $(mkinstalldirs) in the patch is what I've suggested because
> previously the patch was using mkdir -p which we almost never use
> (I think only some Ada Makefiles).  Above when it is a single directory
> mkdir is fine.
>   -test -d $(TESTSUITEDIR) || mkdir $(TESTSUITEDIR)
> etc. is what is used in gcc/Makefile.in in some spots.
> If 2 shells do that test -d plugin || mkdir plugin at the same time,
> then yes, both might do mkdir, but that is why we have the - at the start,
> the error of doing mkdir twice will be ignored then.

thanks both - will apply the patch and close the PR

regards,
Gaius


Re: Missing dependencies in m2/ ?

2023-01-09 Thread Gaius Mulley via Gcc-patches
Jeff Law  writes:

> I'm still seeing it as of about 2 hours ago:
>
> http://law-sandy.freeddns.org:8080/job/avr-elf/2125/console
>
> A good run (yesterday):
>
> http://law-sandy.freeddns.org:8080/job/avr-elf/2124/console
>
>
Hi Jeff,

many thanks for the urls above - useful I'll attempt to reproduce the
gcc compile.

> However, I did find that my scripts were enabling all languages --
> sorry I stated otherwise and blamed it on the M2 front-end.

No problem at all - it allowed me to find I was using wrong
version of autoconf :-).

> THe only issue we need to resolve is the dependency problems.

Yes indeed, I think I've found some missing dependencies which I'll push
to git when the bootstrap completes.  In the meantime here is the patch:

regards,
Gaius

--- o< --- o< --- o< --- o< --- o< --- o< --- o<
diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 08d0f3b963f..5c173f22540 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -1360,7 +1360,7 @@ m2/boot-bin/mc$(exeext): $(BUILD-MC-BOOT-O) 
$(BUILD-MC-INTERFACE-O) \
  $(BUILD-MC-INTERFACE-O) m2/mc-boot/main.o \
  mcflex.o m2/gm2-libs-boot/RTcodummy.o -lm
 
-m2/mc-boot/$(SRC_PREFIX)%.o: m2/mc-boot/$(SRC_PREFIX)%.c
+m2/mc-boot/$(SRC_PREFIX)%.o: m2/mc-boot/$(SRC_PREFIX)%.c 
m2/gm2-libs/gm2-libs-host.h
$(CXX) -g -c -I. -I$(srcdir)/m2/mc-boot-ch -I$(srcdir)/m2/mc-boot 
-I$(srcdir)/../include -I$(srcdir) $(INCLUDES) $< -o $@
 
 m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c 
m2/gm2-libs/gm2-libs-host.h
@@ -1373,7 +1373,7 @@ m2/mc-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
unset CC ; $(M2LINK) -s --langc++ --exit --name m2/mc-boot/main.c 
$(srcdir)/m2/init/mcinit
$(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) 
m2/mc-boot/main.c -o $@
 
-mcflex.o: mcflex.c
+mcflex.o: mcflex.c m2/gm2-libs/gm2-libs-host.h
$(CC) -I$(srcdir)/m2/mc -g -c $< -o $@   # remember that mcReserved.h 
is copied into m2/mc
 
 mcflex.c: $(srcdir)/m2/mc/mc.flex


[PATCH, Modula2] PR-108142 Many empty directories created in the build directory

2023-01-09 Thread Gaius Mulley via Gcc-patches


PR-108142 Modula-2 configure generates many subdirectories in the top
build directory.  This patch dynamically creates subdirectories under
gcc/m2 if and when required.

Bootstrapped on x86_64 gnu/linux, ok for master?

regards,
Gaius


gcc/m2/ChangeLog:

* Make-lang.in (GM2_1): Change -B path to m2/stage1.
($(objdir)/m2/images/gnu.eps): Check and create dest dir
if necessary.
(gm2-libs.texi-check): Check and create dir m2/gm2-libs-pim,
m2/gm2-libs-iso and m2/gm2-libs if necessary.
($(objdir)/m2/gm2-compiler-boot): Remove.
($(objdir)/m2/gm2-libs-boot): Remove.
($(objdir)/m2/gm2-libs-libiberty): Remove.
($(objdir)/m2/gm2-libiberty): Remove.
($(objdir)/m2/gm2-gcc): Remove.
($(objdir)/m2/gm2-compiler): Remove.
($(objdir)/m2/gm2-libs): Remove.
($(objdir)/m2/gm2-libs-iso): Remove.
($(objdir)/m2/gm2-libs-min): Remove.
($(objdir)/m2/gm2-compiler-paranoid): Remove.
($(objdir)/m2/gm2-libs-paranoid): Remove.
($(objdir)/m2/gm2-compiler-verify): Remove.
($(objdir)/m2/boot-bin): Remove.
($(objdir)/m2/gm2-libs-pim): Remove.
($(objdir)/m2/gm2-libs-coroutines): Remove.
(stage1/m2): Remove.
(stage2/m2): Remove.
(stage3/m2): Remove.
(m2.stageprofile): New rule.
(m2.stagefeedback): New rule.
(cc1gm2$(exeext)): Change dependent name.
(m2/stage2/cc1gm2$(exeext)): Change dependent name.
Check and create dest dir.
(m2/stage1/cc1gm2$(exeext)): Check and create dest dir
if necessary.
(m2/gm2-gcc/%.o): Ditto.
(m2/gm2-gcc/rtegraph.o): Ditto.
(m2/gm2-gcc/$(SRC_PREFIX)%.h): Ditto.
(m2/gm2-gcc/$(SRC_PREFIX)%.h): Ditto.
(m2/mc-boot): Ditto.
(m2/mc-boot-ch): Ditto.
(m2/gm2-libs-boot): Ditto.
(m2/gm2-compiler-boot): Ditto.
(m2/gm2-compiler): Ditto.
(m2/gm2-libiberty): Ditto.
(m2/gm2-compiler): Ditto.
(m2/gm2-libs-iso): Ditto.
(m2/gm2-libs): Ditto.
(m2/gm2-libs-min): Ditto.
(m2/gm2-libs-coroutines): Ditto.
(m2/boot-bin): Ditto.
(m2/pge-boot): Ditto.
(m2/pge-boot): Ditto.
* Make-maintainer.in (m2/gm2-ppg-boot): Check and create
dest dir if necessary.
(m2): Ditto.
(m2/gm2-ppg-boot): Ditto.
(m2/gm2-pg-boot): Ditto.
(m2/gm2-auto): Ditto.
(m2/gm2-pg-boot): Ditto.
(m2/gm2-pge-boot): Ditto.
($(objdir)/plugin): Ditto.
($(objdir)/m2/mc-boot-ch): Ditto.
($(objdir)/m2/mc-boot-gen): Ditto.
(m2/boot-bin): Ditto.
(m2/mc): Ditto.
(m2/mc-obj): Ditto.
($(objdir)/m2/gm2-ppg-boot): Ditto.
($(objdir)/m2/gm2-pg-boot): Ditto.
($(objdir)/m2/gm2-pge-boot): Ditto.
(m2/mc-boot-gen): Ditto.
(m2/m2obj3): Ditto.
(m2/gm2-libs-paranoid): Ditto.
(m2/gm2-compiler-paranoid): Ditto.
(m2/gm2-libs-paranoid): Ditto.
(m2/gm2-compiler-paranoid): Ditto.
(m2/gm2-libs-paranoid): Ditto.
(m2/gm2-compiler-paranoid): Ditto.
* config-lang.in (m2/gm2-compiler-boot): Remove mkdir.
(m2/gm2-libs-boot): Ditto.
(m2/gm2-ici-boot): Ditto.
(m2/gm2-libiberty): Ditto.
(m2/gm2-gcc): Ditto.
(m2/gm2-compiler): Ditto.
(m2/gm2-libs): Ditto.
(m2/gm2-libs-iso): Ditto.
(m2/gm2-compiler-paranoid): Ditto.
(m2/gm2-libs-paranoid): Ditto.
(m2/gm2-compiler-verify): Ditto.
(m2/boot-bin): Ditto.
(m2/gm2-libs-pim): Ditto.
(m2/gm2-libs-coroutines): Ditto.
(m2/gm2-libs-min): Ditto.
(m2/pge-boot): Ditto.
(plugin): Ditto.
(stage1/m2): Ditto.
(stage2/m2): Ditto.
(stage3/m2): Ditto.
(stage4/m2): Ditto.
(m2/gm2-auto): Ditto.
(m2/gm2-pg-boot): Ditto.
(m2/gm2-pge-boot): Ditto.
(m2/gm2-ppg-boot): Ditto.
(m2/mc-boot): Ditto.
(m2/mc-boot-ch): Ditto.
(m2/mc-boot-gen): Ditto.

-- o< -- o< -- o< -- o< -- o< -- o< -- o<
diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 08d0f3b963f..a3751109481 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed 
'$(program_transform_cross_name)'`

 M2_MAINTAINER = no

-GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
+GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g

 GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
-L$(objdir)/../ld $(TFLAGS)

@@ -71,7 +71,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi 
m2/gm2-libs.texi m2/gm2-ebnf.
-cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
-cp -p m2/gm2-libs.texi $(srcdir)/m2
-cp -p m2/gm2-ebnf.texi $(srcdir)/m2
-   find . -name '*.texi' -print
 else
 m2.srcextra:
 endif
@@ -167,7 +166,7 @@ doc/m2.info: $(TEXISRC)
else true; fi

 

Re: [PATCH] Modula-2: fix documentation layout

2023-01-09 Thread Gaius Mulley via Gcc-patches
Eric Botcazou  writes:

> Hi,
>
> the Modula-2 documentation is rejected by older versions of Makeinfo because 
> the web of @node markers is fairly broken, apparently some subsections were 
> moved around, most notably between the Overview and Using sections, and the 
> @node markers were not (properly) adjusted.
>
> This patch allows me to build it with these older versions, as well as with 
> modern versions.  OK for mainline?
>
>
> 2023-01-09  Eric Botcazou  
>
>   * doc/gm2.texi (Overview): Fix @node markers.
>   (Using): Likewise.  Remove subsections that were moved to
>   Overview from the menu and move others around.

Hi Eric,

yes indeed and thanks for the patch!

regards,
Gaius


Re: Missing dependencies in m2/ ?

2023-01-08 Thread Gaius Mulley via Gcc-patches
Jeff Law via Gcc-patches  writes:

> I've been getting sporatic errors like this since the introduction of
> the modula-2 front-end:
>
>> In file included from ../../..//gcc/gcc/m2/mc-boot/GSFIO.c:29:
>> ../../..//gcc/gcc/system.h:556:20: error: conflicting declaration of C 
>> function 'const char* strsignal(int)'
>>   556 | extern const char *strsignal (int);
>>   |^
>> In file included from /usr/include/c++/12/cstring:42,
>>  from ../../..//gcc/gcc/system.h:241:
>> /usr/include/string.h:478:14: note: previous declaration 'char* 
>> strsignal(int)'
>>   478 | extern char *strsignal (int __sig) __THROW;
>>   |  ^
>> In file included from ../../..//gcc/gcc/system.h:707:
>> ../../..//gcc/gcc/../include/libiberty.h:112:14: error: ambiguating new 
>> declaration of 'char* basename(const char*)'
>>   112 | extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL 
>> ATTRIBUTE_NONNULL(1);
>>   |  ^~~~
>> /usr/include/string.h:524:26: note: old declaration 'const char* 
>> basename(const char*)'
>>   524 | extern "C++" const char *basename (const char *__filename)
>>   |  ^~~~
>> make[1]: *** [../../..//gcc/gcc/m2/Make-lang.in:1364: m2/mc-boot/GSFIO.o] 
>> Error 1
>
>
> They seem to come and go without rhyme or reason.  For example build
> #1885 on lm32-elf failed, while #1884 passed.
>
> Aside from the fact that I coonfigure with --enable-languages=c,c++
> and yet modula-2 stuff still gets built (can that be fixed?) it seems
> like we're missing dependencies to ensure that the generated config.h
> file is made before building the modula-2 stuff.
>
> In a good build you'll see something like this:
>
> config.status: creating auto-host.h
> [ ... ]
> Build GSFIO.o:
> g++ -g -c -I. -I../../..//gcc/gcc/m2/mc-boot-ch
> -I../../..//gcc/gcc/m2/mc-boot -I../../..//gcc/gcc/../include 
> -I../../..//gcc/gcc -I. -Im2/mc-boot -I../../..//gcc/gcc
>  -I../../..//gcc/gcc/m2/mc-boot -I../../..//gcc/gcc/../include 
> -I../../..//gcc/gcc/../libcpp/include -I../../..//gcc/gcc/../libcody
>  -I../../..//gcc/gcc/../libdecnumber 
> -I../../..//gcc/gcc/../libdecnumber/dpd -I../libdecnumber
>  -I../../..//gcc/gcc/../libbacktrace 
> ../../..//gcc/gcc/m2/mc-boot/GSFIO.c -o m2/mc-boot/GSFIO.o
>
> Which naturally works just fine.
>
> In a bad build, auto-host.h is _not_ created before trying to build GSFIO.o.
>
> Can you please take care of this.  It's rather annoying to have builds
> failing in the continuous testing system like this, particularly when 
> modula-2 isn't even enabled.
>
> Jeff

Hi Jeff,

many apologies for the breakage - I've now added the Makefile
dependencies.  I've also regenerated the m2 configure scripts

regards,
Gaius


[PATCH, modula2] v2 PR-108182 gm2 driver mishandles target and multilib options

2023-01-07 Thread Gaius Mulley via Gcc-patches


Hi,

This is version 2 with the SKIPOPT applied to every option given to
save_switch.

ok for master?  Bootstrapped on x86_64 gnu/linux and darwin.

regards,
Gaius



PR-108182 gm2 driver mishandles target and multilib options

here are some patches which attempt to allow target specific include
paths and library paths in the gm2 driver.  I admit that the patch has
flaws in that it only processes options -f, -m in the lang_specific_driver.
[Called after driver::set_up_specs but before read_specs is called].

I suspect a better implementation might be to use a spec function
to fixup the paths.

gcc/ChangeLog:

* gcc.cc (save_switch): Remove static declaration.
(get_multilib_dir): New function.
(reset_mdswitches): New function.
* gcc/gcc.h (save_switch): Declare extern.
(get_multilib_dir): New extern.
(reset_mdswitches): New extern.

gcc/m2/ChangeLog:

* gm2spec.cc (lang_specific_driver): Detect -m and -f options and
call save_switch and SKIPOPT.  Assign multilib_dir with the result
of get_multilib_dir.  Call reset_mdswitches afterwards.

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index d629ca5e424..362a6a96b63 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -3849,7 +3849,7 @@ alloc_switch (void)
 /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
as validated if VALIDATED and KNOWN if it is an internal switch.  */

-static void
+void
 save_switch (const char *opt, size_t n_args, const char *const *args,
 bool validated, bool known)
 {
@@ -9559,6 +9559,24 @@ default_arg (const char *p, int len)
   return 0;
 }

+/* Return the value of multilib_dir.  */
+
+const char *
+get_multilib_dir (void)
+{
+  set_multilib_dir ();
+  return multilib_dir;
+}
+
+/* Reset the mdswitches array to empty.  */
+
+void
+reset_mdswitches (void)
+{
+  n_mdswitches = 0;
+  mdswitches = NULL;
+}
+
 /* Work out the subdirectory to use based on the options. The format of
multilib_select is a list of elements. Each element is a subdirectory
name followed by a list of options followed by a semicolon. The format
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 19a61b373ee..03646ff2d87 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -73,6 +73,11 @@ struct spec_function
 extern int do_spec (const char *);
 extern void record_temp_file (const char *, int, int);
 extern void set_input (const char *);
+extern const char *get_multilib_dir (void);
+extern void reset_mdswitches (void);
+extern void save_switch (const char *opt, size_t n_args,
+const char *const *args,
+bool validated, bool known);

 /* Spec files linked with gcc.cc must provide definitions for these.  */

diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc
index 583723da416..d813de4ab46 100644
--- a/gcc/m2/gm2spec.cc
+++ b/gcc/m2/gm2spec.cc
@@ -797,8 +797,20 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
  if ((decoded_options[i].orig_option_with_args_text != NULL)
  && (strncmp (decoded_options[i].orig_option_with_args_text,
   "-m", 2) == 0))
-   multilib_dir = xstrdup 
(decoded_options[i].orig_option_with_args_text
-   + 2);
+   {
+ save_switch (decoded_options[i].orig_option_with_args_text,
+  0, NULL, true, true);
+ args[i] |= SKIPOPT;
+   }
+ else if ((decoded_options[i].orig_option_with_args_text != NULL)
+  && (strncmp (decoded_options[i].orig_option_with_args_text,
+   "-f", 2) == 0))
+   {
+ save_switch (decoded_options[i].orig_option_with_args_text,
+  0, NULL, true, true);
+ args[i] |= SKIPOPT;
+   }
+ break;
}
 }
   if (language != NULL && (strcmp (language, "modula-2") != 0))
@@ -864,10 +876,13 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   if ((! (seen_uselist || seen_gen_module_list)) && linking)
 append_option (OPT_fgen_module_list_, "-", 1);

+  multilib_dir = get_multilib_dir ();
+  reset_mdswitches ();
   if (allow_libraries)
 {
   /* If the libraries have not been specified by the user but the
-dialect has been specified then select the appropriate libraries.  */
+dialect has been specified then select the appropriate
+libraries.  */
   if (libraries == NULL)
{
  if (strcmp (dialect, "iso") == 0)


Re: [PATCH] modula-2, libm2min: Declare abort and exit as expected.

2023-01-07 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested with a build on x86_64-darwin21, the build warnings are gone and
> the build completed as normal.
> OK for master?
> thanks
> Iain
>
> --- 8< ---
>
> The build is currently emitting a warning that abort() is declared differently
> from the built-in.  This updates the declaration to match expectations.
>
> Signed-off-by: Iain Sandoe 
>
> gcc/m2/ChangeLog:
>
>   * gm2-libs-min/libc.c (abort): Update declaration to match the
>   expected form, add no-return attribute.
>   (exit): Add no-return attribute.
> ---
>  gcc/m2/gm2-libs-min/libc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/m2/gm2-libs-min/libc.c b/gcc/m2/gm2-libs-min/libc.c
> index b39bfffb65c..8cddb5dd7b4 100644
> --- a/gcc/m2/gm2-libs-min/libc.c
> +++ b/gcc/m2/gm2-libs-min/libc.c
> @@ -24,10 +24,10 @@ a copy of the GCC Runtime Library Exception along with 
> this program;
>  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>  .  */
>  
> -void abort (int);
> -void exit (int);
> +extern void abort (void)  __attribute__ ((__noreturn__));
> +extern void exit (int) __attribute__ ((__noreturn__));
>  
> -void abort (int i)
> +void abort (void)
>  {
>while (1)
>  ;

yes LGTM, thanks!

regards,
Gaius


[PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options

2023-01-06 Thread Gaius Mulley via Gcc-patches



ChangeLog entry follows:

regards,
Gaius



[PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options

here are some patches which attempt to allow target specific include
paths and library paths in the gm2 driver.  I admit that the patch has
flaws in that it only processes options -f, -m in the lang_specific_driver.
[Called after driver::set_up_specs but before read_specs is called].

I suspect a better implementation might include a language callback
(lang_post_spec) which could fixup target related paths.

gcc/ChangeLog:

* gcc.cc (save_switch): Remove static declaration.
(get_multilib_dir): New function.
(reset_mdswitches): New function.
* gcc/gcc.h (save_switch): Declare extern.
(get_multilib_dir): New extern.
(reset_mdswitches): New extern.

gcc/m2/ChangeLog:

* gm2spec.cc (lang_specific_driver): Detect -m and -f options and
call save_switch.  Assign multilib_dir with the result of
get_multilib_dir.  Call reset_mdswitches afterwards.


[PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options

2023-01-06 Thread Gaius Mulley via Gcc-patches


Hi,

here are some patches which attempt to allow target specific include
paths and library paths in the gm2 driver.  I admit that the patch has
flaws in that it only processes options -f, -m in the lang_specific_driver.
[Called after driver::set_up_specs but before read_specs is called].

I suspect a better implementation might include a language callback
(lang_post_spec) which could fixup target related paths.

Nevertheless as a stage3 bugfix (workaround) they are presented below:

I wonder if they would be suitable for master?

Tested on Darwin (prior cleanup) and X86_64 Linux

regards,
Gaius

- o< - o< - o< - o< - o< - o< - o< - o<
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index d629ca5e424..362a6a96b63 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -3849,7 +3849,7 @@ alloc_switch (void)
 /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
as validated if VALIDATED and KNOWN if it is an internal switch.  */

-static void
+void
 save_switch (const char *opt, size_t n_args, const char *const *args,
 bool validated, bool known)
 {
@@ -9559,6 +9559,24 @@ default_arg (const char *p, int len)
   return 0;
 }

+/* Return the value of multilib_dir.  */
+
+const char *
+get_multilib_dir (void)
+{
+  set_multilib_dir ();
+  return multilib_dir;
+}
+
+/* Reset the mdswitches array to empty.  */
+
+void
+reset_mdswitches (void)
+{
+  n_mdswitches = 0;
+  mdswitches = NULL;
+}
+
 /* Work out the subdirectory to use based on the options. The format of
multilib_select is a list of elements. Each element is a subdirectory
name followed by a list of options followed by a semicolon. The format
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 19a61b373ee..03646ff2d87 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -73,6 +73,11 @@ struct spec_function
 extern int do_spec (const char *);
 extern void record_temp_file (const char *, int, int);
 extern void set_input (const char *);
+extern const char *get_multilib_dir (void);
+extern void reset_mdswitches (void);
+extern void save_switch (const char *opt, size_t n_args,
+const char *const *args,
+bool validated, bool known);

 /* Spec files linked with gcc.cc must provide definitions for these.  */

diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc
index 583723da416..dbfd1ca 100644
--- a/gcc/m2/gm2spec.cc
+++ b/gcc/m2/gm2spec.cc
@@ -797,8 +797,14 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
  if ((decoded_options[i].orig_option_with_args_text != NULL)
  && (strncmp (decoded_options[i].orig_option_with_args_text,
   "-m", 2) == 0))
-   multilib_dir = xstrdup 
(decoded_options[i].orig_option_with_args_text
-   + 2);
+   save_switch (decoded_options[i].orig_option_with_args_text,
+0, NULL, true, true);
+ else if ((decoded_options[i].orig_option_with_args_text != NULL)
+  && (strncmp (decoded_options[i].orig_option_with_args_text,
+   "-f", 2) == 0))
+ save_switch (decoded_options[i].orig_option_with_args_text,
+  0, NULL, true, true);
+ break;
}
 }
   if (language != NULL && (strcmp (language, "modula-2") != 0))
@@ -864,10 +870,13 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   if ((! (seen_uselist || seen_gen_module_list)) && linking)
 append_option (OPT_fgen_module_list_, "-", 1);

+  multilib_dir = get_multilib_dir ();
+  reset_mdswitches ();
   if (allow_libraries)
 {
   /* If the libraries have not been specified by the user but the
-dialect has been specified then select the appropriate libraries.  */
+dialect has been specified then select the appropriate
+libraries.  */
   if (libraries == NULL)
{
  if (strcmp (dialect, "iso") == 0)



Re: [PATCH] modula-2: Remove uses of scalb*() and significand*() [PR107631]

2023-01-05 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86_64-darwin21 and x86_64-linux-gnu without any m2 regressions.
> OK for trunk?
> thanks
> Iain

yes sure LGTM

thank you!
Gaius


Re: [PATCH] modula-2, driver: Implement handling for -static-libgm2.

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Hi Gaius,
>
>> On 4 Jan 2023, at 12:11, Gaius Mulley  wrote:
>> 
>> Iain Sandoe  writes:
>> 
>>> tested on x86_64-linux-gnu, x86_64,aarch64-darwin21,
>
>> 
>> yes LGTM - it was unimplemented - thanks!
>
> My apologies, when I came to apply this I realised that I posted the wrong
> version of the patch - omitting the documentation changes.
>
> Here is the version with (albeit basic) documentation.
> Still OK for master?
> Iain

Hi Iain,

yes LGTM

thanks,
Gaius

> [PATCH] modula-2, driver: Implement handling for -static-libgm2.
>
> This was unimplemented so far.
>
> gcc/ChangeLog:
>
>   * common.opt: Add -static-libgm2.
>   * config/darwin.h (LINK_SPEC): Handle static-libgm2.
>   * doc/gm2.texi: Document static-libgm2.
>   * gcc.cc (driver_handle_option): Allow static-libgm2.
>
> gcc/m2/ChangeLog:
>
>   * gm2spec.cc (lang_specific_driver): Handle static-libgm2.
>   * lang.opt: Add static-libgm2.
> ---
>  gcc/common.opt  |  4 
>  gcc/config/darwin.h |  7 ++-
>  gcc/doc/gm2.texi|  4 
>  gcc/gcc.cc  | 12 +++-
>  gcc/m2/gm2spec.cc   | 24 +++-
>  gcc/m2/lang.opt |  4 
>  6 files changed, 48 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 97a78030228..d0371aec8db 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -3622,6 +3622,10 @@ static-libgfortran
>  Driver
>  ; Documented for Fortran, but always accepted by driver.
>  
> +static-libgm2
> +Driver
> +; Documented for Modula-2, but always accepted by driver.
> +
>  static-libphobos
>  Driver
>  ; Documented for D, but always accepted by driver.
> diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
> index efe3187cd96..e6f76e598e6 100644
> --- a/gcc/config/darwin.h
> +++ b/gcc/config/darwin.h
> @@ -447,7 +447,12 @@ extern GTY(()) int darwin_ms_struct;
> %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos 
> libgphobos.a%s)}\
> 
> %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp
>  libgomp.a%s)}\
> %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ 
> libstdc++.a%s)}\
> -   %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
> +   %{static|static-libgm2:%:replace-outfile(-lm2pim libm2pim.a%s)}\
> +   %{static|static-libgm2:%:replace-outfile(-lm2iso libm2iso.a%s)}\
> +   %{static|static-libgm2:%:replace-outfile(-lm2min libm2min.a%s)}\
> +   %{static|static-libgm2:%:replace-outfile(-lm2log libm2log.a%s)}\
> +   %{static|static-libgm2:%:replace-outfile(-lm2cor libm2cor.a%s)}\
> +  %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
> %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\
> LINK_SYSROOT_SPEC \
>"%{mmacosx-version-min=*:-macosx_version_min %*} \
> diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
> index 513fdd3ec7f..18cb798c6cd 100644
> --- a/gcc/doc/gm2.texi
> +++ b/gcc/doc/gm2.texi
> @@ -573,6 +573,10 @@ the they provide the base modules which all other 
> dialects utilize.
>  The option @samp{-fno-libs=-} disables the @samp{gm2} driver from
>  modifying the search and library paths.
>  
> +@item -static-libgm2
> +On systems that provide the m2 runtimes as both shared and static libraries,
> +this option forces the use of the static version.
> +
>  @c flocation=
>  @c Modula-2 Joined
>  @c set all location values to a specific value (internal switch)
> diff --git a/gcc/gcc.cc b/gcc/gcc.cc
> index 91313a8516d..d629ca5e424 100644
> --- a/gcc/gcc.cc
> +++ b/gcc/gcc.cc
> @@ -4540,12 +4540,14 @@ driver_handle_option (struct gcc_options *opts,
>  case OPT_static_libgfortran:
>  case OPT_static_libquadmath:
>  case OPT_static_libphobos:
> +case OPT_static_libgm2:
>  case OPT_static_libstdc__:
> -  /* These are always valid, since gcc.cc itself understands the
> -  first two, gfortranspec.cc understands -static-libgfortran,
> -  d-spec.cc understands -static-libphobos, g++spec.cc
> -  understands -static-libstdc++ and libgfortran.spec handles
> -  -static-libquadmath.  */
> +  /* These are always valid; gcc.cc itself understands the first two
> +  gfortranspec.cc understands -static-libgfortran,
> +  libgfortran.spec handles -static-libquadmath,
> +  d-spec.cc understands -static-libphobos,
> +  gm2spec.cc understands -static-libgm2,
> +  and g++spec.cc understands -static-libstdc++.  */
>validated = true;
>break;
>  
> diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc
> index b9a5c4e79bb..583723da416 100644
> --- a/gcc/m2/gm2spec.cc
> +++ b/gcc/m2/gm2spec.cc
> @@ -586,6 +586,9 @@ lang_specific_driver (struct cl_decoded_option 
> **in_decoded_options,
>/* Should the driver perform a link?  */
>bool linking = true;
>  
> +  /* Should the driver link the shared gm2 libs?  */
> +  bool shared_libgm2 = true;
> +
>/* "-lm" or "-lmath" if it appears on the command line.  */
>const struct cl_decoded_option *saw_math = NULL;
>  
> @@ 

Re: [PATCH 4/n] modula-2, driver: Handle static-libstd++ for targets without static/dynamic

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Oops pressed ‘send' too soon - this is part of the series for Darwin:
>
> There are several modula-2 issues on Darwin, some blocking bootstrap on
> one or more system versions.
>
> This has been tested on powerpc/i688-darwin9 .. x86_64-darwin10,17,21 and
> the prototype aarch64-darwin branch on darwin21.
>
> OK for trunk?
> thanks
> Iain

sure, LGTM

regards,
Gaius

>> On 30 Dec 2022, at 10:58, Iain Sandoe  wrote:
>> 
>> The follows the pattern used in C++ and D drivers to pass -static-libstdc++
>> onto the target driver to allow spec substitution of static libraries.
>> 
>> NOTE: The general handling of Bstatic/dynamic and the possible use of static
>> libgm2 libraries is unimplemented in this driver so far.  It seems likely
>> that the driver construction could be greatly simplified if the modula-2
>> runtimes were combined into fewer (hopefully, one) libraries.
>> 
>> Signed-off-by: Iain Sandoe 
>> 
>> gcc/m2/ChangeLog:
>> 
>>  * gm2spec.cc (lang_specific_driver): Pass -static-libstdc++ on to
>>  the target driver if the linker does not support Bstatic/dynamic.
>> ---
>> gcc/m2/gm2spec.cc | 5 +
>> 1 file changed, 5 insertions(+)
>> 
>> diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc
>> index 680dd3602ef..b9a5c4e79bb 100644
>> --- a/gcc/m2/gm2spec.cc
>> +++ b/gcc/m2/gm2spec.cc
>> @@ -767,7 +767,12 @@ lang_specific_driver (struct cl_decoded_option 
>> **in_decoded_options,
>> 
>>  case OPT_static_libstdc__:
>>library = library >= 0 ? 2 : library;
>> +#ifdef HAVE_LD_STATIC_DYNAMIC
>> +  /* Remove -static-libstdc++ from the command only if target supports
>> + LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
>> + back-end target can use outfile substitution.  */
>>args[i] |= SKIPOPT;
>> +#endif
>>break;
>> 
>>  case OPT_stdlib_:
>> -- 
>> 2.37.1 (Apple Git-137.1)
>> 


[PATCH modula2] Add missing declarations to gcc/m2/gm2-libs-min/M2RTS.def

2023-01-04 Thread Gaius Mulley via Gcc-patches


Bootstrapped on gnu/linux x86_64

Ok for trunk?

thanks
Gaius

- o< - o< - o< - o< - o<


Add missing declarations to gcc/m2/gm2-libs-min/M2RTS.def

This patch adds two missing procedures to gcc/m2/gm2-libs-min/M2RTS.def
required for linking (the procedures are already present in the pim and
iso M2RTS.def).  The patch also includes test code, changes to
gcc/testsuite/lib/gm2.exp and an expect tcl script to test the min
libraries.


gcc/m2/ChangeLog:

* gm2-libs-min/M2RTS.def (ConstructModules): New procedure
declaration.
(DeconstructModules): New procedure declaration.

gcc/testsuite:

* lib/gm2.exp (gm2_init_minx): New procedure.
(gm2_init_min): New procedure calls gm2_init_min with
dialect flags.
* gm2/link/min/pass/tiny.mod: New test case.
* gm2/link/min/pass/link-min-pass.exp: New file.


diff --git a/gcc/m2/gm2-libs-min/M2RTS.def b/gcc/m2/gm2-libs-min/M2RTS.def
index e3e13b7b554..147024ebe78 100644
--- a/gcc/m2/gm2-libs-min/M2RTS.def
+++ b/gcc/m2/gm2-libs-min/M2RTS.def
@@ -38,6 +38,10 @@ TYPE
all these procedures do nothing except satisfy the linker.
 *)

+PROCEDURE ConstructModules (applicationmodule: ADDRESS;
+argc: INTEGER; argv, envp: ADDRESS) ;
+PROCEDURE DeconstructModules (applicationmodule: ADDRESS;
+  argc: INTEGER; argv, envp: ADDRESS) ;
 PROCEDURE RegisterModule (name: ADDRESS;
   init, fini:  ArgCVEnvP;
   dependencies: PROC) ;
diff --git a/gcc/testsuite/lib/gm2.exp b/gcc/testsuite/lib/gm2.exp
index 450cb4c2d35..9eba195291a 100644
--- a/gcc/testsuite/lib/gm2.exp
+++ b/gcc/testsuite/lib/gm2.exp
@@ -496,3 +496,42 @@ proc gm2_init_cor { {path ""} args } {
 gm2_link_lib "m2cor m2pim m2iso"
 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args};
 }
+
+
+#
+#  gm2_init_minx - set the default libraries to choose MIN library and
+#  choose Modula-2, dialect.
+#
+#
+
+proc gm2_init_minx { dialect {path ""} args } {
+global srcdir;
+global gccpath;
+
+set gm2src ${srcdir}/../m2;
+
+send_log "srcdir is $srcdir\n"
+send_log "gccpath is $gccpath\n"
+send_log "gm2src is $gm2src\n"
+
+set minIpath "${gccpath}/libgm2/libm2min";
+set minLpath "${gccpath}/libgm2/libm2min/.libs";
+
+set theIpath "-I${minIpath}";
+set theLpath "-L${minLpath}";
+
+if { $path != "" } then {
+   append theIpath " -I"
+   append theIpath ${path}
+}
+gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args};
+}
+
+#
+#  gm2_init_min - set the default libraries to choose MIN libraries
+# and pim dialect.
+#
+
+proc gm2_init_min { {path ""} args } {
+gm2_init_minx -fpim {*}${path} {*}${args};
+}
diff --git a/gcc/testsuite/gm2/link/min/pass/link-min-pass.exp 
b/gcc/testsuite/gm2/link/min/pass/link-min-pass.exp
new file mode 100644
index 000..88d180ec31e
--- /dev/null
+++ b/gcc/testsuite/gm2/link/min/pass/link-min-pass.exp
@@ -0,0 +1,37 @@
+# Expect driver script for GCC Regression Tests
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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
+# .
+
+# This file was written by Gaius Mulley (gaiusm...@gmail.com)
+# for GNU Modula-2.
+
+if $tracelevel then {
+strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_min "${srcdir}/gm2/min/pass"
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] {
+# If we're only testing specific files and this isn't one of them, skip it.
+if ![runtest_file_p $runtests $testcase] then {
+   continue
+}
+
+gm2-torture $testcase
+}
diff --git a/gcc/testsuite/gm2/link/min/pass/tiny.mod 
b/gcc/testsuite/gm2/link/min/pass/tiny.mod
new file mode 100644
index 000..e1165edbe4a
--- /dev/null
+++ b/gcc/testsuite/gm2/link/min/pass/tiny.mod
@@ -0,0 +1,7 @@
+MODULE tiny ;
+
+(* Does nothing at all, but it should link if -flibs=min is used.  *)
+
+BEGIN
+
+END tiny.


Re: [PATCH] modula-2, driver: Implement handling for -static-libgm2.

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> tested on x86_64-linux-gnu, x86_64,aarch64-darwin21,
> OK for trunk?
> thanks,
> Iain
>
> --- 8< ---
>
> This was unimplemented so far.
>
> gcc/ChangeLog:
>
>   * common.opt: Add -static-libgm2.
>   * config/darwin.h (LINK_SPEC): Handle static-libgm2.
>
> gcc/m2/ChangeLog:
>
>   * gm2spec.cc (lang_specific_driver): Handle static-libgm2.
> ---
>  gcc/common.opt  |  4 
>  gcc/config/darwin.h |  7 ++-
>  gcc/m2/gm2spec.cc   | 24 +++-
>  3 files changed, 33 insertions(+), 2 deletions(-)
>

yes LGTM - it was unimplemented - thanks!

regards,
Gaius


Re: [PATCH] modula-2: Module registration constructors need to be visible [PR108259].

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86_64-linux-gnu, x86_64,aarch64-darwin21.
> There remain issues with shared libraries, but the link fails are fixed
> by this.
>
> OK for master?
> Thanks
> Iain
>
> --- 8< ---
>
> In the current design the main executable links explicitly to the module
> registration construtors that it uses.  This means that they must be
> visible in shared libraries.
>
>   PR modula2/108259
>
> gcc/m2/ChangeLog:
>
>   * gm2-gcc/m2decl.cc (m2decl_DeclareModuleCtor): Make module
>   registration constructors visible.
> ---
>  gcc/m2/gm2-gcc/m2decl.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/m2/gm2-gcc/m2decl.cc b/gcc/m2/gm2-gcc/m2decl.cc
> index 62bfefd2530..d849f8aefc4 100644
> --- a/gcc/m2/gm2-gcc/m2decl.cc
> +++ b/gcc/m2/gm2-gcc/m2decl.cc
> @@ -276,7 +276,7 @@ m2decl_DeclareModuleCtor (tree decl)
>/* Declare module_ctor ().  */
>TREE_PUBLIC (decl) = 1;
>DECL_ARTIFICIAL (decl) = 1;
> -  DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
> +  DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
>DECL_VISIBILITY_SPECIFIED (decl) = 1;
>DECL_STATIC_CONSTRUCTOR (decl) = 1;
>return decl;

LGTM thanks,

Gaius


Re: [PATCH] modula-2: Fix registration of modules via constructors [PR108183].

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

>  When I first made this patch I had a question as to what should be
>  done for registration CTORs generated by the compiler for .mod files.
>  I've now answered that question (the code that makes the GCC decl
>  has also be updated in a separately posted patch).
>  
> tested on x86_64-linux-gnu, x86_64, aarch64-darwin21,
> OK for master?
> Thanks,
> Iain
>  
>  --- 8< ---
>
> This reworks the mechanism used for module registration to use init-
> time constructors.  The order of registration is not important, the
> actual initialization dependency tree will be computed early in the
> execution (all that matters is that we have registered before that).
>
> This fixes a potential issue in which the external name known to the
> m2 system is of the form _M2_XX_ctor() but the C++ code was
> producing a static variable instance with the same name.
>
> Signed-off-by: Iain Sandoe 
>
>   PR modula2/108183
>
> gcc/m2/ChangeLog:
>
>   * gm2-libs-ch/UnixArgs.cc (_M2_UnixArgs_ctor): Rework to use
>   an extern "C" function with 'constructor' attribute.
>   * gm2-libs-ch/dtoa.cc (_M2_dtoa_ctor): Likewise.
>   * gm2-libs-ch/ldtoa.cc (_M2_ldtoa_ctor): Likewise.
>
> libgm2/ChangeLog:
>
>   * libm2cor/KeyBoardLEDs.cc (_M2_KeyBoardLEDs_ctor): Rework to use
>   an extern "C" function with 'constructor' attribute.
>   * libm2iso/ErrnoCategory.cc (_M2_ErrnoCategory_ctor): Likewise.
>   * libm2iso/RTco.cc (_M2_RTco_ctor): Likewise.
>   * libm2pim/Selective.cc (_M2_Selective_ctor): Likewise.
>   * libm2pim/SysExceptions.cc (_M2_SysExceptions_ctor): Likewise.
>   * libm2pim/UnixArgs.cc (_M2_UnixArgs_ctor): Likewise.
>   * libm2pim/cgetopt.cc (_M2_cgetopt_ctor): Likewise.
>   * libm2pim/dtoa.cc (_M2_dtoa_ctor): Likewise.
>   * libm2pim/errno.cc (_M2_errno_ctor): Likewise.
>   * libm2pim/ldtoa.cc (_M2_ldtoa_ctor): Likewise.
>   * libm2pim/sckt.cc (_M2_sckt_ctor): Likewise.
>   * libm2pim/termios.cc (_M2_termios_ctor): Likewise.
>   * libm2pim/wrapc.c: Add a new line to the file end.

all LGTM  (together with the other GCC decl patch),

thanks,
Gaius


Re: [PATCH] modula-2, doc: Build dvi, ps and pdf doc in the gcc/doc directory.

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on darwin21 with "make m2.pdf" and "make m2.dvi".
> OK for trunk?
> thanks.
> Iain
>
> --- 8< ---
>
> This also uses the configured $(TEXI2DVI) and $(TEXI2PDF) to deal with those
> targets (since we cannot assume to know what the user might have installed).
>
> gcc/m2/ChangeLog:
>
>   * Make-lang.in (dvi, ps, pdf): Build in the gcc/doc directory, also
>   use the configured tools for texi -> dvi and texi -> pdf.
> ---
>  gcc/m2/Make-lang.in | 14 +-
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
> index a134d3aca92..6c2b095bb7d 100644
> --- a/gcc/m2/Make-lang.in
> +++ b/gcc/m2/Make-lang.in
> @@ -140,18 +140,22 @@ $(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext): 
> doc/m2.1 installdirs
>   -$(INSTALL_DATA) $< $@
>   -chmod a-x $@
>  
> -m2.dvi: $(TEXISRC)
> +m2.dvi: doc/m2.dvi
> +
> +doc/m2.dvi: $(TEXISRC)
>   $(TEXI2DVI) -I $(objdir)/m2 -I $(srcdir)/doc/include 
> $(srcdir)/doc/gm2.texi -o $@
>  
> -m2.ps: m2.dvi
> +doc/m2.ps: doc/m2.dvi
>   dvips -o $@ $<
>  
> -m2.pdf: m2.ps
> - gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$@ $<
> +m2.pdf: doc/m2.pdf
> +
> +doc/m2.pdf: $(TEXISRC)
> + $(TEXI2PDF) -I $(objdir)/m2 -I $(srcdir)/doc/include 
> $(srcdir)/doc/gm2.texi -o $@
>  
>  .INTERMEDIATE: m2.pod
>  
> -m2.pod: doc/gm2.texi $(TEXISRC)
> +m2.pod: $(TEXISRC)
>   -$(TEXI2POD) -I $(objdir)/m2 -D m2 < $< > $@
>  
>  doc/m2.info: $(TEXISRC)

thanks LGTM -

regards,
Gaius


Re: [PATCH] Modula-2, testsuite: No 96 bit floating type on Darwin.

2023-01-04 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Tested on x86_64  and aarch64 Darwin,
> OK for master?
> thanks
> Iain
>
> --- 8< ---
>
> The realbitscast.mod is currently failing on x86_64 and aarch64
> Darwin since they do not have a 96b floating type.  Disable the
> type for all Darwin arches.
>
> gcc/testsuite/ChangeLog:
>
>   * gm2/iso/pass/realbitscast.mod: Disable REAL96 on Darwin.
> ---
>  gcc/testsuite/gm2/iso/pass/realbitscast.mod | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/testsuite/gm2/iso/pass/realbitscast.mod 
> b/gcc/testsuite/gm2/iso/pass/realbitscast.mod
> index 4da5cee..c6b70eb032c 100644
> --- a/gcc/testsuite/gm2/iso/pass/realbitscast.mod
> +++ b/gcc/testsuite/gm2/iso/pass/realbitscast.mod
> @@ -28,11 +28,10 @@ FROM SYSTEM IMPORT CAST, WORD ;
>  #elif defined(__ppc__)
>  #   undef HAVE_REAL96
>  #elif defined(__ia64)
> -#   undef HAVE_REAL69
> -#elif defined(__APPLE__) && defined(__i386__)
>  #   undef HAVE_REAL96
>  #elif defined(__APPLE__)
> -#   define HAVE_REAL96
> +(* No 96 bit floating type on Apple platforms *)
> +#   undef HAVE_REAL96
>  #endif

Hi Iain,

sure yes LGTM,

regards,
Gaius


Re: [PATCH 3/n] modula2: Ensure that module registration constructors are 'extern' [PR108183].

2022-12-31 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> There are several modula-2 issues on Darwin, some blocking bootstrap on
> one or more system versions.
>
> This has been tested on powerpc/i688-darwin9 .. x86_64-darwin10,17,21 and
> the prototype aarch64-darwin branch on darwin21.
>
> OK for trunk?
> thanks
> Iain
>
> NOTE: As discussed in the PR, there are likely to be other changes to the
> _definitions_ of the module registration constructors.  This patch only
> relates to the _references_ to those CTORs.
>
> --- 8< ---
>
> The symbols for module registration constructors need to be external
> or we get wrong code generated for targets that allow direct access to
> local symbol definitions.
>
> Signed-off-by: Iain Sandoe 
>
>   PR modula2/108183
>
> gcc/m2/ChangeLog:
>
>   * gm2-compiler/M2GCCDeclare.mod: Module registration constructors are
>   externs to the builder of m2_link.
> ---
>  gcc/m2/gm2-compiler/M2GCCDeclare.mod | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/gcc/m2/gm2-compiler/M2GCCDeclare.mod 
> b/gcc/m2/gm2-compiler/M2GCCDeclare.mod
> index 7e814b631ee..4c177c47398 100644
> --- a/gcc/m2/gm2-compiler/M2GCCDeclare.mod
> +++ b/gcc/m2/gm2-compiler/M2GCCDeclare.mod
> @@ -2294,6 +2294,11 @@ PROCEDURE IsExternal (sym: CARDINAL) : BOOLEAN ;
>  VAR
> mod: CARDINAL ;
>  BEGIN
> +   IF IsProcedure (sym) AND IsExtern (sym)
> +   THEN
> + Assert (NOT IsDefImp (sym));
> + RETURN TRUE
> +   END ;
> mod := GetScope(sym) ;
> REPEAT
>IF mod=NulSym

a very minor change suggested:

VAR
   mod: CARDINAL ;
BEGIN
   Assert (NOT IsDefImp (sym)) ;
   IF IsProcedure (sym) AND IsExtern (sym)
   THEN
  RETURN TRUE
   END ;
   mod := GetScope(sym) ;
   REPEAT
  IF mod=NulSym


as it doesn't make sense to call GetScope from a DefImp symbol.
There is no entry in the double booking tree for DefImp symbols
(definition / implmentation modules) - so it really shouldn't occur.

Other than this obvious change, the patches 1, 2, 3 LGTM - I've also
boot strapped and built these patches (with the above Assert change) on
amd64 gnu/linux for what it is worth,

regards,
Gaius


Re: [PATCH modula2] PR-108142 Remove empty directories created in the build directory

2022-12-29 Thread Gaius Mulley via Gcc-patches
Iain Sandoe  writes:

> Hi Gaius,
>
> I’m finding it hard to figure out how the configuration is supposed to work 
> for cross compilers (and more so for Canadian/native crosses).
>
> Apologies if this is already answered in other review (but maybe some notes 
> would help in that case).
>
> questions in-line, thanks
> Iain

Hi Iain,

many thanks for the comments.  The patch only addresses the empty
directories issue.  I take your point about Canadian cross compiler
problems.  I think there is confusion in my use of stage1, stage2,
stage3 directory names which perhaps should be renamed cxxobj1, m2obj2,
m2obj3.  All objects in cxxobj1 are created by 'mc' and 'g++' and this
would occur if the compiler is built native or in any cross
configuration.

The m2obj2 objects would be built from modula-2 sources using cxxobj1
and would be a developer/maintainer enabled option principally used for
debugging.  Finally m2obj3 is also used by developers to allow the
compiler generations output to be compared (cxxobj1 vs m2obj2 vs
m2obj3).  

This could coexist with the standard stage1, stage2, stage3 of gcc.  The
gcc stage check would only check cxxobj1 having been rebuilt by the
relevant g++/gcc.

I propose to rework the patch (renaming the directories) and ensure that
Canadian cross works (currently it doesn't) - although it was tested for
classic cross (build == host != target).

regards,
Gaius


>> On 26 Dec 2022, at 14:46, Gaius Mulley via Gcc-patches 
>>  wrote:
>>
>>
>> Hello,
>>
>> Bootstrapped on amd64 GNU/Linux.  Ok for trunk?
>>
>> regards,
>> Gaius
>>
>> --- 8< ---
>>
>> PR-108142 Remove empty directories created in the build directory.
>>
>> This patch removes empty directories created in the build directory.
>> Directories are only created if required and all modula-2 build output
>> is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.
>>
>> gcc/m2/ChangeLog:
>>
>>* PR m2/108142
>>  * Make-lang.in: Change build directory to m2.
>>Change all rules to dynamically create subdirectories
>>when required.
>>  (m2.stageprofile): New.
>>  (m2.stagefeedback): New.
>>  * Make-maintainer.in: Change build directory to m2.
>>Change all rules to dynamically create subdirectories when
>>required.
>>  * config-lang.in: Remove static creation of build directories.
>>
>> diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
>> index a8bd7fe4d19..828eaad6285 100644
>> --- a/gcc/m2/Make-lang.in
>> +++ b/gcc/m2/Make-lang.in
>> @@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed 
>> '$(program_transform_cross_name)'`
>>
>> M2_MAINTAINER = no
>>
>> -GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
>> +GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g
>
> What does “stage1” mean in the case of a cross-compiler or a
> —disable-bootstrap configure?

stage1 (or the proposed newly named cxxobj1) is created when the first
generation modula-2 compiler is built (using mc/g++).

>> GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
>> -L$(objdir)/../ld $(TFLAGS)
>>
>> @@ -61,7 +61,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi 
>> m2/gm2-libs.texi m2/gm2-ebnf.
>>  -cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
>>  -cp -p m2/gm2-libs.texi $(srcdir)/m2
>>  -cp -p m2/gm2-ebnf.texi $(srcdir)/m2
>> -find . -name '*.texi' -print
>> else
>> m2.srcextra:
>> endif



>> @@ -565,6 +518,7 @@ m2/gm2-gcc/m2configure.o: 
>> $(srcdir)/m2/gm2-gcc/m2configure.cc \
>>$(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
>>m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
>>$(generated_files) $(C_TREE_H) insn-attr-common.h
>> +-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
>>  $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>>  $(DRIVER_DEFINES) \
>>  -DLIBSUBDIR=\"$(libsubdir)\" \
>> @@ -585,6 +539,7 @@ m2/m2pp.o : $(srcdir)/m2/m2pp.cc 
>> $(GCC_HEADER_DEPENDENCIES_FOR_M2)
>>
>> m2/gm2-gcc/rtegraph.o: $(srcdir)/m2/gm2-gcc/rtegraph.cc 
>> $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
>>gt-m2-rtegraph.h
>> +-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
>>  $(COMPILER) -c -g -I$(GM2GCC) $(ALL_COMPILERFLAGS) \
>
> GM2GCC = -I$(srcdir)/m2 -Im2 -I$(srcdir)/m2/gm2-gcc -Im2/gm2-gcc ?

allows g++ to pick up the mc translated definition modules in the build
directory gcc/m2/gm2-gcc/G*.h.  Maybe I've misunderstood the question?
There is some redundancy when this macro is used within some rules (I'll
reduce the paths), thanks for spotting it!

> (and in two other places).
>
>> $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
>>
>> @@ -593,6 +548,7 @@ c-family/m2pp.o : $(srcdir)/m2/m2pp.cc 
>> $(GCC_HEADER_DEPENDENCIES_FOR_M2)
>> $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
>>




[PATCH modula2] PR-108142 Remove empty directories created in the build directory

2022-12-26 Thread Gaius Mulley via Gcc-patches


Hello,

Bootstrapped on amd64 GNU/Linux.  Ok for trunk?

regards,
Gaius

--- 8< ---

PR-108142 Remove empty directories created in the build directory.

This patch removes empty directories created in the build directory.
Directories are only created if required and all modula-2 build output
is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.

gcc/m2/ChangeLog:

* PR m2/108142
* Make-lang.in: Change build directory to m2.
Change all rules to dynamically create subdirectories
when required.
(m2.stageprofile): New.
(m2.stagefeedback): New.
* Make-maintainer.in: Change build directory to m2.
Change all rules to dynamically create subdirectories when
required.
* config-lang.in: Remove static creation of build directories.

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index a8bd7fe4d19..828eaad6285 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed 
'$(program_transform_cross_name)'`
 
 M2_MAINTAINER = no
 
-GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
+GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g
 
 GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
-L$(objdir)/../ld $(TFLAGS)
 
@@ -61,7 +61,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi 
m2/gm2-libs.texi m2/gm2-ebnf.
-cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
-cp -p m2/gm2-libs.texi $(srcdir)/m2
-cp -p m2/gm2-ebnf.texi $(srcdir)/m2
-   find . -name '*.texi' -print
 else
 m2.srcextra:
 endif
@@ -153,7 +152,7 @@ doc/m2.info: $(TEXISRC)
else true; fi
 
 $(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
-   test -d m2/images || mkdir -p m2/images
+   -test -d m2/images || $(mkinstalldirs) m2/images
cp $(srcdir)/m2/images/gnu.eps $@
 
 # gm2-libs.texi
@@ -163,6 +162,9 @@ m2/gm2-libs.texi: gm2-libs.texi-check; @true
 ifeq ($(HAVE_PYTHON),yes)
 gm2-libs.texi-check: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/Builtins.texi \
  $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def
+   test -d m2/gm2-libs-pim || $(mkinstalldirs) m2/gm2-libs-pim
+   test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
+   test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
$(PYTHON) $(srcdir)/m2/tools-src/def2doc.py -t -uLibraries 
-s$(srcdir)/m2 -b$(objdir)/m2 -o $(objdir)/m2/gm2-libs.texi
 else
 gm2-libs.texi-check:
@@ -279,59 +281,21 @@ Builtins.rst-check:  m2/gm2-libs/Builtins.def
 endif
$(STAMP) Builtins.rst-check
 
-$(objdir)/m2/gm2-compiler-boot:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-boot:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libiberty:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-gcc:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-iso:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-min:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler-paranoid:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-paranoid:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler-verify:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/boot-bin:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-pim:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-coroutines:
-   test -d $@ || mkdir $@
-
-stage1/m2:
-   -test -d $@ || mkdir -p stage1/m2
-
-stage2/m2:
-   -test -d $@ || mkdir -p stage2/m2
-
-stage3/m2:
-   -test -d $@ || mkdir -p stage3/m2
+# Stage hooks:
+# The toplevel makefile has already created stage?/m2 at this point.
 
-stage4/m2:
-   -test -d $@ || mkdir -p stage4/m2
+m2.stage1: stage1-start
+   -mv m2/*$(objext) stage1/m2
+m2.stage2: stage2-start
+   -mv m2/*$(objext) stage2/m2
+m2.stage3: stage3-start
+   -mv m2/*$(objext) stage3/m2
+m2.stage4: stage4-start
+   -mv m2/*$(objext) stage4/m2
+m2.stageprofile: stageprofile-start
+   -mv m2/*$(objext) stageprofile/m2
+m2.stagefeedback: stageprofile-start
+   -mv m2/*$(objext) stagefeedback/m2
 
 # No gm2-specific selftests
 selftest-m2:
@@ -408,7 +372,7 @@ m2.install-plugin: installdirs
 
 plugin/m2rte$(exeext).so: $(srcdir)/m2/plugin/m2rte.cc 
$(GCC_HEADER_DEPENDENCIES_FOR_M2) \
 insn-attr-common.h insn-flags.h $(generated_files)
-   test -d plugin || mkdir plugin
+   -test -d plugin || $(mkinstalldirs) plugin
$(PLUGINCC) $(PLUGINCFLAGS) -fno-rtti -I. -I$(srcdir) -I$(srcdir)/m2 
-I$(srcdir)/m2/gm2-gcc -I$(srcdir)/../include -I$(srcdir)/../libcpp/include 
-Wall $(GMPINC) -Wno-literal-suffix -fPIC -c -o plugin/m2rte.o 
$(srcdir)/m2/plugin/m2rte.cc
$(PLUGINCC) $(PLUGINCFLAGS) $(PLUGINLIBS) -fno-rtti plugin/m2rte.o 
-shared -o $@
 
@@ -428,20 +392,6 @@ m2.clean:
 m2.extraclean:
 m2.realclean:
 
-# Stage hooks:
-
-m2.stage1: stage1-start
-   -mv m2/*$(objext) stage1/m2
-
-m2.stage2: 

Re: [PATCH] modula2: PR-108119 Disable m2 plugin m2rte

2022-12-21 Thread Gaius Mulley via Gcc-patches
Rainer Orth  writes:

> Hi Gaius,
>
> Btw., you've got a couple of formatting errors in your ChangeLog entires:
>
 ChangeLog:

 * Makefile.def (extra_configure_flags): Add @enable_m2plugin@.
 * Makefile.in : Rebuilt.
>  ^ no blank here.  Besides, the entires are
>usually in present tense ("Rebuild").
>
 * configure.ac (host_tools): Remove unused gm2tools.
 (m2plugin) New AC_ARG_ENABLE.
>   ^ missing :
>
> and several times more.  Just nits, but best keep the entires consistent
> with the GNU Coding Standards.
>
> Thanks.
> Rainer

Hi Rainer,

thanks for spotting these - yes I'll double check ChangeLogs in the
future and adjust to present tense,

regards,
Gaius




Re: [PATCH] modula2: PR-108119 Disable m2 plugin m2rte

2022-12-21 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

>>
>> ChangeLog:
>>
>> * Makefile.def (extra_configure_flags): Add @enable_m2plugin@.
>> * Makefile.in : Rebuilt.
>> * configure : Rebuilt.
>> * configure.ac (host_tools): Remove unused gm2tools.
>> (m2plugin) New AC_ARG_ENABLE.
>> (enable_m2plugin) New AC_SUBST added.
>
> Why's this at the toplevel?

ah sorry - my misunderstanding on how configure and friends work.  I'll
rework the patch local to gcc/m2.  Thanks for spotting this error,

regards,
Gaius


Re: [committed] modula2: Fix lto profiledbootstrap on powerpc64le-linux and s390x-linux [PR108153]

2022-12-21 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> Hi!
>
> Lto profiledbootstrap was failing for me on {powerpc64le,s390x}-linux with
> modula 2 enabled, with:
> cc1gm2: internal compiler error: the location value is corrupt
> 0x11a3d2d m2assert_AssertLocation(unsigned int)
> ../../gcc/m2/gm2-gcc/m2assert.cc:40
> 0x11a3d2d m2statement_BuildAssignmentTree
> ../../gcc/m2/gm2-gcc/m2statement.cc:177
> ICE.  The problem was that caller (m2assert_AssertLocation used
> location_t M2Options_OverrideLocation (location_t);
> prototype with the libcpp/line-map.h
> typedef unsigned int location_t;
> typedef, but the callee defined in Modula 2 was using:
> TYPE
>location_t = INTEGER ;
> and
> PROCEDURE OverrideLocation (location: location_t) : location_t ;
> Now, on powerpc64le-linux unsigned int is returned and passed zero extended
> into 64-bits, while signed int is returned and passed sign-extended into 
> 64-bits
> and Modula 2 INTEGER is signed 32-bit type, so when the caller then compared
> M2Options_OverrideLocation (location) != location
> and powerpc64le-linux performed the comparison as 64-bit compare, there
> was a mismatch for location_t of 0x807 or others with the MSB set.
>
> Fixed by making Modula 2 location_t a CARDINAL, which is 32-bit unsigned type.
>
> Bootstrapped/regtested normally on x86_64-linux and i686-linux, with
> bootstrap-lto profiledbootstrap on powerpc64le-linux and aarch64-linux so
> far (and in regtesting on x86_64-linux, i686-linux and s390x-linux),
> approved in the PR by Gaius, committed to trunk.
>
> 2022-12-21  Jakub Jelinek  
>
>   PR modula2/108153
>   * gm2-gcc/m2linemap.def (location_t): Use CARDINAL instead of INTEGER.
>
> --- gcc/m2/gm2-gcc/m2linemap.def.jj   2022-12-19 14:59:50.169762747 +0100
> +++ gcc/m2/gm2-gcc/m2linemap.def  2022-12-20 16:36:18.321555969 +0100
> @@ -30,7 +30,7 @@ EXPORT QUALIFIED StartFile, EndFile, Sta
>   WarningAtf, NoteAtf, internal_error, location_t ;
>  
>  TYPE
> -   location_t = INTEGER ;
> +   location_t = CARDINAL ;
>  
>  
>  PROCEDURE StartFile (filename: ADDRESS; linebegin: CARDINAL) ;
>
>   Jakub

Hi Jakub,

thanks for finding the bug and the fix!

regards,
Gaius





[PATCH] modula2: PR-108119 Disable m2 plugin m2rte

2022-12-21 Thread Gaius Mulley via Gcc-patches


Hello,

PR-108119 Disable m2 plugin m2rte (provide --enable-m2plugin configure option).

The m2 plugin m2rte attempts to find reachable calls to the m2 exception
handler, but it identifies the m2 exception calls by procedure name.
As this won't work with other languages it should be disabled by default.

This patch disables the plugin from being built.  It provides a new
configure switch --enable-m2plugin to override the default and it will
check the HAVE_PLUGIN of the host and warn if there is a conflict.

Tested on x86_64 GNU/Linux bootstrapped for all languages no extra
failures (m2 tests missing as the plugin is disabled and TCL expect
now disables m2 plugin tests)

ok for trunk?

regards,
Gaius


ChangeLog:

* Makefile.def (extra_configure_flags): Add @enable_m2plugin@.
* Makefile.in : Rebuilt.
* configure : Rebuilt.
* configure.ac (host_tools): Remove unused gm2tools.
(m2plugin) New AC_ARG_ENABLE.
(enable_m2plugin) New AC_SUBST added.

gcc/ChangeLog:

* Makefile.in (enable_m2plugin): Added.
(site.exp): New variable ENABLE_M2PLUGIN.
* config.in: Rebuilt.
* configure : Rebuilt.
* gcc/configure.ac (m2plugin): New AC_ARG_ENABLE.
(enable_m2plugin) New AC_SUBST added.
* doc/install.texi (--enable-m2plugin): Documented.

gcc/m2/ChangeLog:

* gm2spec.cc (ENABLE_PLUGIN): Replaced by ENABLE_M2PLUGIN.  Ensure
that OPT_fplugin option is only created if ENABLE_M2PLUGIN is
defined.
(lang_specific_driver) Change warning to mention
--enable-m2plugin.
* Make-lang.in (enable_m2plugin): Set to no if enable_plugin is
no.
(M2RTE_PLUGIN_SO) New definition.
(m2.all.cross) Use M2RTE_PLUGIN_SO.
(m2.start.encap) Use M2RTE_PLUGIN_SO.
(m2.install-plugin) Use M2RTE_PLUGIN_SO.
(m2.install-plugin) Add dummy rule when enable_m2plugin is no.
(plugin/m2rte$(exeext).so) Add dummy rule when enable_m2plugin is
no.
(stage1/m2/cc1gm2$(exeext) Use M2RTE_PLUGIN_SO.
(stage2/m2/cc1gm2$(exeext) Use M2RTE_PLUGIN_SO.

gcc/testsuite/ChangeLog:

* gm2/coroutines/pim/run/pass/coroutines-pim-run-pass.exp
(ENABLE_M2PLUGIN): Checked to see whether the test should be ignored.
* gm2/iso/check/fail/iso-check-fail.exp (ENABLE_M2PLUGIN): Ditto.
* gm2/switches/auto-init/fail/switches-auto-init-fail.exp
(ENABLE_M2PLUGIN): Ditto.
* gm2/switches/check-all/pim2/fail/switches-check-all-pim2-fail.exp
(ENABLE_M2PLUGIN): Ditto.
* 
gm2/switches/check-all/plugin/iso/fail/switches-check-all-plugin-iso-fail.exp
(ENABLE_M2PLUGIN): Ditto.
* 
gm2/switches/check-all/plugin/pim2/fail/switches-check-all-plugin-pim2-fail.exp
(ENABLE_M2PLUGIN): Ditto.

diff --git a/Makefile.def b/Makefile.def
index 5f44190154e..d33e4528b63 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -103,7 +103,7 @@ host_modules= { module= libiberty; bootstrap=true;
 // @extra_linker_plugin_flags@ and @extra_linker_plugin_configure_flags@.
 host_modules= { module= libiberty-linker-plugin; bootstrap=true;
module_srcdir=libiberty;
-   extra_configure_flags='@extra_host_libiberty_configure_flags@ 
--disable-install-libiberty @extra_linker_plugin_flags@ 
@extra_linker_plugin_configure_flags@';
+   extra_configure_flags='@extra_host_libiberty_configure_flags@ 
--disable-install-libiberty @extra_linker_plugin_flags@ 
@extra_linker_plugin_configure_flags@ @enable_m2plugin@';
extra_make_flags='@extra_linker_plugin_flags@'; };
 // We abuse missing to avoid installing anything for libiconv.
 host_modules= { module= libiconv;
diff --git a/configure.ac b/configure.ac
index c5191ce24ae..b771f61ef33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,7 +140,7 @@ host_libs="intl libiberty opcodes bfd readline tcl tk itcl 
libgui zlib libbacktr
 # binutils, gas and ld appear in that order because it makes sense to run
 # "make check" in that particular order.
 # If --enable-gold is used, "gold" may replace "ld".
-host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gm2tools gotools c++tools"
+host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gotools c++tools"
 
 # these libraries are built for the target environment, and are built after
 # the host libraries and the host tools (which may be a cross compiler)
@@ -465,13 +465,22 @@ if test "${ENABLE_LIBADA}" != "yes" ; then
   noconfigdirs="$noconfigdirs gnattools"
 fi
 
+
 AC_ARG_ENABLE(libgm2,
 [AS_HELP_STRING([--enable-libgm2], [build libgm2 directory])],
 ENABLE_LIBGM2=$enableval,
 ENABLE_LIBGM2=no)
-if test "${ENABLE_LIBGM2}" != "yes" ; then
-  noconfigdirs="$noconfigdirs gm2tools"
+
+

Re: [PATCH] modula2: Don't treat % in Modula 2 messages specially

2022-12-19 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> Hi!
>
> On top of the just posted patch, this patch makes sure that
> any % chars in message strings aren't treated as format chars.
> None of these functions take variable number of arguments, so for
> most of format specifiers there is nowhere to take arguments from,
> it is true that a couple of format specifiers don't take any
> arguments - %%, %m, %<, %>, %' - so it is actually possible
> to use them, but one needs to verify that no other are emitted and
> that what should be printed as % is really emitted as %%.
> If the FE does that, then please ignore this patch, otherwise I think
> it is safer to do this.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux.

yes it might be possible for % to slip though.  Thus much safer to avoid
the situation by using the patch.

LGTM

regards,
Gaius


Re: [PATCH] modula2: Fix up bootstrap on powerpc64le-linux [PR108147]

2022-12-19 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> Hi!
>
> As mentioned in the PR, bootstrap with m2 enabled currently fails
> on powerpc64le-linux, we get weird ICE after printing some diagnostics.
> The problem is that mc creates from *.def prototypes like
> extern void m2linemap_WarningAtf (m2linemap_location_t location, void * 
> message);
> but the actual function definitions use
> void m2linemap_WarningAtf (m2linemap_location_t location, void * message,
> ...) { code }
> and on powerpc64le-linux such lying about the prototype results in
> wrong-code, on the caller side we assume the function isn't varargs
> and so don't reserve 64 bytes in the frame for it, while the callee
> relies on the area being reserved and stores into it.
>
> Fixed by adding non-stdarg wrappers around stdarg functions (because
> we want va_list and pass it to diagnostics functions).
>
> Bootstrapped/regtested on {x86_64,i686,powerpc64le,s390x,aarch64}-linux,
> ok for trunk?
>
> 2022-12-19  Jakub Jelinek  
>
>   PR modula2/108147
>   * m2/gm2-gcc/m2linemap.def (ErrorAtf, WarningAtf, NoteAtf):
>   Comment out prototypes with varargs.
>   * m2/gm2-gcc/m2linemap.h (m2linemap_ErrorAtf, m2linemap_WarningAtf,
>   m2linemap_NoteAtf): No longer varargs.
>   * m2/gm2-gcc/m2linemap.cc (m2linemap_ErrorAtf): Turned into a
>   non-varargs wrapper around ...
>   (m2linemap_ErrorAtf_1): ... this.  New static function.
>   (m2linemap_WarningAtf): Turned into a non-varargs wrapper around ...
>   (m2linemap_WarningAtf_1): ... this.  New static function.
>   (m2linemap_NoteAtf): Turned into a non-varargs wrapper around ...
>   (m2linemap_NoteAtf_1): ... this.  New static function.

thanks for the patch, both this and the subsequent followup patch LGTM,

regards,
Gaius


[PATCH, m2]: PR-108122 Reduce sleep times in gm2/pimcoroutines/run/pass/testtime.mod

2022-12-17 Thread Gaius Mulley via Gcc-patches


PR-108122 Reduce sleep times in gm2/pimcoroutines/run/pass/testtime.mod

Change time unit to 1 jiffy (with respect to TimerHandler.def) rather
than a second.

gcc/testsuite/ChangeLog:

* gm2/pimcoroutines/run/pass/testtime.mod: Reduce sleep times in
the test by a factor of 25.

Tested on amd64, ok for Trunk?


diff --git a/gcc/testsuite/gm2/pimcoroutines/run/pass/testtime.mod 
b/gcc/testsuite/gm2/pimcoroutines/run/pass/testtime.mod
index fa43163b107..f457716c89e 100644
--- a/gcc/testsuite/gm2/pimcoroutines/run/pass/testtime.mod
+++ b/gcc/testsuite/gm2/pimcoroutines/run/pass/testtime.mod
@@ -1,4 +1,4 @@
-(* Copyright (C) 2005-2020
+(* Copyright (C) 2005-2022
  Free Software Foundation, Inc. *)
 (* This file is part of GNU Modula-2.
 
@@ -31,30 +31,34 @@ FROM SYSTEM IMPORT ADR ;
 FROM libc IMPORT write, printf ;
 
 
+CONST
+   TicksPerTimeUnit = 1 ;
+
+
 (*
-   OneSecond -
+   OneUnit -
 *)
 
-PROCEDURE OneSecond ;
+PROCEDURE OneUnit ;
 VAR
n: CARDINAL ;
 BEGIN
OldInts := TurnInterrupts (MIN (PROTECTION)) ;
-   printf ("1 second process has come to life\n");
+   printf ("1 unit second process has come to life\n");
n := 0 ;
LOOP
-  Sleep (1*TicksPerSecond) ;
+  Sleep (1*TicksPerTimeUnit) ;
   INC (n) ;
-  printf ("%d seconds\n", n);
+  printf ("%d units\n", n);
END
-END OneSecond ;
+END OneUnit ;
 
 
 (*
-   FourSeconds -
+   FourUnits -
 *)
 
-PROCEDURE FourSeconds ;
+PROCEDURE FourUnits ;
 VAR
n: CARDINAL ;
 BEGIN
@@ -62,23 +66,23 @@ BEGIN
printf ("4 seconds process has come to life\n");
n := 0 ;
LOOP
-  Sleep (4*TicksPerSecond) ;
+  Sleep (4*TicksPerTimeUnit) ;
   INC (n) ;
-  printf ("4 second alarm (%d occurance)\n", n);
+  printf ("4 units alarm (%d occurance)\n", n);
END
-END FourSeconds ;
+END FourUnits ;
 
 
 (*
-   SixSeconds -
+   SixUnits -
 *)
 
-PROCEDURE SixSeconds ;
+PROCEDURE SixUnits ;
 VAR
n: CARDINAL ;
 BEGIN
OldInts := TurnInterrupts (MAX (PROTECTION)) ;
-   printf ("6 seconds process has come to life\n");
+   printf ("6 units process has come to life\n");
n := 0 ;
LOOP
   Timeout := ArmEvent (6*TicksPerSecond) ;
@@ -87,10 +91,10 @@ BEGIN
  WriteString ('...someone cancelled it...')
   ELSE
  INC (n) ;
- printf ("6 second alarm (%d occurance)\n", n)
+ printf ("6 unit alarm (%d occurance)\n", n)
   END
END
-END SixSeconds ;
+END SixUnits ;
 
 
 CONST
@@ -107,10 +111,10 @@ BEGIN
 
printf ("now to create three processes...\n") ;
 
-   p1 := Resume (InitProcess (OneSecond  , StackSize, '1')) ;
-   p4 := Resume (InitProcess (FourSeconds, StackSize, '4')) ;
-   p6 := Resume (InitProcess (SixSeconds , StackSize, '6')) ;
+   p1 := Resume (InitProcess (OneUnit  , StackSize, '1')) ;
+   p4 := Resume (InitProcess (FourUnits, StackSize, '4')) ;
+   p6 := Resume (InitProcess (SixUnits , StackSize, '6')) ;
 
-   Sleep (20*TicksPerSecond) ;
+   Sleep (20*TicksPerTimeUnit) ;
printf ("successfully completed, finishing now.\n")
 END testtime.


[PATCH, m2] Add missing m2.stage{profile,feedback} to Make-lang.in

2022-12-16 Thread Gaius Mulley via Gcc-patches



Add missing profile and feedback hooks consistent with
all other frontends.

gcc/m2/ChangeLog:

* Make-lang.in (m2.stageprofile): Added.
(m2.stagefeedback) Added.

Bootstrapped and tested using
configure --with-build-config=bootstrap-lto-lean --enable-languages=m2
make profiledbootstrap-lean
ok for trunk?


diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index a8bd7fe4d19..be33e012dc9 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -442,6 +442,12 @@ m2.stage3: stage3-start
 m2.stage4: stage4-start
-mv m2/*$(objext) stage4/m2
 
+m2.stageprofile: stageprofile-start
+   -mv m2/*$(objext) stageprofile/m2
+
+m2.stagefeedback: stagefeedback-start
+   -mv m2/*$(objext) stagefeedback/m2
+
 quit: force
echo "calling exit"
exit 1


[committed, pushed] PR-107607 m2: Remove bdepend on realpath, cut and echo

2022-12-15 Thread Gaius Mulley via Gcc-patches



It can be replaced by a subshell'd cd just fine.
(cd gcc/m2; autoconf-2.69)

gcc/m2/ChangeLog:

* configure.ac: Stop probing for realpath.
* tools-src/calcpath: Break dependency on realpath, cut
and echo.
* configure: Rebuilt
---
 gcc/m2/configure.ac   |  5 -
 gcc/m2/tools-src/calcpath | 34 ++
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/gcc/m2/configure.ac b/gcc/m2/configure.ac
index 756e01c4321..5583af7f64c 100644
--- a/gcc/m2/configure.ac
+++ b/gcc/m2/configure.ac
@@ -24,11 +24,6 @@ AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
 AC_CANONICAL_TARGET
 
-AC_CHECK_PROGS(regex_realpath, realpath)
-if test x$regex_realpath = "x" ; then
-AC_MSG_ERROR([realpath is required to build GNU Modula-2 (hint install 
coreutils).])
-fi
-
 AC_CHECK_FUNCS([stpcpy])
 
 AC_CHECK_HEADERS(sys/types.h)
diff --git a/gcc/m2/tools-src/calcpath b/gcc/m2/tools-src/calcpath
index e0817704f64..05324513aa1 100755
--- a/gcc/m2/tools-src/calcpath
+++ b/gcc/m2/tools-src/calcpath
@@ -23,27 +23,29 @@
 
 
 Usage () {
-   echo "Usage: calcpath pathcomponent1 pathcomponent2 subdir"
-   echo -n "  if pathcomponent1 is relative then 
pathcomponent1/pathcomponet2/subdir is"
-   echo " returned"
-   echo "  otherwise pathcomponet2/subdir is returned"
-   echo "  the path is checked for legality in subdir."
+   cat<&2
+   exit 1
+}
 
 if [ $# -eq 3 ]; then
-   if [ "$(echo $2 | cut -b 1)" = "." ] ; then
-   # relative path
-   the_path=$1/$2/$3
+   case "$2" in
+  /*) the_path="$2/$3" ;;
+  *) the_path="$1/$2/$3" ;;
+   esac
+   cd "$3" || die "could not access $3"
+   if ( cd "$the_path" ); then
+  printf '%s\n' "${the_path}"
else
-   the_path=$2/$3
-   fi
-   cd $3
-   if realpath ${the_path} > /dev/null ; then
-   echo ${the_path}
-   else
-   echo "calcpath: error ${the_path} is not a valid path in subdirectory 
$3" 1>&2
-   exit 1
+  die "${the_path} is not a valid path in subdirectory $3"
fi
 else
Usage
-- 
2.39.0



Re: [PATCH v5 1/19] modula2 front end: Fixes, improvements detecting python3 and documentation generation (shorter).

2022-12-15 Thread Gaius Mulley via Gcc-patches
Jakub Jelinek  writes:

> On Wed, Dec 14, 2022 at 08:35:07AM +0000, Gaius Mulley via Gcc-patches wrote:
>> thanks - this is the last patch tick.  So I'll actually do the merge now :-)
>
> I've committed following patch to fix up formatting of ChangeLog entries.

Many thanks and apologies for messing up the house style.


Re: [PATCH v5 1/19] modula2 front end: Fixes, improvements detecting python3 and documentation generation (shorter).

2022-12-14 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Wed, Dec 14, 2022 at 8:48 AM Gaius Mulley  wrote:
>>
>>
>>
>> This patch set adds a re-exp ACX_CHECK_PROG_VER to detect python3.
>> HAVE_PYTHON is then checked in gcc/m2/Make-lang.in to generate library
>> chapters if python3 is available.  If python3 is unavailable then the
>> chapters are copied from a target-independent version.
>>
>> Bugfixed --enable-generated-files-in-srcdir.
>>
>> Python3 modules section added to install.texi.
>>
>> Also included are the target-independent versions of the
>> documentation.  The only difference is in the SYSTEM module which if
>> generated when HAVE_PYTHON is "yes" will enumerate all fundamental
>> data types supported by the target and compiler.
>>
>> I've hand snipped to try and reduce the size/noise as some of
>> these files have already been reviewed.
>>
>> I'll post the unedited version as well for completness,
>
> LGTM.

thanks - this is the last patch tick.  So I'll actually do the merge now :-)

> I'll note that in other GCC manuals we have target dependent
> things documented for each supported target.  It looks like
> the M2 docs will have only documentation built for the target
> the compiler is built for?  So for example the online documentation
> hosted on gcc.gnu.org will then contain only documentation for
> the x86_64-linux target specific SYSTEM module?

true

> building documentation for openSUSE (caveat: we only build
> .info docs and manpages) the documentation is only built once
> (aka for rpm 'noarch') with the idea it will be the same on all targets.
>
> So it seems to me that enumerating the SYSTEM module documentation
> for all targets or somehow differently organizing it would be better?

yes it would.  There is a desire to move the non standard data types out
of SYSTEM (by the user community) for the future.  But having a comment
saying data type availability dependant upon target architecture would
suffice for now, I'll add a comment,

regards,
Gaius


Re: [PATCH v4 1/19] modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite.

2022-12-12 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Sat, Dec 10, 2022 at 1:49 AM Gaius Mulley via Gcc-patches
>  wrote:
>>
>>
>> While writing the ChangeLog entries git gcc-verify spotted an oversight
>> with v3 of this patch set.  I had forgotten to post gm2.texi and also a
>> tiny patchlet in gcc/configure.ac (to detect Python).  HAVE_PYTHON is
>> used within gcc/m2/Make-lang.in to avoid generating the library section
>> included by gm2.texi should Python not be available.
>
> The configure check doesn't verify the python version.

indeed - I'll fix this

>  Does --enable-generated-files-in-srcdir (used when building release
> tarballs) generate the required section so it's packed up in the
> release tarball and avoid requiring python3 when building from the
> release tarball?

currently working on it - no it fails - should be done rsn.

> Note these kind of dependences should be mentioned in
> install.texi - for python also listing required modules would be nice.

I'll add these.

> Thanks,
> Richard.
>
>> ok to commit?  I've included gm2-lang.cc and lang.opt for reference.
>
> The python script would have been more informative, the generated
> .texi fragment and the Make-lang.in part as well

ah yes this is true, sorry.

regards,
Gaius


Re: [PATCH v5 1/19] modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite. Addendum.

2022-12-11 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Sat, Dec 10, 2022 at 12:29 PM Gaius Mulley via Gcc-patches
>  wrote:
>>
>>
>> This patch contains a replacement doc/gm2.texi which uses American
>> spelling, all references to gm2 outside the gcc tree purged and the
>> News/Obtaining sections have been removed.
>>
>> Also included at the end is the lang.opt file for reference.
>
> LGTM.

thanks!


[PATCH v5 1/19] modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite. Addendum.

2022-12-10 Thread Gaius Mulley via Gcc-patches


This patch contains a replacement doc/gm2.texi which uses American
spelling, all references to gm2 outside the gcc tree purged and the
News/Obtaining sections have been removed.

Also included at the end is the lang.opt file for reference.


diff -ruw /dev/null gcc-git-devel-modula2/gcc/doc/gm2.texi
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/doc/gm2.texi  2022-12-10 10:58:06.177440039 
+
@@ -0,0 +1,2843 @@
+\input texinfo
+@c -*-texinfo-*-
+@c Copyright (C) 2001-2022 Free Software Foundation, Inc.
+@c This is part of the GM2 manual.
+
+@c User level documentation for GNU Modula-2
+@c
+@c header
+
+@setfilename gm2.info
+@settitle The GNU Modula-2 Compiler
+
+@set version-python  3.5
+
+@include gcc-common.texi
+
+@c Copyright years for this manual.
+@set copyrights-gm2 1999-2022
+
+@copying
+@c man begin COPYRIGHT
+Copyright @copyright{} @value{copyrights-gm2} Free Software Foundation, Inc.
+
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.3 or
+any later version published by the Free Software Foundation; with no
+Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+A copy of the license is included in the
+@c man end
+section entitled ``GNU Free Documentation License''.
+@ignore
+@c man begin COPYRIGHT
+man page gfdl(7).
+@c man end
+@end ignore
+@end copying
+
+@ifinfo
+@format
+@dircategory Software development
+@direntry
+* gm2: (gm2).   A GCC-based compiler for the Modula-2 language
+@end direntry
+@end format
+
+@insertcopying
+@end ifinfo
+
+@titlepage
+@title The GNU Modula-2 Compiler
+@versionsubtitle
+@author Gaius Mulley
+
+@page
+@vskip 0pt plus 1filll
+Published by the Free Software Foundation @*
+51 Franklin Street, Fifth Floor@*
+Boston, MA 02110-1301, USA@*
+@sp 1
+@insertcopying
+@end titlepage
+@contents
+@page
+
+@c `Top' Node and Master Menu
+
+@node Top, Overview, (dir), (dir)
+@top Introduction
+
+@menu
+* Overview:: What is GNU Modula-2.
+* Using::Using GNU Modula-2.
+* Licence::  Licence of GNU Modula-2
+* Copying::  GNU Public Licence V3.
+* Contributing:: Contributing to GNU Modula-2
+* Internals::GNU Modula-2 internals.
+* EBNF:: EBNF of GNU Modula-2
+* Libraries::PIM and ISO library definitions.
+* Indices::  Document and function indices.
+@end menu
+
+@node Overview, Using, Top, Top
+@chapter Overview of GNU Modula-2
+
+@menu
+* What is GNU Modula-2::  Brief description of GNU Modula-2.
+* Why use GNU Modula-2::  Advantages of GNU Modula-2.
+* Development::   How to get source code using git.
+* Features::  GNU Modula-2 Features
+@end menu
+
+@node What is GNU Modula-2, Why use GNU Modula-2, , Using
+@section What is GNU Modula-2
+
+GNU Modula-2 is a @uref{http://gcc.gnu.org/frontends.html, front end}
+for the GNU Compiler Collection (@uref{http://gcc.gnu.org/, GCC}).
+The GNU Modula-2 compiler is compliant with the PIM2, PIM3, PIM4 and
+ISO dialects.  Also implemented are a complete set of free ISO
+libraries and PIM libraries.
+
+@footnote{The four Modula-2 dialects supported are defined in the following
+references:
+
+PIM2: 'Programming in Modula-2', 2nd Edition, Springer Verlag, 1982,
+1983 by Niklaus Wirth (PIM2).
+
+PIM3: 'Programming in Modula-2', 3rd Corrected Edition, Springer Verlag,
+1985 (PIM3).
+
+PIM4: 'Programming in Modula-2', 4th Edition, Springer Verlag, 1988
+(@uref{http://freepages.modula2.org/report4/modula-2.html, PIM4}).
+
+ISO: the ISO Modula-2 language as defined in 'ISO/IEC Information
+technology - programming languages - part 1: Modula-2 Language,
+ISO/IEC 10514-1 (1996)'
+}
+
+@node Why use GNU Modula-2, Release map, What is GNU Modula-2, Using
+@section Why use GNU Modula-2
+
+There are a number of advantages of using GNU Modula-2 rather than
+translate an existing project into another language.
+
+The first advantage is of maintainability of the original sources
+and the ability to debug the original project source code using a
+combination of gm2 and gdb.
+
+The second advantage is that gcc runs on many processors and
+platforms.  gm2 builds and runs on powerpc64le, amd64, i386, aarch64
+to name but a few processors.
+
+gm2 can produce swig interface headers to allow access from Python and
+other scripting languages.  It can also be used with C/C++ and
+generate shared libraries.
+
+The compiler provides semantic analysis and runtime checking (full ISO
+Modula-2 checking is implemented) and there is a plugin which can,
+under certain conditions, detect runtime errors at compile time.
+
+The compiler supports PIM2, PIM3, PIM4 and ISO dialects of Modula-2,
+work is underway to implement M2R10.  Many of the GCC builtins are
+available and access to assembly programming is achieved using the
+same syntax as that used by GCC.
+
+The gm2 driver allows third party libraries to be installed 

[PATCH v4 1/19] modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite.

2022-12-09 Thread Gaius Mulley via Gcc-patches


While writing the ChangeLog entries git gcc-verify spotted an oversight
with v3 of this patch set.  I had forgotten to post gm2.texi and also a
tiny patchlet in gcc/configure.ac (to detect Python).  HAVE_PYTHON is
used within gcc/m2/Make-lang.in to avoid generating the library section
included by gm2.texi should Python not be available.

ok to commit?  I've included gm2-lang.cc and lang.opt for reference.

regards,
Gaius




diff -ruw gcc-git-master/gcc/configure.ac gcc-git-devel-modula2/gcc/configure.ac
--- gcc-git-master/gcc/configure.ac 2022-12-07 20:16:24.571677189 +
+++ gcc-git-devel-modula2/gcc/configure.ac  2022-12-07 19:46:20.036302786 
+
@@ -1263,6 +1263,10 @@
 # Bison?
 AC_CHECK_PROGS([BISON], bison, [$MISSING bison])

+# Python3?
+AM_PATH_PYTHON(,, [:])
+AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
+
 # Binutils are not build modules, unlike bison/flex/makeinfo.  So we
 # check for build == host before using them.

@@ -7651,4 +7655,3 @@
 ],
 [subdirs='$subdirs'])
 AC_OUTPUT
-
diff -ruw /dev/null gcc-git-devel-modula2/gcc/doc/gm2.texi
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/doc/gm2.texi  2022-12-10 00:04:30.263603238 
+
@@ -0,0 +1,2944 @@
+\input texinfo
+@c -*-texinfo-*-
+@c Copyright (C) 2001-2022 Free Software Foundation, Inc.
+@c This is part of the GM2 manual.
+
+@c User level documentation for GNU Modula-2
+@c
+@c header
+
+@setfilename gm2.info
+@settitle The GNU Modula-2 Compiler
+
+@set version-python  3.5
+
+@include gcc-common.texi
+
+@c Copyright years for this manual.
+@set copyrights-gm2 1999-2022
+
+@copying
+@c man begin COPYRIGHT
+Copyright @copyright{} @value{copyrights-gm2} Free Software Foundation, Inc.
+
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.3 or
+any later version published by the Free Software Foundation; with no
+Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+A copy of the license is included in the
+@c man end
+section entitled ``GNU Free Documentation License''.
+@ignore
+@c man begin COPYRIGHT
+man page gfdl(7).
+@c man end
+@end ignore
+@end copying
+
+@ifinfo
+@format
+@dircategory Software development
+@direntry
+* gm2: (gm2).   A GCC-based compiler for the Modula-2 language
+@end direntry
+@end format
+
+@insertcopying
+@end ifinfo
+
+@titlepage
+@title The GNU Modula-2 Compiler
+@versionsubtitle
+@author Gaius Mulley
+
+@page
+@vskip 0pt plus 1filll
+Published by the Free Software Foundation @*
+51 Franklin Street, Fifth Floor@*
+Boston, MA 02110-1301, USA@*
+@sp 1
+@insertcopying
+@end titlepage
+@contents
+@page
+
+@c `Top' Node and Master Menu
+
+@node Top, Overview, (dir), (dir)
+@top Introduction
+
+@menu
+* Overview:: What is GNU Modula-2.
+* Using::Using GNU Modula-2.
+* Licence::  Licence of GNU Modula-2
+* Copying::  GNU Public Licence V3.
+* Contributing:: Contributing to GNU Modula-2
+* Internals::GNU Modula-2 internals.
+* EBNF:: EBNF of GNU Modula-2
+* Libraries::PIM and ISO library definitions.
+* Indices::  Document and function indices.
+@end menu
+
+@node Overview, Using, Top, Top
+@chapter Overview of GNU Modula-2
+
+@menu
+* What is GNU Modula-2::  Brief description of GNU Modula-2.
+* Why use GNU Modula-2::  Advantages of GNU Modula-2.
+* News::  Latest news about GNU Modula-2.
+* Development::   How to get source code using git.
+* Obtaining:: Where to get the source code using git.
+* Features::  GNU Modula-2 Features
+@end menu
+
+@node What is GNU Modula-2, Why use GNU Modula-2, , Using
+@section What is GNU Modula-2
+
+GNU Modula-2 is a @uref{http://gcc.gnu.org/frontends.html, front end}
+for the GNU Compiler Collection (@uref{http://gcc.gnu.org/, GCC}).
+The GNU Modula-2 compiler is compliant with the PIM2, PIM3, PIM4 and
+ISO dialects.  Also implemented are a complete set of free ISO
+libraries and PIM libraries.
+
+@footnote{The four Modula-2 dialects supported are defined in the following
+references:
+
+PIM2: 'Programming in Modula-2', 2nd Edition, Springer Verlag, 1982,
+1983 by Niklaus Wirth (PIM2).
+
+PIM3: 'Programming in Modula-2', 3rd Corrected Edition, Springer Verlag,
+1985 (PIM3).
+
+PIM4: 'Programming in Modula-2', 4th Edition, Springer Verlag, 1988
+(@uref{http://freepages.modula2.org/report4/modula-2.html, PIM4}).
+
+ISO: the ISO Modula-2 language as defined in 'ISO/IEC Information
+technology - programming languages - part 1: Modula-2 Language,
+ISO/IEC 10514-1 (1996)'
+}
+
+@node Why use GNU Modula-2, Release map, What is GNU Modula-2, Using
+@section Why use GNU Modula-2
+
+There are a number of advantages of using GNU Modula-2 rather than
+translate an existing project into another language.
+
+The first advantage is of maintainability of the original sources
+and the ability to debug the 

Re: [PATCH v3 16/19] modula2 front end: bootstrap and documentation tools

2022-12-07 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

> On 12/6/22 15:47, Gaius Mulley wrote:
>> |Hi Martin, here is the revised patch having applied all previous
>> recommendations:
>> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603436.html. Is
>> this ok now? Thanks for the improvement suggestions.|
>
> Hello.
>
> It looks much better and I'm sending a small patch that resolves the remaining
> flake8 issue. I use the following plugins (some listed here: 
> https://gcc.gnu.org/codingconventions.html#python):
>
> $ flake8 --version
> 5.0.4 (flake8-bugbear: 22.10.27, flake8-builtins: 1.5.3,
> flake8-comprehensions: 3.4.0, flake8-import-order: 0.18.1,
> flake8-quotes: 3.3.1, mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes:
> 2.5.0) CPython 3.10.8 on Linux
>
> and I see:
>
> gcc/m2/tools-src> flake8
> ./boilerplate.py:108:66: E999 SyntaxError: invalid syntax
> ./tidydates.py:26:1: I100 Import statements are in the wrong order. 'import 
> pathlib' should be before 'import sys'
> ./tidydates.py:129:50: E128 continuation line under-indented for visual indent
> ./def2doc.py:49:5: E301 expected 1 blank line, found 0
> ./def2doc.py:49:18: E211 whitespace before '('
> ./def2doc.py:51:5: E301 expected 1 blank line, found 0
> ./def2doc.py:51:18: E211 whitespace before '('
> ./def2doc.py:53:5: E301 expected 1 blank line, found 0
> ./def2doc.py:55:5: E301 expected 1 blank line, found 0
> ./def2doc.py:57:5: E301 expected 1 blank line, found 0
> ./def2doc.py:59:5: E301 expected 1 blank line, found 0
> ./def2doc.py:61:5: E301 expected 1 blank line, found 0
> ./def2doc.py:65:5: E301 expected 1 blank line, found 0
> ./def2doc.py:70:5: E301 expected 1 blank line, found 0
> ./def2doc.py:72:5: E301 expected 1 blank line, found 0
> ./def2doc.py:191:80: E501 line too long (81 > 79 characters)
> ./def2doc.py:330:22: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:348:23: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:377:17: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:396:21: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:406:16: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:418:15: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:432:25: A002 argument "dir" is shadowing a python builtin
> ./def2doc.py:437:19: Q000 Double quotes found but single quotes preferred
> ./def2doc.py:439:19: Q000 Double quotes found but single quotes preferred
> ./def2doc.py:441:19: Q000 Double quotes found but single quotes preferred
> ./def2doc.py:468:18: Q001 Single quote multiline found but double quotes 
> preferred
>
> It seems the first one is a real syntax error. Anyway, feel free to apply the 
> suggested patch.
>
> And I would consider replacing the following static 'str.' calls:
>
> def2doc.py:output.write(str.replace(str.replace(str.rstrip(line),
> def2doc.py:output.write(str.replace(str.replace(line, '{', '@{'), 
> '}', '@}'))
>
> with line.rstrip().replace(...).replace(...)
>
> Cheers,
> Martin

Hi Martin,

many thanks for the patch and suggestions (and flake8 plugin output) - I
will apply the patch and change the str calls,

regards,
Gaius


[PATCH v4 15/19] modula2 front end: cc1gm2 additional non modula2 source files

2022-12-06 Thread Gaius Mulley via Gcc-patches


Version 4 contains two missed feedback suggestions (namespace in
m2pp.cc) and use build_nonstandard_integer_type in
gm2-lang.cc:gm2_type_for_size.

This patch set contains the .h, .cc and .flex files found in
gcc/m2.  The files are tightly coupled with the gimple interface
(see 04-gimple-interface) and built using the rules found in
(01-03-make).


--8<--8<--8<--8<--8<--8<
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-lang.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-lang.cc2022-12-06 18:18:32.612239623 
+
@@ -0,0 +1,889 @@
+/* gm2-lang.cc language-dependent hooks for GNU Modula-2.
+
+Copyright (C) 2002-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
+
+#include "gm2-gcc/gcc-consolidation.h"
+
+#include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name.  */
+#include "tree-pass.h" /* FIXME: only for PROP_gimple_any.  */
+#include "toplev.h"
+#include "debug.h"
+
+#include "opts.h"
+
+#define GM2_LANG_C
+#include "gm2-lang.h"
+#include "m2block.h"
+#include "dynamicstrings.h"
+#include "m2options.h"
+#include "m2convert.h"
+#include "m2linemap.h"
+#include "init.h"
+#include "m2-tree.h"
+#include "convert.h"
+#include "rtegraph.h"
+
+static void write_globals (void);
+
+static int insideCppArgs = FALSE;
+
+#define EXPR_STMT_EXPR(NODE) TREE_OPERAND (EXPR_STMT_CHECK (NODE), 0)
+
+/* start of new stuff.  */
+
+/* Language-dependent contents of a type.  */
+
+struct GTY (()) lang_type
+{
+  char dummy;
+};
+
+/* Language-dependent contents of a decl.  */
+
+struct GTY (()) lang_decl
+{
+  char dummy;
+};
+
+/* Language-dependent contents of an identifier.  This must include a
+   tree_identifier.  */
+
+struct GTY (()) lang_identifier
+{
+  struct tree_identifier common;
+};
+
+/* The resulting tree type.  */
+
+union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
+chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), "
+"TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN "
+"(&%h.generic)) : NULL"))) lang_tree_node
+{
+  union tree_node GTY ((tag ("0"),
+desc ("tree_node_structure (&%h)"))) generic;
+  struct lang_identifier GTY ((tag ("1"))) identifier;
+};
+
+struct GTY (()) language_function
+{
+
+  /* While we are parsing the function, this contains information about
+  the statement-tree that we are building.  */
+  /* struct stmt_tree_s stmt_tree;  */
+  tree stmt_tree;
+};
+
+/* Language hooks.  */
+
+bool
+gm2_langhook_init (void)
+{
+  build_common_tree_nodes (false);
+  build_common_builtin_nodes ();
+
+  /* The default precision for floating point numbers.  This is used
+ for floating point constants with abstract type.  This may eventually
+ be controllable by a command line option.  */
+  mpfr_set_default_prec (256);
+
+  /* GNU Modula-2 uses exceptions.  */
+  using_eh_for_cleanups ();
+  return true;
+}
+
+/* The option mask.  */
+
+static unsigned int
+gm2_langhook_option_lang_mask (void)
+{
+  return CL_ModulaX2;
+}
+
+/* Initialize the options structure.  */
+
+static void
+gm2_langhook_init_options_struct (struct gcc_options *opts)
+{
+  /* Default to avoiding range issues for complex multiply and divide.  */
+  opts->x_flag_complex_method = 2;
+
+  /* The builtin math functions should not set errno.  */
+  opts->x_flag_errno_math = 0;
+  opts->frontend_set_flag_errno_math = true;
+
+  /* Exceptions are used.  */
+  opts->x_flag_exceptions = 1;
+  init_FrontEndInit ();
+}
+
+/* Infrastructure for a VEC of bool values.  */
+
+/* This array determines whether the filename is associated with the
+   C preprocessor.  */
+
+static vec filename_cpp;
+
+void
+gm2_langhook_init_options (unsigned int decoded_options_count,
+   struct cl_decoded_option *decoded_options)
+{
+  unsigned int i;
+  bool in_cpp_args = false;
+
+  for (i = 1; i < decoded_options_count; i++)
+{
+  switch (decoded_options[i].opt_index)
+{
+case OPT_fcpp_begin:
+  in_cpp_args = true;
+  break;
+case OPT_fcpp_end:
+  in_cpp_args = false;
+  break;
+case 

[PATCH v3 14/19] modula2 front end: gimple interface remainder

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the gimple interface.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/init.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/init.cc2022-12-06 
02:56:51.344774733 +
@@ -0,0 +1,196 @@
+/* init.cc initializes the modules of the GNU Modula-2 front end.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "init.h"
+#include "config.h"
+#include "system.h"
+
+#if defined(__GNUG__)
+#define EXTERN extern "C"
+#else /* !__GNUG__  */
+#define EXTERN extern
+#endif /* !__GNUG__  */
+
+EXTERN void _M2_M2Bitset_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Debug_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Defaults_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Environment_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_RTExceptions_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2EXCEPTION_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2RTS_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Dependent_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SysExceptions_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_DynamicStrings_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Assertion_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FormatStrings_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SFIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SArgs_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Lists_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_UnixArgs_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Args_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_wrapc_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_TimeString_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_IO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_StdIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_CmdArgs_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Preprocess_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Error_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Search_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Indexing_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_NameKey_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_NumberIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FpuIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SysStorage_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_Storage_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_StrIO_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Debug_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Batch_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_StrLib_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2ALU_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Options_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Comp_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2LexBuf_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SymbolTable_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Base_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Quads_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_SymbolKey_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_FifoQueue_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Reserved_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2Const_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_P1SymBuild_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_P2SymBuild_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_P3SymBuild_init (int argc, char *argv[], char *envp[]);
+EXTERN void _M2_M2System_init (int argc, char *argv[], char *envp[]);
+EXTERN 

[PATCH v3 11/19] modula2 front end: gimple interface *[a-d]*.cc

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the gimple interface.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2assert.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2assert.cc2022-12-06 
02:56:51.344774733 +
@@ -0,0 +1,41 @@
+/* m2assert.cc provides a simple assertion for location.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "gcc-consolidation.h"
+
+#include "../gm2-lang.h"
+#include "../m2-tree.h"
+
+#define m2assert_c
+#include "m2assert.h"
+#include "m2options.h"
+
+void
+m2assert_AssertLocation (location_t location)
+{
+  /* Internally the compiler will use unknown location and
+ builtins_location so we ignore these values.  */
+  if (location == BUILTINS_LOCATION || location == UNKNOWN_LOCATION)
+return;
+
+  if (M2Options_OverrideLocation (location) != location)
+internal_error ("the location value is corrupt");
+}
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2block.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2block.cc 2022-12-06 
02:56:51.344774733 +
@@ -0,0 +1,770 @@
+/* m2block.cc provides an interface to maintaining block structures.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "gcc-consolidation.h"
+
+#define m2block_c
+#include "m2assert.h"
+#include "m2block.h"
+#include "m2decl.h"
+#include "m2options.h"
+#include "m2tree.h"
+#include "m2treelib.h"
+
+/* For each binding contour we allocate a binding_level structure
+   which records the entities defined or declared in that contour.
+   Contours include:
+
+   the global one one for each subprogram definition
+
+   Binding contours are used to create GCC tree BLOCK nodes.  */
+
+struct GTY (()) binding_level
+{
+  /* The function associated with the scope.  This is NULL_TREE for the
+ global scope.  */
+  tree fndecl;
+
+  /* A chain of _DECL nodes for all variables, constants, functions,
+ and typedef types.  These are in the reverse of the order supplied.  */
+  tree names;
+
+  /* A boolean to indicate whether this is binding level is a global ie
+ outer module scope.  In which case fndecl will be NULL_TREE.  */
+  int is_global;
+
+  /* The context of the binding level, for a function binding level
+ this will be the same as fndecl, however for a global binding level
+ this is a translation_unit.  */
+  tree context;
+
+  /* The binding level below this one.  This field is only used when
+ the binding level has been pushed by pushFunctionScope.  */
+  struct binding_level *next;
+
+  /* All binding levels are placed onto this list.  */
+  struct binding_level *list;
+
+  /* A varray of trees, which represent the list of statement
+ sequences.  */
+  vec *m2_statements;
+
+  /* A list of constants (only kept in the global binding level).
+ Constants need to be kept through the life of the compilation, as the
+ same constants can be used in any scope.  */
+  tree constants;
+
+  /* A list of inner module initialization functions.  */
+  tree init_functions;
+
+  /* A list of types created by M2GCCDeclare prior to code generation
+ and those which may not be specifically declared and saved via a
+ push_decl.  */
+  tree types;
+
+  /* A list of all DECL_EXPR created within this binding level.  This
+ will be prepended to the statement list once the binding level (scope
+ is finished).  */
+  tree decl;
+
+  /* A list of labels which have 

[PATCH v3 0/19] modula-2 front end patches overview

2022-12-06 Thread Gaius Mulley via Gcc-patches


Here are the latest modula-2 front end patches.  Since the posting in
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603161.html
I've rewritten the python3 documentation scripts (feedback from
patchset 16) and applied all the suggestions from the feedback in
patchset 15 (gm2-lang.cc).

All the patches are can also be at:
https://splendidisolation.ddns.net/public/modula2/patchsummary.html
which contains the status of the patch, their contents and testing
summary.

Thanks for the feedback - and clean up suggestions!

regards,
Gaius


Patch Summary
=

The gm2 driver program and top level makefile infrastructure

[PATCH v3] 1/19: changes outside gcc/m2, libgm2 and gcc/testsuite.
[PATCH v3] 2/19: Make-lang.in
[PATCH v3] 3/19: gm2 driver files.

The libraries /libgm2

[PATCH v3] 4/19: libgm2/libm2pim contents
[PATCH v3] 5/19: libgm2/libm2iso contents
[PATCH v3] 6/19: libgm2/libm2min contents
[PATCH v3] 7/19: libgm2/libm2log contents
[PATCH v3] 8/19: libgm2 contents

Modula-2 plugin

[PATCH v3] 9/19: plugin source files

Modula-2 to gimple interface

[PATCH v3] 10/19: gimple interface header files *.h and *.def
[PATCH v3] 11/19: gimple interface *[a-d]*.cc
[PATCH v3] 12/19: gimple interface *[e-f]*.cc
[PATCH v3] 13/19: gimple interface *[g-m]*.cc
[PATCH v3] 14/19: gimple interface remainder

Lexical analysis (flex), lang hooks and debug tree module

[PATCH v3] 15/19: cc1gm2 additional non modula2 source files

Linking bootstrap tool and documentation build script

[PATCH v3] 16/19: bootstrap and documentation tools

Testsuite and remaining files

[PATCH v3] 17/19: dejagnu expect library scripts.

[PATCH v3] 18/19: remainder of the files for the compiler and libraries.  (not 
posted)
[PATCH v3] 19/19: modula2 testsuite.  (not posted)


[PATCH v3 13/19] modula2 front end: gimple interface *[g-m]*.cc

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the gimple interface.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2linemap.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2linemap.cc   2022-12-06 
02:56:51.344774733 +
@@ -0,0 +1,254 @@
+/* m2linemap.cc provides an interface to GCC linemaps.
+
+Copyright (C) 2012-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "gcc-consolidation.h"
+
+/* Utilize some of the C build routines */
+
+#include "../gm2-lang.h"
+#include "../m2-tree.h"
+
+#include "m2assert.h"
+#include "m2block.h"
+#include "m2decl.h"
+#include "m2expr.h"
+#include "m2options.h"
+#include "m2tree.h"
+#include "m2type.h"
+#define m2linemap_c
+#include "m2linemap.h"
+
+static int inFile = FALSE;
+
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
+/* Start getting locations from a new file.  */
+
+EXTERN
+void
+m2linemap_StartFile (void *filename, unsigned int linebegin)
+{
+  if (inFile)
+m2linemap_EndFile ();
+  linemap_add (line_table, LC_ENTER, false,
+   xstrdup (reinterpret_cast (filename)), linebegin);
+  inFile = TRUE;
+}
+
+/* Tell the line table the file has ended.  */
+
+EXTERN
+void
+m2linemap_EndFile (void)
+{
+  linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
+  inFile = FALSE;
+}
+
+/* Indicate that there is a new source file line number with a
+   maximum width.  */
+
+EXTERN
+void
+m2linemap_StartLine (unsigned int linenumber, unsigned int linesize)
+{
+  linemap_line_start (line_table, linenumber, linesize);
+}
+
+/* GetLocationColumn, returns a location_t based on the current line
+   number and column.  */
+
+EXTERN
+location_t
+m2linemap_GetLocationColumn (unsigned int column)
+{
+  return linemap_position_for_column (line_table, column);
+}
+
+/* GetLocationRange, returns a location based on the start column
+   and end column.  */
+
+EXTERN
+location_t
+m2linemap_GetLocationRange (unsigned int start, unsigned int end)
+{
+  location_t caret = m2linemap_GetLocationColumn (start);
+
+  source_range where;
+  where.m_start = linemap_position_for_column (line_table, start);
+  where.m_finish = linemap_position_for_column (line_table, end);
+  return make_location (caret, where);
+}
+
+
+static
+int
+isSrcLocation (location_t location)
+{
+  return (location != BUILTINS_LOCATION) && (location != UNKNOWN_LOCATION);
+}
+
+
+/* GetLocationBinary, returns a location based on the expression
+   start caret finish locations.  */
+
+EXTERN
+location_t
+m2linemap_GetLocationBinary (location_t caret, location_t start, location_t 
finish)
+{
+  if (isSrcLocation (start) && isSrcLocation (finish) && isSrcLocation (caret)
+&& (m2linemap_GetFilenameFromLocation (start) != NULL))
+{
+  linemap_add (line_table, LC_ENTER, false, xstrdup 
(m2linemap_GetFilenameFromLocation (start)), 1);
+  gcc_assert (inFile);
+  location_t location = make_location (caret, start, finish);
+  return location;
+}
+  return caret;
+}
+
+/* GetLineNoFromLocation - returns the lineno given a location.  */
+
+EXTERN
+int
+m2linemap_GetLineNoFromLocation (location_t location)
+{
+  if (isSrcLocation (location) && (!M2Options_GetCpp ()))
+{
+  expanded_location xl = expand_location (location);
+  return xl.line;
+}
+  return 0;
+}
+
+/* GetColumnNoFromLocation - returns the columnno given a location.  */
+
+EXTERN
+int
+m2linemap_GetColumnNoFromLocation (location_t location)
+{
+  if (isSrcLocation (location) && (!M2Options_GetCpp ()))
+{
+  expanded_location xl = expand_location (location);
+  return xl.column;
+}
+  return 0;
+}
+
+/* GetFilenameFromLocation - returns the filename given a location.  */
+
+EXTERN
+const char *
+m2linemap_GetFilenameFromLocation (location_t location)
+{
+  if (isSrcLocation (location) && (!M2Options_GetCpp ()))
+{
+  expanded_location xl = expand_location (location);
+  return xl.file;
+}
+  return NULL;
+}
+
+/* ErrorAt - issue an error message.  */
+
+EXTERN
+void
+m2linemap_ErrorAt (location_t location, char *message)
+{
+  error_at (location, message);
+}
+
+/* m2linemap_ErrorAtf - wraps up an error message.  */
+
+void
+m2linemap_ErrorAtf 

[PATCH v3 16/19] modula2 front end: bootstrap and documentation tools

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

Hi Martin,
here is the revised patch having applied all previous recommendations:
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603436.html.
Is this ok now?  Thanks for the improvement suggestions.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/mli...@suse.cz
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-12-06 
02:56:51.380775219 +
@@ -0,0 +1,166 @@
+#!/usr/bin/env python3
+
+# utility to tidy dates and detect lack of copyright.
+
+# Copyright (C) 2016-2022 Free Software Foundation, Inc.
+#
+# This file is part of GNU Modula-2.
+#
+# GNU Modula-2 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.
+#
+# GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+import os
+import sys
+import pathlib
+import shutil
+
+max_line_length = 60
+
+COPYRIGHT = 'Copyright (C)'
+
+
+def visit_dir(directory, ext, func):
+# visit_dir - call func for each file below, dir, matching extension, ext.
+list_of_files = os.listdir(directory)
+list_of_files.sort()
+for filename in list_of_files:
+path = pathlib.PurePath(filename)
+full = os.path.join(directory, filename)
+if path.is_file(full):
+if path.suffix == ext:
+func(full)
+elif path.is_dir(full):
+visit_dir(full, ext, func)
+
+
+def is_year(year):
+# is_year - returns True if, year, is legal.
+if len(year) == 5:
+year = year[:-1]
+for c in year:
+if not c.isdigit():
+return False
+return True
+
+
+def handle_copyright(outfile, lines, n, leader1, leader2):
+# handle_copyright look for Copyright in the comment.
+global max_line_length
+i = lines[n]
+c = i.find(COPYRIGHT)+len(COPYRIGHT)
+outfile.write(i[:c])
+d = i[c:].split()
+start = c
+seen_date = True
+years = []
+while seen_date:
+if d == []:
+n += 1
+i = lines[n]
+d = i[2:].split()
+else:
+e = d[0]
+punctuation = ''
+if len(d) == 1:
+d = []
+else:
+d = d[1:]
+if c > max_line_length:
+outfile.write('\n')
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(' '*(start-2))
+c = start
+if is_year(e):
+if (e[-1] == '.') or (e[-1] == ','):
+punctuation = e[-1]
+e = e[:-1]
+else:
+punctuation = ''
+else:
+seen_date = False
+if seen_date:
+if not (e in years):
+c += len(e) + len(punctuation)
+outfile.write(' ')
+outfile.write(e)
+outfile.write(punctuation)
+years += [e]
+else:
+if start < c:
+outfile.write('\n')
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(' '*(start-2))
+
+outfile.write(' ')
+outfile.write(e)
+outfile.write(punctuation)
+for w in d:
+outfile.write(' ')
+outfile.write(w)
+outfile.write('\n')
+return outfile, n+1
+
+
+def handle_header(filename, leader1, leader2):
+# handle_header reads in the header of a file and inserts
+# a line break around the Copyright dates.
+print('--')
+lines = open(filename).readlines()
+if len(lines) > 20:
+with open('tmptidy', 'w') as outfile:
+n = 0
+for i in lines:
+if i.find('Copyright (C)') >= 0:
+outfile, n = handle_copyright(outfile, lines,
+ n, leader1, leader2)
+outfile.writelines(lines[n:])
+outfile.close()
+print('-> mv tmptidy', filename)
+shutil.move('tmptidy', filename)
+return
+else:
+ 

[PATCH v3 2/19] modula2 front end: Make-lang.in

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

The makefile fragment for modula2 which builds the gm2 driver and cc1gm2.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/Make-lang.in
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/Make-lang.in   2022-12-06 02:56:51.328774517 
+
@@ -0,0 +1,1649 @@
+# Top level -*- makefile -*- fragment for GNU M2.
+
+# Copyright (C) 2000-2022 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
+#.
+
+# Actual names to use when installing a native compiler.
+GM2_INSTALL_NAME = $(shell echo gm2|sed '$(program_transform_name)')
+GM2_TARGET_INSTALL_NAME = $(target_noncanonical)-$(shell echo gm2|sed 
'$(program_transform_name)')
+
+# Actual names to use when installing a cross-compiler.
+GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`
+
+M2_MAINTAINER = no
+
+GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
+
+GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
-L$(objdir)/../ld $(TFLAGS)
+
+TEXISRC = $(objdir)/m2/images/gnu.eps \
+  $(srcdir)/doc/gm2.texi \
+  m2/gm2-libs.texi \
+  m2/gm2-ebnf.texi \
+  m2/SYSTEM-pim.texi \
+  m2/SYSTEM-iso.texi \
+  m2/Builtins.texi
+
+RSTSRC = $(objdir)/m2/images/gnu.eps \
+  $(srcdir)/doc/gm2.texi \
+  m2/gm2-libs.rst \
+  m2/gm2-ebnf.rst \
+  m2/SYSTEM-pim.rst \
+  m2/SYSTEM-iso.rst \
+  m2/Builtins.rst
+
+# Define the names for selecting modula-2 in LANGUAGES.
+m2 modula-2 modula2: gm2$(exeext) xgcc$(exeext) cc1gm2$(exeext) \
+ $(GCC_PASSES) $(GCC_PARTS)
+m2.serial = cc1gm2$(exeext)
+
+# Tell GNU make to ignore these if they exist.
+.PHONY: m2 modula-2 modula2
+
+GM2_PROG_DEP=gm2$(exeext) xgcc$(exeext) cc1gm2$(exeext)
+
+include m2/config-make
+
+LIBSTDCXX=../$(TARGET_SUBDIR)/libstdc++-v3/src/.libs/libstdc++.a
+
+PGE=m2/pge$(exeext)
+
+SRC_PREFIX=G
+
+m2/gm2spec.o: $(srcdir)/m2/gm2spec.cc $(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
+   m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
+   $(generated_files) $(C_TREE_H) insn-attr-common.h
+   (SHLIB_LINK='$(SHLIB_LINK)' \
+   SHLIB_MULTILIB='$(SHLIB_MULTILIB)'; \
+   $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+ $(DRIVER_DEFINES) \
+   -DLIBSUBDIR=\"$(libsubdir)\" \
+-DPREFIX=\"$(prefix)\" \
+-c $(srcdir)/m2/gm2spec.cc $(OUTPUT_OPTION))
+
+# Create the compiler driver for M2.
+CFLAGS-m2/m2/gm2spec.o += $(DRIVER_DEFINES)
+
+GM2_OBJS = $(GCC_OBJS) prefix.o intl.o m2/gm2spec.o
+
+# Create the compiler driver for gm2.
+gm2$(exeext): $(GM2_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS) \
+m2/gm2config.h
+   +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+ $(GM2_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
+ $(EXTRA_GCC_LIBS) $(LIBS)
+
+# Create a version of the gm2 driver which calls the cross-compiler.
+gm2-cross$(exeext): gm2$(exeext)
+   -rm -f gm2-cross$(exeext)
+   cp gm2$(exeext) gm2-cross$(exeext)
+
+po-generated:
+
+# Build hooks:
+
+m2.all.cross: gm2-cross$(exeext) plugin/m2rte$(exeext).so
+
+m2.start.encap: gm2$(exeext) plugin/m2rte$(exeext).so
+m2.rest.encap:
+
+
+m2.info: doc/m2.info
+
+m2.man: doc/m2.1
+
+m2.install-man: $(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext)
+
+$(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext): doc/m2.1 installdirs
+   -rm -f $@
+   -$(INSTALL_DATA) $< $@
+   -chmod a-x $@
+
+m2.dvi: $(TEXISRC)
+   $(TEXI2DVI) -I $(objdir)/m2 -I $(srcdir)/doc/include 
$(srcdir)/doc/gm2.texi -o $@
+
+m2.ps: m2.dvi
+   dvips -o $@ $<
+
+m2.pdf: m2.ps
+   gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$@ $<
+
+.INTERMEDIATE: gm2.pod
+
+m2.pod: doc/gm2.texi $(TEXISRC)
+   -$(TEXI2POD) -I $(objdir)/m2 -D m2 < $< > $@
+
+doc/m2.info: $(TEXISRC)
+   if test "x$(BUILD_INFO)" = xinfo; then \
+ rm -f doc/m2.info*; \
+  $(MAKEINFO) -I$(objdir)/m2 -I$(srcdir)/doc/include \
+  -o $@ $(srcdir)/doc/gm2.texi ; \
+   else true; fi
+
+$(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
+   test -d m2/images || mkdir -p m2/images
+   if [ -f $(srcdir)/m2/images/gnu.eps ] ; then \
+   cp $(srcdir)/m2/images/gnu.eps $@ ; \
+else 

[PATCH v3 15/19] modula2 front end: cc1gm2 additional non modula2 source files

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set contains the .h, .cc and .flex files found in
gcc/m2.  The files are tightly coupled with the gimple interface
(see 04-gimple-interface) and built using the rules found in
(01-03-make).

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-lang.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-lang.cc2022-12-06 02:57:10.909039217 
+
@@ -0,0 +1,887 @@
+/* gm2-lang.cc language-dependent hooks for GNU Modula-2.
+
+Copyright (C) 2002-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
+
+#include "gm2-gcc/gcc-consolidation.h"
+
+#include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name.  */
+#include "tree-pass.h" /* FIXME: only for PROP_gimple_any.  */
+#include "toplev.h"
+#include "debug.h"
+
+#include "opts.h"
+
+#define GM2_LANG_C
+#include "gm2-lang.h"
+#include "m2block.h"
+#include "dynamicstrings.h"
+#include "m2options.h"
+#include "m2convert.h"
+#include "m2linemap.h"
+#include "init.h"
+#include "m2-tree.h"
+#include "convert.h"
+#include "rtegraph.h"
+
+static void write_globals (void);
+
+static int insideCppArgs = FALSE;
+
+#define EXPR_STMT_EXPR(NODE) TREE_OPERAND (EXPR_STMT_CHECK (NODE), 0)
+
+/* start of new stuff.  */
+
+/* Language-dependent contents of a type.  */
+
+struct GTY (()) lang_type
+{
+  char dummy;
+};
+
+/* Language-dependent contents of a decl.  */
+
+struct GTY (()) lang_decl
+{
+  char dummy;
+};
+
+/* Language-dependent contents of an identifier.  This must include a
+   tree_identifier.  */
+
+struct GTY (()) lang_identifier
+{
+  struct tree_identifier common;
+};
+
+/* The resulting tree type.  */
+
+union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
+chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), "
+"TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN "
+"(&%h.generic)) : NULL"))) lang_tree_node
+{
+  union tree_node GTY ((tag ("0"),
+desc ("tree_node_structure (&%h)"))) generic;
+  struct lang_identifier GTY ((tag ("1"))) identifier;
+};
+
+struct GTY (()) language_function
+{
+
+  /* While we are parsing the function, this contains information about
+  the statement-tree that we are building.  */
+  /* struct stmt_tree_s stmt_tree;  */
+  tree stmt_tree;
+};
+
+/* Language hooks.  */
+
+bool
+gm2_langhook_init (void)
+{
+  build_common_tree_nodes (false);
+  build_common_builtin_nodes ();
+
+  /* The default precision for floating point numbers.  This is used
+ for floating point constants with abstract type.  This may eventually
+ be controllable by a command line option.  */
+  mpfr_set_default_prec (256);
+
+  /* GNU Modula-2 uses exceptions.  */
+  using_eh_for_cleanups ();
+  return true;
+}
+
+/* The option mask.  */
+
+static unsigned int
+gm2_langhook_option_lang_mask (void)
+{
+  return CL_ModulaX2;
+}
+
+/* Initialize the options structure.  */
+
+static void
+gm2_langhook_init_options_struct (struct gcc_options *opts)
+{
+  /* Default to avoiding range issues for complex multiply and divide.  */
+  opts->x_flag_complex_method = 2;
+
+  /* The builtin math functions should not set errno.  */
+  opts->x_flag_errno_math = 0;
+  opts->frontend_set_flag_errno_math = true;
+
+  /* Exceptions are used.  */
+  opts->x_flag_exceptions = 1;
+  init_FrontEndInit ();
+}
+
+/* Infrastructure for a VEC of bool values.  */
+
+/* This array determines whether the filename is associated with the
+   C preprocessor.  */
+
+static vec filename_cpp;
+
+void
+gm2_langhook_init_options (unsigned int decoded_options_count,
+   struct cl_decoded_option *decoded_options)
+{
+  unsigned int i;
+  bool in_cpp_args = false;
+
+  for (i = 1; i < decoded_options_count; i++)
+{
+  switch (decoded_options[i].opt_index)
+{
+case OPT_fcpp_begin:
+  in_cpp_args = true;
+  break;
+case OPT_fcpp_end:
+  in_cpp_args = false;
+  break;
+case OPT_SPECIAL_input_file:
+case OPT_SPECIAL_program_name:
+  filename_cpp.safe_push (in_cpp_args);
+}
+}
+  

[PATCH v3 4/19] modula2 front end: libgm2/libm2pim contents

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf sources necessary
to build the various libgm2/libm2pim libraries.  The c/c++/h files
are included in the patch set.  The modula-2 sources are found in
gcc/m2/ as they are used by the compiler.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2pim/target.c
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2pim/target.c  2022-12-06 
02:56:51.432775922 +
@@ -0,0 +1,61 @@
+/* target.c provide access to miscellaneous math functions.
+
+Copyright (C) 2005-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include 
+
+#if defined(HAVE_MATH_H)
+#include 
+#endif
+
+#if !defined(HAVE_EXP10)
+#if defined(M_LN10)
+double
+exp10 (double x)
+{
+  return exp (x * M_LN10);
+}
+#endif
+#endif
+
+#if !defined(HAVE_EXP10F)
+#if defined(M_LN10)
+float
+exp10f (float x)
+{
+  return expf (x * M_LN10);
+}
+#endif
+#endif
+
+#if !defined(HAVE_EXP10L)
+#if defined(M_LN10)
+long double
+exp10l (long double x)
+{
+  return expl (x * M_LN10);
+}
+#endif
+#endif
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2pim/Selective.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2pim/Selective.cc  2022-12-06 
02:56:51.432775922 +
@@ -0,0 +1,319 @@
+/* Selective.c provide access to timeval and select.
+
+Copyright (C) 2009-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include 
+#include 
+
+#if defined(HAVE_STDDEF_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_STDIO_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_SYS_TIME_H)
+#include 
+#endif
+
+#if defined(HAVE_TIME_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_STRING_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_WCHAR_H)
+/* Obtain a definition for NULL.  */
+#include 
+#endif
+
+#if defined(HAVE_STDLIB_H)
+/* Obtain a prototype for free and malloc.  */
+#include 
+#endif
+
+#if defined(HAVE_SYS_TYPES_H)
+#include 
+#endif
+
+#if defined(HAVE_UNISTD_H)
+#include 
+#endif
+
+#if !defined(NULL)
+#define NULL (void *)0
+#endif
+
+#if defined(HAVE_SELECT)
+#define FDSET_T fd_set
+#else
+#define FDSET_T void
+#endif
+
+/* Select wrap a call to the C select.  */
+
+#if defined(HAVE_STRUCT_TIMEVAL)
+extern "C" int
+Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds,
+  fd_set *exceptfds, struct timeval *timeout)
+{
+  return select (nooffds, readfds, writefds, exceptfds, timeout);
+}
+#else
+extern "C" int
+Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
+  void *timeout)
+{
+  return 0;
+}
+#endif
+
+/* InitTime initializes a timeval structure and returns a pointer to it.  */
+
+#if defined(HAVE_STRUCT_TIMEVAL)
+extern "C" struct timeval *
+Selective_InitTime (unsigned int sec, unsigned int usec)
+{
+  struct timeval *t = (struct timeval *)malloc (sizeof 

[PATCH v3 17/19] modula2 front end: dejagnu expect library scripts

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

Here are the dejagnu expect library scripts for the gm2
testsuite.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/testsuite/lib/gm2.exp
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/testsuite/lib/gm2.exp 2022-12-06 
02:56:51.424775814 +
@@ -0,0 +1,498 @@
+# Copyright (C) 2003-2020 Free Software Foundation, Inc.
+
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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
+# .
+
+# This file was written by Gaius Mulley (gaius.mul...@southwales.ac.uk)
+# for GNU Modula-2.
+
+# we want to use libgloss so we can get find_gcc.
+load_lib libgloss.exp
+load_lib prune.exp
+load_lib gcc-defs.exp
+load_lib target-libpath.exp
+
+
+#
+# GCC_UNDER_TEST is the compiler under test.
+#
+
+#
+# default_gcc_version -- extract and print the version number of the compiler
+#
+
+proc default_gcc_version { } {
+global GCC_UNDER_TEST
+
+gm2_init;
+
+# ignore any arguments after the command
+set compiler [lindex $GCC_UNDER_TEST 0]
+
+if ![is_remote host] {
+   set compiler_name [which $compiler];
+} else {
+   set compiler_name $compiler;
+}
+
+# verify that the compiler exists
+if { $compiler_name != 0 } then {
+   set tmp [remote_exec host "$compiler --version"]
+   set status [lindex $tmp 0];
+   set output [lindex $tmp 1];
+   regexp "version.*$" $output version
+   if { $status == 0 && [info exists version] } then {
+   clone_output "$compiler_name $version\n"
+   } else {
+   clone_output "Couldn't determine version of $compiler_name: 
$output\n"
+   }
+} else {
+   # compiler does not exist (this should have already been detected)
+   warning "$compiler does not exist"
+}
+}
+
+#
+# gcc_version -- Call default_gcc_version, so we can override it if needed.
+#
+
+proc gcc_version { } {
+default_gcc_version;
+}
+
+#
+# gm2_init -- called at the start of each .exp script.
+#
+# There currently isn't much to do, but always using it allows us to
+# make some enhancements without having to go back and rewrite the scripts.
+#
+
+set gm2_initialized 0;
+set gm2_compile_method "default";
+set gm2_link_path "";
+set gm2_link_libraries "m2pim m2iso";
+set gm2_link_objects "";
+
+proc gm2_set_compile_method { arg } {
+global gm2_compile_method;
+
+send_log "\n"
+send_log " setting gm2_compile_method to $arg \n"
+send_log "\n"
+set gm2_compile_method $arg;
+}
+
+
+proc gm2_init { args } {
+global tmpdir;
+global objdir;
+global rootme;
+global base_dir;
+global tool_root_dir;
+global gluefile wrap_flags;
+global gm2_initialized;
+global GCC_UNDER_TEST;
+global TOOL_EXECUTABLE;
+global gm2_link_libraries;
+global gm2_link_objects;
+global gm2_link_path;
+global HAVE_LIBSTDCXX_V3;
+
+if { $gm2_initialized == 1 } { return; }
+
+set gm2_link_objects "";
+set GCC_UNDER_TEST [lookfor_file $rootme gm2];
+append GCC_UNDER_TEST " " -B[file dirname $rootme]/gcc " " ${args};
+append GCC_UNDER_TEST " " -fno-diagnostics-show-caret
+append GCC_UNDER_TEST " " -fno-diagnostics-show-line-numbers
+append GCC_UNDER_TEST " " -fdiagnostics-color=never
+send_log "GCC_UNDER_TEST is ${GCC_UNDER_TEST}\n"
+
+if ![info exists tmpdir] then {
+   set tmpdir /tmp;
+}
+if {[target_info needs_status_wrapper] != "" && \
+   [target_info needs_status_wrapper] != "0" && \
+   ![info exists gluefile]} {
+   set gluefile ${tmpdir}/gcc-testglue.o;
+   set result [build_wrapper $gluefile];
+   if { $result != "" } {
+   set gluefile [lindex $result 0];
+   set wrap_flags [lindex $result 1];
+   } else {
+   unset gluefile
+   }
+}
+
+set gm2_link_path "[gm2_link_flags [get_multilibs]]";
+verbose $gm2_link_path 1
+}
+
+#
+# gm2_target_compile_default -- compile a source file
+#
+
+proc gm2_target_compile_default { source dest type options } {
+global gluefile wrap_flags
+global GCC_UNDER_TEST
+global TOOL_OPTIONS
+global TEST_ALWAYS_FLAGS
+global gm2_link_objects
+global gm2_link_libraries
+global gm2_link_path
+
+if {[target_info 

[PATCH v3 3/19] modula2 front end: gm2 driver files.

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the c++, h and option related files necessary
to build the driver program gm2.  The patch also consists of the
autoconf/configure related build infastructure sources found in
gcc/m2.  The reviewer might need to look at the 01-02-make patchset.
The gm2 driver is heavily based on the fortran driver, it also adds
the c++ libraries and modula-2 search paths and libraries depending
upon dialect for user convenience.  Users could link modula-2 objects
using g++ if they supply the include and link paths.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2spec.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2spec.cc 2022-12-06 02:56:51.360774949 
+
@@ -0,0 +1,946 @@
+/* gm2spec.cc specific flags and argument handling within GNU Modula-2.
+
+Copyright (C) 2007-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "xregex.h"
+#include "obstack.h"
+#include "intl.h"
+#include "prefix.h"
+#include "opt-suggestions.h"
+#include "gcc.h"
+#include "opts.h"
+#include "vec.h"
+
+#include "m2/gm2config.h"
+
+#ifdef HAVE_DIRENT_H
+#include 
+#else
+#ifdef HAVE_SYS_NDIR_H
+#include 
+#endif
+#ifdef HAVE_SYS_DIR_H
+#include 
+#endif
+#ifdef HAVE_NDIR_H
+#include 
+#endif
+#endif
+
+/* This bit is set if we saw a `-xfoo' language specification.  */
+#define LANGSPEC   (1<<1)
+/* This bit is set if they did `-lm' or `-lmath'.  */
+#define MATHLIB(1<<2)
+/* This bit is set if they did `-lc'.  */
+#define WITHLIBC   (1<<3)
+/* Skip this option.  */
+#define SKIPOPT(1<<4)
+
+#ifndef MATH_LIBRARY
+#define MATH_LIBRARY "m"
+#endif
+#ifndef MATH_LIBRARY_PROFILE
+#define MATH_LIBRARY_PROFILE MATH_LIBRARY
+#endif
+
+#ifndef LIBSTDCXX
+#define LIBSTDCXX "stdc++"
+#endif
+#ifndef LIBSTDCXX_PROFILE
+#define LIBSTDCXX_PROFILE LIBSTDCXX
+#endif
+#ifndef LIBSTDCXX_STATIC
+#define LIBSTDCXX_STATIC NULL
+#endif
+
+#ifndef LIBCXX
+#define LIBCXX "c++"
+#endif
+#ifndef LIBCXX_PROFILE
+#define LIBCXX_PROFILE LIBCXX
+#endif
+#ifndef LIBCXX_STATIC
+#define LIBCXX_STATIC NULL
+#endif
+
+#ifndef LIBCXXABI
+#define LIBCXXABI "c++abi"
+#endif
+#ifndef LIBCXXABI_PROFILE
+#define LIBCXXABI_PROFILE LIBCXXABI
+#endif
+#ifndef LIBCXXABI_STATIC
+#define LIBCXXABI_STATIC NULL
+#endif
+
+/* The values used here must match those of the stdlib_kind enumeration
+   in c.opt.  */
+enum stdcxxlib_kind
+{
+  USE_LIBSTDCXX = 1,
+  USE_LIBCXX = 2
+};
+
+#define DEFAULT_DIALECT "pim"
+#undef DEBUG_ARG
+
+typedef enum { iso, pim, min, logitech, pimcoroutine, maxlib } libs;
+
+/* These are the library names which are installed as part of gm2 and reflect
+   -flibs=name.  The -flibs= option provides the user with a short cut to add
+   libraries without having to know the include and link path.  */
+
+static const char *library_name[maxlib]
+= { "m2iso", "m2pim", "m2min", "m2log", "m2cor" };
+
+/* They match the installed archive name for example libm2iso.a,
+   libm2pim.a, libm2min.a, libm2log.a and libm2cor.a.  They also match a
+   subdirectory name where the definition modules are kept.  The driver
+   checks the argument to -flibs= for an entry in library_name or
+   alternatively the existance of the subdirectory (to allow for third
+   party libraries to coexist).  */
+
+static const char *library_abbrev[maxlib]
+= { "iso", "pim", "min", "log", "cor" };
+
+/* Users may specifiy -flibs=pim,iso etc which are mapped onto
+   -flibs=m2pim,m2iso respectively.  This provides a match between
+   the dialect of Modula-2 and the library set.  */
+
+static const char *add_include (const char *libpath, const char *library);
+
+static bool seen_scaffold_static = false;
+static bool seen_scaffold_dynamic = false;
+static bool scaffold_static = false;
+static bool scaffold_dynamic = true;  // Default uses -fscaffold-dynamic.
+static bool seen_gen_module_list = false;
+static bool seen_uselist = false;
+static bool uselist = false;
+static bool gen_module_list = true;  // Default uses -fgen-module-list=-.
+static const char *gen_module_filename = "-";
+static const char *multilib_dir = NULL;
+/* The original 

[PATCH v3 8/19] modula2 front end: libgm2 contents

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the libgm2 makefile, autoconf sources
necessary to build the libm2pim, libm2iso, libm2min, libm2cor
and libm2log.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/ChangeLog
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/ChangeLog  2022-12-06 02:56:51.428775868 
+
@@ -0,0 +1,506 @@
+2022-05-18  Gaius Mulley  
+
+   * Corrected dates on all source files.
+   * libm2pim/Selective.c: Reformatted comments.
+   * libm2pim/SysExceptions.c: Reformatted comments.
+   * libm2pim/dtoa.c: Reformatted comments.
+   * libm2pim/ldtoa.c: Reformatted comments.
+   * libm2pim/sckt.c: Reformatted comments.
+   * libm2pim/termios.c: Reformatted comments.
+   * libm2pim/wrapc.c: Reformatted comments.
+   * libm2pim/termios.c: Reformatted comments within enum.
+   * libm2pim/Selective.c: Correct spelling.
+   * libm2pim/termios.c: Use GNU comment formatting.
+
+2022-05-17  Gaius Mulley  
+
+   * Corrected dates on all source files.
+
+2022-03-02  Gaius Mulley  
+
+   * libm2pim/sckt.c (tcpServerEstablishPort): Corrected spelling.
+   (tcpServerEstablish) Corrected spelling.
+
+2021-06-27  Gaius Mulley  
+
+   * Makefile.am: renamed getopt.c to cgetopt.c.
+
+2021-05-29  Gaius Mulley  
+
+   * Makefile.in: (rebuilt).
+   * aclocal.m4: (rebuilt).
+   * configure: (rebuilt).
+   * configure.ac: tidied up messages.  Removed android
+   from the list of supported hosts.  Corrected a comment
+   * libm2pim/Makefile.am: Conditionally build.
+   * libm2cor/Makefile.am: Conditionally build.
+   * libm2log/Makefile.am: Conditionally build.
+   * libm2iso/Makefile.am: Conditionally build.
+   * libm2cor/Makefile.in: (Rebuilt).
+   * libm2iso/Makefile.in: (Rebuilt).
+   * libm2log/Makefile.in: (Rebuilt).
+   * libm2min/Makefile.in: (Rebuilt).
+   * libm2pim/Makefile.in: (Rebuilt).
+
+2021-05-28  Gaius Mulley  
+
+   * Makefile.in: (Rebuilt).
+   * aclocal.m4: (Rebuilt).
+   * configure: (Rebuilt).
+   * configure.ac: Introduce checks for supported host
+   operating system and also known detect target architectures
+   which are currently restricted to minimal runtime libraries.
+   * libm2cor/Makefile.in: (Rebuilt).
+   * libm2iso/Makefile.in: (Rebuilt).
+   * libm2log/Makefile.in: (Rebuilt).
+   * libm2min/Makefile.in: (Rebuilt).
+   * libm2pim/Makefile.in: (Rebuilt).
+
+2021-02-12  Gaius Mulley  
+
+   * libm2iso/RTco.c: (threadSem) new declaration
+and implmentation of thread semaphores used internally by
+the m2 runtime system.
+
+2021-01-13  Gaius Mulley  
+
+   * Makefile.am: Updated dates.
+   * aclocal.m4: (Rebuilt).
+   * autogen.sh: Updated dates.
+   * configure: (Rebuilt).
+   * configure.ac: Updated dates.
+   * libm2cor/KeyBoardLEDs.c: Updated dates.
+   * libm2cor/Makefile.am: Updated dates.
+   * libm2iso/ChanConsts.h: Updated dates.
+   * libm2iso/ErrnoCategory.c: Updated dates.
+   * libm2iso/Makefile.am: Updated dates.
+   * libm2iso/RTco.c: Updated dates.
+   * libm2iso/wrapsock.c: Updated dates.
+   * libm2iso/wraptime.c: Updated dates.
+   * libm2log/Break.c: Updated dates.
+   * libm2log/Makefile.am: Updated dates.
+   * libm2min/Makefile.am: Updated dates.
+   * libm2min/libc.c: Updated dates.
+   * libm2pim/Makefile.am: Updated dates.
+   * libm2pim/Selective.c: Updated dates.
+   * libm2pim/SysExceptions.c: Updated dates.
+   * libm2pim/UnixArgs.c: Updated dates.
+   * libm2pim/dtoa.c: Updated dates.
+   * libm2pim/errno.c: Updated dates.
+   * libm2pim/getopt.c: Updated dates.
+   * libm2pim/ldtoa.c: Updated dates.
+   * libm2pim/sckt.c: Updated dates.
+   * libm2pim/target.c: Updated dates.
+   * libm2pim/termios.c: Updated dates.
+   * libm2pim/wrapc.c: Updated dates.
+
+2020-11-20  Gaius Mulley  
+
+   * Makefile.in: (Rebuilt).
+   * aclocal.m4: (Rebuilt).
+   * configure: (Rebuilt).
+   * configure.ac: (libtool_VERSION=17.0.0)
+
+2020-06-18  Gaius Mulley  
+
+   * Makefile.in: (Rebuilt).
+   * aclocal.m4: (Rebuilt).
+   * autogen.sh: Execute automake including dependencies.
+   * configure: (Rebuilt).
+   * libm2cor/Makefile.in: (Rebuilt).
+   * libm2iso/Makefile.in: (Rebuilt).
+   * libm2log/Makefile.am: SYSTEM.def is a dependency using
+ BUILT_SOURCES.
+   * libm2log/Makefile.in: (Rebuilt).
+   * libm2min/Makefile.in: (Rebuilt).
+   * libm2pim/Makefile.in: (Rebuilt).
+
+2020-06-15  Gaius Mulley  
+
+   * libm2pim/Makefile.am: Added SYSTEM.def as a dependency.
+   * libm2log/Makefile.am: Added SYSTEM.def as a dependency.
+
+2020-06-11  Matthias Klose  
+
+   * Makefile.am: Reordered 

[PATCH v3 1/19] modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite.

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set contains the non machine generated changes found in /
for example the language die and documentation changes.  It also
contains the changes to the top level build Makefile infastructure
and the install.texi sourcebuild.texi documentation.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw gcc-git-master/configure.ac gcc-git-devel-modula2/configure.ac
--- gcc-git-master/configure.ac 2022-12-06 02:56:41.628643384 +
+++ gcc-git-devel-modula2/configure.ac  2022-12-06 02:56:51.240773327 +
@@ -140,7 +140,7 @@
 # binutils, gas and ld appear in that order because it makes sense to run
 # "make check" in that particular order.
 # If --enable-gold is used, "gold" may replace "ld".
-host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gotools c++tools"
+host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gm2tools gotools c++tools"
 
 # these libraries are built for the target environment, and are built after
 # the host libraries and the host tools (which may be a cross compiler)
@@ -161,6 +161,7 @@
target-libffi \
target-libobjc \
target-libada \
+   target-libgm2 \
target-libgo \
target-libphobos \
target-zlib"
@@ -464,6 +465,14 @@
   noconfigdirs="$noconfigdirs gnattools"
 fi
 
+AC_ARG_ENABLE(libgm2,
+[AS_HELP_STRING([--enable-libgm2], [build libgm2 directory])],
+ENABLE_LIBGM2=$enableval,
+ENABLE_LIBGM2=no)
+if test "${ENABLE_LIBGM2}" != "yes" ; then
+  noconfigdirs="$noconfigdirs gm2tools"
+fi
+
 AC_ARG_ENABLE(libssp,
 [AS_HELP_STRING([--enable-libssp], [build libssp directory])],
 ENABLE_LIBSSP=$enableval,
@@ -3569,6 +3578,7 @@
 NCN_STRICT_CHECK_TARGET_TOOLS(GFORTRAN_FOR_TARGET, gfortran)
 NCN_STRICT_CHECK_TARGET_TOOLS(GOC_FOR_TARGET, gccgo)
 NCN_STRICT_CHECK_TARGET_TOOLS(GDC_FOR_TARGET, gdc)
+NCN_STRICT_CHECK_TARGET_TOOLS(GM2_FOR_TARGET, gm2)
 
 ACX_CHECK_INSTALLED_TARGET_TOOL(AR_FOR_TARGET, ar)
 ACX_CHECK_INSTALLED_TARGET_TOOL(AS_FOR_TARGET, as)
@@ -3607,6 +3617,8 @@
[gcc/gccgo -B$$r/$(HOST_SUBDIR)/gcc/], go)
 GCC_TARGET_TOOL(gdc, GDC_FOR_TARGET, GDC,
[gcc/gdc -B$$r/$(HOST_SUBDIR)/gcc/], d)
+GCC_TARGET_TOOL(gm2, GM2_FOR_TARGET, GM2,
+   [gcc/gm2 -B$$r/$(HOST_SUBDIR)/gcc/], m2)
 GCC_TARGET_TOOL(ld, LD_FOR_TARGET, LD, [ld/ld-new])
 GCC_TARGET_TOOL(lipo, LIPO_FOR_TARGET, LIPO)
 GCC_TARGET_TOOL(nm, NM_FOR_TARGET, NM, [binutils/nm-new])
@@ -3733,6 +3745,9 @@
 # Specify what files to not compare during bootstrap.
 
 compare_exclusions="gcc/cc*-checksum\$(objext) | gcc/ada/*tools/*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2-compiler-boot/M2Version*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2-compiler-boot/SYSTEM*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2version*"
 case "$target" in
   hppa*64*-*-hpux*) ;;
   powerpc*-ibm-aix*) compare_exclusions="$compare_exclusions | 
*libgomp*\$(objext)" ;;
diff -ruw gcc-git-master/gcc/doc/sourcebuild.texi 
gcc-git-devel-modula2/gcc/doc/sourcebuild.texi
diff -ruw gcc-git-master/gcc/doc/install.texi 
gcc-git-devel-modula2/gcc/doc/install.texi
diff -ruw gcc-git-master/gcc/dwarf2out.cc gcc-git-devel-modula2/gcc/dwarf2out.cc
--- gcc-git-master/gcc/dwarf2out.cc 2022-12-06 02:56:42.392653713 +
+++ gcc-git-devel-modula2/gcc/dwarf2out.cc  2022-12-06 02:56:51.312774299 
+
@@ -25206,6 +25206,8 @@
 }
   else if (strcmp (language_string, "GNU F77") == 0)
 language = DW_LANG_Fortran77;
+  else if (strcmp (language_string, "GNU Modula-2") == 0)
+language = DW_LANG_Modula2;
   else if (dwarf_version >= 3 || !dwarf_strict)
 {
   if (strcmp (language_string, "GNU Ada") == 0)
diff -ruw gcc-git-master/Makefile.def gcc-git-devel-modula2/Makefile.def
--- gcc-git-master/Makefile.def 2022-12-06 02:56:41.612643168 +
+++ gcc-git-devel-modula2/Makefile.def  2022-12-06 02:56:51.228773165 +
@@ -184,6 +184,7 @@
 target_modules = { module= zlib; bootstrap=true; };
 target_modules = { module= rda; };
 target_modules = { module= libada; };
+target_modules = { module= libgm2; lib_path=.libs; };
 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; };
@@ -306,6 +307,8 @@
 flags_to_pass = { flag= GOCFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= GDC_FOR_TARGET ; };
 flags_to_pass = { flag= GDCFLAGS_FOR_TARGET ; };
+flags_to_pass = { flag= GM2_FOR_TARGET ; };
+flags_to_pass = { flag= GM2FLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= LD_FOR_TARGET ; };
 flags_to_pass = { flag= LIPO_FOR_TARGET ; };
 flags_to_pass = { flag= LDFLAGS_FOR_TARGET ; };
@@ -617,6 +620,8 @@
 dependencies = 

[PATCH v3 9/19] modula2 front end: plugin source files

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patchset contains the modula2 plugin which detects some runtime
errors at compiletime.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/plugin/m2rte.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/plugin/m2rte.cc2022-12-06 
02:56:51.380775219 +
@@ -0,0 +1,335 @@
+/* m2rte.cc a plugin to detect runtime exceptions at compiletime.
+
+Copyright (C) 2017-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING3.  If not see
+.  */
+
+
+#include "gcc-plugin.h"
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "options.h"
+#include "tree-pass.h"
+#include "diagnostic-core.h"
+#include "flags.h"
+#include "intl.h"
+#include "plugin.h"
+#include "tree.h"
+#include "gimple.h"
+#include "gimplify.h"
+#include "gimple-iterator.h"
+#include "gimplify-me.h"
+#include "gimple-pretty-print.h"
+#include "plugin-version.h"
+#include "diagnostic.h"
+#include "context.h"
+
+#include "rtegraph.h"
+extern bool ggc_force_collect;
+extern void ggc_collect (void);
+
+#undef DEBUG_BASICBLOCK
+
+int plugin_is_GPL_compatible;
+
+void debug_tree (tree);
+
+/* All dialects of Modula-2 issue some or all of these runtime error calls.
+   This plugin detects whether a runtime error will be called in the first
+   basic block of a reachable function.  */
+
+static const char *m2_runtime_error_calls[] = {
+  "M2RTS_AssignmentException",
+  "M2RTS_ReturnException",
+  "M2RTS_IncException",
+  "M2RTS_DecException",
+  "M2RTS_InclException",
+  "M2RTS_ExclException",
+  "M2RTS_ShiftException",
+  "M2RTS_RotateException",
+  "M2RTS_StaticArraySubscriptException",
+  "M2RTS_DynamicArraySubscriptException",
+  "M2RTS_ForLoopBeginException",
+  "M2RTS_ForLoopToException",
+  "M2RTS_ForLoopEndException",
+  "M2RTS_PointerNilException",
+  "M2RTS_NoReturnException",
+  "M2RTS_CaseException",
+  "M2RTS_WholeNonPosDivException",
+  "M2RTS_WholeNonPosModException",
+  "M2RTS_WholeZeroDivException",
+  "M2RTS_WholeZeroRemException",
+  "M2RTS_WholeValueException",
+  "M2RTS_RealValueException",
+  "M2RTS_ParameterException",
+  "M2RTS_NoException",
+  NULL,
+};
+
+
+#if defined(DEBUG_BASICBLOCK)
+/* pretty_function display the name of the function.  */
+
+static void
+pretty_function (tree fndecl)
+{
+  if (fndecl != NULL && (DECL_NAME (fndecl) != NULL))
+{
+  const char *n = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+  fprintf (stderr, "PROCEDURE %s ;\n", n);
+}
+}
+#endif
+
+void
+print_rtl (FILE *outf, const_rtx rtx_first);
+
+/* strend returns true if string name has ending.  */
+
+static bool
+strend (const char *name, const char *ending)
+{
+  unsigned int len = strlen (name);
+  return (len > strlen (ending)
+ && (strcmp ([len-strlen (ending)], ending) == 0));
+}
+
+/* is_constructor returns true if the function name is that of a module
+   constructor or deconstructor.  */
+
+static bool
+is_constructor (tree fndecl)
+{
+  const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+  unsigned int len = strlen (name);
+
+  return ((len > strlen ("_M2_"))
+ && (strncmp (name, "_M2_", strlen ("_M2_")) == 0)
+ && (strend (name, "_init") || strend (name, "_finish")));
+}
+
+/* is_external returns true if the function is extern.  */
+
+static bool
+is_external (tree function)
+{
+  return (! DECL_EXTERNAL (function))
+&& TREE_PUBLIC (function)
+&& TREE_STATIC (function);
+}
+
+/* is_external returns true if the function is a call to a Modula-2
+   runtime exception handler.  */
+
+static bool
+is_rte (tree fndecl)
+{
+  const char *n = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+
+  for (int i = 0; m2_runtime_error_calls[i] != NULL; i++)
+if (strcmp (m2_runtime_error_calls[i], n) == 0)
+  return true;
+  return false;
+}
+
+/* examine_call extract the function tree from the gimple call
+   statement and check whether it is a call to a runtime exception.  */
+
+static void
+examine_call (gimple *stmt)
+{
+  tree fndecl = gimple_call_fndecl (stmt);
+  rtenode *func = rtegraph_lookup (stmt, fndecl, true);
+  // rtegraph_dump ();
+  if (fndecl != NULL && (DECL_NAME (fndecl) != NULL))
+{
+  /* Firstly check if the function is a runtime exception.  */
+  if (is_rte (fndecl))
+

[PATCH v3 5/19] modula2 front end: libgm2/libm2iso contents

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf sources necessary
to build the various libgm2/libm2iso libraries.  The c/c++/h files
are also included in the patch set.  The modula-2 sources are found
in gcc/m2.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2iso/wrapsock.c
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2iso/wrapsock.c2022-12-06 
02:56:51.432775922 +
@@ -0,0 +1,250 @@
+/* wrapsock.c provides access to socket related system calls.
+
+Copyright (C) 2008-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include "config.h"
+
+#if defined(HAVE_SYS_TYPES_H)
+#include "sys/types.h"
+#endif
+
+#if defined(HAVE_SYS_SOCKET_H)
+#include "sys/socket.h"
+#endif
+
+#if defined(HAVE_NETINET_IN_H)
+#include "netinet/in.h"
+#endif
+
+#if defined(HAVE_NETDB_H)
+#include "netdb.h"
+#endif
+
+#if defined(HAVE_UNISTD_H)
+#include "unistd.h"
+#endif
+
+#if defined(HAVE_SIGNAL_H)
+#include "signal.h"
+#endif
+
+#if defined(HAVE_SYS_ERRNO_H)
+#include "sys/errno.h"
+#endif
+
+#if defined(HAVE_ERRNO_H)
+#include "errno.h"
+#endif
+
+#if defined(HAVE_MALLOC_H)
+#include "malloc.h"
+#endif
+
+#if defined(HAVE_MALLOC_H)
+#include "signal.h"
+#endif
+
+#if defined(HAVE_STRING_H)
+#include "string.h"
+#endif
+
+#if defined(HAVE_STDLIB_H)
+#include "stdlib.h"
+#endif
+
+#if !defined(TRUE)
+#define TRUE (1 == 1)
+#endif
+#if !defined(FALSE)
+#define FALSE (1 == 0)
+#endif
+
+#include "ChanConsts.h"
+
+#define MAXHOSTNAME 1024
+#define MAXPBBUF 1024
+
+#if defined(HAVE_NETINET_IN_H)
+
+typedef struct
+{
+  char hostname[MAXHOSTNAME];
+  struct hostent *hp;
+  struct sockaddr_in sa;
+  int sockFd;
+  int portNo;
+  int hasChar;
+  char pbChar[MAXPBBUF];
+} clientInfo;
+
+static openResults clientConnect (clientInfo *c);
+
+/* clientOpen - returns an ISO Modula-2 OpenResult.  It attempts to
+   connect to: hostname:portNo.  If successful then the data
+   structure, c, will have its fields initialized.  */
+
+openResults
+wrapsock_clientOpen (clientInfo *c, char *hostname, unsigned int length,
+ int portNo)
+{
+  /* remove SIGPIPE which is raised on the server if the client is killed.  */
+  signal (SIGPIPE, SIG_IGN);
+
+  c->hp = gethostbyname (hostname);
+  if (c->hp == NULL)
+return noSuchFile;
+
+  memset ((void *)>sa, 0, sizeof (c->sa));
+  c->sa.sin_family = AF_INET;
+  memcpy ((void *)>sa.sin_addr, (void *)c->hp->h_addr, c->hp->h_length);
+  c->portNo = portNo;
+  c->sa.sin_port = htons (portNo);
+  c->hasChar = 0;
+  /* Open a TCP socket (an Internet stream socket) */
+
+  c->sockFd = socket (c->hp->h_addrtype, SOCK_STREAM, 0);
+  return clientConnect (c);
+}
+
+/* clientOpenIP - returns an ISO Modula-2 OpenResult.  It attempts to
+   connect to: ipaddress:portNo.  If successful then the data
+   structure, c, will have its fields initialized.  */
+
+openResults
+wrapsock_clientOpenIP (clientInfo *c, unsigned int ip, int portNo)
+{
+  /* remove SIGPIPE which is raised on the server if the client is killed.  */
+  signal (SIGPIPE, SIG_IGN);
+
+  memset ((void *)>sa, 0, sizeof (c->sa));
+  c->sa.sin_family = AF_INET;
+  memcpy ((void *)>sa.sin_addr, (void *), sizeof (ip));
+  c->portNo = portNo;
+  c->sa.sin_port = htons (portNo);
+
+  /* Open a TCP socket (an Internet stream socket) */
+
+  c->sockFd = socket (PF_INET, SOCK_STREAM, 0);
+  return clientConnect (c);
+}
+
+/* clientConnect - returns an ISO Modula-2 OpenResult once a connect
+   has been performed.  If successful the clientInfo will include the
+   file descriptor ready for read/write operations.  */
+
+static openResults
+clientConnect (clientInfo *c)
+{
+  if (connect (c->sockFd, (struct sockaddr *)>sa, sizeof (c->sa)) < 0)
+return noSuchFile;
+
+  return opened;
+}
+
+/* getClientPortNo - returns the portNo from structure, c.  */
+
+int
+wrapsock_getClientPortNo (clientInfo *c)
+{
+  return c->portNo;
+}
+
+/* getClientHostname - fills in 

[PATCH v3 6/19] modula2 front end: libgm2/libm2min contents

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf and a few C sources
to build the libgm2/libm2min libraries.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2min/Makefile.am
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2min/Makefile.am   2022-12-06 
02:56:51.432775922 +
@@ -0,0 +1,147 @@
+# Makefile for libm2min.
+#   Copyright 2013-2022  Free Software Foundation, Inc.
+#
+# This file 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; see the file COPYING3.  If not see
+# .
+
+SUFFIXES = .c .mod .def .o .obj .lo .a .la
+
+ACLOCAL_AMFLAGS = -I . -I .. -I ../config
+
+VPATH = . @srcdir@/../../gcc/m2/gm2-libs-min
+
+# Multilib support.
+MAKEOVERRIDES=
+
+version := $(shell $(CC) -dumpversion)
+
+# Directory in which the compiler finds libraries etc.
+libsubdir = $(libdir)/gcc/$(target_alias)/$(version)
+# Used to install the shared libgcc.
+slibdir = @slibdir@
+
+toolexeclibdir=@toolexeclibdir@
+toolexecdir=@toolexecdir@
+GM2_FOR_TARGET=@GM2_FOR_TARGET@
+
+MULTIDIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
+MULTIOSDIR := $(shell $(CC) $(CFLAGS) -print-multi-os-directory)
+
+MULTIOSSUBDIR := $(shell if test x$(MULTIOSDIR) != x.; then echo 
/$(MULTIOSDIR); fi)
+inst_libdir = $(libsubdir)$(MULTISUBDIR)
+inst_slibdir = $(slibdir)$(MULTIOSSUBDIR)
+
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+"GCC_DIR=$(GCC_DIR)" \
+"GM2_SRC=$(GM2_SRC)" \
+   "AR_FLAGS=$(AR_FLAGS)" \
+   "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+   "CC_FOR_TARGET=$(CC_FOR_TARGET)" \
+   "GM2_FOR_TARGET=$(GM2_FOR_TARGET)" \
+   "CFLAGS=$(CFLAGS)" \
+   "CXXFLAGS=$(CXXFLAGS)" \
+   "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+   "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+   "INSTALL=$(INSTALL)" \
+   "INSTALL_DATA=$(INSTALL_DATA)" \
+   "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+   "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+   "LDFLAGS=$(LDFLAGS)" \
+   "LIBCFLAGS=$(LIBCFLAGS)" \
+   "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+   "MAKE=$(MAKE)" \
+   "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+"MULTISUBDIR=$(MULTISUBDIR)" \
+"MULTIOSDIR=$(MULTIOSDIR)" \
+"MULTIBUILDTOP=$(MULTIBUILDTOP)" \
+"MULTIFLAGS=$(MULTIFLAGS)" \
+   "PICFLAG=$(PICFLAG)" \
+   "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+   "SHELL=$(SHELL)" \
+   "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+   "exec_prefix=$(exec_prefix)" \
+   "infodir=$(infodir)" \
+   "libdir=$(libdir)" \
+   "includedir=$(includedir)" \
+   "prefix=$(prefix)" \
+   "tooldir=$(tooldir)" \
+   "AR=$(AR)" \
+   "AS=$(AS)" \
+   "LD=$(LD)" \
+   "RANLIB=$(RANLIB)" \
+   "NM=$(NM)" \
+   "NM_FOR_BUILD=$(NM_FOR_BUILD)" \
+   "NM_FOR_TARGET=$(NM_FOR_TARGET)" \
+   "DESTDIR=$(DESTDIR)" \
+   "WERROR=$(WERROR)" \
+"TARGET_LIB_PATH_libgm2=$(TARGET_LIB_PATH_libgm2)"
+
+# Subdir rules rely on $(FLAGS_TO_PASS)
+FLAGS_TO_PASS = $(AM_MAKEFLAGS)
+
+M2DEFS = libc.def  M2RTS.def \
+ SYSTEM.def
+
+M2MODS = M2RTS.mod  SYSTEM.mod
+
+libm2mindir = libm2min
+toolexeclib_LTLIBRARIES = libm2min.la
+libm2min_la_SOURCES = $(M2MODS) libc.c
+libm2min_la_DEPENDENCIES = SYSTEM.def $(addsuffix .lo, $(basename 
$(libm2min_la_SOURCES)))
+libm2min_la_CFLAGS = -I. -I$(GM2_SRC)/gm2-libs-min -I$(GM2_SRC)/gm2-libs
+libm2min_la_M2FLAGS = -I. -I$(GM2_SRC)/gm2-libs-min -I$(GM2_SRC)/gm2-libs 
-fno-exceptions \
+   -fno-m2-plugin -fno-scaffold-dynamic -fno-scaffold-main
+libm2min_la_LINK = $(LINK) -version-info $(libtool_VERSION)
+BUILT_SOURCES = SYSTEM.def
+CLEANFILES = SYSTEM.def
+
+M2LIBDIR = /m2/m2min/
+
+.mod.lo:
+   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile 
$(GM2_FOR_TARGET) -c $(CFLAGS_FOR_TARGET) $(LIBCFLAGS) $(libm2min_la_M2FLAGS) 
$< -o $@
+
+libc.o: $(GM2_SRC)/gm2-libs-min/libc.c
+
+
+SYSTEM.def: Makefile
+   echo "CC = $(CC_FOR_BUILD)  CC_FOR_TARGET = $(CC_FOR_TARGET)  GM2 = 
$(GM2)  GM2_FOR_TARGET = $(GM2_FOR_TARGET) GM2_FOR_BUILD = $(GM2_FOR_BUILD)"
+   bash $(GM2_SRC)/tools-src/makeSystem -fpim \
+ $(GM2_SRC)/gm2-libs-min/SYSTEM.def \

[PATCH v3 7/19] modula2 front end: libgm2/libm2log contents

2022-12-06 Thread Gaius Mulley via Gcc-patches
 

This patch set consists of the makefiles, autoconf sources necessary
to build the various libgm2 libraries.  The c/c++/h files are included
in the patch set.  The modula-2 sources are found in gcc/m2.

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2log/Break.c
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2log/Break.c   2022-12-06 
02:56:51.432775922 +
@@ -0,0 +1,134 @@
+/* Break.c implements an interrupt handler for SIGINT.
+
+Copyright (C) 2004-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+#include 
+
+#if defined(HAVE_STDIO_H)
+#include 
+#endif
+
+#if defined(HAVE_STDARG_H)
+#include 
+#endif
+
+#if defined(HAVE_STDLIB_H)
+#include 
+#endif
+
+#if defined(HAVE_MALLOC_H)
+#include 
+#endif
+
+typedef void (*PROC) (void);
+
+#if defined(HAVE_SIGNAL_H)
+#include 
+
+struct plist
+{
+  PROC proc;
+  struct plist *next;
+};
+
+static struct plist *head = NULL;
+
+/* localHandler - dismisses the parameter, p, and invokes the GNU
+   Modula-2 handler.  */
+
+static void
+localHandler (int p)
+{
+  if (head != NULL)
+head->proc ();
+}
+
+/* EnableBreak - enable the current break handler.  */
+
+void
+Break_EnableBreak (void)
+{
+  signal (SIGINT, localHandler);
+}
+
+/* DisableBreak - disable the current break handler (and all
+   installed handlers).  */
+
+void
+Break_DisableBreak (void)
+{
+  signal (SIGINT, SIG_IGN);
+}
+
+/* InstallBreak - installs a procedure, p, to be invoked when a
+   ctrl-c is caught.  Any number of these procedures may be stacked.
+   Only the top procedure is run when ctrl-c is caught.  */
+
+void
+Break_InstallBreak (PROC p)
+{
+  struct plist *q = (struct plist *)malloc (sizeof (struct plist));
+
+  if (q == NULL)
+{
+  perror ("out of memory error in module Break");
+  exit (1);
+}
+  q->next = head;
+  head = q;
+  head->proc = p;
+}
+
+/* UnInstallBreak - pops the break handler stack.  */
+
+void
+Break_UnInstallBreak (void)
+{
+  struct plist *q = head;
+
+  if (head != NULL)
+{
+  head = head->next;
+  free (q);
+}
+}
+#else
+void
+Break_EnableBreak (void)
+{
+}
+void
+Break_DisableBreak (void)
+{
+}
+void
+Break_InstallBreak (PROC *p)
+{
+}
+void
+Break_UnInstallBreak (void)
+{
+}
+#endif
diff -ruw /dev/null gcc-git-devel-modula2/libgm2/libm2log/Makefile.am
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/libgm2/libm2log/Makefile.am   2022-12-06 
02:56:51.432775922 +
@@ -0,0 +1,166 @@
+# Makefile for libm2log.
+#   Copyright 2013-2022  Free Software Foundation, Inc.
+#
+# This file 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; see the file COPYING3.  If not see
+# .
+
+SUFFIXES = .c .mod .def .o .obj .lo .a .la
+
+ACLOCAL_AMFLAGS = -I . -I .. -I ../config
+
+VPATH = . @srcdir@ @srcdir@/../../gcc/m2/gm2-libs-pim
+
+# Multilib support.
+MAKEOVERRIDES=
+
+version := $(shell $(CC) -dumpversion)
+
+# Directory in which the compiler finds libraries etc.
+libsubdir = $(libdir)/gcc/$(target_alias)/$(version)
+# Used to install the shared libgcc.
+slibdir = @slibdir@
+
+toolexeclibdir=@toolexeclibdir@
+toolexecdir=@toolexecdir@
+GM2_FOR_TARGET=@GM2_FOR_TARGET@
+
+MULTIDIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
+MULTIOSDIR := $(shell $(CC) $(CFLAGS) -print-multi-os-directory)
+
+MULTIOSSUBDIR := $(shell if test x$(MULTIOSDIR) != x.; then echo 
/$(MULTIOSDIR); 

Re: [PATCH] 0/19 modula-2 front end patches overview

2022-12-05 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

>>
>> I think it's important to get this (and the rust frontend) into the tree 
>> before
>> Christmas holidays so it gets exposed to the more weird treatment of some
>> of our users (build wise).  This way we can develop either a negative or
>> positive list of host/targets where to disable the new frontends.
>
> So let's go ahead with the Modula-2 merge.  Gaius, can you post a final
> series of the patches and perform the merging please?
>
> Thus - OK to merge to trunk!
>
> Thanks,
> Richard.

Hi Richard,

certainly will do - and thanks!

regards,
Gaius


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-27 Thread Gaius Mulley via Gcc-patches
David Malcolm  writes:

>> Once modula-2 is in master I'd like to revisit rst in devel/modula-2
>> along with analyzer patches and m2 generics.  If successful then
>> submit
>> patches in early stage 1.
>
> Am I right in thinking the analyzer stuff would be an updated version
> of the work you posted here:
> https://gcc.gnu.org/pipermail/gcc-patches/2021-April/567953.html ?

Sure, yes.

regards,
Gaius


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-24 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

> On 11/8/22 14:22, Gaius Mulley wrote:
>> Martin Liška  writes:
>> 
>> should be good - I'll complete the rst output in the scripts,
>
> Hi.
>

Hi Martin,

> As you probably noticed, the Sphinx migration didn't go well.

Yes, sorry to see this didn't happen.  Thank you for your hard work and
I hope it can occur in the future.

> However, it's still up to you if you want to use it or not for Modula
> 2.

Once modula-2 is in master I'd like to revisit rst in devel/modula-2
along with analyzer patches and m2 generics.  If successful then submit
patches in early stage 1.

> We have manuals like libgccjit, or Ada manuals
> that use RST natively and provide exported .texi files.

Ok thanks for the pointers, I will experiment with these build rhunes.

> Cheers and sorry for the troubles I caused.

No problem at all - the modula-2 scripts are now improved and cleaner
due to the port.  Hopefully rst will happen sometime in the future,

regards,
Gaius


Re: [PATCH] 8/19 modula2 front end: libgm2 contents

2022-11-24 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Mon, Oct 10, 2022 at 5:35 PM Gaius Mulley via Gcc-patches
>  wrote:
>>
>>
>>
>> This patch set consists of the libgm2 makefile, autoconf sources
>> necessary to build the libm2pim, libm2iso, libm2min, libm2cor
>> and libm2log.
>
> This looks OK.  I suppose it was also tested building a cross-compiler?
>
> Can we get some up-to-date status on the build and support status for the
> list of primary and secondary platforms we list on
> https://gcc.gnu.org/gcc-13/criteria.html?

sure, here is a summary of the primary/secondary platforms, added at the
end of the page:

https://splendidisolation.ddns.net/public/modula2/patchsummary.html

regards,
Gaius


Re: [PATCH] 8/19 modula2 front end: libgm2 contents

2022-11-22 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Mon, Oct 10, 2022 at 5:35 PM Gaius Mulley via Gcc-patches
>  wrote:
>>
>>
>>
>> This patch set consists of the libgm2 makefile, autoconf sources
>> necessary to build the libm2pim, libm2iso, libm2min, libm2cor
>> and libm2log.
>
> This looks OK.

Thanks!

> I suppose it was also tested building a cross-compiler?

yes it builds a cross compiler tool chain targetting aarch64, hosted and
built on amd64 gnu linux.

> Can we get some up-to-date status on the build and support status for the
> list of primary and secondary platforms we list on
> https://gcc.gnu.org/gcc-13/criteria.html?

Primary platform summary


aarch64-none-linux-gnu  bootstrapped 6 reg failures
arm-linux-gnueabi   (still building)
i686-pc-linux-gnu   bootstrapped 7 reg failures
powerpc64-unknown-linux-gnu bootstrapped 12 reg failures
powerpc64le-unknown-linux-gnu   bootstrapped 18 reg failures
sparc-sun-solaris2.11   (still building)
x86_64-pc-linux-gnu bootstrapped 6 reg failures
(tumbleweed and bullseye)


there are six regression tests failures common to all platforms (one
test failing with 6 option permutations and with a reasonably obvious
fix will be purged soon)


i586-unknown-freebsdfails at:

ctype_members.cc:137:3: error: redefinition of ‘bool 
std::ctype::do_is(std::ctype_base::mask, char_type) const’
  137 |   ctype::
  |   ^~
In file included from 
/home/gaius/GM2/graft-combine/build-devel-modula2-enabled/i586-unknown-freebsd13.0/libstdc++-v3/include/bits/locale_facets.h:1546,
 from 
/home/gaius/GM2/graft-combine/build-devel-modula2-enabled/i586-unknown-freebsd13.0/libstdc++-v3/include/locale:42,
 from ctype_members.cc:31:


regards,
Gaius


Re: [PATCH] 3/19 modula2 front end: gm2 driver files.

2022-11-21 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

[snip]

> It feels like most of the above would usually be handled via lang specific
> specs rather than open-coded in the driver?  Is there a specific reason you
> opted for explicit handling here?

The last time submitting the patches I perhaps went overboard using
lang-specs - and so tried to adopt the style from C++/fortran this time
around.  I'm happy to utilize lang-specs to reduce the driver code though.

> Otherwise the patch looks generally OK, the string builds using strcat & 
> friends
> looks like it neither takes advantage of how obstacks can be used there nor
> that we're now C++ and could use std::string - but that's a matter of taste 
> and
> no objection.

ok thanks!

regards,
Gaius


Re: [PATCH] 15/19 modula2 front end: cc1gm2 additional non modula2 source files

2022-11-19 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

>> +/* We don't use language_function.  */
>
> well ...

oops, yes - I'll remove the comment!

>> +struct GTY (()) language_function
>> +{
>> +
>> +  /* While we are parsing the function, this contains information about
>> +  the statement-tree that we are building.  */
>> +  /* struct stmt_tree_s stmt_tree;  */
>> +  tree stmt_tree;
>
> ... but this?
>
>> +};
>> +
>> +/* end of new stuff.  */
>> +
>> +/* Language hooks.  */
>> +
>> +bool
>> +gm2_langhook_init (void)
>> +{
>> +  build_common_tree_nodes (false);
>> +
>> +  /* I don't know why this has to be done explicitly.  */
>> +  void_list_node = build_tree_list (NULL_TREE, void_type_node);
>
> it's now done in build_common_tree_nodes

thanks

>> +  build_common_builtin_nodes ();
>> +
>> +  /* The default precision for floating point numbers.  This is used
>> + for floating point constants with abstract type.  This may eventually
>> + be controllable by a command line option.  */
>> +  mpfr_set_default_prec (256);
>> +
>> +  /* GNU Modula-2 uses exceptions.  */
>> +  using_eh_for_cleanups ();
>> +
>> +  return true;
>> +}
>> +
>> +/* The option mask.  */
>> +
>> +static unsigned int
>> +gm2_langhook_option_lang_mask (void)
>> +{
>> +  return CL_ModulaX2;
>> +}
>> +
>> +/* Initialize the options structure.  */
>> +
>> +static void
>> +gm2_langhook_init_options_struct (struct gcc_options *opts)
>> +{
>> +  /* Default to avoiding range issues for complex multiply and divide.  */
>> +  opts->x_flag_complex_method = 2;
>> +
>> +  /* The builtin math functions should not set errno.  */
>> +  opts->x_flag_errno_math = 0;
>> +  opts->frontend_set_flag_errno_math = true;
>> +
>> +  /* Exceptions are used to handle recovering from panics.  */
>> +  opts->x_flag_exceptions = 1;
>> +  opts->x_flag_non_call_exceptions = 1;
>
> whohoo - really non-call-exceptions?

ah thankyou.  Now removed, bootstrapped and regression tests pass.

>> +  init_FrontEndInit ();
>> +}
>> +

[snip]

>> +static tree
>> +gm2_langhook_type_for_mode (machine_mode mode, int unsignedp)
>> +{
>> +  tree type;
>> +
>> +  if (VECTOR_MODE_P (mode))
>> +{
>> +  tree inner;
>> +
>> +  inner = gm2_langhook_type_for_mode (GET_MODE_INNER (mode), unsignedp);
>> +  if (inner != NULL_TREE)
>> +return build_vector_type_for_mode (inner, mode);
>> +  return NULL_TREE;
>> +}
>> +
>> +  scalar_int_mode imode;
>> +  scalar_float_mode fmode;
>> +  complex_mode cmode;
>> +  if (is_int_mode (mode, ))
>> +return gm2_langhook_type_for_size (GET_MODE_BITSIZE (imode), unsignedp);
>> +  else if (is_float_mode (mode, ))
>> +{
>> +  switch (GET_MODE_BITSIZE (fmode))
>> +{
>> +case 32:
>> +  return float_type_node;
>> +case 64:
>> +  return double_type_node;
>
> Have a look at lto/lto-lang.cc where we match the global types with

thanks will do!

>   if (mode == TYPE_MODE (float_type_node))
> return float_type_node;
>
> I think that's better than relying on the size statically as you do
> above.

yes indeed

>> +default:
>> +  // We have to check for long double in order to support
>> +  // i386 excess precision.
>> +  if (fmode == TYPE_MODE (long_double_type_node))
>> +return long_double_type_node;
>> +}
>> +}
>> +  else if (is_complex_float_mode (mode, ))
>> +{
>> +  switch (GET_MODE_BITSIZE (cmode))
>> +{
>> +case 64:
>> +  return complex_float_type_node;
>> +case 128:
>> +  return complex_double_type_node;
>> +default:
>> +  // We have to check for long double in order to support
>> +  // i386 excess precision.
>> +  if (cmode == TYPE_MODE (complex_long_double_type_node))
>> +return complex_long_double_type_node;
>> +}
>> +}
>> +
>> +#if HOST_BITS_PER_WIDE_INT >= 64
>> +
>> +  /* The middle-end and some backends rely on TImode being supported
>> +  for 64-bit HWI.  */
>> +  if (mode == TImode)
>> +{
>> +  type = build_nonstandard_integer_type (GET_MODE_BITSIZE (TImode),
>> + unsignedp);
>> +  if (type && TYPE_MODE (type) == TImode)
>> +return type;
>> +}
>> +#endif
>
> Instead of this block look at c-family/c-common.cc which does
>
>   for (i = 0; i < NUM_INT_N_ENTS; i ++)
> if (int_n_enabled_p[i]
> && mode == int_n_data[i].m)
>   return (unsignedp ? int_n_trees[i].unsigned_type
>   : int_n_trees[i].signed_type);

ok will do - thanks for the direction.

> it might be practical to factor out handling of the global tree nodes into
> a function in the middle-end that frontends can call after processing modes
> it has special types for.

yes it sounds like a common front end use.

>> +  return NULL_TREE;
>> +}
>> +

[snip]

>> +/* m2_write_global_declarations writes out globals by coping into a vec
>> +   and calling wrapup_global_declarations.  */
>> 

Re: [PATCH] 0/19 modula-2 front end patches overview

2022-11-14 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Mon, Oct 10, 2022 at 5:32 PM Gaius Mulley via Gcc-patches
>  wrote:
>>
>>
>> Here are the latest modula-2 front end patches for review.
>> The status of the patches and their contents are also contained at:
>>
>>https://splendidisolation.ddns.net/public/modula2/patchsummary.html
>>
>> where they are also broken down into topic groups.
>>
>> In summary the high level changes from the last posting are:
>>
>>* the driver code has been completely rewritten and it is now based
>>  on the fortran driver and the c++ driver.  The gm2 driver adds
>>  paths/libraries depending upon dialect chosen.
>>* the linking mechanism has been completely redesigned
>>  (As per
>>  https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595725.html).
>>  Objects can be linked via g++.  New linking options
>>  are available to allow linking with/without a scaffold.
>>* gcc/m2/Make-lang.in (rewritten).
>>* gm2tools/ removed and any required functionality with the
>>  new linking mechanism has been moved into cc1gm2.
>>
>> The gm2 testsuite has been extended to test project linking
>> options.
>
> Thanks for these improvements!

the front end feels alot cleaner now!

> The frontend specific parts are a lot to digest and I think it isn't
> too important to wait for the unlikely event that all of that gets a
> review.  I'm trusting you here as a maintainer and also based on the
> use of the frontend out in the wild.  I've CCed the other two RMs for
> their opinion on this.
>
> I hope to get to the driver parts that I reviewed the last time, I'd
> appreciate a look on the runtime library setup by somebody else.
>
> I think it's important to get this (and the rust frontend) into the tree 
> before
> Christmas holidays so it gets exposed to the more weird treatment of some
> of our users (build wise).  This way we can develop either a negative or
> positive list of host/targets where to disable the new frontends.

great news thanks - yes this makes sense,

regards,
Gaius


Re: [PATCH] 2/19 modula2 front end: Make-lang.in

2022-11-11 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

>> +M2_MAINTAINER = no
>> +
>> +CPP_GM2=-fpermissive -DIN_GCC -g
>
> Do we really need -fpermissive here?

no not needed (and now removed) - thanks for spotting it.

>> +GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
>> +
>> +GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
>> -L$(objdir)/../ld $(TFLAGS)
>> +
>> +TEXISRC = $(objdir)/m2/images/gnu.eps \
>> +  $(srcdir)/doc/gm2.texi \
>> +  m2/gm2-libs.texi \
>> +  m2/gm2-ebnf.texi \
>> +  m2/SYSTEM-pim.texi \
>> +  m2/SYSTEM-iso.texi \
>> +  m2/Builtins.texi
>> +
>
> That will need Sphinx treatment

true

>> +# Define the names for selecting modula-2 in LANGUAGES.

snip

>> +m2.info: doc/m2.info
>> +
>> +m2.man: doc/m2.1
>> +
>> +m2.install-man: $(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext)
>> +
>> +$(DESTDIR)$(man1dir)/$(GM2_INSTALL_NAME)$(man1ext): doc/m2.1 installdirs
>> +   -rm -f $@
>> +   -$(INSTALL_DATA) $< $@
>> +   -chmod a-x $@
>> +
>> +m2.dvi: $(TEXISRC)
>> +   $(TEXI2DVI) -I $(objdir)/m2 -I $(srcdir)/doc/include 
>> $(srcdir)/doc/gm2.texi -o $@
>> +
>> +m2.ps: m2.dvi
>> +   dvips -o $@ $<
>> +
>> +m2.pdf: m2.ps
>> +   gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$@ $<
>> +
>> +.INTERMEDIATE: gm2.pod
>> +
>> +m2.pod: doc/gm2.texi $(TEXISRC)
>> +   -$(TEXI2POD) -I $(objdir)/m2 -D m2 < $< > $@
>
> Likewise for the doc parts above and below

yes, sure I'll convert them

>> +doc/m2.info: $(TEXISRC)
>> +   if test "x$(BUILD_INFO)" = xinfo; then \
>> + rm -f doc/m2.info*; \
>> +  $(MAKEINFO) --no-headers -I$(objdir)/m2 -I$(srcdir)/doc/include \
>> +  -o $@ $(srcdir)/doc/gm2.texi ; \
>> +   else true; fi
>> +
>> +$(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
>> +   test -d m2/images || mkdir -p m2/images
>> +   if [ -f $(srcdir)/m2/images/gnu.eps ] ; then \
>> +   cp $(srcdir)/m2/images/gnu.eps $@ ; \
>> +else \
>> +   pngtopnm $< | pnmtops -noturn > $@ ; \
>> +fi
>> +
>> +m2/gm2-libs.texi: gm2-libs.texi-check; @true
>> +
>> +gm2-libs.texi-check:  m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi 
>> m2/Builtins.texi \
>> +  $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def 
>> m2/gm2-ebnf.texi
>> +   python3 $(srcdir)/m2/tools-src/def2texi.py -uLibraries 
>> -s$(srcdir)/m2 -b$(objdir)/m2 > $(objdir)/m2/gm2-libs.texi
>> +   $(STAMP) gm2-libs.texi-check
>> +
>> +m2/gm2-ebnf.texi: gm2-ebnf.texi-check; @true
>> +
>> +gm2-ebnf.texi-check: $(PGE) $(srcdir)/m2/gm2-compiler/P0SyntaxCheck.bnf
>> +   $(PGE) -c -p -t -f $(srcdir)/m2/gm2-compiler/P0SyntaxCheck.bnf > 
>> m2/gm2-ebnf.texi
>> +   $(STAMP) gm2-ebnf.texi-check
>> +
>> +m2/SYSTEM-pim.texi: SYSTEM-pim-texi-check; @true
>> +
>> +SYSTEM-pim-texi-check: $(objdir)/m2/gm2-libs/SYSTEM.def
>> +   python3 $(srcdir)/m2/tools-src/def2texi.py -b$(objdir)/m2 
>> -f$(objdir)/m2/gm2-libs/SYSTEM.def > $(objdir)/m2/SYSTEM-pim.texi
>> +   $(STAMP) SYSTEM-pim-texi-check
>> +
>> +m2/SYSTEM-iso.texi:  SYSTEM-iso.texi-check; @true
>> +
>> +SYSTEM-iso.texi-check:  $(objdir)/m2/gm2-libs-iso/SYSTEM.def
>> +   python3 $(srcdir)/m2/tools-src/def2texi.py -b$(objdir)/m2 
>> -f$(objdir)/m2/gm2-libs-iso/SYSTEM.def > $(objdir)/m2/SYSTEM-iso.texi
>> +   $(STAMP) SYSTEM-iso.texi-check
>> +
>> +m2/Builtins.texi:  Builtins.texi-check; @true
>> +
>> +Builtins.texi-check:  m2/gm2-libs/Builtins.def
>> +   python3 $(srcdir)/m2/tools-src/def2texi.py -b./ 
>> -f$(srcdir)/m2/gm2-libs/Builtins.def > $(objdir)/m2/Builtins.texi
>> +   $(STAMP) Builtins.texi-check

snip

>> +gm2.paranoid: stage3/m2/cc1gm2$(exeext) gm2.verifyparanoid
>> +
>> +cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) $(m2.prev)
>> +   cp -p $< $@
>> +
>> +stage3/m2/cc1gm2$(exeext): stage2/m2/cc1gm2$(exeext) 
>> m2/gm2-compiler-paranoid/m2flex.o \
>> +$(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) 
>> $(GM2_LIBS_PARANOID) \
>> +m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so
>> +   @$(call LINK_PROGRESS,$(INDEX.m2),start)
>> +   +$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) 
>> m2/gm2-compiler-paranoid/m2flex.o \
>> +attribs.o \
>> +  $(GM2_LIBS_PARANOID) \
>> +  $(BACKEND) $(LIBS) m2/gm2-gcc/rtegraph.o \
>> +  $(BACKENDLIBS) $(LIBSTDCXX) -lm
>> +   @$(call LINK_PROGRESS,$(INDEX.m2),end)
>> +
>> +stage2/m2/cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) 
>> m2/gm2-compiler/m2flex.o $(P) \
>> +$(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS) 
>> \
>> +m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so
>> +   @$(call LINK_PROGRESS,$(INDEX.m2),start)
>> +   +$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) 
>> m2/gm2-compiler/m2flex.o \
>> +attribs.o \

Re: [PATCH] 1/19 modula2 front end: changes outside gcc/m2, libgm2 and gcc/testsuite.

2022-11-11 Thread Gaius Mulley via Gcc-patches
Richard Biener  writes:

> On Mon, Oct 10, 2022 at 5:36 PM Gaius Mulley via Gcc-patches
>  wrote:
>>
>>
>>
>> This patch set contains the non machine generated changes found in /
>> for example the language die and documentation changes.  It also
>> contains the changes to the top level build Makefile infastructure
>> and the install.texi sourcebuild.texi documentation.
>
> I couldn't spot any issue besides the docs now being written in
> Sphinx, so this part
> is OK (with the docs ported)

awesome, many thanks - I'm working on the tool
(gcc/m2/tools-src/def2doc.py) which generates Sphinx from the modula-2
library sources and should post this in a few days time,

regards,
Gaius


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-08 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

> 1) I would prefer using ' instead of ":
>
> $ flake8 ./gcc/m2/tools-src/tidydates.py
> ...
> ./gcc/m2/tools-src/tidydates.py:124:30: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:127:27: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:132:27: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:133:33: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:138:26: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:143:28: Q000 Double quotes found but
> single quotes preferred

ah yes will switch the quotes character.

> 2) Python-names would be nicer:
>
> def writeTemplate(fo, magic, start, end, dates, contribution, summary,
> lic):
>
> def write_template(...)

agreed, will change

> 3) def hasExt(name, ext) - please use Path from pathlib
>
> 4) while (str.find(line, "(*") != -1):
>
> '(*' in line
> ? Similarly elsewhere.
>
> 5) str.find(line, ...)
>
> Use rather directly: line.find(...)
>
> 6) please use flake8:
> https://gcc.gnu.org/codingconventions.html#python

sure will do all above - I used flake8 but maybe the plugins weren't
enabled.  I'll try flake8 on tumbleweed.

> Thanks,
> Martin
>
> P.S. I'm going to merge Sphinx branch this Wednesday, so then we should port 
> your
> conversion scripts to emit .rst instead of .texi.

should be good - I'll complete the rst output in the scripts,

regards,
Gaius


[PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-07 Thread Gaius Mulley via Gcc-patches


Hi Martin,

here is the revised patch having applied all previous recommendations:

  https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603436.html
  
Is this ok now?  Thanks for the improvement suggestions (argparse
results in fewer lines of code :-)

regards,
Gaius

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/mli...@suse.cz
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-11-05 
17:33:53.685584357 +
@@ -0,0 +1,166 @@
+#!/usr/bin/env python3
+
+# utility to tidy dates and detect lack of copyright.
+
+# Copyright (C) 2016-2022 Free Software Foundation, Inc.
+#
+# This file is part of GNU Modula-2.
+#
+# GNU Modula-2 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.
+#
+# GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+import os
+import sys
+import pathlib
+import shutil
+
+maxLineLength = 60
+
+COPYRIGHT = "Copyright (C)"
+
+
+def visitDir(directory, ext, func):
+# visitDir - call func for each file below, dir, matching extension, ext.
+listOfFiles = os.listdir(directory)
+listOfFiles.sort()
+for filename in listOfFiles:
+path = pathlib.PurePath(filename)
+full = os.path.join(directory, filename)
+if path.is_file(full):
+if path.suffix == ext:
+func(full)
+elif path.is_dir(full):
+visitDir(full, ext, func)
+
+
+def isYear(year):
+# isYear - returns True if, year, is legal.
+if len(year) == 5:
+year = year[:-1]
+for c in year:
+if not c.isdigit():
+return False
+return True
+
+
+def handleCopyright(outfile, lines, n, leader1, leader2):
+# handleCopyright look for Copyright in the comment.
+global maxLineLength
+i = lines[n]
+c = i.find(COPYRIGHT)+len(COPYRIGHT)
+outfile.write(i[:c])
+d = i[c:].split()
+start = c
+seenDate = True
+years = []
+while seenDate:
+if d == []:
+n += 1
+i = lines[n]
+d = i[2:].split()
+else:
+e = d[0]
+punctuation = ""
+if len(d) == 1:
+d = []
+else:
+d = d[1:]
+if c > maxLineLength:
+outfile.write("\n")
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(" "*(start-2))
+c = start
+if isYear(e):
+if (e[-1] == ".") or (e[-1] == ","):
+punctuation = e[-1]
+e = e[:-1]
+else:
+punctuation = ""
+else:
+seenDate = False
+if seenDate:
+if not (e in years):
+c += len(e) + len(punctuation)
+outfile.write(" ")
+outfile.write(e)
+outfile.write(punctuation)
+years += [e]
+else:
+if start < c:
+outfile.write("\n")
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(" "*(start-2))
+
+outfile.write(" ")
+outfile.write(e)
+outfile.write(punctuation)
+for w in d:
+outfile.write(" ")
+outfile.write(w)
+outfile.write("\n")
+return outfile, n+1
+
+
+def handleHeader(filename, leader1, leader2):
+# handleHeader reads in the header of a file and inserts
+# a line break around the Copyright dates.
+print("--")
+lines = open(filename, "r").readlines()
+if len(lines) > 20:
+with open("tmptidy", "w") as outfile:
+n = 0
+for i in lines:
+if i.find("Copyright (C)") >= 0:
+outfile, n = handleCopyright(outfile, lines,
+ n, leader1, leader2)
+outfile.writelines(lines[n:])
+outfile.close()
+print("-> mv tmptidy", filename)
+shutil.move("tmptidy", filename)
+

Re: [PATCH] 16/19 modula2 front end: bootstrap and documentation tools

2022-10-28 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

> Hello.
>
> I noticed the devel/modula-2 branch contains the following dead links:
>
> - http://www.gccsummit.org/2006
> - http://www.gccsummit.org/2010/speakers.php?types=LIGHTNING
> - http://floppsie.comp.glam.ac.uk/Papers/paper23/gaius-mulley-gnu-m2.pdf
> - http://floppsie.comp.glam.ac.uk/Papers/paper15/mulley-proc.pdf
> - http://floppsie.comp.glam.ac.uk/Papers/paper22/gaius-gcc-cauldron-2016.pdf
>
> Thanks,
> Martin

many thanks - I will remove these,

regards,
Gaius


Re: [PATCH] 16/19 modula2 front end: bootstrap and documentation tools

2022-10-14 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

>> This patch set contains the bootstrap linking tool as well as python3
>> scripts to automatically generate texi libraries section of the gm2
>> documentation.  In the fullness of time this will be changed to emit
>> sphinx.
>
> Yep, looking forward to it. I'm going to write an email with Sphinx transition
> schedule once Sphinx 5.3 gets released (should happen during the upcoming 
> weekend).
>
> I have general comments about the Python scripts:
>
> 1) please follow the Python coding style and not the GCC one (I'm going to 
> document
> it in https://gcc.gnu.org/codingconventions.html under a new Python section).
> The easiest approach is using flake8 and the following plugins:
>
> python3-flake8, python3-flake8-builtins, python3-flake8-bugbear,
> python3-flake8-import-order, python3-flake8-quotes

Hi Martin,

many thanks for the pointers to the style tool and python lint - I'll
reformat the code accordingly.

> plus, you might want to come up with a setup.cfg like we have in:
> ./maintainer-scripts/setup.cfg

yes sounds sensible.  Thanks for the detailed
observations/suggestions/improvements below - I agree with them all and
will fix/change the code and then repost the patch

regards,
Gaius


>> --8<--8<--8<--8<--8<--8< 
>> diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py
>> --- /dev/null2022-08-24 16:22:16.88870 +0100
>> +++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py  2022-10-07 
>> 20:21:18.682097332 +0100
>> @@ -0,0 +1,184 @@
>> +#!/usr/bin/env python3
>> +
>> +# utility to tidy dates and detect lack of copyright.
>> +
>> +# Copyright (C) 2016-2022 Free Software Foundation, Inc.
>> +#
>> +# This file is part of GNU Modula-2.
>> +#
>> +# GNU Modula-2 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.
>> +#
>> +# GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
>> +# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
>> +# 02110-1301, USA.
>> +
>> +import os, sys
>> +
>> +maxLineLength = 60
>> +
>> +
>> +#
>> +#  visitDir - call func for each file below, dir, matching extension, ext.
>> +#
>> +
>> +def visitDir (dir, ext, func):
>> +listOfFiles = os.listdir(dir)
>> +listOfFiles.sort()
>> +for file in listOfFiles:
>> +if os.path.isfile(os.path.join(dir, file)):
>> +l = len(ext)
>> +if (len(file)>l) and (file[-l:] == ext):
>> +func(os.path.join(dir, file))
>
> please use pathlib.Path(...).stem

>
>> +elif os.path.isdir(os.path.join(dir, file)):
>> +visitDir(os.path.join(dir, file), ext, func)
>> +
>> +#
>> +#  isYear - returns True if, year, is legal.
>> +#
>> +
>> +def isYear (year):
>> +if len(year)==5:
>> +year = year[:-1]
>> +for c in year:
>> +if not c.isdigit():
>> +return False
>> +return True
>> +
>> +
>> +#
>> +#  handleCopyright -
>> +#
>> +
>> +def handleCopyright (outfile, lines, n, leader1, leader2):
>> +global maxLineLength
>> +i = lines[n]
>> +c = i.find('Copyright (C) ')+len('Copyright (C)')
>> +outfile.write(i[:c])
>> +d = i[c:].split()
>> +start = c
>> +seenDate = True
>> +years = []
>> +while seenDate:
>> +if d == []:
>> +n += 1
>> +i = lines[n]
>> +d = i[2:].split()
>> +else:
>> +e = d[0]
>> +punctuation = ""
>
> Please unify "" and '', you only apostrophes.
>
>> +if len(d)==1:
>> +d = []
>> +else:
>> +d = d[1:]
>> +
>> +if c>maxLineLength:
>> +outfile.write('\n')
>> +outfile.write(leader1)
>> +outfile.write(leader2)
>> +outfile.write(' '*(start-2))
>> +c = start
>> +
>> +if isYear(e):
>> +if (e[-1]=='.') or (e[-1]==','):
>> +punctuation = e[-1]
>> +e = e[:-1]
>> +else:
>> +punctuation = ""
>> +else:
>> +seenDate = False
>> +if seenDate:
>> +if not (e in years):
>> +c += len(e) + len(punctuation)
>> +outfile.write(' ')
>> +outfile.write(e)
>> +outfile.write(punctuation)
>> +years += [e]
>> + 

Re: [DOCS] Python Language Conventions

2022-10-13 Thread Gaius Mulley via Gcc-patches
David Malcolm  writes:

> On Thu, 2022-10-13 at 11:44 +0200, Gerald Pfeifer wrote:
>> Hi Martin,
>> 
>> On Thu, 13 Oct 2022, Martin Liška wrote:
>> > I think we should add how Python scripts should be formatted. I
>> > noticed
>> > that while reading the Modula-2 patchset where it follows the C/C++
>> > style
>> > when it comes to Python files.
>> 
>> good initiative, thank you! This makes sense to me, alas I'm not a
>> Python 
>> hacker, so best wait to see what David and Gaius think, too?
>
> I'm very much +1 on recommending PEP 8.

hi,

all sounds very sensible - yes I'm also happy to adopt any house style
and will reformat the code accordingly

regards,
Gaius


Re: [PATCH] 0/19 modula-2 front end patches overview

2022-10-12 Thread Gaius Mulley via Gcc-patches
Rainer Orth  writes:

> Hi Gaius,
>
>> Testing
>> ===
> [...]
>> The devel/modula-2 branch has been bootstrapped on:
>>
> [...]
>>sparc64 solaris
>>sparc32 solaris
>
> which versions exactly did you run those bootstraps on?  I'm asking
> because for Solaris 11.4/SPARCV9 (sparcv9-sun-solaris2.11) was fine,
> while Solaris 11.4/SPARC (sparc-sun-solaris2.11) still runs into PR
> modula2/101392 (cc1gm2 -fdump-system-exports SEGV on Solaris/SPARC).

Hi Rainer,

ah very sorry - I thought I was relaying a summary of your findings.
Thanks for the clarification and detailed correction.

> For good measure, I also tried Solaris 11.3/SPARC (matching gcc211 in
> the cfarm), but that only revealed a couple of additional issues not
> seen on 11.4:
>
> modula2/107233gm2 build hardcodes python3
> modula2/107234Format error in m2pp.cc (m2pp_integer_cst)
> modula2/107235m2/boot-bin/mc leaks file descriptors
>
> before running into the same SEGV in the end.

thanks for the PRs above - will apply fixes to the first two and
examine the 3rd (again).

> Just for the record, both Solaris 11.4/amd64 (amd64-pc-solaris2.11) and
> Solaris 11.4/i386 (i386-pc-solaris2.11) are fine.

great news and thanks for this report,

regards,
Gaius


[PATCH] 15/19 modula2 front end: cc1gm2 additional non modula2 source files

2022-10-10 Thread Gaius Mulley via Gcc-patches
 

This patch set contains the .h, .cc and .flex files found in
gcc/m2.  The files are tightly coupled with the gimple interface
(see 04-gimple-interface) and built using the rules found in
(01-03-make).

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-lang.cc
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/gm2-lang.cc2022-10-07 20:21:18.650096940 
+0100
@@ -0,0 +1,938 @@
+/* gm2-lang.cc language-dependent hooks for GNU Modula-2.
+
+Copyright (C) 2002-2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley .
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 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.
+
+GNU Modula-2 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 GNU Modula-2; see the file COPYING.  If not, write to the
+Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
+
+#include "gm2-gcc/gcc-consolidation.h"
+
+#include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name.  */
+#include "tree-pass.h" /* FIXME: only for PROP_gimple_any.  */
+#include "toplev.h"
+#include "debug.h"
+
+#include "opts.h"
+
+#define GM2_LANG_C
+#include "gm2-lang.h"
+#include "m2block.h"
+#include "dynamicstrings.h"
+#include "m2options.h"
+#include "m2convert.h"
+#include "m2linemap.h"
+#include "init.h"
+#include "m2-tree.h"
+#include "convert.h"
+#include "rtegraph.h"
+
+static void write_globals (void);
+
+static int insideCppArgs = FALSE;
+
+#define EXPR_STMT_EXPR(NODE) TREE_OPERAND (EXPR_STMT_CHECK (NODE), 0)
+
+/* start of new stuff.  */
+
+/* Language-dependent contents of a type.  */
+
+struct GTY (()) lang_type
+{
+  char dummy;
+};
+
+/* Language-dependent contents of a decl.  */
+
+struct GTY (()) lang_decl
+{
+  char dummy;
+};
+
+/* Language-dependent contents of an identifier.  This must include a
+   tree_identifier.  */
+
+struct GTY (()) lang_identifier
+{
+  struct tree_identifier common;
+};
+
+/* The resulting tree type.  */
+
+union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
+chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), "
+"TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN "
+"(&%h.generic)) : NULL"))) lang_tree_node
+{
+  union tree_node GTY ((tag ("0"),
+desc ("tree_node_structure (&%h)"))) generic;
+  struct lang_identifier GTY ((tag ("1"))) identifier;
+};
+
+/* We don't use language_function.  */
+
+struct GTY (()) language_function
+{
+
+  /* While we are parsing the function, this contains information about
+  the statement-tree that we are building.  */
+  /* struct stmt_tree_s stmt_tree;  */
+  tree stmt_tree;
+};
+
+/* end of new stuff.  */
+
+/* Language hooks.  */
+
+bool
+gm2_langhook_init (void)
+{
+  build_common_tree_nodes (false);
+
+  /* I don't know why this has to be done explicitly.  */
+  void_list_node = build_tree_list (NULL_TREE, void_type_node);
+
+  build_common_builtin_nodes ();
+
+  /* The default precision for floating point numbers.  This is used
+ for floating point constants with abstract type.  This may eventually
+ be controllable by a command line option.  */
+  mpfr_set_default_prec (256);
+
+  /* GNU Modula-2 uses exceptions.  */
+  using_eh_for_cleanups ();
+
+  return true;
+}
+
+/* The option mask.  */
+
+static unsigned int
+gm2_langhook_option_lang_mask (void)
+{
+  return CL_ModulaX2;
+}
+
+/* Initialize the options structure.  */
+
+static void
+gm2_langhook_init_options_struct (struct gcc_options *opts)
+{
+  /* Default to avoiding range issues for complex multiply and divide.  */
+  opts->x_flag_complex_method = 2;
+
+  /* The builtin math functions should not set errno.  */
+  opts->x_flag_errno_math = 0;
+  opts->frontend_set_flag_errno_math = true;
+
+  /* Exceptions are used to handle recovering from panics.  */
+  opts->x_flag_exceptions = 1;
+  opts->x_flag_non_call_exceptions = 1;
+
+  init_FrontEndInit ();
+}
+
+/* Infrastructure for a VEC of bool values.  */
+
+/* This array determines whether the filename is associated with the
+   C preprocessor.  */
+
+static vec filename_cpp;
+
+void
+gm2_langhook_init_options (unsigned int decoded_options_count,
+   struct cl_decoded_option *decoded_options)
+{
+  unsigned int i;
+  bool in_cpp_args = false;
+
+  // filename_cpp = ggc_vec_alloc (decoded_options_count);
+
+  for (i = 1; i < decoded_options_count; i++)
+{
+  switch 

  1   2   >