Skip to content

Instantly share code, notes, and snippets.

@ircmaxell ircmaxell/code.php
Last active Aug 29, 2015

Embed
What would you like to do?
Tuli printing
<?php
$a = 1;
if ($a > 1) {
$b = 2;
} else {
$b = 3;
}
$c = 1;
if ($b === 3) {
$a = 2;
} else {
$c = 4;
}
echo $a;
echo $b;
echo $c;
$ bin/tuli analyze code.php
Analyzing code.php
Determining Variable Types
Round 1 (17 unresolved variables out of 25)
.
0 Variables Left Unresolved
Executing rule: Function and Method Call Argument Types
Executing rule: Function and Method Return Types
Executing rule: Constructor Argument Types
$ bin/tuli print-cfg code.php
Analyzing code.php
Determining Variable Types
Round 1 (17 unresolved variables out of 25)
.
0 Variables Left Unresolved
Block#1
Expr_Assign
var: Var<int>#1<$a>
expr: LITERAL<int>(1)
result: Var<int>#4
Expr_BinaryOp_Greater
left: Var<int>#1<$a>
right: LITERAL<int>(1)
result: Var<bool>#6
Stmt_JumpIf
cond: Var<bool>#6
if: Block#2
else: Block#3
Block#2
Expr_Assign
var: Var<int>#7<$b>
expr: LITERAL<int>(2)
result: Var<int>#10
Stmt_Jump
target: Block#4
Block#3
Expr_Assign
var: Var<int>#11<$b>
expr: LITERAL<int>(3)
result: Var<int>#14
Stmt_Jump
target: Block#4
Block#4
Phi<Var<int>#15<$b>>: = [Var<int>#7<$b>,Var<int>#11<$b>,]
Expr_Assign
var: Var<int>#17<$c>
expr: LITERAL<int>(1)
result: Var<int>#20
Expr_BinaryOp_Identical
left: Var<int>#15<$b>
right: LITERAL<int>(3)
result: Var<bool>#22
Stmt_JumpIf
cond: Var<bool>#22
if: Block#5
else: Block#6
Block#5
Expr_Assign
var: Var<int>#23<$a>
expr: LITERAL<int>(2)
result: Var<int>#26
Stmt_Jump
target: Block#7
Block#6
Expr_Assign
var: Var<int>#27<$c>
expr: LITERAL<int>(4)
result: Var<int>#30
Stmt_Jump
target: Block#7
Block#7
Phi<Var<int>#31<$a>>: = [Var<int>#23<$a>,Var<int>#1<$a>,]
Phi<Var<int>#33<$c>>: = [Var<int>#17<$c>,Var<int>#27<$c>,]
Terminal_Echo
expr: Var<int>#31<$a>
Terminal_Echo
expr: Var<int>#15<$b>
Terminal_Echo
expr: Var<int>#33<$c>
$ bin/tuli print-cfg code.php --image="test-cfg.png"
Analyzing code.php
Determining Variable Types
Round 1 (17 unresolved variables out of 25)
.
0 Variables Left Unresolved

CFG

