Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5f569e3
Refactor to allow fast-path
radical Sep 11, 2021
5b3b91f
MonoAOTCompiler: check for nothing-changed case
radical Sep 11, 2021
28fdcba
[wasm] Change optimization flag defaults for Debug config
radical Sep 17, 2021
6e52172
[wasm] EmccCompile: Fix incremental build, in case of only partial
radical Sep 21, 2021
08ae443
MonoAOTCompiler: Skip unmanaged assemblies, and emit a warning
radical Sep 22, 2021
7fe0e69
Apply suggestions from code review
radical Sep 22, 2021
1c0a340
MonoAOTCompiler: write the cache even when some files fail to compile
radical Sep 22, 2021
7230cd3
Don't set optimization defaults for Debug config, when publishing
radical Sep 22, 2021
c71f9c2
Wasm.Build.Tests: Disable net5.0 because they can't be tested right now
radical Sep 23, 2021
110ed85
[wasm] Error for undefined symbols only when publishing
radical Sep 24, 2021
d17bc64
[wasm] PInvokeTableGenerator: Add support for variadic functions
radical Sep 24, 2021
8ecfd1c
[wasm] Handle pinvokes with function pointers
radical Sep 24, 2021
f4cb745
[wasm] PInvokeTableGenerator: handle pinvokes with function pointers
radical Sep 25, 2021
aac1537
add missing variadic.{c,o}
radical Sep 25, 2021
f48d6b2
[wasm] Add test for issue dotnet#59255
radical Sep 25, 2021
9dd1976
Bump sdk for workload testing to 6.0.100-rc.2.21474.31
radical Sep 22, 2021
46ddc76
Merge remote-tracking branch 'origin/main' into wasm-improvements
radical Sep 27, 2021
712dbb3
MonoAOTCompiler: Check the hash for the file also, for "all up-to-dat…
radical Sep 27, 2021
b23e11e
Merge remote-tracking branch 'origin/main' into wasm-improvements
radical Sep 27, 2021
dc09bf6
Revert "MonoAOTCompiler: Check the hash for the file also, for "all u…
radical Sep 27, 2021
41c7476
PInvokeTableGenerator: don't generate any decl for variadic functions
radical Sep 27, 2021
dcbcc35
Add missing `using` for disposable objects.
radical Sep 29, 2021
1f57975
cleanup
radical Sep 29, 2021
4519646
Merge remote-tracking branch 'origin/main' into rf-wasm-improvements
radical Sep 29, 2021
20a67a1
address feedback from @lewing
radical Sep 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[wasm] PInvokeTableGenerator: Add support for variadic functions
Currently, for a variadic function like:

`int sqlite3_config(int, ...);`

.. and multiple pinvokes like:

```csharp
[DllImport(SQLITE_DLL, ExactSpelling=true, EntryPoint = "sqlite3_config", CallingConvention = CALLING_CONVENTION)]
public static extern unsafe int sqlite3_config_none(int op);

[DllImport(SQLITE_DLL, ExactSpelling=true, EntryPoint = "sqlite3_config", CallingConvention = CALLING_CONVENTION)]
public static extern unsafe int sqlite3_config_int(int op, int val);

[DllImport(SQLITE_DLL, ExactSpelling=true, EntryPoint = "sqlite3_config", CallingConvention = CALLING_CONVENTION)]
public static extern unsafe int sqlite3_config_log(int op, NativeMethods.callback_log func, hook_handle pvUser);
```

.. we generate:

```c
int sqlite3_config (int);
int sqlite3_config (int,int);
int sqlite3_config (int,int,int);
```

.. which fails to compile.

Instead, this patch will generate a variadic declaration with one fixed
parameter:

```c
// Variadic signature created for
//   System.Int32 sqlite3_config_none(System.Int32)
//   System.Int32 sqlite3_config_int(System.Int32, System.Int32)
//   System.Int32 sqlite3_config_log(System.Int32, SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods+callback_log, SQLitePCL.hook_handle)
int sqlite3_config (int, ...);
```

TODO: functions with different first argument
  • Loading branch information
radical committed Sep 25, 2021
commit d17bc64fe47e6fd668ac1b138e49983a7f0acd44
41 changes: 31 additions & 10 deletions src/tasks/WasmAppBuilder/PInvokeTableGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,23 @@ private void EmitPInvokeTable(StreamWriter w, Dictionary<string, string> modules
w.WriteLine();

var decls = new HashSet<string>();
foreach (var pinvoke in pinvokes.OrderBy(l => l.EntryPoint))
// FIXME: handle sigs with different first args
foreach (var group in pinvokes.OrderBy(l => l.EntryPoint).GroupBy(l => l.EntryPoint))
{
IEnumerable<string?>? uniqueSigs = group.Select(l => l.Method.ToString()).Distinct();
bool treatAsVariadic = uniqueSigs.Count() > 1;
if (treatAsVariadic)
{
w.WriteLine($"// Variadic signature created for");
foreach (string? method in uniqueSigs)
w.WriteLine($"// {method}");
}

PInvoke pinvoke = group.First();
if (modules.ContainsKey(pinvoke.Module)) {
try
{
var decl = GenPInvokeDecl(pinvoke);
var decl = GenPInvokeDecl(pinvoke, treatAsVariadic);
if (decls.Contains(decl))
continue;

Expand Down Expand Up @@ -205,7 +216,7 @@ private string MapType (Type t)
return "int";
}

private string GenPInvokeDecl(PInvoke pinvoke)
private string GenPInvokeDecl(PInvoke pinvoke, bool treatAsVariadic=false)
{
var sb = new StringBuilder();
var method = pinvoke.Method;
Expand All @@ -215,15 +226,25 @@ private string GenPInvokeDecl(PInvoke pinvoke)
sb.Append($"int {pinvoke.EntryPoint} (int, int, int, int, int);");
return sb.ToString();
}

sb.Append(MapType(method.ReturnType));
sb.Append($" {pinvoke.EntryPoint} (");
int pindex = 0;
var pars = method.GetParameters();
foreach (var p in pars) {
if (pindex > 0)
sb.Append(',');
sb.Append(MapType(pars[pindex].ParameterType));
pindex++;
if (!treatAsVariadic)
{
int pindex = 0;
var pars = method.GetParameters();
foreach (var p in pars) {
if (pindex > 0)
sb.Append(',');
sb.Append(MapType(pars[pindex].ParameterType));
pindex++;
}
}
else
{
ParameterInfo firstParam = method.GetParameters()[0];
sb.Append(MapType(firstParam.ParameterType));
sb.Append(", ...");
}
sb.Append(");");
return sb.ToString();
Expand Down