pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-35
pTAL Code Generation for Structure References
pTAL Code Generation for Structure
References
When pTAL generates code for references to the fields of structures and substructures,
it generates two kinds of code. These are referred to as:
Fast code
Conservative code
pTAL generates fast code if you reference fields in a structure compiled with
FIELDALIGN(SHARED8). It generates conservative code if you reference fields in a
structure compiled with FIELDALIGN(SHARED2).
Example 11-17 on page 11-35 through Example 11-20 on page 11-37 use the structure
templates in Example 11-16 on page 11-35.
Example 11-16. Structure Templates
STRUCT t_s2(*) FIELDALIGN(SHARED2); ! Base alignment is 2
BEGIN
INT(32) j;
END;
STRUCT t_s8(*) FIELDALIGN(SHARED8); ! Base alignment is 4
BEGIN
INT(32) j;
END;
Example 11-17. SHARED8 Substructure in a SHARED2 Structure
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i;
STRUCT s2(t_s8); ! s2 has SHARED8 alignment
END; ! Base alignment of s2 is 2
INT .p2(t_s8) REFALIGNED(2); ! Reference alignment is 2
INT .p3(t_s8); ! Reference alignment defaults
! to 8
PROC p;
BEGIN
INT i;
@p2 := @s1.s2 '>>' 1;
@p3 := @s1.s2 '>>' 1;
i := p2.j;
i := p3.j;
...
END;