当前位置: 首页>>代码示例>>C#>>正文


C# Compiler.InstantiateMethod方法代码示例

本文整理汇总了C#中Compiler.InstantiateMethod方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.InstantiateMethod方法的具体用法?C# Compiler.InstantiateMethod怎么用?C# Compiler.InstantiateMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compiler的用法示例。


在下文中一共展示了Compiler.InstantiateMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMethod


//.........这里部分代码省略.........

            HighSsaRegister methodReturnValue;
            if (targetMethodSignature.RetType is TypeSpecVoidTag)
                methodReturnValue = null;
            else
            {
                bool isValueType = compiler.TypeIsValueType(targetMethodSignature.RetType);
                methodReturnValue = new HighSsaRegister(isValueType ? HighValueType.ValueValue : HighValueType.ReferenceValue, targetMethodSignature.RetType, null);
            }

            HighInstruction callInstr;

            switch (methodSpec.MethodSlotType)
            {
                case MethodSlotType.Instance:
                    {
                        HighSsaRegister instanceReg;
                        HighSsaRegister thisReg = new HighSsaRegister(HighValueType.ReferenceValue, m_dt, null);
                        instrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, thisReg, thisLocal));

                        if (compiler.TypeIsValueType(methodSpec.DeclaringClass))
                        {
                            HighSsaRegister boxedReg = new HighSsaRegister(HighValueType.BoxedValue, methodSpec.DeclaringClass, null);
                            instrs.Add(new Instructions.LoadDelegateTargetInstruction(null, boxedReg, thisReg));
                            instanceReg = new HighSsaRegister(HighValueType.ManagedPtr, methodSpec.DeclaringClass, null);
                            instrs.Add(new Rpa.Instructions.UnboxPtrInstruction(null, instanceReg, boxedReg));
                        }
                        else
                        {
                            instanceReg = new HighSsaRegister(HighValueType.BoxedValue, methodSpec.DeclaringClass, null);
                            instrs.Add(new Instructions.LoadDelegateTargetInstruction(null, instanceReg, thisReg));
                        }

                        MethodHandle methodHandle = compiler.InstantiateMethod(new MethodSpecMethodKey(methodSpec), instantiationPath);
                        callInstr = new Instructions.CallRloInstanceMethodInstruction(null, methodHandle, methodReturnValue, instanceReg, convertedParameters.ToArray());
                    }
                    break;
                case MethodSlotType.Virtual:
                    {
                        HighSsaRegister instanceReg;
                        HighSsaRegister thisReg = new HighSsaRegister(HighValueType.ReferenceValue, m_dt, null);
                        instrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, thisReg, thisLocal));

                        if (compiler.TypeIsValueType(methodSpec.DeclaringClass))
                        {
                            HighSsaRegister boxedReg = new HighSsaRegister(HighValueType.BoxedValue, methodSpec.DeclaringClass, null);
                            instrs.Add(new Instructions.LoadDelegateTargetInstruction(null, boxedReg, thisReg));
                            instanceReg = new HighSsaRegister(HighValueType.ManagedPtr, methodSpec.DeclaringClass, null);
                            instrs.Add(new Rpa.Instructions.UnboxPtrInstruction(null, instanceReg, boxedReg));
                        }
                        else
                        {
                            instanceReg = new HighSsaRegister(HighValueType.BoxedValue, methodSpec.DeclaringClass, null);
                            instrs.Add(new Instructions.LoadDelegateTargetInstruction(null, instanceReg, thisReg));
                        }

                        if (isInterface)
                        {
                            uint cliSlot = targetIfc.CliSlotForSlotTag(methodSpec.MethodDecl);
                            callInstr = new Instructions.CallRloInterfaceMethodInstruction(null, cliSlot, methodReturnValue, instanceReg, convertedParameters.ToArray());
                        }
                        else
                        {
                            uint targetVtableSlot = targetCls.DeclTagToVTableSlot[methodSpec.MethodDecl];
                            callInstr = new Instructions.CallRloVirtualMethodInstruction(null, targetVtableSlot, methodReturnValue, instanceReg, convertedParameters.ToArray());
                        }
