enhancements to open source translator fable for code porting … · 2017-08-17 · a sample...
TRANSCRIPT
International Journals of Advanced Research in Computer Science and Software Engineering ISSN: 2277-128X (Volume-7, Issue-6)
Research Article
June 2017
© www.ijarcsse.com, All Rights Reserved Page | 631
Enhancements to Open Source Translator FABLE for Code
Porting of Legacy Applications S. Suguna Mallika
*, Ch. Sharada
Department of CSE, CVR College of Engineering,
Telangana, India
DOI: 10.23956/ijarcsse/V7I6/0145
Abstract - With the current and young researchers moving towards object oriented languages like C++ and Java,
maintenance of legacy software developed in languages like Fortran 77 and its native versions are becoming
increasingly difficult. To ease the maintenance of legacy software it is recommended to port them to C++ or Java. But
the task of hand coding every line of the existing software is painstakingly demanding lot of resources, time, and cost.
It is practical that any automatic translator is used for this purpose and among the many tools available, FABLE is
one. FABLE which is an open source translator, however needs some enhancements in appropriate binaries to
complete the translation successfully. This work focuses on some of the common practices of FORTRAN
programming which essentially hamper the effective translation of code. A detailed account on such challenges faced
with FABLE and enhancements done to FABLE is presented in the current work.
Keywords – FORTRAN file translation, C++ conversion, porting legacy software, code porting
I. INTRODUCTION
With the advent of many new programmer friendly languages, and the younger set of scientific community
learning the new languages like C++, the maintenance of legacy software developed in languages like FORTRAN is a
complex job[1]. Hence there is a need to translate legacy software to newer languages like C++ and Java which would
simplify the job of maintenance by the novices who are well versed with only the new languages. There is an open source
translator called “FABLE” which translates the original source program written in FORTRAN to C++ [1].
II. EXISTING CHALLENGES
Though FABLE is an automatic translator from FORTRAN to C++, there are set of challenges that we face at
three levels with respect to the translation [2]. The Source program statements may need modifications to get accurate
translations to CPP.
A. Pause Command – The pause statement in FORTRAN is used for debugging purposes which halts the program and
gives control to the user. Fable cannot interpret this statement and instead halts the translation process, throwing an error
in the command window resulting in a failure of translation. The figure 1 shows the error encountered when fable
encounters the keyword “pause”.
Figure 1. Screenshot displaying PAUSE Statement Error when translating FORTRAN code
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 632
B. Inability to process some of the mathematical functions like tanh – There are many mathematical functions which
have not been defined in the fable fem libraries. However it has been observed that the source file responsible for
mathematical functions is the intrinsics.py file for which upon some enhancements FABLE, began accepting all the
mathematical functions which it was earlier failing to do so and was creating a user defined function with the same name
and dummy code placed to avert conversion errors. The definitions for all these functions are available at intrinsics.hpp.
However FABLE would refer only to intrinsics.py file to check whether the declaration of a particular function is
available at conversion time and would refer to intrinsics.hpp only at the time of invocation of the respective function at
compile time. The screenshot of the error displayed when a function declaration is not found is as shown in figure 2 and
figure 3.
Figure 2. Error Screenshot displayed when intrinsics.py file has missing math library inbuilt functions declarations
Figure 2. Error Screenshot when intrinsics.hpp has missing definitions of inbuilt functions
C. Equivalence Statements of FORTRAN – The Equivalence statement of FORTRAN was introduced originally for
conserving the memory on the early computers which typically operated on very low RAM‟s. Non - Overlapping arrays
within a program are assigned the same memory location to save space. Most of the programming practices of legacy
programming indulged in the extensive usage of EQUIVALENCE statements due to Constraints on memory. FABLE
does translate these EQUIVALENCE statements into corresponding C++ statements replacing independent arrays
preserving the logic. However, existing FABLE constrained the acceptance of only six EQUIVALENCE statements
where in legacy code normally land up with several hundreds of such statements by virtue of memory optimization.
Hence existing FABLE renders an error during the conversion process with the error message “„with‟: is not a member of
„fem::arr_index_data<Ndims>‟” which can see highlighted in figure 4.
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 633
Figure 3. Error Screenshot of existing FABLE throwing error at 10 EQUIVALENCE statements in source code
D. Formats of FORTRAN like the “T Format” were not being implemented with Fable. Fable needs modifications in
several binaries to enhance its functionality as it has many unimplemented features of FORTRAN like t format, b format,
s format, which simply rest on throwing an errorusing tbxx utils. The translation of these formats has not been considered
in the original implementation of FABLE. Figure 5 displays the error screenshot which is due to non-handling of T
format in the source program [4].
Figure 5. Error Screenshot displaying unhandled T format version
III. ENHANCEMENTS
Several enhancements are made to the existing code to overcome the challenges listed in Section 2. Some of the major
contributions include
A. The pause statement is parsed by the cout.py and the read.py files of the fem library. These two files were modified to
overcome the translation of pause statement. A small piece of code was inserted in the cout.py to handle the pause
keyword. Figure 6 shows the code modification made to read.py to parse the pause statement during translation
successfully without any hindrance.
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 634
Figure 6. Code modification in read.py binary for handling pause statement in source FORTRAN program
And the keyword pause is added to the process body_line_function() of the read.py file which would recognize the
keyword pause upon encountering it in the FORTRAN source code. A modification in the read.py and write.py to
support the translation of pause which was earlier not supported is incorporated to enable the user driven input “go” upon
which the translator would further continue with the process of execution. After the modification of binaries to handle
pause the output is displayed as in figure 7.
Figure 7. Screenshot showing successful translation of FORTRAN program with the pause statement handled effectively
B. Inability to process some of the mathematical functions like tanh - Appropriate modifications done to the intrinsics.py
and intrinsics.hpp file where the declarations and definitions of the missing functions are placed respectively, the success
screenshot is as shown in figure 8.
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 635
Figure 8. Screenshot of successful compilation of translated CPP file with the builtin functions definitions and
declarations implemented
C. The existing implementation of FABLE which is responsible for the translation of the EQUIVALENCE statement is
supporting only 6 equivalence variables only. The code that is newly added is as shown in figure 9 after which the
converted code gets successfully compiled supporting more number of equivalence variables.
Figure 9.Original FABLE Code showing accommodating limited EQUIVALENCEs
D. T Format - For horizontal positioning along the print line, FORTRAN supports Tn format where n is a strictly
positive integer [5]. The format specifier T be preceded by a positive nonzero number.Tn tab reads from the nth column
or writes to the nth column. This feature is not supported by FABLE. As the part of FABLE enhancement, this feature is
added. To add this feature modifications are done in the write.hpp and new header file named xy.h has been created. xy.h
is the header file contains definitions of gotoxy(), wherex() and wherey() functions and gotoxy() function in C++
language is used to take the cursor to a particular co-ordinate of the screen, wherex() return current horizontal cursor
position and wherey() return current vertical cursor position. Modifications of write.hpp are shown in the figure 10.
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 636
Figure 10. Code Modification for handling one variation of T format in write.hpp binary
IV. CASE STUDY
A sample Fortran program of around 200 lines, menu driven to display ratios of various standard intrinsic
functions has been written for demonstrating the enhancements made.
C MENU DIVEN PROGRAM TO DISPLAY RATIOS
C OF STANDARD INTRINSIC FUNCTIONS
REAL*8 DSINHVAL,A,DCOSHVAL,DAS,DAC,ATAN2,DAT,DAT2
REAL*8 DSINTBL(100),DCOSTBL(100),DTANTBL(100)
EQUIVALENCE(DSINTBL,DCOSTBL,DTANTBL)
EQUIVALENCE(DARCCOSVAL,DSINHVAL,DCOSHVAL,DAS,DAC,ATAN2,DAT,DAT2)
REAL*8 J
C MENU
15 CONTINUE
WRITE(6,*) "TRIGNOMETRY RATIOS"
WRITE(6,*) " 1.Dsin"
WRITE(6,*)
WRITE(6,*) " 2.Dasin"
WRITE(6,*)
WRITE(6,*) " 3.Dsinh"
WRITE(6,*)
WRITE(6,*)
WRITE(6,*) " 4.Dcos"
WRITE(6,*)
WRITE(6,*) " 5.Dacos"
WRITE(6,*)
WRITE(6,*) " 6.DcosH"
WRITE(6,*)
WRITE(6,*)
WRITE(6,*) " 7.Dtan"
WRITE(6,*)
WRITE(6,*) " 8.Datan"
WRITE(6,*)
WRITE(6,*) " 9.Datan2"
WRITE(6,*)
WRITE(6,*) " 10.DtanH"
WRITE(6,*)
WRITE(6,*) "ENTER AN TRIGNOMETRY OPTION TO KNOW THE RATIOS"
READ(5,*) I
c OPTION 1 DISPLAY SIN RATIOS.IT RETURNS THE SINE OF GIVEN ANGLE IN RADIANS.
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 637
IF(I.EQ.1) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,115) "DSIN TABLE RATIOS FROM 0 TO 30 DEGREES"
115 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,115) "-------------------------------------"
WRITE(6,*)
WRITE(6,110) "ANGLE" , "SINVALUE"
110 FORMAT(t20,a5,T40,a9)
WRITE(6,115) "-------------------------------------"
WRITE(6,*)
DO 160 k=0, 30
j=k
DSINTBL(K+1)=DSIN(J*(3.14159265/180))
WRITE(6,100) '|', J,'|','|',DSINTBL(J+1),'|'
100 FORMAT(T20,a,f5.0,t28,a,T35,a,t40,f5.4,t50,a)
160 continue
WRITE(6,*)
WRITE(6,115) "-------------------------------------"
c OPTION 2 DISPLAY ARCSIN VALUES.RETURNS THE PRINCIPAL VALUE OF
CTHE ARC SINE OF X, EXPRESSED IN RADIANS.IN TRIGONOMETRICS, ARC
C SINE IS THE INVERSE OPERATION OF SINE
ELSE IF(I.EQ.2) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,215) "ARCSIN TABLE RATIOS"
215 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,215) "-------------------------------------"
DO 255 k=0, 30
j=k
DSINTBL(K+1)=DSIN(J*(3.14159265/180))
255 continue
WRITE(6,*)
WRITE(6,210) "SIN VALUE" , "ANGLE"
210 FORMAT(t20,a5,T40,a9)
WRITE(6,215) "-------------------------------------"
WRITE(6,*)
DO 260 k=0, 30
j=k
DAS=DASIN(DSINTBL(K+1))*(180/3.14159265)
WRITE(6,200) '|', DSINTBL(K+1),'|','|',DAS,'|'
200 FORMAT(T20,a,f7.4,t28,a,T35,a,t40,f7.2,t50,a)
260 continue
WRITE(6,*)
WRITE(6,215) "-------------------------------------"
C OPTION 3 DISPLAY HYPERBOLIC SIN VALUES.PARAMETER REPRESENTS
C A HYPERBOLIC ANGLE.
ELSE IF(I.EQ.3) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,*) " HYPERBOLIC SIN WITH DOUBLE PRECISION"
WRITE(6,*) " RETURNS THE HYPERBOLIC SINE OF ANGLE."
WRITE(6,*)
315 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,315) "-------------------------------------"
WRITE(6,*)
WRITE(6,310) "VALUE" , "HYPERBOLIC SIN IN DEGREES"
310 FORMAT(t20,a5,T40,a9)
WRITE(6,315) "-------------------------------------"
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 638
WRITE(6,*)
DO 350 K=0, 30
J=K*1.0/10
DSINHVAL=DSINH(J)
WRITE(6,320) '|', J,'|','|',DSINHVAL,'|'
320 FORMAT(T20,a,f5.2,t28,a,T35,a,t40,f8.4,t50,a)
350 continue
WRITE(6,*)
WRITE(6,315) "-------------------------------------"
C OPTION 4RETURNS THE COSINE OF AN ANGLE OF GIVEN RADIANS.
ELSE IF(I.EQ.4) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,415) "DCOS TABLE RATIOS FROM 0 TO 30 DEGREES"
415 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,415) "-------------------------------------"
WRITE(6,*)
WRITE(6,410) "ANGLE" , "DCOS VALUE"
410 FORMAT(t20,a5,T40,a9)
WRITE(6,415) "-------------------------------------"
WRITE(6,*)
DO 460 K=0, 30
J=K
DCOSTBL(K+1)=DCOS(J*(3.14159265/180))
WRITE(6,400) '|', J,'|','|',DCOSTBL(K+1),'|'
400 FORMAT(T20,a,f5.0,t28,a,T35,a,t40,f7.4,t50,a)
460 continue
WRITE(6,*)
WRITE(6,415) "-------------------------------------"
C OPTION 5 RETUNS ARC COS VALUE
ELSE IF(I.EQ.5) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,515) "DARCCOS TABLE RATIOS"
515 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,515) "-------------------------------------"
DO 555 K=0, 30
J=K
DCOSTBL(K+1)=DCOS(J*(3.14159265/180))
555 continue
WRITE(6,*)
WRITE(6,510) "ANGLE" , "COSVALUE"
510 FORMAT(t20,a5,T40,a9)
WRITE(6,515) "-------------------------------------"
WRITE(6,*)
DO 560 K=0, 30
J=K
DARCCOSVAL=DACOS(DCOSTBL(K+1))*(180/3.14159265)
WRITE(6,500) '|', DCOSTBL(K+1),'|',DARCCOSVAL,'|'
500 FORMAT(T20,a,f7.4,t28,T35,a,t40,f7.2,t50,a)
560 continue
WRITE(6,*)
WRITE(6,515) "-------------------------------------"
ELSE IF(I.EQ.6) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,*) " COMPUTE HYPERBOLIC COS"
WRITE(6,*) " RETURNS THE HYPERBOLIC COS OF ANGLE."
WRITE(6,*)
C OPTION 6 RETURN HYPERBOLIC COS IN DEGREES
615 FORMAT(T15,a40)
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 639
WRITE(6,*)
WRITE(6,615) "-------------------------------------"
WRITE(6,*)
WRITE(6,610) "VALUE" , "HYPERBOLIC COS IN DEGREES"
610 FORMAT(t20,a5,T40,a9)
WRITE(6,615) "-------------------------------------"
WRITE(6,*)
DO 660 K=0, 30
J=K*1.0/10
DCOSHVAL=DCOSH(J)
WRITE(6,600) '|', J,'|','|',DCOSHVAL,'|'
600 FORMAT(T20,a,f5.2,t28,a,T35,a,t40,f8.4,t50,a)
660 continue
WRITE(6,*)
WRITE(6,615) "-------------------------------------"
C OPTION 7 RETURN TAN VALUE FOR GIVEN RADIANS
ELSE IF(I.EQ.7) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,715) "DTAN TABLE RATIOS FROM 0 TO 30 DEGREES"
715 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,715) "-------------------------------------"
WRITE(6,*)
WRITE(6,710) "ANGLE" , "TAN VALUE"
710 FORMAT(t20,a5,T40,a9)
WRITE(6,715) "-------------------------------------"
WRITE(6,*)
DO 760 K=0, 30
J=K
DTANTBL(K+1)=DTAN(J*(3.14159265/180))
WRITE(6,700) '|', J,'|','|',DTANTBL(K+1),'|'
700 FORMAT(T20,a,f5.0,t28,a,T35,a,t40,f5.4,t50,a)
760 continue
WRITE(6,*)
WRITE(6,715) "-------------------------------------"
C OPTION 8 RETURN ARC TAN VALUE
ELSE IF(I.EQ.8) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,815) "ARCTAN TABLE RATIOS"
815 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,815) "-------------------------------------"
DO 855 K=0, 30
J=K
DTANTBL(K+1)=DTAN(J*(3.14159265/180))
855 continue
WRITE(6,*)
WRITE(6,810) "TAN VALUE" , "ARCTAN"
810 FORMAT(t20,a5,T40,a9)
WRITE(6,815) "-------------------------------------"
WRITE(6,*)
DO 860 K=0, 30
J=K
DAT=DATAN(DTANTBL(K+1))*(180/3.14159265)
WRITE(6,800) '|', DTANTBL(K+1),'|','|',DAT,'|'
800 FORMAT(T20,a,f7.4,t28,a,T35,a,t40,f7.2,t50,a)
860 continue
WRITE(6,*)
WRITE(6,815) "-------------------------------------"
c OPTION 9 COMPUTE DATAN2. ARC TANGENT WITH TWO PARAMETERS
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 640
c RETURNS THE PRINCIPAL VALUE OF THE ARC TANGENT OF
c Y/X, EXPRESSED IN RADIANS.Y VALUE REPRESENTING THE
c PROPORTION OF THE Y-COORDINATE.X VALUE REPRESENTING
c THE PROPORTION OFTHE X-COORDINATE.
ELSE IF(I.EQ.9) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,*) "SDATAN2 COMPUTE ARC TANGENT WITH TWO PARAMETERS "
WRITE(6,*) "RETURNS THE PRINCIPAL VALUE OF THE ARC TANGENT OF"
WRITE(6,*) "Y/X, EXPRESSED IN RADIANS.Y VALUE REPRESENTING THE"
WRITE(6,*) "PROPORTION OF THE Y-COORDINATE.X VALUE REPRESENTING"
WRITE(6,*) "THE PROPORTION OFTHE X-COORDINATE."
WRITE(6,*)
WRITE(6,*)
WRITE(6,915) "ARCTAN2 TABLE RATIOS"
915 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,915) "-------------------------------------"
DO 955 K=0, 30
J=K
DTANTBL(K+1)=DTAN(J*(3.14159265/180))
955 continue
WRITE(6,*)
WRITE(6,910) "Y X" , "RESULT"
910 FORMAT(t20,a15,T40,a9)
WRITE(6,915) "-------------------------------------"
WRITE(6,*)
DO 960 K=1, 30
J=K
DAT2=DATAN2(DTANTBL(K+1), J)*180/3.14159265
WRITE(6,900) DTANTBL(J+1),J,DAT2
900 FORMAT(T20,f7.4,t28,T30,f5.0,t40,f7.2,t50)
960 continue
WRITE(6,*)
WRITE(6,915) "-------------------------------------"
ELSE IF(I.EQ.10) THEN
WRITE(6,*)
WRITE(6,*)
WRITE(6,*) " HYPERBOLIC TAN WITH DOUBLE PRECISION"
WRITE(6,*) " RETURNS THE HYPERBOLIC TAN OF ANGLE."
WRITE(6,*)
1015 FORMAT(T15,a40)
WRITE(6,*)
WRITE(6,1015) "-------------------------------------"
WRITE(6,*)
WRITE(6,1010) "VALUE" , "HYPERBOLIC TAN IN DEGREES"
1010 FORMAT(t20,a5,T40,a9)
WRITE(6,1015) "-------------------------------------"
WRITE(6,*)
DO 1050 K=0, 30
J=K*1.0/10
DTANHVAL=DTANH(J)
WRITE(6,320) '|', J,'|','|',DTANHVAL,'|'
1020 FORMAT(T20,a,f5.2,t28,a,T35,a,t40,f8.4,t50,a)
1050 continue
WRITE(6,*)
WRITE(6,1015) "-------------------------------------"
END IF
PAUSE
IF (I .LE. 10) GOTO 15
stop
END
Mallika et al., International Journals of Advanced Research in Computer Science and Software Engineering
ISSN: 2277-128X (Volume-7, Issue-6)
© www.ijarcsse.com, All Rights Reserved Page | 641
V. RESULTS
Post the modifications made to the binaries of FABLE, the FORTRAN code got translated into CPP file successfully and
the results of compilation of CPP file thereof are presented in Figure 11.
Figure 11. Screenshot displaying output of successfully translated FORTRAN source code into CPP file
VI. CONCLUSIONS AND FUTURE SCOPE
The code generated through FABLE is the FORTRAN code internally embedded in a class. This class in turn invokes the
FEM (FORTRAN Emulation Library) which calls the standard C/C++ libraries. The final output is more a look alike of a
FORTRAN program than a typical C++ code. The tool could further be enhanced to replace the FORTRAN statements
with the equivalent C++ statements for the end users to emulate a hand coded translation.
ACKNOWLEDGEMENT
The authors express their whole hearted The authors would like to thank Prof. Badrinarayana, who was instrumental in
getting them introduced to this tool and encouraging them towards working on this framework. The authors express their
heartfelt gratitude to the management of CVR College of Engineering for the support and encouragement all through the
work. The authors appreciate and acknowledge the effort of the original authors of FABLE, Grosse-Kunstleve RW,
Terwilliger TC, Sauter NK, Adams PD for inspiring them towards enhancement of this work and providing open source
access for enthusiasts to further enhance the tool.
REFERENCES
[1] Ralf W Grosse-Kunstleve,Thomas C Terwilliger, Nicholas K Sauter and Paul D Adams, “Automatic Fortran to
C++ conversion with FABLE”, Open Access, Source Code for Biology and Medicine 2012.
[2] Grosse-Kunstleve RW, Terwilliger TC, Sauter NK, Adams PD: Automatic Fortran to C++ conversion with
FABLE.
[3] https://www.python.org/downloads/
[4] http://www.cse.yorku.ca/~roumani/fortran/ftn.htm.
[5] R S Dhaliwal, SK Agarwal, SK Gupta, “Programming with FORTRAN 77 A structured Approach”, New Age
International Publishers.