Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ab56290
Add SwiftRuntimeLibrary project
kotlarmilos Feb 14, 2024
49bd30d
Add SyntaxDynamo project
kotlarmilos Feb 14, 2024
8a1a04f
Add SwiftReflector project
kotlarmilos Feb 14, 2024
1876c1a
Add SwiftBindings project
kotlarmilos Feb 14, 2024
1345f05
Add basic testing coverage
kotlarmilos Feb 14, 2024
65dda63
Fix sample application
kotlarmilos Feb 14, 2024
56e96bc
Remove Swift4 demangler
kotlarmilos Feb 16, 2024
9a1753c
Update the BindingsTool class to use System.CommandLine
kotlarmilos Feb 16, 2024
cad936e
Remove SyntaxDynamo.SwiftLang files
kotlarmilos Feb 16, 2024
61aeb9e
Update README.md
kotlarmilos Feb 16, 2024
002ac6a
Remove Swift4 support
kotlarmilos Feb 16, 2024
5ddfc20
Rename verbose argument
kotlarmilos Feb 16, 2024
a352696
Update src/SwiftBindings/tests/CMakeLists.txt
kotlarmilos Feb 16, 2024
91dd9fd
Use ninja generator for cmake
kotlarmilos Feb 16, 2024
0b3f817
Fix lint formatting
kotlarmilos Feb 16, 2024
1da30bd
Update bindings compiler to use a module name and emit pinvokes and s…
kotlarmilos Feb 16, 2024
283938a
Update Microsoft.DotNet.Arcade.Sdk version
kotlarmilos Feb 16, 2024
7262401
Add .sln file
kotlarmilos Feb 19, 2024
aef5b02
Add nuget.org as package source
kotlarmilos Feb 19, 2024
7587908
Remove ninja generator to test the CI
kotlarmilos Feb 19, 2024
799187f
Revert temporary changes
kotlarmilos Feb 19, 2024
d23735a
Update .gitignore
kotlarmilos Feb 19, 2024
b8457c9
Use cmake instead of ninja
kotlarmilos Feb 19, 2024
59a5a65
Use macOS vmImage
kotlarmilos Feb 19, 2024
2866a2e
Don't override SWIFT_PLATFORM_SUFFIX if set
kotlarmilos Feb 19, 2024
ac3f569
Fix SWIFT_COMPILER_TARGET variable
kotlarmilos Feb 19, 2024
62b93c7
Use cmake instead of ninja
kotlarmilos Feb 19, 2024
69ef2e5
Introduce Swift types database
kotlarmilos Feb 19, 2024
99834f5
Temporarily remove SwiftInterfaceReflector from the project
kotlarmilos Feb 21, 2024
4856a8e
Refactor null exceptions to use ArgumentNullException.ThrowIfNull
kotlarmilos Feb 21, 2024
4ba46cb
Update target framework to net8.0
kotlarmilos Feb 21, 2024
497cbe1
Add src and tests directories for projects
kotlarmilos Feb 21, 2024
aed517c
Introduce PInvoke tests
kotlarmilos Feb 22, 2024
442d9ae
Add uniqueId to CompiledAssembly name
kotlarmilos Feb 22, 2024
0574a8b
Update runtimelab.yml pipeline configuration
kotlarmilos Feb 22, 2024
919f7ce
Change osGroup from Linux to OSX in runtimelab.yml
kotlarmilos Feb 22, 2024
276918e
Add sample bindings to .gitignore
kotlarmilos Feb 22, 2024
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,15 @@ Session.vim

# VS debug support files
launchSettings.json

# Swift output files
*.swiftinterface*
*.swiftdoc*
*.swiftmodule*
*.abi*
*.swiftsourceinfo*
*.dylib

# Testing artifacts
testing/
src/samples/**/*Bindings.cs
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TargetingPackVersion="$(MicrosoftNETCoreAppVersion)" />
</ItemGroup>

<Import Condition="'$(IsTestProject)' == 'true'" Project="$(RepositoryEngineeringDir)testing\runsettings.targets" />
<!-- <Import Condition="'$(IsTestProject)' == 'true'" Project="$(RepositoryEngineeringDir)testing\runsettings.targets" /> -->

<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
</Project>
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

This is a collection of tools designed to consume a compiled Apple Swift library and generate bindings and wrappers that enable it to be used as a .NET library.

## Current Status

The components are currently undergoing iterative reviews and will be moved from https://github.com/xamarin/binding-tools-for-swift.
## Installation and usage

