Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • This slide will show how ACC fits into the compilation of a C program. This is a compilation process of a C program, including preprocessing and compiling stages. The output from the preprocessing stage is fed into compiling stage, and the compilng will generate executable. ACC adds a new stage, between preprocessing and compiling. We call it weaving stage. During weaving stage, ACC will do parsing, semantic checking , matching join point, and other works. The output of the weaving stage are normal C files, which then compiled by ordinary C compiler, like gcc. In summary, ACC is a source-to-source transformation tool.
  • In ACC, we define an aspect to be a file or a list of files which are able to modularize a crosscutting concern. Syntatically, an aspect contains normal C code and ACC-extension to define pointcut or advice. This is a simple aspect. Could anyone guess what this aspect is about ? It is a memory profiling aspect. It counts the number of bytes allocated by malloc(), and it will print out the total used memory after the main() is done. The black parts are normal C code. The colored parts are ACC-extensions. Most specifically, the red parts are pointcut declaration, and the green parts are advice definition.
  • This is a basic and simple red black tree. The first concern is trace. The second concern is a memory profiling aspect. We hope to know how many memory used. The third concern is adding a field to the root node of the red black tree to record the number of nodes The last concern is call thread pointer support. In order to improve the efficiency of traversing the tree. It will utilize the 2 children pointer of each leafs to point to the predecessor and successor of each leaf. As you can see, as those 4 concerns are added to the base red black tree, the implementations of the tree could become more complex.
  • Because these previous 4 concerns are crosscutting the red black tree implemenations, we implemented them by using 4 aspects. By customizing the red black tree with 4 aspects, we can create 16 distinct instances of red black trees. I will do the demo to show how to create those instances. Do the demo. Since red black tree is still a simple C projects, I can manually set up aspect compilation inside Makefile, which is like: Though we can do it for small projects, it is not suitable for integrating aspects into building of large C projects. During our refactoring work, we also realize such a problem. So Charles wrote a set of weave adapters in order to automatically and easily incorporate aspects into the building process of large C projects. Though it was still experimental, we used it successfully in gcc, orbit2 and Nut/OS case studies.
  • Stop here
  • Show output of gcc.
  • ppt

    1. 1. A spect- o riented P rogramming <ul><li>AOP is </li></ul><ul><ul><li>a programming paradigm that aims to support the modularization of crosscutting concerns in software </li></ul></ul><ul><ul><li>complementary to existing paradigms </li></ul></ul><ul><li>Emerged about 10 years ago from different research efforts studying the separation of concerns in software </li></ul><ul><li>Supported in industry today by IBM, BEA,… </li></ul><ul><li>AOP support is available for Java, C++, C, PHP, … </li></ul><ul><li>AspectJ, AspectC++, AspectC, AOPHP, … </li></ul>
    2. 2. AOP Key Idea base/core program aspect weave final system
    3. 3. AspeCt-oriented C (ACC) <ul><li>Designed by Michael Gong and Hans-Arno Jacobsen </li></ul><ul><ul><li>started around April 2006 </li></ul></ul><ul><ul><li>as an effort by the Middleware Systems Research Group at the University of Toronto </li></ul></ul><ul><li>An aspect-oriented extension to C </li></ul><ul><li>Highlights comprise </li></ul><ul><ul><li>ANSI-C and C99 compliance </li></ul></ul><ul><ul><li>gcc source-compatibility </li></ul></ul><ul><ul><li>Compiler and generated code portability </li></ul></ul><ul><ul><li>Seamless Linux, Solaris and Windows support (Mac OSX support in progress) </li></ul></ul><ul><ul><li>Integration into existing build processes possible </li></ul></ul><ul><ul><li>Code transparency through source-to-source transformations </li></ul></ul><ul><ul><li>Based on open source license and compiler </li></ul></ul>
    4. 4. ACC Key Idea normal C files C files with ACC extensions ACC compilation normal C files compilation executable
    5. 5. ACC Work Flow
    6. 6. ACC Features <ul><li>join point : function call/execution, variable set/get </li></ul><ul><li>advice : before, after , and around </li></ul><ul><li>pointcut :call(), execution(), args(), infile(), infunc(), result() </li></ul><ul><li>pointcut composition, named pointcut </li></ul><ul><li>proceed() , cflow(), preturn() </li></ul><ul><li>wildcard character matching through “$” and “…” </li></ul><ul><li>exception handling: </li></ul><ul><ul><li>try() pointcut, catch() advice, throw() call </li></ul></ul><ul><li>reflective information about join points </li></ul><ul><li>static crosscutting support : add new struct/union member </li></ul><ul><ul><li>intype() pointcut and introduce() advice </li></ul></ul><ul><li>support debugging on the original sources </li></ul><ul><li>match join points inside aspects </li></ul><ul><li>seemingly integration into existing building system: tacc </li></ul>
    7. 7. Aspects in ACC #include <stdio.h> int functionCounter; void printResult() { printf(“total functions called = %d ”, functionCounter; } pointcut ExecMain(): execution (int main()) ; before (): ExecMain() { functionCounter = 0; } before () : call($ $(…)) { functionCounter ++; } after (): ExecMain() { printResult(); } <ul><li>Aspect = a file having ACC extension & C code </li></ul>an aspect counting # of function calls helper function counter named pointcut before executing main, initialize counter before any function call, increase the counter after executing main, print result
    8. 8. ACC Example: #include <stdio.h> #include <stdlib.h> size_t totalMem = 0; void print() { printf(&quot;total = %d &quot;, totalMem); } after(): execution(int main()) { print(); } before(size_t s): call($ malloc(...)) && args(s) { totalMem += s; } pointcut advice Memory Profiling Aspect
    9. 9. ACC Example: Red-Black Tree
    10. 10. ACC Demo: Software Product Lines <ul><li>16 instances of RBT </li></ul>test.c ACC rb-test.c rb.c trace node count memory profiler core aspects thread pointer 1 5 9 13 14 15 16 7 3 2 8 6 4 11 12 10
    11. 11. ACC Example: Nut/OS <ul><li>Ethernut project </li></ul><ul><ul><li>hardware and open source software project for building tiny embedded Ethernet devices. </li></ul></ul><ul><ul><li>hardware </li></ul></ul><ul><ul><ul><li>ATmega128 CPU </li></ul></ul></ul><ul><ul><ul><li>on-chip 128 kBytes of Flash memory </li></ul></ul></ul><ul><ul><ul><li>external 32 kByte SRAM </li></ul></ul></ul><ul><ul><ul><li>10 MBit Ethernet interface </li></ul></ul></ul><ul><ul><li>software </li></ul></ul><ul><ul><ul><li>Nut/OS </li></ul></ul></ul><ul><ul><ul><ul><li>a simple real-time-operating-system </li></ul></ul></ul></ul><ul><ul><ul><ul><li>~110 KLOC </li></ul></ul></ul></ul>http://www.ethernut.de/en/
    12. 12. ACC Example: Tracing In Nut/OS
    13. 13. ACC Example: GCC <ul><li>Aspectized GCC 4 </li></ul><ul><ul><li>a tracing aspect for GCC </li></ul></ul>#include<stdio.h> void main(){         char *cool = &quot;cool&quot;;         printf(&quot;%s &quot;,cool); } GCC internal function calls during compilation: 1. main 2. xmalloc_set_program_name 3. unlock_std_streams 4. unlock_1 5. unlock_1 … 637925: delete_temp_files 637926: delete_if_ordinary 637927: stat 637928: delete_if_ordinary 637929: stat
    14. 14. www. aspectc .net