Pseudocode: Introduce pseudo-value analysis

This commit is contained in:
Alexey Sedunov
2014-05-12 17:42:44 +04:00
parent 3ce96671d9
commit d2c055e9da
103 changed files with 2417 additions and 1432 deletions
@@ -19,13 +19,13 @@ L2 [onExceptionToFinallyBlock]:
L4 [start finally]:
3 mark({ test() }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])]
mark(test())
call(test, test)
call(test, test) -> <v0>
L5 [finish finally]:
2 jmp(error) NEXT:[<ERROR>]
L3 [skipFinallyToErrorBlock]:
3 mark({ test() }) PREV:[jmp(L3 [skipFinallyToErrorBlock])]
mark(test())
call(test, test)
call(test, test) -> <v0>
L1:
1 <END> NEXT:[<SINK>]
error:
@@ -19,17 +19,17 @@ L2 [onExceptionToFinallyBlock]:
L4 [start finally]:
3 mark({ return test() }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])]
mark(test())
call(test, test)
ret(*) L1 NEXT:[<END>]
call(test, test) -> <v0>
ret(*|<v0>) L1 NEXT:[<END>]
L5 [finish finally]:
- 2 jmp(error) NEXT:[<ERROR>] PREV:[]
L3 [skipFinallyToErrorBlock]:
3 mark({ return test() }) PREV:[jmp(L3 [skipFinallyToErrorBlock])]
mark(test())
call(test, test)
ret(*) L1
call(test, test) -> <v0>
ret(*|<v0>) L1
L1:
1 <END> NEXT:[<SINK>] PREV:[ret(*) L1, ret(*) L1]
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v0>) L1, ret(*|<v0>) L1]
error:
<ERROR> PREV:[]
sink:
@@ -7,38 +7,40 @@ tailRecursive fun sum(x: Long, sum: Long): Long {
L0:
1 <START>
v(x: Long)
w(x)
magic(x: Long) -> <v0>
w(x|<v0>)
v(sum: Long)
w(sum)
magic(sum: Long) -> <v1>
w(sum|<v1>)
2 mark({ if (x == 0.toLong()) return sum return sum(x - 1, sum + x) })
mark(if (x == 0.toLong()) return sum)
mark(x == 0.toLong())
r(x)
r(x) -> <v2>
mark(0.toLong())
mark(toLong())
r(0)
call(toLong, toLong)
call(==, equals)
jf(L2) NEXT:[read (Unit), r(sum)]
r(sum)
ret(*) L1 NEXT:[<END>]
r(0) -> <v3>
call(toLong, toLong|<v3>) -> <v4>
call(==, equals|<v2>, <v4>) -> <v5>
jf(L2|<v5>) NEXT:[read (Unit), r(sum) -> <v6>]
r(sum) -> <v6>
ret(*|<v6>) L1 NEXT:[<END>]
- jmp(L3) NEXT:[mark(sum(x - 1, sum + x))] PREV:[]
L2:
read (Unit) PREV:[jf(L2)]
read (Unit) PREV:[jf(L2|<v5>)]
L3:
mark(sum(x - 1, sum + x))
mark(x - 1)
r(x)
r(1)
call(-, minus)
r(x) -> <v7>
r(1) -> <v8>
call(-, minus|<v7>, <v8>) -> <v9>
mark(sum + x)
r(sum)
r(x)
call(+, plus)
call(sum, sum)
ret(*) L1
r(sum) -> <v10>
r(x) -> <v11>
call(+, plus|<v10>, <v11>) -> <v12>
call(sum, sum|<v9>, <v12>) -> <v13>
ret(*|<v13>) L1
L1:
1 <END> NEXT:[<SINK>] PREV:[ret(*) L1, ret(*) L1]
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v6>) L1, ret(*|<v13>) L1]
error:
<ERROR> PREV:[]
sink:
@@ -14,18 +14,19 @@ L0:
jmp?(L2 [onException]) NEXT:[v(e: Throwable), mark({ return foo() })]
3 mark({ return foo() })
mark(foo())
call(foo, foo)
ret(*) L1 NEXT:[<END>]
call(foo, foo) -> <v0>
ret(*|<v0>) L1 NEXT:[<END>]
- 2 jmp(L3 [afterCatches]) NEXT:[<END>] PREV:[]
L2 [onException]:
3 v(e: Throwable) PREV:[jmp?(L2 [onException])]
w(e)
magic(e: Throwable) -> <v1>
w(e|<v1>)
4 mark({ })
read (Unit)
3 jmp(L3 [afterCatches])
L1:
L3 [afterCatches]:
1 <END> NEXT:[<SINK>] PREV:[ret(*) L1, jmp(L3 [afterCatches])]
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v0>) L1, jmp(L3 [afterCatches])]
error:
<ERROR> PREV:[]
sink:
@@ -13,36 +13,38 @@ L0:
1 <START>
2 mark({ try { test() } catch (any : Exception) { test() } finally { test() } })
mark(try { test() } catch (any : Exception) { test() } finally { test() })
jmp?(L2 [onException]) NEXT:[v(any : Exception), jmp?(L3 [onExceptionToFinallyBlock])]
jmp?(L3 [onExceptionToFinallyBlock]) NEXT:[mark({ test() }), mark({ test() })]
jmp?(L2 [onException]) NEXT:[v(any : Exception), jmp?(L3 [onExceptionToFinallyBlock])]
jmp?(L3 [onExceptionToFinallyBlock]) NEXT:[mark({ test() }), mark({ test() })]
3 mark({ test() })
mark(test())
call(test, test)
2 jmp(L4 [afterCatches]) NEXT:[jmp(L5 [skipFinallyToErrorBlock])]
call(test, test) -> <v0>
2 jmp(L4 [afterCatches]) NEXT:[jmp(L5 [skipFinallyToErrorBlock])]
L2 [onException]:
3 v(any : Exception) PREV:[jmp?(L2 [onException])]
w(any)
3 v(any : Exception) PREV:[jmp?(L2 [onException])]
magic(any : Exception) -> <v1>
w(any|<v1>)
4 mark({ test() })
mark(test())
call(test, test)
call(test, test) -> <v2>
3 jmp(L4 [afterCatches])
L4 [afterCatches]:
2 jmp(L5 [skipFinallyToErrorBlock]) NEXT:[mark({ test() })] PREV:[jmp(L4 [afterCatches]), jmp(L4 [afterCatches])]
2 jmp(L5 [skipFinallyToErrorBlock]) NEXT:[mark({ test() })] PREV:[jmp(L4 [afterCatches]), jmp(L4 [afterCatches])]
L3 [onExceptionToFinallyBlock]:
L6 [start finally]:
3 mark({ test() }) PREV:[jmp?(L3 [onExceptionToFinallyBlock])]
3 mark({ test() }) PREV:[jmp?(L3 [onExceptionToFinallyBlock])]
mark(test())
call(test, test)
call(test, test) -> <v3>
L7 [finish finally]:
2 jmp(error) NEXT:[<ERROR>]
2 jmp(error) NEXT:[<ERROR>]
L5 [skipFinallyToErrorBlock]:
3 mark({ test() }) PREV:[jmp(L5 [skipFinallyToErrorBlock])]
3 mark({ test() }) PREV:[jmp(L5 [skipFinallyToErrorBlock])]
mark(test())
call(test, test)
call(test, test) -> <v3>
2 magic(try { test() } catch (any : Exception) { test() } finally { test() }|<v0>, <v2>) -> <v4>
L1:
1 <END> NEXT:[<SINK>]
1 <END> NEXT:[<SINK>]
error:
<ERROR> PREV:[jmp(error)]
<ERROR> PREV:[jmp(error)]
sink:
<SINK> PREV:[<ERROR>, <END>]
<SINK> PREV:[<ERROR>, <END>]
=====================