Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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;
            }
        }