示例#1
0
文件: Shl.cs 项目: mirec12590/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction,
                                           IntegerValue value, int shiftCount)
 {
     value.LeftShift(shiftCount);
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }
示例#2
0
        /// <summary>
        /// Converts the provided trilean to an I4 stack value, pushes it onto the stack and returns the success
        /// dispatcher result.
        /// </summary>
        /// <param name="context">The current execution context.</param>
        /// <param name="result">The trilean value.</param>
        /// <returns>The dispatch result.</returns>
        protected static DispatchResult ConvertToI4AndReturnSuccess(CilExecutionContext context, Trilean result)
        {
            var i4Result = new I4Value(result.ToBooleanOrFalse() ? 1 : 0, 0xFFFFFFFEu | (result.IsKnown ? 1u : 0u));

            context.ProgramState.Stack.Push(i4Result);
            return(DispatchResult.Success());
        }
示例#3
0
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction,
                                           IntegerValue value, int shiftCount)
 {
     value.RightShift(shiftCount, instruction.OpCode.Code == CilCode.Shr);
     context.ProgramState.Stack.Push((ICliValue)value);
     return(DispatchResult.Success());
 }
示例#4
0
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction,
                                           IntegerValue left, IntegerValue right)
 {
     left.Xor(right);
     context.ProgramState.Stack.Push((ICliValue)left);
     return(DispatchResult.Success());
 }
示例#5
0
文件: Add.cs 项目: mirec12590/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction,
     IntegerValue left, IntegerValue right)
 {
     left.Add(right);
     context.ProgramState.Stack.Push(left);
     return DispatchResult.Success();
 }
示例#6
0
文件: Mul.cs 项目: mirec12590/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction,
                                           FValue left, FValue right)
 {
     left.F64 *= right.F64;
     context.ProgramState.Stack.Push(left);
     return(DispatchResult.Success());
 }
示例#7
0
        /// <inheritdoc />
        public DispatchResult Execute(ExecutionContext context, CilInstruction instruction)
        {
            var result = VerifyCondition(context, instruction);

            int newOffset;

            if (result.IsKnown)
            {
                if (result)
                {
                    newOffset = ((ICilLabel)instruction.Operand).Offset;
                }
                else
                {
                    newOffset = instruction.Offset + instruction.Size;
                }
            }
            else
            {
                // TODO: dispatch event, allowing the user to handle unknown branch conditions.
                throw new DispatchException("Branch condition could not be evaluated.");
            }

            var stack = context.ProgramState.Stack;

            for (int i = 0; i < ArgumentCount; i++)
            {
                stack.Pop();
            }

            context.ProgramState.ProgramCounter = newOffset;
            return(DispatchResult.Success());
        }
示例#8
0
文件: Ceq.cs 项目: lanicon/Echo
        /// <inheritdoc />
        protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction,
                                                  FValue left, FValue right)
        {
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            var i4Result = new I4Value(left.F64 == right.F64 ? 1 : 0);

            context.ProgramState.Stack.Push(i4Result);
            return(DispatchResult.Success());
        }
示例#9
0
        private static DispatchResult ExecuteDefault(ExecutionContext context, IntegerValue value, IntegerValue left)
        {
            if (value.IsNonZero.IsUnknown)
            {
                value.MarkFullyUnknown();
            }

            context.ProgramState.Stack.Push(left);
            return(DispatchResult.Success());
        }
示例#10
0
文件: StObj.cs 项目: lanicon/Echo
        /// <inheritdoc />
        public override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction)
        {
            var environment = context.GetService <ICilRuntimeEnvironment>();
            var stack       = context.ProgramState.Stack;

            // Pop address to dereference.
            var elementValue = stack.Pop();
            var addressValue = stack.Pop();

            if (!(addressValue is IPointerValue pointerValue))
            {
                return(DispatchResult.InvalidProgram());
            }

            // Determine type layout.
            var type         = ((ITypeDefOrRef)instruction.Operand).ToTypeSignature();
            var memoryLayout = environment.ValueFactory.GetTypeMemoryLayout(type);

            // Write
            pointerValue.WriteStruct(0, environment.ValueFactory, memoryLayout, elementValue);

            return(DispatchResult.Success());
        }
示例#11
0
        /// <inheritdoc />
        public override DispatchResult Execute(ExecutionContext context, CilInstruction instruction)
        {
            var environment = context.GetService <ICilRuntimeEnvironment>();
            var stack       = context.ProgramState.Stack;

            // Pop address to dereference.
            var addressValue = stack.Pop();

            if (!(addressValue is PointerValue pointerValue))
            {
                return(DispatchResult.InvalidProgram());
            }

            // Determine type layout.
            var type         = ((ITypeDefOrRef)instruction.Operand).ToTypeSignature();
            var memoryLayout = environment.MemoryAllocator.GetTypeMemoryLayout(type);

            // Dereference.
            var structureValue = pointerValue.ReadStruct(0, environment.MemoryAllocator, memoryLayout);

            stack.Push(environment.CliMarshaller.ToCliValue(structureValue, type));

            return(DispatchResult.Success());
        }
示例#12
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, IntegerValue value)
 {
     value.Not();
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }
示例#13
0
 /// <inheritdoc />
 public virtual DispatchResult Execute(ExecutionContext context, CilInstruction instruction)
 {
     context.ProgramState.ProgramCounter += instruction.Size;
     return(DispatchResult.Success());
 }
示例#14
0
文件: Neg.cs 项目: lanicon/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, IntegerValue value)
 {
     value.TwosComplement();
     context.ProgramState.Stack.Push((ICliValue)value);
     return(DispatchResult.Success());
 }
示例#15
0
文件: Neg.cs 项目: lanicon/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, FValue value)
 {
     value.F64 = -value.F64;
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }