コード例 #1
0
        private static JArray GetMethods(NeoModule module, IReadOnlyDictionary <string, int> docMap, IReadOnlyDictionary <int, int> addrConvTable)
        {
            var outjson = new JArray();

            foreach (var method in module.mapMethods.Values)
            {
                if (method.body_Codes.Values.Count == 0)
                {
                    continue;
                }

                var name = string.Format("{0},{1}",
                                         method._namespace, method.displayName);

                var range = string.Format("{0}-{1}",
                                          method.body_Codes.Values.First().addr,
                                          method.body_Codes.Values.Last().addr);

                var methodJson = new JObject();
                methodJson["id"]              = method.name;
                methodJson["name"]            = name;
                methodJson["range"]           = range;
                methodJson["params"]          = ConvertParamList(method.paramtypes);
                methodJson["return"]          = FuncExport.ConvType(method.returntype);
                methodJson["variables"]       = ConvertParamList(method.method?.body_Variables);
                methodJson["sequence-points"] = GetSequencePoints(method.body_Codes.Values, docMap, addrConvTable);
                outjson.Add(methodJson);
            }
            return(outjson);
        }
コード例 #2
0
 private static IReadOnlyDictionary <string, int> GetDocumentMap(NeoModule module)
 {
     return(module.mapMethods.Values
            .SelectMany(m => m.body_Codes.Values)
            .Where(code => code.sequencePoint != null)
            .Select(code => code.sequencePoint.Document.Url)
            .Distinct()
            .Select((d, i) => (d, i))
            .ToDictionary(t => t.d, t => t.i));
 }
コード例 #3
0
ファイル: _DebugOutput.cs プロジェクト: ikvm/neondebug
        public static void DebugOutput(string outpath, NeoModule module, byte[] avm, MyJson.JsonNode_Object abi)
        {
            if (System.IO.Directory.Exists(outpath) == false)
            {
                System.IO.Directory.CreateDirectory(outpath);
            }
            string mapInfo = null;
            string srcfile = null;

            {//gen debug info
                Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array();
                foreach (var m in module.mapMethods)
                {
                    Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object();
                    arr.Add(item);
                    item.SetDictValue("name", m.Value.displayName);
                    item.SetDictValue("addr", m.Value.funcaddr.ToString("X04"));
                    Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array();
                    item.SetDictValue("map", infos);
                    foreach (var c in m.Value.body_Codes)
                    {
                        if (c.Value.debugcode != null)
                        {
                            var debugcode = c.Value.debugcode.ToLower();
                            if (debugcode.Contains(".cs"))
                            {
                                srcfile = debugcode;
                                infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString());
                            }
                        }
                    }
                }
                mapInfo = arr.ToString();
            }


            var hash    = abi["hash"].AsString();
            var abistr  = abi.ToString();
            var outfile = System.IO.Path.Combine(outpath, hash);

            System.IO.File.WriteAllBytes(outfile + ".avm", avm);
            System.IO.File.WriteAllText(outfile + ".map.json", mapInfo);
            System.IO.File.WriteAllText(outfile + ".abi.json", abistr);
            if (srcfile != null)
            {
                var targetfilename = outfile + ".cs";
                System.IO.File.Delete(targetfilename);
                System.IO.File.Copy(srcfile, targetfilename);
            }
            new DefLogger().Log("output to local succ");
            DebugOutputToService(hash, avm, abistr, mapInfo, System.IO.File.ReadAllText(srcfile));
        }
コード例 #4
0
        public static JObject Export(NeoModule module, byte[] script, IReadOnlyDictionary <int, int> addrConvTable)
        {
            var docMap = GetDocumentMap(module);

            addrConvTable ??= ImmutableDictionary <int, int> .Empty;

            var outjson = new JObject();

            outjson["hash"]      = ComputeHash(script);
            outjson["documents"] = GetDocuments(docMap);
            outjson["methods"]   = GetMethods(module, docMap, addrConvTable);
            outjson["events"]    = GetEvents(module);
            return(outjson);
        }
コード例 #5
0
        private static JArray GetEvents(NeoModule module)
        {
            var outjson = new JArray();

            foreach (var @event in module.mapEvents.Values)
            {
                var name = string.Format("{0},{1}",
                                         @event._namespace, @event.displayName);

                var eventJson = new JObject();
                eventJson["id"]     = @event.name;
                eventJson["name"]   = name;
                eventJson["params"] = ConvertParamList(@event.paramtypes);
                outjson.Add(eventJson);
            }
            return(outjson);
        }
