From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1499) id 2A8C33858D39; Fri, 4 Mar 2022 18:30:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A8C33858D39 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Gaius Mulley To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/modula-2] M2Quads.mod allow TSIZE and TBITSIZE to calculate size of pointers. X-Act-Checkin: gcc X-Git-Author: q X-Git-Refname: refs/heads/devel/modula-2 X-Git-Oldrev: 11470d2c217175bb308dc4dade4f6f28103df1da X-Git-Newrev: c684b7809ef1db61e6e649b5b5771e0ff28371b8 Message-Id: <20220304183010.2A8C33858D39@sourceware.org> Date: Fri, 4 Mar 2022 18:30:10 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2022 18:30:10 -0000 https://gcc.gnu.org/g:c684b7809ef1db61e6e649b5b5771e0ff28371b8 commit c684b7809ef1db61e6e649b5b5771e0ff28371b8 Author: q Date: Fri Mar 4 18:27:11 2022 +0000 M2Quads.mod allow TSIZE and TBITSIZE to calculate size of pointers. This patch allows TSIZE (ptr^) irrespective of the value of ptr. It also allows TBITSIZE (ptr^). It extends the solution in the implementation of SIZE for both TBITSIZE and TSIZE. gcc/m2/ChangeLog: * gm2-compiler/M2Quads.mod (BuildSizeCheckEnd): Extended to include TSize and TBitSize. (BuildTSizeFunction) Call BuildSizeCheckEnd. (BuildTBitSizeFunction) Call BuildSizeCheckEnd. gcc/testsuite/gm2/ChangeLog: * pim/run/pass/testsize4.mod: (New file). * pim/run/pass/testtbitsize.mod: (New file). Signed-off-by: Diff: --- gcc/m2/gm2-compiler/M2Quads.mod | 12 ++++---- gcc/testsuite/gm2/pim/run/pass/testsize4.mod | 37 +++++++++++++++++++++++++ gcc/testsuite/gm2/pim/run/pass/testtbitsize.mod | 34 +++++++++++++++++++++++ gm2tools/Makefile.in | 2 +- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod index cb84066b1f2..a388c2ace94 100644 --- a/gcc/m2/gm2-compiler/M2Quads.mod +++ b/gcc/m2/gm2-compiler/M2Quads.mod @@ -4332,10 +4332,10 @@ VAR ProcSym, Type, tok: CARDINAL ; BEGIN PopTFtok (ProcSym, Type, tok) ; - IF ProcSym=Size + IF (ProcSym=Size) OR (ProcSym=TSize) OR (ProcSym=TBitSize) THEN QuadrupleGeneration := FALSE ; - BuildingSize := TRUE ; + BuildingSize := TRUE ELSIF ProcSym=High THEN QuadrupleGeneration := FALSE ; @@ -4352,10 +4352,10 @@ END BuildSizeCheckStart ; PROCEDURE BuildSizeCheckEnd (ProcSym: CARDINAL) ; BEGIN - IF ProcSym=Size + IF (ProcSym=Size) OR (ProcSym=TSize) OR (ProcSym=TBitSize) THEN QuadrupleGeneration := TRUE ; - BuildingSize := FALSE ; + BuildingSize := FALSE ELSIF ProcSym=High THEN QuadrupleGeneration := TRUE ; @@ -9551,6 +9551,7 @@ BEGIN PopT (NoOfParam) ; ProcSym := OperandT (NoOfParam + 1) ; functok := OperandTtok (NoOfParam) ; + BuildSizeCheckEnd (ProcSym) ; (* quadruple generation now on *) IF NoOfParam = 1 THEN paramtok := OperandTtok (1) ; @@ -9562,7 +9563,7 @@ BEGIN ELSIF IsVar (OperandT (1)) THEN ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; - GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, GetSType(OperandT(1)), FALSE) + GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, GetSType (OperandT (1)), FALSE) ELSE MetaErrorT1 (resulttok, '{%E}SYSTEM procedure function {%kTSIZE} expects a variable as its first parameter, seen {%E1d}', @@ -9637,6 +9638,7 @@ BEGIN PopT (NoOfParam) ; ProcSym := OperandT (NoOfParam + 1) ; functok := OperandTtok (NoOfParam) ; + BuildSizeCheckEnd (ProcSym) ; (* quadruple generation now on *) IF NoOfParam = 1 THEN paramtok := OperandTtok (1) ; diff --git a/gcc/testsuite/gm2/pim/run/pass/testsize4.mod b/gcc/testsuite/gm2/pim/run/pass/testsize4.mod new file mode 100644 index 00000000000..5f9c8018e63 --- /dev/null +++ b/gcc/testsuite/gm2/pim/run/pass/testsize4.mod @@ -0,0 +1,37 @@ +(* Copyright (C) 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 2, 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 gm2; see the file COPYING. If not, write to the Free Software +Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) + +MODULE testsize4 ; + +FROM SYSTEM IMPORT TSIZE ; +FROM libc IMPORT printf ; + +TYPE + ptr = POINTER TO CARDINAL ; + +VAR + foo: ptr ; + bar: CARDINAL ; +BEGIN + foo := NIL ; + (* should be able to dereference an initialized pointer using TSIZE. *) + bar := TSIZE (foo^) ; + printf ("result of TSIZE (foo^) is %d\n", bar) ; + (* and SIZE. *) + bar := SIZE (foo^) ; + printf ("result of SIZE (foo^) is %d\n", bar) +END testsize4. diff --git a/gcc/testsuite/gm2/pim/run/pass/testtbitsize.mod b/gcc/testsuite/gm2/pim/run/pass/testtbitsize.mod new file mode 100644 index 00000000000..1e893c73abc --- /dev/null +++ b/gcc/testsuite/gm2/pim/run/pass/testtbitsize.mod @@ -0,0 +1,34 @@ +(* Copyright (C) 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 2, 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 gm2; see the file COPYING. If not, write to the Free Software +Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) + +MODULE testtbitsize ; + +FROM SYSTEM IMPORT TBITSIZE ; +FROM libc IMPORT printf ; + +TYPE + ptr = POINTER TO CARDINAL ; + +VAR + foo: ptr ; + bar: CARDINAL ; +BEGIN + foo := NIL ; + (* should be able to dereference an initialized pointer using TBITSIZE. *) + bar := TBITSIZE (foo^) ; + printf ("result of TBITSIZE (foo^) is %d\n", bar) +END testtbitsize. diff --git a/gm2tools/Makefile.in b/gm2tools/Makefile.in index d228a6a9b39..386f2e4163a 100644 --- a/gm2tools/Makefile.in +++ b/gm2tools/Makefile.in @@ -639,8 +639,8 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -@NATIVE_FALSE@install-exec-local: @NATIVE_FALSE@uninstall-local: +@NATIVE_FALSE@install-exec-local: clean: clean-am clean-am: clean-binPROGRAMS clean-generic mostlyclean-am