开发者ID:elasota,项目名称:clarity,代码行数:67,代码来源:GMDelegateInvoke.cs

示例2: GenerateMethod

        public override RloMethod GenerateMethod(Compiler compiler, MethodInstantiationPath instantiationPath)
        {
            HighLocal[] locals = new HighLocal[0];
            HighLocal[] args = new HighLocal[0];
            HighLocal instanceLocal = new HighLocal(m_bt, HighLocal.ETypeOfType.Value);

            Stack<HighField> fieldStack = new Stack<HighField>();

            uint getHashCodeSlot = m_vtCache.GetGetHashCodeVTableSlot(compiler);
            HighSsaRegister result = new HighSsaRegister(HighValueType.ValueValue, m_vtCache.GetSystemInt32Type(compiler), null);

            MethodSignatureTag methodSignature = new MethodSignatureTag(0, m_vtCache.GetSystemInt32Type(compiler), new MethodSignatureParam[0]);
            methodSignature = compiler.TagRepository.InternMethodSignature(methodSignature);

            if (RecursiveFindHashableField(compiler, m_bt.ContainedType, fieldStack))
            {
                // Found a field that can be hashed
                Queue<HighField> fieldQueue = new Queue<HighField>();
                while (fieldStack.Count > 0)
                    fieldQueue.Enqueue(fieldStack.Pop());

                HighSsaRegister thisRef = new HighSsaRegister(HighValueType.BoxedValue, m_bt.ContainedType, null);
                HighSsaRegister thisPtr = new HighSsaRegister(HighValueType.ManagedPtr, m_bt.ContainedType, null);

                HighCfgNodeHandle unboxHdl = new HighCfgNodeHandle();
                HighCfgNodeHandle locateAndHashFieldHdl = new HighCfgNodeHandle();

                {
                    List<HighInstruction> instrs = new List<HighInstruction>();
                    instrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, thisRef, instanceLocal));
                    Rpa.Instructions.UnboxPtrInstruction unboxInstr = new Rpa.Instructions.UnboxPtrInstruction(null, thisPtr, thisRef);
                    unboxInstr.ContinuationEdge = new HighCfgEdge(unboxInstr, locateAndHashFieldHdl);
                    instrs.Add(unboxInstr);

                    unboxHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
                }

                HighSsaRegister hashablePtr = thisPtr;

                List<HighInstruction> lahInstrs = new List<HighInstruction>();
                while (fieldQueue.Count > 0)
                {
                    HighField fld = fieldQueue.Dequeue();

                    HighSsaRegister nextFldPtr = new HighSsaRegister(HighValueType.ManagedPtr, fld.Type, null);
                    lahInstrs.Add(new Rpa.Instructions.PtrFieldInstruction(null, nextFldPtr, hashablePtr, fld.Name));
                    hashablePtr = nextFldPtr;
                }

                if (compiler.TypeIsValueType(hashablePtr.Type))
                {
                    HighCfgNodeHandle returnResultHdl = new HighCfgNodeHandle();

                    CliClass cls = compiler.GetClosedClass((TypeSpecClassTag)hashablePtr.Type);

                    CliMethodIndex vtableHashCodeIndex = cls.VTable[getHashCodeSlot].MethodIndex;
                    if (vtableHashCodeIndex.Depth == 0)
                    {
                        HighMethod method = cls.Methods[vtableHashCodeIndex.Index];

                        Instructions.CallRloVirtualMethodInstruction callInstr = new Instructions.CallRloVirtualMethodInstruction(null, getHashCodeSlot, result, hashablePtr, new HighSsaRegister[0]);
                        callInstr.ContinuationEdge = new HighCfgEdge(callInstr, returnResultHdl);
                        lahInstrs.Add(callInstr);
                    }
                    else
                    {
                        // Base class GetHashCode, but field was found as hashable, which means it's POD
                        MethodDeclTag hashBytesDecl = m_vtCache.GetHashBytesDeclTag(compiler);

                        MethodSpecTag methodSpec = new MethodSpecTag(MethodSlotType.Static, new TypeSpecTag[] { hashablePtr.Type }, m_vtCache.GetClarityToolsType(compiler), hashBytesDecl);
                        methodSpec = compiler.TagRepository.InternMethodSpec(methodSpec);

                        MethodHandle methodHandle = compiler.InstantiateMethod(new MethodSpecMethodKey(methodSpec), instantiationPath);

                        Instructions.CallRloStaticMethodInstruction callInstr = new Instructions.CallRloStaticMethodInstruction(null, methodHandle, result, new HighSsaRegister[] { hashablePtr });
                        callInstr.ContinuationEdge = new HighCfgEdge(callInstr, returnResultHdl);
                        lahInstrs.Add(callInstr);
                    }

                    // Add return block
                    {
                        List<HighInstruction> rrInstrs = new List<HighInstruction>();
                        rrInstrs.Add(new Rpa.Instructions.ReturnValueInstruction(null, result));

                        returnResultHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], rrInstrs.ToArray());
                    }
                }
                else
                {
                    HighCfgNodeHandle fldNullHdl = new HighCfgNodeHandle();
                    HighCfgNodeHandle callGetHashCodeHdl = new HighCfgNodeHandle();
                    HighCfgNodeHandle returnResultHdl = new HighCfgNodeHandle();

                    HighSsaRegister fldValue = new HighSsaRegister(HighValueType.ReferenceValue, hashablePtr.Type, null);

                    lahInstrs.Add(new Rpa.Instructions.LoadPtrInstruction(null, fldValue, hashablePtr));
                    lahInstrs.Add(new Rpa.Instructions.BranchRefNullInstruction(null, fldValue, fldNullHdl, callGetHashCodeHdl));

                    {
                        HighSsaRegister zeroConstant = new HighSsaRegister(HighValueType.ConstantValue, m_vtCache.GetSystemInt32Type(compiler), 0);
//.........这里部分代码省略.........
开发者ID:elasota,项目名称:clarity,代码行数:101,代码来源:GMBoxedValueTypeGetHashCode.cs

示例3: GenerateMethod


//.........这里部分代码省略.........
            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                Rpa.Instructions.UnboxPtrInstruction unboxInstr = new Rpa.Instructions.UnboxPtrInstruction(null, unboxedThisPtr, thisRef);
                unboxInstr.ContinuationEdge = new HighCfgEdge(unboxInstr, unboxOtherHdl);
                instrs.Add(unboxInstr);
                unboxThisHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                Rpa.Instructions.UnboxPtrInstruction unboxInstr = new Rpa.Instructions.UnboxPtrInstruction(null, unboxedOtherPtr, otherRef);
                unboxInstr.ContinuationEdge = new HighCfgEdge(unboxInstr, nextFieldCheckHdl);
                instrs.Add(unboxInstr);
                unboxOtherHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            if ((vtCache.GetClassPodFlags(compiler, cls) & VTableGenerationCache.PodFlags.Equality) != VTableGenerationCache.PodFlags.None)
            {
                HighCfgNodeHandle nextHdl = new HighCfgNodeHandle();
                List<HighInstruction> instrs = new List<HighInstruction>();
                instrs.Add(new Instructions.BranchComparePodInstruction(null, unboxedThisPtr, unboxedOtherPtr, nextHdl, returnFalseHdl));
                nextFieldCheckHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());

                nextFieldCheckHdl = nextHdl;
            }
            else
            {
                foreach (HighField fld in cls.InstanceFields)
                {
                    HighCfgNodeHandle nextHdl = new HighCfgNodeHandle();

                    TypeSpecTag fldType = fld.Type;
                    HighSsaRegister thisFldPtr = new HighSsaRegister(HighValueType.ManagedPtr, fldType, null);
                    HighSsaRegister otherFldPtr = new HighSsaRegister(HighValueType.ManagedPtr, fldType, null);

                    {
                        List<HighInstruction> instrs = new List<HighInstruction>();
                        instrs.Add(new Rpa.Instructions.PtrFieldInstruction(null, thisFldPtr, unboxedThisPtr, fld.Name));
                        instrs.Add(new Rpa.Instructions.PtrFieldInstruction(null, otherFldPtr, unboxedOtherPtr, fld.Name));

                        if (compiler.TypeIsValueType(fldType) &&
                            (((m_vtCache.GetClassPodFlags(compiler, compiler.GetClosedClass((TypeSpecClassTag)fldType))) & VTableGenerationCache.PodFlags.Equality) != VTableGenerationCache.PodFlags.None))
                        {
                            instrs.Add(new Instructions.BranchComparePodInstruction(null, thisFldPtr, otherFldPtr, nextHdl, returnFalseHdl));
                        }
                        else
                        {
                            HighCfgNodeHandle checkResultHdl = new HighCfgNodeHandle();
                            HighSsaRegister result = new HighSsaRegister(HighValueType.ValueValue, vtCache.GetSystemBoolType(compiler), null);
                            HighSsaRegister resultInt = new HighSsaRegister(HighValueType.ValueValue, vtCache.GetSystemBoolType(compiler), null);
                            HighSsaRegister zeroConstant = new HighSsaRegister(HighValueType.ConstantValue, vtCache.GetSystemInt32Type(compiler), 0);

                            TypeSpecClassTag clarityToolsClass = vtCache.GetClarityToolsType(compiler);
                            MethodDeclTag compareFieldsDeclTag = vtCache.GetCompareFieldsDeclTag(compiler);
                            MethodSpecTag compareMethodSpec = new MethodSpecTag(MethodSlotType.Static, new TypeSpecTag[] { fldType }, clarityToolsClass, compareFieldsDeclTag);

                            MethodHandle compareHdl = compiler.InstantiateMethod(new MethodSpecMethodKey(compareMethodSpec), instantiationPath);
                            Instructions.CallRloStaticMethodInstruction callInstr = new Instructions.CallRloStaticMethodInstruction(null, compareHdl, result, new HighSsaRegister[] { thisFldPtr, otherFldPtr });

                            callInstr.ContinuationEdge = new HighCfgEdge(callInstr, checkResultHdl);
                            instrs.Add(callInstr);

                            List<HighInstruction> checkResultsInstrs = new List<HighInstruction>();
                            checkResultsInstrs.Add(new Instructions.RloConvertNumberInstruction(null, resultInt, result, Instructions.RloConvertNumberInstruction.NumConversionType.ZeroExtend, 32, 8));
                            checkResultsInstrs.Add(new Rpa.Instructions.BranchCompareNumbersInstruction(null, Rpa.Instructions.NumberCompareOperation.Equal, Rpa.Instructions.NumberArithType.Int32, resultInt, zeroConstant, returnFalseHdl, nextHdl));
                            checkResultHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], checkResultsInstrs.ToArray());
                        }

                        nextFieldCheckHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
                    }

                    nextFieldCheckHdl = nextHdl;
                }

                // Generate terminators
                {
                    HighSsaRegister falseConstant = new HighSsaRegister(HighValueType.ConstantValue, boolType, false);
                    List<HighInstruction> instrs = new List<HighInstruction>();
                    instrs.Add(new Rpa.Instructions.ReturnValueInstruction(null, falseConstant));
                    returnFalseHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
                }

                {
                    HighSsaRegister trueConstant = new HighSsaRegister(HighValueType.ConstantValue, boolType, false);
                    List<HighInstruction> instrs = new List<HighInstruction>();
                    instrs.Add(new Rpa.Instructions.ReturnValueInstruction(null, trueConstant));
                    nextFieldCheckHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
                }
            }

            MethodSignatureTag methodSignature = new MethodSignatureTag(0, m_vtCache.GetSystemBoolType(compiler),
                new MethodSignatureParam[] {
                    new MethodSignatureParam(m_vtCache.GetSystemObjectType(compiler), new MethodSignatureParamTypeOfType(MethodSignatureParamTypeOfType.Values.Value))
                });
            methodSignature = compiler.TagRepository.InternMethodSignature(methodSignature);

            HighRegion region = new HighRegion(entryHdl);
            RloMethodBody body = new RloMethodBody(instanceLocal, args, locals, boolType, region, methodSignature, instantiationPath);
            return new RloMethod(body);
        }
开发者ID:elasota,项目名称:clarity,代码行数:101,代码来源:GMBoxedValueTypeEquals.cs


注:本文中的Compiler.InstantiateMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。