170 likes | 190 Views
Institute for System Programming Department of CASE Systems. Alexei Ragozin Nikolai Mansurov. Generating readable programs from SDL. {ar,nick}@ispras.ru. Overview of presentation. Objectives of our project Example of generated code Techniques for generating readable programs
E N D
Institute for System Programming Department of CASE Systems Alexei Ragozin Nikolai Mansurov Generating readable programs from SDL {ar,nick}@ispras.ru Institute for System Programming, Moscow
Overview of presentation • Objectives of our project • Example of generated code • Techniques for generating readable programs • Start-up time of generated program • Quality metrics of generated code • Conclusions Institute for System Programming, Moscow
Objectives • What? • Automatic generation of readable programs from SDL-92 Readable = preserving appearance of original SDL specification • Why? • Research in new code generation techniques: • What are the properties of semantic-preserving mappings between two formal languages • How to synthesize target programs with given structural qualities • Readable generated code will lead to wider use of SDL code generators in industry Institute for System Programming, Moscow
Example SDL PROCESS Ping; TIMER Tmr; DCL Count INTEGER; START; ... STATE Wait; ... ENDSTATE; ENDPROCESS Ping; Institute for System Programming, Moscow
Example (cont.) C++ SDL PROCESS_DECL(PING); TIMER_DECL0(TMR); DCL(COUNT,int); STATE_LIST STATE_DECL(WAIT); END_STATE_LIST ENDPROCESS_DECL(PING); TIMER_DEF(TMR); PROCESS_DEF(PING) START; ... ENDSTART; STATE(WAIT); ... ENDSTATE; ENDPROCESS_DEF(PING); PROCESS Ping; TIMER Tmr; DCLCount INTEGER; START; ... STATE Wait; ... ENDSTATE; ENDPROCESS Ping; Institute for System Programming, Moscow
Example (cont.) SDL START; TASK Count := 0; Lab : OUTPUT Ping; SET(NOW + 10, Tmr); NEXTSTATE Wait; Institute for System Programming, Moscow
Example (cont.) SDL C++ START; TASK COUNT=0; LAB: OUTPUT(PING()); SET(NOW+10,TMR()); NEXTSTATE(WAIT); ENDSTART; START; TASK Count := 0; Lab : OUTPUT Ping; SET(NOW + 10, Tmr); NEXTSTATE Wait; Institute for System Programming, Moscow
Example (cont.) SDL STATE Wait; INPUT Pong; RESET(Tmr); TASK Count := Count + 1; DECISION Count = 100000; (true) : OUTPUT Finish; STOP; else : JOIN Lab; ENDDECISION; INPUT Tmr; STOP; ENDSTATE; Institute for System Programming, Moscow
Example (cont.) SDL C++ STATE(WAIT); INPUT(PONG,); RESET(TMR()); TASK COUNT = COUNT +1; DECISION(COUNT==100000); CASE( IS_EQUAL (COUNT==100000, TRUE )); OUTPUT(FINISH()); STOP; ELSE JOIN(LAB); ENDDECISION; INPUT(TMR,); STOP; ENDSTATE; STATE Wait; INPUT Pong; RESET(Tmr); TASK Count := Count + 1; DECISION Count = 100000; (true) : OUTPUT Finish; STOP; else : JOIN Lab; ENDDECISION; INPUT Tmr; STOP; ENDSTATE; Institute for System Programming, Moscow
Code generation techniques Source program c2 c1 c3 expansion d2.1 d3 d1 d2.2 fragmentation domain Target program glue Institute for System Programming, Moscow
Code generation techniques (cont.) gen macro STS RTS Source Indirect mappings gen STS RTS gen Direct mappings gen macro RTS gen RTS • gen - generated part of target program • macro - macro library • STS - start-up support • RTS - run-time support Institute for System Programming, Moscow
Start-up time «Interpreter» Direct mapping RTS Run gen gen Run STS RTS gen Run STS Indirect mapping RTS Institute for System Programming, Moscow
Start-up time (cont.) STS Macro library Generated code Macro library RTS Operating System Institute for System Programming, Moscow
Quality metrics Expansion E = Vtarget/Vsrc (for a given program) Institute for System Programming, Moscow
Quality metrics (cont.) • Structure transformation S =Rnosrc/Rsrc • Fragmentation F=1/n ni=1 Fi • Usage of names U =Utarget /Usrc (for a given program) Institute for System Programming, Moscow
Quality metrics (cont.) Benchmark time Tbench (sec) Ping-Pong benchmark with 100 000 repeats. Platform SUN ULTRASPARC-1 (147 MHz) Institute for System Programming, Moscow
Conclusions • Current state • Mapping: most SDL including SDL graph, structural types, inheritance, common cases of context parameters, excluding most SDL data • Implementation: prototype code generator for most of mapping • Generated code much more readable then produced by commercial code generators • Generated code is easily configurable, can be combined with legacy • There is no significant drop of performance of generated code Institute for System Programming, Moscow