Skip to content

Commit

Permalink
Generate only unique entries in wasm pinvoke table generator (#39356)
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar authored Jul 15, 2020
1 parent 78fb02b commit 4cc3750
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,34 @@ private void EmitPInvokeTable(StreamWriter w, Dictionary<string, string> modules
w.WriteLine("// GENERATED FILE, DO NOT MODIFY");
w.WriteLine();

foreach (var pinvoke in pinvokes)
var decls = new HashSet<string>();
foreach (var pinvoke in pinvokes.OrderBy(l => l.EntryPoint))
{
if (modules.ContainsKey(pinvoke.Module))
w.WriteLine(GenPInvokeDecl(pinvoke));
if (modules.ContainsKey(pinvoke.Module)) {
var decl = GenPInvokeDecl(pinvoke);
if (decls.Contains(decl))
continue;

w.WriteLine(decl);
decls.Add(decl);
}
}

foreach (var module in modules.Keys)
{
string symbol = module.Replace(".", "_") + "_imports";
w.WriteLine("static PinvokeImport " + symbol + " [] = {");
foreach (var pinvoke in pinvokes)
{
if (pinvoke.Module == module)
w.WriteLine("{\"" + pinvoke.EntryPoint + "\", " + pinvoke.EntryPoint + "},");

var assemblies_pinvokes = pinvokes.
Where(l => l.Module == module).
OrderBy(l => l.EntryPoint).
GroupBy(d => d.EntryPoint).
Select (l => "{\"" + l.Key + "\", " + l.Key + "}, // " + string.Join (", ", l.Select(c => c.Method.DeclaringType!.Module!.Assembly!.GetName ()!.Name!).Distinct()));

foreach (var pinvoke in assemblies_pinvokes) {
w.WriteLine (pinvoke);
}

w.WriteLine("{NULL, NULL}");
w.WriteLine("};");
}
Expand Down

0 comments on commit 4cc3750

Please sign in to comment.