Shri Ramdeobaba College of Engineering and Management, Nagpur
Shri Ramdeobaba College of Engineering and Management, Nagpur
PRACTICAL No. 7
Aim:
a. Write TAC to identify whether the number is prime or not.
b. Write a program to find leader statement, basic blocks, program flow graph &
dominators.
c. Identify the Generate and Kill function for each block to be used in Elimination of
loop invariant computation
Hint:
GEN (B): Set of all definitions generated in Block B.
KILL (B): Set of all definitions outside Block B that define the same variables which are defined
in Block B.
Sample Output:
A.
The leader statements are:
1) count=0
3) If count > 20 GOTO 8
4) count=count + 1
8) end
The PFG is
B1->B2
B2->B3
B2->B4
B3->B2
B.
GEN(B1) = [1,2]
GEN(B2) = [3]
GEN(B3) = [4,5,6,7]
GEN(B4) = [8]
KILL(B1) = [4,6]
KILL(B2) = [Φ]
KILL(B3) = [1,2]
KILL(B4) = [Φ]
1.
1. Input n
2. i = 2
3. is_prime = 1
4. while i * i <= n:
5. if n % i == 0:
6. is_prime = 0
7. break
8. i = i + 1
9. Output is_prime
3.
Code:
package main
import (
"fmt"
"strings"
)
kill[1] = []int{4, 6}
func main() {
statements := []string{
"count = 0",
"Result = 0",
"If count > 20 GOTO 8",
"count=count + 1",
"increment = 2 * count",
"result = result +increment",
"GOTO 3",
"end",
}
fmt.Println("GEN sets:")
for i := 1; i <= len(statements); i++ {
fmt.Printf("GEN(B%d) = %v\n", i, gen[i])
}
fmt.Println("\nKILL sets:")
for i := 1; i <= len(statements); i++ {
fmt.Printf("KILL(B%d) = %v\n", i, kill[i])
}
}
OUTPUT: