Algorithm 11.1 Tabulation Algorithm

Input: Exploded supergraph GG^{\sharp} of a program.

Output: Solution to the realizable-path reachability problem.

1:declare PathEdge, WorkList, SummaryEdge: global edge set

2:Let (N,E)=G(N^{\sharp}, E^{\sharp}) = G^{\sharp}

3:PathEdge := {(smain,0)(smain,0)}\{(s_{main}, 0) \to (s_{main}, 0)\}

4:WorkList := {(smain,0)(smain,0)}\{(s_{main}, 0) \to (s_{main}, 0)\}

5:SummaryEdge := \emptyset

6:ForwardTabulateSLRPs()

7:for each nNn \in N^{*} do

8:XnX_n := {d2Dd1(D{0})\{d_2 \in D | \exists d_1 \in (D \cup \{0\}) such that (sprocOf(n),d1)(n,d2)PathEdge}(s_{procOf(n)}, d_1) \to (n, d_2) \in PathEdge\}

9: // procOfprocOf maps a node to the name of its enclosing procedure.

10:end for

11:

12:procedure Propagate(ee)

13:if ee \notin PathEdge then

14:Insert ee into PathEdge.

15:Insert ee into WorkList.

16:end if

17:end procedure

18:

19:procedure ForwardTabulateSLRPs()

20:while WorkList \ne \emptyset do

21:Select and remove an edge (sp,d1)(n,d2)(s_p, d_1) \to (n, d_2) from WorkList.

22:if nCallpn \in Call_p then

23:for each d3d_3 such that (n,d2)(scalledProc(n),d3)E(n, d_2) \to (s_{calledProc(n)}, d_3) \in E^{\sharp} do

24:Propagate((scalledProc(n),d3)(scalledProc(n),d3)(s_{calledProc(n)}, d_3) \to (s_{calledProc(n)}, d_3))

25: // calledProccalledProc maps a call node to the name of the called procedure.

26:end for

27:for each d3d_3 such that (n,d2)(returnSite(n),d3)(ESummaryEdge)(n, d_2) \to (returnSite(n), d_3) \in (E^{\sharp} \cup SummaryEdge) do

28:Propagate((sp,d1)(returnSite(n),d3)(s_p, d_1) \to (returnSite(n), d_3))

29: // returnSitereturnSite maps a call node to its corresponding return-site node.

30:end for

31:else if n=epn = e_p then

32:for each ccallers(p)c \in callers(p) do

33: // callerscallers maps a procedure name to the set of call nodes that represents calls to that procedure.

34:for each d4,d5d_4, d_5 such that (c,d4)(dp,d1)E(c, d_4)\to (d_p, d_1) \in E^{\sharp} and (ep,d2)(returnSite(c),d5)E(e_p, d_2)\to(returnSite(c), d_5)\in E^{\sharp} do

35:if (c,d4)(returnSite(c),d5)(c, d_4) \to (returnSite(c), d_5) \notin SummaryEdge then

36:Insert (c,d4)(returnSite(c),d5)(c, d_4) \to (returnSite(c), d_5) into SummaryEdge.

37:for each d3d_3 such that (sprocOf(c),d3)(c,d4)(s_{procOf(c)}, d_3) \to (c, d_4) \in PathEdge do

38:Propagate((sprocOf(c),d3)(returnSite(c),d5)(s_{procOf(c)}, d_3) \to (returnSite(c), d_5))

39:end for

40:end if

41:end for

42:end for

43:else if n(NpCallp{ep})n \in (N_p - Call_p - \{e_p\}) then

44:for each (m,d3)(m, d_3) such that (n,d2)(m,d3)E(n, d_2)\to (m, d_3) \in E^{\sharp} do

45:Propagate((sp,d1)(m,d3)(s_p, d_1) \to (m, d_3))

46:end for

47:end if

48:end while

49:end procedure