Docstoc

A wide-spectrum type system for WSL

Document Sample
A wide-spectrum type system for WSL Powered By Docstoc
					A Wide-Spectrum Type System for
          Transformation Theory

          Matthias Ladkau




                          Refining the FermaT migration
                          process
A Wide-Spectrum Type System for WSL


  The FermaT migration process
    The FermaT migration engine applies formal proven transformations
    to a legacy system to raise the abstraction level. It uses a special
    wide-spectrum language (WSL) as intermediate language because:


    • It is extremly useful to work within a single language which is
      able to represent both low-level programs and high-level
      abstract specifications

    • The transformation system should not be biased toward a
      particular source or target language




                                                                           2/24
A Wide-Spectrum Type System for WSL


  The FermaT migration process
    The FermaT migration engine applies formal proven transformations
    to a legacy system to raise the abstraction level. It uses a special
    wide-spectrum language (WSL) as intermediate language because:



                                                                    Process
                                                                    Language
                                                                    Translation




    Language1                                        Language2
    (low-level)                                      (high-level)

                                                                                  3/24
A Wide-Spectrum Type System for WSL


  The FermaT migration process
    A concrete example is the migration from IBM 360 Assembler to ANSI
    C.




                                                                 Process
                                                                 Language
                                                                 Translation




    Assembler                                          C
    (low-level)                                   (high-level)

                                                                               4/24
A Wide-Spectrum Type System for WSL


  The FermaT migration process
    But also other scenarios should be easily possible by writing a
    „simple-minded“ translator. Here the migration from IBM 360
    Assembler to Cobol 2.



                                                                     Process
                                                                     Language
                                                                     Translation




    Assembler                                           Cobol 2
    (low-level)                                       (high-level)

                                                                                   5/24
A Wide-Spectrum Type System for WSL


  Generalisation of migration process
     „...An obvious disadvantage of working in a separate language to the source language of the
     legacy system is that translators to and from WSL will have to be written. Fortunately, for
     the „old fashioned" languages typical of legacy systems, this is not much more difficult than
     writing a parser for the language, which in turn is a simple application of well-developed
     compiler technology for which there is a wide variety of tool support available.

                                         Successful Evolution Of Software Systems, Yang & Ward



                                                                                          Process
                                                                                          Language
                                                                                          Translation




        C                                                                  Fortran
    (low-level)                                                          (high-level)

                                                                                                        6/24
A Wide-Spectrum Type System for WSL


  Example (Calculating the factorial)
    C:                                      WSL:                                   FORTRAN:
    long facul(int f) {                     PROC facul(f VAR ret) ==               FUNCTION facul(f)
      long i,ret;                            VAR < i := 0 >:
                                               ret := 1;                           IMPLICIT NONE
         ret = 1;                              i := 1;
                                               WHILE i < f + 1 DO                  INTEGER*? facul,f
         for (i=1;i<f+1;i++) {                    ret := ret * i;                  INTEGER*? ret,i
             ret = ret * i;                       i := i + 1
         }                                     OD                                  ret = 1
                                             ENDVAR
         return ret;                                                               i = 1
    }                                                                              DO WHILE (i<f+1)
                                                                                     ret = ret * i;
                                                                                     i = i + 1
    Dangerous but common assumption in C:                                          ENDDO

    sizeof (int) = sizeof (long) = sizeof (pointer)                                facul = ret;

                                                                                   END
    Length of datatype: long and int in C
                                              long       int
    PDP-11 (since 1973)                      : -         16 Bit
    PDP-11 (since 1977)                      : 32 Bit    16 Bit
    UltraSPARC v9 (Unix) (since 1995)        : 64 Bit    32 Bit
    SPARC v8 (Unix) (since 1992)             : 32 Bit    32 Bit
    Windows 32 Bit & 64 Bit                  : 32 Bit    32 Bit
    Linux 32 Bit (ILP32 data model )         : 32 Bit    32 Bit
    Linux 64 Bit (LP64 data model )          : 64 Bit    32 Bit

    The Long Road to 64 Bits, John R. Mashey, Legacy Systems Vol. 4 No. 8, October 2006
                                                                                                       7/24
