[offset-tool] fix assignment for GeniOS
[mono.git] / tools / offsets-tool / MonoAotOffsetsDumper.cs
index efcac3b6b5dce2fb2edcafdff2afba76ba48d6a3..199b974559eb1b26ef3b42a5408adb544fe475ff 100644 (file)
@@ -24,10 +24,11 @@ namespace CppSharp
         static List<string> Abis = new List<string> ();
         static string OutputDir;
 
-        static bool XamarinAndroid;
         static string MonodroidDir = @"";
         static string AndroidNdkPath = @"";
         static string MaccoreDir = @"";
+        static string TargetDir = @"";
+        static bool GenIOS;
 
         public enum TargetPlatform
         {
@@ -89,28 +90,24 @@ namespace CppSharp
             Targets.Add (new Target {
                 Platform = TargetPlatform.Android,
                 Triple = "i686-none-linux-android",
-                Build = XamarinAndroid ? "x86" : "mono-x86",
                 Defines = { "TARGET_X86" }
             });
 
             Targets.Add (new Target {
                 Platform = TargetPlatform.Android,
                 Triple = "x86_64-none-linux-android",
-                Build = XamarinAndroid ? "x86_64" : "mono-x86_64",
                 Defines = { "TARGET_AMD64" }
             });            
 
             Targets.Add (new Target {
                 Platform = TargetPlatform.Android,
                 Triple = "armv5-none-linux-androideabi",
-                Build = XamarinAndroid ? "armeabi" : "mono-armv6",
                 Defines = { "TARGET_ARM", "ARM_FPU_VFP", "HAVE_ARMV5" }
             });
 
             Targets.Add (new Target {
                 Platform = TargetPlatform.Android,
                 Triple = "armv7-none-linux-androideabi",
-                Build = XamarinAndroid ? "armeabi-v7a" : "mono-armv7",
                 Defines = { "TARGET_ARM", "ARM_FPU_VFP", "HAVE_ARMV5", "HAVE_ARMV6",
                     "HAVE_ARMV7"
                 }
@@ -119,14 +116,12 @@ namespace CppSharp
             Targets.Add (new Target {
                 Platform = TargetPlatform.Android,
                 Triple = "aarch64-v8a-linux-android",
-                Build = XamarinAndroid ? "arm64-v8a" : "mono-aarch64",
                 Defines = { "TARGET_ARM64" }
             });            
 
             /*Targets.Add(new Target {
                     Platform = TargetPlatform.Android,
                     Triple = "mipsel-none-linux-android",
-                    Build = "mono-mips",
                     Defines = { "TARGET_MIPS", "__mips__" }
                 });*/
 
@@ -212,7 +207,7 @@ namespace CppSharp
                 MaccoreDir = Path.Combine (maccoreDir);
             }
 
-            if (Directory.Exists(MaccoreDir))
+            if (Directory.Exists(MaccoreDir) || GenIOS)
                 SetupiOSTargets();
 
             foreach (var target in Targets)
@@ -225,8 +220,7 @@ namespace CppSharp
 
                 var options = new DriverOptions();
 
-                var log = new TextDiagnosticPrinter();
-                var driver = new Driver(options, log);
+                var driver = new Driver(options);
 
                 Setup(driver, target);
                 driver.Setup();
@@ -251,6 +245,7 @@ namespace CppSharp
 
                 source.Options.AddDefines ("HAVE_SGEN_GC");
                 source.Options.AddDefines ("HAVE_MOVING_COLLECTOR");
+                source.Options.AddDefines("MONO_GENERATING_OFFSETS");
             }
         }
 
@@ -279,8 +274,9 @@ namespace CppSharp
                 { "maccore=", "include directory", v => MaccoreDir = v },
                 { "monodroid=", "top monodroid directory", v => MonodroidDir = v },
                 { "android-ndk=", "Path to Android NDK", v => AndroidNdkPath = v },
-                { "xamarin-android", "Generate for Xamarin.Android instead of monodroid", v => XamarinAndroid = true },
+                { "targetdir=", "Path to the directory containing the mono build", v =>TargetDir = v },
                 { "mono=", "include directory", v => MonoDir = v },
+                { "gen-ios", "generate iOS offsets", v => GenIOS = v != null },
                 { "h|help",  "show this message and exit",  v => showHelp = v != null },
             };
 
