Skip to content

Commit ad5ce72

Browse files
committed
Collected extra symbols in the order of their compilation.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent ce22a3c commit ad5ce72

File tree

1 file changed

+51
-34
lines changed

1 file changed

+51
-34
lines changed

src/Generator/Passes/GenerateSymbolsPass.cs

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void GenerateSymbols()
7373
RemainingCompilationTasks--;
7474
else
7575
InvokeCompiler(e.CustomCompiler, e.CompilerArguments,
76-
e.OutputDir, module.SymbolsLibraryName);
76+
e.OutputDir, module);
7777
}
7878
}
7979

@@ -156,49 +156,23 @@ private SymbolsCodeGenerator GetSymbolsCodeGenerator(Module module)
156156
return symbolsCodeGenerator;
157157
}
158158

159-
private void InvokeCompiler(string compiler, string arguments, string outputDir, string symbols)
159+
private void InvokeCompiler(string compiler, string arguments, string outputDir, Module module)
160160
{
161161
new Thread(() =>
162162
{
163163
int error;
164164
string errorMessage;
165165
ProcessHelper.Run(compiler, arguments, out error, out errorMessage);
166-
CollectSymbols(outputDir, symbols, errorMessage);
166+
var output = GetOutputFile(module.SymbolsLibraryName);
167+
if (!File.Exists(Path.Combine(outputDir, output)))
168+
Diagnostics.Error(errorMessage);
169+
else
170+
compiledLibraries[module] = new CompiledLibrary
171+
{ OutputDir = outputDir, Library = module.SymbolsLibraryName };
167172
RemainingCompilationTasks--;
168173
}).Start();
169174
}
170175

171-
private void CollectSymbols(string outputDir, string symbols, string errorMessage)
172-
{
173-
using (var parserOptions = new ParserOptions())
174-
{
175-
parserOptions.AddLibraryDirs(outputDir);
176-
var output = Path.GetFileName($@"{(Platform.IsWindows ?
177-
string.Empty : "lib")}{symbols}.{
178-
(Platform.IsMacOS ? "dylib" : Platform.IsWindows ? "dll" : "so")}");
179-
if (!File.Exists(Path.Combine(outputDir, output)))
180-
{
181-
Diagnostics.Error(errorMessage);
182-
return;
183-
}
184-
parserOptions.LibraryFile = output;
185-
using (var parserResult = Parser.ClangParser.ParseLibrary(parserOptions))
186-
{
187-
if (parserResult.Kind == ParserResultKind.Success)
188-
{
189-
var nativeLibrary = ClangParser.ConvertLibrary(parserResult.Library);
190-
lock (@lock)
191-
{
192-
Context.Symbols.Libraries.Add(nativeLibrary);
193-
Context.Symbols.IndexSymbols();
194-
}
195-
}
196-
else
197-
Diagnostics.Error($"Parsing of {Path.Combine(outputDir, output)} failed.");
198-
}
199-
}
200-
}
201-
202176
private void CheckBasesForSpecialization(Class @class)
203177
{
204178
foreach (var @base in @class.Bases.Where(b => b.IsClass))
@@ -232,19 +206,62 @@ private int RemainingCompilationTasks
232206
remainingCompilationTasks = value;
233207
if (remainingCompilationTasks == 0)
234208
{
209+
foreach (var module in Context.Options.Modules.Where(compiledLibraries.ContainsKey))
210+
{
211+
CompiledLibrary compiledLibrary = compiledLibraries[module];
212+
CollectSymbols(compiledLibrary.OutputDir, compiledLibrary.Library);
213+
}
235214
var findSymbolsPass = Context.TranslationUnitPasses.FindPass<FindSymbolsPass>();
236215
findSymbolsPass.Wait = false;
237216
}
238217
}
239218
}
240219
}
241220

221+
private void CollectSymbols(string outputDir, string library)
222+
{
223+
using (var parserOptions = new ParserOptions())
224+
{
225+
parserOptions.AddLibraryDirs(outputDir);
226+
var output = GetOutputFile(library);
227+
parserOptions.LibraryFile = output;
228+
using (var parserResult = Parser.ClangParser.ParseLibrary(parserOptions))
229+
{
230+
if (parserResult.Kind == ParserResultKind.Success)
231+
{
232+
var nativeLibrary = ClangParser.ConvertLibrary(parserResult.Library);
233+
lock (@lock)
234+
{
235+
Context.Symbols.Libraries.Add(nativeLibrary);
236+
Context.Symbols.IndexSymbols();
237+
}
238+
}
239+
else
240+
Diagnostics.Error($"Parsing of {Path.Combine(outputDir, output)} failed.");
241+
}
242+
}
243+
}
244+
245+
private static string GetOutputFile(string library)
246+
{
247+
return Path.GetFileName($@"{(Platform.IsWindows ?
248+
string.Empty : "lib")}{library}.{
249+
(Platform.IsMacOS ? "dylib" : Platform.IsWindows ? "dll" : "so")}");
250+
}
251+
242252
private int remainingCompilationTasks;
243253
private static readonly object @lock = new object();
244254

245255
private Dictionary<Module, SymbolsCodeGenerator> symbolsCodeGenerators =
246256
new Dictionary<Module, SymbolsCodeGenerator>();
247257
private Dictionary<Module, HashSet<ClassTemplateSpecialization>> specializations =
248258
new Dictionary<Module, HashSet<ClassTemplateSpecialization>>();
259+
private Dictionary<Module, CompiledLibrary> compiledLibraries = new Dictionary<Module, CompiledLibrary>();
260+
261+
private class CompiledLibrary
262+
{
263+
public string OutputDir { get; set; }
264+
public string Library { get; set; }
265+
}
249266
}
250267
}

0 commit comments

Comments
 (0)