GenerateRegisterInternalCalls() public static method

public static GenerateRegisterInternalCalls ( AssemblyDefinition assemblies, TextWriter output ) : void
assemblies Mono.Cecil.AssemblyDefinition
output System.IO.TextWriter
return void
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
 {
     using (TextWriter textWriter = new StreamWriter(file))
     {
         string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
         AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
         bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
         ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
         if (buildTarget == BuildTarget.iOS)
         {
             textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
             textWriter.WriteLine("#include <stdio.h>");
         }
         textWriter.WriteLine(string.Empty);
         textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
         textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
         textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f)\\");
         textWriter.WriteLine("\t\tdo {\\");
         textWriter.WriteLine("\t\tif(f != NULL)\\");
         textWriter.WriteLine("\t\t\tmono_dl_register_symbol(#f, (void*)f);\\");
         textWriter.WriteLine("\t\telse\\");
         textWriter.WriteLine("\t\t\t::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
         textWriter.WriteLine("\t\t}while(0)");
         textWriter.WriteLine("#else");
         textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() ");
         textWriter.WriteLine("\t#if !defined(__arm64__)");
         textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
         textWriter.WriteLine("\t#else");
         textWriter.WriteLine("\t\t#define REGISTER_USER_FUNC(f)");
         textWriter.WriteLine("\t#endif");
         textWriter.WriteLine("#endif");
         textWriter.WriteLine("extern \"C\"\n{");
         textWriter.WriteLine("\ttypedef void* gpointer;");
         textWriter.WriteLine("\ttypedef int gboolean;");
         if (buildTarget == BuildTarget.iOS)
         {
             textWriter.WriteLine("\tconst char*\t\t\tUnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
             textWriter.WriteLine("\tvoid\t\t\t\tmono_dl_register_symbol (const char* name, void *addr);");
             textWriter.WriteLine("#if !defined(__arm64__)");
             textWriter.WriteLine("\textern int\t\t\tmono_ficall_flag;");
             textWriter.WriteLine("#endif");
         }
         textWriter.WriteLine("\tvoid\t\t\t\tmono_aot_register_module(gpointer *aot_info);");
         textWriter.WriteLine("#if !(__ORBIS__)");
         textWriter.WriteLine("#define DLL_EXPORT");
         textWriter.WriteLine("#else");
         textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
         textWriter.WriteLine("#endif");
         textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
         textWriter.WriteLine("\textern gboolean\t\tmono_aot_only;");
         for (int i = 0; i < assemblyFileNames.Length; i++)
         {
             string arg  = assemblyFileNames[i];
             string text = assemblyDefinitions[i].Name.Name;
             text = text.Replace(".", "_");
             text = text.Replace("-", "_");
             text = text.Replace(" ", "_");
             textWriter.WriteLine("\textern gpointer*\tmono_aot_module_{0}_info; // {1}", text, arg);
         }
         textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
         foreach (string arg2 in arrayList)
         {
             textWriter.WriteLine("\tDECL_USER_FUNC({0});", arg2);
         }
         textWriter.WriteLine("}");
         textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
         textWriter.WriteLine("{");
         textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         textWriter.WriteLine("\tmono_aot_only = true;");
         if (buildTarget == BuildTarget.iOS)
         {
             textWriter.WriteLine("\tmono_ficall_flag = {0};", (!flag) ? "false" : "true");
         }
         AssemblyDefinition[] array = assemblyDefinitions;
         for (int j = 0; j < array.Length; j++)
         {
             AssemblyDefinition assemblyDefinition = array[j];
             string             text2 = assemblyDefinition.Name.Name;
             text2 = text2.Replace(".", "_");
             text2 = text2.Replace("-", "_");
             text2 = text2.Replace(" ", "_");
             textWriter.WriteLine("\tmono_aot_register_module(mono_aot_module_{0}_info);", text2);
         }
         textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         textWriter.WriteLine(string.Empty);
         if (buildTarget == BuildTarget.iOS)
         {
             foreach (string arg3 in arrayList)
             {
                 textWriter.WriteLine("\tREGISTER_USER_FUNC({0});", arg3);
             }
         }
         textWriter.WriteLine("}");
         textWriter.WriteLine(string.Empty);
         AssemblyDefinition assemblyDefinition2 = null;
         for (int k = 0; k < assemblyFileNames.Length; k++)
         {
             if (assemblyFileNames[k] == "UnityEngine.dll")
             {
                 assemblyDefinition2 = assemblyDefinitions[k];
             }
         }
         if (buildTarget == BuildTarget.iOS)
         {
             AssemblyDefinition[] assemblies = new AssemblyDefinition[]
             {
                 assemblyDefinition2
             };
             MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter);
             MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
             MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, assemblyDefinition2, usedClassRegistry);
             if (stripping && usedClassRegistry != null)
             {
                 MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, textWriter);
             }
             else
             {
                 MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, textWriter);
             }
         }
         textWriter.Close();
     }
 }
 public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker)
 {
     using (TextWriter output = (TextWriter) new StreamWriter(file))
     {
         string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
         AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
         bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
         ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
         if (buildTarget == BuildTarget.iOS)
         {
             output.WriteLine("#include \"RegisterMonoModules.h\"");
             output.WriteLine("#include <stdio.h>");
         }
         output.WriteLine(string.Empty);
         output.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
         output.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
         output.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
         output.WriteLine("        do {\\");
         output.WriteLine("        if(f != NULL)\\");
         output.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
         output.WriteLine("        else\\");
         output.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
         output.WriteLine("        }while(0)");
         output.WriteLine("#else");
         output.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
         output.WriteLine("    #if !defined(__arm64__)");
         output.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
         output.WriteLine("    #else");
         output.WriteLine("        #define REGISTER_USER_FUNC(f)");
         output.WriteLine("    #endif");
         output.WriteLine("#endif");
         output.WriteLine("extern \"C\"\n{");
         output.WriteLine("    typedef void* gpointer;");
         output.WriteLine("    typedef int gboolean;");
         if (buildTarget == BuildTarget.iOS)
         {
             output.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", (object)Application.unityVersion);
             output.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
             output.WriteLine("#if !defined(__arm64__)");
             output.WriteLine("    extern int          mono_ficall_flag;");
             output.WriteLine("#endif");
         }
         output.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
         output.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
         output.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
         output.WriteLine("#else");
         output.WriteLine("#define DLL_EXPORT");
         output.WriteLine("#endif");
         output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
         output.WriteLine("    extern gboolean     mono_aot_only;");
         for (int index = 0; index < assemblyFileNames.Length; ++index)
         {
             string str1 = assemblyFileNames[index];
             string str2 = ((AssemblyNameReference)assemblyDefinitions[index].get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             output.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", (object)str2, (object)str1);
         }
         output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
         foreach (string str in arrayList)
         {
             output.WriteLine("    DECL_USER_FUNC({0});", (object)str);
         }
         output.WriteLine("}");
         output.WriteLine("DLL_EXPORT void RegisterMonoModules()");
         output.WriteLine("{");
         output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         output.WriteLine("    mono_aot_only = true;");
         if (buildTarget == BuildTarget.iOS)
         {
             output.WriteLine("    mono_ficall_flag = {0};", !flag ? (object)"false" : (object)"true");
         }
         foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions)
         {
             string str = ((AssemblyNameReference)assemblyDefinition.get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_");
             output.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", (object)str);
         }
         output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
         output.WriteLine(string.Empty);
         if (buildTarget == BuildTarget.iOS)
         {
             foreach (string str in arrayList)
             {
                 output.WriteLine("    REGISTER_USER_FUNC({0});", (object)str);
             }
         }
         output.WriteLine("}");
         output.WriteLine(string.Empty);
         AssemblyDefinition unityEngine = (AssemblyDefinition)null;
         for (int index = 0; index < assemblyFileNames.Length; ++index)
         {
             if (assemblyFileNames[index] == "UnityEngine.dll")
             {
                 unityEngine = assemblyDefinitions[index];
             }
         }
         if (buildTarget == BuildTarget.iOS)
         {
             AssemblyDefinition[] assemblies = new AssemblyDefinition[1] {
                 unityEngine
             };
             MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, output);
             MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
             MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
             MonoAOTRegistration.GenerateRegisterModules(usedClassRegistry, output, stripping);
             if (stripping && usedClassRegistry != null)
             {
                 MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, output);
             }
             else
             {
                 MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, output);
             }
         }
         output.Close();
     }
 }
