public NeoModule Convert(ILModule _in, ConvOption option = null)
        {
            this.inModule  = _in;
            this.outModule = new NeoModule(this.logger)
            {
                option = option ?? ConvOption.Default
            };
            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;                        //skip system type
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                          // skip api
                }
                if (t.Key.Contains(".My."))
                {
                    continue;                         //vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;                                                      // skip the code generated by event
                    }
                    if (m.Value.method.Is_ctor())
                    {
                        continue;
                    }
                    if (m.Value.method.Is_cctor())
                    {
                        //if cctor contains sth can not be as a const value.
                        //  then need 1.record these cctor's code.
                        //            2.insert them to main function
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }

                    NeoMethod nm = new NeoMethod(m.Value);
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }

                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent(e.Value);
                        outModule.mapEvents[ae.name] = ae;
                    }
                    else if (e.Value.field.IsStatic)
                    {
                        var _fieldindex = outModule.mapFields.Count;
                        var field       = new NeoField(e.Key, e.Value.type, _fieldindex);
                        outModule.mapFields[e.Value.field.FullName] = field;
                    }
                }
            }

            var keys = new List <string>(_in.mapType.Keys);

            foreach (var key in keys)
            {
                var value = _in.mapType[key];
                if (key.Contains("<"))
                {
                    continue;                    // skip system typee
                }
                if (key.Contains("_API_"))
                {
                    continue;                        // skip api
                }
                if (key.Contains(".My."))
                {
                    continue;                       //vb system
                }
                foreach (var m in value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.Is_cctor())
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;                                                      // skip the code generated by event
                    }
                    var nm = this.methodLink[m.Value];

                    //try
                    {
                        nm.returntype = m.Value.returntype;

                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        if (IsContractCall(m.Value.method, out byte[] outcall))
Beispiel #2
0
        public NeoModule Convert(ILModule _in, ConvOption option = null)
        {
            this.inModule = _in;
            //logger.Log("beginConvert.");
            this.outModule        = new NeoModule(this.logger);
            this.outModule.option = option == null ? ConvOption.Default : option;
            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;//系统的,不要
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    NeoMethod nm = new NeoMethod();
                    if (m.Key.Contains(".cctor"))
                    {
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }
                    if (m.Value.method.IsConstructor)
                    {
                        continue;
                    }
                    nm._namespace  = m.Value.method.DeclaringType.FullName;
                    nm.name        = m.Value.method.FullName;
                    nm.displayName = m.Value.method.Name;

                    Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes;
                    foreach (var attr in ca)
                    {
                        if (attr.AttributeType.Name == "DisplayNameAttribute")
                        {
                            nm.displayName = (string)attr.ConstructorArguments[0].Value;
                        }
                    }
                    nm.inSmartContract            = m.Value.method.DeclaringType.BaseType.Name == "SmartContract";
                    nm.isPublic                   = m.Value.method.IsPublic;
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }
                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent();
                        ae._namespace  = e.Value.field.DeclaringType.FullName;
                        ae.name        = ae._namespace + "::" + e.Key;
                        ae.displayName = e.Value.displayName;
                        ae.returntype  = e.Value.returntype;
                        ae.paramtypes  = e.Value.paramtypes;
                        outModule.mapEvents[ae.name] = ae;
                    }
                }
            }

            var keys = new List <string>(_in.mapType.Keys);

            foreach (var key in keys)
            {
                var value = _in.mapType[key];
                if (key.Contains("<"))
                {
                    continue;//系统的,不要
                }
                if (key.Contains("_API_"))
                {
                    continue;                       //api的,不要
                }
                if (key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Key.Contains(".cctor"))
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    var nm = this.methodLink[m.Value];


                    //try
                    {
                        nm.returntype = m.Value.returntype;
                        try
                        {
                            var type = m.Value.method.ReturnType.Resolve();
                            foreach (var i in type.Interfaces)
                            {
                                if (i.InterfaceType.Name == "IApiInterface")
                                {
                                    nm.returntype = "IInteropInterface";
                                }
                            }
                        }
                        catch (Exception err)
                        {
                        }

                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        byte[] outcall; string name; VM.OpCode[] opcodes; string[] opdata;
                        if (IsAppCall(m.Value.method, out outcall))
                        {
                            continue;
                        }
                        if (IsNonCall(m.Value.method))
                        {
                            continue;
                        }
                        if (IsMixAttribute(m.Value.method, out opcodes, out opdata))
                        {
                            continue;
                        }

                        this.ConvertMethod(m.Value, nm);
                    }
                    //catch (Exception err)
                    //{
                    //    logger.Log("error:" + err.Message);
                    //}
                }
            }
            //转换完了,做个link,全部拼到一起
            string mainmethod = "";

            foreach (var key in outModule.mapMethods.Keys)
            {
                if (key.Contains("::Main("))
                {
                    NeoMethod m = outModule.mapMethods[key];
                    if (m.inSmartContract)
                    {
                        foreach (var l in this.methodLink)
                        {
                            if (l.Value == m)
                            {
                                if (mainmethod != "")
                                {
                                    throw new Exception("Have too mush EntryPoint,Check it.");
                                }
                                mainmethod = key;
                            }
                        }
                    }
                }
            }
            if (mainmethod == "")
            {
                throw new Exception("Can't find EntryPoint,Check it.");
            }
            else
            {
                //单一默认入口
                logger.Log("Find entrypoint:" + mainmethod);
            }

            outModule.mainMethod = mainmethod;
            this.LinkCode(mainmethod);
            //this.findFirstFunc();//得找到第一个函数
            //然后给每个method 分配一个func addr
            //还需要对所有的call 做一次地址转换

            //this.outModule.Build();
            return(outModule);
        }
