Esempio n. 1
0
        private Instruction SetCacheKeyLocalVariable(Instruction current, MethodDefinition methodDefinition,
                                                     ILProcessor processor, int cacheKeyIndex, int objectArrayIndex)
        {
            if (methodDefinition.IsSetter || methodDefinition.IsGetter)
            {
                return(current.AppendStloc(processor, cacheKeyIndex));
            }
            else
            {
                // Create object[] for string.format
                current =
                    current.AppendLdcI4(processor, methodDefinition.Parameters.Count)
                    .Append(processor.Create(OpCodes.Newarr, ModuleDefinition.TypeSystem.Object), processor)
                    .AppendStloc(processor, objectArrayIndex);

                // Set object[] values
                for (int i = 0; i < methodDefinition.Parameters.Count; i++)
                {
                    current =
                        current.AppendLdloc(processor, objectArrayIndex)
                        .AppendLdcI4(processor, i)
                        .AppendLdarg(processor, !methodDefinition.IsStatic ? i + 1 : i)
                        .AppendBoxIfNecessary(processor, methodDefinition.Parameters[i].ParameterType)
                        .Append(processor.Create(OpCodes.Stelem_Ref), processor);
                }

                // Call string.format
                return
                    (current.AppendLdloc(processor, objectArrayIndex)
                     .Append(processor.Create(OpCodes.Call,
                                              methodDefinition.Module.ImportMethod(References.StringFormatMethod)), processor)
                     .AppendStloc(processor, cacheKeyIndex));
            }
        }
Esempio n. 2
0
        private static Instruction SetCacheKeyLocalVariable(BaseModuleWeaver weaver, Instruction current, MethodDefinition methodDefinition,
                                                            ILProcessor processor, int cacheKeyIndex, int objectArrayIndex)
        {
            if (methodDefinition.IsSetter || methodDefinition.IsGetter)
            {
                return(current.AppendStloc(processor, cacheKeyIndex));
            }
            else
            {
                // Create object[] for string.format
                int parameterCount = methodDefinition.Parameters.Count + methodDefinition.GenericParameters.Count;

                current = current
                          .AppendLdcI4(processor, parameterCount)
                          .Append(processor.Create(OpCodes.Newarr, weaver.ModuleDefinition.TypeSystem.Object), processor)
                          .AppendStloc(processor, objectArrayIndex);


                // Set object[] values
                for (int i = 0; i < methodDefinition.GenericParameters.Count; i++)
                {
                    current = current
                              .AppendLdloc(processor, objectArrayIndex)
                              .AppendLdcI4(processor, i)
                              .Append(processor.Create(OpCodes.Ldtoken, methodDefinition.GenericParameters[i]), processor)
                              .Append(processor.Create(OpCodes.Call, methodDefinition.Module.ImportMethod(ReferenceFinder.SystemTypeGetTypeFromHandleMethod)),
                                      processor)
                              .Append(processor.Create(OpCodes.Stelem_Ref), processor);
                }

                for (int i = 0; i < methodDefinition.Parameters.Count; i++)
                {
                    current = current
                              .AppendLdloc(processor, objectArrayIndex)
                              .AppendLdcI4(processor, methodDefinition.GenericParameters.Count + i)
                              .AppendLdarg(processor, !methodDefinition.IsStatic ? i + 1 : i)
                              .AppendBoxIfNecessary(processor, methodDefinition.Parameters[i].ParameterType)
                              .Append(processor.Create(OpCodes.Stelem_Ref), processor);
                }

                // Call string.format



                var ins = processor.Create(OpCodes.Call, methodDefinition.Module.ImportMethod(ReferenceFinder.StringFormatMethod));

                return(current
                       .AppendLdloc(processor, objectArrayIndex)
                       .Append(ins, processor)
                       .AppendStloc(processor, cacheKeyIndex));
            }
        }
Esempio n. 3
0
        private void InjectIlForDispose(ILProcessor processor, Instruction returnInstruction, ReferenceContainer references)
        {
            // load context then call dispose

            /*
             *  nop
             *  ldloc.0
             *  callvirt instance void [Yalf]Yalf.IContext::Dispose()
             *  return mumbo jumbo
             */

            returnInstruction.AppendLdloc(processor, contextVar.Index)
            .Append(processor.Create(OpCodes.Callvirt, references.DisposeMethod), processor);
        }