Esempio n. 3
0
        public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider)
        {
            string text = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            string exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", Path.Combine(stagingAreaDataManaged, "UnityEngine.dll"), text);

            Runner.RunManagedProgram(exe, args);
            HashSet <UnityType> hashSet;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), text, usedClassRegistry, stripping, out hashSet, out nativeModules, platformProvider);
            using (TextWriter textWriter = new StreamWriter(file))
            {
                string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
                bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
                ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
                    textWriter.WriteLine("#include <stdio.h>");
                }
                textWriter.WriteLine("");
                textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
                textWriter.WriteLine("        do {\\");
                textWriter.WriteLine("        if(f != NULL)\\");
                textWriter.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
                textWriter.WriteLine("        else\\");
                textWriter.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                textWriter.WriteLine("        }while(0)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                textWriter.WriteLine("    #if !defined(__arm64__)");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                textWriter.WriteLine("    #else");
                textWriter.WriteLine("        #define REGISTER_USER_FUNC(f)");
                textWriter.WriteLine("    #endif");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("extern \"C\"\n{");
                textWriter.WriteLine("    typedef void* gpointer;");
                textWriter.WriteLine("    typedef int gboolean;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    textWriter.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
                    textWriter.WriteLine("#if !defined(__arm64__)");
                    textWriter.WriteLine("    extern int          mono_ficall_flag;");
                    textWriter.WriteLine("#endif");
                }
                textWriter.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
                textWriter.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("#define DLL_EXPORT");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                textWriter.WriteLine("    extern gboolean     mono_aot_only;");
                for (int i = 0; i < assemblyFileNames.Length; i++)
                {
                    string arg   = assemblyFileNames[i];
                    string text2 = assemblyDefinitions[i].Name.Name;
                    text2 = text2.Replace(".", "_");
                    text2 = text2.Replace("-", "_");
                    text2 = text2.Replace(" ", "_");
                    textWriter.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", text2, arg);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                IEnumerator enumerator = arrayList.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string arg2 = (string)enumerator.Current;
                        textWriter.WriteLine("    DECL_USER_FUNC({0});", arg2);
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                textWriter.WriteLine("{");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("    mono_aot_only = true;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    mono_ficall_flag = {0};", (!flag) ? "false" : "true");
                }
                AssemblyDefinition[] array = assemblyDefinitions;
                for (int j = 0; j < array.Length; j++)
                {
                    AssemblyDefinition assemblyDefinition = array[j];
                    string             text3 = assemblyDefinition.Name.Name;
                    text3 = text3.Replace(".", "_");
                    text3 = text3.Replace("-", "_");
                    text3 = text3.Replace(" ", "_");
                    textWriter.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", text3);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    IEnumerator enumerator2 = arrayList.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string arg3 = (string)enumerator2.Current;
                            textWriter.WriteLine("    REGISTER_USER_FUNC({0});", arg3);
                        }
                    }
                    finally
                    {
                        IDisposable disposable2;
                        if ((disposable2 = (enumerator2 as IDisposable)) != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("");
                AssemblyDefinition assemblyDefinition2 = null;
                for (int k = 0; k < assemblyFileNames.Length; k++)
                {
                    if (assemblyFileNames[k] == "UnityEngine.dll")
                    {
                        assemblyDefinition2 = assemblyDefinitions[k];
                    }
                }
                if (buildTarget == BuildTarget.iOS)
                {
                    AssemblyDefinition[] assemblies = new AssemblyDefinition[]
                    {
                        assemblyDefinition2
                    };
                    MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter);
                    MonoAOTRegistration.GenerateRegisterModules(hashSet, nativeModules, textWriter, stripping);
                    if (stripping && usedClassRegistry != null)
                    {
                        MonoAOTRegistration.GenerateRegisterClassesForStripping(hashSet, textWriter);
                    }
                    else
                    {
                        MonoAOTRegistration.GenerateRegisterClasses(hashSet, textWriter);
                    }
                }
                textWriter.Close();
            }
        }