Jump to content

Source-to-source compiler

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Stypex (talk | contribs) at 07:39, 26 February 2011 (DMS Software Reengineering Toolkit: typo). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A source-to-source compiler is a type of compiler that takes a high level programming language as its input and outputs a high level language. For example, an automatic parallelizing compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations (e.g., OpenMP) or language constructs (e.g. Fortran's DOALL statements)[1].

Another purpose of source-to-source-compiling is translating legacy code to use the next version of the underlying programming language or an API that breaks backward compatibility. It will perform automatic code refactoring which is useful when the programs to refactor are outside the control of the original implementer (for example, converting programs from Python 2 to Python 3, or converting programs from an old API to the new API) or when the size of the program makes it impractical or time consuming to refactor it by hand.

Examples

DMS Software Reengineering Toolkit

DMS Software Reengineering Toolkit is a source-to-source program transformation tool, parameterized by explicit source and target (may be the same) computer language definitions. 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. DMS has a library of language definitions for most widely used computer languages (including full C++, and a means for defining other languages which it does not presently know.

LLVM

Low Level Virtual Machine (LLVM) can translate from any language supported by gcc 4.2.1 (Ada, C, C++, Fortran, Java, Objective-C, or Objective-C++) to any of: C, C++, or MSIL by way of the "arch" command in llvm-gcc.

% llvm-g++ x.cpp -o program
% llc -march=c program.bc -o program.c
% cc x.c

% llvm-g++ x.cpp -o program
% llc -march=msil program.bc -o program.msil

The "arch" command can also emit assembly language code in these architectures:

Refactoring tools

The refactoring tools automate transforming source code into another:

See also

References

  1. ^ "Types of compilers". compilers.net. 1997–2005. Retrieved 28 October 2010.{{cite web}}: CS1 maint: date format (link)
  2. ^ Valerie Henson (January 20, 2009). "Semantic patching with Coccinelle". lwn.net. Retrieved 28 October 2010.