Skip to content

Commit 9b06e7b

Browse files
authored
Add C++ WebAssembly ABI (mono#1711)
* Minor code refactorings. * Fix debug assert issue with vtable methods. * Add support for WebAssembly C++ ABI to parser and AST converter.
1 parent db7949b commit 9b06e7b

File tree

18 files changed

+872
-880
lines changed

18 files changed

+872
-880
lines changed

src/AST/ASTContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum CppAbi
1111
Microsoft,
1212
ARM,
1313
iOS,
14-
iOS64
14+
iOS64,
15+
WebAssembly
1516
}
1617

1718
/// <summary>

src/AST/ClassLayout.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ public struct VTableComponent
3131
public Declaration Declaration;
3232

3333
/// Method declaration (if Kind == FunctionPointer).
34-
public Method Method
35-
{
36-
get
37-
{
38-
Debug.Assert(Kind == VTableComponentKind.FunctionPointer);
39-
return Declaration as Method;
40-
}
41-
}
34+
public Method Method => Declaration as Method;
4235
}
4336

4437
/// <summary>

src/CLI/CLI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void Main(string[] args)
288288

289289
Generator gen = new Generator(options);
290290

291-
bool validOptions = gen.ValidateOptions(errorMessages);
291+
var validOptions = gen.ValidateOptions(errorMessages);
292292
PrintErrorMessages(errorMessages);
293293

294294
if (errorMessages.Any() || !validOptions)

src/CLI/Generator.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,13 @@ namespace CppSharp
1313
{
1414
class Generator : ILibrary
1515
{
16-
private Options options = null;
16+
private readonly Options options;
1717
private string triple = "";
1818
private CppAbi abi = CppAbi.Microsoft;
1919

2020
public Generator(Options options)
2121
{
22-
if (options == null)
23-
throw new ArgumentNullException(nameof(options));
24-
25-
this.options = options;
26-
}
27-
28-
static TargetPlatform GetCurrentPlatform()
29-
{
30-
if (Platform.IsWindows)
31-
return TargetPlatform.Windows;
32-
33-
if (Platform.IsMacOS)
34-
return TargetPlatform.MacOS;
35-
36-
if (Platform.IsLinux)
37-
return TargetPlatform.Linux;
38-
39-
throw new System.NotImplementedException("Unknown host platform");
22+
this.options = options ?? throw new ArgumentNullException(nameof(options));
4023
}
4124

4225
void SetupTargetTriple()
@@ -78,8 +61,7 @@ public bool ValidateOptions(List<string> messages)
7861
return false;
7962
}
8063

81-
if (!options.Platform.HasValue)
82-
options.Platform = GetCurrentPlatform();
64+
options.Platform ??= Platform.Host;
8365

8466
if (string.IsNullOrEmpty(options.OutputDir))
8567
{
@@ -189,7 +171,7 @@ public void Postprocess(Driver driver, ASTContext ctx)
189171

190172
public void Run()
191173
{
192-
StringBuilder messageBuilder = new StringBuilder();
174+
var messageBuilder = new StringBuilder();
193175
messageBuilder.Append($"Generating {GetGeneratorKindName(options.Kind)}");
194176
messageBuilder.Append($" bindings for {GetPlatformName(options.Platform)} {options.Architecture}");
195177

src/CppParser/Bindings/CLI/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ namespace CppSharp
256256
Microsoft = 1,
257257
ARM = 2,
258258
iOS = 3,
259-
iOS64 = 4
259+
iOS64 = 4,
260+
WebAssembly = 5
260261
};
261262

262263
public enum class RecordArgABI

src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6301,7 +6301,8 @@ public enum CppAbi
63016301
Microsoft = 1,
63026302
ARM = 2,
63036303
iOS = 3,
6304-
iOS64 = 4
6304+
iOS64 = 4,
6305+
WebAssembly = 5
63056306
}
63066307

63076308
public enum RecordArgABI

src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6301,7 +6301,8 @@ public enum CppAbi
63016301
Microsoft = 1,
63026302
ARM = 2,
63036303
iOS = 3,
6304-
iOS64 = 4
6304+
iOS64 = 4,
6305+
WebAssembly = 5
63056306
}
63066307

63076308
public enum RecordArgABI

src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6301,7 +6301,8 @@ public enum CppAbi
63016301
Microsoft = 1,
63026302
ARM = 2,
63036303
iOS = 3,
6304-
iOS64 = 4
6304+
iOS64 = 4,
6305+
WebAssembly = 5
63056306
}
63066307

63076308
public enum RecordArgABI

src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6301,7 +6301,8 @@ public enum CppAbi
63016301
Microsoft = 1,
63026302
ARM = 2,
63036303
iOS = 3,
6304-
iOS64 = 4
6304+
iOS64 = 4,
6305+
WebAssembly = 5
63056306
}
63066307

63076308
public enum RecordArgABI

src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6301,7 +6301,8 @@ public enum CppAbi
63016301
Microsoft = 1,
63026302
ARM = 2,
63036303
iOS = 3,
6304-
iOS64 = 4
6304+
iOS64 = 4,
6305+
WebAssembly = 5
63056306
}
63066307

63076308
public enum RecordArgABI

src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6301,7 +6301,8 @@ public enum CppAbi
63016301
Microsoft = 1,
63026302
ARM = 2,
63036303
iOS = 3,
6304-
iOS64 = 4
6304+
iOS64 = 4,
6305+
WebAssembly = 5
63056306
}
63066307

63076308
public enum RecordArgABI

0 commit comments

Comments
 (0)