A Wide-Spectrum Type System for WSL


  The FermaT migration process
    What happens really during the migration from IBM 360 Assembler to
    ANSI C




                                                                  Process
                                                                  Language
                                                                  Translation




    Assembler                                           C
    (low-level)                                    (high-level)

                                                                                8/24
A Wide-Spectrum Type System for WSL


  Example migration
   Assembler Code Section: example.lst
   Micro Focus Assembler version V3.0.18   07/21/04 Listing as of 06/22/05 16.01
      LOC DATA               ADR1  ADR2    LINE LABEL    OP       OPERANDS
   000000                                     1 FMT001A5 CSECT
                                              2 * SAMPLE PROGRAM TO LOAD A SERIES OF PROGRAMS
                                              3 * ADDRESSES STORED IN A REFERENCE TABLE
    000000                      00000000      4 R0       EQU   0
    000000                      00000001      5 R1       EQU   1
    000000                      00000003      6 R3       EQU   3
    000000                      00000005      7 R5       EQU   5
    000000                      00000006      8 R6       EQU   6
    000000                      0000000B      9 R11      EQU   11
    000000                      0000000E     10 R14      EQU   14
    000000                      0000000F     11 R15      EQU   15
    000000   0530                            12          BALR R3,0
    000002                                   13          USING *,R3
    000002   58B10000            000000      14          L     R11,0(R1)
    000006                                   15          USING MODSTORE,R11
    000006                                   16          LOAD EP=FMT113
    000006   45003010            000012      18+         BAL   0,*+12
    00000A   C6D4E3F1F1F34040                19+         DC    CL8'FMT113'
    000012   0A08                            20+         SVC   8
    000014   5000B000            000000      21          ST    R0,AMOD113
    000018                                   22          LOAD EP=FMT114
    000018   45003022            000024      24+         BAL   0,*+12
   ...

                                                                                                9/24
A Wide-Spectrum Type System for WSL


  Example migration
   Assembler Data Section: example.lst
   Micro Focus Assembler version V3.0.18   07/21/04 Listing as   of 06/22/05 16.01
      LOC DATA               ADR1   ADR2   LINE LABEL    OP          OPERANDS
   000088 58FF0000                000000     60+         L       15,0(15)
   00008C 05EF                               61+         BALR    14,15
   00008E 47F03042                000044     62          B       LABA
   000092 07FE                               63 LABZ     BR      R14
                                             64 *
   000094    4040404040404040                65 WREC2    DC      CL80' '
   0000E4    C1C1C1C1F1F2F3F4                66 WTAB1    DC      CL16'AAAA123456BBBCCC'
   0000F4    C2C2C2C2F1F2F3F4                67          DC      CL16'BBBB123456XXXDDD'
   000104    C3C3C3C3F1F2F3F4                68          DC      CL16'CCCC123456XXXDDD'
   000114    C4C4C4C4F1F2F3F4                69          DC      CL16'DDDD123456XXXDDD'
   000124    C5C5C5C5F1F2F3F4                70          DC      CL16'EEEE123456XXXDDD'
   000134    FF                              71          DC      X'FF'
   000135    000000                          72
   000138                                    72          LTORG
                                             73 *
    000000                                   91 MODSTORE DSECT
    000000                                   92 AMOD113 DS       F
    000004                                   93 AMOD114 DS       F
    000008                                   94 AMOD115 DS       F
   ...




                                                                                          10/24
A Wide-Spectrum Type System for WSL


  Example migration




     Translate to C




                                      11/24
A Wide-Spectrum Type System for WSL


    Example migration result
      Assembler Code Section: example.lst -> example.c
            Micro Focus Assembler version V3.0.18      07/21/04 Listing as of 06/22/05 16.01
               LOC DATA               ADR1  ADR2       LINE LABEL    OP       OPERANDS
            000000                                        1 FMT001A5 CSECT
                                                          2 * SAMPLE PROGRAM TO LOAD A SERIES OF PROGRAMS
                                                          3 * ADDRESSES STORED IN A REFERENCE TABLE
             000000                       00000000        4 R0       EQU   0
             000000                       00000001        5 R1       EQU   1
             000000
#include "FMT001A5.h"                     00000003        6 R3       EQU   3
             000000
