What are the Different Compiler Engineering Techniques?

Irrespective of whatever programming language you use, your computer will only understand machine code. Then how is your application running? That is with the help of translators. Translator converts your programming language into machine code called object code which your computer can understand.


There are two types of translators: Compilers and Interpreters. Compilers convert your programming language into an intermediary representation and this intermediary representation is then converted into object code. Interpreters work in a different way. They do not have an intermediary representation. They read each line of code from your language and convert it directly to object code. Then they read next line of your code and so on. If the language you use can be easily convertible to object code then interpreters can be used.

Understanding Key Terms:

The language which you use i.e. the input language is called Source Language. Compiler which you use will be implemented using a particular language. That is termed as Implementation Language. Compiler will output object code in a different language, which is termed as Target Language. Following diagram pictorially represents these three key languages:


Assume that the source language is S and Target Language is T. Implementation language for compiler is C. Then it can be symbolically represented as KC: S?T meaning that compiler which is implemented using Implementation Language C maps source language S to the Target Language T.

Compiler Engineering Techniques:

Based on the source language, target language and other requirements (like Performance, Efficiency) Compiler can be developed with a particular implementation language. For compiler development and implementation, different compiler engineering techniques are proposed. This article will focus on the following most commonly used and famous compiler engineering techniques:

• Assembly Language as Implementation Language and Target Language
• Bootstrapping
• Cross Compiler Technology
• Virtual Machines
• Just In Time Compiler Technology

Overview of each of these techniques is given below:

Assembly Language as Implementation Language and Target Language: This is a direct solution. In general, developing a compiler involves more complications. Using assembly language as implementation language will require complex programming as well as debugging activities. This will be expensive. Hence bootstrapping technique was introduced.

Bootstrapping: In bootstrapping, compiler will compile the source program in the language used for developing source program. i.e., source language and implementation language will be the same. Assume that there is a compiler KC: A?B, where language A is a higher language when compared to assembly language. Implement a compiler with definition KA: L?B. Apply KC over KA and process the source program. Compiler mapping will now have the definition KC =KC (KA): L?B. This means that KC has bootstrapped KA.

Bootstrapping is also termed as self-hosting. Few sample languages that have bootstrapped compiler are Basic, Pascal, C, Modula-2 and much more. First language to be bootstrapped was LISP and it happened in the year 1962.

Cross Compiler Technology: Cross Compilers are used to generate target object code in a non-resident platform for the compiler. If you have to use multiple platforms to perform different computing functions while converting to target language, you can use cross-compilers.

One example for this situation is embedded systems. Embedded systems might include many systems belonging to different platforms. Then converting the whole lot of code for different systems will surely require cross compilers. You can work on different machines or even different operating systems all bounded together in a network using cross compilers.

Virtual Machines: Virtual machines are alternatives to cross compilers. They are also portable and support multiple platforms, multiple operating systems. When you have more than one target platforms, how will you translate the source program to each of the target object code? As per this technique, source program will be converted into an intermediate byte code using compilers.

This intermediate representation is then converted into object code for each of the target platforms using virtual machine emulator. Virtual machine emulator is an interpreter. Since interpreters interpret each line of code, virtual machines are comparatively slow and its performance is low. Hence Just-In-Time Compilers are introduced. Here is a pictorial representation for using virtual machines:

First virtual machine was developed for Pascal in 1970s. JVM (Java Virtual Machine) is a best example for virtual machines.

Just-In-Time Compilation: This compilation technique is also termed as dynamic compilation. It highly concentrates on increasing run time performance of your program. Using this technique, object code is generated directly in the memory and not stored anywhere. Hence there is an improvisation in performance.

As per this technique, source program is translated into an intermediate byte code. This intermediate byte code is then handled by the just-in-time compiler which coverts it into target specific object code directly inside memory. Here is a pictorial representation for usage of just-in-time compilers.

Sometimes, just-in-time compilers work together with virtual machine interpreters. Intermediate byte code is initially processed by virtual machine interpreters. If the time taken by this interpreter for a particular block of code is high and it affects performance, then just-in-time compilers will come into action and do the translation into target object code. In this case, just-in-time compilers can do the complete translation of intermediate representation into object code or perform translation for a particular file or function which consumes more time when tried with virtual machine interpreter.

First just-in-time compiler was developed for Smalltalk in 1980s. Many implementations of Java Virtual Machine use this technique. .NET Applications are also using Just-In-Time Compilers for effective and efficient compilation.

_______________________________________________________________________

Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource

|How and Why to Use Trace Option for Debugging in ASP.NET Application | How to Display Tool Tip in Your ASP.NET Web Application | How to Use “const” Class Member Modifier in C# | How to Use HTML Help Viewer in Your ASP.NET Web Application | List of Preprocessor Directives Available in C# | More about #define, #undef and Conditional Compilation Directives in C# |Understanding Different Class Member Modifiers in C# | Understanding of Diagnostic Directives and #pragma, #line, #region, #endregion Directives in C# | Usage of Roles API to Perform Authorization in .NET| What are the Different Compiler Engineering Techniques|Writing Unsafe Code in C#|

 


| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2017 - All Rights Reserved.