@@ -295,9 +291,9 @@ namespace CppSharp
             if (showHelp)
             {
                 // Print usage and exit.
-                Console.WriteLine("{0} [--abi=triple] [--out=dir] "
-                    + "[--monodroid/maccore=dir] [--mono=dir]",
+                Console.WriteLine("{0} <options>",
                     AppDomain.CurrentDomain.FriendlyName);
+                options.WriteOptionDescriptions (Console.Out);
                 Environment.Exit(0);
             }
         }
@@ -314,6 +310,7 @@ namespace CppSharp
             parserOptions.AddArguments("-xc");
             parserOptions.AddArguments("-std=gnu99");
             parserOptions.AddDefines("CPPSHARP");
+            parserOptions.AddDefines("MONO_GENERATING_OFFSETS");
 
             foreach (var define in target.Defines)
                 parserOptions.AddDefines(define);
@@ -325,25 +322,39 @@ namespace CppSharp
 
         static void SetupMono(Driver driver, Target target)
         {
-            string targetPath;
+            string targetBuild;
             switch (target.Platform) {
             case TargetPlatform.Android:
-                targetPath = Path.Combine (MonodroidDir, XamarinAndroid ? "build-tools/mono-runtimes/obj/Debug" : "builds");
+                if (TargetDir == "") {
+                    Console.Error.WriteLine ("The --targetdir= option is required when targeting android.");
+                    Environment.Exit (1);
+                }
+                if (MonoDir == "") {
+                    Console.Error.WriteLine ("The --mono= option is required when targeting android.");
+                    Environment.Exit (1);
+                }
+                if (Abis.Count != 1) {
+                    Console.Error.WriteLine ("Exactly one --abi= argument is required when targeting android.");
+                    Environment.Exit (1);
+                }
+                targetBuild = TargetDir;
                 break;
             case TargetPlatform.WatchOS:
-            case TargetPlatform.iOS:
-                targetPath = Path.Combine (MaccoreDir, "builds");
+            case TargetPlatform.iOS: {
+                if (!string.IsNullOrEmpty (TargetDir)) {
+                    targetBuild = TargetDir;
+                } else {
+                    string targetPath = Path.Combine (MaccoreDir, "builds");
+                    if (!Directory.Exists (MonoDir))
+                        MonoDir = Path.GetFullPath (Path.Combine (targetPath, "../../mono"));
+                    targetBuild = Path.Combine(targetPath, target.Build);
+                }
                 break;
+            }
             default:
                 throw new ArgumentOutOfRangeException ();
             }
 
-            if (!Directory.Exists (MonoDir)) {
-                MonoDir = Path.GetFullPath (Path.Combine (targetPath, "../../mono"));
-            }
-
-            var targetBuild = Path.Combine(targetPath, target.Build);
-
             if (!Directory.Exists(targetBuild))
                 throw new Exception(string.Format("Could not find the target build directory: {0}", targetBuild));
 
@@ -641,8 +652,8 @@ namespace CppSharp
         {
             var targetFile = target.Triple;
 
-                       if (!string.IsNullOrEmpty (OutputDir))
-                               targetFile = Path.Combine (OutputDir, targetFile);
+            if (!string.IsNullOrEmpty (OutputDir))
+                targetFile = Path.Combine (OutputDir, targetFile);
 
             targetFile += ".h";
 
@@ -757,7 +768,7 @@ namespace CppSharp
             var types = new List<string>
             {
                 "MonoObject",
-               "MonoObjectHandlePayload",
+                "MonoObjectHandlePayload",
                 "MonoClass",
                 "MonoVTable",
                 "MonoDelegate",
@@ -806,7 +817,8 @@ namespace CppSharp
                 "SeqPointInfo",
                 "DynCallArgs", 
                 "MonoLMFTramp",
-            };            
+                "InterpMethodArguments",
+            };
 
             DumpClasses(writer, ctx, optionalTypes, optional: true);
 
@@ -816,8 +828,8 @@ namespace CppSharp
         static void DumpStruct(TextWriter writer, Class @class)
         {
             var name = @class.Name;
-                       if (name.StartsWith ("_", StringComparison.Ordinal))
-                               name = name.Substring (1);
+            if (name.StartsWith ("_", StringComparison.Ordinal))
+                name = name.Substring (1);
 
             foreach (var field in @class.Fields)
             {