예제 #1
0
파일: Callee.cs 프로젝트: z77ma/runtime
        public void Emit()
        {
            if (Method != null)
            {
                return;
            }

            Method = new DynamicMethod(
                Name, typeof(int), Parameters.Select(t => t.Type).ToArray(), typeof(Program));

            ILGenerator  g        = Method.GetILGenerator();
            LocalBuilder hashCode = g.DeclareLocal(typeof(HashCode));

            if (Config.Verbose)
            {
                Program.EmitDumpValues("Callee's incoming args", g, Parameters.Select((t, i) => new ArgValue(t, i)));
            }

            g.Emit(OpCodes.Ldloca, hashCode);
            g.Emit(OpCodes.Initobj, typeof(HashCode));

            for (int i = 0; i < Parameters.Count; i++)
            {
                TypeEx pm = Parameters[i];
                g.Emit(OpCodes.Ldloca, hashCode);

                g.Emit(OpCodes.Ldarga, checked ((short)i));
                g.Emit(OpCodes.Ldc_I4, pm.Size);
                g.Emit(OpCodes.Call, s_memoryMarshalCreateReadOnlySpanMethod);

                g.Emit(OpCodes.Call, s_hashCodeAddBytesMethod);
            }

            g.Emit(OpCodes.Ldloca, hashCode);
            g.Emit(OpCodes.Call, s_hashCodeToHashCodeMethod);
            g.Emit(OpCodes.Ret);
        }
예제 #2
0
 public Value(TypeEx type)
 {
     Type = type;
 }
예제 #3
0
 public ConstantValue(TypeEx type, object value) : base(type)
 {
     Value = value;
 }
예제 #4
0
 public ArgValue(TypeEx type, int index) : base(type)
 {
     Index = index;
 }