One problem (of many) with the code we generated in Section 15.3 is that it computes at
Question:
One problem (of many) with the code we generated in Section 15.3 is that it computes at run time the value of expressions that could have been computed at compile time. Modify the grammar of Figure 15.6 to perform a simple form of constant folding: whenever both operands of an operator are compile-time constants, we should compute the value at compile time and then generate code that uses the value directly. Be sure to consider how to handle overflow.
Figure 15.6:
Transcribed Image Text:
reg_names : array [0..k–1] of register_name := ["r1" "r2" ..., "rk"] -- ordered set of temporaries !! program - stmt stmt.next.free_reg := 0 program.code := ["main:"] + stmt.code + ["goto exit"] while : stmt → expr stmtz stmtz • expr.next.free_reg := stmt2.next.free_reg := stmt3.next_free_reg := stmt.next.free_reg L1:= new.label(); L2 := newJabel() stmtj.code := ["goto" L1] + [L2 ":"] + stmt2.code + [L1 ":"] + expr.code + ["if" expr.reg "goto" L2] + stmt3.code if : stmti expr stmtz stmt3 stmt4 expr.next.free_reg := stmt2.next_free_reg := stmt3.next_free_reg := stmt4.next_free_reg := stmtj.next-free-reg L1:= new.label(); L2 := newJabel() stmtj.code := expr.code + ["if" expr.reg "goto" L1] + stmt3.code + ["goto" L2] + [L1 ":"] + stmtz.code + [L2 ":"] + stmtą.code assign : stmt → id expr stmtz expr.next.free_reg := stmt,.next.free. reg := stmtj.next.free.reg stmti.code := expr.code + [id.stp→name ":=" expr.reg] + stmt2.code read : stmtį + id, idz stmt2 stmtj.code := ["a1 := &" idj.stp-name] + ["call" if id2.stp type = int then "readint" else ..] + [id2.stp→name ":= rv"] + stmt2.code -- file write : stmt → id expr stmt2 expr.next.free_reg := stmt2.next.free reg := stmtj.next.free.reg stmtj.code := ["a1 := &" id.stp→name] + ["a2 :=" expr.reg] + ["call" if id.stp type int then "writeint" else ...] + stmt2.code -- file -- value %3D writeln : stmt id stmtz stmtj.code := ["a1 := &" id.stpname] + ["call writeln"] + stmt2.code null : stmt
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 36% (11 reviews)
ANSWER regnames array 0k1 of registername r1 r2 rk ordered set of temporaries program stmt stmtnextf...View the full answer
Answered By
Churchil Mino
I have been a tutor for 2 years and have experience working with students of all ages and abilities. I am comfortable working with students one-on-one or in small groups, and am able to adapt my teaching style to meet the needs of each individual. I am patient and supportive, and my goal is to help my students succeed.
I have a strong background in math and science, and have tutored students in these subjects at all levels, from elementary school to college. I have also helped students prepare for standardized tests such as the SAT and ACT. In addition to academic tutoring, I have also worked as a swim coach and a camp counselor, and have experience working with children with special needs.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Eight people were asked to perform a simple puzzle-assembly task under normal conditions and under stressful conditions. During the stressful time, a stimulus was delivered to subjects 3 minutes...
-
How many time constants will it take for a charged capacitor to be discharged to one-fourth of its initial stored energy?
-
Generate equilibrium constant expressions for the following reactions. Calculate numerical values for Keq.
-
In a popular carnival ride called The Centrifuge, shown above, riders stand against the inside wall of a large cylinder, which starts spinning. The radius of the circle traveled by the riders is 4 ....
-
Consider a thermal energy reservoir at 1500 K that can supply heat at a rate of 150,000 kJ/h. Determine the exergy of this supplied energy, assuming an environmental temperature of 25C.
-
12. In late 2018 "company XYZ" discovered that "sales revenues" of 2016 was overstated by $ 40,000, and "selling expenses" was understated by $ 30,000. What is the balance of retained earnings as of...
-
Do antioxidants prevent cancer? People who eat lots of fruits and vegetables have lower rates of colon cancer than those who eat little of these foods. Fruits and vegetables are rich in antioxidants...
-
Writing Improvement Exercise: Employing Passive-Voice Verbs Your Task. Revise the following sentences to present the bad news with passive-voice verbs. a. Company policy prevents us from offering...
-
A govemment issued $4 million of general obligation bonds on November 1, 2022, to build a firehouse. The first debt service payment ($200,000 principal plus 6 percent interest per annum on...
-
Mr B aged 52 years, has earned rupees 75,00,000 out of his business. His ex-wife gifted him a car worth rupees 8 lakh. He spent a total of rupees 20 lakh during a family trip. He won a lottery of 16...
-
Modify the grammar of Figure 15.6 to generate jump code for Boolean expressions, as described in Section 6.4.1. You should assume short circuit evaluation. Figure 15.6 : type = int then "readint"...
-
Add productions and attribute rules to the grammar of Figure 15.6 to handle Ada-style for loops. Using your modified grammar, hand-translate the syntax tree of Figure 15.10 into pseudo assembly...
-
Felicia Manufacturing Company sells a single model of an auxiliary fuel tank which is manufactured in two producing departments, Fabricating and Finishing. Each fuel tank is cut from steel, shaped,...
-
The equation for the standard normal curve (the normal curve with mean 0 and standard deviation 1) graphs as an exponential curve. Graph this curve, whose equation is \[y=\frac{e^{-x^{2} /...
-
Design an undirected network with N=7 and L=12. Based on how you drew your network, classify it as either fully connected ,random, or scale-free. Justify your decision with a short paragraph response.
-
Use the Ch08_AviaCo database shown in Figure P8.35 to work Problems 3546. Modify the MODEL table to add the attribute and insert the values shown in the following table. Table P8.35 Attribute and...
-
The Tip Calculator app does not need a Button to perform its calculations. Reimplement this app to use property listeners to perform the calculations whenever the user modifies the bill amount or...
-
A particle, carrying a positive charge of \(4 \mathrm{nC}\), located at \((5 \mathrm{~cm}, 0)\) on the \(x\)-axis experiences an attractive force of magnitude 115.2 \(\mathrm{N}\) due to an unknown...
-
How many significant figures are there in each of the following measurements? a. 4.0100 mg b. 0.05930 g c. 0.035 mm d. 3.100 s e. 8.91 10 1 L f. 9.100 10 4 cm
-
1. What is the semi-annually compounded interest rate if $200 accumulates to $318.77 in eight years? Answer in percentage with two decimal places. 2. What is the quarterly compounded interest rate if...
-
Define carrier signal and explain its role in analog transmission.
-
Calculate the baud rate for the given bit rate and type of modulation. a. 2000 bps, FSK b. 4000 bps, ASK c. 6000 bps, QPSK d. 36,000 bps, 64-QAM
-
Define analog transmission.
-
Sociology
-
I am unsure how to answer question e as there are two variable changes. In each of the following, you are given two options with selected parameters. In each case, assume the risk-free rate is 6% and...
-
On January 1, Interworks paid a contractor to construct a new cell tower at a cost of $850,000. The tower had an estimated useful life of ten years and a salvage value of $100,000. Interworks...
Study smarter with the SolutionInn App