The tool will be available as a NuGet CLI package in the [`dotnet-experimental`](https://dev.azure.com/dnceng/public/_packaging?_a=feed&feed=dotnet-experimental) feed.

Options:
```
-d, --dylib Required. Path to the dynamic library.
-s, --swiftinterface Required. Path to the Swift interface file.
-o, --output Required. Output directory for generated bindings.
-v, --verbose Information about work in process.
-h, --help Display this help message.
```

## .NET Foundation

Expand Down
132 changes: 132 additions & 0 deletions SwiftBindings.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftBindings", "src\SwiftBindings\src\SwiftBindings.csproj", "{B7977360-6671-4707-9A1C-1C29D5BE2674}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftBindings.Tests", "src\SwiftBindings\tests\SwiftBindings.Tests.csproj", "{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftReflector.Tests", "src\SwiftReflector\tests\SwiftReflector.Tests.csproj", "{1C381A63-38D7-4801-97CB-5FA7F683E28A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftReflector", "src\SwiftReflector\src\SwiftReflector.csproj", "{EF015979-24E8-490E-B940-F28988EC5C19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftRuntimeLibrary", "src\SwiftRuntimeLibrary\src\SwiftRuntimeLibrary.csproj", "{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftRuntimeLibrary.Tests", "src\SwiftRuntimeLibrary\tests\SwiftRuntimeLibrary.Tests.csproj", "{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyntaxDynamo", "src\SyntaxDynamo\src\SyntaxDynamo.csproj", "{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyntaxDynamo.Tests", "src\SyntaxDynamo\tests\SyntaxDynamo.Tests.csproj", "{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Debug|x64.Build.0 = Debug|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Debug|x86.ActiveCfg = Debug|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Debug|x86.Build.0 = Debug|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Release|Any CPU.Build.0 = Release|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Release|x64.ActiveCfg = Release|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Release|x64.Build.0 = Release|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Release|x86.ActiveCfg = Release|Any CPU
{B7977360-6671-4707-9A1C-1C29D5BE2674}.Release|x86.Build.0 = Release|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Debug|x64.ActiveCfg = Debug|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Debug|x64.Build.0 = Debug|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Debug|x86.ActiveCfg = Debug|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Debug|x86.Build.0 = Debug|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Release|Any CPU.Build.0 = Release|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Release|x64.ActiveCfg = Release|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Release|x64.Build.0 = Release|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Release|x86.ActiveCfg = Release|Any CPU
{CE81B6BD-CCCC-4223-9069-B28435A4A5C1}.Release|x86.Build.0 = Release|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Debug|x64.ActiveCfg = Debug|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Debug|x64.Build.0 = Debug|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Debug|x86.ActiveCfg = Debug|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Debug|x86.Build.0 = Debug|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Release|Any CPU.Build.0 = Release|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Release|x64.ActiveCfg = Release|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Release|x64.Build.0 = Release|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Release|x86.ActiveCfg = Release|Any CPU
{1C381A63-38D7-4801-97CB-5FA7F683E28A}.Release|x86.Build.0 = Release|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Debug|x64.ActiveCfg = Debug|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Debug|x64.Build.0 = Debug|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Debug|x86.ActiveCfg = Debug|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Debug|x86.Build.0 = Debug|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Release|Any CPU.Build.0 = Release|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Release|x64.ActiveCfg = Release|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Release|x64.Build.0 = Release|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Release|x86.ActiveCfg = Release|Any CPU
{EF015979-24E8-490E-B940-F28988EC5C19}.Release|x86.Build.0 = Release|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Debug|x64.ActiveCfg = Debug|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Debug|x64.Build.0 = Debug|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Debug|x86.ActiveCfg = Debug|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Debug|x86.Build.0 = Debug|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Release|x64.ActiveCfg = Release|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Release|x64.Build.0 = Release|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Release|x86.ActiveCfg = Release|Any CPU
{8E9013BE-01BD-4F4C-8BF7-E8C71FA6608E}.Release|x86.Build.0 = Release|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Debug|x64.ActiveCfg = Debug|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Debug|x64.Build.0 = Debug|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Debug|x86.ActiveCfg = Debug|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Debug|x86.Build.0 = Debug|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Release|Any CPU.Build.0 = Release|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Release|x64.ActiveCfg = Release|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Release|x64.Build.0 = Release|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Release|x86.ActiveCfg = Release|Any CPU
{61F74BC6-1CCA-49FA-B5B8-6C9EABC1D0AB}.Release|x86.Build.0 = Release|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Debug|x64.ActiveCfg = Debug|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Debug|x64.Build.0 = Debug|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Debug|x86.ActiveCfg = Debug|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Debug|x86.Build.0 = Debug|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Release|Any CPU.Build.0 = Release|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Release|x64.ActiveCfg = Release|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Release|x64.Build.0 = Release|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Release|x86.ActiveCfg = Release|Any CPU
{E05ECC4A-7212-4077-AD30-E4183CA3C1AF}.Release|x86.Build.0 = Release|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Debug|x64.ActiveCfg = Debug|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Debug|x64.Build.0 = Debug|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Debug|x86.ActiveCfg = Debug|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Debug|x86.Build.0 = Debug|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Release|Any CPU.Build.0 = Release|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Release|x64.ActiveCfg = Release|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Release|x64.Build.0 = Release|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Release|x86.ActiveCfg = Release|Any CPU
{0C13F0AC-76F1-4FCB-AF42-9CB910A9471B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<UsingToolXliff>false</UsingToolXliff>
<!-- Libs -->
<MicrosoftNETTestSdkVersion>16.7.1</MicrosoftNETTestSdkVersion>
<XUnitVersion>2.4.1</XUnitVersion>
<XUnitVersion>2.4.2</XUnitVersion>
<XUnitRunnerVisualStudioVersion>2.4.3</XUnitRunnerVisualStudioVersion>
<!-- Set the custom NETCoreApp version -->
<MicrosoftNETCoreAppVersion>7.0.0-preview.7.22375.6</MicrosoftNETCoreAppVersion>
Expand Down
27 changes: 22 additions & 5 deletions eng/pipelines/runtimelab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,33 @@ stages:
- stage: build
displayName: Build
jobs:
- template: /eng/pipelines/templates/build-job.yml
parameters:
osGroup: OSX
archType: x64
${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- template: /eng/pipelines/templates/build-job.yml
parameters:
osGroup: OSX
archType: x64
isOfficialBuild: true
runTests: false
pool:
vmImage: 'macOS-latest'

- ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
- template: /eng/pipelines/templates/build-job.yml
parameters:
osGroup: OSX
archType: arm64
runTests: true
pool:
vmImage: 'macOS-latest'

- template: /eng/pipelines/templates/build-job.yml
parameters:
osGroup: OSX
archType: x64
runTests: true
pool:
vmImage: 'macOS-latest'

# Publish and validation steps. Only run in official builds
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- template: \eng\common\templates\post-build\post-build.yml
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"dotnet": "8.0.100"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24102.4"
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.22430.3"
}
}
48 changes: 0 additions & 48 deletions src/SwiftBindings/SwiftBindings.sln

This file was deleted.

59 changes: 59 additions & 0 deletions src/SwiftBindings/src/BindingsCompiler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using SyntaxDynamo;
using SyntaxDynamo.CSLang;
using SwiftReflector.SwiftXmlReflection;
using SwiftReflector.TypeMapping;

namespace SwiftReflector
{
public class BindingsCompiler
{
UnicodeMapper UnicodeMapper;
TypeMapper TypeMapper;
FunctionCompiler TLFCompiler;

public BindingsCompiler()
{
UnicodeMapper = new UnicodeMapper();
TypeMapper = new TypeMapper(null, UnicodeMapper);
TLFCompiler = new FunctionCompiler(TypeMapper);
}

public void CompileModule(ModuleDeclaration decl, string outputDirectory, ErrorHandling errors)
{
var namespaceName = $"{decl.Name}Bindings";
var csNamespace = new CSNamespace(namespaceName);
var csUsingPackages = new CSUsingPackages("System", "System.Runtime.InteropServices");
var csClass = new CSClass(CSVisibility.Public, decl.Name);

var csFile = new CSFile(csUsingPackages, new CSNamespace[] { csNamespace });
csNamespace.Block.Add(csClass);
IEnumerable<CSMethod> methods = CompileFunctions(decl.Functions, errors);
csClass.Methods.AddRange(methods);

string csOutputPath = Path.Combine(outputDirectory, string.Format("{0}.cs", namespaceName));
CodeWriter.WriteToFile(csOutputPath, csFile);
}

IEnumerable<CSMethod> CompileFunctions(IEnumerable<FunctionDeclaration> decls, ErrorHandling errors)
{
List<CSMethod> methods = new List<CSMethod>();
foreach (FunctionDeclaration decl in decls)
{
var piMethod = TLFCompiler.CompileMethod(decl, true);
methods.Add(piMethod);
var publicMethod = TLFCompiler.CompileMethod(decl, false);
methods.Add(publicMethod);

var marshaler = new MarshalEngine(null, null, TypeMapper, null);
var lines = marshaler.MarshalFunctionCall(decl, publicMethod, piMethod);
publicMethod.Body.AddRange(lines);
}

return methods;
}
}
}
Loading