public void Build(Stream fs, Stream fspdb, bool optimizer)
        {
            this.IsBuild = false;
            this.Error   = null;

            var log = new DefLogger();

            this.modIL = new ILModule(log);
            try
            {
                modIL.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                this.Error = err;
                return;
            }

            converterIL = new ModuleConverter(log);
            ConvOption option = new ConvOption();

#if NDEBUG
            try
#endif
            {
                converterIL.Convert(modIL, option);
                finalNEF = converterIL.outModule.Build();
                if (optimizer)
                {
                    var   opbytes = NefOptimizeTool.Optimize(finalNEF);
                    float ratio   = (opbytes.Length * 100.0f) / (float)finalNEF.Length;
                    log.Log("optimization ratio = " + ratio + "%");
                    finalNEF = opbytes;
                }
                IsBuild = true;
            }
#if NDEBUG
            catch (Exception err)
            {
                this.Error = err;
                log.Log("Convert IL->ASM Error:" + err.ToString());
                return;
            }
#endif
            try
            {
                finialABI = vmtool.FuncExport.Export(converterIL.outModule, finalNEF);
            }
            catch
            {
            }
        }
        public void Build(Stream fs, Stream fspdb, bool optimizer)
        {
            this.IsBuild      = false;
            this.Error        = null;
            this.UseOptimizer = optimizer;

            var log = new DefLogger();

            this.modIL = new ILModule(log);
            try
            {
                modIL.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                this.Error = err;
                return;
            }

            converterIL = new ModuleConverter(log);
            Dictionary <int, int> addrConvTable = null;
            ConvOption            option        = new ConvOption();

#if NDEBUG
            try
#endif
            {
                converterIL.Convert(modIL, option);
                finalNEF = converterIL.outModule.Build();
                if (optimizer)
                {
                    var   opbytes = NefOptimizeTool.Optimize(finalNEF, out addrConvTable);
                    float ratio   = (opbytes.Length * 100.0f) / (float)finalNEF.Length;
                    log.Log("optimization ratio = " + ratio + "%");
                    finalNEF = opbytes;
                }
                IsBuild = true;
            }
#if NDEBUG
            catch (Exception err)
            {
                this.Error = err;
                log.Log("Convert IL->ASM Error:" + err.ToString());
                return;
            }
#endif
            try
            {
                finialABI = vmtool.FuncExport.Export(converterIL.outModule, finalNEF, addrConvTable);
            }
            catch (Exception e)
            {
                throw e;
            }

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

                var extraAttributes = converterIL.outModule == null ? new List <Mono.Collections.Generic.Collection <CustomAttributeArgument> >()
                    : converterIL.outModule.attributes.Where(u => u.AttributeType.Name == "ManifestExtraAttribute").Select(attribute => attribute.ConstructorArguments).ToList();
                var storage = features.HasFlag(ContractFeatures.HasStorage).ToString().ToLowerInvariant();
                var payable = features.HasFlag(ContractFeatures.Payable).ToString().ToLowerInvariant();

                finalManifest =
                    @"{""groups"":[],""features"":{""storage"":" + storage + @",""payable"":" + payable + @"},""abi"":" +
                    finialABI +
                    @",""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[],""extra"":[]" + "}";
            }
            catch
            {
            }
        }
