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 ;
PROCEDURE CalculateStemName (Module: String) : String ;
BEGIN
- RETURN( Slice(Module, 0, MaxStemName) )
+ RETURN Slice (Module, 0, MaxStemName)
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 ;
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 ;
(*
- 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) ;
(*
- 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 ;
CONST
GarbageDebugging = FALSE ;
+ DefaultDefExt = '.def' ;
+ DefaultModExt = '.mod' ;
VAR
Def, Mod: String ;
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 ;
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 ;
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));
#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"
int *args;
/* Have we seen -fmod=? */
- bool seen_module_extension = false;
+ char *module_extension = NULL;
/* Should the driver perform a link? */
bool linking = true;
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;
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;
}
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
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);
--- /dev/null
+MODULE hello ;
+
+FROM liba IMPORT bar ;
+FROM libc IMPORT printf ;
+
+BEGIN
+ bar ;
+ printf ("hello world\n")
+END hello.
--- /dev/null
+DEFINITION MODULE liba ;
+
+CONST
+ max = 12 ;
+
+PROCEDURE bar ;
+
+END liba.
--- /dev/null
+IMPLEMENTATION MODULE liba ;
+
+PROCEDURE bar ;
+END bar ;
+
+END liba.
--- /dev/null
+# 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"
+}