1
0
Fork 0

Decompiler: improves break/continue/goto, updates test sample

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@758 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
This commit is contained in:
Xuefer 2011-04-17 08:23:57 +00:00
parent f16b6d7027
commit 70864b7369
2 changed files with 45 additions and 16 deletions

View File

@ -649,6 +649,11 @@ class Decompiler
*/
$op['line'] = $i;
switch ($op['opcode']) {
case XC_CONT:
case XC_BRK:
$op['jmpouts'] = array();
break;
case XC_GOTO:
case XC_JMP:
$target = $op['op1']['var'];
@ -800,19 +805,30 @@ class Decompiler
if (!isset($next)) {
return;
}
if (!empty($op['jmpouts']) && isset($op['isjmp'])) {
if (isset($op['jmpouts']) && isset($op['isjmp'])) {
if (isset($op['cond'])) {
echo "{$indent}check (" . str($op["cond"]) . ") {\n";
echo INDENT;
}
echo $indent;
echo xcache_get_opcode($op['opcode']), ' line', $op['jmpouts'][0];
if (isset($op['jmpouts'][1])) {
echo ', line', $op['jmpouts'][1];
switch ($op['opcode']) {
case XC_CONT:
case XC_BRK:
break;
case XC_GOTO:
echo $indent, 'goto', ' line', $op['jmpouts'][0], ';', "\n";
break;
default:
echo $indent;
echo xcache_get_opcode($op['opcode']), ' line', $op['jmpouts'][0];
if (isset($op['jmpouts'][1])) {
echo ', line', $op['jmpouts'][1];
}
echo ";";
// echo ' // <- line', $op['line'];
echo "\n";
}
echo ";";
// echo ' // <- line', $op['line'];
echo "\n";
if (isset($op['cond'])) echo "$indent}\n";
}
@ -1520,6 +1536,16 @@ class Decompiler
}
break;
// }}}
case XC_CONT:
case XC_BRK:
$op['cond'] = null;
$op['isjmp'] = true;
$resvar = $opc == XC_CONT ? 'continue' : 'break';
$count = str($this->getOpVal($op2, $EX));
if ($count != '1') {
$resvar .= ' ' . $count;
}
break;
case XC_GOTO:
case XC_JMP: // {{{
$op['cond'] = null;
@ -1531,8 +1557,6 @@ class Decompiler
$caseValue = $this->getOpVal($op2, $EX);
$resvar = str($switchValue) . ' == ' . str($caseValue);
break;
case XC_BRK:
break;
case XC_RECV_INIT:
case XC_RECV:
$offset = $this->getOpVal($op1, $EX);
@ -1579,9 +1603,6 @@ class Decompiler
$lastresvar = '@' . str($lastresvar, $EX);
break;
// }}}
case XC_CONT: // {{{
break;
// }}}
case XC_CAST: // {{{
$type = $ext;
static $type2cast = array(

View File

@ -185,6 +185,8 @@ $a = $b & $c;
$a = $b | $c;
$a = $b ^ $c;
$a = ~$b;
$a = -$b;
$a = +$b;
$a = $b >> $c;
$a = $b >> $c;
$a = $b == $c;
@ -248,8 +250,11 @@ for ($i = 1; $i < 10; ++$i) {
}
foreach ($array as $key => $value) {
echo $key . ' = ' . $value . "\n";
continue;
foreach ($array as $key => $value) {
echo $key . ' = ' . $value . "\n";
break 2;
continue;
}
}
switch ($switch) {
@ -278,7 +283,7 @@ include_once 'include_once.php';
echo __FILE__;
echo __LINE__;
//* >= PHP 5.3
//*
echo 'PHP 5.3+ code testing';
const CONST_VALUE = 1;
echo $this::CONST_VALUE;
@ -308,7 +313,10 @@ $greet = function ($name) {
$greet('World');
$greet('PHP');
$total = 0;
$tax = 1;
$callback = function ($quantity, $product) use ($tax, &$total) {
static $static = array(1);
$tax = 'tax';
$pricePerItem = constant('PRICE_' . strtoupper($product));
$total += $pricePerItem * $quantity * ($tax + 1);
};