diff options
author | Gaius Mulley <gaiusmod2@gmail.com> | 2023-03-29 17:38:22 +0100 |
---|---|---|
committer | Gaius Mulley <gaiusmod2@gmail.com> | 2023-03-29 17:38:22 +0100 |
commit | 3be4e43a6a0f429648ea188c8e110b74268fed27 (patch) | |
tree | ad07cf9e70e6dcd9d12ef9dd7a289ab538a04acd | |
parent | b2f327b9be81326c9e59fc6da98074c909ac7408 (diff) | |
download | gcc-3be4e43a6a0f429648ea188c8e110b74268fed27.zip gcc-3be4e43a6a0f429648ea188c8e110b74268fed27.tar.gz gcc-3be4e43a6a0f429648ea188c8e110b74268fed27.tar.bz2 |
PR modula2/109336 - The -fmod= and -fdef= options do not work
The -fmod= and -fdef= options do not work. After the linking
re-implementation and subsequent restructuring the -fmod= amd -fdef= are
now broken. This patch adds -fmod= and -fdef= processing into gm2spec.cc.
It also reduces the complexity of extension handling within M2Search
by storing the preceeding "." in the extension.
gcc/m2/ChangeLog:
PR modula2/109336
PR modula2/109315
* gm2-compiler/M2FileName.mod (CalculateFileName): Simplified by
ensuring the extension contains the ".".
(CalculateStemName): Re-formatted.
(ExtractExtension): Re-formatted.
(ExtractModule): Re-formatted.
* gm2-compiler/M2Options.def (setdefextension): Add block comment.
(setmodextension): Add block comment. Re-formatted.
* gm2-compiler/M2Options.mod (setdefextension): Add block comment.
(setmodextension): Add block comment. Re-formatted.
* gm2-compiler/M2Search.mod (FindSourceDefFile): Use
DefaultDefExt.
(DefaultDefExt): New constant.
(DefaultModExt): New constant.
(FindSourceModFile): Use DefaultModExt.
* gm2-gcc/m2decl.cc (m2decl_DeclareKnownVariable): Correct
spelling.
* gm2spec.cc (M2SOURCE): New constant.
(LANGSPEC): New value.
(MATHLIB): New value.
(WITHLIBC): New value.
(SKIPOPT): New value.
(lang_specific_driver): Replace seen_module_extension bool with
module_extension char *. Detect -fmod= and remember extension.
Use the extension to detect modula-2 source and mark it as such.
gcc/testsuite/ChangeLog:
PR modula2/109336
* gm2/link/nondefaultext/pass/hello.md: New test.
* gm2/link/nondefaultext/pass/liba.dm: New test.
* gm2/link/nondefaultext/pass/liba.md: New test.
* gm2/link/nondefaultext/pass/link-nondefaultext-pass.exp: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
-rw-r--r-- | gcc/m2/gm2-compiler/M2FileName.mod | 18 | ||||
-rw-r--r-- | gcc/m2/gm2-compiler/M2Options.def | 6 | ||||
-rw-r--r-- | gcc/m2/gm2-compiler/M2Options.mod | 18 | ||||
-rw-r--r-- | gcc/m2/gm2-compiler/M2Search.mod | 6 | ||||
-rw-r--r-- | gcc/m2/gm2-gcc/m2decl.cc | 2 | ||||
-rw-r--r-- | gcc/m2/gm2spec.cc | 96 | ||||
-rw-r--r-- | gcc/testsuite/gm2/link/nondefaultext/pass/hello.md | 9 | ||||
-rw-r--r-- | gcc/testsuite/gm2/link/nondefaultext/pass/liba.dm | 8 | ||||
-rw-r--r-- | gcc/testsuite/gm2/link/nondefaultext/pass/liba.md | 6 | ||||
-rwxr-xr-x | gcc/testsuite/gm2/link/nondefaultext/pass/link-nondefaultext-pass.exp | 38 |
10 files changed, 167 insertions, 40 deletions
diff --git a/gcc/m2/gm2-compiler/M2FileName.mod b/gcc/m2/gm2-compiler/M2FileName.mod index 45a77f8..e52df96 100644 --- a/gcc/m2/gm2-compiler/M2FileName.mod +++ b/gcc/m2/gm2-compiler/M2FileName.mod @@ -49,9 +49,9 @@ PROCEDURE CalculateFileName (Module, Extension: String) : String ; BEGIN IF MaxFileName=0 THEN - RETURN( ConCat(ConCatChar(Slice(Module, 0, MaxFileName), '.'), Extension) ) + RETURN ConCat (Slice (Module, 0, MaxFileName), Extension) ELSE - RETURN( ConCat(ConCatChar(Slice(Module, 0, MaxFileName-Length(Extension)-1), '.'), Extension) ) + RETURN ConCat (Slice (Module, 0, MaxFileName-Length (Extension)), Extension) END END CalculateFileName ; @@ -64,7 +64,7 @@ END CalculateFileName ; PROCEDURE CalculateStemName (Module: String) : String ; BEGIN - RETURN( Slice(Module, 0, MaxStemName) ) + RETURN Slice (Module, 0, MaxStemName) END CalculateStemName ; @@ -75,11 +75,11 @@ END CalculateStemName ; PROCEDURE ExtractExtension (filename, ext: String) : String ; BEGIN - IF Equal(ext, Mark(Slice(filename, -Length(ext), 0))) + IF Equal (ext, Mark (Slice (filename, -Length (ext), 0))) THEN - RETURN( Slice(filename, 0, -Length(ext)) ) + RETURN Slice (filename, 0, -Length (ext)) ELSE - RETURN( filename ) + RETURN filename END END ExtractExtension ; @@ -93,12 +93,12 @@ PROCEDURE ExtractModule (filename: String) : String ; VAR i: INTEGER ; BEGIN - i := Index(filename, Directory, 0) ; + i := Index (filename, Directory, 0) ; IF i=-1 THEN - RETURN( Dup(filename) ) + RETURN Dup (filename) ELSE - RETURN( Slice(filename, i+1, 0) ) + RETURN Slice (filename, i+1, 0) END END ExtractModule ; diff --git a/gcc/m2/gm2-compiler/M2Options.def b/gcc/m2/gm2-compiler/M2Options.def index 2be92d5..7e4d2aa 100644 --- a/gcc/m2/gm2-compiler/M2Options.def +++ b/gcc/m2/gm2-compiler/M2Options.def @@ -730,14 +730,16 @@ PROCEDURE SetStrictTypeChecking (value: BOOLEAN) ; (* - setdefextension - + setdefextension - set the source file definition module extension to arg. + This should include the . and by default it is set to .def. *) PROCEDURE setdefextension (arg: ADDRESS) ; (* - setmodextension - + setmodextension - set the source file module extension to arg. + This should include the . and by default it is set to .mod. *) PROCEDURE setmodextension (arg: ADDRESS) ; diff --git a/gcc/m2/gm2-compiler/M2Options.mod b/gcc/m2/gm2-compiler/M2Options.mod index 2b3ed81..7cacee2 100644 --- a/gcc/m2/gm2-compiler/M2Options.mod +++ b/gcc/m2/gm2-compiler/M2Options.mod @@ -959,30 +959,32 @@ END SetSearchPath ; (* - setdefextension - + setdefextension - set the source file definition module extension to arg. + This should include the . and by default it is set to .def. *) PROCEDURE setdefextension (arg: ADDRESS) ; VAR s: String ; BEGIN - s := InitStringCharStar(arg) ; - SetDefExtension(s) ; - s := KillString(s) + s := InitStringCharStar (arg) ; + SetDefExtension (s) ; + s := KillString (s) END setdefextension ; (* - setmodextension - + setmodextension - set the source file module extension to arg. + This should include the . and by default it is set to .mod. *) PROCEDURE setmodextension (arg: ADDRESS) ; VAR s: String ; BEGIN - s := InitStringCharStar(arg) ; - SetModExtension(s) ; - s := KillString(s) + s := InitStringCharStar (arg) ; + SetModExtension (s) ; + s := KillString (s) END setmodextension ; diff --git a/gcc/m2/gm2-compiler/M2Search.mod b/gcc/m2/gm2-compiler/M2Search.mod index 80806bf..5e48f6b 100644 --- a/gcc/m2/gm2-compiler/M2Search.mod +++ b/gcc/m2/gm2-compiler/M2Search.mod @@ -36,6 +36,8 @@ FROM DynamicStrings IMPORT InitString, InitStringChar, CONST GarbageDebugging = FALSE ; + DefaultDefExt = '.def' ; + DefaultModExt = '.mod' ; VAR Def, Mod: String ; @@ -156,7 +158,7 @@ BEGIN f := KillString (f) END ; (* Try the GNU Modula-2 default extension. *) - f := CalculateFileName (Stem, Mark (InitString ('def'))) ; + f := CalculateFileName (Stem, Mark (InitString (DefaultDefExt))) ; RETURN FindSourceFile (f, FullPath, named) END FindSourceDefFile ; @@ -182,7 +184,7 @@ BEGIN f := KillString (f) END ; (* Try the GNU Modula-2 default extension. *) - f := CalculateFileName (Stem, Mark (InitString ('mod'))) ; + f := CalculateFileName (Stem, Mark (InitString (DefaultModExt))) ; RETURN FindSourceFile (f, FullPath, named) END FindSourceModFile ; diff --git a/gcc/m2/gm2-gcc/m2decl.cc b/gcc/m2/gm2-gcc/m2decl.cc index 4fb646e..6dde7a2 100644 --- a/gcc/m2/gm2-gcc/m2decl.cc +++ b/gcc/m2/gm2-gcc/m2decl.cc @@ -122,7 +122,7 @@ m2decl_DeclareKnownVariable (location_t location, const char *name, tree type, error ("storage size of %qD has not been resolved", decl); if ((TREE_PUBLIC (decl) == 0) && DECL_EXTERNAL (decl)) - internal_error ("inconsistant because %qs", + internal_error ("inconsistent because %qs", "PUBLIC_DECL(decl) == 0 && DECL_EXTERNAL(decl) == 1"); m2block_addDeclExpr (build_stmt (location, DECL_EXPR, decl)); diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc index 3b2652c..8b40108 100644 --- a/gcc/m2/gm2spec.cc +++ b/gcc/m2/gm2spec.cc @@ -50,14 +50,16 @@ along with GNU Modula-2; see the file COPYING3. If not see #endif #endif +/* This bit is set if the arguments is a M2 source file. */ +#define M2SOURCE (1<<1) /* This bit is set if we saw a `-xfoo' language specification. */ -#define LANGSPEC (1<<1) +#define LANGSPEC (1<<2) /* This bit is set if they did `-lm' or `-lmath'. */ -#define MATHLIB (1<<2) +#define MATHLIB (1<<3) /* This bit is set if they did `-lc'. */ -#define WITHLIBC (1<<3) +#define WITHLIBC (1<<4) /* Skip this option. */ -#define SKIPOPT (1<<4) +#define SKIPOPT (1<<5) #ifndef MATH_LIBRARY #define MATH_LIBRARY "m" @@ -431,7 +433,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, int *args; /* Have we seen -fmod=? */ - bool seen_module_extension = false; + char *module_extension = NULL; /* Should the driver perform a link? */ bool linking = true; @@ -530,8 +532,11 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, args[i] |= SKIPOPT; /* We will add the option if it is needed. */ break; case OPT_fmod_: - seen_module_extension = true; + module_extension = xstrdup (arg); args[i] |= SKIPOPT; /* We will add the option if it is needed. */ +#if defined(DEBUG_ARG) + printf ("seen -fmod=%s\n", module_extension); +#endif break; case OPT_fpthread: need_pthread = decoded_options[i].value; @@ -674,6 +679,34 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, which_library = (stdcxxlib_kind) decoded_options[i].value; break; + case OPT_SPECIAL_input_file: + { + const char *source_file = decoded_options[i].orig_option_with_args_text; +#if defined(DEBUG_ARG) + printf ("seen OPT_SPECIAL_input_file: %s\n", source_file); +#endif + if (source_file != NULL) + { + /* Record that this is a Modula-2 source file. */ + const char *suffix = strrchr (source_file, '.'); +#if defined(DEBUG_ARG) + printf ("ext = %s\n", suffix); +#endif + if ((suffix != NULL) + && ((strcmp (suffix, ".mod") == 0) + || ((module_extension != NULL) + && (strcmp (suffix, module_extension) == 0)))) + { +#if defined(DEBUG_ARG) + printf ("modula-2 source file detected: %s\n", source_file); +#endif + args[i] |= M2SOURCE; + // args[i] = 0; + } + } + } + break; + default: break; } @@ -719,19 +752,49 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, for (i = 1; i < argc; ++i) { #if defined(DEBUG_ARG) - printf ("2nd pass: %s\n", + printf ("2nd pass: %s", decoded_options[i].orig_option_with_args_text); + if ((args[i] & SKIPOPT) != 0) + printf (" skipped"); + if ((args[i] & M2SOURCE) != 0) + printf (" m2 source"); + printf ("\n"); #endif if ((args[i] & SKIPOPT) == 0) { - append_arg (&decoded_options[i]); - /* Make sure -lstdc++ is before the math library, since libstdc++ - itself uses those math routines. */ - if (!saw_math && (args[i] & MATHLIB) && library > 0) - saw_math = &decoded_options[i]; - - if (!saw_libc && (args[i] & WITHLIBC) && library > 0) - saw_libc = &decoded_options[i]; + if ((args[i] & M2SOURCE) == 0) + { + append_arg (&decoded_options[i]); + /* Make sure -lstdc++ is before the math library, since libstdc++ + itself uses those math routines. */ + if (!saw_math && (args[i] & MATHLIB) && library > 0) + saw_math = &decoded_options[i]; + + if (!saw_libc && (args[i] & WITHLIBC) && library > 0) + saw_libc = &decoded_options[i]; + } + else + { + if ((! seen_x_flag) && module_extension) + { +#if defined(DEBUG_ARG) + printf (" adding: -x modula-2 "); +#endif + append_option (OPT_x, "modula-2", 1); + } + append_arg (&decoded_options[i]); +#if defined(DEBUG_ARG) + printf (" adding: %s\n", + decoded_options[i].orig_option_with_args_text); +#endif + if ((! seen_x_flag) && module_extension) + { +#if defined(DEBUG_ARG) + printf (" adding: -x none "); +#endif + append_option (OPT_x, "none", 1); + } + } } #if defined(DEBUG_ARG) else @@ -789,9 +852,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, else append_option (OPT_flibs_, xstrdup ("-"), 0); /* no system libs. */ - if ((! seen_x_flag) && seen_module_extension) - append_option (OPT_x, "modula-2", 1); - if (need_plugin) append_option (OPT_fplugin_, "m2rte", 1); diff --git a/gcc/testsuite/gm2/link/nondefaultext/pass/hello.md b/gcc/testsuite/gm2/link/nondefaultext/pass/hello.md new file mode 100644 index 0000000..c2f2dcb --- /dev/null +++ b/gcc/testsuite/gm2/link/nondefaultext/pass/hello.md @@ -0,0 +1,9 @@ +MODULE hello ; + +FROM liba IMPORT bar ; +FROM libc IMPORT printf ; + +BEGIN + bar ; + printf ("hello world\n") +END hello. diff --git a/gcc/testsuite/gm2/link/nondefaultext/pass/liba.dm b/gcc/testsuite/gm2/link/nondefaultext/pass/liba.dm new file mode 100644 index 0000000..e86d9e3 --- /dev/null +++ b/gcc/testsuite/gm2/link/nondefaultext/pass/liba.dm @@ -0,0 +1,8 @@ +DEFINITION MODULE liba ; + +CONST + max = 12 ; + +PROCEDURE bar ; + +END liba. diff --git a/gcc/testsuite/gm2/link/nondefaultext/pass/liba.md b/gcc/testsuite/gm2/link/nondefaultext/pass/liba.md new file mode 100644 index 0000000..20d1206 --- /dev/null +++ b/gcc/testsuite/gm2/link/nondefaultext/pass/liba.md @@ -0,0 +1,6 @@ +IMPLEMENTATION MODULE liba ; + +PROCEDURE bar ; +END bar ; + +END liba. diff --git a/gcc/testsuite/gm2/link/nondefaultext/pass/link-nondefaultext-pass.exp b/gcc/testsuite/gm2/link/nondefaultext/pass/link-nondefaultext-pass.exp new file mode 100755 index 0000000..e9e38f7 --- /dev/null +++ b/gcc/testsuite/gm2/link/nondefaultext/pass/link-nondefaultext-pass.exp @@ -0,0 +1,38 @@ +# 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 +# <http://www.gnu.org/licenses/>. + +# This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk) +# for GNU Modula-2. + +if $tracelevel then { + strace $tracelevel +} + +# load support procs +load_lib gm2-torture.exp + +gm2_init_pim "${srcdir}/gm2/link/nondefaultext/pass" +gm2_link_obj "liba.o" + +foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/hello.md]] { + # 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_target_compile $srcdir/$subdir/liba.md liba.o object "-g -fdef=.dm -fmod=.md" + gm2-torture $testcase "-g -fdef=.dm -fmod=.md" +} |