public IILGen Mark(IILLabel label) { _sourceCodeWriter.Indent--; _sourceCodeWriter.WriteLine(((ILLabelImpl)label).Name + ":"); _sourceCodeWriter.Indent++; _ilGenerator.MarkLabel(((ILLabelImpl)label).Label); return(this); }
public static IILGen BneUnS(this IILGen il, IILLabel targetLabel) { il.Emit(OpCodes.Bne_Un_S, targetLabel); return(il); }
public static IILGen BrtrueS(this IILGen il, IILLabel targetLabel) { il.Emit(OpCodes.Brtrue_S, targetLabel); return(il); }
public IILGen Mark(IILLabel label) { _instructions.Add(new MarkInst(label)); return this; }
public void ReplayTo(IILGen target) { Label = target.DefineLabel(_name); }
public static void GenerateJumpIfEqual(IILGen ilGenerator, Type type, IILLabel jumpTo, Action <IILGen> loadLeft, Action <IILGen> loadRight) { if (type == typeof(sbyte) || type == typeof(byte) || type == typeof(short) || type == typeof(ushort) || type == typeof(int) || type == typeof(uint) || type == typeof(long) || type == typeof(ulong) || type == typeof(float) || type == typeof(double) || type == typeof(bool) || type.IsEnum) { ilGenerator .Do(loadLeft) .Do(loadRight) .BeqS(jumpTo); return; } if (type.IsGenericType) { var genType = type.GetGenericTypeDefinition(); if (genType == typeof(Nullable <>)) { var localLeft = ilGenerator.DeclareLocal(type, "left"); var localRight = ilGenerator.DeclareLocal(type, "right"); var hasValueMethod = type.GetMethod("get_HasValue"); var getValueMethod = type.GetMethod("GetValueOrDefault", Type.EmptyTypes); var labelLeftHasValue = ilGenerator.DefineLabel("leftHasValue"); var labelDifferent = ilGenerator.DefineLabel("different"); ilGenerator .Do(loadLeft) .Stloc(localLeft) .Do(loadRight) .Stloc(localRight) .Ldloca(localLeft) .Call(hasValueMethod) .BrtrueS(labelLeftHasValue) .Ldloca(localRight) .Call(hasValueMethod) .BrtrueS(labelDifferent) .BrS(jumpTo) .Mark(labelLeftHasValue) .Ldloca(localRight) .Call(hasValueMethod) .BrfalseS(labelDifferent); GenerateJumpIfEqual( ilGenerator, type.GetGenericArguments()[0], jumpTo, g => g.Ldloca(localLeft).Call(getValueMethod), g => g.Ldloca(localRight).Call(getValueMethod)); ilGenerator.Mark(labelDifferent); return; } } var equalsMethod = type.GetMethod("Equals", new[] { type, type }) ?? type.GetMethod("op_Equality", new[] { type, type }); if (equalsMethod != null) { loadLeft(ilGenerator); loadRight(ilGenerator); ilGenerator .Call(equalsMethod) .BrtrueS(jumpTo); return; } throw new ArgumentOutOfRangeException(nameof(type), $"Don't know how to compare type {type}"); }
public IILGen Mark(IILLabel label) { _ilGenerator.MarkLabel(((ILLabelImpl)label).Label); return(this); }
public MarkInst(IILLabel label) { _label = label; }
public void Emit(OpCode opCode, IILLabel ilLabel) { _sourceCodeWriter.MarkAndWriteLine(_ilGenerator, $"{opCode} {((ILLabelImpl) ilLabel).Name}"); _ilGenerator.Emit(opCode, ((ILLabelImpl)ilLabel).Label); }
public IILGen Mark(IILLabel label) { _instructions.Add(new MarkInst(label)); return(this); }
public void Emit(OpCode opCode, IILLabel ilLabel) { _ilGenerator.Emit(opCode, ((ILLabelImpl)ilLabel).Label); }
public IILGen Mark(IILLabel label) { _ilGenerator.MarkLabel(((ILLabelImpl)label).Label); return this; }
public void FreeTemps() { Label = null; }
public static IILGen Beq(this IILGen il, IILLabel targetLabel) { il.Emit(OpCodes.Beq, targetLabel); return(il); }
public void Emit(OpCode opCode, IILLabel ilLabel) { _instructions.Add(new EmitILLabel(opCode, ilLabel)); }
public static IILGen BgeUn(this IILGen il, IILLabel targetLabel) { il.Emit(OpCodes.Bge_Un, targetLabel); return(il); }
public EmitILLabel(OpCode opCode, IILLabel ilLabel) { _opCode = opCode; _ilLabel = ilLabel; }
public void Emit(OpCode opCode, IILLabel ilLabel) { _sourceCodeWriter.MarkAndWriteLine(_ilGenerator, string.Format("{0} {1}", opCode, ((ILLabelImpl)ilLabel).Name)); _ilGenerator.Emit(opCode, ((ILLabelImpl)ilLabel).Label); }
public IILGen Mark(IILLabel label) { _sourceCodeWriter.Indent--; _sourceCodeWriter.WriteLine(((ILLabelImpl)label).Name + ":"); _sourceCodeWriter.Indent++; _ilGenerator.MarkLabel(((ILLabelImpl)label).Label); return this; }