60 likes | 150 Views
Model-based code generation is essentially uni-directional. Manual code changes un-synchronize code and model. Model-based ideology allows only model changes: works well if code change easily expressible in model works well if code change easily identifiable in model. Model. change.
E N D
Model-based code generation is essentially uni-directional. • Manual code changes un-synchronize code and model. • Model-based ideology allows only model changes: • works well if code change easily expressible in model • works well if code change easily identifiable in model Model change re-generate • Transformations • complex • opaque Code implied change v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } if ( 0 == v52 ) ab_error( division_by_zero ) else { v95 = 0; for( v50 = 0;pv50 <= n_points - 1;pv50++ ) v95 += (x(p42,v50) - mu(v42,v43)) * (x(p42,v50) - mu(v42,v43)) * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; v95 = 0; for( v50 = 0;v50 <= n_points - 1;v50++ ) v95 += (x(v42,v50) - mu(v42,v43))**2 * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } }
Round-trip engineering tries to makemodel-based code generation bi-directional. • Round-trip engineering embraces code changes. • Model and code are re-synchronized by abstraction. (conceptually) • in practice: model change derived from code change • Problem: uni-directional nature of transformations remains. • in practice: add abstraction residuals to transformations Model change abstract re-generate • Transformations • complex • opaque abstract trap doors residuals Code implied change v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } if ( 0 == v52 ) ab_error( division_by_zero ) else { v95 = 0; for( v50 = 0;pv50 <= n_points - 1;pv50++ ) v95 += (x(p42,v50) - mu(v42,v43)) * (x(p42,v50) - mu(v42,v43)) * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; v95 = 0; for( v50 = 0;v50 <= n_points - 1;v50++ ) v95 += (x(v42,v50) - mu(v42,v43))**2 * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) { printf(“bailing out...”); exit(0) } else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } }
Generated code can be customizeduni-directionally by automating residuals. • Abstraction typically uses information from the transformation. • Residuals modify the transformation unsystematically. • Customization transformations automate residuals: • replace abstraction and residuals by reflection and strategy • capture notion of code change in model-based ideology Model change abstract re-generate • Transformations • complex • opaque trap doors customize residuals Code implied change v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } if ( 0 == v52 ) ab_error( division_by_zero ) else { v95 = 0; for( v50 = 0;pv50 <= n_points - 1;pv50++ ) v95 += (x(p42,v50) - mu(v42,v43)) * (x(p42,v50) - mu(v42,v43)) * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; v95 = 0; for( v50 = 0;v50 <= n_points - 1;v50++ ) v95 += (x(v42,v50) - mu(v42,v43))**2 * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) { printf(“bailing out...”); exit(0) } else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } }
Customization requires controlled exposure of generator-internal details. • Generator built on top of solution space domain model: • concepts and algorithms used to formulate generated programs • Customizations are transformations on this (sub-) model • need to record model-code relation during transformation • information exposed as domain-specific join points • customization implemented via weaving Model customize Code v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } if ( 0 == v52 ) ab_error( division_by_zero ) else { v95 = 0; for( v50 = 0;pv50 <= n_points - 1;pv50++ ) v95 += (x(p42,v50) - mu(v42,v43)) * (x(p42,v50) - mu(v42,v43)) * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) ab_error( division_by_zero ) else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; v95 = 0; for( v50 = 0;v50 <= n_points - 1;v50++ ) v95 += (x(v42,v50) - mu(v42,v43))**2 * q(v50,v43); sigma(v42,v43) = sqrt(v95 / v52); } } v52 = 0; for( v49 = 0;v49 <= n_points - 1;v49++ ) v52 += q(v49,v43); if ( 0 == v52 ) { printf(“bailing out...”); exit(0) } else { v94 = 0; for( v48 = 0;v48 <= n_points - 1;v48++ ) v94 += q(v48,v43) * x(v42,v48); mu(v42,v43) = v94 / v52; } }
Current Status and Outlook • Work in progress (not enough yet...) • probably not on presentation-level • Focus on building generators that expose domain model • record and maintain model-code-relation • weavers for domain-specific aspect languages • Certification aspects • prove that user customizations don’t violate code invariants