Skip -fwhole-program when merging LTO options.
[official-gcc.git] / gcc / m2 / gm2-compiler / M2Range.def
blobd2bc4f62aea788c714a1e8f42db697454ae298e7
1 (* M2Range.def exports procedures which maintain the range checking.
3 Copyright (C) 2008-2022 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
22 DEFINITION MODULE M2Range ;
25 Title : M2Range
26 Author : Gaius Mulley
27 System : GNU Modula-2
28 Date : Thu Feb 28 10:18:55 2008
29 Revision : $Version$
30 Description: exports procedures which maintain the range checking
31 state which is explored once all the subrange values
32 have been resolved by the front end (once
33 M2GCCDeclare has completed its task). We cannot
34 perform this activity during M2Quads, as we dont
35 know the subrange values and also we can do so much
36 more once optimization has occurred. It should be
37 possible to detect simple overflow errors at compile
38 time, post optimization.
41 FROM SYSTEM IMPORT ADDRESS ;
42 FROM m2tree IMPORT Tree ;
43 FROM m2linemap IMPORT location_t ;
44 FROM DynamicStrings IMPORT String ;
46 EXPORT QUALIFIED InitAssignmentRangeCheck,
47 InitReturnRangeCheck,
48 InitSubrangeRangeCheck,
49 InitStaticArraySubscriptRangeCheck,
50 InitDynamicArraySubscriptRangeCheck,
51 InitIncRangeCheck,
52 InitDecRangeCheck,
53 InitInclCheck,
54 InitExclCheck,
55 InitRotateCheck,
56 InitShiftCheck,
57 InitTypesExpressionCheck,
58 InitTypesAssignmentCheck,
59 InitTypesParameterCheck,
60 InitParameterRangeCheck,
61 InitForLoopBeginRangeCheck,
62 InitForLoopToRangeCheck,
63 InitForLoopEndRangeCheck,
64 InitPointerRangeCheck,
65 InitNoReturnRangeCheck,
66 InitNoElseRangeCheck,
67 InitCaseBounds,
68 InitWholeNonPosDivCheck,
69 InitWholeNonPosModCheck,
70 InitWholeZeroDivisionCheck,
71 InitWholeZeroRemainderCheck,
72 CodeRangeCheck, FoldRangeCheck, CodeErrorCheck,
73 (* CheckRangeAddVariableRead, *)
74 (* CheckRangeRemoveVariableRead, *)
75 WriteRangeCheck,
76 OverlapsRange,
77 IsEqual, IsGreaterOrEqual, IsGreater,
78 BuildIfCallRealHandlerLoc,
79 BuildIfCallWholeHandlerLoc,
80 GetMinMax ;
84 InitAssignmentRangeCheck - returns a range check node which
85 remembers the information necessary
86 so that a range check for d := e
87 can be generated later on.
90 PROCEDURE InitAssignmentRangeCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
94 InitReturnRangeCheck - returns a range check node which
95 remembers the information necessary
96 so that a range check for RETURN e
97 from procedure, d, can be generated later on.
100 PROCEDURE InitReturnRangeCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
104 InitSubrangeRangeCheck - returns a range check node which
105 remembers the information necessary
106 so that a range check for d := e
107 can be generated later on.
110 PROCEDURE InitSubrangeRangeCheck (d, e: CARDINAL) : CARDINAL ;
114 InitStaticArraySubscriptRangeCheck - returns a range check node which
115 remembers the information necessary
116 so that a range check for d[e]
117 can be generated later on.
120 PROCEDURE InitStaticArraySubscriptRangeCheck (d, e, dim: CARDINAL) : CARDINAL ;
124 InitDynamicArraySubscriptRangeCheck - returns a range check node which
125 remembers the information necessary
126 so that a range check for d[e]
127 can be generated later on.
130 PROCEDURE InitDynamicArraySubscriptRangeCheck (d, e, dim: CARDINAL) : CARDINAL ;
134 InitIncRangeCheck - returns a range check node which
135 remembers the information necessary
136 so that a range check for INC(d, e)
137 can be generated later on.
140 PROCEDURE InitIncRangeCheck (d, e: CARDINAL) : CARDINAL ;
144 InitDecRangeCheck - returns a range check node which
145 remembers the information necessary
146 so that a range check for DEC(d, e)
147 can be generated later on.
150 PROCEDURE InitDecRangeCheck (d, e: CARDINAL) : CARDINAL ;
154 InitForLoopBeginRangeCheck - returns a range check node which
155 remembers the information necessary
156 so that a range check for FOR d := e TO .. DO
157 can be generated later on.
160 PROCEDURE InitForLoopBeginRangeCheck (d, e: CARDINAL) : CARDINAL ;
164 InitForLoopToRangeCheck - returns a range check node which
165 remembers the information necessary
166 so that a range check for the final value
167 implied by ... e1 TO e2 BY e3 DO
168 can be generated later on.
171 PROCEDURE InitForLoopToRangeCheck (d, e: CARDINAL) : CARDINAL ;
175 InitForLoopEndRangeCheck - returns a range check node which
176 remembers the information necessary
177 so that a range check for
178 INC or DEC(d, e)
179 can be generated later on.
182 PROCEDURE InitForLoopEndRangeCheck (d, e: CARDINAL) : CARDINAL ;
186 InitPointerRangeCheck - creates a pointer # NIL check.
189 PROCEDURE InitPointerRangeCheck (tokno: CARDINAL;
190 d: CARDINAL; isLeft: BOOLEAN) : CARDINAL ;
194 InitNoReturnRangeCheck - creates a check held in the function
195 to detect the absence of a RETURN
196 statement at runtime.
199 PROCEDURE InitNoReturnRangeCheck () : CARDINAL ;
203 InitNoElseRangeCheck - creates a check held at the end of
204 a CASE statement without an ELSE
205 clause to detect its absence
206 at runtime.
209 PROCEDURE InitNoElseRangeCheck () : CARDINAL ;
213 InitWholeNonPosDivCheck - creates a check expression for non positive
214 or zero 2nd operand to division.
217 PROCEDURE InitWholeNonPosDivCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
221 InitWholeNonPosModCheck - creates a check expression for non positive
222 or zero 2nd operand to modulus.
225 PROCEDURE InitWholeNonPosModCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
229 InitWholeZeroDivisionCheck - creates a check expression for zero 2nd
230 operand for division.
233 PROCEDURE InitWholeZeroDivisionCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
237 InitWholeZeroRemainderCheck - creates a check expression for zero 2nd
238 operand for remainder.
241 PROCEDURE InitWholeZeroRemainderCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
245 InitInclCheck - checks to see that bit, e, is type compatible with
246 d and also in range.
249 PROCEDURE InitInclCheck (d, e: CARDINAL) : CARDINAL ;
253 InitExclCheck - checks to see that bit, e, is type compatible with
254 d and also in range.
257 PROCEDURE InitExclCheck (d, e: CARDINAL) : CARDINAL ;
261 InitShiftCheck - checks to see that bit, e, is type compatible with
262 d and also in range.
265 PROCEDURE InitShiftCheck (d, e: CARDINAL) : CARDINAL ;
269 InitRotateCheck - checks to see that bit, e, is type compatible with
270 d and also in range.
273 PROCEDURE InitRotateCheck (d, e: CARDINAL) : CARDINAL ;
277 InitTypesAssignmentCheck - checks to see that the types of, d, and, e,
278 are assignment compatible.
281 PROCEDURE InitTypesAssignmentCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
285 InitTypesParameterCheck - checks to see that the types of, d, and, e,
286 are parameter compatible.
289 PROCEDURE InitTypesParameterCheck (proc: CARDINAL; i: CARDINAL;
290 formal, actual: CARDINAL) : CARDINAL ;
294 InitParameterRangeCheck - checks to see that the types of, d, and, e,
295 are parameter compatible.
298 PROCEDURE InitParameterRangeCheck (proc: CARDINAL; i: CARDINAL;
299 formal, actual: CARDINAL) : CARDINAL ;
303 InitTypesExpressionCheck - checks to see that the types of, d, and, e,
304 are expression compatible.
307 PROCEDURE InitTypesExpressionCheck (tokno: CARDINAL; d, e: CARDINAL;
308 strict, isin: BOOLEAN) : CARDINAL ;
312 InitCaseBounds - creates a case bound range check.
315 PROCEDURE InitCaseBounds (b: CARDINAL) : CARDINAL ;
319 CodeRangeCheck - creates a sequence of Trees representing the code for a
320 range test defined by, r.
323 PROCEDURE CodeRangeCheck (r: CARDINAL; function: String) ;
327 FoldRangeCheck - returns a Tree representing the code for a
328 range test defined by, r.
331 PROCEDURE FoldRangeCheck (tokenno: CARDINAL; q: CARDINAL; r: CARDINAL) ;
335 CodeErrorCheck - returns a Tree calling the approprate exception handler.
338 PROCEDURE CodeErrorCheck (r: CARDINAL; function, message: String) : Tree ;
342 CheckRangeAddVariableRead - ensures that any references to reading
343 variables used by this range check, r,
344 at this, quadNo, are recorded in the
345 symbol table.
348 (* PROCEDURE CheckRangeAddVariableRead (r: CARDINAL; quadNo: CARDINAL) ; *)
352 CheckRangeRemoveVariableRead - ensures that any references to reading
353 variable at this quadNo are removed from
354 the symbol table.
357 (* PROCEDURE CheckRangeRemoveVariableRead (r: CARDINAL; quadNo: CARDINAL) ; *)
361 WriteRangeCheck - displays debugging information about range, r.
364 PROCEDURE WriteRangeCheck (r: CARDINAL) ;
368 OverlapsRange - returns TRUE if a1..a2 overlaps with b1..b2.
371 PROCEDURE OverlapsRange (a1, a2, b1, b2: Tree) : BOOLEAN ;
375 IsEqual - returns TRUE if a=b.
378 PROCEDURE IsEqual (a, b: Tree) : BOOLEAN ;
382 IsGreaterOrEqual - returns TRUE if a>=b.
385 PROCEDURE IsGreaterOrEqual (a, b: Tree) : BOOLEAN ;
389 IsGreater - returns TRUE if a>b.
392 PROCEDURE IsGreater (a, b: Tree) : BOOLEAN ;
396 BuildIfCallWholeHandlerLoc - return a Tree containing a runtime test whether, condition, is true.
399 PROCEDURE BuildIfCallWholeHandlerLoc (location: location_t; condition: Tree;
400 scope, message: ADDRESS) : Tree ;
404 BuildIfCallRealHandlerLoc - return a Tree containing a runtime test whether, condition, is true.
407 PROCEDURE BuildIfCallRealHandlerLoc (location: location_t; condition: Tree;
408 scope, message: ADDRESS) : Tree ;
412 GetMinMax - returns TRUE if we know the max and min of a type, t.
415 PROCEDURE GetMinMax (tokenno: CARDINAL; type: CARDINAL; VAR min, max: Tree) : BOOLEAN ;
418 END M2Range.