COMPILER DESIGN IN C SOURCE CODE CODE
Programmers may have accidently written a piece of code that can never be reached. Unreachable code is a part of the program code that is never accessed because of programming constructs. We can delete the first instruction and re-write the sentence as: Multiple loading and storing of instructions may carry the same meaning even if some of them are removed. A bunch of statements is analyzed and are checked for the following possible optimization: Redundant instruction eliminationĪt source code level, the following can be done by the user:Īt compilation level, the compiler searches for instructions redundant in nature. These methods can be applied on intermediate codes as well as on target codes. By locally, we mean a small portion of the code block at hand. This optimization technique works locally on the source code to transform it into an optimized code. Interior nodes also represent the results of expressions or the identifiers/name where the values are to be stored or assigned. Leaf nodes represent identifiers, names or constants. DAG provides easy transformation on basic blocks. Directed Acyclic Graphĭirected Acyclic Graph (DAG) is a tool that depicts the structure of basic blocks, helps to see the flow of values flowing among the basic blocks, and offers optimization too. We will now see how the intermediate code is transformed into target object code (assembly code, in this case). It should be efficient in terms of CPU usage and memory management.It should carry the exact meaning of the source code.We have seen that the source code written in a higher-level language is transformed into a lower-level language that results in a lower-level object code, which should have the following minimum properties:
The code generated by the compiler is an object code of some lower-level programming language, for example, assembly language. Through post code generation, optimization process can be applied on the code, but that can be seen as a part of code generation phase itself. Code generation can be considered as the final phase of compilation.