예제 #1
0
        public static Func <IExtractContext, string[]> ApplyFalse(
            ICodeInformation operand, string oper, DecodeContext decodeContext)
        {
            var si = decodeContext.PopStack();

            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            if (si.TargetType.IsBooleanType)
            {
                return(extractContext => new[] { string.Format(
                                                     "if ({0} {1} false) goto {2}",
                                                     extractContext.GetSymbolName(si),
                                                     oper,
                                                     labelName) });
            }
            else if (si.TargetType.IsNumericPrimitive ||
                     si.TargetType.IsEnum)
            {
                return(extractContext => new[] { string.Format(
                                                     "if ({0} {1} 0) goto {2}",
                                                     extractContext.GetSymbolName(si),
                                                     oper,
                                                     labelName) });
            }
            else
            {
                return(extractContext => new[] { string.Format(
                                                     "if ({0} {1} NULL) goto {2}",
                                                     extractContext.GetSymbolName(si),
                                                     oper,
                                                     labelName) });
            }
        }
예제 #2
0
        public override ExpressionEmitter Prepare(
            ICodeInformation operand, DecodeContext decodeContext)
        {
            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            return((_, __) => new[] { string.Format("goto {0}", labelName) });
        }
예제 #3
0
        public override Func <IExtractContext, string[]> Apply(
            ICodeInformation operand, DecodeContext decodeContext)
        {
            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            return(_ => new[] { string.Format("goto {0}", labelName) });
        }
예제 #4
0
        public override Func <IExtractContext, string[]> Apply(
            ICodeInformation operand, DecodeContext decodeContext)
        {
            var si = decodeContext.PopStack();

            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            if (si.TargetType.IsBooleanType)
            {
                return(extractContext => new[] { string.Format(
                                                     "if (!({0})) goto {1}",
                                                     extractContext.GetSymbolName(si),
                                                     labelName) });
            }
            else if (si.TargetType.IsNumericPrimitive)
            {
                return(extractContext => new[] { string.Format(
                                                     "if ({0} == 0) goto {1}",
                                                     extractContext.GetSymbolName(si),
                                                     labelName) });
            }
            else
            {
                return(extractContext => new[] { string.Format(
                                                     "if ({0} == NULL) goto {1}",
                                                     extractContext.GetSymbolName(si),
                                                     labelName) });
            }
        }
예제 #5
0
        public override Func <IExtractContext, string[]> Apply(
            Instruction operand, DecodeContext decodeContext)
        {
            var si1 = decodeContext.PopStack();
            var si0 = decodeContext.PopStack();

            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            return(_ => new[] { string.Format(
                                    "if ({0} != {1}) goto {2}",
                                    si0.SymbolName,
                                    si1.SymbolName,
                                    labelName) });
        }
예제 #6
0
        public override Func <IExtractContext, string[]> Apply(
            ICodeInformation operand, DecodeContext decodeContext)
        {
            var si1 = decodeContext.PopStack();
            var si0 = decodeContext.PopStack();

            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            return(extractContext => new[] { string.Format(
                                                 "if ({0} != {1}) goto {2}",
                                                 extractContext.GetSymbolName(si0),
                                                 extractContext.GetSymbolName(si1),
                                                 labelName) });
        }
예제 #7
0
        public static ExpressionEmitter ApplyBinary(
            ICodeInformation operand, string oper, DecodeContext decodeContext)
        {
            var si1 = decodeContext.PopStack();
            var si0 = decodeContext.PopStack();

            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            return((extractContext, _) => new[] { string.Format(
                                                      "if ({0} {1} {2}) goto {3}",
                                                      extractContext.GetSymbolName(si0),
                                                      oper,
                                                      extractContext.GetSymbolName(si1),
                                                      labelName) });
        }
예제 #8
0
        public override Func <IExtractContext, string[]> Apply(
            Instruction operand, DecodeContext decodeContext)
        {
            var si = decodeContext.PopStack();

            var labelName = decodeContext.EnqueueNewPath(operand.Offset);

            if (si.TargetType.IsNumericPrimitive())
            {
                return(_ => new[] { string.Format(
                                        "if ({0} != 0) goto {1}",
                                        si.SymbolName,
                                        labelName) });
            }
            else
            {
                return(_ => new[] { string.Format(
                                        "if ({0} != NULL) goto {1}",
                                        si.SymbolName,
                                        labelName) });
            }
        }
예제 #9
0
        public override Func <IExtractContext, string[]> Apply(
            ICodeInformation operand, DecodeContext decodeContext)
        {
            // Strategy:
            //   The exception handlers have to use "leave" opcode to exit.
            //   It will be transition to finally block if declared.
            //   AND, continue to operand label (therefore it delayed evaluation.)
            //   The AssemblyWriter will write these fragments by labelName side-by-side declared continuationIndex.

            decodeContext.EnqueueNewPath(operand.Offset);
            var continuationIndex = decodeContext.RegisterLeaveContinuation(
                decodeContext.CurrentCode.Offset, operand.Offset);

            return(extractContext =>
            {
                var nestedIndexName = extractContext.GetExceptionNestedFrameIndexName();

                return new[] { string.Format(
                                   "il2c_leave({0}, {1})",
                                   nestedIndexName,
                                   continuationIndex) };
            });
        }