From 6ecd733761737b60b63da8f5123568241bca4f0b Mon Sep 17 00:00:00 2001 From: triton Date: Fri, 3 May 2013 14:43:18 +0100 Subject: [PATCH] Added support for native library symbol finds/indexing. --- src/Bridge/Library.cs | 39 +++++++++++++++++++++++++++++++++++++++ src/Generator/Driver.cs | 6 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Library.cs b/src/Bridge/Library.cs index c3978310..00c86163 100644 --- a/src/Bridge/Library.cs +++ b/src/Bridge/Library.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace Cxxi @@ -42,6 +43,7 @@ namespace Cxxi public string SharedLibrary; public List TranslationUnits; public List Libraries; + public Dictionary Symbols; public Library(string name, string sharedLibrary) { @@ -49,6 +51,7 @@ namespace Cxxi SharedLibrary = sharedLibrary; TranslationUnits = new List(); Libraries = new List(); + Symbols = new Dictionary(); } public NativeLibrary FindOrCreateLibrary(string file) @@ -64,6 +67,42 @@ namespace Cxxi return library; } + public void IndexSymbols() + { + foreach (var library in Libraries) + { + foreach (var symbol in library.Symbols) + Symbols[symbol] = library; + } + } + + public bool FindSymbol(ref string symbol) + { + NativeLibrary lib; + + if (FindLibraryBySymbol(symbol, out lib)) + return true; + + if (FindLibraryBySymbol("_imp_" + symbol, out lib)) + { + symbol = "_imp_" + symbol; + return true; + } + + if (FindLibraryBySymbol("__imp_" + symbol, out lib)) + { + symbol = "__imp_" + symbol; + return true; + } + + return false; + } + + public bool FindLibraryBySymbol(string symbol, out NativeLibrary library) + { + return Symbols.TryGetValue(symbol, out library); + } + /// Finds an existing module or creates a new one given a file path. public TranslationUnit FindOrCreateModule(string file) { diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 9c68b865..ee21891f 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -16,6 +16,7 @@ namespace Cxxi public IDiagnosticConsumer Diagnostics { get; private set; } public TypeMapDatabase TypeDatabase { get; private set; } public Library Library { get; private set; } + public Library LibrarySymbols { get; private set; } public Generator Generator { get; private set; } public Driver(DriverOptions options, ILibrary transform) @@ -119,7 +120,10 @@ namespace Cxxi if (!parser.ParseLibraries(Options.Libraries)) return false; - Library = parser.Library; + LibrarySymbols = parser.Library; + + Console.WriteLine("Indexing library symbols..."); + LibrarySymbols.IndexSymbols(); return true; }