]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/gm2-gcc/m2expr.def
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-gcc / m2expr.def
CommitLineData
1eee94d3
GM
1(* m2expr.def definition module for m2expr.cc.
2
83ffe9cd 3Copyright (C) 2011-2023 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Modula-2; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. *)
21
22DEFINITION MODULE FOR "C" m2expr ;
23
24FROM SYSTEM IMPORT ADDRESS ;
25FROM m2tree IMPORT Tree ;
26FROM m2linemap IMPORT location_t ;
27
28
29TYPE
30 BuildBinCheckProcedure = PROCEDURE (location_t, Tree, Tree, Tree, Tree, Tree) : Tree ;
31 BuildBinProcedure = PROCEDURE (location_t, Tree, Tree, BOOLEAN) : Tree ;
32 BuildUnaryProcedure = PROCEDURE (location_t, Tree, BOOLEAN) : Tree ;
33 BuildUnaryCheckProcedure = PROCEDURE (location_t, Tree, Tree, Tree, Tree) : Tree ;
34 BuildExprProcedure = PROCEDURE (location_t, Tree, Tree) : Tree ;
35 BuildSetProcedure = PROCEDURE (location_t, Tree, Tree, Tree, Tree, BOOLEAN) ;
36 BuildUnarySetProcedure = PROCEDURE (location_t, Tree, BOOLEAN) ;
37 BuildUnarySetFunction = PROCEDURE (location_t, Tree, BOOLEAN) : Tree ;
38
39
40(*
41 init - initialise this module.
42*)
43
44PROCEDURE init (location: location_t) ;
45
46
47(*
48 CompareTrees - returns -1 if e1 < e2, 0 if e1 == e2, and 1 if e1 > e2.
49*)
50
51PROCEDURE CompareTrees (e1: Tree; e2: Tree) : INTEGER ;
52
53
54PROCEDURE GetPointerOne (location: location_t) : Tree ;
55
56
57PROCEDURE GetPointerZero (location: location_t) : Tree ;
58
59
60PROCEDURE GetWordOne (location: location_t) : Tree ;
61
62
63PROCEDURE GetWordZero (location: location_t) : Tree ;
64
65
66PROCEDURE GetIntegerOne (location: location_t) : Tree ;
67
68
69PROCEDURE GetIntegerZero (location: location_t) : Tree ;
70
71
72PROCEDURE GetCardinalOne (location: location_t) : Tree ;
73
74
75PROCEDURE GetCardinalZero (location: location_t) : Tree ;
76
77
78PROCEDURE GetSizeOfInBits (type: Tree) : Tree ;
79
80
81PROCEDURE GetSizeOf (location: location_t; type: Tree) : Tree ;
82
83
84(*
85 BuildLogicalRotate - builds the ISO Modula-2 ROTATE operator
86 for a fundamental data type.
87*)
88
89PROCEDURE BuildLogicalRotate (location: location_t; op1: Tree; op2: Tree; op3: Tree; nBits: Tree; needconvert: BOOLEAN) ;
90
91
92(*
93 BuildLRRn - builds and returns tree (op1 rotate right by op2 bits)
94 it rotates a set of size, nBits.
95*)
96
97PROCEDURE BuildLRRn (location: location_t; op1: Tree; op2: Tree; nBits: Tree; needconvert: BOOLEAN) : Tree ;
98
99
100(*
101 BuildLRLn - builds and returns tree (op1 rotate left by op2 bits)
102 it rotates a set of size, nBits.
103*)
104
105PROCEDURE BuildLRLn (location: location_t; op1: Tree; op2: Tree; nBits: Tree; needconvert: BOOLEAN) : Tree ;
106
107
108
109PROCEDURE BuildMask (location: location_t; nBits: Tree; needconvert: BOOLEAN) : Tree ;
110
111
112(*
113 BuildMult - builds a multiplication tree.
114*)
115
116PROCEDURE BuildMult (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
117
118
119(*
120 BuildMultCheck - builds a multiplication tree after checking for overflow.
121*)
122
123PROCEDURE BuildMultCheck (location: location_t; op1, op2, lowest, min, max: Tree) : Tree ;
124
125
126(*
127 BuildLRR - builds and returns tree (op1 rotate right by op2 bits)
128*)
129
130PROCEDURE BuildLRR (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
131
132
133(*
134 BuildLRL - builds and returns tree (op1 rotate left by op2 bits)
135*)
136
137PROCEDURE BuildLRL (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
138
139
140(*
141 BuildLogicalShift - builds the ISO Modula-2 SHIFT operator
142 for a fundamental data type.
143*)
144
145PROCEDURE BuildLogicalShift (location: location_t; op1: Tree; op2: Tree; op3: Tree; nBits: Tree; needconvert: BOOLEAN) ;
146
147
148(*
149 BuildLSR - builds and returns tree (op1 >> op2)
150*)
151
152PROCEDURE BuildLSR (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
153
154
155(*
156 BuildLSL - builds and returns tree (op1 << op2)
157*)
158
159PROCEDURE BuildLSL (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
160
161
162(*
163 BuildDivM2 - build and return ((op2 < 0) : (op1 divtrunc op2) ? (op1 divfloor op2))
164 when -fiso, -fpim4 or -fpositive-mod-floor-div is present else
165 return op1 div trunc op2
166*)
167
168PROCEDURE BuildDivM2 (location: location_t; op1, op2: Tree; needsconvert: BOOLEAN) : Tree ;
169
170
171(*
172 BuildDivM2Check - build and return ((op2 < 0) : (op1 divtrunc op2) ? (op1 divfloor op2))
173 when -fiso, -fpim4 or -fpositive-mod-floor-div is present else
174 return op1 div trunc op2. Use the checking div equivalents.
175*)
176
177PROCEDURE BuildDivM2Check (location: location_t; op1, op2, lowest, min, max: Tree) : Tree ;
178
179
180(*
181 BuildModM2 - build and return ((op2 < 0) : (op1 divtrunc op2) ? (op1 divfloor op2))
182 when -fiso, -fpim4 or -fpositive-mod-floor-div is present else
183 return op1 div trunc op2
184*)
185
186PROCEDURE BuildModM2 (location: location_t; op1, op2: Tree; needsconvert: BOOLEAN) : Tree ;
187
188
189(*
190 BuildModM2Check - if iso or pim4 then build and return ((op2 < 0) : (op1
191 modceil op2) ? (op1 modfloor op2)) otherwise use modtrunc.
192 Use the checking mod equivalents.
193 build and return ((op2 < 0) : (op1 divtrunc op2) ? (op1 divfloor op2))
194 when -fiso, -fpim4 or -fpositive-mod-floor-div is present else
195 return op1 div trunc op2. Use the checking div equivalents.
196*)
197
198PROCEDURE BuildModM2Check (location: location_t; op1, op2, lowest, min, max: Tree) : Tree ;
199
200
201(*
202 BuildModFloor - builds a modulus tree.
203*)
204
205PROCEDURE BuildModFloor (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
206
207
208(*
209 BuildDivCeil - builds a division tree.
210*)
211
212PROCEDURE BuildDivCeil (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
213
214
215(*
216 BuildModCeil - builds a modulus tree.
217*)
218
219PROCEDURE BuildModCeil (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
220
221
222(*
223 BuildDivFloor - builds a division tree.
224*)
225
226PROCEDURE BuildDivFloor (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
227
228
229(*
230 BuildModTrunc - builds a modulus tree.
231*)
232
233PROCEDURE BuildModTrunc (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
234
235
236(*
237 BuildDivTrunc - builds a division tree.
238*)
239
240PROCEDURE BuildDivTrunc (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
241
242
243(*
244 BuildDivTruncCheck - builds a division tree after checking for overflow.
245*)
246
247PROCEDURE BuildDivTruncCheck (location: location_t; op1, op2, lowest, min, max: Tree) : Tree ;
248
249
250(*
251 BuildRDiv - builds a division tree (this should only be used for REAL and COMPLEX
252 types and NEVER for integer based types).
253*)
254
255PROCEDURE BuildRDiv (location: location_t; op1, op2: Tree; needconvert: BOOLEAN) : Tree ;
256
257
258(*
259 BuildSubCheck - builds a subtraction tree after checking for overflow.
260*)
261
262PROCEDURE BuildSubCheck (location: location_t; op1, op2, lowest, min, max: Tree) : Tree ;
263
264
265(*
266 BuildAddCheck - builds an addition tree after checking for overflow.
267*)
268
269PROCEDURE BuildAddCheck (location: location_t; op1, op2, lowest, min, max: Tree) : Tree ;
270
271
272(*
273 BuildSub - builds a subtraction tree.
274*)
275
276PROCEDURE BuildSub (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
277
278
279(*
280 BuildAdd - builds an addition tree.
281*)
282
283PROCEDURE BuildAdd (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
284
285
286(*
287 FoldAndStrip - return expression, t, after it has been folded (if possible).
288*)
289
290PROCEDURE FoldAndStrip (t: Tree) : Tree ;
291
292
293(*
294 StringLength - returns an unsigned int which is the length
295 of, string.
296*)
297
298PROCEDURE StringLength (string: Tree) : CARDINAL ;
299
300
301(*
302 TreeOverflow - returns TRUE if the contant expression, t, has
303 caused an overflow. No error message or warning
304 is emitted and no modification is made to, t.
305*)
306
307PROCEDURE TreeOverflow (t: Tree) : BOOLEAN ;
308
309
310(*
311 RemoveOverflow - if tree, t, is a constant expression it removes
312 any overflow flag and returns, t.
313*)
314
315PROCEDURE RemoveOverflow (t: Tree) : Tree ;
316
317
318(*
319 BuildCoerce - returns a tree containing the expression, expr, after
320 it has been coersed to, type.
321*)
322
323PROCEDURE BuildCoerce (location: location_t; des: Tree; type: Tree; expr: Tree) : Tree ;
324
325
326(*
327 BuildTrunc - returns an integer expression from a REAL or LONGREAL op1.
328*)
329
330PROCEDURE BuildTrunc (op1: Tree) : Tree ;
331
332
333(*
334 BuildNegate - builds a negate expression and returns the tree.
335*)
336
337PROCEDURE BuildNegate (location: location_t; op1: Tree; needconvert: BOOLEAN) : Tree ;
338
339
340(*
341 BuildNegateCheck - builds a negate expression and returns the tree.
342*)
343
344PROCEDURE BuildNegateCheck (location: location_t; arg, lowest, min, max: Tree) : Tree ;
345
346
347(*
348 BuildSetNegate - builds a set negate expression and returns the tree.
349*)
350
351PROCEDURE BuildSetNegate (location: location_t; op1: Tree; needconvert: BOOLEAN) : Tree ;
352
353
354(*
355 BuildTBitSize - returns the minimum number of bits to represent, type.
356*)
357
358PROCEDURE BuildTBitSize (location: location_t; type: Tree) : Tree ;
359
360
361(*
362 BuildSize - builds a SIZE function expression and returns the tree.
363*)
364
365PROCEDURE BuildSize (location: location_t; op1: Tree; needconvert: BOOLEAN) : Tree ;
366
367
368(*
369 BuildAddr - builds an expression which calculates the address of
370 op1 and returns the tree.
371*)
372
373PROCEDURE BuildAddr (location: location_t; op1: Tree; needconvert: BOOLEAN) : Tree ;
374
375
376(*
377 BuildOffset1 - builds an expression containing the number of bytes the field
378 is offset from the start of the record structure.
379 This function is the same as the above, except that it
380 derives the record from the field and then calls BuildOffset.
381 The expression is returned.
382*)
383
384PROCEDURE BuildOffset1 (location: location_t; field: Tree; needconvert: BOOLEAN) : Tree ;
385
386
387(*
388 BuildOffset - builds an expression containing the number of bytes the field
389 is offset from the start of the record structure.
390 The expression is returned.
391*)
392
393PROCEDURE BuildOffset (location: location_t; record: Tree; field: Tree; needconvert: BOOLEAN) : Tree ;
394
395
396(*
397 BuildLogicalOrAddress - build a logical or expressions and return the tree.
398*)
399
400PROCEDURE BuildLogicalOrAddress (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
401
402
403(*
404 BuildLogicalOr - build a logical or expressions and return the tree.
405*)
406
407PROCEDURE BuildLogicalOr (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
408
409
410(*
411 BuildLogicalAnd - build a logical and expression and return the tree.
412*)
413
414PROCEDURE BuildLogicalAnd (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
415
416
417
418PROCEDURE BuildSymmetricDifference (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
419
420
421(*
422 BuildLogicalDifference - build a logical difference expression and
423 return the tree.
424 (op1 and (not op2))
425*)
426
427PROCEDURE BuildLogicalDifference (location: location_t; op1: Tree; op2: Tree; needconvert: BOOLEAN) : Tree ;
428
429
430(*
431 BuildLessThan - return a tree which computes <
432*)
433
434PROCEDURE BuildLessThan (location: location_t; op1: Tree; op2: Tree) : Tree ;
435
436
437(*
438 BuildGreaterThan - return a tree which computes >
439*)
440
441PROCEDURE BuildGreaterThan (location: location_t; op1: Tree; op2: Tree) : Tree ;
442
443
444(*
445 BuildLessThanOrEqual - return a tree which computes <
446*)
447
448PROCEDURE BuildLessThanOrEqual (location: location_t; op1: Tree; op2: Tree) : Tree ;
449
450
451(*
452 BuildGreaterThanOrEqual - return a tree which computes >=
453*)
454
455PROCEDURE BuildGreaterThanOrEqual (location: location_t; op1: Tree; op2: Tree) : Tree ;
456
457
458(*
459 BuildEqualTo - return a tree which computes =
460*)
461
462PROCEDURE BuildEqualTo (location: location_t; op1: Tree; op2: Tree) : Tree ;
463
464
465
466PROCEDURE BuildNotEqualTo (location: location_t; op1: Tree; op2: Tree) : Tree ;
467
468
469(*
470 BuildIsSuperset - return a tree which computes: op1 & op2 == op2
471*)
472
473PROCEDURE BuildIsSuperset (location: location_t; op1: Tree; op2: Tree) : Tree ;
474
475
476(*
477 BuildIsNotSuperset - return a tree which computes: op1 & op2 != op2
478*)
479
480PROCEDURE BuildIsNotSuperset (location: location_t; op1: Tree; op2: Tree) : Tree ;
481
482
483(*
484 BuildIsSubset - return a tree which computes: op1 & op2 == op1
485*)
486
487PROCEDURE BuildIsSubset (location: location_t; op1: Tree; op2: Tree) : Tree ;
488
489
490(*
491 BuildIsNotSubset - return a tree which computes: op1 & op2 != op1
492*)
493
494PROCEDURE BuildIsNotSubset (location: location_t; op1: Tree; op2: Tree) : Tree ;
495
496
497(*
498 BuildIfConstInVar - generates: if constel in varset then goto label.
499*)
500
501PROCEDURE BuildIfConstInVar (location: location_t; type: Tree; varset: Tree; constel: Tree; is_lvalue: BOOLEAN; fieldno: INTEGER; label: ADDRESS) ;
502
503
504
505PROCEDURE BuildIfNotConstInVar (location: location_t; type: Tree; varset: Tree; constel: Tree; is_lvalue: BOOLEAN; fieldno: INTEGER; label: ADDRESS) ;
506
507
508(*
509 BuildIfVarInVar - generates: if varel in varset then goto label
510*)
511
512PROCEDURE BuildIfVarInVar (location: location_t; type: Tree; varset: Tree; varel: Tree; is_lvalue: BOOLEAN; low: Tree; high: Tree; label: ADDRESS) ;
513
514
515(*
516 BuildIfNotVarInVar - generates: if not (varel in varset) then goto label
517*)
518
519PROCEDURE BuildIfNotVarInVar (location: location_t; type: Tree; varset: Tree; varel: Tree; is_lvalue: BOOLEAN; low: Tree; high: Tree; label: ADDRESS) ;
520
521
522(*
523 BuildForeachWordInSetDoIfExpr - foreach word in set, type, compute the expression, expr, and if true
524 goto label.
525*)
526
527PROCEDURE BuildForeachWordInSetDoIfExpr (location: location_t;
528 type, op1, op2: Tree;
529 is_op1lvalue, is_op2lvalue,
530 is_op1const, isop2const: BOOLEAN;
531 expr: BuildExprProcedure; label: ADDRESS) ;
532
533
534(*
535 BuildIfInRangeGoto - if var is in the range low..high then goto label
536*)
537
538PROCEDURE BuildIfInRangeGoto (location: location_t; var: Tree; low: Tree; high: Tree; label: ADDRESS) ;
539
540
541(*
542 BuildIfNotInRangeGoto - if var is not in the range low..high then goto label
543*)
544
545PROCEDURE BuildIfNotInRangeGoto (location: location_t; var: Tree; low: Tree; high: Tree; label: ADDRESS) ;
546
547
548(*
549 BuildArray - returns a tree which accesses array[index]
550 given, lowIndice.
551*)
552
553PROCEDURE BuildArray (location: location_t; type: Tree; array: Tree; index: Tree; lowIndice: Tree) : Tree ;
554
555
556(*
557 BuildComponentRef - build a component reference tree which accesses record.field.
558 If field does not belong to record it calls
559 BuildComponentRef on the penultimate field.
560*)
561
562PROCEDURE BuildComponentRef (location: location_t; record: Tree; field: Tree) : Tree ;
563
564
565(*
566 BuildIndirect - build: ( *target) given that the object to be copied is of, type.
567*)
568
569PROCEDURE BuildIndirect (location: location_t; target: Tree; type: Tree) : Tree ;
570
571
572(*
573 IsTrue - returns TRUE if, t, is known to be TRUE.
574*)
575
576PROCEDURE IsTrue (t: Tree) : BOOLEAN ;
577
578
579(*
580 IsFalse - returns FALSE if, t, is known to be FALSE.
581*)
582
583PROCEDURE IsFalse (t: Tree) : BOOLEAN ;
584
585
586(*
587 AreConstantsEqual - maps onto tree.c (tree_int_cst_equal). It returns
588 TRUE if the value of e1 is the same as e2.
589*)
590
591PROCEDURE AreConstantsEqual (e1: Tree; e2: Tree) : BOOLEAN ;
592
593
594(*
595 AreRealOrComplexConstantsEqual - returns TRUE if constants,
596 e1 and e2 are equal according
597 to IEEE rules. This does not
598 perform bit equivalence for
599 example IEEE states that
600 -0 == 0 and NaN != NaN.
601*)
602
603PROCEDURE AreRealOrComplexConstantsEqual (e1: Tree; e2: Tree) : BOOLEAN ;
604
605
606(*
607 DetermineSign - returns -1 if e<0
608 0 if e==0
609 1 if e>0
610
611 an unsigned constant will never return -1
612*)
613
614PROCEDURE DetermineSign (e: Tree) : INTEGER ;
615
616
617(*
618 BuildCap - builds the Modula-2 function CAP(t) and returns
619 the result in a gcc Tree.
620*)
621
622PROCEDURE BuildCap (location: location_t; t: Tree) : Tree ;
623
624
625(*
626 BuildAbs - builds the Modula-2 function ABS(t) and returns
627 the result in a gcc Tree.
628*)
629
630PROCEDURE BuildAbs (location: location_t; t: Tree) : Tree ;
631
632
633(*
634 BuildRe - builds an expression for the function RE.
635*)
636
637PROCEDURE BuildRe (op1: Tree) : Tree ;
638
639
640(*
641 BuildIm - builds an expression for the function IM.
642*)
643
644PROCEDURE BuildIm (op1: Tree) : Tree ;
645
646
647(*
648 BuildCmplx - builds an expression for the function CMPLX.
649*)
650
651PROCEDURE BuildCmplx (location: location_t; type: Tree; real: Tree; imag: Tree) : Tree ;
652
653
654(*
655 BuildBinaryForeachWordDo - provides the large set operators. Each word
656 (or less) of the set can be calculated by binop.
657 This procedure runs along each word of the
658 large set invoking the binop.
659*)
660
661PROCEDURE BuildBinaryForeachWordDo (location: location_t;
662 type, op1, op2, op3: Tree;
663 binop: BuildBinProcedure;
664 is_op1lvalue,
665 is_op2lvalue,
666 is_op3lvalue,
667 is_op1_const,
668 is_op2_const,
669 is_op3_const: BOOLEAN) ;
670
671(*
672 BuildBinarySetDo - if the size of the set is <= TSIZE(WORD) then
673 op1 := binop(op2, op3)
674 else
675 call m2rtsprocedure(op1, op2, op3)
676*)
677
678PROCEDURE BuildBinarySetDo (location: location_t;
679 settype, op1, op2, op3: Tree;
680 binop: BuildSetProcedure;
681 is_op1lvalue, is_op2lvalue, is_op3lvalue: BOOLEAN;
682 nBits, unbounded: Tree;
683 varproc, leftproc, rightproc: Tree) ;
684
685(*
686 ConstantExpressionWarning - issue a warning if the constant has overflowed.
687*)
688
689PROCEDURE ConstantExpressionWarning (value: Tree) ;
690
691
692(*
693 BuildAddAddress - returns an expression op1+op2 where op1 is a pointer type
694 and op2 is not a pointer type.
695*)
696
697PROCEDURE BuildAddAddress (location: location_t; op1, op2: Tree) : Tree ;
698
699
700END m2expr.