13.8 Machine Code Insertions
1
[
{machine code insertion}
A machine code insertion can be achieved by a call
to a subprogram whose
sequence_of_statements
contains
code_statements.]
Syntax
2
code_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_statements, then within
this subprogram_body the only allowed form
of statement is a code_statement
(labeled or not), the only allowed declarative_items
are use_clauses, and no exception_handler
is allowed (comments and pragmas
are allowed as usual).
Name Resolution Rules
4
{expected type (code_statement)
[partial]} The
qualified_expression
is expected to be of any type.
Legality Rules
5
The qualified_expression
shall be of a type declared in package System.Machine_Code.
5.a
Ramification: This includes types declared
in children of System.Machine_Code.
6
A code_statement shall
appear only within the scope of a with_clause
that mentions package System.Machine_Code.
6.a
Ramification: 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
7
{System.Machine_Code}
The contents of the library package
System.Machine_Code (if provided) are implementation defined. The meaning
of
code_statements is implementation defined.
[Typically, each
qualified_expression represents
a machine instruction or assembly directive.]
7.a
Discussion: For example, an instruction
might be a record with an Op_Code component and other components for
the operands.
7.b
Implementation defined: The contents
of the visible part of package System.Machine_Code, and the meaning of
code_statements.
Implementation Permissions
8
An implementation may place restrictions on code_statements.
An implementation is not required to provide package System.Machine_Code.
9
16 An implementation may provide implementation-defined
pragmas specifying register conventions and calling conventions.
10/2
17 {
AI-00318-02}
Machine code functions are exempt from the rule that a
return
statement return_statement
is required. In fact,
return statements return_statements
are forbidden, since only
code_statements
are allowed.
10.a
Discussion: 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.”
11
Examples
12
Example of a code
statement:
13
M : Mask;
procedure Set_Mask; pragma Inline(Set_Mask);
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
14.a
{
extensions to Ada 83}
Machine
code functions are allowed in Ada 95; in Ada 83, only procedures were
allowed.
Wording Changes from Ada 83
14.b
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.