コード例 #6
0
        public static void DebugOutput(NeoModule module, byte[] avm, MyJson.JsonNode_Object abi)
        {
            string mapInfo = null;
            string srcfile = null;

            {//gen debug info
                Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array();
                foreach (var m in module.mapMethods)
                {
                    Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object();
                    arr.Add(item);
                    item.SetDictValue("name", m.Value.displayName);
                    item.SetDictValue("addr", m.Value.funcaddr.ToString("X04"));
                    Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array();
                    item.SetDictValue("map", infos);
                    foreach (var c in m.Value.body_Codes)
                    {
                        if (c.Value.debugcode != null)
                        {
                            var debugcode = c.Value.debugcode.ToLower();
                            if (debugcode.Contains(".cs"))
                            {
                                srcfile = debugcode;
                                infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString());
                            }
                        }
                    }
                }
                mapInfo = arr.ToString();
            }


            var hash   = abi["hash"].AsString();
            var abistr = abi.ToString();

            System.IO.File.WriteAllBytes(hash + ".avm", avm);
            System.IO.File.WriteAllText(hash + ".map.json", mapInfo);
            System.IO.File.WriteAllText(hash + ".abi.json", abistr);
            if (srcfile != null)
            {
                var targetfilename = hash + ".cs";
                System.IO.File.Delete(targetfilename);
                System.IO.File.Copy(srcfile, targetfilename);
            }
        }
コード例 #7
0
        public static JObject GenerateAbi(NeoModule module, Dictionary <int, int> addrConvTable)
        {
            var outjson = new JObject();

            //functions
            var methods = new JArray();

            outjson["methods"] = methods;

            HashSet <string> names = new HashSet <string>();

            foreach (var function in module.mapMethods.OrderBy(u => u.Value.funcaddr))
            {
                var mm = function.Value;
                if (mm.inSmartContract == false)
                {
                    continue;
                }
                if (mm.isPublic == false)
                {
                    continue;
                }

                if (!names.Add(function.Value.displayName))
                {
                    throw new Exception("abi not allow same name functions");
                }
                var funcsign = new JObject();
                methods.Add(funcsign);
                funcsign["name"]   = function.Value.displayName;
                funcsign["offset"] = addrConvTable?[function.Value.funcaddr] ?? function.Value.funcaddr;
                funcsign["safe"]   = function.Value.method?.method.CustomAttributes.Any(u => u.AttributeType.FullName == "Neo.SmartContract.Framework.SafeAttribute") == true;
                JArray funcparams = new JArray();
                funcsign["parameters"] = funcparams;
                if (mm.paramtypes != null)
                {
                    foreach (var v in mm.paramtypes)
                    {
                        var item = new JObject();
                        funcparams.Add(item);

                        item["name"] = v.name;
                        item["type"] = ConvType(v.type);
                    }
                }

                var rtype = ConvType(mm.returntype);
                if (rtype.StartsWith("Unknown:"))
                {
                    throw new Exception($"Unknown return type '{mm.returntype}' for method '{function.Value.name}'");
                }

                funcsign["returntype"] = rtype;
            }

            //events
            var eventsigns = new JArray();

            outjson["events"] = eventsigns;
            foreach (var events in module.mapEvents)
            {
                var mm       = events.Value;
                var funcsign = new JObject();
                eventsigns.Add(funcsign);

                funcsign["name"] = events.Value.displayName;
                JArray funcparams = new JArray();
                funcsign["parameters"] = funcparams;
                if (mm.paramtypes != null)
                {
                    foreach (var v in mm.paramtypes)
                    {
                        var item = new JObject();
                        funcparams.Add(item);

                        item["name"] = v.name;
                        item["type"] = ConvType(v.type);
                    }
                }
                //event do not have returntype in nep3
                //var rtype = ConvType(mm.returntype);
                //funcsign["returntype", rtype);
            }

            return(outjson);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: uvmetal/neo-devpack-dotnet
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static void Main(string[] args)
        {
            //set console
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.MSIL console app v" + Assembly.GetEntryAssembly().GetName().Version);

            if (args.Length == 0)
            {
                log.Log("need one param for DLL filename.");
                log.Log("Example:neon abc.dll");
                return;
            }

            string filename = args[0];
            string onlyname = Path.GetFileNameWithoutExtension(filename);
            string filepdb  = onlyname + ".pdb";
            var    path     = Path.GetDirectoryName(filename);

            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    Directory.SetCurrentDirectory(path);
                }
                catch
                {
                    log.Log("Could not find path: " + path);
                    Environment.Exit(-1);
                    return;
                }
            }

            ILModule mod = new ILModule(log);
            Stream   fs;
            Stream   fspdb = null;

            //open file
            try
            {
                fs = File.OpenRead(filename);

                if (File.Exists(filepdb))
                {
                    fspdb = File.OpenRead(filepdb);
                }
            }
            catch (Exception err)
            {
                log.Log("Open File Error:" + err.ToString());
                return;
            }
            //load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return;
            }
            byte[] bytes;
            bool   bSucc;
            string jsonstr = null;

            //convert and build
            try
            {
                var        conv   = new ModuleConverter(log);
                ConvOption option = new ConvOption();
                NeoModule  am     = conv.Convert(mod, option);
                bytes = am.Build();
                log.Log("convert succ");

                try
                {
                    var           outjson = vmtool.FuncExport.Export(am, bytes);
                    StringBuilder sb      = new StringBuilder();
                    outjson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return;
            }
            //write bytes
            try
            {
                string bytesname = onlyname + ".avm";

                File.Delete(bytesname);
                File.WriteAllBytes(bytesname, bytes);
                log.Log("write:" + bytesname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }
            try
            {
                string abiname = onlyname + ".abi.json";

                File.Delete(abiname);
                File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return;
            }
            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }

            if (bSucc)
            {
                log.Log("SUCC");
            }
        }
