|
|
|
@ -17,7 +17,7 @@ using CppSharp.Generators.Cpp;
@@ -17,7 +17,7 @@ using CppSharp.Generators.Cpp;
|
|
|
|
|
|
|
|
|
|
namespace CppSharp |
|
|
|
|
{ |
|
|
|
|
public class Driver |
|
|
|
|
public class Driver : IDisposable |
|
|
|
|
{ |
|
|
|
|
public DriverOptions Options { get; private set; } |
|
|
|
|
public ParserOptions ParserOptions { get; set; } |
|
|
|
@ -399,6 +399,13 @@ namespace CppSharp
@@ -399,6 +399,13 @@ namespace CppSharp
|
|
|
|
|
Context.GeneratorOutputPasses.AddPass(pass); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
Generator.Dispose(); |
|
|
|
|
Context.TargetInfo?.Dispose(); |
|
|
|
|
ParserOptions.Dispose(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private bool hasParsingErrors; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -407,72 +414,69 @@ namespace CppSharp
@@ -407,72 +414,69 @@ namespace CppSharp
|
|
|
|
|
public static void Run(ILibrary library) |
|
|
|
|
{ |
|
|
|
|
var options = new DriverOptions(); |
|
|
|
|
var driver = new Driver(options); |
|
|
|
|
|
|
|
|
|
library.Setup(driver); |
|
|
|
|
|
|
|
|
|
driver.Setup(); |
|
|
|
|
using (var driver = new Driver(options)) |
|
|
|
|
{ |
|
|
|
|
library.Setup(driver); |
|
|
|
|
|
|
|
|
|
if(driver.Options.Verbose) |
|
|
|
|
Diagnostics.Level = DiagnosticKind.Debug; |
|
|
|
|
driver.Setup(); |
|
|
|
|
|
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Parsing libraries..."); |
|
|
|
|
if (driver.Options.Verbose) |
|
|
|
|
Diagnostics.Level = DiagnosticKind.Debug; |
|
|
|
|
|
|
|
|
|
if (!driver.ParseLibraries()) |
|
|
|
|
return; |
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Parsing libraries..."); |
|
|
|
|
|
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Parsing code..."); |
|
|
|
|
if (!driver.ParseLibraries()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (!driver.ParseCode()) |
|
|
|
|
{ |
|
|
|
|
Diagnostics.Error("CppSharp has encountered an error while parsing code."); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Parsing code..."); |
|
|
|
|
|
|
|
|
|
new CleanUnitPass { Context = driver.Context }.VisitASTContext(driver.Context.ASTContext); |
|
|
|
|
options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any()); |
|
|
|
|
if (!driver.ParseCode()) |
|
|
|
|
{ |
|
|
|
|
Diagnostics.Error("CppSharp has encountered an error while parsing code."); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Processing code..."); |
|
|
|
|
new CleanUnitPass { Context = driver.Context }.VisitASTContext(driver.Context.ASTContext); |
|
|
|
|
options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any()); |
|
|
|
|
|
|
|
|
|
driver.SetupPasses(library); |
|
|
|
|
driver.SetupTypeMaps(); |
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Processing code..."); |
|
|
|
|
|
|
|
|
|
library.Preprocess(driver, driver.Context.ASTContext); |
|
|
|
|
driver.SetupPasses(library); |
|
|
|
|
driver.SetupTypeMaps(); |
|
|
|
|
|
|
|
|
|
driver.ProcessCode(); |
|
|
|
|
library.Postprocess(driver, driver.Context.ASTContext); |
|
|
|
|
library.Preprocess(driver, driver.Context.ASTContext); |
|
|
|
|
|
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Generating code..."); |
|
|
|
|
driver.ProcessCode(); |
|
|
|
|
library.Postprocess(driver, driver.Context.ASTContext); |
|
|
|
|
|
|
|
|
|
if (!options.DryRun) |
|
|
|
|
{ |
|
|
|
|
var outputs = driver.GenerateCode(); |
|
|
|
|
if (!options.Quiet) |
|
|
|
|
Diagnostics.Message("Generating code..."); |
|
|
|
|
|
|
|
|
|
foreach (var output in outputs) |
|
|
|
|
if (!options.DryRun) |
|
|
|
|
{ |
|
|
|
|
foreach (var pass in driver.Context.GeneratorOutputPasses.Passes) |
|
|
|
|
{ |
|
|
|
|
pass.VisitGeneratorOutput(output); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
var outputs = driver.GenerateCode(); |
|
|
|
|
|
|
|
|
|
driver.SaveCode(outputs); |
|
|
|
|
if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) |
|
|
|
|
foreach (var module in driver.Options.Modules) |
|
|
|
|
foreach (var output in outputs) |
|
|
|
|
{ |
|
|
|
|
driver.CompileCode(module); |
|
|
|
|
if (driver.HasCompilationErrors) |
|
|
|
|
break; |
|
|
|
|
foreach (var pass in driver.Context.GeneratorOutputPasses.Passes) |
|
|
|
|
{ |
|
|
|
|
pass.VisitGeneratorOutput(output); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
driver.Generator.Dispose(); |
|
|
|
|
driver.Context.TargetInfo.Dispose(); |
|
|
|
|
driver.ParserOptions.Dispose(); |
|
|
|
|
driver.SaveCode(outputs); |
|
|
|
|
if (driver.Options.IsCSharpGenerator && driver.Options.CompileCode) |
|
|
|
|
foreach (var module in driver.Options.Modules) |
|
|
|
|
{ |
|
|
|
|
driver.CompileCode(module); |
|
|
|
|
if (driver.HasCompilationErrors) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|