Example #3
0
        public void Build(Stream fs, Stream fspdb, bool optimizer)
        {
            this.IsBuild      = false;
            this.Error        = null;
            this.UseOptimizer = optimizer;

            var log = new DefLogger();

            this.modIL = new ILModule(log);
            try
            {
                modIL.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                this.Error = err;
                return;
            }

            converterIL = new ModuleConverter(log);
            Dictionary <int, int> addrConvTable = null;
            ConvOption            option        = new ConvOption();

#if NDEBUG
            try
#endif
            {
                converterIL.Convert(modIL, option);
                finalNEFScript = converterIL.outModule.Build();
                if (optimizer)
                {
                    List <int> entryPoints = new List <int>();
                    foreach (var f in converterIL.outModule.mapMethods.Values)
                    {
                        if (!entryPoints.Contains(f.funcaddr))
                        {
                            entryPoints.Add(f.funcaddr);
                        }
                    }
                    var   opbytes = NefOptimizeTool.Optimize(finalNEFScript, entryPoints.ToArray(), out addrConvTable);
                    float ratio   = (opbytes.Length * 100.0f) / (float)finalNEFScript.Length;
                    log.Log("optimization ratio = " + ratio + "%");
                    finalNEFScript = opbytes;
                }
                IsBuild = true;
            }
#if NDEBUG
            catch (Exception err)
            {
                this.Error = err;
                log.Log("Convert IL->ASM Error:" + err.ToString());
                return;
            }
#endif
            try
            {
                finalABI = FuncExport.GenerateAbi(converterIL.outModule, addrConvTable);
            }
            catch (Exception err)
            {
                log.Log("Gen Abi Error:" + err.ToString());
                this.Error = err;
                return;
            }

            try
            {
                debugInfo = DebugExport.Export(converterIL.outModule, finalNEFScript, addrConvTable);
            }
            catch (Exception err)
            {
                log.Log("Gen debugInfo Error:" + err.ToString());
                this.Error = err;
                return;
            }

            try
            {
                finalManifest = FuncExport.GenerateManifest(finalABI, converterIL.outModule);
            }
            catch (Exception err)
            {
                log.Log("Gen Manifest Error:" + err.ToString());
                this.Error = err;
                return;
            }
        }
Example #4
0
        public void Build(Stream fs, Stream fspdb, bool optimizer)
        {
            this.IsBuild      = false;
            this.Error        = null;
            this.UseOptimizer = optimizer;

            var log = new DefLogger();

            this.modIL = new ILModule(log);
            try
            {
                modIL.LoadModule(fs, fspdb);
            }
            catch (Exception err)
            {
                log.Log("LoadModule Error:" + err.ToString());
                this.Error = err;
                return;
            }

            converterIL = new ModuleConverter(log);
            Dictionary <int, int> addrConvTable = null;
            ConvOption            option        = new ConvOption();

#if NDEBUG
            try
#endif
            {
                converterIL.Convert(modIL, option);
                finalNEFScript = converterIL.outModule.Build();
                if (optimizer)
                {
                    List <int> entryPoints = new List <int>();
                    foreach (var f in converterIL.outModule.mapMethods.Values)
                    {
                        if (!entryPoints.Contains(f.funcaddr))
                        {
                            entryPoints.Add(f.funcaddr);
                        }
                    }
                    var   opbytes = NefOptimizeTool.Optimize(finalNEFScript, entryPoints.ToArray(), out addrConvTable);
                    float ratio   = (opbytes.Length * 100.0f) / (float)finalNEFScript.Length;
                    log.Log("optimization ratio = " + ratio + "%");
                    finalNEFScript = opbytes;
                }
                IsBuild = true;
            }
#if NDEBUG
            catch (Exception err)
            {
                this.Error = err;
                log.Log("Convert IL->ASM Error:" + err.ToString());
                return;
            }
#endif
            try
            {
                finalABI = FuncExport.GenerateAbi(converterIL.outModule, addrConvTable);
            }
            catch (Exception err)
            {
                log.Log("Gen Abi Error:" + err.ToString());
                this.Error = err;
                return;
            }

            try
            {
                debugInfo = DebugExport.Export(converterIL.outModule, finalNEFScript, addrConvTable);
            }
            catch (Exception err)
            {
                log.Log("Gen debugInfo Error:" + err.ToString());
                this.Error = err;
                return;
            }

            try
            {
                finalManifest = FuncExport.GenerateManifest(finalABI, converterIL.outModule);
            }
            catch (Exception err)
            {
                log.Log("Gen Manifest Error:" + err.ToString());
                this.Error = err;
                return;
            }

            try
            {
                nefFile = new NefFile
                {
                    Compiler = "neon-" + Version.Parse(((AssemblyFileVersionAttribute)Assembly.GetAssembly(typeof(Program))
                                                        .GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version).ToString(),
                    Tokens = converterIL.methodTokens.ToArray(),
                    Script = finalNEFScript
                };
                nefFile.CheckSum = NefFile.ComputeChecksum(nefFile);
            }
            catch (Exception err)
            {
                log.Log("Write Bytes Error:" + err.ToString());
                return;
            }
        }