private function dumpOp(Op $op) { $result = $op->getType(); foreach ($op->getVariableNames() as $varName) { $result .= "\n {$varName}: "; $result .= $this->indent($this->dumpOperand($op->{$varName})); } foreach ($op->getSubBlocks() as $subBlock) { $result .= "\n {$subBlock}: " . $this->indent($this->dumpBlockRef($op->{$subBlock})); } return $result; }
public function enterOp(Op $op, Block $block) { foreach ($op->getVariableNames() as $name) { $var = $op->{$name}; if (!is_array($var)) { $var = [$var]; } foreach ($var as $v) { if (is_null($v)) { continue; } $this->variables->attach($v); } } }
public static function removeUsage(Operand $var, Op $op) { foreach ($op->getVariableNames() as $varName) { $vars = $op->{$varName}; $newVars = []; if (!is_array($vars)) { $vars = [$vars]; } foreach ($vars as $key => $value) { if ($value !== $var) { $newVars[$key] = $value; } } if (!is_array($op->{$varName})) { $op->{$varName} = array_shift($newVars); } else { $op->{$varName} = array_keys($newVars); } } }
protected function renderOp(Op $op) { $result = $op->getType(); if ($op instanceof Op\CallableOp) { $func = $op->getFunc(); $result .= "<" . $func->name . ">"; } if ($op instanceof Op\Expr\Assertion) { $result .= "<" . $this->renderAssertion($op->assertion) . ">"; } foreach ($op->getVariableNames() as $varName) { $vars = $op->{$varName}; if (is_array($vars)) { foreach ($vars as $key => $var) { if (!$var) { continue; } $result .= "\n {$varName}[{$key}]: "; $result .= $this->indent($this->renderOperand($var)); } } elseif ($vars) { $result .= "\n {$varName}: "; $result .= $this->indent($this->renderOperand($vars)); } } $childBlocks = []; foreach ($op->getSubBlocks() as $blockName) { $sub = $op->{$blockName}; if (is_array($sub)) { foreach ($sub as $key => $subBlock) { if (!$subBlock) { continue; } $this->enqueueBlock($subBlock); $childBlocks[] = ["block" => $subBlock, "name" => $blockName . "[" . $key . "]"]; } } elseif ($sub) { $this->enqueueBlock($sub); $childBlocks[] = ["block" => $sub, "name" => $blockName]; } } return ["op" => $op, "label" => $result, "childBlocks" => $childBlocks]; }
protected function renderOp(Op $op) { $result = $op->getType(); if ($op instanceof Op\CallableOp) { $result .= '<' . $op->name->value . '>'; foreach ($op->getParams() as $key => $param) { $result .= $this->indent("\nParam[{$key}]: " . $this->renderOperand($param->result)); } } if ($op instanceof Op\Expr\Assertion) { $result .= "<" . $this->renderAssertion($op->assertion) . ">"; } foreach ($op->getVariableNames() as $varName) { $vars = $op->{$varName}; if (!is_array($vars)) { $vars = [$vars]; } foreach ($vars as $var) { if (!$var) { continue; } $result .= "\n {$varName}: "; $result .= $this->indent($this->renderOperand($var)); } } $childBlocks = []; foreach ($op->getSubBlocks() as $blockName) { $sub = $op->{$blockName}; if (is_null($sub)) { continue; } if (!is_array($sub)) { $sub = [$sub]; } foreach ($sub as $subBlock) { if (!$subBlock) { continue; } $this->enqueueBlock($subBlock); $childBlocks[] = ["block" => $subBlock, "name" => $blockName]; } } return ["op" => $op, "label" => $result, "childBlocks" => $childBlocks]; }
private function replaceOpVariable(Operand $from, Operand $to, Op $op) { foreach ($op->getVariableNames() as $name) { if (is_null($op->{$name})) { continue; } if (is_array($op->{$name})) { // SIGH, PHP won't let me do this directly (parses as $op->($name[$key])) $result = $op->{$name}; $new = []; foreach ($result as $key => $value) { if ($value === $from) { $new[$key] = $to; if ($op->isWriteVariable($name)) { $to->addWriteOp($op); } else { $to->addUsage($op); } } else { $new[$key] = $value; } } $op->{$name} = $new; } elseif ($op->{$name} === $from) { $op->{$name} = $to; if ($op->isWriteVariable($name)) { $to->addWriteOp($op); } else { $to->addUsage($op); } } } }