2017년 6월 7일 수요일

Concepts in Code Generation

1. Code Generation
 : automatic derivation of source code in a conventional language from an input model
 : different with compilation
https://en.wikipedia.org/wiki/Automatic_programming

https://en.wikipedia.org/wiki/Code_generation_(compiler)

 - Code generation changes the software development process
 (before) programmers -> requirements / domain knowledge / design knowledge
 (after) programmers -> focus on requirements
  ∴ reduces conceptual gap & formalises and internalises domain and design knowledge by automatic programming

 - Code generators can also generate non-code artefacts from the same model
  e.g. documentation / installation and control scripts / test data, test data generators, and simulations etc.

 !! Benefits of Code Generation
  1) increased productivity: fast turn-around
  2) increased reliability: no (manual) coding errors
  3) increased portability: re-generate for new platform
  4) increased level of intentionality: algorithms represented in domain-specific concepts

2. Code Generator
 - Anatomy of a Code Generator
  1) separation between engine and transformations
   : basic transformations built into a code generator
   : additional transformations extracted from a model
   : reflection allows reasoning over transformations
  2) ASTs as internal representation

 - Most code generators follow one of the basic code generation paradigms
  1) generative / code-based: assemble code from fragments
  http://programmingexamples.wikidot.com/generative-programming

  2) transformative / model-based: refine model into code
  https://www.oreilly.com/ideas/transformative-programming

  3) deductive / proof-based: logically deduce code from specification
  https://en.wikipedia.org/wiki/Deductive_language


3. Software transformations are a fundamental concept in code generation
 - Horizontal transformations: evolution (evolve specification), refactoring (evolve architecture)

 - Vertical transformations: refinement (implement/refine to code)
   https://en.wikipedia.org/wiki/Program_transformation

 - Compositional generators apply only vertical transformations
  1) typical for CASE tools
  2) structure-preserving
  3) specfications often executable

 - Holistic generators apply vertical and horizontal transformations
  1) the "whole system" transformations: optimisation / refactoring / weaving
  2) cannot be composed from vertical / horizontal transformations


4. Domain Modelling
 : establish and define vocabulary/concepts and roles/features
 : define common and variable properties of systems
 : define common architecture(s)

 - Domain modelling is a hard problem: often think too abstract for code generation
 - Domain modelling requires a formal modelling language 
   e.g. UML

https://computersciencesource.wordpress.com/2009/11/26/year-2-software-engineering-domain-modelling-2/


5. Generative domain modelling 
 - ... must cover problem space and solution space
 - ... adds solution concepts
  1) code fragments + structure
  2) relevant variables + types
http://www.program-transformation.org/Transform/GenerativeCoreConcepts


6. Generator frameworks provide dedicated tools to build generators
 - typically provide tools for meta-modelling / meta-programming / transformation and search
 - often used to build itself (bootstrapping)

댓글 없음:

댓글 쓰기