Esempio n. 1
0
        /// <summary>
        /// Get the size of the IL opcodes for this expression.
        /// <param name="context">The context of the block containing the expression</param>
        /// <param name="dropResult">Toggles if the result of the expression should be also put on the stack or just dropped.</param>
        /// </summary>
        public ILCount GetILCount(IBlockContext context, bool dropResult)
        {
            IBlockContext countingContext = context.CloneCountingContext();

            EmitCode(countingContext, dropResult);

            return(new ILCount {
                opCodes = countingContext.IL.ILSize,
                stack = countingContext.IL.StackCount
            });
        }
Esempio n. 2
0
        private ILCount EstimateLoop(IBlockContext context, IForInSource source)
        {
            IBlockContext prepContext = context.CloneCountingContext();

            sourceExpression.EmitCode(prepContext, false);
            source.EmitInitialize(prepContext);

            IBlockContext countingContext = prepContext.CloneCountingContext()
                                            .CreateLoopContext(context.IL.DefineLabel(false), context.IL.DefineLabel(false));
            IBlockVariable loopVariable = countingContext.DeclaredVariable(variableName, true, source.ElementType);
            LabelRef       loop         = countingContext.IL.DefineLabel(false);

            source.EmitNext(countingContext);
            loopVariable.EmitStore(countingContext);
            loopExpression.EmitCode(countingContext, true);
            source.EmitCheckDone(countingContext, loop);

            return(new ILCount {
                opCodes = countingContext.IL.ILSize,
                stack = countingContext.IL.StackCount
            });
        }