Ejemplo n.º 1
0
        static void BuildParseOptions(Driver driver, Target target)
        {
            foreach (var header in driver.Options.Headers)
            {
                var source = driver.Project.AddFile(header);
                source.Options = driver.BuildParseOptions(source);

                if (header.Contains("mini"))
                {
                    continue;
                }

                source.Options.addDefines("HAVE_SGEN_GC");
                source.Options.addDefines("HAVE_MOVING_COLLECTOR");
            }
        }
Ejemplo n.º 2
0
        static void BuildParseOptions(Driver driver)
        {
            var json         = File.ReadAllText(CompilationDatabasePath);
            var compileUnits = JsonConvert.DeserializeObject <List <CompileUnit> >(json);

            compileUnits = CleanCompileUnits(compileUnits);
            compileUnits = compileUnits.OrderBy(unit => unit.file).ToList();

            foreach (var unit in compileUnits)
            {
                var source = driver.Project.AddFile(unit.file);
                source.Options = driver.BuildParseOptions(source);

                var args = unit.command.Split(new char[] { ' ' }).Skip(1);
                foreach (var arg in args)
                {
                    // Skip some arguments that Clang complains about...
                    var arguments = new List <string> {
                        "-no-cpp-precomp",
                        "-Qunused-arguments",
                        "-fno-strict-aliasing",
                        "-Qunused-arguments",
                        "-MD",
                        "-MF",
                        "-c"
                    };

                    if (arguments.Contains(arg))
                    {
                        continue;
                    }

                    source.Options.addArguments(arg);
                }
            }
        }
Ejemplo n.º 3
0
        public static void Run(ILibrary library)
        {
            var options = new DriverOptions();
            var driver  = new Driver(options);

            library.Setup(driver);

            driver.Setup();

            if (driver.ParserOptions.Verbose)
            {
                Diagnostics.Level = DiagnosticKind.Debug;
            }

            if (!options.Quiet)
            {
                Diagnostics.Message("Parsing libraries...");
            }

            if (!driver.ParseLibraries())
            {
                return;
            }

            if (!options.Quiet)
            {
                Diagnostics.Message("Parsing code...");
            }

            driver.BuildParseOptions();

            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);

            library.Preprocess(driver, driver.Context.ASTContext);



            driver.ProcessCode();
            library.Postprocess(driver, driver.Context.ASTContext);

            if (!options.Quiet)
            {
                Diagnostics.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();
            driver.ParserOptions.Dispose();
        }
Ejemplo n.º 4
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();

            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())
                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.WriteCode(outputs);

            if (driver.Options.IsCSharpGenerator)
                driver.CompileCode();
        }
Ejemplo n.º 5
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();

            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();
        }
Ejemplo n.º 6
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();

            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();
        }
Ejemplo n.º 7
0
        static void BuildParseOptions(Driver driver, Target target)
        {
            foreach (var header in driver.Options.Headers)
            {
                var source = driver.Project.AddFile(header);
                source.Options = driver.BuildParseOptions(source);

                if (header.Contains ("mini"))
                    continue;

                source.Options.addDefines ("HAVE_SGEN_GC");
                source.Options.addDefines ("HAVE_MOVING_COLLECTOR");
            }
        }
Ejemplo n.º 8
0
        static void BuildParseOptions(Driver driver)
        {
            var json = File.ReadAllText(CompilationDatabasePath);
            var compileUnits = JsonConvert.DeserializeObject<List<CompileUnit>>(json);

            compileUnits = CleanCompileUnits(compileUnits);
            compileUnits = compileUnits.OrderBy(unit => unit.file).ToList();

            foreach (var unit in compileUnits) {
                var source = driver.Project.AddFile(unit.file);
                source.Options = driver.BuildParseOptions(source);

                var args = unit.command.Split(new char[] {' '}).Skip(1);
                foreach (var arg in args) {
                    // Skip some arguments that Clang complains about...
                    var arguments = new List<string> {
                        "-no-cpp-precomp",
                        "-Qunused-arguments",
                        "-fno-strict-aliasing",
                        "-Qunused-arguments",
                        "-MD",
                        "-MF",
                        "-c"
                    };

                    if (arguments.Contains(arg))
                        continue;

                    source.Options.addArguments(arg);
                }
            }
        }