/* End of declarations */                 00000005        7 R5       EQU   5
             000000
#include "FMT001A5_init.h"                00000006        8 R6       EQU   6
             000000                       0000000B        9 R11      EQU   11
             000000
  int fmt001a5(regs_t * p_regs)           0000000E       10 R14      EQU   14
{            000000                       0000000F       11 R15      EQU   15
             000000 0530
  regs = *p_regs;                                        12          BALR R3,0
  exit_flag =000002
              0;                                         13          USING *,R3
             000002 58B10000
/* <ENTRY POINT> */                         000000       14          L     R11,0(R1)
             000006 regs.r6;
  wds2 = (wds2_t *)                                      15          USING MODSTORE,R11
             000006
  wds1 = (wds1_t *) regs.r5;                             16          LOAD EP=FMT113
             000006 */
/* <NAME=FMT001A5> 45003010                 000012       18+         BAL   0,*+12
             00000A C6D4E3F1F1F34040 PROGRAMS */
/* SAMPLE PROGRAM TO LOAD A SERIES OF                    19+         DC    CL8'FMT113'
             000012 IN A
/* ADDRESSES STORED 0A08 REFERENCE TABLE */              20+         SVC   8
             000014 *) regs.r1;
  regs.r11 = *(FWORD5000B000                000000       21          ST    R0,AMOD113
             000018
  modstore = (modstore_t *) regs.r11;                    22          LOAD EP=FMT114
                                            000024
  result_code000018 45003022 EP=FMT113", &regs.r0,
              = load("FMT113                             24+
                                                     &regs.r1);      BAL   0,*+12
            ...
  modstore->amod113 = V_FMT113;                                                                example.lst
  result_code = load("FMT114 EP=FMT114", &regs.r0, &regs.r1);
...                                                   example.c                                     12/24
A Wide-Spectrum Type System for WSL


  Example migration result
     Assembler Data Section: example.lst -> example.h / example_init.h

                                              void
 static struct { /* --> CSECT: FMT001A5_ */ initialise_FMT001A5()
                   Micro Focus Assembler version V3.0.18 07/21/04 Listing as of 06/22/05 16.01
   BYTE __FILLER__0005[104];                  {
                       LOC DATA              ADR1   ADR2   LINE LABEL    OP       OPERANDS
   BYTE __b0007[4];                             memmove(b0007, "YES ", 4);
                   000088 58FF0000                000000     60+         L     15,0(15)
   FWORD __UNNAMED__0001;                                    (FWORD)b0007;
                                                STAR__0001 = 61+
                   00008C 05EF                                           BALR 14,15
   BYTE __FILLER__0006[8];                                    =
                                                UNNAMED__000362 V_FMT200;B
                   00008E 47F03042                000044                       LABA
   FWORD __STAR__0001;                                        ' ', 80); BR
                                                memset(wrec2,63 LABZ
                   000092 07FE                                                 R14
   BYTE __FILLER__0007[8];                      memmove(wtab1, "AAAA123456BBBCCC", 16);
                                                             64 *
   FWORD __UNNAMED__0003;                     ...
                   000094 4040404040404040                   65 WREC2    DC    CL80' example_init.c
                                                                                      '
   BYTE __FILLER__0008[12];
                   0000E4 C1C1C1C1F1F2F3F4                   66 WTAB1    DC    CL16'AAAA123456BBBCCC'
   BYTE __wrec2[80];
                   0000F4 C2C2C2C2F1F2F3F4                   67          DC    CL16'BBBB123456XXXDDD'
   BYTE __wtab1[16];
                   000104 C3C3C3C3F1F2F3F4                   68          DC    CL16'CCCC123456XXXDDD'
   BYTE __UNNAMED__0004[16];
                   000114 C4C4C4C4F1F2F3F4                   69          DC    CL16'DDDD123456XXXDDD'
   BYTE __UNNAMED__0005[16];
                   000124 C5C5C5C5F1F2F3F4                   70          DC    CL16'EEEE123456XXXDDD'
   BYTE __UNNAMED__0006[16];
                   000134 FF                                 71          DC    X'FF'
   BYTE __UNNAMED__0007[16];
                   000135 000000                             72
   BYTE __UNNAMED__0008;
                   000138                                    72          LTORG
 } __attribute__((packed)) local;
                                                             73 *
                   000000                                    91 MODSTORE DSECT
 typedef struct { /* modstore */
                   000000                                    92 AMOD113 DS     F
   FWORD amod113;
                   000004                                    93 AMOD114 DS     F
   FWORD amod114;
                   000008                                    94 AMOD115 DS     F
   FWORD amod115;
                  ...                                                                       example.lst
 } __attribute__((packed)) modstore_t;
  ...
                                   example.h
                                                                                                13/24
A Wide-Spectrum Type System for WSL


  Conclusion
   •   Translator is not a “simple minded” parser. It has to be quiete complex
       due to the extraction and restructuring of data structures.

   •   Parser has to know the target language and is bound to it. (The
       translator for assembler to C migration is different to the translator for
       assembler to COBOL 2.

                                                                             Process
                                                                             Language
                                                                             Translation




    Assembler                                                      C
    (low-level)                                               (high-level)

                                                                                        14/24
A Wide-Spectrum Type System for WSL


  Generalisation of migration process
     „...An obvious disadvantage of working in a separate language to the source language of the
     legacy system is that translators to and from WSL will have to be written. Fortunately, for
     the „old fashioned" languages typical of legacy systems, this is not much more difficult than
     writing a parser for the language, which in turn is a simple application of well-developed
     compiler technology for which there is a wide variety of tool support available.

                                         Successful Evolution Of Software Systems, Yang & Ward




                                                                                             Process
                                  Translation of Data Structures                             Language
                                                                                             Translation




                Assembler                                                          C
                (low-level)                                                   (high-level)
                                                                                                        15/24
A Wide-Spectrum Type System for WSL


  Why should a language have a type system ?

  •   Assigning datatypes ("typing") gives
      meaning to collections of bits.

  •   A type system can prove a program to
      be free of certain kinds of
      misbehaviour.

  •   The introduction of a type system
      doesn’t change but clarify the
      behaviour of a program.

  •   The more defined and strict a type
      system is the better the change to
                                             The different forms of typing ...
      migrate a software system to another
      platform easily.




                                                                       16/24
A Wide-Spectrum Type System for WSL


  A Wide-Spectrum Type System
   • The great advantage of WSL is that the language can model
     low-level constructs but also high-level specifications in
     one language. A type-system for WSL should have similar
     properties.

   • The type system must be able to model as close as possible
     the type-systems of potential target languages.

   • The strictness of the type system must be adjustable during
     the migration process.

   • The process of type checking must report found typing errors
     clearly and comprehensible to the maintainer so they can be
     resolved quickly.




                                                                    17/24
A Wide-Spectrum Type System for WSL


                                                              An object oriented version of WSL
     The approach                                             including inheritance, modularity,
C#          OO Typed WSL
                                                              encapsulation, etc...
                                 Java


                                                              A typed WSL without pointers and no
        Strong-Safe Typed WSL    FORTRAN
                                                              unsafe type-casting possibilities.

       Strong-Unsafe Typed WSL                   A typed WSL with pointers but more diversification of
                                                 types and only limited unsafe type-casting possibilities.
       Weak-Unsafe Typed WSL
 C
                                                            A typed WSL which includes pointers
                                                            and unsafe type-casting.
          Simple Typed WSL
                                                            A simple typed WSL which expicitly
         Dynamic Typed WSL
                                                            expresses the implicit dynamic typing
                                   Transformation
                                                            of the current WSL.
                                   Translation
                                                            The current WSL with no type
              Untyped
             Assembler             Layer                    annotations at all.

 A layered type-system infrastructure with type transformation to
 move a given program among the different layers
                                                                                                     18/24
A Wide-Spectrum Type System for WSL


  Enhancing the migration process




     Translate to C




                                      19/24
A Wide-Spectrum Type System for WSL


  Enhancing the migration process
   a2w                                             datreorg
    Convert Assembler     <File>.dat                          Reorganise                    <File>.da2
         to WSL                                                  Data

                          <File>.ws1




  dat2ll
      Extract used
       variables
                          <File>.ll

                                      dat2wsl
  dotrans
          Apply                         Create WSL variable                <File>.wsl
    transformations                        declarations




                                                                            Perform
         <File>.ws7                                                        Typecheck


  wsl2c
  tidy_c
         Translate to C




         <File>.c                        <File>_init.h                           <File>.h                20/24
A Wide-Spectrum Type System for WSL


  Conclusion
   • The migration process is more general by including the data
     structures into WSL. WSL can now model the properties of the
     „old fashioned" legacy system languages more accuratly.

   • The translator does not have to know the target language any
     more. It is not longer bound to a particular pair of source-
     target languages.

   • A new kind of transformation is possible which take the
     complete data structures into account and their layout in the
     memory.

   • The migration to object oriented languages is only possible
     when a type system is present.




                                                                     21/24
A Wide-Spectrum Type System for WSL


  Typing Examples
    C:                                      WSL:                                   FORTRAN:
    long facul(int f) {                     PROC facul(INTEGER*4 :: f VAR          FUNCTION facul(f)
      long i,ret;                           INTEGER*8 :: ret) ==
                                             VAR <INTEGER*8 :: i := 0 >:           IMPLICIT NONE
         ret = 1;                              ret := 1;
                                               i := 1;                             INTEGER*4 f
         for (i=1;i<f+1;i++) {                 WHILE i < f + 1 DO                  INTEGER*8 facul,ret,i
             ret = ret * i;                       ret := ret * i;
         }                                        i := i + 1                       ret = 1
                                               OD
         return ret;                         ENDVAR                                i = 1
    }                                                                              DO WHILE (i<f+1)
                                                                                     ret = ret * i;
                                                                                     i = i + 1
                                                                                   ENDDO

                                                                                   facul = ret;

                                                                                   END
    Length of datatype: long and int in C
                                              long       int
    PDP-11 (since 1973)                      : -         16 Bit
    PDP-11 (since 1977)                      : 32 Bit    16 Bit
    UltraSPARC v9 (Unix) (since 1995)        : 64 Bit    32 Bit
    SPARC v8 (Unix) (since 1992)             : 32 Bit    32 Bit
    Windows 32 Bit & 64 Bit                  : 32 Bit    32 Bit
    Linux 32 Bit (ILP32 data model )         : 32 Bit    32 Bit
    Linux 64 Bit (LP64 data model )          : 64 Bit    32 Bit

    The Long Road to 64 Bits, John R. Mashey, Legacy Systems Vol. 4 No. 8, October 2006
                                                                                                           22/24
A Wide-Spectrum Type System for WSL


  Typing Examples
 C:" <ENTRY POINT> ";                                 static struct { /* --> CSECT: FMT001A5_ */
 WDS2 := r6;                                            BYTE __FILLER__0005[104];
 WDS1 := r5;                                            BYTE __b0007[4];
 C:" <NAME=FMT001A5> ";                                 FWORD __UNNAMED__0001;
 r1 := __r1_init__;                                     BYTE __FILLER__0006[8];
 C:"* SAMPLE PROGRAM TO LOAD A SERIES OF PROGRAMS";
                                                        FWORD __STAR__0001;
 C:"* ADDRESSES STORED IN A REFERENCE TABLE";
 C:"<FermaT> 00000020 r0 r3";                           BYTE __FILLER__0007[8];
 C:"<FermaT> 00000022 r11 r1";                          FWORD __UNNAMED__0003;
 r11 := a[r1, 4];                                       BYTE __FILLER__0008[12];
 MODSTORE := r11;                                       BYTE __wrec2[80];
 C:"<FermaT> 00000024 r0 r1 r15";                       BYTE __wtab1[16];
 r0 := NOT_USED;                                        BYTE __UNNAMED__0004[16];
 r1 := NOT_USED;                                        BYTE __UNNAMED__0005[16];
 result_code := NOT_USED;                               BYTE __UNNAMED__0006[16];
 !P LOAD("FMT113 EP=FMT113"                             BYTE __UNNAMED__0007[16];
  VAR r0, r1, result_code, os);
                                                        BYTE __UNNAMED__0008;
 C:"<FermaT> 00000028 AMOD113 r0";
 a[MODSTORE].AMOD113 := v_fmt113;                     } __attribute__((packed)) local;
 C:"<FermaT> 00000029 r0 r1 r15";
 r0 := NOT_USED;                                      typedef struct { /* modstore */
 r1 := NOT_USED;                                        FWORD amod113;
 result_code := NOT_USED;                               FWORD amod114;
 !P LOAD("FMT114 EP=FMT114"                             FWORD amod115;
  VAR r0, r1, result_code, os);                       } __attribute__((packed)) modstore_t;
 C:"<FermaT> 00000033 AMOD114 r0";                     ...
 a[MODSTORE].AMOD114 := v_fmt114;
 C:"<FermaT> 00000034 r0 r1 r15";                                                        example.h
 r0 := NOT_USED;
 r1 := NOT_USED;
 result_code := NOT_USED;
 !P LOAD("FMT115 EP=FMT115"
  VAR r0, r1, result_code, os);         example.ws7
                                                                                              23/24
A Wide-Spectrum Type System for WSL


   Typing Examples
C:"Type-Level: WeakUnsafeTypedWSL DirectMemoryAccess";   ...

VAR <                                                           STRUCT :: MODSTORE_structure := <
   INTEGER*0 :: r15 := 15,                                       INTEGER*4 :: AMOD113 := 0,
   INTEGER*0 :: r14 := 14,                                       INTEGER*4 :: AMOD114 := 0,
   INTEGER*0 :: r11 := 11,                                       INTEGER*4 :: AMOD115 := 0    >,
   INTEGER*0 :: r6 := 6,                                        MODSTORE_structure :: MODSTORE :=
   INTEGER*0 :: r5 := 5,                                            {MODSTORE_structure} < >,
   INTEGER*0 :: r3 := 3,
   INTEGER*0 :: r1 := 1,                                        LIST<POINTER*0> :: a := {LIST<POINTER*0>} < >
   INTEGER*0 :: r0 := 0,                                       >:
   INTEGER*104 :: filler_FMT001A5__0001 := -1,
   STRING*4 :: B0007 := "YES",                           SYMBOL WDS1L "star__0002-WDS1F1";
   INTEGER*4 :: unnamed__0001 := 0,                      SYMBOL MFI0008 star__0001;
   INTEGER*8 :: filler_FMT001A5__0002 := -1,
                                                         C:" <ENTRY POINT> ";
   STRING*4 :: star__0001 := "B0007",
                                                         WDS2 := r6;
   INTEGER*8 :: filler_FMT001A5__0003 := -1,
                                                         WDS1 := r5;
   STRING*4 :: unnamed__0003 := "FMT200",                C:" <NAME=FMT001A5> ";
   INTEGER*12 :: filler_FMT001A5__0004 := -1,            r1 := __r1_init__;
   STRING*80 :: WREC2 := " ",                            C:"* SAMPLE PROGRAM TO LOAD A SERIES OF PROGRAMS";
   STRING*16 :: WTAB1 := "AAAA123456BBBCCC",             C:"* ADDRESSES STORED IN A REFERENCE TABLE";
   STRING*16 :: unnamed__0004 := "BBBB123456XXXDDD",     C:"<FermaT> 00000020 r0 r3";
   STRING*16 :: unnamed__0005 := "CCCC123456XXXDDD",     C:"<FermaT> 00000022 r11 r1";
   STRING*16 :: unnamed__0006 := "DDDD123456XXXDDD",     r11 := a[r1,4];
                                                         MODSTORE := r11;
   STRING*16 :: unnamed__0007 := "EEEE123456XXXDDD",
                                                         C:"<FermaT> 00000024 r0 r1 r15";
   INTEGER*1 :: unnamed__0008 := 0xFF,
                                                         r0 := NOT_USED;
                                                         r1 := NOT_USED;
                                                         result_code := NOT_USED;
                                                         !P LOAD("FMT113 EP=FMT113" VAR r0,r1,result_code,os);
                                                         ...


                                                                                                    example.wsl
                                                                                                                  24/24
A Wide-Spectrum Type System for WSL


             Thanks for your questions ...




                                             25/24

				
DOCUMENT INFO