|
|
@ -1,4 +1,7 @@ |
|
|
|
using Cxxi.Generators; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using Cxxi.Generators; |
|
|
|
|
|
|
|
using Cxxi.Generators.CLI; |
|
|
|
|
|
|
|
using Cxxi.Generators.CSharp; |
|
|
|
using Cxxi.Passes; |
|
|
|
using Cxxi.Passes; |
|
|
|
using Cxxi.Types; |
|
|
|
using Cxxi.Types; |
|
|
|
using System; |
|
|
|
using System; |
|
|
@ -8,64 +11,84 @@ namespace Cxxi |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class Driver |
|
|
|
public class Driver |
|
|
|
{ |
|
|
|
{ |
|
|
|
private readonly DriverOptions options; |
|
|
|
public DriverOptions Options { get; private set; } |
|
|
|
private readonly ILibrary transform; |
|
|
|
public ILibrary Transform { get; private set; } |
|
|
|
private readonly IDiagnosticConsumer diagnostics; |
|
|
|
public IDiagnosticConsumer Diagnostics { get; private set; } |
|
|
|
private readonly TypeMapDatabase typeDatabase; |
|
|
|
public TypeMapDatabase TypeDatabase { get; private set; } |
|
|
|
private Library library; |
|
|
|
public Library Library { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
public Driver(DriverOptions options, ILibrary transform) |
|
|
|
public Driver(DriverOptions options, ILibrary transform) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.options = options; |
|
|
|
Options = options; |
|
|
|
this.transform = transform; |
|
|
|
Transform = transform; |
|
|
|
this.diagnostics = new TextDiagnosticPrinter(); |
|
|
|
Diagnostics = new TextDiagnosticPrinter(); |
|
|
|
|
|
|
|
TypeDatabase = new TypeMapDatabase(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Setup() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
TypeDatabase.SetupTypeMaps(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Transform != null) |
|
|
|
|
|
|
|
Transform.Setup(Options); |
|
|
|
|
|
|
|
|
|
|
|
typeDatabase = new TypeMapDatabase(); |
|
|
|
ValidateOptions(); |
|
|
|
typeDatabase.SetupTypeMaps(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ValidateOptions() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(Options.LibraryName)) |
|
|
|
|
|
|
|
throw new InvalidDataException(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Options.OutputDir == null) |
|
|
|
|
|
|
|
Options.OutputDir = Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Options.IncludeDirs.Count; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (Options.IncludeDirs[i] != ".") |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
Options.IncludeDirs[i] = Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void ParseCode() |
|
|
|
public void ParseCode() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.WriteLine("Parsing code..."); |
|
|
|
Console.WriteLine("Parsing code..."); |
|
|
|
|
|
|
|
|
|
|
|
var headers = new List<string>(); |
|
|
|
var parser = new Parser(Options); |
|
|
|
transform.SetupHeaders(headers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parser = new Parser(options); |
|
|
|
|
|
|
|
parser.HeaderParsed += (file, result) => |
|
|
|
parser.HeaderParsed += (file, result) => |
|
|
|
Console.WriteLine(result.Success ? " Parsed '" + file + "'." : |
|
|
|
Console.WriteLine(result.Success ? " Parsed '" + file + "'." : |
|
|
|
" Could not parse '" + file + "'."); |
|
|
|
" Could not parse '" + file + "'."); |
|
|
|
|
|
|
|
|
|
|
|
parser.ParseHeaders(headers); |
|
|
|
parser.ParseHeaders(Options.Headers); |
|
|
|
parser.ParseHeaders(options.Headers); |
|
|
|
Library = parser.Library; |
|
|
|
|
|
|
|
|
|
|
|
library = parser.Library; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void ProcessCode() |
|
|
|
public void ProcessCode() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (Transform != null) |
|
|
|
if (Transform != null) |
|
|
|
Transform.Preprocess(library); |
|
|
|
Transform.Preprocess(Library); |
|
|
|
|
|
|
|
|
|
|
|
var passes = new PassBuilder(library); |
|
|
|
var passes = new PassBuilder(Library); |
|
|
|
passes.SortDeclarations(); |
|
|
|
passes.SortDeclarations(); |
|
|
|
passes.ResolveIncompleteDecls(typeDatabase); |
|
|
|
passes.ResolveIncompleteDecls(TypeDatabase); |
|
|
|
passes.CleanInvalidDeclNames(); |
|
|
|
|
|
|
|
passes.CheckFlagEnums(); |
|
|
|
passes.CheckFlagEnums(); |
|
|
|
|
|
|
|
|
|
|
|
if (transform != null) |
|
|
|
if (Transform != null) |
|
|
|
transform.SetupPasses(passes); |
|
|
|
Transform.SetupPasses(passes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
passes.CleanInvalidDeclNames(); |
|
|
|
|
|
|
|
|
|
|
|
var transformer = new Transform() { Options = options, Passes = passes }; |
|
|
|
var transformer = new Transform() { Options = Options, Passes = passes }; |
|
|
|
transformer.TransformLibrary(library); |
|
|
|
transformer.TransformLibrary(Library); |
|
|
|
|
|
|
|
|
|
|
|
if (Transform != null) |
|
|
|
if (Transform != null) |
|
|
|
Transform.Postprocess(library); |
|
|
|
Transform.Postprocess(Library); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateCode() |
|
|
|
public void GenerateCode() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (library.TranslationUnits.Count <= 0) |
|
|
|
if (Library.TranslationUnits.Count <= 0) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Generating wrapper code..."); |
|
|
|
Console.WriteLine("Generating wrapper code..."); |
|
|
@ -124,6 +147,7 @@ namespace Cxxi |
|
|
|
public string Template; |
|
|
|
public string Template; |
|
|
|
public string Assembly; |
|
|
|
public string Assembly; |
|
|
|
public int ToolsetToUse; |
|
|
|
public int ToolsetToUse; |
|
|
|
|
|
|
|
public string IncludePrefix; |
|
|
|
public string WrapperSuffix; |
|
|
|
public string WrapperSuffix; |
|
|
|
public LanguageGeneratorKind GeneratorKind; |
|
|
|
public LanguageGeneratorKind GeneratorKind; |
|
|
|
} |
|
|
|
} |
|
|
|