예제 #1
0
        private static PhiNodes GetPhiValues(IEnumerable <OpCodePart> values, OpCodePart currentValue)
        {
            var phiNodes = new PhiNodes();
            var any      = false;

            foreach (var alternateValue in values.Where(alternateValue => currentValue == null || !alternateValue.Equals(currentValue)))
            {
                AddPhiValue(phiNodes, alternateValue);
                any = true;
            }

            if (any)
            {
                if (currentValue != null)
                {
                    AddPhiValue(phiNodes, currentValue);
                }

                // all values the same - return null
                var firstValueAddressStart = phiNodes.Values.First().AddressStart;
                if (phiNodes.Values.Count() > 1 && phiNodes.Values.All(v => v.AddressStart == firstValueAddressStart))
                {
                    return(null);
                }

                return(phiNodes);
            }

            return(null);
        }
예제 #2
0
        private static void AddPhiValue(PhiNodes phiNodes, OpCodePart value)
        {
            var currentLabel = value.FindBeginOfBasicBlock();

            phiNodes.Values.Add(value);
            if (currentLabel.HasValue)
            {
                phiNodes.Labels.Add(currentLabel.Value);
            }
            else
            {
                // we need to create a label
                var opCode = value.OpCodeOperands != null && value.OpCodeOperands.Length > 0
                    ? value.OpCodeOperands[0]
                    : value;
                if (opCode.JumpDestination == null)
                {
                    opCode.JumpDestination = new List <OpCodePart>();
                }

                opCode.JumpDestination.Add(value);

                phiNodes.Labels.Add(opCode.AddressStart);
            }
        }
예제 #3
0
        private static PhiNodes GetPhiValues(IEnumerable<OpCodePart> values, OpCodePart currentValue)
        {
            var phiNodes = new PhiNodes();
            var any = false;
            foreach (
                var alternateValue in
                    values.Where(alternateValue => currentValue == null || !alternateValue.Equals(currentValue)))
            {
                AddPhiValue(phiNodes, alternateValue);
                any = true;
            }

            if (any)
            {
                if (currentValue != null)
                {
                    AddPhiValue(phiNodes, currentValue);
                }

                // all values the same - return null
                var firstValueAddressStart = phiNodes.Values.First().AddressStart;
                if (phiNodes.Values.Count() > 1 && phiNodes.Values.All(v => v.AddressStart == firstValueAddressStart))
                {
                    return null;
                }

                return phiNodes;
            }

            return null;
        }
예제 #4
0
        private static void AddPhiValue(PhiNodes phiNodes, OpCodePart value)
        {
            var currentLabel = value.FindBeginOfBasicBlock();
            phiNodes.Values.Add(value);
            if (currentLabel.HasValue)
            {
                phiNodes.Labels.Add(currentLabel.Value);
            }
            else
            {
                // we need to create a label
                var opCode = value.OpCodeOperands != null && value.OpCodeOperands.Length > 0
                    ? value.OpCodeOperands[0]
                    : value;
                if (opCode.JumpDestination == null)
                {
                    opCode.JumpDestination = new List<OpCodePart>();
                }

                opCode.JumpDestination.Add(value);

                phiNodes.Labels.Add(opCode.AddressStart);
            }
        }