• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ILGen类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ILGen的典型用法代码示例。如果您正苦于以下问题:C# ILGen类的具体用法?C# ILGen怎么用?C# ILGen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ILGen类属于命名空间,在下文中一共展示了ILGen类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Compile

 public override Type Compile(Executive engine, ILGen il, LocalAccess locals, Type[] parameterTypes)
 {
     for (int k = 0; k < parameterTypes.Length; k++)
         il.Emit(OpCodes.Pop);
     il.EmitFieldGet(typeof(DBNull), "Value");
     return typeof(DBNull);
 }
开发者ID:,项目名称:,代码行数:7,代码来源:


示例2: Create

        internal static Type Create(GenContext context, Type baseClass)
        {
            //ModuleBuilder mb = context.ModuleBldr;
            string name = baseClass.Name + "_impl";
            //TypeBuilder baseTB = context.ModuleBldr.DefineType(name, TypeAttributes.Class | TypeAttributes.Public, baseClass);
            TypeBuilder baseTB = context.AssemblyGen.DefinePublicType(name, baseClass, true);

            ObjExpr.MarkAsSerializable(baseTB);

            baseTB.DefineDefaultConstructor(MethodAttributes.Public);

            FieldBuilder metaField = baseTB.DefineField("_meta", typeof(IPersistentMap), FieldAttributes.Public);

            MethodBuilder metaMB = baseTB.DefineMethod("meta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IPersistentMap), Type.EmptyTypes);
            ILGen gen = new ILGen(metaMB.GetILGenerator());
            gen.EmitLoadArg(0);
            gen.EmitFieldGet(metaField);
            gen.Emit(OpCodes.Ret);

            MethodBuilder withMB = baseTB.DefineMethod("withMeta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IObj), new Type[] { typeof(IPersistentMap)});
            gen = new ILGen(withMB.GetILGenerator());
            gen.EmitLoadArg(0);
            gen.EmitCall(Compiler.Method_Object_MemberwiseClone);
            gen.Emit(OpCodes.Castclass, baseTB);
            gen.Emit(OpCodes.Dup);
            gen.EmitLoadArg(1);
            gen.EmitFieldSet(metaField);
            gen.Emit(OpCodes.Ret);

            for (int i = 0; i < 20; i++ )
                DefineDelegateFieldAndOverride(baseTB, i);

            return baseTB.CreateType();
        }
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:34,代码来源:AFnImplGenerator.cs


示例3: Define

        // Returns true if the label was successfully defined
        // or false if the label is now ambiguous
        internal void Define(ILGen il, LabelBlockInfo block) {
            // Prevent the label from being shadowed, which enforces cleaner
            // trees. Also we depend on this for simplicity (keeping only one
            // active IL Label per LabelInfo)
            for (LabelBlockInfo j = block; j != null; j = j.Parent) {
                if (j.ContainsTarget(Node)) {
                    throw Error.LabelTargetAlreadyDefined(Node.Name);
                }
            }

            Definitions.Add(block);
            block.AddLabelInfo(Node, this);

            // Once defined, validate all jumps
            if (Definitions.Count == 1) {
                foreach (var r in References) {
                    ValidateJump(r);
                }
            } else {
                // Was just redefined, if we had any across block jumps, they're
                // now invalid
                if (_acrossBlockJump) {
                    throw Error.AmbiguousJump(Node.Name);
                }
                // For local jumps, we need a new IL label
                // This is okay because:
                //   1. no across block jumps have been made or will be made
                //   2. we don't allow the label to be shadowed
                Label = il.DefineLabel();
            }
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:33,代码来源:LabelInfo.cs


示例4: GetCCtor

 protected ILGen GetCCtor() {
     if (_cctor == null) {
         ConstructorBuilder cctor = _tb.DefineTypeInitializer();
         _cctor = CreateILGen(cctor.GetILGenerator());
     }
     return _cctor;
 }
开发者ID:BrianGenisio,项目名称:ironruby,代码行数:7,代码来源:ClsTypeEmitter.cs


示例5: FixReturn

 internal void FixReturn(ILGen cg)
 {
     cg.EmitLoadArg(_argIndex);
     cg.Emit(OpCodes.Ldloc, _refSlot);
     cg.Emit(OpCodes.Ldfld, _refSlot.LocalType.GetDeclaredField("Value"));
     cg.EmitStoreValueIndirect(_argType.GetElementType());
 }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:ReturnFixer.cs


示例6: LabelInfo

        internal LabelInfo(ILGen il, LabelTarget node, bool canReturn) {
            _ilg = il;
            Node = node;
            Label = il.DefineLabel();
            _canReturn = canReturn;
            if (node != null && node.Type != typeof(void)) {
                Value = il.DeclareLocal(node.Type);
            }

            // Until we have more information, default to a leave instruction, which always works
            _opCode = OpCodes.Leave;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:12,代码来源:LabelInfo.cs


示例7: GetBranch

 private Branch GetBranch(List<Branch> branches, ILGen il, Type type)
 {
     foreach (Branch b in branches)
         if (b.type == type)
             return b;
     Branch branch = new Branch();
     branch.type = type;
     branch.localVar = il.DeclareLocal(type);
     branch.handler = il.DefineLabel();
     branches.Add(branch);
     return branch;
 }
开发者ID:,项目名称:,代码行数:12,代码来源:


示例8: EmitArgument

        internal static ReturnFixer EmitArgument(ILGen cg, int argIndex, Type argType) {
            cg.EmitLoadArg(argIndex);

            if (!argType.IsByRef) {
                cg.EmitBoxing(argType);
                return null;
            }

            Type elementType = argType.GetElementType();
            cg.EmitLoadValueIndirect(elementType);
            Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
            cg.EmitNew(concreteType, new Type[] { elementType });

            LocalBuilder refSlot = cg.DeclareLocal(concreteType);
            cg.Emit(OpCodes.Dup);
            cg.Emit(OpCodes.Stloc, refSlot);
            return new ReturnFixer(refSlot, argIndex, argType);
        }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:18,代码来源:ReturnFixer.cs


示例9: CreateVariables

 public override void CreateVariables(Executive engine, object form, ILGen il, LocalAccess locals, object[] args)
 {
     if (args.Length == 0)
         throw new ArgumentException("Unproperly formated expression");
     locals.DeclareScope(form);
     locals.EnterScope(form, _activeScope);
     foreach (object arg in Lisp.getIterator(args[0]))
     {
         object[] pair = Lisp.ToArray(arg);
         if (pair.Length != 2 || !Lisp.IsAtom(pair[0]))
             throw new ArgumentException("Unproperly formated expression");
         locals.DeclareLocal(pair[0]);
         engine.CreateVariables(il, locals, pair[1]);
     }
     if (!_activeScope)
         locals.ActivateScope();
     for (int k = 1; k < args.Length; k++)
         engine.CreateVariables(il, locals, args[k]);
     locals.LeaveScope();
 }
开发者ID:,项目名称:,代码行数:20,代码来源:


示例10: Init

    internal void Init(ILGen.BaseILGenerator ilGen)
    {
      _ilGen = ilGen;

      if (_availableLocals == null)
      {
        //First time initialization
        _availableLocals = new Dictionary<Type, AvailableLocals>();
        _symbolLocals = new Dictionary<JSSymbol, LocalBuilder>();
        _namedLocals = new Dictionary<string, LocalBuilder>();
        _unnamedLocals = new Dictionary<IR.WriteTemporaryExpression, LocalBuilder>();
        _temporaryStackLocals = new List<LocalBuilder>();
      }
      else
        Debug.Assert(
          _availableLocals.Count == 0
          && _symbolLocals.Count == 0
          && _namedLocals.Count == 0
          && _unnamedLocals.Count == 0
          && _temporaryStackLocals.Count == 0
          , "LocalVarManager was not cleared properly in the last use!");
    }
开发者ID:reshadi2,项目名称:mcjs,代码行数:22,代码来源:LocalVarManager.cs


示例11: OverrideDeserializer

        private void OverrideDeserializer(ConstructorInfo/*!*/ baseCtor) {
            // ctor(SerializationInfo! info, StreamingContext! context) : base(info, context) {
            //   RubyOps.DeserializeObject(out this._instanceData, out this._immediateClass, info);
            // }

            ConstructorBuilder cb = _tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, _deserializerSignature);
            ILGen il = new ILGen(cb.GetILGenerator());

            il.EmitLoadArg(0);
            il.EmitLoadArg(1);
            il.EmitLoadArg(2);
            il.Emit(OpCodes.Call, baseCtor);

            il.EmitLoadArg(0);
            il.EmitFieldAddress(InstanceDataField);
            il.EmitLoadArg(0);
            il.EmitFieldAddress(ImmediateClassField);
            il.EmitLoadArg(1);
            il.EmitCall(Methods.DeserializeObject);
            il.Emit(OpCodes.Ret);
        }
开发者ID:jschementi,项目名称:iron,代码行数:21,代码来源:RubyTypeBuilder.cs


示例12: BuildConstructors

        private void BuildConstructors(IList<ConstructorBuilderInfo>/*!*/ ctors) {
            foreach (var ctor in ctors) {
                // ctor(... RubyClass! class ..., <visible params>) : base(<hidden params>, <visible params>) { _class = class; }
                // ctor(... RubyClass! class ..., <visible params>) : base(... RubyOps.GetContextFromClass(class) ..., <visible params>) { _class = class; }
                // ctor(RubyClass! class) : base(RubyOps.GetDefaultExceptionMessage(class)) { _class = class; }
                ConstructorBuilder cb = _tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ctor.ParameterTypes);
                ILGen il = new ILGen(cb.GetILGenerator());

                int paramIndex = 0;
                int argIndex = 0;

                // We need to initialize before calling base ctor since the ctor can call virtual methods.
                // _immediateClass = immediateClass:
                if (!IsDerivedRubyType) {
                    il.EmitLoadArg(0);
                    il.EmitLoadArg(1 + ctor.ClassParamIndex);
                    il.EmitFieldSet(ImmediateClassField);
                }

                // base ctor call:
                il.EmitLoadArg(0);

                ConstructorInfo msgCtor;
                if (ctor.ParameterTypes.Length == 1 && ctor.Adjustment == SignatureAdjustment.InsertClass &&
                    _tb.IsSubclassOf(typeof(Exception)) && IsAvailable(msgCtor = _tb.BaseType.GetConstructor(_exceptionMessageSignature))) {

                    // a parameterless exception constructor should use Ruby default message:
                    il.EmitLoadArg(1);
                    il.EmitCall(Methods.GetDefaultExceptionMessage);
                    il.Emit(OpCodes.Call, msgCtor);
                } else {
                    if (ctor.Adjustment == SignatureAdjustment.InsertClass) {
                        paramIndex++;
                    }

                    while (paramIndex < ctor.ParameterTypes.Length) {
                        if (ctor.Adjustment == SignatureAdjustment.ConvertClassToContext && argIndex == ctor.ContextArgIndex) {
                            il.EmitLoadArg(1 + ctor.ClassParamIndex);
                            il.EmitCall(Methods.GetContextFromModule);
                        } else {
                            ClsTypeEmitter.DefineParameterCopy(cb, paramIndex, ctor.BaseParameters[argIndex]);
                            il.EmitLoadArg(1 + paramIndex);
                        }
                        argIndex++;
                        paramIndex++;
                    }
                    il.Emit(OpCodes.Call, ctor.BaseCtor);
                }

                il.Emit(OpCodes.Ret);
            }
        }
开发者ID:jschementi,项目名称:iron,代码行数:52,代码来源:RubyTypeBuilder.cs


示例13: GenerateGetRequiredArityMethod

        static MethodBuilder GenerateGetRequiredArityMethod(TypeBuilder tb, int requiredArity)
        {
            MethodBuilder mb = tb.DefineMethod(
                "getRequiredArity",
                MethodAttributes.ReuseSlot | MethodAttributes.Public | MethodAttributes.Virtual,
                typeof(int),
                Type.EmptyTypes);

            ILGen gen = new ILGen(mb.GetILGenerator());
            gen.EmitInt(requiredArity);
            gen.Emit(OpCodes.Ret);

            return mb;
        }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:14,代码来源:FnExpr.cs


示例14: EmitConstantGet

 private static void EmitConstantGet(ILGen il, int index, Type type) {
     il.Emit(OpCodes.Ldarg_0);
     il.EmitInt(index);
     il.Emit(OpCodes.Ldelem_Ref);
     if (type != typeof(object)) {
         il.Emit(OpCodes.Castclass, type);
     }
 }
开发者ID:octavioh,项目名称:ironruby,代码行数:8,代码来源:DelegateSignatureInfo.cs


示例15: EmitClrCallStub

        /// <summary>
        /// Generates stub to receive the CLR call and then call the dynamic language code.
        /// </summary>
        private object[] EmitClrCallStub(ILGen cg) {

            List<ReturnFixer> fixers = new List<ReturnFixer>(0);
            // Create strongly typed return type from the site.
            // This will, among other things, generate tighter code.
            Type[] siteTypes = MakeSiteSignature();

            CallSite callSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(siteTypes), InvokeBinder);
            Type siteType = callSite.GetType();

            Type convertSiteType = null;
            CallSite convertSite = null;

            if (_returnType != typeof(void)) {
                convertSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(typeof(object), _returnType), ConvertBinder);
                convertSiteType = convertSite.GetType();
            }

            // build up constants array
            object[] constants = new object[] { TargetPlaceHolder, CallSitePlaceHolder, ConvertSitePlaceHolder };
            const int TargetIndex = 0, CallSiteIndex = 1, ConvertSiteIndex = 2;

            LocalBuilder convertSiteLocal = null;
            FieldInfo convertTarget = null;
            if (_returnType != typeof(void)) {
                // load up the conversesion logic on the stack
                convertSiteLocal = cg.DeclareLocal(convertSiteType);
                EmitConstantGet(cg, ConvertSiteIndex, convertSiteType);

                cg.Emit(OpCodes.Dup);
                cg.Emit(OpCodes.Stloc, convertSiteLocal);

                convertTarget = convertSiteType.GetField("Target");
                cg.EmitFieldGet(convertTarget);
                cg.Emit(OpCodes.Ldloc, convertSiteLocal);
            }

            // load up the invoke logic on the stack
            LocalBuilder site = cg.DeclareLocal(siteType);
            EmitConstantGet(cg, CallSiteIndex, siteType);
            cg.Emit(OpCodes.Dup);
            cg.Emit(OpCodes.Stloc, site);

            FieldInfo target = siteType.GetField("Target");
            cg.EmitFieldGet(target);
            cg.Emit(OpCodes.Ldloc, site);

            EmitConstantGet(cg, TargetIndex, typeof(object));

            for (int i = 0; i < _parameters.Length; i++) {
                if (_parameters[i].ParameterType.IsByRef) {
                    ReturnFixer rf = ReturnFixer.EmitArgument(cg, i + 1, _parameters[i].ParameterType);
                    if (rf != null) fixers.Add(rf);
                } else {
                    cg.EmitLoadArg(i + 1);
                }
            }

            // emit the invoke for the call
            cg.EmitCall(target.FieldType, "Invoke");

            // emit the invoke for the convert
            if (_returnType == typeof(void)) {
                cg.Emit(OpCodes.Pop);
            } else {
                cg.EmitCall(convertTarget.FieldType, "Invoke");
            }

            // fixup any references
            foreach (ReturnFixer rf in fixers) {
                rf.FixReturn(cg);
            }

            cg.Emit(OpCodes.Ret);
            return constants;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:79,代码来源:DelegateSignatureInfo.cs


示例16: EmitUnsupported

 private static void EmitUnsupported(ILGen gen, string name)
 {
     gen.EmitString(name);                               // gen.Emit(OpCodes.Ldstr, name);
     gen.EmitNew(CtorInfo_NotImplementedException_1);    // gen.Emit(OpCodes.Newobj, CtorInfo_NotImplementedException_1);
     gen.Emit(OpCodes.Throw);
 }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:6,代码来源:GenClass.cs


示例17: EmitMain

        static void EmitMain(GenContext context, TypeBuilder proxyTB, string mainName, FieldBuilder mainFB)
        {
            MethodBuilder cb = proxyTB.DefineMethod("Main",MethodAttributes.Public| MethodAttributes.Static,CallingConventions.Standard,typeof(void),new Type[] { typeof(String[]) });
            ILGen gen = new ILGen(cb.GetILGenerator()); ;

            Label noMainLabel = gen.DefineLabel();
            Label endLabel = gen.DefineLabel();

            EmitGetVar(gen, mainFB);
            gen.Emit(OpCodes.Dup);
            gen.Emit(OpCodes.Brfalse_S, noMainLabel);
            gen.Emit(OpCodes.Castclass, typeof(IFn));
            gen.EmitLoadArg(0);                                 // gen.Emit(OpCodes.Ldarg_0);
            gen.EmitCall(Method_RT_seq);                        // gen.Emit(OpCodes.Call, Method_RT_seq);
            gen.EmitCall(Method_IFn_applyTo_Object_ISeq);       // gen.Emit(OpCodes.Call, Method_IFn_applyTo_Object_ISeq);
            gen.Emit(OpCodes.Pop);
            gen.Emit(OpCodes.Br_S, endLabel);

            // no main found
            gen.MarkLabel(noMainLabel);
            EmitUnsupported(gen, mainName);

            gen.MarkLabel(endLabel);
            gen.Emit(OpCodes.Ret);

            //context.AssyBldr.SetEntryPoint(cb);
            context.AssemblyBuilder.SetEntryPoint(cb);
        }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:28,代码来源:GenClass.cs


示例18: EmitGetVar

        static void EmitGetVar(ILGen gen, FieldBuilder fb)
        {
            Label falseLabel = gen.DefineLabel();
            Label endLabel = gen.DefineLabel();

            gen.EmitFieldGet(fb);                       // gen.Emit(OpCodes.Ldsfld,fb);
            gen.Emit(OpCodes.Dup);
            gen.EmitCall(Method_Var_isBound);           // gen.Emit(OpCodes.Call, Method_Var_IsBound);
            gen.Emit(OpCodes.Brfalse_S,falseLabel);
            gen.Emit(OpCodes.Call,Method_Var_get);
            gen.Emit(OpCodes.Br_S,endLabel);
            gen.MarkLabel(falseLabel);
            gen.Emit(OpCodes.Pop);
            gen.EmitNull();                             // gen.Emit(OpCodes.Ldnull);
            gen.MarkLabel(endLabel);
        }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:16,代码来源:GenClass.cs



注:本文中的ILGen类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ILLabel类代码示例发布时间:2022-05-24
下一篇:
C# ILExpression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap