Debian Codegraph @

gcc/m2/gm2-compiler/M2System.mod

raw
1 (* M2System.mod defines the SYSTEM builtin types.
2
3 Copyright (C) 2001-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
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 IMPLEMENTATION MODULE M2System ;
23
24 (*
25 Title : M2System
26 Author : Gaius Mulley
27 System : UNIX (gm2)
28 Date : Mon Jul 10 20:24:31 2000
29 Description: gcc version of M2System. It defines the builtin types within the
30 SYSTEM.def module. Remember that these modules (SYSTEM.def, SYSTEM.mod)
31 really exist, but not all type definitions are expressed in this file.
32 We also need to tell the compiler the size of the data types.
33 *)
34
35 FROM SymbolTable IMPORT NulSym,
36 StartScope,
37 EndScope,
38 MakeConstLit,
39 MakeConstVar,
40 MakePointer,
41 MakeType,
42 MakeProcedure,
43 MakeSet,
44 MakeSubrange,
45 PutFunction,
46 PutType, PutPointer,
47 PutSet, PutVar,
48 PutSubrange,
49 PutExportQualified,
50 PutProcedureNoReturn,
51 GetSym, GetSymName,
52 GetCurrentModule, SetCurrentModule,
53 IsLegal, ProcedureKind,
54 PopValue,
55 PopSize ;
56
57 FROM Assertion IMPORT Assert ;
58 FROM M2LexBuf IMPORT BuiltinTokenNo ;
59 FROM M2Options IMPORT Iso, Pim2, Pedantic, DumpSystemExports ;
60 FROM NameKey IMPORT Name, MakeKey, NulName ;
61 FROM M2Batch IMPORT MakeDefinitionSource ;
62 FROM M2Base IMPORT Cardinal, ZType ;
63 FROM M2Size IMPORT Size, MakeSize ;
64 FROM M2ALU IMPORT PushCard, PushIntegerTree, PushRealTree, DivTrunc ;
65 FROM M2Error IMPORT InternalError ;
66 FROM Lists IMPORT List, InitList, IsItemInList, PutItemIntoList, GetItemFromList, NoOfItemsInList ;
67 FROM SymbolKey IMPORT SymbolTree, InitTree, GetSymKey, PutSymKey ;
68 FROM StrLib IMPORT StrEqual ;
69 FROM M2Printf IMPORT printf1 ;
70 FROM SymbolConversion IMPORT Mod2Gcc ;
71
72 FROM M2Base IMPORT Real, Cardinal, Integer, Complex,
73 LongReal, LongCard, LongInt, LongComplex,
74 ShortReal, ShortCard, ShortInt, ShortComplex ;
75
76 FROM gcctypes IMPORT tree ;
77 FROM m2linemap IMPORT BuiltinsLocation ;
78 FROM m2decl IMPORT GetBitsPerBitset, GetBitsPerUnit ;
79
80 FROM m2type IMPORT GetMaxFrom, GetMinFrom,
81 GetWordType, GetPointerType, GetByteType, GetISOLocType,
82 GetM2Integer8, GetM2Integer16, GetM2Integer32, GetM2Integer64,
83 GetM2Cardinal8, GetM2Cardinal16, GetM2Cardinal32, GetM2Cardinal64,
84 GetM2Word16, GetM2Word32, GetM2Word64,
85 GetM2Bitset8, GetM2Bitset16, GetM2Bitset32,
86 GetM2Real32, GetM2Real64, GetM2Real96, GetM2Real128,
87 GetM2Complex32, GetM2Complex64, GetM2Complex96, GetM2Complex128,
88 GetBitsetType, GetISOByteType, GetISOWordType,
89 GetCSizeTType, GetCSSizeTType, GetCOffTType,
90 InitSystemTypes ;
91
92 FROM m2expr IMPORT BuildSize, GetSizeOf, AreConstantsEqual ;
93
94
95 TYPE
96 IsP = PROCEDURE (CARDINAL) : BOOLEAN ;
97
98 VAR
99 MinValues,
100 MaxValues : SymbolTree ;
101 SystemTypes: List ;
102
103
104 (*
105 Init -
106 *)
107
108 PROCEDURE Init ;
109 BEGIN
110 InitList(SystemTypes) ;
111 InitTree(MinValues) ;
112 InitTree(MaxValues)
113 END Init ;
114
115
116 (*
117 CreateMinMaxFor - creates the min and max values for type given gccType.
118 *)
119
120 PROCEDURE CreateMinMaxFor (type: CARDINAL; min, max: ARRAY OF CHAR;
121 gccType: tree; realtype: BOOLEAN) ;
122 VAR
123 maxval, minval: CARDINAL ;
124 BEGIN
125 maxval := MakeConstVar (BuiltinTokenNo, MakeKey(max)) ;
126 IF realtype
127 THEN
128 PushRealTree (GetMaxFrom (BuiltinsLocation (), gccType))
129 ELSE
130 PushIntegerTree (GetMaxFrom (BuiltinsLocation (), gccType))
131 END ;
132 PopValue (maxval) ;
133 PutVar (maxval, type) ;
134 PutSymKey (MaxValues, GetSymName (type), maxval) ;
135
136 minval := MakeConstVar (BuiltinTokenNo, MakeKey(min)) ;
137 IF realtype
138 THEN
139 PushRealTree (GetMinFrom (BuiltinsLocation (), gccType))
140 ELSE
141 PushIntegerTree (GetMinFrom (BuiltinsLocation (), gccType))
142 END ;
143 PopValue (minval) ;
144 PutVar (minval, type) ;
145 PutSymKey (MinValues, GetSymName (type), minval)
146 END CreateMinMaxFor ;
147
148
149 (*
150 MapType - create a mapping of the M2 frontend type to gcctype.
151 *)
152
153 PROCEDURE MapType (type: CARDINAL;
154 name, min, max: ARRAY OF CHAR;
155 needsExporting: BOOLEAN;
156 gcctype: tree; realtype: BOOLEAN) ;
157 VAR
158 n: Name ;
159 BEGIN
160 PushIntegerTree (BuildSize (BuiltinsLocation (), gcctype, FALSE)) ;
161 PopSize (type) ;
162 IF IsItemInList (SystemTypes, type)
163 THEN
164 InternalError ('not expecting system type to already be declared')
165 END ;
166 PutItemIntoList (SystemTypes, type) ;
167
168 (* Create min, max constants if type is ordinal or a floating point type. *)
169 IF (NOT StrEqual (min, '')) AND (NOT StrEqual (max, ''))
170 THEN
171 CreateMinMaxFor (type, min, max, gcctype, realtype)
172 END ;
173 IF needsExporting AND DumpSystemExports
174 THEN
175 n := GetSymName (type) ;
176 printf1('SYSTEM module creates type: %a\n', n)
177 END
178 END MapType ;
179
180
181 (*
182 CreateType - create and return a frontend type which matches the GCC tree type.
183 *)
184
185 PROCEDURE CreateType (name, min, max: ARRAY OF CHAR;
186 needsExporting: BOOLEAN; gccType: tree;
187 realtype: BOOLEAN) : CARDINAL ;
188 VAR
189 type: CARDINAL ;
190 BEGIN
191 IF gccType=NIL
192 THEN
193 (* GCC backend does not support this type. *)
194 RETURN NulSym
195 ELSE
196 (* Create base type. *)
197 type := MakeType (BuiltinTokenNo, MakeKey (name)) ;
198 PutType (type, NulSym) ; (* a Base Type *)
199 MapType (type, name, min, max, needsExporting, gccType, realtype) ;
200 RETURN type
201 END
202 END CreateType ;
203
204
205 (*
206 AttemptToCreateType - attempts to create a frontend type which matches the
207 GCC tree type.
208 *)
209
210 PROCEDURE AttemptToCreateType (name, min, max: ARRAY OF CHAR;
211 needsExporting: BOOLEAN; gccType: tree;
212 realtype: BOOLEAN) ;
213 BEGIN
214 Assert (IsLegal (CreateType (name, min, max, needsExporting,
215 gccType, realtype)))
216 END AttemptToCreateType ;
217
218
219 (*
220 CreateSetType - creates and returns a, SET OF [0..highBit], type.
221 It maps this type onto the GCC type.
222 *)
223
224 PROCEDURE CreateSetType (name, highBit: ARRAY OF CHAR;
225 needsExporting: BOOLEAN; gccType: tree) : CARDINAL ;
226 VAR
227 low,
228 high,
229 subrange,
230 type : CARDINAL ;
231 BEGIN
232 IF gccType=NIL
233 THEN
234 (* GCC backend does not support this type *)
235 RETURN NulSym
236 ELSE
237 (* create base type *)
238 type := MakeSet (BuiltinTokenNo, MakeKey (name)) ;
239 low := MakeConstLit (BuiltinTokenNo, MakeKey ('0'), Cardinal) ;
240 high := MakeConstLit (BuiltinTokenNo, MakeKey (highBit), Cardinal) ;
241 subrange := MakeSubrange (BuiltinTokenNo, NulName) ;
242 PutSubrange (subrange, low, high, Cardinal) ;
243 PutSet (type, subrange, FALSE) ;
244 MapType (type, name, '', '', needsExporting, gccType, FALSE) ;
245 RETURN type
246 END
247 END CreateSetType ;
248
249
250 (*
251 AttemptToCreateSetType - creates and returns a, SET OF [0..highBit], type.
252 It maps this type onto the GCC type.
253 *)
254
255 PROCEDURE AttemptToCreateSetType (name, highBit: ARRAY OF CHAR;
256 needsExporting: BOOLEAN; gccType: tree) ;
257 BEGIN
258 Assert (IsLegal (CreateSetType (name, highBit, needsExporting, gccType)))
259 END AttemptToCreateSetType ;
260
261
262 (*
263 MakeFixedSizedTypes - creates the SYSTEM fixed sized types providing the
264 gcc backend supports them.
265 *)
266
267 PROCEDURE MakeFixedSizedTypes ;
268 BEGIN
269 AttemptToCreateType ('INTEGER8', 'MinInteger8', 'MaxInteger8', TRUE, GetM2Integer8 (), FALSE) ;
270 AttemptToCreateType ('INTEGER16', 'MinInteger16', 'MaxInteger16', TRUE, GetM2Integer16 (), FALSE) ;
271 AttemptToCreateType ('INTEGER32', 'MinInteger32', 'MaxInteger32', TRUE, GetM2Integer32 (), FALSE) ;
272 AttemptToCreateType ('INTEGER64', 'MinInteger64', 'MaxInteger64', TRUE, GetM2Integer64 (), FALSE) ;
273
274 AttemptToCreateType ('CARDINAL8', 'MinCardinal8', 'MaxCardinal8', TRUE, GetM2Cardinal8 (), FALSE) ;
275 AttemptToCreateType ('CARDINAL16', 'MinCardinal16', 'MaxCardinal16', TRUE, GetM2Cardinal16 (), FALSE) ;
276 AttemptToCreateType ('CARDINAL32', 'MinCardinal32', 'MaxCardinal32', TRUE, GetM2Cardinal32 (), FALSE) ;
277 AttemptToCreateType ('CARDINAL64', 'MinCardinal64', 'MaxCardinal64', TRUE, GetM2Cardinal64 (), FALSE) ;
278
279 AttemptToCreateType ('WORD16', '', '', TRUE, GetM2Word16 (), FALSE) ;
280 AttemptToCreateType ('WORD32', '', '', TRUE, GetM2Word32 (), FALSE) ;
281 AttemptToCreateType ('WORD64', '', '', TRUE, GetM2Word64 (), FALSE) ;
282
283 AttemptToCreateSetType ('BITSET8' , '7' , TRUE, GetM2Bitset8 ()) ;
284 AttemptToCreateSetType ('BITSET16', '15', TRUE, GetM2Bitset16 ()) ;
285 AttemptToCreateSetType ('BITSET32', '31', TRUE, GetM2Bitset32 ()) ;
286
287 AttemptToCreateType ('REAL32', 'MinReal32', 'MaxReal32', TRUE, GetM2Real32 (), TRUE) ;
288 AttemptToCreateType ('REAL64', 'MinReal64', 'MaxReal64', TRUE, GetM2Real64 (), TRUE) ;
289 AttemptToCreateType ('REAL96', 'MinReal96', 'MaxReal96', TRUE, GetM2Real96 (), TRUE) ;
290 AttemptToCreateType ('REAL128', 'MinReal128', 'MaxReal128', TRUE, GetM2Real128 (), TRUE) ;
291
292 AttemptToCreateType ('COMPLEX32', '', '', TRUE, GetM2Complex32 (), TRUE) ;
293 AttemptToCreateType ('COMPLEX64', '', '', TRUE, GetM2Complex64 (), TRUE) ;
294 AttemptToCreateType ('COMPLEX96', '', '', TRUE, GetM2Complex96 (), TRUE) ;
295 AttemptToCreateType ('COMPLEX128', '', '', TRUE, GetM2Complex128 (), TRUE)
296 END MakeFixedSizedTypes ;
297
298
299 (*
300 InitPIMTypes -
301 *)
302
303 PROCEDURE InitPIMTypes ;
304 BEGIN
305 Loc := CreateType ('LOC', '', '', TRUE, GetISOLocType(), FALSE) ;
306 InitSystemTypes(BuiltinsLocation(), Loc) ;
307 Word := CreateType ('WORD', '', '', TRUE, GetWordType(), FALSE) ;
308 Byte := CreateType ('BYTE', '', '', TRUE, GetByteType(), FALSE) ;
309
310 (* ADDRESS = POINTER TO BYTE *)
311
312 Address := MakePointer (BuiltinTokenNo, MakeKey('ADDRESS')) ;
313 PutPointer (Address, Byte) ; (* Base Type *)
314 MapType (Address, 'ADDRESS', '', '', TRUE, GetPointerType(), FALSE)
315 END InitPIMTypes ;
316
317
318 (*
319 InitISOTypes -
320 *)
321
322 PROCEDURE InitISOTypes ;
323 BEGIN
324 Loc := CreateType ('LOC', 'MinLoc', 'MaxLoc', TRUE, GetISOLocType (), FALSE) ;
325 InitSystemTypes (BuiltinsLocation (), Loc) ;
326
327 Address := MakePointer (BuiltinTokenNo, MakeKey ('ADDRESS')) ;
328 PutPointer (Address, Loc) ; (* Base Type *)
329 MapType (Address, 'ADDRESS', '', '', TRUE, GetPointerType(), FALSE) ;
330
331 Byte := CreateType ('BYTE', '', '', TRUE, GetISOByteType(), FALSE) ;
332 Word := CreateType ('WORD', '', '', TRUE, GetISOWordType(), FALSE) ;
333 END InitISOTypes ;
334
335
336 (*
337 MakeExtraSystemTypes - create any extra system types required
338 for portability.
339 *)
340
341 PROCEDURE MakeExtraSystemTypes ;
342 BEGIN
343 CSizeT := CreateType ('CSIZE_T' , '', '', TRUE, GetCSizeTType (), FALSE) ;
344 CSSizeT := CreateType ('CSSIZE_T', '', '', TRUE, GetCSSizeTType (), FALSE) ;
345 COffT := CreateType ('COFF_T', '', '', TRUE, GetCOffTType (), FALSE)
346 END MakeExtraSystemTypes ;
347
348
349 (*
350 InitSystem - creates the system dependant types and procedures.
351 Note that they are not exported here, but they are
352 exported in the textual module: SYSTEM.def.
353 We build our system types from those given in the gcc
354 backend. Essentially we perform double book keeping.
355 *)
356
357 PROCEDURE InitSystem ;
358 VAR
359 Previous: CARDINAL ;
360 BEGIN
361 Init ;
362
363 (* create SYSTEM module *)
364 System := MakeDefinitionSource(BuiltinTokenNo, MakeKey('SYSTEM')) ;
365 StartScope(System) ;
366 Previous := GetCurrentModule() ;
367 SetCurrentModule(System) ;
368
369 IF Iso
370 THEN
371 InitISOTypes ;
372 MakeSize ;
373 PutExportQualified(BuiltinTokenNo, MakeKey('SIZE'))
374 ELSE
375 InitPIMTypes ;
376 (* SIZE is declared in SYSTEM.def in PIM-2 but not PIM-[34] *)
377 IF Pedantic
378 THEN
379 IF Pim2
380 THEN
381 MakeSize ;
382 PutExportQualified(BuiltinTokenNo, MakeKey('SIZE'))
383 END
384 ELSE
385 MakeSize ;
386 PutExportQualified(BuiltinTokenNo, MakeKey('SIZE'))
387 END
388 END ;
389
390 (* The predefined pseudo functions. *)
391
392 Adr := MakeProcedure(BuiltinTokenNo,
393 MakeKey('ADR')) ; (* Function *)
394 PutFunction (BuiltinTokenNo, Adr, DefProcedure, Address) ;
395 (* Return Type *)
396 (* Address *)
397 TSize := MakeProcedure(BuiltinTokenNo,
398 MakeKey('TSIZE')) ; (* Function *)
399 PutFunction (BuiltinTokenNo, TSize, DefProcedure, ZType) ;
400 (* Return Type *)
401 (* ZType *)
402 TBitSize := MakeProcedure(BuiltinTokenNo,
403 MakeKey('TBITSIZE')) ; (* GNU extension *)
404 (* Function *)
405 PutFunction (BuiltinTokenNo, TBitSize, DefProcedure, ZType) ;
406 (* Return Type *)
407 (* ZType *)
408 (* The ISO specific predefined pseudo functions. *)
409
410 AddAdr := MakeProcedure(BuiltinTokenNo,
411 MakeKey('ADDADR')) ; (* Function *)
412 PutFunction (BuiltinTokenNo, AddAdr, DefProcedure, Address) ;
413 (* Return Type *)
414 SubAdr := MakeProcedure(BuiltinTokenNo,
415 MakeKey('SUBADR')) ; (* Function *)
416 PutFunction (BuiltinTokenNo, SubAdr, DefProcedure, Address) ;
417 (* Return Type *)
418 DifAdr := MakeProcedure (BuiltinTokenNo,
419 MakeKey ('DIFADR')) ; (* Function *)
420 PutFunction (BuiltinTokenNo, DifAdr, DefProcedure, Address) ;
421 (* Return Type *)
422 MakeAdr := MakeProcedure (BuiltinTokenNo,
423 MakeKey ('MAKEADR')) ; (* Function *)
424 PutFunction (BuiltinTokenNo, MakeAdr, DefProcedure, Address) ;
425 (* Return Type *)
426
427 (* The return value for ROTATE, SHIFT and CAST is the
428 same as the first parameter and is faked in M2Quads. *)
429
430 Rotate := MakeProcedure(BuiltinTokenNo,
431 MakeKey('ROTATE')) ; (* Function *)
432 Shift := MakeProcedure(BuiltinTokenNo,
433 MakeKey('SHIFT')) ; (* Function *)
434 Cast := MakeProcedure(BuiltinTokenNo,
435 MakeKey('CAST')) ; (* Function *)
436
437 Throw := MakeProcedure(BuiltinTokenNo,
438 MakeKey('THROW')) ; (* Procedure *)
439 PutProcedureNoReturn (Throw, DefProcedure, TRUE) ;
440
441 CreateMinMaxFor(Word, 'MinWord', 'MaxWord', GetWordType(), FALSE) ;
442 CreateMinMaxFor(Address, 'MinAddress', 'MaxAddress', GetPointerType(), FALSE) ;
443 CreateMinMaxFor(Byte, 'MinByte', 'MaxByte', GetByteType(), FALSE) ;
444
445 MakeFixedSizedTypes ;
446 MakeExtraSystemTypes ;
447
448 EndScope ;
449 SetCurrentModule(Previous)
450 END InitSystem ;
451
452
453 (*
454 GetSystemTypeMinMax - returns the minimum and maximum values for a given system type.
455 *)
456
457 PROCEDURE GetSystemTypeMinMax (type: CARDINAL; VAR min, max: CARDINAL) ;
458 BEGIN
459 IF IsItemInList(SystemTypes, type)
460 THEN
461 min := GetSymKey(MinValues, GetSymName(type)) ;
462 max := GetSymKey(MaxValues, GetSymName(type))
463 ELSE
464 InternalError ('system does not know about this type')
465 END
466 END GetSystemTypeMinMax ;
467
468
469 (*
470 IsISOPseudoSystemFunction -
471 *)
472
473 PROCEDURE IsISOPseudoSystemFunction (sym: CARDINAL) : BOOLEAN ;
474 BEGIN
475 RETURN Iso AND ((sym=AddAdr) OR (sym=SubAdr) OR (sym=DifAdr) OR
476 (sym=MakeAdr) OR (sym=Rotate) OR (sym=Shift) OR
477 (sym=Cast))
478 END IsISOPseudoSystemFunction ;
479
480
481 (*
482 IsPIMPseudoSystemFunction - returns TRUE if sym is specifically a PIM
483 system function.
484 *)
485
486 PROCEDURE IsPIMPseudoSystemFunction (sym: CARDINAL) : BOOLEAN ;
487 BEGIN
488 RETURN (NOT Iso) AND ((sym=Size) OR (sym=Shift) OR (sym=Rotate))
489 END IsPIMPseudoSystemFunction ;
490
491
492 (*
493 IsPseudoSystemFunction - returns true if sym is a SYSTEM pseudo function.
494 *)
495
496 PROCEDURE IsPseudoSystemFunction (sym: CARDINAL) : BOOLEAN ;
497 BEGIN
498 RETURN( (sym=Adr) OR (sym=TSize) OR (sym=TBitSize) OR
499 IsPIMPseudoSystemFunction(sym) OR
500 IsISOPseudoSystemFunction(sym) )
501 END IsPseudoSystemFunction ;
502
503
504 (*
505 IsPseudoSystemFunctionConstExpression - returns TRUE if this procedure
506 is legal in a constant expression.
507 *)
508
509 PROCEDURE IsPseudoSystemFunctionConstExpression (sym: CARDINAL) : BOOLEAN ;
510 BEGIN
511 RETURN(
512 (sym=Size) OR (sym=TSize) OR (sym=Rotate) OR (sym=Shift) OR
513 (Iso AND ((sym=Cast) OR (sym=MakeAdr)))
514 )
515 END IsPseudoSystemFunctionConstExpression ;
516
517
518 (*
519 IsPseudoSystemProcedure - returns true if sym is a SYSTEM pseudo procedure.
520 *)
521
522 PROCEDURE IsPseudoSystemProcedure (sym: CARDINAL) : BOOLEAN ;
523 BEGIN
524 RETURN( sym=Throw )
525 END IsPseudoSystemProcedure ;
526
527
528 (*
529 IsSystemType - returns TRUE if sym is a SYSTEM (inbuilt) type.
530 It does not search your SYSTEM implementation module.
531 *)
532
533 PROCEDURE IsSystemType (sym: CARDINAL) : BOOLEAN ;
534 BEGIN
535 RETURN( IsItemInList(SystemTypes, sym) )
536 END IsSystemType ;
537
538
539 (*
540 GetSafeSystem -
541 *)
542
543 PROCEDURE GetSafeSystem (name: Name) : CARDINAL ;
544 VAR
545 sym,
546 i, n: CARDINAL ;
547 BEGIN
548 n := NoOfItemsInList(SystemTypes) ;
549 i := 1 ;
550 WHILE i<=n DO
551 sym := GetItemFromList(SystemTypes, i) ;
552 IF GetSymName(sym)=name
553 THEN
554 RETURN( sym )
555 END ;
556 INC(i)
557 END ;
558 RETURN( NulSym )
559 END GetSafeSystem ;
560
561
562 (*
563 IntegerN - returns the symbol associated with INTEGER[N].
564 NulSym is returned if the type does not exist.
565 *)
566
567 PROCEDURE IntegerN (bitlength: CARDINAL) : CARDINAL ;
568 BEGIN
569 CASE bitlength OF
570
571 8 : RETURN( GetSafeSystem(MakeKey('INTEGER8')) ) |
572 16: RETURN( GetSafeSystem(MakeKey('INTEGER16')) ) |
573 32: RETURN( GetSafeSystem(MakeKey('INTEGER32')) ) |
574 64: RETURN( GetSafeSystem(MakeKey('INTEGER64')) )
575
576 ELSE
577 InternalError ('system does not know about this type')
578 END
579 END IntegerN ;
580
581
582 (*
583 CardinalN - returns the symbol associated with CARDINAL[N].
584 NulSym is returned if the type does not exist.
585 *)
586
587 PROCEDURE CardinalN (bitlength: CARDINAL) : CARDINAL ;
588 BEGIN
589 CASE bitlength OF
590
591 8 : RETURN( GetSafeSystem(MakeKey('CARDINAL8')) ) |
592 16: RETURN( GetSafeSystem(MakeKey('CARDINAL16')) ) |
593 32: RETURN( GetSafeSystem(MakeKey('CARDINAL32')) ) |
594 64: RETURN( GetSafeSystem(MakeKey('CARDINAL64')) )
595
596 ELSE
597 InternalError ('system does not know about this type')
598 END
599 END CardinalN ;
600
601
602 (*
603 WordN - returns the symbol associated with WORD[N].
604 NulSym is returned if the type does not exist.
605 *)
606
607 PROCEDURE WordN (bitlength: CARDINAL) : CARDINAL ;
608 BEGIN
609 CASE bitlength OF
610
611 16: RETURN( GetSafeSystem(MakeKey('WORD16')) ) |
612 32: RETURN( GetSafeSystem(MakeKey('WORD32')) ) |
613 64: RETURN( GetSafeSystem(MakeKey('WORD64')) )
614
615 ELSE
616 InternalError ('system does not know about this type')
617 END
618 END WordN ;
619
620
621 (*
622 SetN - returns the symbol associated with SET[N].
623 NulSym is returned if the type does not exist.
624 *)
625
626 PROCEDURE SetN (bitlength: CARDINAL) : CARDINAL ;
627 BEGIN
628 CASE bitlength OF
629
630 8 : RETURN( GetSafeSystem(MakeKey('BITSET8')) ) |
631 16: RETURN( GetSafeSystem(MakeKey('BITSET16')) ) |
632 32: RETURN( GetSafeSystem(MakeKey('BITSET32')) )
633
634 ELSE
635 InternalError ('system does not know about this type')
636 END
637 END SetN ;
638
639
640 (*
641 RealN - returns the symbol associated with REAL[N].
642 NulSym is returned if the type does not exist.
643 *)
644
645 PROCEDURE RealN (bitlength: CARDINAL) : CARDINAL ;
646 BEGIN
647 CASE bitlength OF
648
649 32 : RETURN( GetSafeSystem(MakeKey('REAL32')) ) |
650 64 : RETURN( GetSafeSystem(MakeKey('REAL64')) ) |
651 96 : RETURN( GetSafeSystem(MakeKey('REAL96')) ) |
652 128: RETURN( GetSafeSystem(MakeKey('REAL128')) )
653
654 ELSE
655 InternalError ('system does not know about this type')
656 END
657 END RealN ;
658
659
660 (*
661 ComplexN - returns the symbol associated with COMPLEX[N].
662 NulSym is returned if the type does not exist.
663 *)
664
665 PROCEDURE ComplexN (bitlength: CARDINAL) : CARDINAL ;
666 BEGIN
667 CASE bitlength OF
668
669 32 : RETURN( GetSafeSystem(MakeKey('COMPLEX32')) ) |
670 64 : RETURN( GetSafeSystem(MakeKey('COMPLEX64')) ) |
671 96 : RETURN( GetSafeSystem(MakeKey('COMPLEX96')) ) |
672 128: RETURN( GetSafeSystem(MakeKey('COMPLEX128')) )
673
674 ELSE
675 InternalError ('system does not know about this type')
676 END
677 END ComplexN ;
678
679
680 (*
681 IsIntegerN - returns the TRUE if, sym, is one of the SYSTEM
682 INTEGER types (not the base INTEGER type).
683 *)
684
685 PROCEDURE IsIntegerN (sym: CARDINAL) : BOOLEAN ;
686 BEGIN
687 RETURN(
688 (sym#NulSym) AND
689 ((sym=IntegerN(8)) OR (sym=IntegerN(16)) OR
690 (sym=IntegerN(32)) OR (sym=IntegerN(64)))
691 )
692 END IsIntegerN ;
693
694
695 (*
696 IsCardinalN - returns the TRUE if, sym, is one of the SYSTEM
697 CARDINAL types (not the base CARDINAL type).
698 *)
699
700 PROCEDURE IsCardinalN (sym: CARDINAL) : BOOLEAN ;
701 BEGIN
702 RETURN(
703 (sym#NulSym) AND
704 ((sym=CardinalN(8)) OR (sym=CardinalN(16)) OR
705 (sym=CardinalN(32)) OR (sym=CardinalN(64)))
706 )
707 END IsCardinalN ;
708
709
710 (*
711 IsWordN - returns the TRUE if, sym, is one of the SYSTEM
712 WORD[n] types (not the default SYSTEM WORD type).
713 *)
714
715 PROCEDURE IsWordN (sym: CARDINAL) : BOOLEAN ;
716 BEGIN
717 RETURN(
718 (sym#NulSym) AND
719 ((sym=WordN(16)) OR
720 (sym=WordN(32)) OR (sym=WordN(64)))
721 )
722 END IsWordN ;
723
724
725 (*
726 IsSetN - returns the TRUE if, sym, is one of the SYSTEM
727 SET[n] types (not the default SYSTEM BITSET type).
728 *)
729
730 PROCEDURE IsSetN (sym: CARDINAL) : BOOLEAN ;
731 BEGIN
732 RETURN(
733 (sym#NulSym) AND
734 ((sym=SetN(8)) OR (sym=SetN(16)) OR (sym=SetN(32)))
735 )
736 END IsSetN ;
737
738
739 (*
740 IsRealN - returns the TRUE if, sym, is one of the SYSTEM
741 REAL[n] types (not the default base REAL type).
742 *)
743
744 PROCEDURE IsRealN (sym: CARDINAL) : BOOLEAN ;
745 BEGIN
746 RETURN(
747 (sym#NulSym) AND
748 ((sym=RealN(32)) OR (sym=RealN(64)) OR
749 (sym=RealN(96)) OR (sym=RealN(128)))
750 )
751 END IsRealN ;
752
753
754 (*
755 IsComplexN - returns the TRUE if, sym, is one of the SYSTEM
756 COMPLEX[n] types (not the default base COMPLEX,
757 LONGCOMPLEX or SHORTCOMPLEX types).
758 *)
759
760 PROCEDURE IsComplexN (sym: CARDINAL) : BOOLEAN ;
761 BEGIN
762 RETURN(
763 (sym#NulSym) AND
764 ((sym=ComplexN(32)) OR (sym=ComplexN(64)) OR
765 (sym=ComplexN(96)) OR (sym=ComplexN(128)))
766 )
767 END IsComplexN ;
768
769
770 (*
771 IsGenericSystemType - returns TRUE if, sym, is of type
772 BYTE, WORD or any other length.
773 *)
774
775 PROCEDURE IsGenericSystemType (sym: CARDINAL) : BOOLEAN ;
776 BEGIN
777 RETURN(
778 (sym#NulSym) AND
779 (IsWordN(sym) OR (sym=Word) OR (sym=Byte) OR (sym=Loc))
780 )
781 END IsGenericSystemType ;
782
783
784 (*
785 IsSameSize - return TRUE if SIZE(a)=SIZE(b)
786 *)
787
788 PROCEDURE IsSameSize (a, b: CARDINAL) : BOOLEAN ;
789 BEGIN
790 RETURN( AreConstantsEqual(BuildSize(BuiltinsLocation(), Mod2Gcc(a), FALSE),
791 BuildSize(BuiltinsLocation(), Mod2Gcc(b), FALSE)) )
792 END IsSameSize ;
793
794
795 (*
796 IsSameType - returns TRUE if, t, is the same type as a or b
797 and a or b are a type, p.
798 *)
799
800 PROCEDURE IsSameType (t: CARDINAL; p: IsP; a, b: CARDINAL) : BOOLEAN ;
801 BEGIN
802 IF t=a
803 THEN
804 RETURN( p(b) AND IsSameSize(a, b) )
805 ELSIF t=b
806 THEN
807 RETURN( p(a) AND IsSameSize(a, b) )
808 ELSE
809 RETURN( FALSE )
810 END
811 END IsSameType ;
812
813
814 (*
815 IsSameSizePervasiveType - returns TRUE if a or b are CARDINAL, INTEGER, REAL,
816 LONGREAL, SHORTREAL and the other type is the same
817 size and of the same type.
818 *)
819
820 PROCEDURE IsSameSizePervasiveType (a, b: CARDINAL) : BOOLEAN ;
821 BEGIN
822 RETURN( IsSameType(Integer, IsIntegerN, a, b) OR
823 IsSameType(Cardinal, IsCardinalN, a, b) OR
824 IsSameType(Word, IsWordN, a, b) OR
825 IsSameType(Real, IsRealN, a, b) OR
826 IsSameType(Complex, IsComplexN, a, b) OR
827 IsSameType(LongInt, IsIntegerN, a, b) OR
828 IsSameType(LongCard, IsCardinalN, a, b) OR
829 IsSameType(LongComplex, IsComplexN, a, b) OR
830 IsSameType(LongReal, IsRealN, a, b) OR
831 IsSameType(ShortInt, IsIntegerN, a, b) OR
832 IsSameType(ShortCard, IsCardinalN, a, b) OR
833 IsSameType(ShortComplex, IsComplexN, a, b) OR
834 IsSameType(ShortReal, IsRealN, a, b) )
835 END IsSameSizePervasiveType ;
836
837
838 END M2System.