Exemplo n.º 1
0
        void InitPrerequisites()
        {
            AppAssembly.CustomData().SWF = Swf;

            AssemblyIndex.Setup(AppAssembly);

            LinkRsls();
        }
Exemplo n.º 2
0
        public static bool Run(IAssembly assembly)
        {
            var data = assembly.CustomData();

            if ((data.Flags & InternalAssembyFlags.PassedLinker) != 0)
            {
                return((data.Flags & InternalAssembyFlags.HasAbcImports) != 0);
            }

            var linker = data.Linker ?? new Linker(assembly);

            return(linker.Run());
        }
Exemplo n.º 3
0
        public static AbcInstance FindInstance(IAssembly assembly, string name)
        {
            Setup(assembly);

            var index = assembly.CustomData().Index;

            if (index != null)
            {
                return(index.FindInstanceCore(name));
            }

            return(null);
        }
Exemplo n.º 4
0
        private void ImportMixins(IAssembly assembly)
        {
            var swc = assembly.CustomData().SWC;

            if (swc == null)
            {
                return;
            }

            foreach (var mixin in swc.AbcCache.Mixins)
            {
                _compiler.AppFrame.ImportInstance(mixin);
            }
        }
Exemplo n.º 5
0
        public static void Setup(IAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            var data = assembly.CustomData();

            if (data.Index != null)
            {
                return;
            }

            data.Index = new AssemblyIndex(assembly);
        }
Exemplo n.º 6
0
        private void Link(IAssembly assembly)
        {
            var data = assembly.CustomData();

            data.Index = this;

            if (data.Linker == null)
            {
                var linker = new Linker(assembly);
                linker.TypeLinked += OnTypeLinked;
                linker.Run();
            }
            else
            {
                data.Linker.TypeLinked += OnTypeLinked;
            }

            if (assembly.Loader == null)
            {
                RegisterTypes(assembly.Types);
            }
        }
Exemplo n.º 7
0
        public bool Run()
        {
            //To avoid multiple calls of this routine
            var data = Assembly.CustomData();

            if ((data.Flags & InternalAssembyFlags.PassedLinker) != 0)
            {
                return((data.Flags & InternalAssembyFlags.HasAbcImports) != 0);
            }

            data.Flags |= InternalAssembyFlags.PassedLinker;

#if PERF
            int start = Environment.TickCount;
#endif
            LinkTypes();

#if PERF
            Console.WriteLine("LinkSwc: {0}", Environment.TickCount - start);
#endif

            return((data.Flags & InternalAssembyFlags.HasAbcImports) != 0);
        }
Exemplo n.º 8
0
        public Linker(IAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            var data = assembly.CustomData();

            if (data.Linker != null)
            {
                throw new InvalidOperationException();
            }

            data.Linker = this;

            Assembly = assembly;

            // we should always listen TypeLoaded event to fill AssemblyLinked
            if (Assembly.Loader != null)
            {
                Assembly.Loader.TypeLoaded += OnTypeLoaded;
            }

            var resource = Assembly.MainModule.Resources.FirstOrDefault(
                x => x.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase) ||
                x.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase));

            if (resource != null)
            {
                data.Flags |= InternalAssembyFlags.HasAbcImports;

                if (resource.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase))
                {
                    _abc = new AbcFile(resource.Data)
                    {
                        Assembly = Assembly
                    };
                    data.Abc = _abc;
                    _cache   = new AbcCache();
                    _cache.Add(_abc);
                }
                else if (resource.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase))
                {
                    string swcName = GetResFileName(resource.Name);

                    _swcDeps = LoadSwcDep(swcName);
                    _swc     = new SwcFile(resource.Data)
                    {
                        Assembly = Assembly,
                        Name     = swcName
                    };
                    _cache = _swc.AbcCache;

                    data.SWC = _swc;
                }
            }

            // create all linkers to subscribe on AssemblyLoader.TypeLoaded event before we start process
            assembly.ProcessReferences(true,
                                       asm =>
            {
                if (asm.CustomData().Linker == null)
                {
                    asm.CustomData().Linker = new Linker(asm);
                }
            });

            if (_swc != null)
            {
                _swc.ResolveDependencies(this, _swcDeps);
            }
        }
Exemplo n.º 9
0
        public AbcFile Generate(IAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

#if PERF
            int start = Environment.TickCount;
#endif

#if DEBUG
            DebugService.LogInfo("ABC Generator started");
            DebugService.LogSeparator();
#endif
            AppAssembly = assembly;

            AssemblyIndex.Setup(assembly);

            Abc = new AbcFile
            {
                AutoComplete = true,
                ReduceSize   = true,
                Generator    = this,
                SwfCompiler  = SwfCompiler,
                Assembly     = assembly
            };

            AppAssembly.CustomData().AddAbc(Abc);

            if (SwfCompiler != null)
            {
                SwfCompiler.AppFrame = Abc;
                if (SwfCompiler.IsSwc)
                {
                    Mode = AbcGenerationMode.Full;
                }
            }

            NewApi = new AbcCode(Abc);
            ObjectPrototypes.Init();

            BuildApp();

            if (SwfCompiler != null)
            {
                SwfCompiler.FinishApplication();
            }

            RootSprite.BuildTimeline();

            TypeBuilder.FinishTypes();

            _lateMethods.Finish();

            Scripts.BuildScripts();

            Scripts.FinishMainScript();

            // Finish ABC
            Abc.Finish();

#if PERF
            Console.WriteLine("ABC.MultinameCount: {0}", _abc.Multinames.Count);
            Console.WriteLine("AbcGenerator Elapsed Time: {0}", Environment.TickCount - start);
#endif

            // uncomment to list generated methods
//		    Console.WriteLine("Number of generated methods: {0}", Abc.Methods.Count(x => x.IsGenerated));
//		    Console.WriteLine("Number of anon methods: {0}", Abc.Methods.Count(x => x.IsGenerated && string.IsNullOrEmpty(x.FullName)));
//		    Abc.Methods
//		       .Where(x => x.IsGenerated && !string.IsNullOrEmpty(x.FullName))
//		       .OrderBy(x => x.FullName)
//		       .ToList()
//		       .ForEach(x => Console.WriteLine(x.FullName));

            // reset tags to allow recompilation
            if (!IsSwf && !IsSwc)
            {
                ResetMembersData();
            }

            return(Abc);
        }