3 DEFINITION MODULE SYSTEM;
5 (* Gives access to system programming facilities that are probably
8 (* The constants and types define underlying properties of storage *)
10 EXPORT QUALIFIED BITSPERLOC, LOCSPERWORD,
11 LOC, BYTE, WORD, ADDRESS, CSIZE_T, CSSIZE_T, (*
12 Target specific data types. *)
13 ADDADR, SUBADR, DIFADR, MAKEADR, ADR, ROTATE,
16 (* Internal GM2 compiler functions *)
17 ShiftVal, ShiftLeft, ShiftRight,
18 RotateVal, RotateLeft, RotateRight,
22 (* <implementation-defined constant> ; *)
23 @findex BITSPERLOC (const)
24 BITSPERLOC = __ATTRIBUTE__ __BUILTIN__ ((BITS_PER_UNIT)) ;
25 (* <implementation-defined constant> ; *)
26 @findex LOCSPERWORD (const)
27 LOCSPERWORD = __ATTRIBUTE__ __BUILTIN__ ((UNITS_PER_WORD)) ;
28 (* <implementation-defined constant> ; *)
29 @findex LOCSPERBYTE (const)
30 LOCSPERBYTE = 8 DIV BITSPERLOC ;
32 (* Note that the full list of system and sized datatypes include:
33 LOC, WORD, BYTE, ADDRESS,
35 (and the non language standard target types)
37 INTEGER8, INTEGER16, INTEGER32, INTEGER64,
38 CARDINAL8, CARDINAL16, CARDINAL32, CARDINAL64,
39 WORD16, WORD32, WORD64, BITSET8, BITSET16,
40 BITSET32, REAL32, REAL64, REAL128, COMPLEX32,
41 COMPLEX64, COMPLEX128, CSIZE_T, CSSIZE_T.
43 Also note that the non-standard data types will
44 move into another module in the future. *)
47 All the data types and procedures below are declared internally.
48 ===============================================================
51 (* Target specific data types. *)
54 LOC; (* A system basic type. Values are the uninterpreted
55 contents of the smallest addressable unit of storage *)
56 @findex ADDRESS (type)
57 ADDRESS = POINTER TO LOC;
59 WORD = ARRAY [0 .. LOCSPERWORD-1] OF LOC;
61 (* BYTE and LOCSPERBYTE are provided if appropriate for machine *)
65 BYTE = ARRAY [0 .. LOCSPERBYTE-1] OF LOC;
68 PROCEDURE ADDADR (addr: ADDRESS; offset: CARDINAL): ADDRESS;
69 (* Returns address given by (addr + offset), or may raise
70 an exception if this address is not valid.
74 PROCEDURE SUBADR (addr: ADDRESS; offset: CARDINAL): ADDRESS;
75 (* Returns address given by (addr - offset), or may raise an
76 exception if this address is not valid.
80 PROCEDURE DIFADR (addr1, addr2: ADDRESS): INTEGER;
81 (* Returns the difference between addresses (addr1 - addr2),
82 or may raise an exception if the arguments are invalid
83 or address space is non-contiguous.
87 PROCEDURE MAKEADR (high: <some type>; ...): ADDRESS;
88 (* Returns an address constructed from a list of values whose
89 types are implementation-defined, or may raise an
90 exception if this address is not valid.
92 In GNU Modula-2, MAKEADR can take any number of arguments
93 which are mapped onto the type ADDRESS. The first parameter
94 maps onto the high address bits and subsequent parameters map
95 onto lower address bits. For example:
97 a := MAKEADR(BYTE(0FEH), BYTE(0DCH), BYTE(0BAH), BYTE(098H),
98 BYTE(076H), BYTE(054H), BYTE(032H), BYTE(010H)) ;
100 then the value of, a, on a 64 bit machine is: 0FEDCBA9876543210H
102 The parameters do not have to be the same type, but constants
107 PROCEDURE ADR (VAR v: <anytype>): ADDRESS;
108 (* Returns the address of variable v. *)
111 PROCEDURE ROTATE (val: <a packedset type>;
112 num: INTEGER): <type of first parameter>;
113 (* Returns a bit sequence obtained from val by rotating up/right
114 or down/right by the absolute value of num. The direction is
115 down/right if the sign of num is negative, otherwise the direction
120 PROCEDURE SHIFT (val: <a packedset type>;
121 num: INTEGER): <type of first parameter>;
122 (* Returns a bit sequence obtained from val by shifting up/left
123 or down/right by the absolute value of num, introducing
124 zeros as necessary. The direction is down/right if the sign of
125 num is negative, otherwise the direction is up/left.
129 PROCEDURE CAST (<targettype>; val: <anytype>): <targettype>;
130 (* CAST is a type transfer function. Given the expression
131 denoted by val, it returns a value of the type <targettype>.
132 An invalid value for the target value or a
133 physical address alignment problem may raise an exception.
137 PROCEDURE TSIZE (<type>; ... ): CARDINAL;
138 (* Returns the number of LOCS used to store a value of the
139 specified <type>. The extra parameters, if present,
140 are used to distinguish variants in a variant record.
144 PROCEDURE THROW (i: INTEGER) ;
146 THROW is a GNU extension and was not part of the PIM or ISO
147 standards. It throws an exception which will be caught by the
148 EXCEPT block (assuming it exists). This is a compiler builtin
149 function which interfaces to the GCC exception handling runtime
151 GCC uses the term throw, hence the naming distinction between
152 the GCC builtin and the Modula-2 runtime library procedure Raise.
153 The later library procedure Raise will call SYSTEM.THROW after
154 performing various housekeeping activities.
158 PROCEDURE TBITSIZE (<type>) : CARDINAL ;
159 (* Returns the minimum number of bits necessary to represent
160 <type>. This procedure function is only useful for determining
161 the number of bits used for any type field within a packed RECORD.
162 It is not particularly useful elsewhere since <type> might be
163 optimized for speed, for example a BOOLEAN could occupy a WORD.
168 (* The following procedures are invoked by GNU Modula-2 to
169 shift non word set types. They are not part of ISO Modula-2
170 but are used to implement the SHIFT procedure defined above. *)
173 ShiftVal - is a runtime procedure whose job is to implement
174 the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
175 inline a SHIFT of a single WORD sized set and will only
176 call this routine for larger sets.
180 PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
181 SetSizeInBits: CARDINAL;
182 ShiftCount: INTEGER) ;
186 ShiftLeft - performs the shift left for a multi word set.
187 This procedure might be called by the back end of
188 GNU Modula-2 depending whether amount is known at
193 PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
194 SetSizeInBits: CARDINAL;
195 ShiftCount: CARDINAL) ;
198 ShiftRight - performs the shift left for a multi word set.
199 This procedure might be called by the back end of
200 GNU Modula-2 depending whether amount is known at
205 PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
206 SetSizeInBits: CARDINAL;
207 ShiftCount: CARDINAL) ;
211 RotateVal - is a runtime procedure whose job is to implement
212 the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
213 inline a ROTATE of a single WORD (or less)
214 sized set and will only call this routine for larger
219 PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
220 SetSizeInBits: CARDINAL;
221 RotateCount: INTEGER) ;
225 RotateLeft - performs the rotate left for a multi word set.
226 This procedure might be called by the back end of
227 GNU Modula-2 depending whether amount is known at
232 PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
233 SetSizeInBits: CARDINAL;
234 RotateCount: CARDINAL) ;
238 RotateRight - performs the rotate right for a multi word set.
239 This procedure might be called by the back end of
240 GNU Modula-2 depending whether amount is known at
245 PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
246 SetSizeInBits: CARDINAL;
247 RotateCount: CARDINAL) ;