Beispiel #3
0
        public NeoModule Convert(ILModule _in, ConvOption option = null)
        {
            this.inModule = _in;
            //logger.Log("beginConvert.");
            this.outModule = new NeoModule(this.logger)
            {
                option = option ?? ConvOption.Default
            };
            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;//系统的,不要
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    if (m.Value.method.Is_cctor())
                    {
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }
                    if (m.Value.method.Is_ctor())
                    {
                        continue;
                    }
                    NeoMethod nm = new NeoMethod(m.Value);
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }

                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent(e.Value);
                        outModule.mapEvents[ae.name] = ae;
                    }
                    else if (e.Value.field.IsStatic)
                    {
                        var _fieldindex = outModule.mapFields.Count;
                        var field       = new NeoField(e.Key, e.Value.type, _fieldindex);
                        outModule.mapFields[e.Value.field.FullName] = field;
                    }
                }
            }

            var keys = new List <string>(_in.mapType.Keys);

            foreach (var key in keys)
            {
                var value = _in.mapType[key];
                if (key.Contains("<"))
                {
                    continue;//系统的,不要
                }
                if (key.Contains("_API_"))
                {
                    continue;                       //api的,不要
                }
                if (key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.Is_cctor())
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    var nm = this.methodLink[m.Value];

                    //try
                    {
                        nm.returntype = m.Value.returntype;
                        try
                        {
                            var type = m.Value.method.ReturnType.Resolve();
                            foreach (var i in type.Interfaces)
                            {
                                if (i.InterfaceType.Name == "IApiInterface")
                                {
                                    nm.returntype = "IInteropInterface";
                                }
                            }
                        }
                        catch
                        {
                        }

                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        if (IsAppCall(m.Value.method, out byte[] outcall))
Beispiel #4
0
        public NeoModule Convert(ILModule _in)
        {
            //logger.Log("beginConvert.");
            this.outModule = new NeoModule(this.logger);
            foreach (var t in _in.mapType)
            {
                if (t.Key[0] == '<')
                {
                    continue;                 //系统的,不要
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    NeoMethod nm = new NeoMethod();
                    if (m.Key == ".cctor")
                    {
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }
                    if (m.Value.method.IsConstructor)
                    {
                        continue;
                    }
                    nm._namespace  = m.Value.method.DeclaringType.FullName;
                    nm.name        = m.Value.method.FullName;
                    nm.displayName = m.Value.method.Name;

                    Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes;
                    foreach (var attr in ca)
                    {
                        if (attr.AttributeType.Name == "DisplayNameAttribute")
                        {
                            nm.displayName = (string)attr.ConstructorArguments[0].Value;
                        }
                    }

                    nm.isPublic = m.Value.method.IsPublic;
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }
                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent();
                        ae._namespace  = e.Value.field.DeclaringType.FullName;
                        ae.name        = ae._namespace + "::" + e.Key;
                        ae.displayName = e.Value.displayName;
                        ae.returntype  = e.Value.returntype;
                        ae.paramtypes  = e.Value.paramtypes;
                        outModule.mapEvents[ae.name] = ae;
                    }
                }
            }

            Dictionary <byte, string> spmains = new Dictionary <byte, string>();

            foreach (var t in _in.mapType)
            {
                if (t.Key[0] == '<')
                {
                    continue;                 //系统的,不要
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Key == ".cctor")
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    var  nm = this.methodLink[m.Value];
                    byte entryid;
                    if (IsEntryCall(m.Value.method, out entryid))
                    {
                        spmains[entryid] = nm.name;
                        logger.Log("Find entrypoint:[" + entryid + "]" + nm.name);
                    }

                    //try
                    {
                        nm.returntype = m.Value.returntype;
                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        byte[] outcall; string name;
                        if (IsAppCall(m.Value.method, out outcall))
                        {
                            continue;
                        }
                        if (IsNonCall(m.Value.method))
                        {
                            continue;
                        }
                        if (IsOpCall(m.Value.method, out name))
                        {
                            continue;
                        }
                        if (IsSysCall(m.Value.method, out name))
                        {
                            continue;
                        }

                        this.ConvertMethod(m.Value, nm);
                    }
                    //catch (Exception err)
                    //{
                    //    logger.Log("error:" + err.Message);
                    //}
                }
            }
            //转换完了,做个link,全部拼到一起
            string mainmethod = "";

            foreach (var key in outModule.mapMethods.Keys)
            {
                if (key.Contains("::Main("))
                {
                    NeoMethod m = outModule.mapMethods[key];

                    foreach (var l in this.methodLink)
                    {
                        if (l.Value == m)
                        {
                            var srcm = l.Key.method;
                            if (srcm.DeclaringType.BaseType.Name == "SmartContract")
                            {
                                if (mainmethod != "")
                                {
                                    throw new Exception("Have too mush EntryPoint,Check it.");
                                }
                                mainmethod = key;
                            }
                        }
                    }
                }
            }
            if (mainmethod == "" && spmains.Count == 0)
            {
                throw new Exception("Can't find EntryPoint,Check it.");
            }
            else if (mainmethod != "" && spmains.Count > 0)
            {
                throw new Exception("Have Main Method and Spec EntryPoint sametime,Check it.");
            }
            else if (mainmethod != "")
            {
                //单一默认入口
                logger.Log("Find entrypoint:" + mainmethod);
            }
            else if (spmains.Count > 0) //拥有条件入口的情况
            {
                mainmethod = this.CreateJmpMain(spmains);
            }

            outModule.mainMethod = mainmethod;
            this.LinkCode(mainmethod);
            //this.findFirstFunc();//得找到第一个函数
            //然后给每个method 分配一个func addr
            //还需要对所有的call 做一次地址转换

            //this.outModule.Build();
            return(outModule);
        }