コード例 #9
0
        public static JObject Export(NeoModule module, byte[] script, Dictionary <int, int> addrConvTable)
        {
            var outjson = new JObject();

            //hash
            outjson["hash"] = ComputeHash(script);

            //functions
            var methods = new JArray();

            outjson["methods"] = methods;

            HashSet <string> names = new HashSet <string>();

            foreach (var function in module.mapMethods)
            {
                var mm = function.Value;
                if (mm.inSmartContract == false)
                {
                    continue;
                }
                if (mm.isPublic == false)
                {
                    continue;
                }

                if (!names.Add(function.Value.displayName))
                {
                    throw new Exception("abi not allow same name functions");
                }
                var funcsign = new JObject();
                methods.Add(funcsign);
                funcsign["name"] = function.Value.displayName;
                var offset = addrConvTable?[function.Value.funcaddr] ?? function.Value.funcaddr;
                funcsign["offset"] = offset.ToString();
                JArray funcparams = new JArray();
                funcsign["parameters"] = funcparams;
                if (mm.paramtypes != null)
                {
                    foreach (var v in mm.paramtypes)
                    {
                        var item = new JObject();
                        funcparams.Add(item);

                        item["name"] = v.name;
                        item["type"] = ConvType(v.type);
                    }
                }

                var rtype = ConvType(mm.returntype);
                if (rtype.StartsWith("Unknown:"))
                {
                    throw new Exception($"Unknown return type '{mm.returntype}' for method '{function.Value.name}'");
                }

                funcsign["returntype"] = rtype;
            }

            //events
            var eventsigns = new JArray();

            outjson["events"] = eventsigns;
            foreach (var events in module.mapEvents)
            {
                var mm       = events.Value;
                var funcsign = new JObject();
                eventsigns.Add(funcsign);

                funcsign["name"] = events.Value.displayName;
                JArray funcparams = new JArray();
                funcsign["parameters"] = funcparams;
                if (mm.paramtypes != null)
                {
                    foreach (var v in mm.paramtypes)
                    {
                        var item = new JObject();
                        funcparams.Add(item);

                        item["name"] = v.name;
                        item["type"] = ConvType(v.type);
                    }
                }
                //event do not have returntype in nep3
                //var rtype = ConvType(mm.returntype);
                //funcsign["returntype", rtype);
            }

            return(outjson);
        }
