annotate gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 .. _Intrinsic_Subprograms:
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 *********************
kono
parents:
diff changeset
4 Intrinsic Subprograms
kono
parents:
diff changeset
5 *********************
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 .. index:: Intrinsic Subprograms
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 GNAT allows a user application program to write the declaration:
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 .. code-block:: ada
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 pragma Import (Intrinsic, name);
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 providing that the name corresponds to one of the implemented intrinsic
kono
parents:
diff changeset
18 subprograms in GNAT, and that the parameter profile of the referenced
kono
parents:
diff changeset
19 subprogram meets the requirements. This chapter describes the set of
kono
parents:
diff changeset
20 implemented intrinsic subprograms, and the requirements on parameter profiles.
kono
parents:
diff changeset
21 Note that no body is supplied; as with other uses of pragma Import, the
kono
parents:
diff changeset
22 body is supplied elsewhere (in this case by the compiler itself). Note
kono
parents:
diff changeset
23 that any use of this feature is potentially non-portable, since the
kono
parents:
diff changeset
24 Ada standard does not require Ada compilers to implement this feature.
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 .. _Intrinsic_Operators:
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 Intrinsic Operators
kono
parents:
diff changeset
29 ===================
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 .. index:: Intrinsic operator
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 All the predefined numeric operators in package Standard
kono
parents:
diff changeset
34 in ``pragma Import (Intrinsic,..)``
kono
parents:
diff changeset
35 declarations. In the binary operator case, the operands must have the same
kono
parents:
diff changeset
36 size. The operand or operands must also be appropriate for
kono
parents:
diff changeset
37 the operator. For example, for addition, the operands must
kono
parents:
diff changeset
38 both be floating-point or both be fixed-point, and the
kono
parents:
diff changeset
39 right operand for ``"**"`` must have a root type of
kono
parents:
diff changeset
40 ``Standard.Integer'Base``.
kono
parents:
diff changeset
41 You can use an intrinsic operator declaration as in the following example:
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 .. code-block:: ada
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 type Int1 is new Integer;
kono
parents:
diff changeset
47 type Int2 is new Integer;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 function "+" (X1 : Int1; X2 : Int2) return Int1;
kono
parents:
diff changeset
50 function "+" (X1 : Int1; X2 : Int2) return Int2;
kono
parents:
diff changeset
51 pragma Import (Intrinsic, "+");
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 This declaration would permit 'mixed mode' arithmetic on items
kono
parents:
diff changeset
55 of the differing types ``Int1`` and ``Int2``.
kono
parents:
diff changeset
56 It is also possible to specify such operators for private types, if the
kono
parents:
diff changeset
57 full views are appropriate arithmetic types.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 .. _Compilation_ISO_Date:
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 Compilation_ISO_Date
kono
parents:
diff changeset
62 ====================
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 .. index:: Compilation_ISO_Date
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
67 library package ``GNAT.Source_Info``. The only useful use of the
kono
parents:
diff changeset
68 intrinsic import in this case is the one in this unit, so an
kono
parents:
diff changeset
69 application program should simply call the function
kono
parents:
diff changeset
70 ``GNAT.Source_Info.Compilation_ISO_Date`` to obtain the date of
kono
parents:
diff changeset
71 the current compilation (in local time format YYYY-MM-DD).
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 .. _Compilation_Date:
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 Compilation_Date
kono
parents:
diff changeset
76 ================
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 .. index:: Compilation_Date
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 Same as Compilation_ISO_Date, except the string is in the form
kono
parents:
diff changeset
81 MMM DD YYYY.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 .. _Compilation_Time:
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 Compilation_Time
kono
parents:
diff changeset
86 ================
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 .. index:: Compilation_Time
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
91 library package ``GNAT.Source_Info``. The only useful use of the
kono
parents:
diff changeset
92 intrinsic import in this case is the one in this unit, so an
kono
parents:
diff changeset
93 application program should simply call the function
kono
parents:
diff changeset
94 ``GNAT.Source_Info.Compilation_Time`` to obtain the time of
kono
parents:
diff changeset
95 the current compilation (in local time format HH:MM:SS).
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 .. _Enclosing_Entity:
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 Enclosing_Entity
kono
parents:
diff changeset
100 ================
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 .. index:: Enclosing_Entity
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
105 library package ``GNAT.Source_Info``. The only useful use of the
kono
parents:
diff changeset
106 intrinsic import in this case is the one in this unit, so an
kono
parents:
diff changeset
107 application program should simply call the function
kono
parents:
diff changeset
108 ``GNAT.Source_Info.Enclosing_Entity`` to obtain the name of
kono
parents:
diff changeset
109 the current subprogram, package, task, entry, or protected subprogram.
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 .. _Exception_Information:
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 Exception_Information
kono
parents:
diff changeset
114 =====================
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 .. index:: Exception_Information'
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
119 library package ``GNAT.Current_Exception``. The only useful
kono
parents:
diff changeset
120 use of the intrinsic import in this case is the one in this unit,
kono
parents:
diff changeset
121 so an application program should simply call the function
kono
parents:
diff changeset
122 ``GNAT.Current_Exception.Exception_Information`` to obtain
kono
parents:
diff changeset
123 the exception information associated with the current exception.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 .. _Exception_Message:
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 Exception_Message
kono
parents:
diff changeset
128 =================
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 .. index:: Exception_Message
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
133 library package ``GNAT.Current_Exception``. The only useful
kono
parents:
diff changeset
134 use of the intrinsic import in this case is the one in this unit,
kono
parents:
diff changeset
135 so an application program should simply call the function
kono
parents:
diff changeset
136 ``GNAT.Current_Exception.Exception_Message`` to obtain
kono
parents:
diff changeset
137 the message associated with the current exception.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 .. _Exception_Name:
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 Exception_Name
kono
parents:
diff changeset
142 ==============
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 .. index:: Exception_Name
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
147 library package ``GNAT.Current_Exception``. The only useful
kono
parents:
diff changeset
148 use of the intrinsic import in this case is the one in this unit,
kono
parents:
diff changeset
149 so an application program should simply call the function
kono
parents:
diff changeset
150 ``GNAT.Current_Exception.Exception_Name`` to obtain
kono
parents:
diff changeset
151 the name of the current exception.
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 .. _File:
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 File
kono
parents:
diff changeset
156 ====
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 .. index:: File
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
161 library package ``GNAT.Source_Info``. The only useful use of the
kono
parents:
diff changeset
162 intrinsic import in this case is the one in this unit, so an
kono
parents:
diff changeset
163 application program should simply call the function
kono
parents:
diff changeset
164 ``GNAT.Source_Info.File`` to obtain the name of the current
kono
parents:
diff changeset
165 file.
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 .. _Line:
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 Line
kono
parents:
diff changeset
170 ====
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 .. index:: Line
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
175 library package ``GNAT.Source_Info``. The only useful use of the
kono
parents:
diff changeset
176 intrinsic import in this case is the one in this unit, so an
kono
parents:
diff changeset
177 application program should simply call the function
kono
parents:
diff changeset
178 ``GNAT.Source_Info.Line`` to obtain the number of the current
kono
parents:
diff changeset
179 source line.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 .. _Shifts_and_Rotates:
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 Shifts and Rotates
kono
parents:
diff changeset
184 ==================
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 .. index:: Shift_Left
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 .. index:: Shift_Right
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 .. index:: Shift_Right_Arithmetic
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 .. index:: Rotate_Left
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 .. index:: Rotate_Right
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 In standard Ada, the shift and rotate functions are available only
kono
parents:
diff changeset
197 for the predefined modular types in package ``Interfaces``. However, in
kono
parents:
diff changeset
198 GNAT it is possible to define these functions for any integer
kono
parents:
diff changeset
199 type (signed or modular), as in this example:
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 .. code-block:: ada
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 function Shift_Left
kono
parents:
diff changeset
205 (Value : T;
kono
parents:
diff changeset
206 Amount : Natural) return T;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 The function name must be one of
kono
parents:
diff changeset
210 Shift_Left, Shift_Right, Shift_Right_Arithmetic, Rotate_Left, or
kono
parents:
diff changeset
211 Rotate_Right. T must be an integer type. T'Size must be
kono
parents:
diff changeset
212 8, 16, 32 or 64 bits; if T is modular, the modulus
kono
parents:
diff changeset
213 must be 2**8, 2**16, 2**32 or 2**64.
kono
parents:
diff changeset
214 The result type must be the same as the type of ``Value``.
kono
parents:
diff changeset
215 The shift amount must be Natural.
kono
parents:
diff changeset
216 The formal parameter names can be anything.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 A more convenient way of providing these shift operators is to use
kono
parents:
diff changeset
219 the Provide_Shift_Operators pragma, which provides the function declarations
kono
parents:
diff changeset
220 and corresponding pragma Import's for all five shift functions.
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 .. _Source_Location:
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 Source_Location
kono
parents:
diff changeset
225 ===============
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 .. index:: Source_Location
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 This intrinsic subprogram is used in the implementation of the
kono
parents:
diff changeset
230 library routine ``GNAT.Source_Info``. The only useful use of the
kono
parents:
diff changeset
231 intrinsic import in this case is the one in this unit, so an
kono
parents:
diff changeset
232 application program should simply call the function
kono
parents:
diff changeset
233 ``GNAT.Source_Info.Source_Location`` to obtain the current
kono
parents:
diff changeset
234 source file location.