13.8 Machine Code Insertions
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[ A machine code insertion can be achieved by a call to a subprogram whose sequence_of_statements
contains code_statement
s.]
Syntax
2code_statement
::=
qualified_expression
;
3
A code_statement
is only allowed in the handled_sequence_of_statements
of a subprogram_body
. If a subprogram_body
contains any code_statement
s, then within this subprogram_body
the only allowed form of statement
is a code_statement
(labeled or not), the only allowed declarative_item
s are use_clause
s, and no exception_handler
is allowed (comment
s and pragma
s are allowed as usual).
Name Resolution Rules
4The qualified_expression
is expected to be of any type.
Legality Rules
5The qualified_expression
shall be of a type declared in package System.Machine_Code.
This includes types declared in children of System.Machine_Code.
A code_statement
shall appear only within the scope of a with_clause
that mentions package System.Machine_Code.
Note that this is not a note; without this rule, it would be possible to write machine code in compilation units which depend on System.Machine_Code only indirectly.
Static Semantics
7The contents of the library package System.Machine_Code (if provided) are implementation defined. The meaning of code_statement
s is implementation defined. [Typically, each qualified_expression
represents a machine instruction or assembly directive.]
For example, an instruction might be a record with an Op_Code component and other components for the operands.
The contents of the visible part of package System.Machine_Code, and the meaning of code_statement
s.
Implementation Permissions
8An implementation may place restrictions on code_statement
s. An implementation is not required to provide package System.Machine_Code.
NOTE 1 An implementation can provide implementation-defined pragmas specifying register conventions and calling conventions.
NOTE 2 Machine code functions are exempt from the rule that a return statement is required. In fact, return statements are forbidden, since only code_statement
s are allowed.
The idea is that the author of a machine code subprogram knows the calling conventions, and refers to parameters and results accordingly. The implementation should document where to put the result of a machine code function, for example, “Scalar results are returned in register 0”.
NOTE 3 Intrinsic subprograms (see 6.3.1, “Conformance Rules”) can also be used to achieve machine code insertions. Interface to assembly language can be achieved using the features in Annex B, “Interface to Other Languages”.
Examples
12Example of a code statement:
M : Mask;
procedure Set_Mask
with Inline;
14
procedure Set_Mask is
use System.Machine_Code; -- assume “with System.Machine_Code;” appears somewhere above
begin
SI_Format'(Code => SSM, B => M'Base_Reg, D => M'Disp);
-- Base_Reg and Disp are implementation-defined attributes
end Set_Mask;
Extensions to Ada 83
Machine code functions are allowed in Ada 95; in Ada 83, only procedures were allowed.
Wording Changes from Ada 83
The syntax for code_statement
is changed to say “qualified_expression
” instead of “subtype_mark
'record_aggregate
”. Requiring the type of each instruction to be a record type is overspecification.