예제 #1
0
        private Operand Map(Operand operand, Dictionary <Operand, Operand> map, InstructionNode callNode)
        {
            if (operand == null)
            {
                return(null);
            }

            Operand mappedOperand;

            if (map.TryGetValue(operand, out mappedOperand))
            {
                return(mappedOperand);
            }

            if (operand.IsSymbol)
            {
                if (operand.StringData != null)
                {
                    mappedOperand = Operand.CreateStringSymbol(operand.Type.TypeSystem, operand.Name, operand.StringData);
                }
                else if (operand.Method != null)
                {
                    mappedOperand = Operand.CreateSymbolFromMethod(operand.Type.TypeSystem, operand.Method);
                }
                else if (operand.Name != null)
                {
                    mappedOperand = Operand.CreateManagedSymbol(operand.Type, operand.Name);
                }
            }
            else if (operand.IsParameter)
            {
                mappedOperand = callNode.GetOperand(operand.Index + 1);
            }
            else if (operand.IsStackLocal)
            {
                mappedOperand = MethodCompiler.AddStackLocal(operand.Type, operand.IsPinned);
            }
            else if (operand.IsVirtualRegister)
            {
                mappedOperand = AllocateVirtualRegister(operand.Type);
            }
            else if (operand.IsStaticField)
            {
                mappedOperand = Operand.CreateField(operand.Field);
            }
            else if (operand.IsCPURegister)
            {
                mappedOperand = operand;
            }
            else if (operand.IsConstant)
            {
                mappedOperand = operand;
            }

            Debug.Assert(mappedOperand != null);

            map.Add(operand, mappedOperand);

            return(mappedOperand);
        }
        private static Operand Map(Operand operand, Dictionary <Operand, Operand> map)
        {
            if (operand == null)
            {
                return(null);
            }

            Operand mappedOperand;

            if (map.TryGetValue(operand, out mappedOperand))
            {
                return(mappedOperand);
            }

            if (operand.IsSymbol)
            {
                if (operand.StringData != null)
                {
                    mappedOperand = Operand.CreateStringSymbol(operand.Type.TypeSystem, operand.Name, operand.StringData);
                }
                else if (operand.Method != null)
                {
                    mappedOperand = Operand.CreateSymbolFromMethod(operand.Type.TypeSystem, operand.Method);
                }
                else if (operand.Name != null)
                {
                    mappedOperand = Operand.CreateManagedSymbol(operand.Type, operand.Name);
                }
            }
            else if (operand.IsParameter)
            {
                mappedOperand = operand;
            }
            else if (operand.IsStackLocal)
            {
                mappedOperand = Operand.CreateStackLocal(operand.Type, operand.Index, operand.IsPinned);
            }
            else if (operand.IsVirtualRegister)
            {
                if (operand.Uses.Count != 0 || operand.Definitions.Count != 0)
                {
                    mappedOperand = Operand.CreateVirtualRegister(operand.Type, operand.Index);
                }
            }
            else if (operand.IsStaticField)
            {
                mappedOperand = Operand.CreateField(operand.Field);
            }
            else if (operand.IsCPURegister)
            {
                mappedOperand = operand;
            }
            else if (operand.IsConstant)
            {
                mappedOperand = operand;
            }

            Debug.Assert(mappedOperand != null);

            map.Add(operand, mappedOperand);

            return(mappedOperand);
        }