e641fd845260e4f78350cc863fafc322.ppt
- Количество слайдов: 36
Portability by Automatic Translation: Two Case Studies Yishai A. Feldman The Interdisciplinary Center Herzliya, Israel
First Case: Bogart Large-Scale Translation from Assembly Language to C Joint Work with Doron A. Friedman
The Problem u u 400, 000 lines of IBM 370 assembly code Customers downsizing mainframes Hand-optimized code over 15 calendar years Live system
Success Criteria u Portability u Efficiency u Minimum manual work BUT u Readability is not important
Difficult Assembly Features u Registers u Condition code u Untyped language u Unstructured code u Large unstructured memory areas u Portability: Different byte order u Different word size u Different pointer size u
The Simulating Translator LOOP OUT STM LR USING ST LA LA L LA CR BNL LA LA MR A B LR LM BR R 14, R 12, 12(R 13) R 12, R 15 HORNER, R 12 R 13, SAV+4 R 13, SAV R 7, COEF R 5, 0(R 7) R 9, 0 R 9, R 2 OUT R 9, 1(R 9) R 7, 4(R 7) R 4, R 3 R 5, 0(R 7) LOOP R 0, R 5 R 1, R 12, 24(R 13) R 14 void { HORNER(tag. SAPReg *Reg) T_stm(14, 12, ((Reg[13]. ucp+12)), Reg); Reg[12]. sw = Reg[15]. sw ; SAV[1] = Reg[13]. sw ; Reg[13]. pv = &(SAV[0]) ; Reg[7]. pv = &(COEF[0]) ; Reg[5]. sw = *(s. Word *)Reg[7]. ucp; Reg[9]. sw = 0 ; LOOP: if ((Reg[9]. sw) >= Reg[2]. sw) goto OUT; Reg[9]. sw += 1; Reg[7]. sw += 4; T_mult(&Reg[4], Reg[3]. sw) ; Reg[5]. sw += *((s. Word *)(Reg[7]. ucp)); goto LOOP ; OUT: Reg[0]. sw = Reg[5]. sw; T_lm(1, 12, ((Reg[13]. ucp+24)), Reg); return; }
Bogart Better Optimizing General-purpose Abstract Representation Translator
Translation by Abstraction, Transformation, and Reimplementation Abstraction u Control-flow Transformation and data-flow analysis u Typing by constraint propagation u Automatic cliche recognition Re-implementation
The Code Produced by Bogart void { HORNER(tag. SAPReg *Reg) T_stm(14, 12, ((Reg[13]. ucp+12)), Reg); Reg[12]. sw = Reg[15]. sw ; SAV[1] = Reg[13]. sw ; Reg[13]. pv = &(SAV[0]) ; Reg[7]. pv = &(COEF[0]) ; Reg[5]. sw = *(s. Word *)Reg[7]. ucp; Reg[9]. sw = 0 ; LOOP: if ((Reg[9]. sw) >= Reg[2]. sw) goto OUT; Reg[9]. sw += 1; Reg[7]. sw += 4; T_mult(&Reg[4], Reg[3]. sw) ; Reg[5]. sw += *((s. Word *)(Reg[7]. ucp)); goto LOOP ; OUT: Reg[0]. sw = Reg[5]. sw; T_lm(1, 12, ((Reg[13]. ucp+24)), Reg); return; } s. Word HORNER(s. Word r 2 sw, s. Word r 3 sw) { s. Word r 5 sw; s. Word. Ptr r 7 swp; s. Word r 9 sw; r 7 swp = (s. Word *)(&COEF[0]); r 5 sw = *r 7 swp; r 9 sw = 0; while (r 9 sw < r 2 sw) { r 9 sw++; r 7 swp++; r 5 sw = r 5 sw*r 3 sw + *r 7 swp; } return r 5 sw; }
Accumulating Compound Expressions Assembly Simulating translator L L BAL LPR MR LR BR Reg[11]. sw = NIG; Reg[5]. sw = *(s. Word *)Reg[4]. ucp; INCTAB(Reg); Reg[7]. sw = labs(Reg[0]. sw); T_mult(&Reg[2], Reg[7]. sw); Reg[0]. sw = Reg[3]. sw; return; R 11, NIG R 5, 0(R 4) R 14, INCTAB R 7, R 0 R 2, R 7 R 0, R 3 R 14 Bogart return r 3 sw * labs(INCTAB(NIG, (*r 4 swp)));
Example: Condition Code Support Assembly CGLOOP CH SRL BH BNH R 7, 0(R 5, R 4) R 2, 1 CGADD CGSUB Bogart r 2 sh >>= 1; temp = r 4 ucp + r 5 sh; if (r 7 sh > temp) goto CGADD; if (r 7 sh <= temp) goto CGSUB; Simulating translator if (Reg[7]. sw == *((s. Half *)((Reg[4]. ucp+Reg[5]. sw)))) __CC = _CZero; else if (Reg[7]. sw < *((s. Half *)((Reg[4]. ucp+Reg[5]. sw)))) __CC = _COne; else __CC = _CTwo; Reg[2]. uw >>= 1; if (__CC & 0 x 4) goto CGADD; if (__CC & 0 x 3) goto CGSUB;
The Plan Representation CGR CH R 2, GMF BL CONGR SRL R 2, 1 B CGR CONGR. .
Global Type Analysis by Constraint Propagation
Time and Space Comparison Bogart and Simulating Translator Simulator Bogart Time (sec. ) Space (bytes) BIN 63 4170 33 2802 HORNER 10 3302 3 2465 RANDOM 9 5447 4 2741 SAPDBMS 18 41700 9 29073 (SAPDBMS is a central Sapiens module)
Time Performance on Several Platforms (For example routine BIN) IBM 370 RS/6000 AS/400 PC (DOS) Original Assembly 0. 32 — — — Simulator 1. 74 1. 91 failed 1. 26 Bogart 1 1 Hand Crafted 0. 91 0. 97 0. 49 1. 07
Results u Bogart produces more portable code u Bogart supports a larger portion of the source language u Bogart requires less manual work in code preparation u Bogart produces more efficient code in terms of time and space performance
Conclusions u Translation by abstraction produces better results than simulation on all criteria u Simulation is simpler and faster to implement u Simulated code is easier for the programmers to debug u The advantages of the abstraction approach grow in the long term u “Research-then-transfer” versus “Industry-aslaboratory” (Colin Potts, 1993(
New Developments: Bogart Falcon 2000
Second Case: MIDAS Automatic High-Quality Reengineering of Database Programs by Temporal Abstraction Joint Work with Yossi Cohen
The Problem Legacy Database Software u Much legacy software is DP, many databaserelated programs u Conversion from older models (indexedsequential, hierarchical, network) to relational/object-oriented databases u Need to convert: u Schema u Data u Software
Network vs. Relational Databases
Network Database Program (1( 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 MOVE 0 TO STATUS 1. PERFORM UNTIL STATUS 1 IS NOT EQUAL TO ZERO FETCH NEXT STUDENT WITHIN DEPT-OF-STUDENT AT END MOVE 1 TO STATUS 1 IF STATUS 1 IS EQUAL TO 0 THEN IF STUDENT-DEGREE IS EQUAL TO 2 THEN MOVE 0 TO GRADES-SUM MOVE 0 TO GRADES-COUNT PERFORM SUM-STUDENT-GRADES DIVIDE GRADES-SUM BY GRADES-COUNT GIVING GRADES-AVG IF GRADES-AVG > 95 THEN DISPLAY. . . , GRADES-AVG END-IF END-PERFORM.
Network Database Program (2( 18 19 20 21 22 23 24 25 26 27 SUM-STUDENT-GRADES. MOVE 0 TO STATUS 2 PERFORM UNTIL STATUS 2 IS NOT EQUAL TO ZERO FETCH NEXT GRADES WITHIN STUDENT-OF-GRADES AT END MOVE 1 TO STATUS 2 IF STATUS 2 IS EQUAL TO 0 THEN ADD GRD-GRADE TO GRADES-SUM ADD 1 TO GRADES-COUNT END-IF END-PERFORM.
Naive Translation (1( 01 02 03 04 05 06 07 08 EXEC SQL DECLARE CRS 1 CURSOR FOR SELECT. . . FROM STUDENT WHERE DEPT-NAME = : DEPT-NAME END-EXEC SQL DECLARE CRS 2 CURSOR FOR SELECT. . . FROM GRADES WHERE STUDENT-ID = : STUDENT-ID END-EXEC.
09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Naive Translation (2( MOVE 0 TO STATUS 1 EXEC SQL OPEN CRS 1 END-EXEC PERFORM UNTIL STATUS 1 IS NOT EQUAL TO 0 EXEC SQL FETCH CRS 1 INTO. . . END-EXEC. IF SQL-STATUS = SQL-NOT-FOUND THEN MOVE 1 TO STATUS 1. IF STATUS 1 IS EQUAL TO 0 THEN IF STUDENT-DEGREE IS EQUAL TO 2 THEN MOVE 0 TO GRADES-SUM MOVE 0 TO GRADES-COUNT PERFORM SUM-STUDENT-GRADES DIVIDE GRADES-SUM INTO GRADES-COUNT GIVING GRADES-AVG IF GRADES-AVG > 95 THEN DISPLAY. . . , GRADES-AVG END-IF END-PERFORM. EXEC SQL CLOSE CRS 1 END-EXEC.
Naive Translation (3( 27 28 29 30 31 32 33 34 35 36 37 38 39 SUM-STUDENT-GRADES. MOVE 0 TO STATUS 2 EXEC SQL OPEN CRS 2 END-EXEC. PERFORM UNTIL STATUS 2 IS NOT EQUAL TO 0 EXEC SQL FETCH CRS 2 INTO. . . END-EXEC. IF SQL-STATUS = SQL-NOT-FOUND THEN MOVE 1 TO STATUS 2. IF STATUS 2 IS EQUAL TO 0 THEN ADD GRD-GRADE TO GRADES-SUM ADD 1 TO GRADES-COUNT END-IF END-PERFORM. EXEC SQL CLOSE CRS 2 END-EXEC.
MIDAS: Translation by Abstraction, Transformation, and Re-implementation Temporal Plan Abstraction Network DB code Temporal Abstraction Re-implementation Relational DB code
MIDAS Translation 01 02 03 04 05 06 07 08 09 10 11 12 13 EXEC SQL DECLARE CRS 1 CURSOR FOR SELECT STUDENT-ID, FIRST-NAME, LAST-NAME, AVG(GRADE) FROM STUDENT, GRADES WHERE DEGREE = 2 AND DEPT-NAME = : DEPT-NAME AND GRADES. STUDENT-ID = STUDENT-ID GROUP BY STUDENT-ID, FIRST-NAME, LAST-NAME HAVING AVG(GRADE) > 95 END-EXEC. PERFORM UNTIL SQL-STATUS = SQL-NOT-FOUND EXEC SQL FETCH CRS 1 INTO. . . END-EXEC. DISPLAY. . . , GRADES-AVG END-PERFORM
The Internal Representation: Query Graphs u Temporal abstraction u Generate / Join u Filter u Map u Aggregate u Wide-spectrum formalism
Filtering Transformation
Join-Down Transformation
Accumulation Transformation
Performance Results
Conclusions u Translation by abstraction, transformation, and re-implementation demonstrated in two domains u Query graphs as abstraction for database operations u Adapts to different schema transformations u Scalability
Conclusions and Future Work u Appropriate domain u Same host language u Few cliches give wide coverage u Important commercially u Generalizations u Other legacy models u OODB / 4 GL as targets
Questions? Papers can be downloaded from http: //www. idc. ac. il/yishai
e641fd845260e4f78350cc863fafc322.ppt