/** * @covers ::process */ public function testWithoutChange() { $rule = new BitwiseNot(); $vertex = new JitBitwiseNot($a = new Variable(new Type(Type::TYPE_LONG)), $r = new Variable(new Type(Type::TYPE_DOUBLE))); $this->assertFalse($rule->process($vertex, $this->getMock(DirectedAdjacencyList::class))); $this->assertEquals(Type::TYPE_DOUBLE, $r->getType()->getType()); }
/** * @covers ::process */ public function testAssignWithoutChange() { $rule = new Assign(); $vertex = new JitAssign($a = new Variable(new Type(Type::TYPE_LONG)), $r = new Variable(new Type(Type::TYPE_DOUBLE))); $this->assertFalse($rule->process($vertex, $this->getMock(DirectedAdjacencyList::class))); $this->assertEquals('double', (string) $r->getType()); }
/** * @covers ::process */ public function testInValidKind() { $rule = new BinaryOp(); $vertex = new JitBinaryOp(-1, $a = new Variable(), $b = new Variable(), $r = new Variable()); $this->assertFalse($rule->process($vertex, $this->getMock(DirectedAdjacencyList::class))); $this->assertEquals(Type::TYPE_UNKNOWN, $r->getType()->getType()); }
public function implementSSA(Variable $old, Variable $new, Vertex $vertex, Digraph $graph, \SplObjectStorage $phiNodes, array $args) { if ($this->stack->contains($vertex)) { if (isset($phiNodes[$vertex])) { // we've visited, so it **must** have a node implemented $phiNodes[$vertex]->addValue($new); } return; } $this->stack->attach($vertex); if ($old !== $new && !$vertex instanceof Phi) { $vertex->replaceVariable($old, $new); } if ($vertex instanceof JitAssignment && $vertex->getResult() === $old) { $new = new Variable($new->getType()); $vertex->setResult($new); } if (isset($phiNodes[$vertex])) { if ($phiNodes[$vertex] === true) { // insert phiNode $next = new Variable(); $phi = new Phi($next); $phiNodes[$vertex] = $phi; if ($old !== $new || in_array($old, $args, true)) { $phiNodes[$vertex]->addValue($new); } Helper::insertAfter($vertex, $phiNodes[$vertex], $graph); $new = $next; } else { $phiNodes[$vertex]->addValue($new); } } foreach ($graph->successorsOf($vertex) as $sub) { // Depth first search $this->implementSSA($old, $new, $sub, $graph, $phiNodes, $args); } }
public function __construct($value) { if (is_int($value) || $value === (double) (int) $value) { parent::__construct(new Type(Type::TYPE_NUMERIC)); } elseif (is_float($value)) { parent::__construct(new Type(Type::TYPE_DOUBLE)); } elseif (is_string($value)) { parent::__construct(new Type(Type::TYPE_STRING)); } elseif (is_bool($value)) { parent::__construct(new Type(Type::TYPE_BOOLEAN)); } else { throw new \RuntimeException("Invalid constant type encountered: " . gettype($value)); } $this->value = $value; }
/** * @covers ::isConstant */ public function testIsConstant() { $variable = new Variable(); $this->assertFalse($variable->isConstant()); }