Exemplo n.º 1
0
        private ILInstruction CombineConditions(ILInstruction[] conditions)
        {
            ILInstruction condition = null;

            foreach (var c in conditions)
            {
                if (condition == null)
                {
                    condition = new LogicNot(c);
                }
                else
                {
                    condition = IfInstruction.LogicAnd(new LogicNot(c), condition);
                }
            }
            return(condition);
        }
Exemplo n.º 2
0
        protected override MetricBooleanExpression.IMetricBooleanExpression BuildExpression()
        {
            IMetricBooleanExpression expression =
                new LogicAnd(
                    new Comparison(
                        string.Format(
                            "{0} >= {1:0.0000}",
                            RawMetric,
                            LowThreshold)),
                    new Comparison(
                        string.Format(
                            "{0} <= {1:0.0000}",
                            RawMetric,
                            HighThreshold)));

            if (TriggeringCondition == 0)
            {
                expression = new LogicNot(expression);
            }

            return(expression);
        }
Exemplo n.º 3
0
        protected internal override void VisitLogicNot(LogicNot inst)
        {
            ILInstruction arg, lhs, rhs;

            if (inst.Argument.MatchLogicNot(out arg))
            {
                context.Step("logic.not(logic.not(arg)) => arg", inst);
                Debug.Assert(arg.ResultType == StackType.I4);
                arg.AddILRange(inst.ILRange);
                arg.AddILRange(inst.Argument.ILRange);
                inst.ReplaceWith(arg);
                arg.AcceptVisitor(this);
            }
            else if (inst.Argument is Comp comp)
            {
                if ((comp.InputType != StackType.F && !comp.IsLifted) || comp.Kind.IsEqualityOrInequality())
                {
                    context.Step("push negation into comparison", inst);
                    comp.Kind = comp.Kind.Negate();
                    comp.AddILRange(inst.ILRange);
                    inst.ReplaceWith(comp);
                }
                comp.AcceptVisitor(this);
            }
            else if (inst.Argument.MatchLogicAnd(out lhs, out rhs))
            {
                // logic.not(if (lhs) rhs else ldc.i4 0)
                // ==> if (logic.not(lhs)) ldc.i4 1 else logic.not(rhs)
                context.Step("push negation into logic.and", inst);
                IfInstruction ifInst = (IfInstruction)inst.Argument;
                var           ldc0   = ifInst.FalseInst;
                Debug.Assert(ldc0.MatchLdcI4(0));
                ifInst.Condition = new LogicNot(lhs)
                {
                    ILRange = inst.ILRange
                };
                ifInst.TrueInst = new LdcI4(1)
                {
                    ILRange = ldc0.ILRange
                };
                ifInst.FalseInst = new LogicNot(rhs)
                {
                    ILRange = inst.ILRange
                };
                inst.ReplaceWith(ifInst);
                ifInst.AcceptVisitor(this);
            }
            else if (inst.Argument.MatchLogicOr(out lhs, out rhs))
            {
                // logic.not(if (lhs) ldc.i4 1 else rhs)
                // ==> if (logic.not(lhs)) logic.not(rhs) else ldc.i4 0)
                context.Step("push negation into logic.or", inst);
                IfInstruction ifInst = (IfInstruction)inst.Argument;
                var           ldc1   = ifInst.TrueInst;
                Debug.Assert(ldc1.MatchLdcI4(1));
                ifInst.Condition = new LogicNot(lhs)
                {
                    ILRange = inst.ILRange
                };
                ifInst.TrueInst = new LogicNot(rhs)
                {
                    ILRange = inst.ILRange
                };
                ifInst.FalseInst = new LdcI4(0)
                {
                    ILRange = ldc1.ILRange
                };
                inst.ReplaceWith(ifInst);
                ifInst.AcceptVisitor(this);
            }
            else
            {
                inst.Argument.AcceptVisitor(this);
            }
        }