machine dependent compiler features
point wise ans plz
Answers
Answer:
Translating the programs from the high-level language to the machine language is the most prominent purpose of a compiler. The design of the high-level programming languages is relatively independent of the machine which has been used.
Read the introduction of compilers for high-level language.
The codes are machine dependent in the case of elementary level. It is because of the requirement of the instruction set for the generation of the code of a computer. There are several problems and issues related to this. The allocation of the registers as well as their machine instructions’ rearrangement for the execution of the efficiency improvement process.
Intermediate form
It is the form which is considered for the code optimization technique of the program which has to be compiled. Here, the analysis of the semantics and the syntax of the source statements have already taken place.
Here, in this section, we use the sequence of quadruples for the representation of the executable instructions. The form of the quadruple is as follows-
Operation op1, op2, result
Here, the function which has to be performed by the object code is the operation. The operands for this operation are op1, op2. The resulting value is placed in the result.
Intermediate code-generation routines create the quadruples which we use in the machine-dependent coding. There are several types of manipulation and analysis process which can be performed for the purpose of the optimization of the code on the quadruples. For instance, there can be a rearrangement of the quadruples for the elimination of the store operations and redundant load. In addition to this, the registers and the temporary variables get the values from the intermediate results.
Order of the quadruples
The order is in the form of the execution of the corresponding object code instructions. Then the analysis of the code is simplified, and it helps in the optimization. One more thing that can be made relatively easy is the translation of the code to the machine instructions.
Machine-Dependent Code Optimization
Here, we will begin with the use of registers and their assignment. There are several general-purpose registers which are used for holding the constants as well as the values of the variables, in addition to the intermediate results.
The registers which can be used for the addressing are present here. But here we will read about on the use of registers as instruction operands.
Which is faster?
The instructions of the machine that use the registers in place of operands take over the speed of the corresponding instructions referring to the memory locations. The preference, in that case, is the use of the registers in all the intermediated results. These are the variables and the results which are to be used in the program later.
Every time memory is fetched, there is the possibility of the assessment of the calculation as an intermediate result to the registers. We can use the value of the memory later as well. It does not make any reference to memory.
Machine-Independent Compiler Features
Structured Variables
Arrays, records, sets and strings use the structured variables. The allocation of memory to these structured variables is of prime concern here in the context of the generation of code for the reference purpose. Moderate amount of arrays is used here in detail. It can be used in the context of the other types of structured variables.
An example in PASCAL declaration:
A: ARRAY [1….10] OF INTEGER
Here we have ten elements in the array. If each integer in the memory uses one word, then we need to declare the allocation of ten words in the memory for array storage. In the generalized case,
ARRAY [l…. u] OF INTEGER
The allocation of the memory and the number of words can be described here by u-l+1.
We can consider a two-dimensional array.
B: ARRAY [ 0…3, 1...6] OF INTEGER
In the first subscript, there are four different values. They are from 0 to 3. There are six different values in the second transcript. So, the total amount of memory words is 4*6=24 words for storing array.
ARRAY [ l1... u1, l2... u2] OF INTEGER
The number of words which are to be allocated to the array= (u1-l1+1) * (u2-l2+1)
Machine-Independent Code Optimization
Elimination of the common subexpression is the source of the optimization of the source code. There are various points in the program and then computes the same value by the subexpressions.
Detection of the common subexpressions
It happens with the analysis of the program’s intermediate form. One more source of optimization of the code is the removing the loop invariants. These are one of the types of subexpressions different from the rest. It is because they do not change themselves going from one iteration to the next of the loop.
Answer:
The most important function of a compiler is to translate programs from high-level languages to machine languages.
Explanation:
What does it mean to have machine-independent compiler features?
Optimizing Machine-Independent Code in Compiler Design In compiler design, code optimization is important. Compiler Design: Intermediate Code Generation In Compiler, there are three address codes. Detection of a Loop in Three Address Code | Compiler Design
Features of a Machine-Independent Compiler
Variables with Structure
Structured variables are used by arrays, records, sets, and strings. In the context of the production of code for reference purposes, the allocation of memory to these structured variables is of primary importance. A moderate number of arrays are utilized in this example. It may be used with other sorts of structured variables as well.
In PASCAL, here's an example of a declaration:
Features of a Machine-Independent Compiler
Variables with Structure
A: INTEGER ARRAY [1....10]
The array has ten elements in this case. We need to declare the allocation of 10 words in the memory for array storage if each integer in the memory requires one word. In the broadest sense,
INTEGER ARRAY [l.... u]
u-l+1 describes the memory allocation and the amount of words in this case.
A two-dimensional array can be considered.
B: INTEGER ARRAY [0...3, 1...6]
There are four distinct values in the first subscript. They range in value from 0 to 3. In the second transcript, there are six distinct values. As a result, the total number of memory words required to store the array is 4*6=24.
ARRAY OF INTEGERS [l1... u1, l2... u2]
The source of source code optimization is the elimination of common subexpressions. There are several locations in the program where the same value is computed using subexpressions.
Identifying the most prevalent subexpressions
This occurs during the examination of the program's intermediate form. The removal of loop invariants is another source of code optimization. These are the subexpressions that are distinct from the others. It's because they don't alter as the loop progresses from one iteration to the next.