Generator

617 views

Published on

PDF

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
617
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Generator

  1. 1. Generators Jun Chen March 2003 University of Colorado at Boulder 1
  2. 2. Agenda Part I: Generator Technology Part II: GenVoca Part III: GenVoca vs. AOP 2
  3. 3. Part I: Generator Technology What are Generators? Technologies for Building Generators Vertical, Horizontal, Oblique Transformations Compositional vs. Transformational Generators Kinds of Transformations • Compiler Transformations • Source-to-Source Transformations Transformation Systems 3
  4. 4. What are Generators? Generator: A program that takes a higher- level specification of a piece of software and produces its implementation. • Check Specification System System • Complete Specification Specification Implementation • Perform Optimizations • Generate Implementation Generator 4
  5. 5. Three Issues Raising the intentionality of system descriptions • Focus on “what is needed” • Avoid implementation details 5
  6. 6. Three Issues Raising the intentionality of system descriptions Computing an efficient implementation • Performance Requirements (e.g. response time) • Complex computation inside generators 6
  7. 7. Three Issues Raising the intentionality of system descriptions Computing an efficient implementation Avoiding the library scaling problem • Exponential growth • Factoring libraries into components corresponding to features + Composing using function calls • Avoid “exponential growth” • Poor performance • Generators: factoring + eliminating calling overhead 7
  8. 8. Three Ways to Build Generators Developing generators as stand-alone programs from scratch • Effort-intensive Using the built-in metaprogramming capabilities of a programming lang. (e.g. c++) •Advantage: easier to write generators, generators could be part of the library •Disadvantage: limited by the host lang., debugging 8
  9. 9. Three Ways to Build Generators Using a generator infrastructure • The infrastructure provides basic facilities • A common format for the internal source representation • Operations for encoding transformations • Input/output facilities • Debugging facilities • An example: Intentional Programming 9
  10. 10. Vertical, Horizontal, Oblique Transformations Horizontal Transformation Vertical Oblique Transformation Transformation (Forward Refinement) 10
  11. 11. Compositional vs. Transformational Generators Compositional Generator: vertical transformation Transformational Generators: vertical transformation + horizontal transformation 11
  12. 12. Kinds of Transformations 12
  13. 13. Automating System Implementation System System System Requirements Requirements Requirements Manually Manually Manually Implement Implement Implement High-level system specification Source-to-Source Interactive, Transformations automated support Compiler System source using System source using Transformations domain-specific lang. domain-specific lang. abstractions abstractions Compile Compile System source Could generate Could generate in a general- code in C++ or code in C++ or purpose lang. Java if needed Java if needed Compile Compile Compile System System System Implementation Implementation Implementation
  14. 14. Compiler Transformations Refinements(vertical) – adds implementation details • Decomposition • An abstract data type(ADT) -> A number of other ADTs • Choice of representation • Matrix -> Array? Vector? Hash Table? • Choice of algorithm • Performance 14
  15. 15. Compiler Transformations Optimizations(horizontal) – improve performance • Structural changes of the code -> code becomes hard to understand • Inlining – replace the symbol by its definition • Loop fusion – combine two loops into one if two loops have a similar structure and can be done in parallel • Beyond conventional compilers • Domain-specific optimizations (domain knowledge) • Global optimizations (cross multiple locations) 15
  16. 16. Source-to-Source Transformations Restructuring transformations • Editing transformations • Mechanize some simple editing operations • Ex. converting a code section into a procedure • Refactoring transformations • Recognize code • Ex. abstraction and generalization 16
  17. 17. Transformation Systems Definition • Environments for building transformational generators • Transformational generators 17
  18. 18. Elements of transformation systems A common format for the internal program representation • Abstract syntax tree, data and control flow graph Code analysis facilities • Check the input program and guide transformation A transformation engine • Apply transformations Input and output facilities for the internal representation 18
  19. 19. An Example Program text Transformed AST e.g., (y+1/y+1)+z 1+z AST Transformation Parser Unparser Engine + + / z z 1 + + / y1y 1 1 x x Rewrite Rule 19
  20. 20. Summary: Generator Technology What are Generators? Technologies for Building Generators Vertical, Horizontal, Oblique Transformations Compositional vs. Transformational Generators Kinds of Transformations • Compiler Transformations • Source-to-Source Transformations Transformation Systems 20
  21. 21. Part II: GenVoca GenVoca Approach GenVoca Model Implementing GenVoca in C++ Composition Validation 21
  22. 22. GenVoca Approach Build software system generators based on composing object-oriented layers of abstraction. • Stacked layers • Layer above refines the layer below it. Ex. add new classes OO framework v.s. GenVoca model 22
  23. 23. Transforming a framework into a GenVoca model (step 1) Identify layers of abstractions in a framework C11 C13 C21 C22 Most C31 C32 C33 Refined 23
  24. 24. Transforming a framework into a GenVoca model (step 2) Turn the hierarchy of layers upside down Most C31 C32 C33 Refined C21 C22 C11 C13 24
  25. 25. Transforming a framework into a GenVoca model (step 3) Treat “the layer below” as a parameter of “the layer” above C31 C32 C33 C21 C22 C11 C13 25
  26. 26. Transforming a framework into a GenVoca model (step 4) Provide families of alternative, parameterized layers 26
  27. 27. GenVoca Model Components and Realms • Component (or layer): an implementation of abstract data type or feature • Realm: all components that implement the same abstract data type or feature Example: S = { a, b, c } T = { d[S], e[S], f[S] } W = { n[W], m[W], p, q[T,S] } 27
  28. 28. GenVoca Model Parameters & Transformations • A component has a realm parameter for every realm that it imports. Example: S = { a, b, c } T = { d[S], e[S], f[S] } W = { n[W], m[W], p, q[T,S] } Vertical v.s. Horizontal Parameters • Vertical parameters: layer parameters • Horizontal parameters: other parameters 28
  29. 29. GenVoca Model Symmetric Components • Exports the same interface as it imports Example: S = { a, b, c } T = { d[S], e[S], f[S] } W = { n[W], m[W], p, q[T,S] } n[W], m[W] 29
  30. 30. GenVoca Model Grammar Example: S = { a, b, c } T = { d[S], e[S], f[S] } W = { n[W], m[W], p, q[T,S] } S := a | b | c T := d[S] | e[S] | f[S] W:= n[W] | m[W] | p | q[T,S] 30
  31. 31. GenVoca Model Type Expressions • describing layer composition, used to model software system Example: S := a | b | c T := d[S] | e[S] | f[S] W:= n[W] | m[W] | p | q[T,S] System_1 = d [b] System_2 = q [d[a], c] 31
  32. 32. GenVoca Model Families of Systems • The set of all component compositions Scalability • Few components, large families of systems Design Rules and Domain Models S = { a, b, c } T = { d[S], e[S], f[S] } d[a], d[b], d[c], e[a], e[b], e[c], f[a], f[b], f[c] • Type expression, syntax correct, semantics wrong • Domain-specific constrains -> Design rules • Domain model: Realms of components + Design rules 32
  33. 33. An Example – Booch Data Structure Data Structure Families • Bag: unordered collection of objects • Queue: ordered sequence of objects with FIFO semantics Data Structure Features for Every Family • Unbounded: No upper bound on total number of objects • Concurrent: A multithread environment, read/write serialized • Managed: Free objects are stored on a list for subsequent reuse. Data Structure Features only for Queue • Priority: Objects are sorted based on some priority function 33
  34. 34. An Example – Booch Data Structure Bag[Concurrent[Size_of[Unbounded[Managed[heap]]]]] Formal Bag parameter Concurrent Multiple Parameters Size_of Unbounded Managed Used as a heap parameter of 34
  35. 35. Implementing GenVoca Layers in C++ Implement GenVoca layers as class templates containing member classes Example: LayerA 35
  36. 36. Template <class LowerLayer> Forwarding Implementation Class LayerA { public: class ClassA { public: void operationA() //refine operationA() { …//LayerA-specific work lower.operationA(); …//LayerA-specific work }; void operationB() { lower.operationB(); }; //forward operationB private: typedef typename LowerLayer::ClassA LowerLayerClassA; LowerLayerClassA lower; }; class ClassB {…}; }
  37. 37. Forwarding Static Wrapper Template <class Component> Class Wrapper { public: void operationA() //refine operationA() Problem: { …//wrapper-specific work propagation of operations component.operationA(); Solution: Inheritance …//wrapper-specific work }; void operationB() { component.operationB(); }; //forward operationB private: Component component; } 37
  38. 38. Inheritance-based Static Wrapper Template <class Component> Class Wrapper : public Component { public: void operationA() //refine operationA() { …//wrapper-specific work Component :: operationA(); …//wrapper-specific work }; } 38
  39. 39. Template <class LowerLayer> Inheritance-based Implementation Class LayerA { private: typedef typename LowerLayer::ClassA LowerLayerClassA; typedef typename LowerLayer::ClassB LowerLayerClassB; public: class ClassA : Public LowerLayerA { public: void operationA() //refine operationA() { …//LayerA-specific work LowerLayerClassA :: operationA(); …//LayerA-specific work }; }; class ClassB : Public LowerLayerClassB {…}; }
  40. 40. Upward Type Propagation Scope operator, :: typedef Problem: the layer might have to explicitly pass types they are not interested for themselves. Solution: configuration repository • an “envelop” containing all the layers, types and constants 40
  41. 41. An Example Accessing R2 and R3 Possible R1: A R1: A R2: B,C Config R2: B,C export: R3: D,E Global1, Global2 ConfigA::HorizA Accessing R3 ConfigB::HorizB Possible 41
  42. 42. Downward Type Propagation Idea: put the whole layer hierarchy into the configuration repository. Access R1 R1: A possible R2: B Config export: R1, R2 42
  43. 43. Composition Validation Problem: syntactically correct composition might be wrong in semantics. Example: DS_Size: guarded[DS_Size] | concurrent[DS_Size] multiple[DS_Size] | size_of[DS] | … DS : bounded | unbounded[Memory] | … guarded[guarded[multiple[concurrent[guarded[concurrent[si ze_of[bounded]]]]]]] Solution: Configuration Rules 43
  44. 44. A model – Conditions & Restrictions Upward and downward propagation of attributes that represent constraints on layers or properties of layers Conditions: constraints propagated downwards Restrictions: constraints propagated upwards Postrestrictions Preconditions Layer A Prerestrictions Postconditions 44
  45. 45. Summary : GenVoca GenVoca Approach GenVoca Model Implementing GenVoca in C++ Composition Validation 45
  46. 46. Part III: GenVoca vs. AOP Richard Cardone AOP: a meta-programming model that promotes code reuse by localizing the implementation of design features that cut across multiple functional unit. GenVoca: a model of hierarchical software construction that enables customized applications to be assembled from interchangeable and reusable components. 46
  47. 47. Difference & Similarity Difference • Starting point • Focus • Style Similarity • Basic concepts • Effort required for implementation 47
  48. 48. Fundamental Concepts AOP • Components, Aspects, Joint Points GenVoca • Components, Realms, Parameters 48
  49. 49. Implementation AOP • Aspect language • Weaver (preprocessor) GenVoca • Type expression • Generator (preprocessor) 49
  50. 50. Focus AOP • For any existing code base • Support code reuse by applying new features in a controlled and localized way Genvoca • Require the definition of standardized realm interfaces, domain analysis needed • Provide techniques to decompose applications into reusable and composable components 50
  51. 51. Conclusion Generators • Automate system implementation • Various levels: compiler, source-to-source • Depending on the needs • Transformation systems GenVoca • A systematic approach • Issues: • composition validation (distance) • how to get effective component composition • component changes 51
  52. 52. Sources “Generative Programming” textbook Don Batory, http://www.cs.utexas.edu/users/dsb/ • “Composition Validation and Subjectivity in GenVoca Generators”, 1997 “On the Relationship of Aspect-Oriented Programming and GenVoca”, Richard Cardone 52

×