Beispiel #5
0
        public NeoModule Convert(ILModule _in, ConvOption option = null)
        {
            this.inModule = _in;
            //logger.Log("beginConvert.");
            this.outModule = new NeoModule(this.logger)
            {
                option = option ?? ConvOption.Default
            };
            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;//系统的,不要
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    NeoMethod nm = new NeoMethod();
                    if (m.Key.Contains(".cctor"))
                    {
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }
                    if (m.Value.method.IsConstructor)
                    {
                        continue;
                    }
                    nm._namespace  = m.Value.method.DeclaringType.FullName;
                    nm.name        = m.Value.method.FullName;
                    nm.displayName = m.Value.method.Name;

                    Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes;
                    foreach (var attr in ca)
                    {
                        if (attr.AttributeType.Name == "DisplayNameAttribute")
                        {
                            nm.displayName = (string)attr.ConstructorArguments[0].Value;
                        }
                    }
                    nm.inSmartContract            = m.Value.method.DeclaringType.BaseType.Name == "SmartContract";
                    nm.isPublic                   = m.Value.method.IsPublic;
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }
                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent
                        {
                            _namespace  = e.Value.field.DeclaringType.FullName,
                            name        = e.Value.field.DeclaringType.FullName + "::" + e.Key,
                            displayName = e.Value.displayName,
                            returntype  = e.Value.returntype,
                            paramtypes  = e.Value.paramtypes
                        };
                        outModule.mapEvents[ae.name] = ae;
                    }
                    else if (e.Value.field.IsStatic)
                    {
                        var _fieldindex = outModule.mapFields.Count;
                        var field       = new NeoField(e.Key, e.Value.type, _fieldindex);
                        outModule.mapFields[e.Value.field.FullName] = field;
                    }
                }
            }

            var keys = new List <string>(_in.mapType.Keys);

            foreach (var key in keys)
            {
                var value = _in.mapType[key];
                if (key.Contains("<"))
                {
                    continue;//系统的,不要
                }
                if (key.Contains("_API_"))
                {
                    continue;                       //api的,不要
                }
                if (key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Key.Contains(".cctor"))
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要
                    }
                    var nm = this.methodLink[m.Value];


                    //try
                    {
                        nm.returntype = m.Value.returntype;
                        try
                        {
                            var type = m.Value.method.ReturnType.Resolve();
                            foreach (var i in type.Interfaces)
                            {
                                if (i.InterfaceType.Name == "IApiInterface")
                                {
                                    nm.returntype = "IInteropInterface";
                                }
                            }
                        }
                        catch
                        {
                        }

                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        if (IsAppCall(m.Value.method, out byte[] outcall))
Beispiel #6
0
        public NeoModule Convert(ILModule _in)
        {
            //logger.Log("beginConvert.");
            this.outModule = new NeoModule(this.logger);
            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;//系统的,不要 system, no
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要 api, do not
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要 Auto - generated code, do not
                    }
                    NeoMethod nm = new NeoMethod();
                    if (m.Key.Contains(".cctor"))
                    {
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }
                    if (m.Value.method.IsConstructor)
                    {
                        continue;
                    }
                    nm._namespace  = m.Value.method.DeclaringType.FullName;
                    nm.name        = m.Value.method.FullName;
                    nm.displayName = m.Value.method.Name;

                    Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes;
                    foreach (var attr in ca)
                    {
                        if (attr.AttributeType.Name == "DisplayNameAttribute")
                        {
                            nm.displayName = (string)attr.ConstructorArguments[0].Value;
                        }
                    }
                    nm.inSmartContract            = m.Value.method.DeclaringType.BaseType.Name == "SmartContract";
                    nm.isPublic                   = m.Value.method.IsPublic;
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }
                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent();
                        ae._namespace  = e.Value.field.DeclaringType.FullName;
                        ae.name        = ae._namespace + "::" + e.Key;
                        ae.displayName = e.Value.displayName;
                        ae.returntype  = e.Value.returntype;
                        ae.paramtypes  = e.Value.paramtypes;
                        outModule.mapEvents[ae.name] = ae;
                    }
                }
            }


            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;//系统的,不要 Systematic, no
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                         //api的,不要 api, do not
                }
                if (t.Key.Contains(".My."))
                {
                    continue;//vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Key.Contains(".cctor"))
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;//event 自动生成的代码,不要 Auto-generated code, do not
                    }
                    var nm = this.methodLink[m.Value];


                    //try
                    {
                        nm.returntype = m.Value.returntype;
                        try
                        {
                            var type = m.Value.method.ReturnType.Resolve();
                            foreach (var i in type.Interfaces)
                            {
                                if (i.Name == "IApiInterface")
                                {
                                    nm.returntype = "IInteropInterface";
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }

                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        byte[] outcall; string name;
                        if (IsAppCall(m.Value.method, out outcall))
                        {
                            continue;
                        }
                        if (IsNonCall(m.Value.method))
                        {
                            continue;
                        }
                        if (IsOpCall(m.Value.method, out name))
                        {
                            continue;
                        }
                        if (IsSysCall(m.Value.method, out name))
                        {
                            continue;
                        }

                        this.ConvertMethod(m.Value, nm);
                    }
                    //catch (Exception err)
                    //{
                    //    logger.Log("error:" + err.Message);
                    //}
                }
            }
            //转换完了,做个link,全部拼到一起 Conversion finished, be a link, all together
            string mainmethod = "";

            foreach (var key in outModule.mapMethods.Keys)
            {
                if (key.Contains("::Main("))
                {
                    NeoMethod m = outModule.mapMethods[key];
                    if (m.inSmartContract)
                    {
                        foreach (var l in this.methodLink)
                        {
                            if (l.Value == m)
                            {
                                if (mainmethod != "")
                                {
                                    throw new Exception("Have too mush EntryPoint,Check it.");
                                }
                                mainmethod = key;
                            }
                        }
                    }
                }
            }
            if (mainmethod == "")
            {
                throw new Exception("Can't find EntryPoint,Check it.");
            }
            else
            {
                //单一默认入口 Single default entry
                logger.Log("Find entrypoint:" + mainmethod);
            }

            outModule.mainMethod = mainmethod;
            this.LinkCode(mainmethod);
            //this.findFirstFunc();//得找到第一个函数 Have to find the first function
            //然后给每个method 分配一个func addr Then assign a func addr to each method
            //还需要对所有的call 做一次地址转换 Also need to do an address translation for all calls

            //this.outModule.Build();
            return(outModule);
        }
        public NeoModule Convert(ILModule _in, ConvOption option = null)
        {
            this.inModule  = _in;
            this.outModule = new NeoModule()
            {
                option = option ?? ConvOption.Default
            };
            foreach (var t in _in.mapType)
            {
                if (t.Key.Contains("<"))
                {
                    continue;                        //skip system type
                }
                if (t.Key.Contains("_API_"))
                {
                    continue;                          // skip api
                }
                if (t.Key.Contains(".My."))
                {
                    continue;                         //vb system
                }
                foreach (var m in t.Value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;                                                      // skip the code generated by event
                    }
                    if (m.Value.method.Is_ctor())
                    {
                        continue;
                    }
                    if (m.Value.method.Is_cctor())
                    {
                        //if cctor contains sth can not be as a const value.
                        //  then need 1.record these cctor's code.
                        //            2.insert them to main function
                        CctorSubVM.Parse(m.Value, this.outModule);
                        continue;
                    }

                    NeoMethod nm = new NeoMethod(m.Value);
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }

                foreach (var e in t.Value.fields)
                {
                    if (e.Value.isEvent)
                    {
                        NeoEvent ae = new NeoEvent(e.Value);
                        outModule.mapEvents[ae.name] = ae;
                    }
                    else if (e.Value.field.IsStatic)
                    {
                        var _fieldindex = outModule.mapFields.Count;
                        var field       = new NeoField(e.Key, e.Value.type, _fieldindex);
                        outModule.mapFields[e.Value.field.FullName] = field;
                    }
                }
            }

            var keys = new List <string>(_in.mapType.Keys);

            foreach (var key in keys)
            {
                var value = _in.mapType[key];
                if (key.Contains("<"))
                {
                    continue;                    // skip system typee
                }
                if (key.Contains("_API_"))
                {
                    continue;                        // skip api
                }
                if (key.Contains(".My."))
                {
                    continue;                       //vb system
                }
                foreach (var m in value.methods)
                {
                    if (m.Value.method == null)
                    {
                        continue;
                    }
                    if (m.Value.method.Is_cctor())
                    {
                        continue;
                    }
                    if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
                    {
                        continue;                                                      // skip the code generated by event
                    }
                    var nm = this.methodLink[m.Value];

                    //try
                    {
                        nm.returntype = m.Value.returntype;

                        foreach (var src in m.Value.paramtypes)
                        {
                            nm.paramtypes.Add(new NeoParam(src.name, src.type));
                        }

                        if (IsContractCall(m.Value.method, out _))
                        {
                            continue;
                        }
                        if (IsNonCall(m.Value.method))
                        {
                            continue;
                        }
                        if (IsMixAttribute(m.Value.method, out _, out _))
                        {
                            continue;
                        }

                        if (m.Key.Contains("::Main("))
                        {
                            NeoMethod _m = outModule.mapMethods[m.Key];
                        }
                        this.ConvertMethod(m.Value, nm);
                    }
                }
            }

            if (this.outModule.mapFields.Count > MAX_STATIC_FIELDS_COUNT)
            {
                throw new Exception("too much static fields");
            }
            if (this.outModule.mapFields.Count > 0)
            {
                InsertInitializeMethod();
                logger.Log("Insert _initialize().");
            }

            var attr = outModule.mapMethods.Values.Where(u => u.inSmartContract).Select(u => u.type?.attributes.ToArray()).FirstOrDefault();

            if (attr?.Length > 0)
            {
                outModule.attributes.AddRange(attr);
            }

            var declaringTypes = outModule.mapMethods.Values
                                 .Where(u => u.inSmartContract)
                                 .Select(u => u.method?.method?.DeclaringType)
                                 .Where(u => u != null && !string.IsNullOrEmpty(u.Name))
                                 .Distinct()
                                 .ToArray();

            outModule.Name = declaringTypes.Length == 1 ? declaringTypes[0].Name : Path.GetFileNameWithoutExtension(_in.module.Name);

            this.LinkCode();

            // this.findFirstFunc();// Need to find the first method
            // Assign func addr for each method
            // Then convert the call address

            return(outModule);
        }