private Emit(CallingConventions callConvention, Type returnType, Type[] parameterTypes, bool allowUnverifiable, bool doVerify, bool strictBranchVerification) { CallingConventions = callConvention; AllowsUnverifiableCIL = allowUnverifiable; IsVerifying = doVerify; UsesStrictBranchVerification = strictBranchVerification; ReturnType = TypeOnStack.Get(returnType); ParameterTypes = parameterTypes; IL = new BufferedILGenerator <DelegateType>(); Trackers = new LinqList <VerifiableTracker>(); AllLocals = new LinqList <Local>(); UnusedLocals = new LinqHashSet <Local>(); UnusedLabels = new LinqHashSet <Label>(); UnmarkedLabels = new LinqHashSet <Label>(); Branches = new LinqList <SigilTuple <OpCode, Label, int> >(); Marks = new LinqDictionary <Label, int>(); Returns = new LinqList <int>(); Throws = new LinqList <int>(); BranchPatches = new LinqDictionary <int, SigilTuple <Label, UpdateOpCodeDelegate, OpCode> >(); CurrentExceptionBlock = new Stack <ExceptionBlock>(); TryBlocks = new LinqDictionary <ExceptionBlock, SigilTuple <int, int> >(); CatchBlocks = new LinqDictionary <CatchBlock, SigilTuple <int, int> >(); FinallyBlocks = new LinqDictionary <FinallyBlock, SigilTuple <int, int> >(); ReadonlyPatches = new LinqList <SigilTuple <int, TypeOnStack> >(); Shorthand = new EmitShorthand <DelegateType>(this); FreedLocals = new LinqList <Local>(); CurrentLocals = new LinqDictionary <string, Local>(); Locals = new LocalLookup(CurrentLocals); CurrentLabels = new LinqDictionary <string, Label>(); Labels = new LabelLookup(CurrentLabels); ElidableCasts = new LinqList <int>(); TypesProducedAtIndex = new LinqDictionary <int, LinqList <TypeOnStack> >(); var start = DefineLabel("__start"); CurrentVerifiers = IsVerifying ? new RollingVerifier(start, UsesStrictBranchVerification) : new RollingVerifierWithoutVerification(start); MarkLabel(start); }
internal Local(object owner, ushort index, Type localType, BufferedILGenerator.DeclareLocallDelegate local, string name, LocalReusableDelegate reusable) { _Owner = owner; LocalDel = local; Name = name; Index = index; LocalType = localType; StackType = TypeOnStack.Get(localType); Reusable = reusable; }
/// <summary> /// Pops parameterTypes.Length arguments from the stack, invokes the constructor on the given type that matches parameterTypes, and pushes a reference to the new object onto the stack. /// </summary> public Emit <DelegateType> NewObject(Type type, params Type[] parameterTypes) { if (type == null) { throw new ArgumentNullException("type"); } if (parameterTypes == null) { throw new ArgumentNullException("parameterTypes"); } var allCons = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance); var cons = LinqAlternative .Where( allCons, c => c.GetParameters().Length == parameterTypes.Length && LinqAlternative.Select(c.GetParameters(), (p, i) => p.ParameterType == parameterTypes[i]).Aggregate(true, (a, b) => a && b) ).SingleOrDefault(); if (cons == null) { throw new InvalidOperationException("Type " + type + " must have a constructor that matches parameters [" + BufferedILGenerator <DelegateType> .Join(", ", ((LinqArray <Type>)parameterTypes).AsEnumerable()) + "]"); } return(NewObject(cons)); }
internal Label(object owner, BufferedILGenerator.DefineLabelDelegate label, string name) { _Owner = owner; Name = name; LabelDel = label; }