Skip to content

Add C++ WebAssembly ABI #1711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/AST/ASTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum CppAbi
Microsoft,
ARM,
iOS,
iOS64
iOS64,
WebAssembly
}

/// <summary>
Expand Down
9 changes: 1 addition & 8 deletions src/AST/ClassLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ public struct VTableComponent
public Declaration Declaration;

/// Method declaration (if Kind == FunctionPointer).
public Method Method
{
get
{
Debug.Assert(Kind == VTableComponentKind.FunctionPointer);
return Declaration as Method;
}
}
public Method Method => Declaration as Method;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/CLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static void Main(string[] args)

Generator gen = new Generator(options);

bool validOptions = gen.ValidateOptions(errorMessages);
var validOptions = gen.ValidateOptions(errorMessages);
PrintErrorMessages(errorMessages);

if (errorMessages.Any() || !validOptions)
Expand Down
26 changes: 4 additions & 22 deletions src/CLI/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,13 @@ namespace CppSharp
{
class Generator : ILibrary
{
private Options options = null;
private readonly Options options;
private string triple = "";
private CppAbi abi = CppAbi.Microsoft;

public Generator(Options options)
{
if (options == null)
throw new ArgumentNullException(nameof(options));

this.options = options;
}

static TargetPlatform GetCurrentPlatform()
{
if (Platform.IsWindows)
return TargetPlatform.Windows;

if (Platform.IsMacOS)
return TargetPlatform.MacOS;

if (Platform.IsLinux)
return TargetPlatform.Linux;

throw new System.NotImplementedException("Unknown host platform");
this.options = options ?? throw new ArgumentNullException(nameof(options));
}

void SetupTargetTriple()
Expand Down Expand Up @@ -78,8 +61,7 @@ public bool ValidateOptions(List<string> messages)
return false;
}

if (!options.Platform.HasValue)
options.Platform = GetCurrentPlatform();
options.Platform ??= Platform.Host;

if (string.IsNullOrEmpty(options.OutputDir))
{
Expand Down Expand Up @@ -189,7 +171,7 @@ public void Postprocess(Driver driver, ASTContext ctx)

public void Run()
{
StringBuilder messageBuilder = new StringBuilder();
var messageBuilder = new StringBuilder();
messageBuilder.Append($"Generating {GetGeneratorKindName(options.Kind)}");
messageBuilder.Append($" bindings for {GetPlatformName(options.Platform)} {options.Architecture}");

Expand Down
3 changes: 2 additions & 1 deletion src/CppParser/Bindings/CLI/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ namespace CppSharp
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
};

public enum class RecordArgABI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,8 @@ public enum CppAbi
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
}

public enum RecordArgABI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,8 @@ public enum CppAbi
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
}

public enum RecordArgABI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,8 @@ public enum CppAbi
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
}

public enum RecordArgABI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,8 @@ public enum CppAbi
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
}

public enum RecordArgABI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,8 @@ public enum CppAbi
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
}

public enum RecordArgABI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,8 @@ public enum CppAbi
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
iOS64 = 4,
WebAssembly = 5
}

public enum RecordArgABI
Expand Down
Loading