public Driver(DriverOptions options, IDiagnostics diagnostics) { Options = options; Diagnostics = diagnostics; Project = new Project(); ParserOptions = new ParserOptions(); }
public static void Run(ILibrary library) { var options = new DriverOptions(); var Log = new TextDiagnosticPrinter(); var driver = new Driver(options, Log); library.Setup(driver); driver.Setup(); if(driver.Options.Verbose) Log.Level = DiagnosticKind.Debug; if (!options.Quiet) Log.EmitMessage("Parsing libraries..."); if (!driver.ParseLibraries()) return; if (!options.Quiet) Log.EmitMessage("Indexing library symbols..."); driver.Symbols.IndexSymbols(); if (!options.Quiet) Log.EmitMessage("Parsing code..."); if (!driver.ParseCode()) return; if (!options.Quiet) Log.EmitMessage("Processing code..."); library.Preprocess(driver, driver.ASTContext); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver, driver.ASTContext); if (!options.Quiet) Log.EmitMessage("Generating code..."); var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.GeneratorOutputPasses.Passes) { pass.Driver = driver; pass.VisitGeneratorOutput(output); } } if (!driver.Options.DryRun) driver.WriteCode(outputs); if (driver.Options.IsCSharpGenerator) driver.CompileCode(); }
static void ValidateOptions(DriverOptions options) { if (string.IsNullOrWhiteSpace(options.LibraryName)) throw new InvalidOptionException(); if (options.NoGenIncludeDirs != null) foreach (var incDir in options.NoGenIncludeDirs) options.addIncludeDirs(incDir); if (string.IsNullOrWhiteSpace(options.OutputNamespace)) options.OutputNamespace = options.LibraryName; }
public Driver(DriverOptions options, IDiagnosticConsumer diagnostics) { Options = options; Diagnostics = diagnostics; Project = new Project(); ASTContext = new ASTContext(); Symbols = new SymbolContext(); Delegates = new Dictionary<Function, DelegatesPass.DelegateDefinition>(); TypeDatabase = new TypeMapDatabase(); TranslationUnitPasses = new PassBuilder<TranslationUnitPass>(this); GeneratorOutputPasses = new PassBuilder<GeneratorOutputPass>(this); }
static void ValidateOptions(DriverOptions options) { foreach (var module in options.Modules) { if (string.IsNullOrWhiteSpace(module.LibraryName)) throw new InvalidOptionException("One of your modules has no library name."); if (module.OutputNamespace == null) module.OutputNamespace = module.LibraryName; } if (options.NoGenIncludeDirs != null) foreach (var incDir in options.NoGenIncludeDirs) options.addIncludeDirs(incDir); }
public static void Main(string[] args) { ParseCommandLineArgs(args); Console.WriteLine(); Console.WriteLine("Parsing Mono's source code..."); var options = new DriverOptions(); var log = new TextDiagnosticPrinter(); var driver = new Driver(options, log); Setup(driver); driver.Setup(); BuildParseOptions(driver); if (!driver.ParseCode()) return; Check(driver.ASTContext); }
private static void SetupMacOptions(DriverOptions options) { options.MicrosoftMode = false; options.NoBuiltinIncludes = true; if (IsMacOS) { var headersPaths = new List<string> { Path.Combine(GetSourceDirectory("deps"), "llvm/tools/clang/lib/Headers"), Path.Combine(GetSourceDirectory("deps"), "libcxx", "include"), "/usr/include", }; foreach (var header in headersPaths) Console.WriteLine(header); foreach (var header in headersPaths) options.addSystemIncludeDirs(header); } var headersPath = Path.Combine(GetSourceDirectory("build"), "headers", "osx"); options.addSystemIncludeDirs(Path.Combine(headersPath, "include")); options.addSystemIncludeDirs(Path.Combine(headersPath, "clang", "4.2", "include")); options.addSystemIncludeDirs(Path.Combine(headersPath, "libcxx", "include")); options.addArguments("-stdlib=libc++"); }
private static void SetupLinuxOptions(DriverOptions options) { options.MicrosoftMode = false; options.NoBuiltinIncludes = true; string[] sysincdirs = new[] { "/usr/include/c++/4.8", "/usr/include/x86_64-linux-gnu/c++/4.8", "/usr/include/c++/4.8/backward", "/usr/lib/gcc/x86_64-linux-gnu/4.8/include", "/usr/include/x86_64-linux-gnu", "/usr/include", }; foreach (var dir in sysincdirs) { options.addSystemIncludeDirs(LINUX_INCLUDE_BASE_DIR + dir); } }
private static void SetupMacOptions(DriverOptions options) { options.MicrosoftMode = false; options.NoBuiltinIncludes = true; const string MAC_INCLUDE_PATH = @"C:\Development\CppSharp\build\vs2012\lib\Release_x32\"; #if OLD_PARSER options.SystemIncludeDirs.Add(MAC_INCLUDE_PATH + @"include"); options.SystemIncludeDirs.Add(MAC_INCLUDE_PATH + @"lib\libcxx\include"); options.SystemIncludeDirs.Add(MAC_INCLUDE_PATH + @"lib\clang\4.2\include"); options.Arguments.Add("-stdlib=libc++"); #else options.addSystemIncludeDirs(MAC_INCLUDE_PATH + @"include"); options.addSystemIncludeDirs(MAC_INCLUDE_PATH + @"lib\libcxx\include"); options.addSystemIncludeDirs(MAC_INCLUDE_PATH + @"lib\clang\4.2\include"); options.addArguments("-stdlib=libc++"); #endif }
public static void Run(ILibrary library) { var options = new DriverOptions(); var Log = new TextDiagnosticPrinter(); var driver = new Driver(options, Log); library.Setup(driver); driver.Setup(); if(driver.Options.Verbose) Log.Level = DiagnosticKind.Debug; if (!options.Quiet) Log.Message("Parsing libraries..."); if (!driver.ParseLibraries()) return; if (!options.Quiet) Log.Message("Indexing library symbols..."); driver.Symbols.IndexSymbols(); if (!options.Quiet) Log.Message("Parsing code..."); driver.SortModulesByDependencies(); driver.BuildParseOptions(); if (!driver.ParseCode()) { Log.Error("CppSharp has encountered an error while parsing code."); return; } new CleanUnitPass(options).VisitLibrary(driver.ASTContext); options.Modules.RemoveAll(m => m.Units.All(u => u.Declarations.Count == 0)); if (!options.Quiet) Log.Message("Processing code..."); library.Preprocess(driver, driver.ASTContext); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver, driver.ASTContext); if (!options.Quiet) Log.Message("Generating code..."); var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.GeneratorOutputPasses.Passes) { pass.Driver = driver; pass.VisitGeneratorOutput(output); } } if (!driver.Options.DryRun) { driver.SaveCode(outputs); if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) foreach (var module in driver.Options.Modules) { driver.CompileCode(module); if (driver.HasCompilationErrors) break; } } driver.Generator.Dispose(); driver.TargetInfo.Dispose(); }
public static void Run(ILibrary library) { var options = new DriverOptions(); var Log = new TextDiagnosticPrinter(); var driver = new Driver(options, Log); library.Setup(driver); driver.Setup(); if (driver.ParserOptions.Verbose) { Log.Level = DiagnosticKind.Debug; } if (!options.Quiet) { Log.Message("Parsing libraries..."); } if (!driver.ParseLibraries()) { return; } if (!options.Quiet) { Log.Message("Parsing code..."); } driver.BuildParseOptions(); if (!driver.ParseCode()) { Log.Error("CppSharp has encountered an error while parsing code."); return; } new CleanUnitPass { Context = driver.Context }.VisitASTContext(driver.Context.ASTContext); options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any()); if (!options.Quiet) { Log.Message("Processing code..."); } library.Preprocess(driver, driver.Context.ASTContext); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver, driver.Context.ASTContext); if (!options.Quiet) { Log.Message("Generating code..."); } var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.Context.GeneratorOutputPasses.Passes) { pass.VisitGeneratorOutput(output); } } if (!driver.Options.DryRun) { driver.SaveCode(outputs); if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) { foreach (var module in driver.Options.Modules) { driver.CompileCode(module); if (driver.HasCompilationErrors) { break; } } } } driver.Generator.Dispose(); driver.Context.TargetInfo.Dispose(); }
public Parser(DriverOptions options) { this.options = options; Library = new Library(); }
static void ValidateOptions(DriverOptions options) { if (string.IsNullOrWhiteSpace(options.LibraryName)) throw new InvalidOptionException(); #if OLD_PARSER for (var i = 0; i < options.IncludeDirs.Count; i++) options.IncludeDirs[i] = Path.GetFullPath(options.IncludeDirs[i]); for (var i = 0; i < options.LibraryDirs.Count; i++) options.LibraryDirs[i] = Path.GetFullPath(options.LibraryDirs[i]); #endif if (string.IsNullOrWhiteSpace(options.OutputNamespace)) options.OutputNamespace = options.LibraryName; }
public static void Run(ILibrary library) { var options = new DriverOptions(); var driver = new Driver(options, new TextDiagnosticPrinter()); library.Setup(driver); driver.Setup(); if (!options.Quiet) { Console.WriteLine("Parsing libraries..."); } if (!driver.ParseLibraries()) { return; } if (!options.Quiet) { Console.WriteLine("Indexing library symbols..."); } driver.LibrarySymbols.IndexSymbols(); if (!options.Quiet) { Console.WriteLine("Parsing code..."); } if (!driver.ParseCode()) { return; } if (!options.Quiet) { Console.WriteLine("Processing code..."); } library.Preprocess(driver, driver.Library); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver.Library); if (!options.Quiet) { Console.WriteLine("Generating code..."); } var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.GeneratorOutputPasses.Passes) { pass.Driver = driver; pass.VisitGeneratorOutput(output); } } driver.WriteCode(outputs); }
public static void Run(ILibrary library) { var options = new DriverOptions(); var Log = new TextDiagnosticPrinter(); var driver = new Driver(options, Log); library.Setup(driver); driver.Setup(); if(driver.Options.Verbose) Log.Level = DiagnosticKind.Debug; if (!options.Quiet) Log.Message("Parsing libraries..."); if (!driver.ParseLibraries()) return; if (!options.Quiet) Log.Message("Indexing library symbols..."); driver.Symbols.IndexSymbols(); if (!options.Quiet) Log.Message("Parsing code..."); driver.BuildParseOptions(); if (!driver.ParseCode()) { Log.Error("CppSharp has encountered an error while parsing code."); return; } if (!options.Quiet) Log.Message("Processing code..."); library.Preprocess(driver, driver.ASTContext); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver, driver.ASTContext); if (!options.Quiet) Log.Message("Generating code..."); var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.GeneratorOutputPasses.Passes) { pass.Driver = driver; pass.VisitGeneratorOutput(output); } } if (!driver.Options.DryRun) { driver.SaveCode(outputs); if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) driver.CompileCode(); } driver.Generator.Dispose(); driver.TargetInfo.Dispose(); }
public static void Run(ILibrary library) { var options = new DriverOptions(); var Log = new TextDiagnosticPrinter(); var driver = new Driver(options, Log); library.Setup(driver); driver.Setup(); if (driver.Options.Verbose) { Log.Level = DiagnosticKind.Debug; } if (!options.Quiet) { Log.Message("Parsing libraries..."); } if (!driver.ParseLibraries()) { return; } if (!options.Quiet) { Log.Message("Indexing library symbols..."); } driver.Symbols.IndexSymbols(); if (!options.Quiet) { Log.Message("Parsing code..."); } driver.BuildParseOptions(); if (!driver.ParseCode()) { Log.Error("CppSharp has encountered an error while parsing code."); return; } if (!options.Quiet) { Log.Message("Processing code..."); } library.Preprocess(driver, driver.ASTContext); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver, driver.ASTContext); if (!options.Quiet) { Log.Message("Generating code..."); } var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.GeneratorOutputPasses.Passes) { pass.Driver = driver; pass.VisitGeneratorOutput(output); } } if (!driver.Options.DryRun) { driver.SaveCode(outputs); if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) { driver.CompileCode(); } } driver.Generator.Dispose(); driver.TargetInfo.Dispose(); }
static void ValidateOptions(DriverOptions options) { if (string.IsNullOrWhiteSpace(options.LibraryName)) throw new InvalidOptionException(); #if OLD_PARSER for (var i = 0; i < options.IncludeDirs.Count; i++) options.IncludeDirs[i] = Path.GetFullPath(options.IncludeDirs[i]); for (var i = 0; i < options.LibraryDirs.Count; i++) options.LibraryDirs[i] = Path.GetFullPath(options.LibraryDirs[i]); if (options.NoGenIncludeDirs != null) for (var i = 0; i < options.NoGenIncludeDirs.Count; i++) options.NoGenIncludeDirs[i] = Path.GetFullPath(options.NoGenIncludeDirs[i]); #endif if (options.NoGenIncludeDirs != null) foreach (var incDir in options.NoGenIncludeDirs) #if OLD_PARSER options.IncludeDirs.Add(incDir); #else options.addIncludeDirs(incDir); #endif if (string.IsNullOrWhiteSpace(options.OutputNamespace)) options.OutputNamespace = options.LibraryName; }
public static void Main(string[] args) { ParseCommandLineArgs(args); string monodroidDir; if (!Directory.Exists(MonodroidDir) && GetParentSubDirectoryPath("monodroid", out monodroidDir)) { MonodroidDir = Path.Combine(monodroidDir); } if (Directory.Exists(MonodroidDir) || GenAndroid) { SetupAndroidTargets(); } string maccoreDir; if (!Directory.Exists(MaccoreDir) && GetParentSubDirectoryPath("maccore", out maccoreDir)) { MaccoreDir = Path.Combine(maccoreDir); } if (Directory.Exists(MaccoreDir) || GenIOS) { SetupiOSTargets(); } if (Targets.Count == 0) { SetupOtherTargets(); } foreach (var target in Targets) { if (Abis.Any() && !Abis.Any(target.Triple.Contains)) { continue; } Console.WriteLine(); Console.WriteLine("Processing triple: {0}", target.Triple); var options = new DriverOptions(); var driver = new Driver(options); Setup(driver, target); driver.Setup(); BuildParseOptions(driver, target); if (!driver.ParseCode()) { return; } Dump(driver.Context.ASTContext, driver.Context.TargetInfo, target); } }
public Driver(DriverOptions options) { Options = options; ParserOptions = new ParserOptions(); }
public static void Run(ILibrary library) { var options = new DriverOptions(); using (var driver = new Driver(options)) { library.Setup(driver); driver.Setup(); if (driver.Options.Verbose) { Diagnostics.Level = DiagnosticKind.Debug; } if (!options.Quiet) { Diagnostics.Message("Parsing libraries..."); } if (!driver.ParseLibraries()) { return; } if (!options.Quiet) { Diagnostics.Message("Parsing code..."); } if (!driver.ParseCode()) { Diagnostics.Error("CppSharp has encountered an error while parsing code."); return; } new CleanUnitPass { Context = driver.Context }.VisitASTContext(driver.Context.ASTContext); options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any()); if (!options.Quiet) { Diagnostics.Message("Processing code..."); } driver.SetupPasses(library); driver.SetupTypeMaps(); driver.SetupDeclMaps(); library.Preprocess(driver, driver.Context.ASTContext); driver.ProcessCode(); library.Postprocess(driver, driver.Context.ASTContext); if (!options.Quiet) { Diagnostics.Message("Generating code..."); } if (!options.DryRun) { var outputs = driver.GenerateCode(); library.GenerateCode(driver, outputs); foreach (var output in outputs) { foreach (var pass in driver.Context.GeneratorOutputPasses.Passes) { pass.VisitGeneratorOutput(output); } } driver.SaveCode(outputs); if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) { driver.Options.Modules.Any(m => !driver.CompileCode(m)); } } } }
private void SetupLinuxOptions(DriverOptions options) { options.MicrosoftMode = false; options.NoBuiltinIncludes = true; var headersPath = Platform.IsLinux ? string.Empty : Path.Combine(GetSourceDirectory("build"), "headers", "x86_64-linux-gnu"); // Search for the available GCC versions on the provided headers. var versions = Directory.EnumerateDirectories(Path.Combine(headersPath, "usr/include/c++")); if (versions.Count() == 0) throw new Exception("No valid GCC version found on system include paths"); string gccVersionPath = versions.First(); string gccVersion = gccVersionPath.Substring( gccVersionPath.LastIndexOf(Path.DirectorySeparatorChar) + 1); string[] systemIncludeDirs = new[] { Path.Combine("usr", "include", "c++", gccVersion), Path.Combine("usr", "include", "x86_64-linux-gnu", "c++", gccVersion), Path.Combine("usr", "include", "c++", gccVersion, "backward"), Path.Combine("usr", "lib", "gcc", "x86_64-linux-gnu", gccVersion, "include"), Path.Combine("usr", "include", "x86_64-linux-gnu"), Path.Combine("usr", "include") }; foreach (var dir in systemIncludeDirs) options.addSystemIncludeDirs(Path.Combine(headersPath, dir)); options.addDefines("_GLIBCXX_USE_CXX11_ABI=" + (IsGnuCpp11Abi ? "1" : "0")); }
public static void Run(ILibrary library) { var options = new DriverOptions(); var Log = new TextDiagnosticPrinter(); var driver = new Driver(options, Log); library.Setup(driver); driver.Setup(); Log.Verbose = driver.Options.Verbose; if (!options.Quiet) { Log.EmitMessage("Parsing libraries..."); } if (!driver.ParseLibraries()) { return; } if (!options.Quiet) { Log.EmitMessage("Indexing library symbols..."); } driver.Symbols.IndexSymbols(); if (!options.Quiet) { Log.EmitMessage("Parsing code..."); } if (!driver.ParseCode()) { return; } if (!options.Quiet) { Log.EmitMessage("Processing code..."); } library.Preprocess(driver, driver.ASTContext); driver.SetupPasses(library); driver.ProcessCode(); library.Postprocess(driver, driver.ASTContext); if (!options.Quiet) { Log.EmitMessage("Generating code..."); } var outputs = driver.GenerateCode(); foreach (var output in outputs) { foreach (var pass in driver.GeneratorOutputPasses.Passes) { pass.Driver = driver; pass.VisitGeneratorOutput(output); } } driver.WriteCode(outputs); if (driver.Options.IsCSharpGenerator) { driver.CompileCode(); } }
static void SetupMono(DriverOptions options, Target target) { string targetPath; switch (target.Platform) { case TargetPlatform.Android: targetPath = Path.Combine (MonodroidDir, XamarinAndroid ? "build-tools/mono-runtimes/obj/Debug" : "builds"); break; case TargetPlatform.WatchOS: case TargetPlatform.iOS: targetPath = Path.Combine (MaccoreDir, "builds"); 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)); var includeDirs = new[] { targetBuild, Path.Combine(targetBuild, "eglib", "src"), MonoDir, Path.Combine(MonoDir, "mono"), Path.Combine(MonoDir, "mono", "mini"), Path.Combine(MonoDir, "eglib", "src") }; foreach (var inc in includeDirs) options.addIncludeDirs(inc); var filesToParse = new[] { Path.Combine(MonoDir, "mono", "metadata", "metadata-cross-helpers.c"), Path.Combine(MonoDir, "mono", "mini", "mini-cross-helpers.c"), }; foreach (var file in filesToParse) options.Headers.Add(file); }
public Driver(DriverOptions options) { Options = options; Project = new Project(); ParserOptions = new ParserOptions(); }
public static void Main(string[] args) { ParseCommandLineArgs(args); string monodroidDir; if (!Directory.Exists (MonodroidDir) && GetParentSubDirectoryPath ("monodroid", out monodroidDir)) { MonodroidDir = Path.Combine (monodroidDir); } if (Directory.Exists (MonodroidDir)) SetupAndroidTargets(); string maccoreDir; if (!Directory.Exists (MaccoreDir) && GetParentSubDirectoryPath ("maccore", out maccoreDir)) { MaccoreDir = Path.Combine (maccoreDir); } if (Directory.Exists(MaccoreDir)) SetupiOSTargets(); foreach (var target in Targets) { if (Abis.Any() && !Abis.Any (target.Triple.Contains)) continue; Console.WriteLine(); Console.WriteLine("Processing triple: {0}", target.Triple); var options = new DriverOptions(); var log = new TextDiagnosticPrinter(); var driver = new Driver(options, log); Setup(driver, target); driver.Setup(); BuildParseOptions(driver, target); if (!driver.ParseCode()) return; Dump(driver.Context.ASTContext, driver.Context.TargetInfo, target); } }
private static void SetupMacOptions(DriverOptions options) { options.MicrosoftMode = false; options.NoBuiltinIncludes = true; var headersPath = Path.Combine(GetSourceDirectory("build"), "headers", "osx"); options.addSystemIncludeDirs(Path.Combine(headersPath, "include")); options.addSystemIncludeDirs(Path.Combine(headersPath, "clang", "4.2", "include")); options.addSystemIncludeDirs(Path.Combine(headersPath, "libcxx", "include")); options.addArguments("-stdlib=libc++"); }