]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-compiler/M2Range.def
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-compiler / M2Range.def
1 (* M2Range.def exports procedures which maintain the range checking.
2
3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6 This file is part of GNU Modula-2.
7
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.
12
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.
17
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/>. *)
21
22 DEFINITION MODULE M2Range ;
23
24 (*
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.
39 *)
40
41 FROM SYSTEM IMPORT ADDRESS ;
42 FROM m2tree IMPORT Tree ;
43 FROM m2linemap IMPORT location_t ;
44 FROM DynamicStrings IMPORT String ;
45
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 ;
81
82
83 (*
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.
88 *)
89
90 PROCEDURE InitAssignmentRangeCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
91
92
93 (*
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.
98 *)
99
100 PROCEDURE InitReturnRangeCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
101
102
103 (*
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.
108 *)
109
110 PROCEDURE InitSubrangeRangeCheck (d, e: CARDINAL) : CARDINAL ;
111
112
113 (*
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.
118 *)
119
120 PROCEDURE InitStaticArraySubscriptRangeCheck (d, e, dim: CARDINAL) : CARDINAL ;
121
122
123 (*
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.
128 *)
129
130 PROCEDURE InitDynamicArraySubscriptRangeCheck (d, e, dim: CARDINAL) : CARDINAL ;
131
132
133 (*
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.
138 *)
139
140 PROCEDURE InitIncRangeCheck (d, e: CARDINAL) : CARDINAL ;
141
142
143 (*
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.
148 *)
149
150 PROCEDURE InitDecRangeCheck (d, e: CARDINAL) : CARDINAL ;
151
152
153 (*
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.
158 *)
159
160 PROCEDURE InitForLoopBeginRangeCheck (d, e: CARDINAL) : CARDINAL ;
161
162
163 (*
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.
169 *)
170
171 PROCEDURE InitForLoopToRangeCheck (d, e: CARDINAL) : CARDINAL ;
172
173
174 (*
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.
180 *)
181
182 PROCEDURE InitForLoopEndRangeCheck (d, e: CARDINAL) : CARDINAL ;
183
184
185 (*
186 InitPointerRangeCheck - creates a pointer # NIL check.
187 *)
188
189 PROCEDURE InitPointerRangeCheck (tokno: CARDINAL;
190 d: CARDINAL; isLeft: BOOLEAN) : CARDINAL ;
191
192
193 (*
194 InitNoReturnRangeCheck - creates a check held in the function
195 to detect the absence of a RETURN
196 statement at runtime.
197 *)
198
199 PROCEDURE InitNoReturnRangeCheck () : CARDINAL ;
200
201
202 (*
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.
207 *)
208
209 PROCEDURE InitNoElseRangeCheck () : CARDINAL ;
210
211
212 (*
213 InitWholeNonPosDivCheck - creates a check expression for non positive
214 or zero 2nd operand to division.
215 *)
216
217 PROCEDURE InitWholeNonPosDivCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
218
219
220 (*
221 InitWholeNonPosModCheck - creates a check expression for non positive
222 or zero 2nd operand to modulus.
223 *)
224
225 PROCEDURE InitWholeNonPosModCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
226
227
228 (*
229 InitWholeZeroDivisionCheck - creates a check expression for zero 2nd
230 operand for division.
231 *)
232
233 PROCEDURE InitWholeZeroDivisionCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
234
235
236 (*
237 InitWholeZeroRemainderCheck - creates a check expression for zero 2nd
238 operand for remainder.
239 *)
240
241 PROCEDURE InitWholeZeroRemainderCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
242
243
244 (*
245 InitInclCheck - checks to see that bit, e, is type compatible with
246 d and also in range.
247 *)
248
249 PROCEDURE InitInclCheck (d, e: CARDINAL) : CARDINAL ;
250
251
252 (*
253 InitExclCheck - checks to see that bit, e, is type compatible with
254 d and also in range.
255 *)
256
257 PROCEDURE InitExclCheck (d, e: CARDINAL) : CARDINAL ;
258
259
260 (*
261 InitShiftCheck - checks to see that bit, e, is type compatible with
262 d and also in range.
263 *)
264
265 PROCEDURE InitShiftCheck (d, e: CARDINAL) : CARDINAL ;
266
267
268 (*
269 InitRotateCheck - checks to see that bit, e, is type compatible with
270 d and also in range.
271 *)
272
273 PROCEDURE InitRotateCheck (d, e: CARDINAL) : CARDINAL ;
274
275
276 (*
277 InitTypesAssignmentCheck - checks to see that the types of, d, and, e,
278 are assignment compatible.
279 *)
280
281 PROCEDURE InitTypesAssignmentCheck (tokno: CARDINAL; d, e: CARDINAL) : CARDINAL ;
282
283
284 (*
285 InitTypesParameterCheck - checks to see that the types of, d, and, e,
286 are parameter compatible.
287 *)
288
289 PROCEDURE InitTypesParameterCheck (proc: CARDINAL; i: CARDINAL;
290 formal, actual: CARDINAL) : CARDINAL ;
291
292
293 (*
294 InitParameterRangeCheck - checks to see that the types of, d, and, e,
295 are parameter compatible.
296 *)
297
298 PROCEDURE InitParameterRangeCheck (proc: CARDINAL; i: CARDINAL;
299 formal, actual: CARDINAL) : CARDINAL ;
300
301
302 (*
303 InitTypesExpressionCheck - checks to see that the types of, d, and, e,
304 are expression compatible.
305 *)
306
307 PROCEDURE InitTypesExpressionCheck (tokno: CARDINAL; d, e: CARDINAL;
308 strict, isin: BOOLEAN) : CARDINAL ;
309
310
311 (*
312 InitCaseBounds - creates a case bound range check.
313 *)
314
315 PROCEDURE InitCaseBounds (b: CARDINAL) : CARDINAL ;
316
317
318 (*
319 CodeRangeCheck - creates a sequence of Trees representing the code for a
320 range test defined by, r.
321 *)
322
323 PROCEDURE CodeRangeCheck (r: CARDINAL; function: String) ;
324
325
326 (*
327 FoldRangeCheck - returns a Tree representing the code for a
328 range test defined by, r.
329 *)
330
331 PROCEDURE FoldRangeCheck (tokenno: CARDINAL; q: CARDINAL; r: CARDINAL) ;
332
333
334 (*
335 CodeErrorCheck - returns a Tree calling the approprate exception handler.
336 *)
337
338 PROCEDURE CodeErrorCheck (r: CARDINAL; function, message: String) : Tree ;
339
340
341 (*
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.
346 *)
347
348 (* PROCEDURE CheckRangeAddVariableRead (r: CARDINAL; quadNo: CARDINAL) ; *)
349
350
351 (*
352 CheckRangeRemoveVariableRead - ensures that any references to reading
353 variable at this quadNo are removed from
354 the symbol table.
355 *)
356
357 (* PROCEDURE CheckRangeRemoveVariableRead (r: CARDINAL; quadNo: CARDINAL) ; *)
358
359
360 (*
361 WriteRangeCheck - displays debugging information about range, r.
362 *)
363
364 PROCEDURE WriteRangeCheck (r: CARDINAL) ;
365
366
367 (*
368 OverlapsRange - returns TRUE if a1..a2 overlaps with b1..b2.
369 *)
370
371 PROCEDURE OverlapsRange (a1, a2, b1, b2: Tree) : BOOLEAN ;
372
373
374 (*
375 IsEqual - returns TRUE if a=b.
376 *)
377
378 PROCEDURE IsEqual (a, b: Tree) : BOOLEAN ;
379
380
381 (*
382 IsGreaterOrEqual - returns TRUE if a>=b.
383 *)
384
385 PROCEDURE IsGreaterOrEqual (a, b: Tree) : BOOLEAN ;
386
387
388 (*
389 IsGreater - returns TRUE if a>b.
390 *)
391
392 PROCEDURE IsGreater (a, b: Tree) : BOOLEAN ;
393
394
395 (*
396 BuildIfCallWholeHandlerLoc - return a Tree containing a runtime test whether, condition, is true.
397 *)
398
399 PROCEDURE BuildIfCallWholeHandlerLoc (location: location_t; condition: Tree;
400 scope, message: ADDRESS) : Tree ;
401
402
403 (*
404 BuildIfCallRealHandlerLoc - return a Tree containing a runtime test whether, condition, is true.
405 *)
406
407 PROCEDURE BuildIfCallRealHandlerLoc (location: location_t; condition: Tree;
408 scope, message: ADDRESS) : Tree ;
409
410
411 (*
412 GetMinMax - returns TRUE if we know the max and min of a type, t.
413 *)
414
415 PROCEDURE GetMinMax (tokenno: CARDINAL; type: CARDINAL; VAR min, max: Tree) : BOOLEAN ;
416
417
418 END M2Range.