Exemplo n.º 1
0
        public void ReplacingSourcesInPhiStatement()
        {
            var target   = new DummyVariable("target");
            var sources1 = new[]
            {
                new DummyVariable("source1"),
                new DummyVariable("source2"),
                new DummyVariable("source3"),
                new DummyVariable("source4")
            };
            var sources2 = new[]
            {
                new DummyVariable("newSource1"),
                new DummyVariable("newSource2"),
                new DummyVariable("newSource3"),
                new DummyVariable("newSource4"),
                new DummyVariable("newSource5")
            };
            var phi = new PhiStatement <DummyInstruction>(
                target, sources1.Select(s => new VariableExpression <DummyInstruction>(s)));

            var sourceExpr = sources2.Select(s => new VariableExpression <DummyInstruction>(s)).ToList();

            phi.WithSources(sourceExpr);

            Assert.Equal(5, phi.Sources.Count);
            Assert.All(phi.Sources, s =>
            {
                Assert.Equal(phi, s.Parent);
                Assert.Equal(sources2[sourceExpr.IndexOf(s)], s.Variable);
            });
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        void IAstNodeVisitor <TInstruction, object> .Visit(PhiStatement <TInstruction> phiStatement, object state)
        {
            EnterPhiStatement(phiStatement);

            foreach (var source in phiStatement.Sources)
            {
                source.Accept(this, state);
            }

            ExitPhiStatement(phiStatement);
        }
Exemplo n.º 3
0
        public void AnyPhiWithAnyVariables()
        {
            var statement = new PhiStatement <int>(new AstVariable("phi1"), new List <VariableExpression <int> >
            {
                new VariableExpression <int>(new AstVariable("v1")),
                new VariableExpression <int>(new AstVariable("v2")),
                new VariableExpression <int>(new AstVariable("v3")),
                new VariableExpression <int>(new AstVariable("v4")),
            });

            var pattern = StatementPattern.Phi <int>();

            Assert.True(pattern.Matches(statement));
        }
Exemplo n.º 4
0
        public void ReplacingTargetVariableInPhiStatement()
        {
            var target1 = new DummyVariable("old");
            var target2 = new DummyVariable("new");
            var sources = new[]
            {
                new DummyVariable("source1"),
                new DummyVariable("source2"),
                new DummyVariable("source3"),
                new DummyVariable("source4")
            };
            var phi = new PhiStatement <DummyInstruction>(
                target1, sources.Select(s => new VariableExpression <DummyInstruction>(s)));

            Assert.Equal(target2, phi.WithTarget(target2).Target);
        }
Exemplo n.º 5
0
        public void AnyPhiWithFixedVariables()
        {
            var statement = new PhiStatement <int>(new AstVariable("phi1"), new List <VariableExpression <int> >
            {
                new VariableExpression <int>(new AstVariable("v1")),
                new VariableExpression <int>(new AstVariable("v2")),
                new VariableExpression <int>(new AstVariable("v3")),
            });

            var pattern = StatementPattern.Phi <int>()
                          .WithSources(
                Pattern.Any <VariableExpression <int> >(),
                Pattern.Any <VariableExpression <int> >(),
                Pattern.Any <VariableExpression <int> >());

            Assert.True(pattern.Matches(statement));

            statement.Sources.Add(new VariableExpression <int>(new AstVariable("v4")));

            Assert.False(pattern.Matches(statement));
        }
Exemplo n.º 6
0
        public void AnyPhiWithSpecificTargetPattern()
        {
            var group = new CaptureGroup("phiGroup");

            var statement = new PhiStatement <int>(new AstVariable("phi1"), new List <VariableExpression <int> >
            {
                new VariableExpression <int>(new AstVariable("v1")),
                new VariableExpression <int>(new AstVariable("v2")),
                new VariableExpression <int>(new AstVariable("v3")),
                new VariableExpression <int>(new AstVariable("v4")),
            });

            var pattern = StatementPattern.Phi <int>()
                          .WithTarget(Pattern.Any <IVariable>().CaptureAs(group));

            var result = pattern.Match(statement);

            Assert.True(result.IsSuccess);
            Assert.Contains(group, result.Captures);
            Assert.Contains(statement.Target, result.Captures[group]);
        }
 protected override void ExitPhiStatement(PhiStatement <TInstruction> phiStatement) =>
 Variables.Add(phiStatement.Target);
Exemplo n.º 8
0
 /// <summary>
 /// Finish visiting a given <see cref="PhiStatement{TInstruction}"/>
 /// </summary>
 /// <param name="phiStatement">The <see cref="PhiStatement{TInstruction}"/> that is being finished</param>
 protected virtual void ExitPhiStatement(PhiStatement <TInstruction> phiStatement)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// Begin visiting a given <see cref="PhiStatement{TInstruction}"/>
 /// </summary>
 /// <param name="phiStatement">The <see cref="PhiStatement{TInstruction}"/> that is being entered</param>
 protected virtual void EnterPhiStatement(PhiStatement <TInstruction> phiStatement) =>
 VisitChildren(phiStatement);