コード例 #10
0
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static void Main(string[] args)
        {
            //set console
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.JVM console app v" + Assembly.GetEntryAssembly().GetName().Version);
            if (args.Length == 0)
            {
                log.Log("need one param for .class filename.");
                return;
            }
            string filename = args[0];
            string onlyname = System.IO.Path.GetFileNameWithoutExtension(filename);
            //javaloader.ClassFile classFile = null;
            JavaModule module = new JavaModule();


            byte[] bytes = null;
            bool   bSucc = false;

            //convert and build
            try
            {
                var path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                path = System.IO.Path.GetDirectoryName(path);
                module.LoadJar(System.IO.Path.Combine(path, "org.neo.smartcontract.framework.jar"));
                module.LoadClass(filename);
                var conv = new ModuleConverter(log);

                NeoModule am = conv.Convert(module);
                bytes = am.Build();
                log.Log("convert succ");
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return;
            }
            //write bytes
            try
            {
                string bytesname = onlyname + ".avm";

                System.IO.File.Delete(bytesname);
                System.IO.File.WriteAllBytes(bytesname, bytes);
                log.Log("write:" + bytesname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }


            if (bSucc)
            {
                log.Log("SUCC");
            }
        }
コード例 #11
0
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static bool Execute(string filename, string filepdb, ILogger log)
        {
            string onlyname = System.IO.Path.GetFileNameWithoutExtension(filename);

            ILModule mod = new ILModule();

            System.IO.Stream fs    = null;
            System.IO.Stream fspdb = null;

            //open file
            try
            {
                fs = System.IO.File.OpenRead(filename);

                if (System.IO.File.Exists(filepdb))
                {
                    fspdb = System.IO.File.OpenRead(filepdb);
                }
            }
            catch (Exception err)
            {
                log.Log("Open File Error:" + err.ToString());
                return(false);
            }
            //load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return(false);
            }
            byte[] bytes       = null;
            bool   bSucc       = false;
            string jsonstr     = null;
            string debugmapstr = null;

            //convert and build
            try
            {
                var conv = new ModuleConverter(log);

                NeoModule am = conv.Convert(mod);
                bytes = am.Build();
                log.Log("convert succ");


                try
                {
                    var           outjson = vmtool.FuncExport.Export(am, bytes);
                    StringBuilder sb      = new StringBuilder();
                    outjson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                }

                try
                {
                    var           outjson = DebugInfo.ExportDebugInfo(onlyname, am);
                    StringBuilder sb      = new StringBuilder();
                    outjson.ConvertToStringWithFormat(sb, 0);
                    debugmapstr = sb.ToString();
                    log.Log("gen debug map succ");
                }
                catch (Exception err)
                {
                    log.Log("gen debug map Error:" + err.ToString());
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return(false);
            }
            //write bytes
            try
            {
                string bytesname = onlyname + ".avm";

                System.IO.File.Delete(bytesname);
                System.IO.File.WriteAllBytes(bytesname, bytes);
                log.Log("write:" + bytesname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return(false);
            }
            try
            {
                string abiname = onlyname + ".abi.json";

                System.IO.File.Delete(abiname);
                System.IO.File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return(false);
            }
            try
            {
                string debugname = onlyname + ".debug.json";

                System.IO.File.Delete(debugname);
                System.IO.File.WriteAllText(debugname, debugmapstr);
                log.Log("write:" + debugname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return(false);
            }
            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }

            return(bSucc);
        }
コード例 #12
0
        public static int Compile(Options options)
        {
            // Set console
            Console.OutputEncoding = Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.MSIL console app v" + Assembly.GetEntryAssembly().GetName().Version);

            var fileInfo = new FileInfo(options.File);

            // Set current directory
            if (!fileInfo.Exists)
            {
                log.Log("Could not find file " + fileInfo.FullName);
                return(-1);
            }

            Stream fs;
            Stream fspdb;
            var    onlyname = Path.GetFileNameWithoutExtension(fileInfo.Name);
            var    path     = fileInfo.Directory.FullName;

            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    Directory.SetCurrentDirectory(path);
                }
                catch
                {
                    log.Log("Could not find path: " + path);
                    return(-1);
                }
            }

            switch (fileInfo.Extension.ToLowerInvariant())
            {
            case ".csproj":
            {
                // Compile csproj file

                log.Log("Compiling from csproj project");
                var output = Compiler.CompileCSProj(fileInfo.FullName);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".vbproj":
            {
                // Compile vbproj file

                log.Log("Compiling from vbproj project");
                var output = Compiler.CompileVBProj(fileInfo.FullName);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".cs":
            {
                // Compile C# files

                log.Log("Compiling from c# source");
                var output = Compiler.CompileCSFiles(new string[] { fileInfo.FullName }, new string[0]);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".vb":
            {
                // Compile VB files

                log.Log("Compiling from VB source");
                var output = Compiler.CompileVBFiles(new string[] { fileInfo.FullName }, new string[0]);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".dll":
            {
                string filepdb = onlyname + ".pdb";

                // Open file
                try
                {
                    fs = fileInfo.OpenRead();

                    if (File.Exists(filepdb))
                    {
                        fspdb = File.OpenRead(filepdb);
                    }
                    else
                    {
                        fspdb = null;
                    }
                }
                catch (Exception err)
                {
                    log.Log("Open File Error:" + err.ToString());
                    return(-1);
                }
                break;
            }

            default:
            {
                log.Log("File format not supported by neon: " + path);
                return(-1);
            }
            }

            ILModule mod = new ILModule(log);

            // Load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return(-1);
            }
            byte[]    bytes;
            int       bSucc   = 0;
            string    jsonstr = null;
            NeoModule module  = null;

            // Convert and build
            try
            {
                var        conv   = new ModuleConverter(log);
                ConvOption option = new ConvOption();
                module = conv.Convert(mod, option);
                bytes  = module.Build();
                log.Log("convert succ");
                Dictionary <int, int> addrConvTable = null;
                if (options.Optimize)
                {
                    module.ConvertFuncAddr();
                    List <int> entryPoints = new List <int>();

                    foreach (var func in module.mapMethods)
                    {
                        int srcaddr = func.Value.funcaddr;
                        if (entryPoints.Contains(srcaddr) == false)
                        {
                            entryPoints.Add(srcaddr);
                        }
                    }
                    var optimize = NefOptimizeTool.Optimize(bytes, entryPoints.ToArray(), out addrConvTable);
                    log.Log("optimization succ " + (((bytes.Length / (optimize.Length + 0.0)) * 100.0) - 100).ToString("0.00 '%'"));
                    bytes = optimize;
                }

                try
                {
                    var           outjson = vmtool.FuncExport.Export(module, bytes, addrConvTable);
                    StringBuilder sb      = new StringBuilder();
                    outjson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                    return(-1);
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return(-1);
            }

            // Write bytes

            try
            {
                string bytesname = onlyname + ".nef";
                var    nef       = new NefFile
                {
                    Compiler = "neon",
                    Version  = Version.Parse(((AssemblyFileVersionAttribute)Assembly.GetExecutingAssembly()
                                              .GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version),
                    Script     = bytes,
                    ScriptHash = bytes.ToScriptHash()
                };
                nef.CheckSum = NefFile.ComputeChecksum(nef);

                File.Delete(bytesname);
                using (var stream = File.OpenWrite(bytesname))
                    using (var writer = new BinaryWriter(stream))
                    {
                        nef.Serialize(writer);
                    }
                log.Log("write:" + bytesname);
                bSucc++;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return(-1);
            }

            try
            {
                string abiname = onlyname + ".abi.json";

                File.Delete(abiname);
                File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc++;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return(-1);
            }

            try
            {
                var features = module == null ? ContractFeatures.NoProperty : module.attributes
                               .Where(u => u.AttributeType.Name == "FeaturesAttribute")
                               .Select(u => (ContractFeatures)u.ConstructorArguments.FirstOrDefault().Value)
                               .FirstOrDefault();

                var extraAttributes = module == null ? new List <Mono.Collections.Generic.Collection <CustomAttributeArgument> >() : module.attributes.Where(u => u.AttributeType.Name == "ManifestExtraAttribute").Select(attribute => attribute.ConstructorArguments).ToList();

                var extra   = BuildExtraAttributes(extraAttributes);
                var storage = features.HasFlag(ContractFeatures.HasStorage).ToString().ToLowerInvariant();
                var payable = features.HasFlag(ContractFeatures.Payable).ToString().ToLowerInvariant();

                string manifest    = onlyname + ".manifest.json";
                string defManifest =
                    @"{""groups"":[],""features"":{""storage"":" + storage + @",""payable"":" + payable + @"},""abi"":" +
                    jsonstr +
                    @",""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[],""extra"":" + extra + "}";

                File.Delete(manifest);
                File.WriteAllText(manifest, defManifest);
                log.Log("write:" + manifest);
                bSucc++;
            }
            catch (Exception err)
            {
                log.Log("Write manifest Error:" + err.ToString());
                return(-1);
            }

            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }

            if (bSucc == 3)
            {
                log.Log("SUCC");
                return(0);
            }

            return(-1);
        }
コード例 #13
0
        public static MyJson.JsonNode_Object ExportDebugInfo(string avmName, NeoModule module)
        {
            var outjson = new MyJson.JsonNode_Object();

            var           debugMap          = new List <DebugMapEntry>();
            DebugMapEntry currentDebugEntry = null;

            var fileMap = new Dictionary <string, int>();

            List <byte> bytes = new List <byte>();

            foreach (var c in module.total_Codes.Values)
            {
                if (c.debugcode != null && c.debugline > 0 && c.debugline < 2000)
                {
                    currentDebugEntry          = new DebugMapEntry();
                    currentDebugEntry.startOfs = debugMap.Count > 0 ? bytes.Count : 0;
                    currentDebugEntry.endOfs   = currentDebugEntry.startOfs;
                    currentDebugEntry.url      = c.debugcode;
                    currentDebugEntry.line     = c.debugline;

                    if (!fileMap.ContainsKey(c.debugcode))
                    {
                        fileMap[c.debugcode] = fileMap.Count + 1;
                    }

                    debugMap.Add(currentDebugEntry);
                }
                else
                if (currentDebugEntry != null)
                {
                    currentDebugEntry.endOfs = bytes.Count;
                }
                bytes.Add((byte)c.code);
                if (c.bytes != null)
                {
                    for (var i = 0; i < c.bytes.Length; i++)
                    {
                        bytes.Add(c.bytes[i]);
                    }
                }
            }

            var hash = CalculateMD5(bytes.ToArray());

            string compilerName = System.AppDomain.CurrentDomain.FriendlyName.ToLowerInvariant();
            var    version      = Assembly.GetEntryAssembly().GetName().Version.ToString();

            var avmInfo = new MyJson.JsonNode_Object();

            avmInfo.Add("name", new MyJson.JsonNode_ValueString(avmName));
            avmInfo.Add("hash", new MyJson.JsonNode_ValueString(hash));

            var compilerInfo = new MyJson.JsonNode_Object();

            compilerInfo.Add("name", new MyJson.JsonNode_ValueString(compilerName));
            compilerInfo.Add("version", new MyJson.JsonNode_ValueString(version));

            var fileInfo = new MyJson.JsonNode_Array();

            foreach (var entry in fileMap)
            {
                var fileEntry = new MyJson.JsonNode_Object();
                fileEntry.Add("id", new MyJson.JsonNode_ValueNumber(entry.Value));
                fileEntry.Add("url", new MyJson.JsonNode_ValueString(entry.Key));
                fileInfo.AddArrayValue(fileEntry);
            }

            var mapInfo = new MyJson.JsonNode_Array();

            foreach (var entry in debugMap)
            {
                if (!fileMap.ContainsKey(entry.url))
                {
                    continue;
                }

                var fileID = fileMap[entry.url];

                var mapEntry = new MyJson.JsonNode_Object();
                mapEntry.Add("start", new MyJson.JsonNode_ValueNumber(entry.startOfs));
                mapEntry.Add("end", new MyJson.JsonNode_ValueNumber(entry.endOfs));
                mapEntry.Add("file", new MyJson.JsonNode_ValueNumber(fileID));
                mapEntry.Add("line", new MyJson.JsonNode_ValueNumber(entry.line));
                mapInfo.AddArrayValue(mapEntry);
            }

            outjson["avm"]      = avmInfo;
            outjson["compiler"] = compilerInfo;
            outjson["files"]    = fileInfo;
            outjson["map"]      = mapInfo;

            return(outjson);
        }
コード例 #14
0
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static void Main(string[] args)
        {
            // Set console
            Console.OutputEncoding = Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.MSIL console app v" + Assembly.GetEntryAssembly().GetName().Version);

            // Check argmuents
            if (args.Length == 0)
            {
                log.Log("You need a parameter to specify the DLL or the file name of the project.");
                log.Log("Examples: ");
                log.Log("  neon mySmartContract.dll");
                log.Log("  neon mySmartContract.csproj");

                Environment.Exit(-1);
                return;
            }

            var fileInfo = new FileInfo(args[0]);

            // Set current directory
            if (!fileInfo.Exists)
            {
                log.Log("Could not find file " + fileInfo.FullName);
                Environment.Exit(-1);
                return;
            }

            Stream fs;
            Stream fspdb;
            var    onlyname = Path.GetFileNameWithoutExtension(fileInfo.Name);
            var    path     = fileInfo.Directory.FullName;

            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    Directory.SetCurrentDirectory(path);
                }
                catch
                {
                    log.Log("Could not find path: " + path);
                    Environment.Exit(-1);
                    return;
                }
            }

            switch (fileInfo.Extension.ToLowerInvariant())
            {
            case ".csproj":
            {
                // Compile csproj file

                log.Log("Compiling from csproj project");
                var output = Compiler.CompileCSProj(fileInfo.FullName);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".vbproj":
            {
                // Compile vbproj file

                log.Log("Compiling from vbproj project");
                var output = Compiler.CompileVBProj(fileInfo.FullName);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".cs":
            {
                // Compile C# files

                log.Log("Compiling from c# source");
                var output = Compiler.CompileCSFile(new string[] { fileInfo.FullName }, new string[0]);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".vb":
            {
                // Compile VB files

                log.Log("Compiling from VB source");
                var output = Compiler.CompileVBFile(new string[] { fileInfo.FullName }, new string[0]);
                fs    = new MemoryStream(output.Dll);
                fspdb = new MemoryStream(output.Pdb);
                break;
            }

            case ".dll":
            {
                string filepdb = onlyname + ".pdb";

                // Open file
                try
                {
                    fs = fileInfo.OpenRead();

                    if (File.Exists(filepdb))
                    {
                        fspdb = File.OpenRead(filepdb);
                    }
                    else
                    {
                        fspdb = null;
                    }
                }
                catch (Exception err)
                {
                    log.Log("Open File Error:" + err.ToString());
                    return;
                }
                break;
            }

            default:
            {
                log.Log("File format not supported by neon: " + path);
                Environment.Exit(-1);
                return;
            }
            }

            ILModule mod = new ILModule(log);

            // Load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return;
            }
            byte[]    bytes;
            int       bSucc   = 0;
            string    jsonstr = null;
            NeoModule module  = null;

            // Convert and build
            try
            {
                var        conv   = new ModuleConverter(log);
                ConvOption option = new ConvOption();
                module = conv.Convert(mod, option);
                bytes  = module.Build();
                log.Log("convert succ");

                try
                {
                    var           outjson = vmtool.FuncExport.Export(module, bytes);
                    StringBuilder sb      = new StringBuilder();
                    outjson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return;
            }

            // Write bytes

            try
            {
                string bytesname = onlyname + ".nef";
                var    nef       = new NefFile
                {
                    Compiler = "neon",
                    Version  = Version.Parse(((AssemblyFileVersionAttribute)Assembly.GetExecutingAssembly()
                                              .GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version),
                    Script     = bytes,
                    ScriptHash = bytes.ToScriptHash()
                };
                nef.CheckSum = NefFile.ComputeChecksum(nef);

                File.Delete(bytesname);
                using (var stream = File.OpenWrite(bytesname))
                    using (var writer = new BinaryWriter(stream))
                    {
                        nef.Serialize(writer);
                    }
                log.Log("write:" + bytesname);
                bSucc++;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }

            try
            {
                string abiname = onlyname + ".abi.json";

                File.Delete(abiname);
                File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc++;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return;
            }

            try
            {
                var features = module == null ? ContractFeatures.NoProperty : module.attributes
                               .Where(u => u.AttributeType.Name == "FeaturesAttribute")
                               .Select(u => (ContractFeatures)u.ConstructorArguments.FirstOrDefault().Value)
                               .FirstOrDefault();

                var storage = features.HasFlag(ContractFeatures.HasStorage).ToString().ToLowerInvariant();
                var payable = features.HasFlag(ContractFeatures.Payable).ToString().ToLowerInvariant();

                string manifest    = onlyname + ".manifest.json";
                string defManifest =
                    @"{""groups"":[],""features"":{""storage"":" + storage + @",""payable"":" + payable + @"},""abi"":" +
                    jsonstr +
                    @",""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[]}";

                File.Delete(manifest);
                File.WriteAllText(manifest, defManifest);
                log.Log("write:" + manifest);
                bSucc++;
            }
            catch (Exception err)
            {
                log.Log("Write manifest Error:" + err.ToString());
                return;
            }

            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }

            if (bSucc == 3)
            {
                log.Log("SUCC");
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: mwherman2000/neondebug
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static void Main(string[] args)
        {
            //set console
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.MSIL(Debug) console app v" + Assembly.GetEntryAssembly().GetName().Version);
            if (args.Length == 0)
            {
                log.Log("need one param for DLL filename.");
                return;
            }
            string filename = args[0];
            string onlyname = System.IO.Path.GetFileNameWithoutExtension(filename);
            string filepdb  = onlyname + ".pdb";

            ILModule mod = new ILModule();

            System.IO.Stream fs    = null;
            System.IO.Stream fspdb = null;

            //open file
            try
            {
                fs = System.IO.File.OpenRead(filename);

                if (System.IO.File.Exists(filepdb))
                {
                    fspdb = System.IO.File.OpenRead(filepdb);
                }
            }
            catch (Exception err)
            {
                log.Log("Open File Error:" + err.ToString());
                return;
            }
            //load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return;
            }
            byte[] bytes   = null;
            bool   bSucc   = false;
            string jsonstr = null;
            //convert and build
            NeoModule neoM = null;

            MyJson.JsonNode_Object abijson = null;
            try
            {
                var conv = new ModuleConverter(log);

                NeoModule am = conv.Convert(mod);
                neoM  = am;
                bytes = am.Build();
                log.Log("convert succ");


                try
                {
                    abijson = vmtool.FuncExport.Export(am, bytes);
                    StringBuilder sb = new StringBuilder();
                    abijson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return;
            }
            //write bytes
            try
            {
                string bytesname = onlyname + ".avm";

                System.IO.File.Delete(bytesname);
                System.IO.File.WriteAllBytes(bytesname, bytes);
                log.Log("write:" + bytesname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }
            try
            {
                string abiname = onlyname + ".abi.json";

                System.IO.File.Delete(abiname);
                System.IO.File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return;
            }
            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }
            if (bSucc)
            {
                _DebugOutput.DebugOutput(neoM, bytes, abijson);
                log.Log("SUCC");
            }
        }
コード例 #16
0
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static void Main(string[] args)
        {
            string outpath = "C:\\NeoCli\\SmartContracts";

            //set console
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.MSIL<Debug> console app v" + Assembly.GetEntryAssembly().GetName().Version);

            bool bCompatible = true;
            //bool bCompatible = false;
            string filename = null;

            for (var i = 0; i < args.Length; i++)
            {
                if (args[i][0] == '-')
                {
                    if (args[i] == "--uncompatible")
                    {
                        bCompatible = false;
                    }

                    //other option
                }
                else
                {
                    filename = args[i];
                }
            }

            if (filename == null)
            {
                log.Log("NEL Forked");
                log.Log("need one param for DLL filename.");
                log.Log("[--uncompatible] able nep8 function");
                log.Log("Example:neon abc.dll --uncompatible");
                return;
            }
            if (bCompatible)
            {
                log.Log("use --uncompatible able nep8");
            }
            string onlyname = System.IO.Path.GetFileNameWithoutExtension(filename);
            string filepdb  = onlyname + ".pdb";
            var    path     = Path.GetDirectoryName(filename);

            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    Directory.SetCurrentDirectory(path);
                }
                catch
                {
                    log.Log("Could not find path: " + path);
                    Environment.Exit(-1);
                }
            }

            ILModule mod = new ILModule();

            System.IO.Stream fs    = null;
            System.IO.Stream fspdb = null;

            //open file
            try
            {
                fs = System.IO.File.OpenRead(filename);

                if (System.IO.File.Exists(filepdb))
                {
                    fspdb = System.IO.File.OpenRead(filepdb);
                }
            }
            catch (Exception err)
            {
                log.Log("Open File Error:" + err.ToString());
                return;
            }
            //load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return;
            }
            byte[]    bytes   = null;
            bool      bSucc   = false;
            string    jsonstr = null;
            NeoModule neoM    = null;

            MyJson.JsonNode_Object abijson = null;
            //convert and build
            try
            {
                var        conv   = new ModuleConverter(log);
                ConvOption option = new ConvOption();
                option.useNep8 = !bCompatible;
                NeoModule am = conv.Convert(mod, option);
                neoM  = am;
                bytes = am.Build();
                log.Log("convert succ");


                try
                {
                    abijson = vmtool.FuncExport.Export(am, bytes);
                    StringBuilder sb = new StringBuilder();
                    abijson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return;
            }
            //write bytes
            try
            {
                string bytesname = onlyname + ".avm";

                System.IO.File.Delete(bytesname);
                System.IO.File.WriteAllBytes(bytesname, bytes);
                log.Log("write:" + bytesname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }
            try
            {
                string abiname = onlyname + ".abi.json";

                System.IO.File.Delete(abiname);
                System.IO.File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return;
            }
            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }

            if (bSucc)
            {
                _DebugOutput.DebugOutput(outpath, neoM, bytes, abijson);
                log.Log("SUCC");
            }
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: ProDog/zoro.one
        //Console.WriteLine("helo ha:"+args[0]); //普通输出
        //Console.WriteLine("<WARN> 这是一个严重的问题。");//警告输出,黄字
        //Console.WriteLine("<WARN|aaaa.cs(1)> 这是ee一个严重的问题。");//警告输出,带文件名行号
        //Console.WriteLine("<ERR> 这是一个严重的问题。");//错误输出,红字
        //Console.WriteLine("<ERR|aaaa.cs> 这是ee一个严重的问题。");//错误输出,带文件名
        //Console.WriteLine("SUCC");//输出这个表示编译成功
        //控制台输出约定了特别的语法
        public static void Main(string[] args)
        {
            var tree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText("class A{public  int aaa(){return 3;}}");

            var op   = new CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind.DynamicallyLinkedLibrary);
            var ref1 = MetadataReference.CreateFromFile("needlib\\mscorlib.dll");
            var comp = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create("aaa.dll", new[] { tree },
                                                                              new[] { ref1 }, op);

            var fs     = new System.IO.MemoryStream();
            var fspdb  = new System.IO.MemoryStream();
            var result = comp.Emit(fs, fspdb);

            fs.Seek(0, System.IO.SeekOrigin.Begin);
            fspdb.Seek(0, System.IO.SeekOrigin.Begin);
            //set console
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var log = new DefLogger();

            log.Log("Neo.Compiler.MSIL(Debug) console app v" + Assembly.GetEntryAssembly().GetName().Version);
            if (args.Length == 0)
            {
                log.Log("need one param for DLL filename.");
                return;
            }
            string filename = args[0];
            string onlyname = System.IO.Path.GetFileNameWithoutExtension(filename);
            //string filepdb = onlyname + ".pdb";

            ILModule mod = new ILModule();

            //System.IO.Stream fs = null;
            //System.IO.Stream fspdb = null;

            //open file
            //try
            //{
            //    fs = System.IO.File.OpenRead(filename);

            //    if (System.IO.File.Exists(filepdb))
            //    {
            //        fspdb = System.IO.File.OpenRead(filepdb);
            //    }

            //}
            //catch (Exception err)
            //{
            //    log.Log("Open File Error:" + err.ToString());
            //    return;
            //}
            //load module
            try
            {
                mod.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                return;
            }
            byte[] bytes   = null;
            bool   bSucc   = false;
            string jsonstr = null;
            //convert and build
            NeoModule neoM = null;

            MyJson.JsonNode_Object abijson = null;
            try
            {
                var conv = new ModuleConverter(log);

                NeoModule am = conv.Convert(mod);
                neoM  = am;
                bytes = am.Build();
                log.Log("convert succ");


                try
                {
                    abijson = vmtool.FuncExport.Export(am, bytes);
                    StringBuilder sb = new StringBuilder();
                    abijson.ConvertToStringWithFormat(sb, 0);
                    jsonstr = sb.ToString();
                    log.Log("gen abi succ");
                }
                catch (Exception err)
                {
                    log.Log("gen abi Error:" + err.ToString());
                }
            }
            catch (Exception err)
            {
                log.Log("Convert Error:" + err.ToString());
                return;
            }
            //write bytes
            try
            {
                string bytesname = onlyname + ".avm";

                System.IO.File.Delete(bytesname);
                System.IO.File.WriteAllBytes(bytesname, bytes);
                log.Log("write:" + bytesname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }
            try
            {
                string abiname = onlyname + ".abi.json";

                System.IO.File.Delete(abiname);
                System.IO.File.WriteAllText(abiname, jsonstr);
                log.Log("write:" + abiname);
                bSucc = true;
            }
            catch (Exception err)
            {
                log.Log("Write abi Error:" + err.ToString());
                return;
            }
            try
            {
                fs.Dispose();
                if (fspdb != null)
                {
                    fspdb.Dispose();
                }
            }
            catch
            {
            }
            if (bSucc)
            {
                _DebugOutput.DebugOutput(neoM, bytes, abijson);
                log.Log("SUCC");
            }
        }