Esempio n. 1
0
        public ConstantDefinition MakeConstant(Type type, object value, string?name = null, string?reg = null)
        {
            var constant = new ConstantDefinition
            {
                Name  = name ?? $"constant{Constants.Count}",
                Type  = type,
                Value = value
            };

            Constants.Add(constant);

            if (reg != null)
            {
                RegisterData[reg] = constant;
            }

            return(constant);
        }
Esempio n. 2
0
        internal MethodAnalysis(MethodDefinition method, ulong methodStart, ulong initialMethodEnd)
        {
            _method           = method;
            MethodStart       = methodStart;
            AbsoluteMethodEnd = initialMethodEnd;
            EmptyRegConstant  = MakeConstant(typeof(int), 0, "0");

            //Set up parameters in registers & as locals.
            var regList = new List <string> {
                "rcx", "rdx", "r8", "r9"
            };

            if (!method.IsStatic)
            {
                MakeLocal(method.DeclaringType, "this", regList.RemoveAndReturn(0));
            }

            var args = method.Parameters.ToList();

            while (args.Count > 0 && regList.Count > 0)
            {
                var arg  = args.RemoveAndReturn(0);
                var dest = regList.RemoveAndReturn(0);

                MakeLocal(arg.ParameterType.Resolve(), arg.Name, dest);
            }

            var stackIdx = 0;

            while (args.Count > 0)
            {
                //Push remainder to stack
                var arg = args.RemoveAndReturn(0);
                PushToStack(MakeLocal(arg.ParameterType.Resolve(), arg.Name), stackIdx);
                stackIdx += (int)Utils.GetSizeOfObject(arg.ParameterType);
            }
        }