Purpose Theoretically, we can directly generate theMiPS assemble code after semantic analysisIntermediate-code give us opportunities toregister allocation, code optimization andeasiness when debugging. After this, the input code and AsT can bethrown away
Purpose ⚫ Theoretically, we can directly generate the MIPS assemble code after semantic analysis. ⚫ Intermediate-code give us opportunities to register allocation, code optimization and easiness when debugging. ⚫ After this, the input code and AST can be thrown away
Where is the data? There are only two possible place containingdata: register and memory. That means the intermediate-code get dataonly with register and memory. For simplicity, we assume the number ofregisters is unlimited
Where is the data? ⚫ There are only two possible place containing data: 𝑟𝑒𝑔𝑖𝑠𝑡𝑒𝑟 and 𝑚𝑒𝑚𝑜𝑟𝑦. ⚫ That means the intermediate-code get data only with 𝑟𝑒𝑔𝑖𝑠𝑡𝑒𝑟 and 𝑚𝑒𝑚𝑜𝑟𝑦 ⚫ For simplicity, we assume the number of 𝑟𝑒𝑔𝑖𝑠𝑡𝑒𝑟𝑠 is unlimited
Quadruple A quadruple consists of an result,argi, op, arg2, which can possibly be null You should design your own IR packageHere is a viable example
Quadruple ⚫ A quadruple consists of an 𝑟𝑒𝑠𝑢𝑙𝑡, 𝑎𝑟𝑔1, 𝑜𝑝, 𝑎𝑟𝑔2, which can possibly be null. ⚫ You should design your own IR package. ⚫ Here is a viable example
Example in the Dragon Booka+a*(b-c)+(-c)*d=b-ct2 =a*tiAt3=a+t2t4 = -cts = t4* dt6 = t3 + ts
Example in the Dragon Book ⚫ 𝑎 + 𝑎 ∗ (𝑏 − 𝑐) + (−𝑐) ∗ 𝑑 ⚫ 𝑡1 = 𝑏 − 𝑐 𝑡2 = 𝑎 ∗ 𝑡1 ⚫ 𝑡3 = 𝑎 + 𝑡2 𝑡4 = −𝑐 ⚫ 𝑡5 = 𝑡4 ∗ 𝑑 𝑡6 = 𝑡3 + 𝑡5
Oprandsregistermem(oprand)constValuelabelfunction
Oprands ⚫ 𝑟𝑒𝑔𝑖𝑠𝑡𝑒𝑟 ⚫ 𝑚𝑒𝑚 𝑜𝑝𝑟𝑎𝑛𝑑 ⚫ 𝑐𝑜𝑛𝑠𝑡𝑉𝑎𝑙𝑢𝑒 ⚫ 𝑙𝑎𝑏𝑒𝑙 ⚫ 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