$ bin/tuli print-vars code.php
Analyzing code.php
Determining Variable Types
Round 1 (17 unresolved variables out of 25)
.
0 Variables Left Unresolved
Var#1
WriteOps:
Expr_Assign
var: Var<int>#1<$a>
expr: LITERAL<int>(1)
result: Var<int>#4
ReadOps:
Expr_BinaryOp_Greater
left: Var<int>#1<$a>
right: LITERAL<int>(1)
result: Var<bool>#6
Var#2
WriteOps:
ReadOps:
Var#3
WriteOps:
ReadOps:
Expr_Assign
var: Var<int>#1<$a>
expr: LITERAL<int>(1)
result: Var<int>#4
Var#4
WriteOps:
Expr_Assign
var: Var<int>#1<$a>
expr: LITERAL<int>(1)
result: Var<int>#4
ReadOps:
Var#5
WriteOps:
ReadOps:
Expr_BinaryOp_Greater
left: Var<int>#1<$a>
right: LITERAL<int>(1)
result: Var<bool>#6
Var#6
WriteOps:
Expr_BinaryOp_Greater
left: Var<int>#1<$a>
right: LITERAL<int>(1)
result: Var<bool>#6
ReadOps:
Stmt_JumpIf
cond: Var<bool>#6
Var#7
WriteOps:
Expr_Assign
var: Var<int>#7<$b>
expr: LITERAL<int>(2)
result: Var<int>#10
ReadOps:
Phi<Var<int>#15<$b>>: = [Var<int>#7<$b>,Var<int>#11<$b>,]
Var#8
WriteOps:
ReadOps:
Var#9
WriteOps:
ReadOps:
Expr_Assign
var: Var<int>#7<$b>
expr: LITERAL<int>(2)
result: Var<int>#10
Var#10
WriteOps:
Expr_Assign
var: Var<int>#7<$b>
expr: LITERAL<int>(2)
result: Var<int>#10
ReadOps:
Var#11
WriteOps:
Expr_Assign
var: Var<int>#11<$b>
expr: LITERAL<int>(3)
result: Var<int>#14
ReadOps:
Phi<Var<int>#15<$b>>: = [Var<int>#7<$b>,Var<int>#11<$b>,]
Var#12
WriteOps:
ReadOps:
Var#13
WriteOps:
ReadOps:
Expr_Assign
var: Var<int>#11<$b>
expr: LITERAL<int>(3)
result: Var<int>#14
Var#14
WriteOps:
Expr_Assign
var: Var<int>#11<$b>
expr: LITERAL<int>(3)
result: Var<int>#14
ReadOps:
Var#15
WriteOps:
Phi<Var<int>#15<$b>>: = [Var<int>#7<$b>,Var<int>#11<$b>,]
ReadOps:
Expr_BinaryOp_Identical
left: Var<int>#15<$b>
right: LITERAL<int>(3)
result: Var<bool>#22
Terminal_Echo
expr: Var<int>#15<$b>
Var#16
WriteOps:
ReadOps:
Var#17
WriteOps:
Expr_Assign
var: Var<int>#17<$c>
expr: LITERAL<int>(1)
result: Var<int>#20
ReadOps:
Phi<Var<int>#33<$c>>: = [Var<int>#17<$c>,Var<int>#27<$c>,]
Var#18
WriteOps:
ReadOps:
Var#19
WriteOps:
ReadOps:
Expr_Assign
var: Var<int>#17<$c>
expr: LITERAL<int>(1)
result: Var<int>#20
Var#20
WriteOps:
Expr_Assign
var: Var<int>#17<$c>
expr: LITERAL<int>(1)
result: Var<int>#20
ReadOps:
Var#21
WriteOps:
ReadOps:
Expr_BinaryOp_Identical
left: Var<int>#15<$b>
right: LITERAL<int>(3)
result: Var<bool>#22
Var#22
WriteOps:
Expr_BinaryOp_Identical
left: Var<int>#15<$b>
right: LITERAL<int>(3)
result: Var<bool>#22
ReadOps:
Stmt_JumpIf
cond: Var<bool>#22
Var#23
WriteOps:
Expr_Assign
var: Var<int>#23<$a>
expr: LITERAL<int>(2)
result: Var<int>#26
ReadOps:
Phi<Var<int>#31<$a>>: = [Var<int>#23<$a>,Var<int>#1<$a>,]
Var#24
WriteOps:
ReadOps:
Var#25
WriteOps:
ReadOps:
Expr_Assign
var: Var<int>#23<$a>
expr: LITERAL<int>(2)
result: Var<int>#26
Var#26
WriteOps:
Expr_Assign
var: Var<int>#23<$a>
expr: LITERAL<int>(2)
result: Var<int>#26
ReadOps:
Var#27
WriteOps:
Expr_Assign
var: Var<int>#27<$c>
expr: LITERAL<int>(4)
result: Var<int>#30
ReadOps:
Phi<Var<int>#33<$c>>: = [Var<int>#17<$c>,Var<int>#27<$c>,]
Var#28
WriteOps:
ReadOps:
Var#29
WriteOps:
ReadOps:
Expr_Assign
var: Var<int>#27<$c>
expr: LITERAL<int>(4)
result: Var<int>#30
Var#30
WriteOps:
Expr_Assign
var: Var<int>#27<$c>
expr: LITERAL<int>(4)
result: Var<int>#30
ReadOps:
Var#31
WriteOps:
Phi<Var<int>#31<$a>>: = [Var<int>#23<$a>,Var<int>#1<$a>,]
ReadOps:
Terminal_Echo
expr: Var<int>#31<$a>
Var#32
WriteOps:
ReadOps:
Var#33
WriteOps:
Phi<Var<int>#33<$c>>: = [Var<int>#17<$c>,Var<int>#27<$c>,]
ReadOps:
Terminal_Echo
expr: Var<int>#33<$c>
Var#34
WriteOps:
ReadOps:
$ bin/tuli print-vars code.php --image="test-vars.png"
Analyzing code.php
Determining Variable Types
Round 1 (17 unresolved variables out of 25)
.
0 Variables Left Unresolved

Vars

@Ocramius

This comment has been minimized.

Copy link

commented Jul 16, 2015

SLOW CLAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.