public ILEmitter Emit(ILEmitter il, Type arrayType, LocalBuilder array, LocalBuilder hash) { il.Ldc_I4(0) // start loop .Stloc(typeof(int), out var index) .EmitArrayLength(arrayType, array, out var count) .DefineLabel(out var loopStart) .DefineLabel(out var loopEnd); using (il.LocalsScope()) { il.MarkLabel(loopStart) .Bne_Un_S(Ldloc(index), Ldloc(count), out var next) .Br(loopEnd) .MarkLabel(next); } using (il.LocalsScope()) { var arrays = new Dictionary <ushort, LocalBuilder>(1) { [Arg.Input] = array }; var itemVariable = new ArrayItemVariable(arrayType, _variable.OwnerType, arrays, index); _resolver .GetHasherEmitter(itemVariable) .EmitHashing(il, hash) .Add(Ldloc(index), Ldc_I4(1)) .Stloc(index) .Br(loopStart); } return(il.MarkLabel(loopEnd).Ldloc(hash)); }
public ILEmitter EmitCompareArrays( ILEmitter il, Type arrayType, Type ownerType, LocalBuilder xArray, LocalBuilder yArray, Label afterLoop) { // todo: 2. compare array lengths at the beginning il.EmitArrayLength(arrayType, xArray, out var countX) .EmitArrayLength(arrayType, yArray, out var countY) .Ldc_I4(0) .Stloc(typeof(int), out var index) .DefineLabel(out var loopStart) .DefineLabel(out var continueLoop) .MarkLabel(loopStart); using (il.LocalsScope()) { il.Ceq(Ldloc(index), Ldloc(countX), out var isDoneX) .Ceq(Ldloc(index), Ldloc(countY), out var isDoneY); _emitCheckIfLoopsAreDone(il, isDoneX, isDoneY, afterLoop); } using (il.LocalsScope()) { var arrays = new Dictionary <ushort, LocalBuilder>(2) { [Arg.X] = xArray, [Arg.Y] = yArray }; var itemVariable = new ArrayItemVariable(arrayType, ownerType, arrays, index); var itemComparison = _resolver.GetComparisonEmitter(itemVariable); return(il.Emit( itemComparison.Emit(continueLoop), itemComparison.EmitCheckForResult(continueLoop)) .MarkLabel(continueLoop) .Add(Ldloc(index), Ldc_I4(1)) .Stloc(index) .Br(loopStart)); } }