Topic: SOURCE TO SOURCE COMPILER Course Title: SYSTEM SOFTWARE Course Code: CAP 607SUBMITTED TO: SUBMITTED BY:Mr. SANJAY SOOD MINTOOJAKHMOLA REG. NO.: 11009054 ROLL NO.: B20 SECTION: D1006
INTRODUCTIONA compiler, in the broadest sense, is just a tool that converts from a language (or away of expressing some knowledge) into another. Most people see compilers astools that have source code as input and produce binary files as output.Source-to-source compilers have as input source code and produce source code asoutput. It is assumed that the output can be used as well as the input of anothercompiler (or even the same!).It is also known as transcompiler (or transpiler) and it is also a type of compilerthat takes the source code of a programming language as its input and outputs thesource code in another programming language. For example, it may perform atranslation of a program from Pascal to C.DEFINITION "transpiler":A program which reads code in language A and converts it into code for languageB. The transpiler converts between languages at the same level. Examples: (C++-> C, Pascal -> C).
DIFFERENCE BETWEEN COMPILER AND TRANSCOMPILERA compiler translates source code to machine code that can be understood by theCPU hardware. A transpiler translates source code to another form of source codethat can be understood by another compiler.OrThe difference between a compiler and a transpiler is that the compiler usuallyconverts from a high to a low level language (C -> Assembler, Java -> Bytecode)while the transpiler converts between languages at (roughly) the same level.Examples: (C++ -> C, Pascal -> C). SOURCE MACHINE COMPILER CODE CODE COMPILER WORKING
SOURCE SOURCE TRANSPILER CODE CODE TRANSPILER WORKINGWhy A Source-To-Source Compiler Is UsefulOne might wonder why a source-to-source compiler is useful if they aregenerating again source code and not a binary ready to run like a "full" compilerwould.Well, it turns that compilers are complex tools. Complex tools because they haveto deal with several processes including, but not limiting to: parsing the input,checking the semantics, implement these semantics, finding out opportunities ofoptimization under the semantics, generating binary code, etc.So, that is why the source-to-source compiler is useful. A source-to-sourcecompiler performs a parsing phase but the generated AST must be much more
detailed than the one of a binary generating compiler. The reason is that the outputof the source-to-source compiler must be valid as an input for another compiler. SOURCE-TO-SOURCE COMPILER EXAMPLE 1. ROSE: It is an open source compiler infrastructure to build source-to- source program transformation and analysis tools for large-scale Fortran 77/95/2003, C, C++, OpenMP, and UPC applications. 2. DMS Software Reengineering Toolkit: It is a source-to-source program transformation tool. It can be used for translating from one computer language to another, for compiling domain-specific languages to a general purpose language, or for carrying out optimizations or massive modifications within a specific language. 3. OpenMP: In this implementation is source-to-source, meaning that it converts the input program, in Fortran source, which contains OpenMP directives into an output program, also in Fortran source. The output program explicitly creates and synchronizes parallel threads to implement parallelism, as indicated by the OpenMP directives in the input program. 4. Cetus: It is a compiler infrastructure for the source-to-source transformation of software programs. It currently supports ANSI C. Since its creation in 2004, it has grown to over 80,000 lines of Java code, has been made available publicly on the web, and has become a basis for several research projects.