vasupedit.blogg.se

Algorithms compiler design
Algorithms compiler design




  1. #ALGORITHMS COMPILER DESIGN GENERATOR#
  2. #ALGORITHMS COMPILER DESIGN CODE#

#ALGORITHMS COMPILER DESIGN CODE#

This will then output the correct instructions appropriate for the intermediate code inputted. In this method, templates are matched over the intermediate code and when a match is found, a macro is executed, with the matched intermediate code as an input. The most basic approach to choosing the most optimal instructions is macro expansion. For example, incrementing a variable could be "INC a" vs "LDR R1, a ADD R1, R1, #1 STR a, R1" Context and data processing will affect the target code.The desired attributes of the target code.For example, floats need to be stored in unique registers Whether the set is uniform and complete will affect the target code.Generally speaking, the lower level the intermediate code is, the more efficient.The complexity of the instructions that the compiler uses is based on three factors:

#ALGORITHMS COMPILER DESIGN GENERATOR#

In the remainder of the article, we will dive into the processes that the code generator carries out to perform these actions and we will see how algorithms can help with the optimal generation. Instruction selection is also a complex process since correct and optimal instructions have to be chosen based on a multitude of factors, such as the level of the intermediate code, the individual instruction set available to the processor architecture or the desired output code. To solve this greedy algorithms are used to get a reasonable solution. To complete this, graph covering algorithms are used, for complex programs, it is NP-Complete since to represent these programs in a graphical format, DAGs are used. Much like register allocation, optimal instruction ordering is also NP-complete. float calculations), the results that are stored in the accumulator and the specific combination of registers used for double-precision arithmetic. Additionally, individual architectural features will also become an issue to deal with, such as registers which are reserved for special instructions (eg. To solve this, heuristics can be used in order to approximate the solution. This is done by a graphing algorithm which we will discuss later in the article. Generate efficient target code in both time and spaceĬode generation is a tricky problem due to the high complexity of operations required and because code itself is extremely volatile since every intermediate code that the complier deals with will be different.Įach aspect of code generation involves a complicated process, for example, optimal register assignment is NP-Complete.Preserve original function of the program defined by programmer.To convert the optimised intermediate code into target code, the code generator generally carries out 3 tasks. It is part of the final stages of compilation, within the overall hierarchy of a compiler it is located between the optimisation steps. The code generator within a compiler is responsible for converting intermediate code to target code. We will explain various functions that the code generator can perform and an example of generation. In this article we will cover the basis of code generation within the compiler, how it works and its function. Pre-requisite: Graph Coloring Introduction In this article, we have explored Code Generation in Compiler Design in depth including challenges and key techniques like Instruction Selection, Register Allocation using Graph Coloring, Instruction Ordering and much more.






Algorithms compiler design