diff options
Diffstat (limited to 'gcc')
23 files changed, 890 insertions, 113 deletions
diff --git a/gcc/common.opt.urls b/gcc/common.opt.urls index c108560..c7f234b 100644 --- a/gcc/common.opt.urls +++ b/gcc/common.opt.urls @@ -159,7 +159,7 @@ Wmissing-noreturn UrlSuffix(gcc/Warning-Options.html#index-Wmissing-noreturn) Wmusttail-local-addr -UrlSuffix(gcc/Warning-Options.html#index-Wno-musttail-local-addr) +UrlSuffix(gcc/Warning-Options.html#index-Wmusttail-local-addr) Wmaybe-musttail-local-addr UrlSuffix(gcc/Warning-Options.html#index-Wmaybe-musttail-local-addr) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 99eeba6..dd29059 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -5436,13 +5436,18 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt) machine_mode mode0 = GET_MODE (op0); machine_mode mode1 = GET_MODE (op1); - /* An integer comparison must be comparing WORD_MODE objects. We - must enforce that so that we don't strip away a sign_extension - thinking it is unnecessary. We might consider using - riscv_extend_operands if they are not already properly extended. */ + /* An integer comparison must be comparing WORD_MODE objects. + Extend the comparison arguments as necessary. */ if ((INTEGRAL_MODE_P (mode0) && mode0 != word_mode) || (INTEGRAL_MODE_P (mode1) && mode1 != word_mode)) - return false; + riscv_extend_comparands (code, &op0, &op1); + + /* We might have been handed back a SUBREG. Just to make things + easy, force it into a REG. */ + if (!REG_P (op0) && !CONST_INT_P (op0)) + op0 = force_reg (word_mode, op0); + if (!REG_P (op1) && !CONST_INT_P (op1)) + op1 = force_reg (word_mode, op1); /* In the fallback generic case use MODE rather than WORD_MODE for the output of the SCC instruction, to match the mode of the NEG diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d7f51b4..189a52b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7060,14 +7060,14 @@ which is enabled by optimizations in most targets. The precision of the warnings depends on the optimization options used. @opindex Wno-musttail-local-addr -@opindex -Wmusttail-local-addr +@opindex Wmusttail-local-addr @item -Wno-musttail-local-addr Do not warn about passing a pointer (or in C++, a reference) to a local variable or label to argument of a @code{musttail} call. Those variables go out of scope before the tail call instruction. @opindex Wmaybe-musttail-local-addr -@opindex -Wno-maybe-musttail-local-addr +@opindex Wno-maybe-musttail-local-addr @item -Wmaybe-musttail-local-addr Warn when address of a local variable can escape to a @code{musttail} call, unless it goes out of scope already before the @code{musttail} diff --git a/gcc/m2/gm2-compiler/P2Build.bnf b/gcc/m2/gm2-compiler/P2Build.bnf index b9a6daa..c28e630 100644 --- a/gcc/m2/gm2-compiler/P2Build.bnf +++ b/gcc/m2/gm2-compiler/P2Build.bnf @@ -46,7 +46,8 @@ see <https://www.gnu.org/licenses/>. *) IMPLEMENTATION MODULE P2Build ; FROM M2LexBuf IMPORT currentstring, currenttoken, GetToken, InsertToken, - InsertTokenAndRewind, GetTokenNo, MakeVirtual2Tok ; + InsertTokenAndRewind, GetTokenNo, MakeVirtual2Tok, + MakeVirtualTok ; FROM M2MetaError IMPORT MetaErrorStringT0, MetaErrorT1 ; FROM NameKey IMPORT NulName, Name, makekey, MakeKey ; @@ -128,13 +129,13 @@ FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, PutGnuAsmInput PutGnuAsmOutput, PutGnuAsmTrash, PutGnuAsmVolatile, MakeRegInterface, PutRegInterface, GetRegInterface, - GetSymName, GetType, MakeConstLit, + GetSymName, GetType, MakeConstLit, IsProcType, NulSym, - StartScope, EndScope, + StartScope, EndScope, GetCurrentModule, PutIncluded, PutExceptionFinally, PutExceptionBlock, GetCurrentScope, IsVarParam, IsProcedure, IsDefImp, IsModule, - IsRecord, IsAModula2Type, + IsRecord, IsAModula2Type, IsImported, RequestSym ; IMPORT M2Error ; @@ -450,6 +451,54 @@ BEGIN Expect(realtok, stopset0, stopset1, stopset2) END Real ; + +(* + CheckModuleQualident - check to see if the beginning ident of the qualident is an + imported module. +*) + +PROCEDURE CheckModuleQualident (stopset0: SetOfStop0; + stopset1: SetOfStop1; + stopset2: SetOfStop2) ; +VAR + name : Name ; + init, + nextLevel, + tok, tokstart: CARDINAL ; +BEGIN + PopTtok (name, tokstart) ; + tok := tokstart ; + init := RequestSym (tok, name) ; + IF IsImported (GetCurrentModule (), init) AND (IsDefImp (init) OR IsModule (init)) + THEN + WHILE IsDefImp (init) OR IsModule (init) DO + Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; + StartScope (init) ; + Ident (stopset0, stopset1, stopset2) ; + PopTtok (name, tok) ; + nextLevel := RequestSym (tok, name) ; + EndScope ; + init := nextLevel + END ; + IF tok#tokstart + THEN + tok := MakeVirtualTok (tokstart, tokstart, tok) + END ; + IF IsProcedure (init) OR IsProcType (init) + THEN + PushTtok (init, tok) + ELSE + Annotate ("%1s(%1d)|%1s(%1d)||qualident|type") ; + PushTFtok (init, GetType (init), tok) ; + END ; + PutIncluded (init) + ELSE + PushTFtok (init, GetType (init), tok) ; + Annotate ("%1s(%1d)|%1s(%1d)||qualident|type") + END +END CheckModuleQualident ; + + % module P2Build end END P2Build. % rules @@ -609,28 +658,10 @@ ImplementationOrProgramModule := ImplementationModule | ProgramModule =: Number := Integer | Real =: -Qualident := % VAR name: Name ; - Type, Sym, tok: CARDINAL ; % - Ident +Qualident := Ident % IF IsAutoPushOn() THEN - PopTtok(name, tok) ; - Sym := RequestSym (tok, name) ; - IF IsDefImp(Sym) OR IsModule(Sym) - THEN - Expect(periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; - StartScope(Sym) ; - Qualident(stopset0, stopset1, stopset2) ; - (* should we test for lack of ident? *) - PopTFtok(Sym, Type, tok) ; - PushTFtok(Sym, Type, tok) ; - Annotate("%1s(%1d)|%1s(%1d)||qualident|type") ; - EndScope ; - PutIncluded(Sym) - ELSE - PushTFtok(Sym, GetType(Sym), tok) ; - Annotate("%1s(%1d)|%1s(%1d)||qualident|type") - END + CheckModuleQualident (stopset0, stopset1, stopset2) ELSE (* just parse qualident *) % { "." Ident } % END % =: diff --git a/gcc/m2/gm2-compiler/P3Build.bnf b/gcc/m2/gm2-compiler/P3Build.bnf index 4f6ffb7..0033d33 100644 --- a/gcc/m2/gm2-compiler/P3Build.bnf +++ b/gcc/m2/gm2-compiler/P3Build.bnf @@ -166,14 +166,14 @@ FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, PutGnuAsmInput MakeRegInterface, PutRegInterface, IsRegInterface, IsGnuAsmVolatile, IsGnuAsm, - GetCurrentModule, + GetCurrentModule, IsInnerModule, GetSymName, GetType, SkipType, NulSym, StartScope, EndScope, PutIncluded, IsVarParam, IsProcedure, IsDefImp, IsModule, IsProcType, IsRecord, - RequestSym, IsExported, + RequestSym, IsExported, IsImported, GetSym, GetLocalSym ; FROM M2Batch IMPORT IsModuleKnown ; @@ -468,6 +468,69 @@ BEGIN Expect(realtok, stopset0, stopset1, stopset2) END Real ; + +(* + PushTFQualident - push the result of the Qualident + to the stack. It checks to see if init + is a procedure or proc type and if so + it does not push the return type. +*) + +PROCEDURE PushTFQualident (tok, tokstart: CARDINAL; + init: CARDINAL) ; +BEGIN + IF tok#tokstart + THEN + tok := MakeVirtualTok (tokstart, tokstart, tok) + END ; + IF IsProcedure (init) OR IsProcType (init) OR IsModule (init) OR IsDefImp (init) + THEN + PushTtok (init, tok) ; + Annotate ("%1s(%1d)||qualident procedure/proctype") ; + ELSE + Annotate ("%1s(%1d)|%1s(%1d)||qualident|type") ; + PushTFtok (init, GetType (init), tok) ; + END +END PushTFQualident ; + + +(* + CheckModuleQualident - check to see if the beginning ident of the qualident is an + imported module. +*) + +PROCEDURE CheckModuleQualident (stopset0: SetOfStop0; + stopset1: SetOfStop1; + stopset2: SetOfStop2) ; +VAR + name : Name ; + init, + nextLevel, + tok, tokstart: CARDINAL ; +BEGIN + PopTtok (name, tokstart) ; + tok := tokstart ; + init := RequestSym (tok, name) ; + IF (IsImported (GetCurrentModule (), init) AND IsDefImp (init)) OR + IsModule (init) + THEN + WHILE IsDefImp (init) OR IsModule (init) DO + Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; + StartScope (init) ; + Ident (stopset0, stopset1, stopset2) ; + PopTtok (name, tok) ; + nextLevel := RequestSym (tok, name) ; + EndScope ; + CheckCanBeImported (init, nextLevel) ; + init := nextLevel + END ; + PushTFQualident (tok, tokstart, init) ; + PutIncluded (init) + ELSE + PushTFQualident (tok, tokstart, init) + END +END CheckModuleQualident ; + % module P3Build end BEGIN BlockState := InitState () @@ -643,37 +706,11 @@ Number := Integer | Real =: -- IsAutoPushOff then we just consume tokens. -- -Qualident := % VAR name : Name ; - init, ip1, - tokstart, tok : CARDINAL ; % - Ident +Qualident := Ident % IF IsAutoPushOn() THEN - PopTtok(name, tokstart) ; - tok := tokstart ; - init := RequestSym (tok, name) ; - WHILE IsDefImp (init) OR IsModule (init) DO - Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; - StartScope (init) ; - Ident (stopset0, stopset1, stopset2) ; - PopTtok (name, tok) ; - ip1 := RequestSym (tok, name) ; - PutIncluded(ip1) ; - EndScope ; - CheckCanBeImported(init, ip1) ; - init := ip1 - END ; - IF tok#tokstart - THEN - tok := MakeVirtualTok (tokstart, tokstart, tok) - END ; - IF IsProcedure(init) OR IsProcType(init) - THEN - PushTtok(init, tok) - ELSE - PushTFtok(init, GetType(init), tok) ; - END - ELSE % + CheckModuleQualident (stopset0, stopset1, stopset2) + ELSE (* just parse qualident *) % { "." Ident } % END % =: diff --git a/gcc/m2/gm2-compiler/PCBuild.bnf b/gcc/m2/gm2-compiler/PCBuild.bnf index a05a55f..ddbe2f1 100644 --- a/gcc/m2/gm2-compiler/PCBuild.bnf +++ b/gcc/m2/gm2-compiler/PCBuild.bnf @@ -65,7 +65,7 @@ FROM M2Quads IMPORT Top, PushT, PopT, PushTF, PopTF, PopNothing, OperandT, Opera PushTFA, PushTFn, PopTFn, PushTFtok, PopTtok, PopTFtok, PushTtok, PushTFntok, PushT, PushTF, IsAutoPushOn, PushAutoOff, PushAutoOn, PopAuto, - DupFrame, + DupFrame, Annotate, BuildTypeForConstructor, BuildConstructor, BuildConstructorEnd, PopConstructor, NextConstructorField, SilentBuildConstructor, @@ -118,6 +118,7 @@ FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, PutGnuAsmInput PutIncluded, IsVarParam, IsProcedure, IsDefImp, IsModule, IsRecord, IsProcType, + GetCurrentModule, IsInnerModule, IsImported, RequestSym, GetSym, GetLocalSym ; @@ -412,6 +413,68 @@ BEGIN Expect(realtok, stopset0, stopset1, stopset2) END Real ; + +(* + PushTFQualident - push the result of the Qualident + to the stack. It checks to see if init + is a procedure or proc type and if so + it does not push the return type. +*) + +PROCEDURE PushTFQualident (tok, tokstart: CARDINAL; + init: CARDINAL) ; +BEGIN + IF tok#tokstart + THEN + tok := MakeVirtualTok (tokstart, tokstart, tok) + END ; + IF IsProcedure (init) OR IsProcType (init) + THEN + PushTtok (init, tok) ; + Annotate ("%1s(%1d)||qualident procedure/proctype") ; + ELSE + Annotate ("%1s(%1d)|%1s(%1d)||qualident|type") ; + PushTFtok (init, GetType (init), tok) ; + END +END PushTFQualident ; + + +(* + CheckModuleQualident - check to see if the beginning ident of the qualident is an + imported module. +*) + +PROCEDURE CheckModuleQualident (stopset0: SetOfStop0; + stopset1: SetOfStop1; + stopset2: SetOfStop2) ; +VAR + name : Name ; + init, + nextLevel, + tok, tokstart: CARDINAL ; +BEGIN + PopTtok (name, tokstart) ; + tok := tokstart ; + init := RequestSym (tok, name) ; + IF IsImported (GetCurrentModule (), init) AND (IsDefImp (init) OR IsModule (init)) + THEN + WHILE IsDefImp (init) OR IsModule (init) DO + Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; + StartScope (init) ; + Ident (stopset0, stopset1, stopset2) ; + PopTtok (name, tok) ; + nextLevel := RequestSym (tok, name) ; + EndScope ; + CheckCanBeImported (init, nextLevel) ; + init := nextLevel + END ; + PushTFQualident (tok, tokstart, init) ; + PutIncluded (init) + ELSE + PushTFQualident (tok, tokstart, init) + END +END CheckModuleQualident ; + % module PCBuild end BEGIN BlockState := InitState () @@ -569,37 +632,11 @@ ImplementationOrProgramModule := % Pus Number := Integer | Real =: -Qualident := % VAR name : Name ; - init, ip1, - tokstart, tok : CARDINAL ; % - Ident +Qualident := Ident % IF IsAutoPushOn() THEN - PopTtok(name, tokstart) ; - tok := tokstart ; - init := RequestSym (tok, name) ; - WHILE IsDefImp (init) OR IsModule (init) DO - Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; - StartScope (init) ; - Ident (stopset0, stopset1, stopset2) ; - PopTtok (name, tok) ; - ip1 := RequestSym (tok, name) ; - PutIncluded(ip1) ; - EndScope ; - CheckCanBeImported(init, ip1) ; - init := ip1 - END ; - IF tok#tokstart - THEN - tok := MakeVirtualTok (tokstart, tokstart, tok) - END ; - IF IsProcedure(init) OR IsProcType(init) - THEN - PushTtok(init, tok) - ELSE - PushTFtok(init, GetType(init), tok) ; - END - ELSE % + CheckModuleQualident (stopset0, stopset1, stopset2) + ELSE (* just parse qualident *) % { "." Ident } % END % =: diff --git a/gcc/m2/gm2-compiler/PHBuild.bnf b/gcc/m2/gm2-compiler/PHBuild.bnf index 7bd5bcc..8153870 100644 --- a/gcc/m2/gm2-compiler/PHBuild.bnf +++ b/gcc/m2/gm2-compiler/PHBuild.bnf @@ -130,12 +130,12 @@ FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, PutGnuAsmInput PutGnuAsmOutput, PutGnuAsmTrash, PutGnuAsmVolatile, MakeRegInterface, PutRegInterface, GetRegInterface, - GetSymName, GetType, + GetSymName, GetType, GetCurrentModule, NulSym, StartScope, EndScope, PutIncluded, IsVarParam, IsProcedure, IsDefImp, IsModule, - IsRecord, IsProcType, + IsRecord, IsProcType, IsInnerModule, IsImported, RequestSym, GetSym, GetLocalSym ; @@ -368,6 +368,68 @@ BEGIN Expect(realtok, stopset0, stopset1, stopset2) END Real ; + +(* + PushTFQualident - push the result of the Qualident + to the stack. It checks to see if init + is a procedure or proc type and if so + it does not push the return type. +*) + +PROCEDURE PushTFQualident (tok, tokstart: CARDINAL; + init: CARDINAL) ; +BEGIN + IF tok#tokstart + THEN + tok := MakeVirtualTok (tokstart, tokstart, tok) + END ; + IF IsProcedure (init) OR IsProcType (init) + THEN + PushTtok (init, tok) ; + Annotate ("%1s(%1d)||qualident procedure/proctype") ; + ELSE + Annotate ("%1s(%1d)|%1s(%1d)||qualident|type") ; + PushTFtok (init, GetType (init), tok) ; + END +END PushTFQualident ; + + +(* + CheckModuleQualident - check to see if the beginning ident of the qualident is an + imported module. +*) + +PROCEDURE CheckModuleQualident (stopset0: SetOfStop0; + stopset1: SetOfStop1; + stopset2: SetOfStop2) ; +VAR + name : Name ; + init, + nextLevel, + tok, tokstart: CARDINAL ; +BEGIN + PopTtok (name, tokstart) ; + tok := tokstart ; + init := RequestSym (tok, name) ; + IF IsImported (GetCurrentModule (), init) AND (IsDefImp (init) OR IsModule (init)) + THEN + WHILE IsDefImp (init) OR IsModule (init) DO + Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; + StartScope (init) ; + Ident (stopset0, stopset1, stopset2) ; + PopTtok (name, tok) ; + nextLevel := RequestSym (tok, name) ; + EndScope ; + CheckCanBeImported (init, nextLevel) ; + init := nextLevel + END ; + PushTFQualident (tok, tokstart, init) ; + PutIncluded (init) + ELSE + PushTFQualident (tok, tokstart, init) + END +END CheckModuleQualident ; + % module PHBuild end END PHBuild. % rules @@ -541,26 +603,10 @@ ImplementationOrProgramModule := % Pus Number := Integer | Real =: -Qualident := % VAR name: Name ; - Type, Sym, tok: CARDINAL ; % - Ident +Qualident := Ident % IF IsAutoPushOn() THEN - PopTtok(name, tok) ; - Sym := RequestSym (tok, name) ; - IF IsDefImp(Sym) OR IsModule(Sym) - THEN - Expect(periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ; - StartScope(Sym) ; - Qualident(stopset0, stopset1, stopset2) ; - (* should we test for lack of ident? *) - PopTFtok(Sym, Type, tok) ; - PushTFtok(Sym, Type, tok) ; - EndScope ; - PutIncluded(Sym) - ELSE - PushTFtok(Sym, GetType(Sym), tok) ; - END + CheckModuleQualident (stopset0, stopset1, stopset2) ELSE (* just parse qualident *) % { "." Ident } % END % =: diff --git a/gcc/m2/gm2-libs/ARRAYOFCHAR.def b/gcc/m2/gm2-libs/ARRAYOFCHAR.def new file mode 100644 index 0000000..451eb56 --- /dev/null +++ b/gcc/m2/gm2-libs/ARRAYOFCHAR.def @@ -0,0 +1,41 @@ +(* ARRAYOFCHAR.def provides output procedures for the ARRAY OF CHAR datatype. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +DEFINITION MODULE ARRAYOFCHAR ; + +FROM FIO IMPORT File ; + + +(* + Description: provides write and read procedures for + ARRAY OF CHAR. +*) + +PROCEDURE Write (f: File; str: ARRAY OF CHAR) ; +PROCEDURE WriteLn (f: File) ; + + +END ARRAYOFCHAR. diff --git a/gcc/m2/gm2-libs/ARRAYOFCHAR.mod b/gcc/m2/gm2-libs/ARRAYOFCHAR.mod new file mode 100644 index 0000000..f27378a --- /dev/null +++ b/gcc/m2/gm2-libs/ARRAYOFCHAR.mod @@ -0,0 +1,56 @@ +(* ARRAYOFCHAR.def provides output procedures for the ARRAY OF CHAR datatype. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +IMPLEMENTATION MODULE ARRAYOFCHAR ; + +FROM FIO IMPORT WriteChar, WriteLine ; +IMPORT StrLib ; + + +(* + Write - writes a string to file f. +*) + +PROCEDURE Write (f: File; a: ARRAY OF CHAR) ; +VAR + len, i: CARDINAL ; +BEGIN + len := StrLib.StrLen (a) ; + i := 0 ; + WHILE i < len DO + WriteChar (f, a[i]) ; + INC (i) + END +END Write ; + + +PROCEDURE WriteLn (f: File) ; +BEGIN + WriteLine (f) +END WriteLn ; + + +END ARRAYOFCHAR. diff --git a/gcc/m2/gm2-libs/CFileSysOp.def b/gcc/m2/gm2-libs/CFileSysOp.def new file mode 100644 index 0000000..1be2135 --- /dev/null +++ b/gcc/m2/gm2-libs/CFileSysOp.def @@ -0,0 +1,56 @@ +DEFINITION MODULE CFileSysOp ; + +FROM SYSTEM IMPORT ADDRESS ; + + +(* + Description: provides access to filesystem operations. + The implementation module is written in C + and the parameters behave as their C + counterparts. +*) + +TYPE + AccessMode = SET OF AccessStatus ; + AccessStatus = (F_OK, R_OK, W_OK, X_OK, A_FAIL) ; + + +PROCEDURE Unlink (filename: ADDRESS) : INTEGER ; + + +(* + Access - test access to a path or file. The behavior is + the same as defined in access(2). Except that + on A_FAIL is only used during the return result + indicating the underlying C access has returned + -1 (and errno can be checked). +*) + +PROCEDURE Access (pathname: ADDRESS; mode: AccessMode) : AccessMode ; + + +(* Return TRUE if the caller can see the existance of the file or + directory on the filesystem. *) + +(* + IsDir - return true if filename is a regular directory. +*) + +PROCEDURE IsDir (dirname: ADDRESS) : BOOLEAN ; + + +(* + IsFile - return true if filename is a regular file. +*) + +PROCEDURE IsFile (filename: ADDRESS) : BOOLEAN ; + + +(* + Exists - return true if pathname exists. +*) + +PROCEDURE Exists (pathname: ADDRESS) : BOOLEAN ; + + +END CFileSysOp. diff --git a/gcc/m2/gm2-libs/CHAR.def b/gcc/m2/gm2-libs/CHAR.def new file mode 100644 index 0000000..71a6791 --- /dev/null +++ b/gcc/m2/gm2-libs/CHAR.def @@ -0,0 +1,40 @@ +(* CHAR.def provides output procedures for the CHAR datatype. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +DEFINITION MODULE CHAR ; + +FROM FIO IMPORT File ; + + +(* + Write a single character ch to file f. +*) + +PROCEDURE Write (f: File; ch: CHAR) ; +PROCEDURE WriteLn (f: File) ; + + +END CHAR. diff --git a/gcc/m2/gm2-libs/CHAR.mod b/gcc/m2/gm2-libs/CHAR.mod new file mode 100644 index 0000000..9673e25 --- /dev/null +++ b/gcc/m2/gm2-libs/CHAR.mod @@ -0,0 +1,48 @@ +(* CHAR.mod provides output procedures for the CHAR datatype. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +IMPLEMENTATION MODULE CHAR ; + +IMPORT FIO ; + + +(* + Write a single character ch to file f. +*) + +PROCEDURE Write (f: File; ch: CHAR) ; +BEGIN + FIO.WriteChar (f, ch) +END Write ; + + +PROCEDURE WriteLn (f: File) ; +BEGIN + FIO.WriteLine (f) +END WriteLn ; + + +END CHAR. diff --git a/gcc/m2/gm2-libs/FileSysOp.def b/gcc/m2/gm2-libs/FileSysOp.def new file mode 100644 index 0000000..64ba392 --- /dev/null +++ b/gcc/m2/gm2-libs/FileSysOp.def @@ -0,0 +1,44 @@ +(* FileSysOp.def provides procedures to manipulate the file system. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +DEFINITION MODULE FileSysOp ; + +FROM CFileSysOp IMPORT AccessMode ; + + +(* + Description: provides access to filesystem operations using + Modula-2 base types. +*) + +PROCEDURE Exists (filename: ARRAY OF CHAR) : BOOLEAN ; +PROCEDURE IsDir (dirname: ARRAY OF CHAR) : BOOLEAN ; +PROCEDURE IsFile (filename: ARRAY OF CHAR) : BOOLEAN ; +PROCEDURE Unlink (filename: ARRAY OF CHAR) : BOOLEAN ; +PROCEDURE Access (pathname: ARRAY OF CHAR; mode: AccessMode) : AccessMode ; + + +END FileSysOp. diff --git a/gcc/m2/gm2-libs/FileSysOp.mod b/gcc/m2/gm2-libs/FileSysOp.mod new file mode 100644 index 0000000..c418c22 --- /dev/null +++ b/gcc/m2/gm2-libs/FileSysOp.mod @@ -0,0 +1,98 @@ +(* FileSysOp.mod provides procedures to manipulate the file system. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +IMPLEMENTATION MODULE FileSysOp ; + +IMPORT StringFileSysOp ; +FROM DynamicStrings IMPORT String, InitString, KillString ; + + +(* + Description: provides access to filesystem operations using + Modula-2 base types. +*) + +PROCEDURE Exists (filename: ARRAY OF CHAR) : BOOLEAN ; +VAR + fn : String ; + result: BOOLEAN ; +BEGIN + fn := InitString (filename) ; + result := StringFileSysOp.Exists (fn) ; + fn := KillString (fn) ; + RETURN result +END Exists ; + + +PROCEDURE IsDir (dirname: ARRAY OF CHAR) : BOOLEAN ; +VAR + fn : String ; + result: BOOLEAN ; +BEGIN + fn := InitString (dirname) ; + result := StringFileSysOp.IsDir (fn) ; + fn := KillString (fn) ; + RETURN result +END IsDir ; + + +PROCEDURE IsFile (filename: ARRAY OF CHAR) : BOOLEAN ; +VAR + fn : String ; + result: BOOLEAN ; +BEGIN + fn := InitString (filename) ; + result := StringFileSysOp.IsFile (fn) ; + fn := KillString (fn) ; + RETURN result +END IsFile ; + + +PROCEDURE Unlink (filename: ARRAY OF CHAR) : BOOLEAN ; +VAR + fn : String ; + result: BOOLEAN ; +BEGIN + fn := InitString (filename) ; + result := StringFileSysOp.Unlink (fn) ; + fn := KillString (fn) ; + RETURN result +END Unlink ; + + +PROCEDURE Access (pathname: ARRAY OF CHAR; mode: AccessMode) : AccessMode ; +VAR + pn : String ; + result: AccessMode ; +BEGIN + pn := InitString (pathname) ; + result := StringFileSysOp.Access (pn, mode) ; + pn := KillString (pn) ; + RETURN result +END Access ; + + +END FileSysOp. diff --git a/gcc/m2/gm2-libs/String.def b/gcc/m2/gm2-libs/String.def new file mode 100644 index 0000000..972232d --- /dev/null +++ b/gcc/m2/gm2-libs/String.def @@ -0,0 +1,35 @@ +(* String.def provides output procedures for the String datatype. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +DEFINITION MODULE String ; + +FROM DynamicStrings IMPORT String ; +FROM FIO IMPORT File ; + +PROCEDURE Write (f: File; str: String) ; +PROCEDURE WriteLn (f: File) ; + +END String. diff --git a/gcc/m2/gm2-libs/String.mod b/gcc/m2/gm2-libs/String.mod new file mode 100644 index 0000000..5dfbb3f --- /dev/null +++ b/gcc/m2/gm2-libs/String.mod @@ -0,0 +1,51 @@ +(* String.mod provides output procedures for the String datatype. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +IMPLEMENTATION MODULE String ; + +IMPORT DynamicStrings, CHAR ; + + +PROCEDURE Write (f: File; str: String) ; +VAR + i, len: CARDINAL ; +BEGIN + i := 0 ; + len := DynamicStrings.Length (str) ; + WHILE i < len DO + CHAR.Write (f, DynamicStrings.char (str, i)) ; + INC (i) + END +END Write ; + + +PROCEDURE WriteLn (f: File) ; +BEGIN + CHAR.WriteLn (f) +END WriteLn ; + + +END String. diff --git a/gcc/m2/gm2-libs/StringFileSysOp.def b/gcc/m2/gm2-libs/StringFileSysOp.def new file mode 100644 index 0000000..ce1d05a --- /dev/null +++ b/gcc/m2/gm2-libs/StringFileSysOp.def @@ -0,0 +1,40 @@ +(* StringFileSysOp.def provides procedures to manipulate the file system. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +DEFINITION MODULE StringFileSysOp ; + +FROM DynamicStrings IMPORT String ; +FROM CFileSysOp IMPORT AccessMode ; + + +PROCEDURE Exists (filename: String) : BOOLEAN ; +PROCEDURE IsDir (dirname: String) : BOOLEAN ; +PROCEDURE IsFile (filename: String) : BOOLEAN ; +PROCEDURE Unlink (filename: String) : BOOLEAN ; +PROCEDURE Access (pathname: String; mode: AccessMode) : AccessMode ; + + +END StringFileSysOp. diff --git a/gcc/m2/gm2-libs/StringFileSysOp.mod b/gcc/m2/gm2-libs/StringFileSysOp.mod new file mode 100644 index 0000000..3cf9ef9 --- /dev/null +++ b/gcc/m2/gm2-libs/StringFileSysOp.mod @@ -0,0 +1,63 @@ +(* StringFileSysOp.mod provides procedures to manipulate the file system. + +Copyright (C) 2025 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaiusmod2@gmail.com>. + +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 +<http://www.gnu.org/licenses/>. *) + +IMPLEMENTATION MODULE StringFileSysOp ; + +IMPORT CFileSysOp ; +FROM DynamicStrings IMPORT string ; + + +PROCEDURE Exists (filename: String) : BOOLEAN ; +BEGIN + RETURN CFileSysOp.Exists (string (filename)) +END Exists ; + + +PROCEDURE IsDir (dirname: String) : BOOLEAN ; +BEGIN + RETURN CFileSysOp.IsDir (string (dirname)) +END IsDir ; + + +PROCEDURE IsFile (filename: String) : BOOLEAN ; +BEGIN + RETURN CFileSysOp.IsFile (string (filename)) +END IsFile ; + + +PROCEDURE Unlink (filename: String) : BOOLEAN ; +BEGIN + RETURN CFileSysOp.Unlink (string (filename)) = 0 +END Unlink ; + + +PROCEDURE Access (pathname: String; mode: AccessMode) : AccessMode ; +BEGIN + RETURN CFileSysOp.Access (string (pathname), mode) +END Access ; + + +END StringFileSysOp. diff --git a/gcc/testsuite/gm2/iso/fail/CHAR.mod b/gcc/testsuite/gm2/iso/fail/CHAR.mod new file mode 100644 index 0000000..0e7d43e --- /dev/null +++ b/gcc/testsuite/gm2/iso/fail/CHAR.mod @@ -0,0 +1,7 @@ +MODULE CHAR ; + +IMPORT CHAR ; + +BEGIN + CHAR.Write ("h") +END CHAR. diff --git a/gcc/testsuite/gm2/iso/run/pass/CHAR.mod b/gcc/testsuite/gm2/iso/run/pass/CHAR.mod new file mode 100644 index 0000000..4ca86b8 --- /dev/null +++ b/gcc/testsuite/gm2/iso/run/pass/CHAR.mod @@ -0,0 +1,7 @@ +MODULE CHAR ; + +FROM libc IMPORT printf ; + +BEGIN + printf ("hello world\n") +END CHAR. diff --git a/gcc/testsuite/gm2/iso/run/pass/importself.mod b/gcc/testsuite/gm2/iso/run/pass/importself.mod new file mode 100644 index 0000000..06cf717 --- /dev/null +++ b/gcc/testsuite/gm2/iso/run/pass/importself.mod @@ -0,0 +1,14 @@ +MODULE importself ; + +IMPORT importself ; + + +PROCEDURE foo ; +BEGIN + +END foo ; + +BEGIN + foo ; + importself.foo +END importself. diff --git a/gcc/testsuite/gm2/pimlib/run/pass/testwrite.mod b/gcc/testsuite/gm2/pimlib/run/pass/testwrite.mod new file mode 100644 index 0000000..ce1f035 --- /dev/null +++ b/gcc/testsuite/gm2/pimlib/run/pass/testwrite.mod @@ -0,0 +1,8 @@ +MODULE testwrite ; + +IMPORT ARRAYOFCHAR ; +FROM FIO IMPORT StdOut ; + +BEGIN + ARRAYOFCHAR.Write (StdOut, "hello world") ; ARRAYOFCHAR.WriteLn (StdOut) +END testwrite. diff --git a/gcc/testsuite/gm2/pimlib/run/pass/testwritechar.mod b/gcc/testsuite/gm2/pimlib/run/pass/testwritechar.mod new file mode 100644 index 0000000..c2f739d --- /dev/null +++ b/gcc/testsuite/gm2/pimlib/run/pass/testwritechar.mod @@ -0,0 +1,13 @@ +MODULE testwritechar ; + +IMPORT CHAR ; +FROM FIO IMPORT StdOut ; + +BEGIN + CHAR.Write (StdOut, 'h') ; + CHAR.Write (StdOut, 'e') ; + CHAR.Write (StdOut, 'l') ; + CHAR.Write (StdOut, 'l') ; + CHAR.Write (StdOut, 'o') ; + CHAR.WriteLn (StdOut) +END testwritechar. |