diff --git a/.editorconfig b/.editorconfig index 3467ebf9..1909f880 100644 --- a/.editorconfig +++ b/.editorconfig @@ -21,6 +21,9 @@ end_of_line = lf insert_final_newline = true indent_style = space indent_size = 4 +spelling_error_severity = information +spelling_exclusion_path = exclusion.dic +spelling_languages = en-us tab_width = 4 trim_trailing_whitespace = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 879ec8fe..42c3c0bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,26 +28,6 @@ jobs: ./artifacts/pkg/**/* ./artifacts/tst/**/* if-no-files-found: error - windows-x86: - runs-on: ${{ matrix.os }}-latest - strategy: - matrix: - architecture: [ x86 ] - configuration: [ debug, release ] - os: [ windows ] - steps: - - uses: actions/checkout@v3 - - run: ./scripts/cibuild.cmd -configuration ${{ matrix.configuration }} -architecture ${{ matrix.architecture }} /p:PlatformTarget=${{ matrix.architecture }} - shell: cmd - - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }} - path: | - ./artifacts/bin/**/* - ./artifacts/log/**/* - ./artifacts/pkg/**/* - ./artifacts/tst/**/* - if-no-files-found: error linux-x64: runs-on: ${{ matrix.os }}-latest strategy: @@ -120,8 +100,8 @@ jobs: path: ./artifacts - uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' - - run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.0-beta.23063.3 + global-json-file: ./global.json + - run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3 - run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --timestamp-url "http://timestamp.digicert.com" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "LLVMSharp" --description-url "https://github.com/dotnet/llvmsharp" --azure-key-vault-certificate "${{ secrets.SC_KEY_VAULT_CERTIFICATE_ID }}" --azure-key-vault-client-id "${{ secrets.SC_AZURE_CLIENT_ID }}" --azure-key-vault-client-secret "${{ secrets.SC_AZURE_CLIENT_SECRET }}" --azure-key-vault-tenant-id "${{ secrets.SC_AZURE_TENANT_ID }}" --azure-key-vault-url "${{ secrets.SC_KEY_VAULT_URL }}" - uses: actions/upload-artifact@v3 with: @@ -161,8 +141,8 @@ jobs: path: ./artifacts - uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' - - run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.0-beta.23063.3 + global-json-file: ./global.json + - run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3 - run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --timestamp-url "http://timestamp.digicert.com" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "LLVMSharp" --description-url "https://github.com/dotnet/llvmsharp" --azure-key-vault-certificate "${{ secrets.SC_KEY_VAULT_CERTIFICATE_ID }}" --azure-key-vault-client-id "${{ secrets.SC_AZURE_CLIENT_ID }}" --azure-key-vault-client-secret "${{ secrets.SC_AZURE_CLIENT_SECRET }}" --azure-key-vault-tenant-id "${{ secrets.SC_AZURE_TENANT_ID }}" --azure-key-vault-url "${{ secrets.SC_KEY_VAULT_URL }}" - uses: actions/upload-artifact@v3 with: @@ -173,15 +153,15 @@ jobs: publish-nightlies-azure: runs-on: ubuntu-latest if: ${{ github.event_name == 'push' }} - needs: [ windows-x64, windows-x86, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ] + needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ] steps: - uses: actions/download-artifact@v3 with: name: windows_release_x64 path: ./artifacts - - uses: actions/setup-dotnet@v2 + - uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' + dotnet-version: '8.0.x' source-url: https://pkgs.clangsharp.dev/index.json env: NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }} @@ -189,13 +169,13 @@ jobs: publish-nightlies-github: runs-on: ubuntu-latest if: false - needs: [ windows-x64, windows-x86, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ] + needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ] steps: - uses: actions/download-artifact@v3 with: name: windows_release_x64 path: ./artifacts - - uses: actions/setup-dotnet@v2 + - uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' + dotnet-version: '8.0.x' - run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --source https://nuget.pkg.github.com/dotnet/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate diff --git a/Directory.Build.props b/Directory.Build.props index 2ed113b7..cf22ba2a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -20,7 +20,7 @@ true - preview + latest-all $(BaseArtifactsPath)obj/$(BaseArtifactsPathSuffix)/ embedded false @@ -42,7 +42,9 @@ $(BaseArtifactsPath)bin/$(BaseArtifactsPathSuffix)/ .NET Foundation true + true $(BaseArtifactsPath)pkg/$(Configuration)/ + 16.0.0 LLVMSharp LLVMSharp 16.0.0 diff --git a/Directory.Build.targets b/Directory.Build.targets index ee04b707..db24925f 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -12,7 +12,7 @@ - $(NoWarn);AD0001 + $(NoWarn) @@ -26,7 +26,7 @@ - + true true diff --git a/LLVMSharp.sln b/LLVMSharp.sln index dd175a68..e0d4fe14 100644 --- a/LLVMSharp.sln +++ b/LLVMSharp.sln @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets Directory.Packages.props = Directory.Packages.props + exclusion.dic = exclusion.dic + global.json = global.json LICENSE.md = LICENSE.md NOTICE.md = NOTICE.md NuGet.config = NuGet.config diff --git a/exclusion.dic b/exclusion.dic new file mode 100644 index 00000000..29aceb68 --- /dev/null +++ b/exclusion.dic @@ -0,0 +1,15 @@ +addr +aliasee +alloca +attrs +bitcode +dest +funclet +greaterthan +instr +interp +lshift +netscripten +trunc +vals +xchg diff --git a/global.json b/global.json new file mode 100644 index 00000000..61d88a71 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "8.0.100", + "allowPrerelease": true, + "rollForward": "latestFeature" + } +} diff --git a/samples/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj b/samples/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj index 725b5d7c..0c3ad700 100644 --- a/samples/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj +++ b/samples/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj @@ -1,6 +1,6 @@  - net6.0;net7.0 + net8.0 diff --git a/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj b/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj index f4f4e34a..3bf1f997 100644 --- a/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj +++ b/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 diff --git a/samples/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj b/samples/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj index 725b5d7c..0c3ad700 100644 --- a/samples/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj +++ b/samples/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj @@ -1,6 +1,6 @@  - net6.0;net7.0 + net8.0 diff --git a/samples/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj b/samples/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj index f4f4e34a..3bf1f997 100644 --- a/samples/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj +++ b/samples/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 diff --git a/samples/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj b/samples/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj index 725b5d7c..0c3ad700 100644 --- a/samples/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj +++ b/samples/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj @@ -1,6 +1,6 @@  - net6.0;net7.0 + net8.0 diff --git a/samples/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj b/samples/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj index f4f4e34a..3bf1f997 100644 --- a/samples/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj +++ b/samples/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 28b21532..09ce84b3 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -123,8 +123,7 @@ try { $DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet" Create-Directory -Path $DotNetInstallDirectory - & $DotNetInstallScript -Channel 6.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture - & $DotNetInstallScript -Channel 7.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture + & $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture $env:PATH="$DotNetInstallDirectory;$env:PATH" } diff --git a/scripts/build.sh b/scripts/build.sh index f59e51a0..9c2e6648 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -204,8 +204,7 @@ if [[ ! -z "$architecture" ]]; then DotNetInstallDirectory="$ArtifactsDir/dotnet" CreateDirectory "$DotNetInstallDirectory" - . "$DotNetInstallScript" --channel 6.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" - . "$DotNetInstallScript" --channel 7.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" + . "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" PATH="$DotNetInstallDirectory:$PATH:" fi diff --git a/sources/Directory.Build.props b/sources/Directory.Build.props index 41533283..785d282c 100644 --- a/sources/Directory.Build.props +++ b/sources/Directory.Build.props @@ -12,6 +12,7 @@ true + false sources @@ -21,8 +22,4 @@ - - - - diff --git a/sources/LLVMSharp.Interop/Configuration.cs b/sources/LLVMSharp.Interop/Configuration.cs new file mode 100644 index 00000000..541700a7 --- /dev/null +++ b/sources/LLVMSharp.Interop/Configuration.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System; +using System.Runtime.InteropServices; + +[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)] + +namespace LLVMSharp.Interop; + +internal static class Configuration +{ + private static readonly bool s_disableResolveLibraryHook = GetAppContextData("LLVMSharp.Interop.DisableResolveLibraryHook", defaultValue: false); + + public static bool DisableResolveLibraryHook => s_disableResolveLibraryHook; + + private static bool GetAppContextData(string name, bool defaultValue) + { + object? data = AppContext.GetData(name); + + if (data is bool value) + { + return value; + } + else if ((data is string s) && bool.TryParse(s, out bool result)) + { + return result; + } + else + { + return defaultValue; + } + } +} diff --git a/sources/LLVMSharp.Interop/Extensions/LLVM.ResolveLibrary.cs b/sources/LLVMSharp.Interop/Extensions/LLVM.ResolveLibrary.cs index 3f5ad660..a4901b6f 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVM.ResolveLibrary.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVM.ResolveLibrary.cs @@ -3,8 +3,11 @@ using System; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +[assembly: DisableRuntimeMarshalling] + namespace LLVMSharp.Interop; public static unsafe partial class LLVM @@ -13,36 +16,53 @@ public static unsafe partial class LLVM static LLVM() { - NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), OnDllImport); + if (!Configuration.DisableResolveLibraryHook) + { + NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), OnDllImport); + } } private static IntPtr OnDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) { - return TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary) - ? nativeLibrary - : libraryName.Equals("libLLVM") && TryResolveLLVM(assembly, searchPath, out nativeLibrary) - ? nativeLibrary - : IntPtr.Zero; + if (TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary)) + { + return nativeLibrary; + } + + if (libraryName.Equals("libLLVM", StringComparison.Ordinal) && TryResolveLLVM(assembly, searchPath, out nativeLibrary)) + { + return nativeLibrary; + } + + return IntPtr.Zero; } private static bool TryResolveLLVM(Assembly assembly, DllImportSearchPath? searchPath, out IntPtr nativeLibrary) { - return (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM.so.14", assembly, searchPath, out nativeLibrary)) - || (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM-14", assembly, searchPath, out nativeLibrary)) - || (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM.so.1", assembly, searchPath, out nativeLibrary)) - || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeLibrary.TryLoad("LLVM-C.dll", assembly, searchPath, out nativeLibrary)) - || NativeLibrary.TryLoad("libLLVM", assembly, searchPath, out nativeLibrary); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return NativeLibrary.TryLoad("libLLVM.so.16", assembly, searchPath, out nativeLibrary) + || NativeLibrary.TryLoad("libLLVM-16", assembly, searchPath, out nativeLibrary) + || NativeLibrary.TryLoad("libLLVM.so.1", assembly, searchPath, out nativeLibrary); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return NativeLibrary.TryLoad("LLVM-C.dll", assembly, searchPath, out nativeLibrary); + } + + nativeLibrary = IntPtr.Zero; + return false; } private static bool TryResolveLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr nativeLibrary) { var resolveLibrary = ResolveLibrary; - if (resolveLibrary != null) + if (resolveLibrary is not null) { - var resolvers = resolveLibrary.GetInvocationList(); + var resolvers = resolveLibrary.GetInvocationList().Cast(); - foreach (DllImportResolver resolver in resolvers.Cast()) + foreach (DllImportResolver resolver in resolvers) { nativeLibrary = resolver(libraryName, assembly, searchPath); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs index 07d167e3..08154b3c 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMAttributeRef : IEquatable +public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMAttributeRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public readonly uint Kind => LLVM.GetEnumAttributeKind(this); @@ -25,11 +20,11 @@ public LLVMAttributeRef(IntPtr handle) public static bool operator !=(LLVMAttributeRef left, LLVMAttributeRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMAttributeRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMAttributeRef other) && Equals(other); - public bool Equals(LLVMAttributeRef other) => this == other; + public readonly bool Equals(LLVMAttributeRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMAttributeRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMAttributeRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs index 5367ee84..d6bd9a9a 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBasicBlockRef.cs @@ -4,26 +4,21 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMBasicBlockRef : IEquatable +public unsafe partial struct LLVMBasicBlockRef(IntPtr handle) : IEquatable { - public IntPtr Handle; + public IntPtr Handle = handle; - public LLVMBasicBlockRef(IntPtr handle) - { - Handle = handle; - } - - public LLVMValueRef FirstInstruction => (Handle != IntPtr.Zero) ? LLVM.GetFirstInstruction(this) : default; + public readonly LLVMValueRef FirstInstruction => (Handle != IntPtr.Zero) ? LLVM.GetFirstInstruction(this) : default; - public LLVMValueRef LastInstruction => (Handle != IntPtr.Zero) ? LLVM.GetLastInstruction(this) : default; + public readonly LLVMValueRef LastInstruction => (Handle != IntPtr.Zero) ? LLVM.GetLastInstruction(this) : default; - public LLVMBasicBlockRef Next => (Handle != IntPtr.Zero) ? LLVM.GetNextBasicBlock(this) : default; + public readonly LLVMBasicBlockRef Next => (Handle != IntPtr.Zero) ? LLVM.GetNextBasicBlock(this) : default; - public LLVMValueRef Parent => (Handle != IntPtr.Zero) ? LLVM.GetBasicBlockParent(this) : default; + public readonly LLVMValueRef Parent => (Handle != IntPtr.Zero) ? LLVM.GetBasicBlockParent(this) : default; - public LLVMBasicBlockRef Previous => (Handle != IntPtr.Zero) ? LLVM.GetPreviousBasicBlock(this) : default; + public readonly LLVMBasicBlockRef Previous => (Handle != IntPtr.Zero) ? LLVM.GetPreviousBasicBlock(this) : default; - public LLVMValueRef Terminator => (Handle != IntPtr.Zero) ? LLVM.GetBasicBlockTerminator(this) : default; + public readonly LLVMValueRef Terminator => (Handle != IntPtr.Zero) ? LLVM.GetBasicBlockTerminator(this) : default; public static explicit operator LLVMBasicBlockRef(LLVMOpaqueValue* value) => new LLVMBasicBlockRef((IntPtr)value); @@ -61,31 +56,31 @@ public static LLVMBasicBlockRef InsertInContext(LLVMContextRef C, LLVMBasicBlock return LLVM.InsertBasicBlockInContext(C, BB, marshaledName); } - public LLVMValueRef AsValue() => LLVM.BasicBlockAsValue(this); + public readonly LLVMValueRef AsValue() => LLVM.BasicBlockAsValue(this); - public void Delete() => LLVM.DeleteBasicBlock(this); + public readonly void Delete() => LLVM.DeleteBasicBlock(this); - public void Dump() => LLVM.DumpValue(this); + public readonly void Dump() => LLVM.DumpValue(this); - public override bool Equals(object? obj) => (obj is LLVMBasicBlockRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMBasicBlockRef other) && Equals(other); - public bool Equals(LLVMBasicBlockRef other) => this == other; + public readonly bool Equals(LLVMBasicBlockRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public LLVMBasicBlockRef InsertBasicBlock(string Name) => InsertBasicBlock(Name.AsSpan()); + public readonly LLVMBasicBlockRef InsertBasicBlock(string Name) => InsertBasicBlock(Name.AsSpan()); - public LLVMBasicBlockRef InsertBasicBlock(ReadOnlySpan Name) + public readonly LLVMBasicBlockRef InsertBasicBlock(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.InsertBasicBlock(this, marshaledName); } - public void MoveAfter(LLVMBasicBlockRef MovePos) => LLVM.MoveBasicBlockAfter(this, MovePos); + public readonly void MoveAfter(LLVMBasicBlockRef MovePos) => LLVM.MoveBasicBlockAfter(this, MovePos); - public void MoveBefore(LLVMBasicBlockRef MovePos) => LLVM.MoveBasicBlockBefore(this, MovePos); + public readonly void MoveBefore(LLVMBasicBlockRef MovePos) => LLVM.MoveBasicBlockBefore(this, MovePos); - public string PrintToString() + public readonly string PrintToString() { var pStr = LLVM.PrintValueToString(this); @@ -99,7 +94,7 @@ public string PrintToString() return result; } - public void RemoveFromParent() => LLVM.RemoveBasicBlockFromParent(this); + public readonly void RemoveFromParent() => LLVM.RemoveBasicBlockFromParent(this); - public override string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; + public override readonly string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBinaryRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBinaryRef.cs index ae7b7729..7e2a3209 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBinaryRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBinaryRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMBinaryRef : IEquatable +public unsafe partial struct LLVMBinaryRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMBinaryRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMBinaryRef(LLVMOpaqueBinary* Comdat) => new LLVMBinaryRef((IntPtr)Comdat); @@ -21,11 +16,11 @@ public LLVMBinaryRef(IntPtr handle) public static bool operator !=(LLVMBinaryRef left, LLVMBinaryRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMBinaryRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMBinaryRef other) && Equals(other); - public bool Equals(LLVMBinaryRef other) => this == other; + public readonly bool Equals(LLVMBinaryRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMBinaryRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMBinaryRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMBuilderRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMBuilderRef.cs index 7e6647e1..faf26e4e 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMBuilderRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMBuilderRef.cs @@ -4,16 +4,11 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMBuilderRef : IDisposable, IEquatable +public unsafe partial struct LLVMBuilderRef(IntPtr handle) : IDisposable, IEquatable { - public IntPtr Handle; + public IntPtr Handle = handle; - public LLVMBuilderRef(IntPtr handle) - { - Handle = handle; - } - - public LLVMValueRef CurrentDebugLocation + public readonly LLVMValueRef CurrentDebugLocation { get { @@ -26,7 +21,7 @@ public LLVMValueRef CurrentDebugLocation } } - public LLVMBasicBlockRef InsertBlock => (Handle != IntPtr.Zero) ? LLVM.GetInsertBlock(this) : default; + public readonly LLVMBasicBlockRef InsertBlock => (Handle != IntPtr.Zero) ? LLVM.GetInsertBlock(this) : default; public static implicit operator LLVMBuilderRef(LLVMOpaqueBuilder* Builder) => new LLVMBuilderRef((IntPtr)Builder); @@ -38,25 +33,25 @@ public LLVMValueRef CurrentDebugLocation public static LLVMBuilderRef Create(LLVMContextRef C) => LLVM.CreateBuilderInContext(C); - public LLVMValueRef BuildAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildAdd(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildAdd(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildAdd(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildAddrSpaceCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildAddrSpaceCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildAddrSpaceCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildAddrSpaceCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildAddrSpaceCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildAddrSpaceCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildAddrSpaceCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildAggregateRet(LLVMValueRef[] RetVals) => BuildAggregateRet(RetVals.AsSpan()); + public readonly LLVMValueRef BuildAggregateRet(LLVMValueRef[] RetVals) => BuildAggregateRet(RetVals.AsSpan()); - public LLVMValueRef BuildAggregateRet(ReadOnlySpan RetVals) + public readonly LLVMValueRef BuildAggregateRet(ReadOnlySpan RetVals) { fixed (LLVMValueRef* pRetVals = RetVals) { @@ -64,69 +59,69 @@ public LLVMValueRef BuildAggregateRet(ReadOnlySpan RetVals) } } - public LLVMValueRef BuildAlloca(LLVMTypeRef Ty, string Name = "") => BuildAlloca(Ty, Name.AsSpan()); + public readonly LLVMValueRef BuildAlloca(LLVMTypeRef Ty, string Name = "") => BuildAlloca(Ty, Name.AsSpan()); - public LLVMValueRef BuildAlloca(LLVMTypeRef Ty, ReadOnlySpan Name) + public readonly LLVMValueRef BuildAlloca(LLVMTypeRef Ty, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildAlloca(this, Ty, marshaledName); } - public LLVMValueRef BuildAnd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildAnd(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildAnd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildAnd(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildAnd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildAnd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildAnd(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildArrayAlloca(LLVMTypeRef Ty, LLVMValueRef Val, string Name = "") => BuildArrayAlloca(Ty, Val, Name.AsSpan()); + public readonly LLVMValueRef BuildArrayAlloca(LLVMTypeRef Ty, LLVMValueRef Val, string Name = "") => BuildArrayAlloca(Ty, Val, Name.AsSpan()); - public LLVMValueRef BuildArrayAlloca(LLVMTypeRef Ty, LLVMValueRef Val, ReadOnlySpan Name) + public readonly LLVMValueRef BuildArrayAlloca(LLVMTypeRef Ty, LLVMValueRef Val, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildArrayAlloca(this, Ty, Val, marshaledName); } - public LLVMValueRef BuildArrayMalloc(LLVMTypeRef Ty, LLVMValueRef Val, string Name = "") => BuildArrayMalloc(Ty, Val, Name.AsSpan()); + public readonly LLVMValueRef BuildArrayMalloc(LLVMTypeRef Ty, LLVMValueRef Val, string Name = "") => BuildArrayMalloc(Ty, Val, Name.AsSpan()); - public LLVMValueRef BuildArrayMalloc(LLVMTypeRef Ty, LLVMValueRef Val, ReadOnlySpan Name) + public readonly LLVMValueRef BuildArrayMalloc(LLVMTypeRef Ty, LLVMValueRef Val, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildArrayMalloc(this, Ty, Val, marshaledName); } - public LLVMValueRef BuildAShr(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildAShr(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildAShr(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildAShr(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildAShr(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildAShr(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildAShr(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildAtomicRMW(LLVMAtomicRMWBinOp op, LLVMValueRef PTR, LLVMValueRef Val, LLVMAtomicOrdering ordering, bool singleThread) => LLVM.BuildAtomicRMW(this, op, PTR, Val, ordering, singleThread ? 1 : 0); + public readonly LLVMValueRef BuildAtomicRMW(LLVMAtomicRMWBinOp op, LLVMValueRef PTR, LLVMValueRef Val, LLVMAtomicOrdering ordering, bool singleThread) => LLVM.BuildAtomicRMW(this, op, PTR, Val, ordering, singleThread ? 1 : 0); - public LLVMValueRef BuildBinOp(LLVMOpcode Op, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildBinOp(Op, LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildBinOp(LLVMOpcode Op, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildBinOp(Op, LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildBinOp(LLVMOpcode Op, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildBinOp(LLVMOpcode Op, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildBinOp(this, Op, LHS, RHS, marshaledName); } - public LLVMValueRef BuildBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildBitCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildBitCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildBitCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildBr(LLVMBasicBlockRef Dest) => LLVM.BuildBr(this, Dest); + public readonly LLVMValueRef BuildBr(LLVMBasicBlockRef Dest) => LLVM.BuildBr(this, Dest); - public LLVMValueRef BuildCall2(LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef[] Args, string Name = "") => BuildCall2(Ty, Fn, Args.AsSpan(), Name.AsSpan()); + public readonly LLVMValueRef BuildCall2(LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef[] Args, string Name = "") => BuildCall2(Ty, Fn, Args.AsSpan(), Name.AsSpan()); - public LLVMValueRef BuildCall2(LLVMTypeRef Ty, LLVMValueRef Fn, ReadOnlySpan Args, ReadOnlySpan Name) + public readonly LLVMValueRef BuildCall2(LLVMTypeRef Ty, LLVMValueRef Fn, ReadOnlySpan Args, ReadOnlySpan Name) { fixed (LLVMValueRef* pArgs = Args) { @@ -135,157 +130,157 @@ public LLVMValueRef BuildCall2(LLVMTypeRef Ty, LLVMValueRef Fn, ReadOnlySpan BuildCast(Op, Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildCast(LLVMOpcode Op, LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildCast(Op, Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildCast(LLVMOpcode Op, LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildCast(LLVMOpcode Op, LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildCast(this, Op, Val, DestTy, marshaledName); } - public LLVMValueRef BuildCondBr(LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) => LLVM.BuildCondBr(this, If, Then, Else); + public readonly LLVMValueRef BuildCondBr(LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) => LLVM.BuildCondBr(this, If, Then, Else); - public LLVMValueRef BuildExactSDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildExactSDiv(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildExactSDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildExactSDiv(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildExactSDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildExactSDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildExactSDiv(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildExtractElement(LLVMValueRef VecVal, LLVMValueRef Index, string Name = "") => BuildExtractElement(VecVal, Index, Name.AsSpan()); + public readonly LLVMValueRef BuildExtractElement(LLVMValueRef VecVal, LLVMValueRef Index, string Name = "") => BuildExtractElement(VecVal, Index, Name.AsSpan()); - public LLVMValueRef BuildExtractElement(LLVMValueRef VecVal, LLVMValueRef Index, ReadOnlySpan Name) + public readonly LLVMValueRef BuildExtractElement(LLVMValueRef VecVal, LLVMValueRef Index, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildExtractElement(this, VecVal, Index, marshaledName); } - public LLVMValueRef BuildExtractValue(LLVMValueRef AggVal, uint Index, string Name = "") => BuildExtractValue(AggVal, Index, Name.AsSpan()); + public readonly LLVMValueRef BuildExtractValue(LLVMValueRef AggVal, uint Index, string Name = "") => BuildExtractValue(AggVal, Index, Name.AsSpan()); - public LLVMValueRef BuildExtractValue(LLVMValueRef AggVal, uint Index, ReadOnlySpan Name) + public readonly LLVMValueRef BuildExtractValue(LLVMValueRef AggVal, uint Index, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildExtractValue(this, AggVal, Index, marshaledName); } - public LLVMValueRef BuildFAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFAdd(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildFAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFAdd(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildFAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFAdd(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildFCmp(LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFCmp(Op, LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildFCmp(LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFCmp(Op, LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildFCmp(LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFCmp(LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFCmp(this, Op, LHS, RHS, marshaledName); } - public LLVMValueRef BuildFDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFDiv(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildFDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFDiv(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildFDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFDiv(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildFence(LLVMAtomicOrdering ordering, bool singleThread, string Name = "") => BuildFence(ordering, singleThread, Name.AsSpan()); + public readonly LLVMValueRef BuildFence(LLVMAtomicOrdering ordering, bool singleThread, string Name = "") => BuildFence(ordering, singleThread, Name.AsSpan()); - public LLVMValueRef BuildFence(LLVMAtomicOrdering ordering, bool singleThread, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFence(LLVMAtomicOrdering ordering, bool singleThread, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFence(this, ordering, singleThread ? 1 : 0, marshaledName); } - public LLVMValueRef BuildFMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFMul(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildFMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFMul(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildFMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFMul(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildFNeg(LLVMValueRef V, string Name = "") => BuildFNeg(V, Name.AsSpan()); + public readonly LLVMValueRef BuildFNeg(LLVMValueRef V, string Name = "") => BuildFNeg(V, Name.AsSpan()); - public LLVMValueRef BuildFNeg(LLVMValueRef V, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFNeg(LLVMValueRef V, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFNeg(this, V, marshaledName); } - public LLVMValueRef BuildFPCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildFPCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildFPCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFPCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFPCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildFPExt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildFPExt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildFPExt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFPExt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFPExt(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildFPToSI(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPToSI(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildFPToSI(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPToSI(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildFPToSI(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFPToSI(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFPToSI(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildFPToUI(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPToUI(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildFPToUI(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPToUI(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildFPToUI(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFPToUI(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFPToUI(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildFPTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPTrunc(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildFPTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildFPTrunc(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildFPTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFPTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFPTrunc(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildFree(LLVMValueRef PointerVal) => LLVM.BuildFree(this, PointerVal); + public readonly LLVMValueRef BuildFree(LLVMValueRef PointerVal) => LLVM.BuildFree(this, PointerVal); - public LLVMValueRef BuildFreeze(LLVMValueRef Val, string Name = "") => BuildFreeze(Val, Name.AsSpan()); + public readonly LLVMValueRef BuildFreeze(LLVMValueRef Val, string Name = "") => BuildFreeze(Val, Name.AsSpan()); - public LLVMValueRef BuildFreeze(LLVMValueRef Val, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFreeze(LLVMValueRef Val, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFreeze(this, Val, marshaledName); } - public LLVMValueRef BuildFRem(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFRem(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildFRem(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFRem(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildFRem(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFRem(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFRem(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildFSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFSub(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildFSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildFSub(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildFSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildFSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildFSub(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, LLVMValueRef[] Indices, string Name = "") => BuildGEP2(Ty, Pointer, Indices.AsSpan(), Name.AsSpan()); + public readonly LLVMValueRef BuildGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, LLVMValueRef[] Indices, string Name = "") => BuildGEP2(Ty, Pointer, Indices.AsSpan(), Name.AsSpan()); - public LLVMValueRef BuildGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, ReadOnlySpan Indices, ReadOnlySpan Name) + public readonly LLVMValueRef BuildGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, ReadOnlySpan Indices, ReadOnlySpan Name) { fixed (LLVMValueRef* pIndices = Indices) { @@ -294,35 +289,35 @@ public LLVMValueRef BuildGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, ReadOnlySpan } } - public LLVMValueRef BuildGlobalString(string Str, string Name = "") => BuildGlobalString(Str.AsSpan(), Name.AsSpan()); + public readonly LLVMValueRef BuildGlobalString(string Str, string Name = "") => BuildGlobalString(Str.AsSpan(), Name.AsSpan()); - public LLVMValueRef BuildGlobalString(ReadOnlySpan Str, ReadOnlySpan Name) + public readonly LLVMValueRef BuildGlobalString(ReadOnlySpan Str, ReadOnlySpan Name) { using var marshaledStr = new MarshaledString(Str); using var marshaledName = new MarshaledString(Name); return LLVM.BuildGlobalString(this, marshaledStr, marshaledName); } - public LLVMValueRef BuildGlobalStringPtr(string Str, string Name = "") => BuildGlobalStringPtr(Str.AsSpan(), Name.AsSpan()); + public readonly LLVMValueRef BuildGlobalStringPtr(string Str, string Name = "") => BuildGlobalStringPtr(Str.AsSpan(), Name.AsSpan()); - public LLVMValueRef BuildGlobalStringPtr(ReadOnlySpan Str, ReadOnlySpan Name) + public readonly LLVMValueRef BuildGlobalStringPtr(ReadOnlySpan Str, ReadOnlySpan Name) { using var marshaledStr = new MarshaledString(Str); using var marshaledName = new MarshaledString(Name); return LLVM.BuildGlobalStringPtr(this, marshaledStr, marshaledName); } - public LLVMValueRef BuildICmp(LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildICmp(Op, LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildICmp(LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildICmp(Op, LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildICmp(LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildICmp(LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildICmp(this, Op, LHS, RHS, marshaledName); } - public LLVMValueRef BuildInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, LLVMValueRef[] Indices, string Name = "") => BuildInBoundsGEP2(Ty, Pointer, Indices.AsSpan(), Name.AsSpan()); + public readonly LLVMValueRef BuildInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, LLVMValueRef[] Indices, string Name = "") => BuildInBoundsGEP2(Ty, Pointer, Indices.AsSpan(), Name.AsSpan()); - public LLVMValueRef BuildInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, ReadOnlySpan Indices, ReadOnlySpan Name) + public readonly LLVMValueRef BuildInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, ReadOnlySpan Indices, ReadOnlySpan Name) { fixed (LLVMValueRef* pIndices = Indices) { @@ -331,43 +326,43 @@ public LLVMValueRef BuildInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, Read } } - public LLVMValueRef BuildIndirectBr(LLVMValueRef Addr, uint NumDests) => LLVM.BuildIndirectBr(this, Addr, NumDests); + public readonly LLVMValueRef BuildIndirectBr(LLVMValueRef Addr, uint NumDests) => LLVM.BuildIndirectBr(this, Addr, NumDests); - public LLVMValueRef BuildInsertElement(LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, string Name = "") => BuildInsertElement(VecVal, EltVal, Index, Name.AsSpan()); + public readonly LLVMValueRef BuildInsertElement(LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, string Name = "") => BuildInsertElement(VecVal, EltVal, Index, Name.AsSpan()); - public LLVMValueRef BuildInsertElement(LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, ReadOnlySpan Name) + public readonly LLVMValueRef BuildInsertElement(LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildInsertElement(this, VecVal, EltVal, Index, marshaledName); } - public LLVMValueRef BuildInsertValue(LLVMValueRef AggVal, LLVMValueRef EltVal, uint Index, string Name = "") => BuildInsertValue(AggVal, EltVal, Index, Name.AsSpan()); + public readonly LLVMValueRef BuildInsertValue(LLVMValueRef AggVal, LLVMValueRef EltVal, uint Index, string Name = "") => BuildInsertValue(AggVal, EltVal, Index, Name.AsSpan()); - public LLVMValueRef BuildInsertValue(LLVMValueRef AggVal, LLVMValueRef EltVal, uint Index, ReadOnlySpan Name) + public readonly LLVMValueRef BuildInsertValue(LLVMValueRef AggVal, LLVMValueRef EltVal, uint Index, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildInsertValue(this, AggVal, EltVal, Index, marshaledName); } - public LLVMValueRef BuildIntCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildIntCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildIntCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildIntCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildIntCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildIntCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildIntCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildIntToPtr(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildIntToPtr(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildIntToPtr(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildIntToPtr(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildIntToPtr(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildIntToPtr(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildIntToPtr(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildInvoke2(LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef[] Args, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, string Name = "") => BuildInvoke2(Ty, Fn, Args.AsSpan(), Then, Catch, Name.AsSpan()); + public readonly LLVMValueRef BuildInvoke2(LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef[] Args, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, string Name = "") => BuildInvoke2(Ty, Fn, Args.AsSpan(), Then, Catch, Name.AsSpan()); - public LLVMValueRef BuildInvoke2(LLVMTypeRef Ty, LLVMValueRef Fn, ReadOnlySpan Args, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, ReadOnlySpan Name) + public readonly LLVMValueRef BuildInvoke2(LLVMTypeRef Ty, LLVMValueRef Fn, ReadOnlySpan Args, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, ReadOnlySpan Name) { fixed (LLVMValueRef* pArgs = Args) { @@ -376,346 +371,346 @@ public LLVMValueRef BuildInvoke2(LLVMTypeRef Ty, LLVMValueRef Fn, ReadOnlySpan BuildIsNotNull(Val, Name.AsSpan()); + public readonly LLVMValueRef BuildIsNotNull(LLVMValueRef Val, string Name = "") => BuildIsNotNull(Val, Name.AsSpan()); - public LLVMValueRef BuildIsNotNull(LLVMValueRef Val, ReadOnlySpan Name) + public readonly LLVMValueRef BuildIsNotNull(LLVMValueRef Val, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildIsNotNull(this, Val, marshaledName); } - public LLVMValueRef BuildIsNull(LLVMValueRef Val, string Name = "") => BuildIsNull(Val, Name.AsSpan()); + public readonly LLVMValueRef BuildIsNull(LLVMValueRef Val, string Name = "") => BuildIsNull(Val, Name.AsSpan()); - public LLVMValueRef BuildIsNull(LLVMValueRef Val, ReadOnlySpan Name) + public readonly LLVMValueRef BuildIsNull(LLVMValueRef Val, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildIsNull(this, Val, marshaledName); } - public LLVMValueRef BuildLandingPad(LLVMTypeRef Ty, LLVMValueRef PersFn, uint NumClauses, string Name = "") => BuildLandingPad(Ty, PersFn, NumClauses, Name.AsSpan()); + public readonly LLVMValueRef BuildLandingPad(LLVMTypeRef Ty, LLVMValueRef PersFn, uint NumClauses, string Name = "") => BuildLandingPad(Ty, PersFn, NumClauses, Name.AsSpan()); - public LLVMValueRef BuildLandingPad(LLVMTypeRef Ty, LLVMValueRef PersFn, uint NumClauses, ReadOnlySpan Name) + public readonly LLVMValueRef BuildLandingPad(LLVMTypeRef Ty, LLVMValueRef PersFn, uint NumClauses, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildLandingPad(this, Ty, PersFn, NumClauses, marshaledName); } - public LLVMValueRef BuildLoad2(LLVMTypeRef Ty, LLVMValueRef PointerVal, string Name = "") => BuildLoad2(Ty, PointerVal, Name.AsSpan()); + public readonly LLVMValueRef BuildLoad2(LLVMTypeRef Ty, LLVMValueRef PointerVal, string Name = "") => BuildLoad2(Ty, PointerVal, Name.AsSpan()); - public LLVMValueRef BuildLoad2(LLVMTypeRef Ty, LLVMValueRef PointerVal, ReadOnlySpan Name) + public readonly LLVMValueRef BuildLoad2(LLVMTypeRef Ty, LLVMValueRef PointerVal, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildLoad2(this, Ty, PointerVal, marshaledName); } - public LLVMValueRef BuildLShr(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildLShr(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildLShr(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildLShr(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildLShr(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildLShr(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildLShr(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildMalloc(LLVMTypeRef Ty, string Name = "") => BuildMalloc(Ty, Name.AsSpan()); + public readonly LLVMValueRef BuildMalloc(LLVMTypeRef Ty, string Name = "") => BuildMalloc(Ty, Name.AsSpan()); - public LLVMValueRef BuildMalloc(LLVMTypeRef Ty, ReadOnlySpan Name) + public readonly LLVMValueRef BuildMalloc(LLVMTypeRef Ty, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildMalloc(this, Ty, marshaledName); } - public LLVMValueRef BuildMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildMul(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildMul(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildMul(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildNeg(LLVMValueRef V, string Name = "") => BuildNeg(V, Name.AsSpan()); + public readonly LLVMValueRef BuildNeg(LLVMValueRef V, string Name = "") => BuildNeg(V, Name.AsSpan()); - public LLVMValueRef BuildNeg(LLVMValueRef V, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNeg(LLVMValueRef V, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNeg(this, V, marshaledName); } - public LLVMValueRef BuildNot(LLVMValueRef V, string Name = "") => BuildNot(V, Name.AsSpan()); + public readonly LLVMValueRef BuildNot(LLVMValueRef V, string Name = "") => BuildNot(V, Name.AsSpan()); - public LLVMValueRef BuildNot(LLVMValueRef V, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNot(LLVMValueRef V, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNot(this, V, marshaledName); } - public LLVMValueRef BuildNSWAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNSWAdd(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildNSWAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNSWAdd(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildNSWAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNSWAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNSWAdd(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildNSWMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNSWMul(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildNSWMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNSWMul(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildNSWMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNSWMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNSWMul(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildNSWNeg(LLVMValueRef V, string Name = "") => BuildNSWNeg(V, Name.AsSpan()); + public readonly LLVMValueRef BuildNSWNeg(LLVMValueRef V, string Name = "") => BuildNSWNeg(V, Name.AsSpan()); - public LLVMValueRef BuildNSWNeg(LLVMValueRef V, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNSWNeg(LLVMValueRef V, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNSWNeg(this, V, marshaledName); } - public LLVMValueRef BuildNSWSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNSWSub(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildNSWSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNSWSub(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildNSWSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNSWSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNSWSub(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildNUWAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNUWAdd(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildNUWAdd(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNUWAdd(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildNUWAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNUWAdd(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNUWAdd(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildNUWMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNUWMul(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildNUWMul(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNUWMul(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildNUWMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNUWMul(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNUWMul(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildNUWNeg(LLVMValueRef V, string Name = "") => BuildNUWNeg(V, Name.AsSpan()); + public readonly LLVMValueRef BuildNUWNeg(LLVMValueRef V, string Name = "") => BuildNUWNeg(V, Name.AsSpan()); - public LLVMValueRef BuildNUWNeg(LLVMValueRef V, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNUWNeg(LLVMValueRef V, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNUWNeg(this, V, marshaledName); } - public LLVMValueRef BuildNUWSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNUWSub(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildNUWSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildNUWSub(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildNUWSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildNUWSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildNUWSub(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildOr(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildOr(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildOr(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildOr(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildOr(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildOr(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildOr(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildPhi(LLVMTypeRef Ty, string Name = "") => BuildPhi(Ty, Name.AsSpan()); + public readonly LLVMValueRef BuildPhi(LLVMTypeRef Ty, string Name = "") => BuildPhi(Ty, Name.AsSpan()); - public LLVMValueRef BuildPhi(LLVMTypeRef Ty, ReadOnlySpan Name) + public readonly LLVMValueRef BuildPhi(LLVMTypeRef Ty, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildPhi(this, Ty, marshaledName); } - public LLVMValueRef BuildPointerCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildPointerCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildPointerCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildPointerCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildPointerCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildPointerCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildPointerCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildPtrDiff2(LLVMTypeRef ElemTy, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildPtrDiff2(ElemTy, LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildPtrDiff2(LLVMTypeRef ElemTy, LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildPtrDiff2(ElemTy, LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildPtrDiff2(LLVMTypeRef ElemTy, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildPtrDiff2(LLVMTypeRef ElemTy, LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildPtrDiff2(this, ElemTy, LHS, RHS, marshaledName); } - public LLVMValueRef BuildPtrToInt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildPtrToInt(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildPtrToInt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildPtrToInt(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildPtrToInt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildPtrToInt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildPtrToInt(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildResume(LLVMValueRef Exn) => LLVM.BuildResume(this, Exn); + public readonly LLVMValueRef BuildResume(LLVMValueRef Exn) => LLVM.BuildResume(this, Exn); - public LLVMValueRef BuildRet(LLVMValueRef V) => LLVM.BuildRet(this, V); + public readonly LLVMValueRef BuildRet(LLVMValueRef V) => LLVM.BuildRet(this, V); - public LLVMValueRef BuildRetVoid() => LLVM.BuildRetVoid(this); + public readonly LLVMValueRef BuildRetVoid() => LLVM.BuildRetVoid(this); - public LLVMValueRef BuildSDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildSDiv(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildSDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildSDiv(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildSDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSDiv(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildSelect(LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, string Name = "") => BuildSelect(If, Then, Else, Name.AsSpan()); + public readonly LLVMValueRef BuildSelect(LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, string Name = "") => BuildSelect(If, Then, Else, Name.AsSpan()); - public LLVMValueRef BuildSelect(LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSelect(LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSelect(this, If, Then, Else, marshaledName); } - public LLVMValueRef BuildSExt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildSExt(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildSExt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildSExt(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildSExt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSExt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSExt(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildSExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildSExtOrBitCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildSExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildSExtOrBitCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildSExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSExtOrBitCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildShl(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildShl(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildShl(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildShl(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildShl(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildShl(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildShl(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildShuffleVector(LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, string Name = "") => BuildShuffleVector(V1, V2, Mask, Name.AsSpan()); + public readonly LLVMValueRef BuildShuffleVector(LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, string Name = "") => BuildShuffleVector(V1, V2, Mask, Name.AsSpan()); - public LLVMValueRef BuildShuffleVector(LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, ReadOnlySpan Name) + public readonly LLVMValueRef BuildShuffleVector(LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildShuffleVector(this, V1, V2, Mask, marshaledName); } - public LLVMValueRef BuildSIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildSIToFP(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildSIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildSIToFP(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildSIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSIToFP(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildSRem(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildSRem(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildSRem(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildSRem(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildSRem(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSRem(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSRem(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildStore(LLVMValueRef Val, LLVMValueRef Ptr) => LLVM.BuildStore(this, Val, Ptr); + public readonly LLVMValueRef BuildStore(LLVMValueRef Val, LLVMValueRef Ptr) => LLVM.BuildStore(this, Val, Ptr); - public LLVMValueRef BuildStructGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, uint Idx, string Name = "") => BuildStructGEP2(Ty, Pointer, Idx, Name.AsSpan()); + public readonly LLVMValueRef BuildStructGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, uint Idx, string Name = "") => BuildStructGEP2(Ty, Pointer, Idx, Name.AsSpan()); - public LLVMValueRef BuildStructGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, uint Idx, ReadOnlySpan Name) + public readonly LLVMValueRef BuildStructGEP2(LLVMTypeRef Ty, LLVMValueRef Pointer, uint Idx, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildStructGEP2(this, Ty, Pointer, Idx, marshaledName); } - public LLVMValueRef BuildSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildSub(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildSub(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildSub(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildSub(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildSub(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildSwitch(LLVMValueRef V, LLVMBasicBlockRef Else, uint NumCases) => LLVM.BuildSwitch(this, V, Else, NumCases); + public readonly LLVMValueRef BuildSwitch(LLVMValueRef V, LLVMBasicBlockRef Else, uint NumCases) => LLVM.BuildSwitch(this, V, Else, NumCases); - public LLVMValueRef BuildTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildTrunc(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildTrunc(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildTrunc(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildTrunc(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildTruncOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildTruncOrBitCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildTruncOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildTruncOrBitCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildTruncOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildTruncOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildTruncOrBitCast(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildUDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildUDiv(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildUDiv(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildUDiv(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildUDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildUDiv(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildUDiv(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildUIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildUIToFP(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildUIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildUIToFP(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildUIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildUIToFP(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildUIToFP(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildUnreachable() => LLVM.BuildUnreachable(this); + public readonly LLVMValueRef BuildUnreachable() => LLVM.BuildUnreachable(this); - public LLVMValueRef BuildURem(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildURem(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildURem(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildURem(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildURem(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildURem(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildURem(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildVAArg(LLVMValueRef List, LLVMTypeRef Ty, string Name = "") => BuildVAArg(List, Ty, Name.AsSpan()); + public readonly LLVMValueRef BuildVAArg(LLVMValueRef List, LLVMTypeRef Ty, string Name = "") => BuildVAArg(List, Ty, Name.AsSpan()); - public LLVMValueRef BuildVAArg(LLVMValueRef List, LLVMTypeRef Ty, ReadOnlySpan Name) + public readonly LLVMValueRef BuildVAArg(LLVMValueRef List, LLVMTypeRef Ty, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildVAArg(this, List, Ty, marshaledName); } - public LLVMValueRef BuildXor(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildXor(LHS, RHS, Name.AsSpan()); + public readonly LLVMValueRef BuildXor(LLVMValueRef LHS, LLVMValueRef RHS, string Name = "") => BuildXor(LHS, RHS, Name.AsSpan()); - public LLVMValueRef BuildXor(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) + public readonly LLVMValueRef BuildXor(LLVMValueRef LHS, LLVMValueRef RHS, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildXor(this, LHS, RHS, marshaledName); } - public LLVMValueRef BuildZExt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildZExt(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildZExt(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildZExt(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildZExt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildZExt(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildZExt(this, Val, DestTy, marshaledName); } - public LLVMValueRef BuildZExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildZExtOrBitCast(Val, DestTy, Name.AsSpan()); + public readonly LLVMValueRef BuildZExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, string Name = "") => BuildZExtOrBitCast(Val, DestTy, Name.AsSpan()); - public LLVMValueRef BuildZExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) + public readonly LLVMValueRef BuildZExtOrBitCast(LLVMValueRef Val, LLVMTypeRef DestTy, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.BuildZExtOrBitCast(this, Val, DestTy, marshaledName); } - public void ClearInsertionPosition() => LLVM.ClearInsertionPosition(this); + public readonly void ClearInsertionPosition() => LLVM.ClearInsertionPosition(this); public void Dispose() { @@ -726,29 +721,29 @@ public void Dispose() } } - public override bool Equals(object? obj) => (obj is LLVMBuilderRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMBuilderRef other) && Equals(other); - public bool Equals(LLVMBuilderRef other) => this == other; + public readonly bool Equals(LLVMBuilderRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public void Insert(LLVMValueRef Instr) => LLVM.InsertIntoBuilder(this, Instr); + public readonly void Insert(LLVMValueRef Instr) => LLVM.InsertIntoBuilder(this, Instr); - public void InsertWithName(LLVMValueRef Instr, string Name = "") => InsertWithName(Instr, Name.AsSpan()); + public readonly void InsertWithName(LLVMValueRef Instr, string Name = "") => InsertWithName(Instr, Name.AsSpan()); - public void InsertWithName(LLVMValueRef Instr, ReadOnlySpan Name) + public readonly void InsertWithName(LLVMValueRef Instr, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); LLVM.InsertIntoBuilderWithName(this, Instr, marshaledName); } - public void Position(LLVMBasicBlockRef Block, LLVMValueRef Instr) => LLVM.PositionBuilder(this, Block, Instr); + public readonly void Position(LLVMBasicBlockRef Block, LLVMValueRef Instr) => LLVM.PositionBuilder(this, Block, Instr); - public void PositionAtEnd(LLVMBasicBlockRef Block) => LLVM.PositionBuilderAtEnd(this, Block); + public readonly void PositionAtEnd(LLVMBasicBlockRef Block) => LLVM.PositionBuilderAtEnd(this, Block); - public void PositionBefore(LLVMValueRef Instr) => LLVM.PositionBuilderBefore(this, Instr); + public readonly void PositionBefore(LLVMValueRef Instr) => LLVM.PositionBuilderBefore(this, Instr); - public void SetInstDebugLocation(LLVMValueRef Inst) => LLVM.SetInstDebugLocation(this, Inst); + public readonly void SetInstDebugLocation(LLVMValueRef Inst) => LLVM.SetInstDebugLocation(this, Inst); - public override string ToString() => $"{nameof(LLVMBuilderRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMBuilderRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMComdatRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMComdatRef.cs index f3d40b0c..03ffce21 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMComdatRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMComdatRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMComdatRef : IEquatable +public unsafe partial struct LLVMComdatRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMComdatRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMComdatRef(LLVMComdat* Comdat) => new LLVMComdatRef((IntPtr)Comdat); @@ -21,11 +16,11 @@ public LLVMComdatRef(IntPtr handle) public static bool operator !=(LLVMComdatRef left, LLVMComdatRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMComdatRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMComdatRef other) && Equals(other); - public bool Equals(LLVMComdatRef other) => this == other; + public readonly bool Equals(LLVMComdatRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMComdatRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMComdatRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs index a8904bb8..103a7235 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMContextRef.cs @@ -5,48 +5,43 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMContextRef : IDisposable, IEquatable +public unsafe partial struct LLVMContextRef(IntPtr handle) : IDisposable, IEquatable { - public IntPtr Handle; - - public LLVMContextRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static LLVMContextRef Global => LLVM.GetGlobalContext(); - public LLVMTypeRef BFloatType => (Handle != IntPtr.Zero) ? LLVM.BFloatTypeInContext(this) : default; + public readonly LLVMTypeRef BFloatType => (Handle != IntPtr.Zero) ? LLVM.BFloatTypeInContext(this) : default; - public LLVMTypeRef DoubleType => (Handle != IntPtr.Zero) ? LLVM.DoubleTypeInContext(this) : default; + public readonly LLVMTypeRef DoubleType => (Handle != IntPtr.Zero) ? LLVM.DoubleTypeInContext(this) : default; - public LLVMTypeRef FloatType => (Handle != IntPtr.Zero) ? LLVM.FloatTypeInContext(this) : default; + public readonly LLVMTypeRef FloatType => (Handle != IntPtr.Zero) ? LLVM.FloatTypeInContext(this) : default; - public LLVMTypeRef HalfType => (Handle != IntPtr.Zero) ? LLVM.HalfTypeInContext(this) : default; + public readonly LLVMTypeRef HalfType => (Handle != IntPtr.Zero) ? LLVM.HalfTypeInContext(this) : default; - public LLVMTypeRef Int1Type => (Handle != IntPtr.Zero) ? LLVM.Int1TypeInContext(this) : default; + public readonly LLVMTypeRef Int1Type => (Handle != IntPtr.Zero) ? LLVM.Int1TypeInContext(this) : default; - public LLVMTypeRef Int8Type => (Handle != IntPtr.Zero) ? LLVM.Int8TypeInContext(this) : default; + public readonly LLVMTypeRef Int8Type => (Handle != IntPtr.Zero) ? LLVM.Int8TypeInContext(this) : default; - public LLVMTypeRef Int16Type => (Handle != IntPtr.Zero) ? LLVM.Int16TypeInContext(this) : default; + public readonly LLVMTypeRef Int16Type => (Handle != IntPtr.Zero) ? LLVM.Int16TypeInContext(this) : default; - public LLVMTypeRef Int32Type => (Handle != IntPtr.Zero) ? LLVM.Int32TypeInContext(this) : default; + public readonly LLVMTypeRef Int32Type => (Handle != IntPtr.Zero) ? LLVM.Int32TypeInContext(this) : default; - public LLVMTypeRef Int64Type => (Handle != IntPtr.Zero) ? LLVM.Int64TypeInContext(this) : default; + public readonly LLVMTypeRef Int64Type => (Handle != IntPtr.Zero) ? LLVM.Int64TypeInContext(this) : default; - public LLVMTypeRef FP128Type => (Handle != IntPtr.Zero) ? LLVM.FP128TypeInContext(this) : default; + public readonly LLVMTypeRef FP128Type => (Handle != IntPtr.Zero) ? LLVM.FP128TypeInContext(this) : default; - public LLVMTypeRef LabelType => (Handle != IntPtr.Zero) ? LLVM.LabelTypeInContext(this) : default; + public readonly LLVMTypeRef LabelType => (Handle != IntPtr.Zero) ? LLVM.LabelTypeInContext(this) : default; - public LLVMTypeRef PPCFP128Type => (Handle != IntPtr.Zero) ? LLVM.PPCFP128TypeInContext(this) : default; + public readonly LLVMTypeRef PPCFP128Type => (Handle != IntPtr.Zero) ? LLVM.PPCFP128TypeInContext(this) : default; - public LLVMTypeRef VoidType => (Handle != IntPtr.Zero) ? LLVM.VoidTypeInContext(this) : default; + public readonly LLVMTypeRef VoidType => (Handle != IntPtr.Zero) ? LLVM.VoidTypeInContext(this) : default; - public LLVMTypeRef X86FP80Type => (Handle != IntPtr.Zero) ? LLVM.X86FP80TypeInContext(this) : default; + public readonly LLVMTypeRef X86FP80Type => (Handle != IntPtr.Zero) ? LLVM.X86FP80TypeInContext(this) : default; - public LLVMTypeRef X86MMXType => (Handle != IntPtr.Zero) ? LLVM.X86MMXTypeInContext(this) : default; + public readonly LLVMTypeRef X86MMXType => (Handle != IntPtr.Zero) ? LLVM.X86MMXTypeInContext(this) : default; - public LLVMTypeRef X86AMXType => (Handle != IntPtr.Zero) ? LLVM.X86AMXTypeInContext(this) : default; + public readonly LLVMTypeRef X86AMXType => (Handle != IntPtr.Zero) ? LLVM.X86AMXTypeInContext(this) : default; public static implicit operator LLVMContextRef(LLVMOpaqueContext* value) => new LLVMContextRef((IntPtr)value); @@ -58,35 +53,35 @@ public LLVMContextRef(IntPtr handle) public static LLVMContextRef Create() => LLVM.ContextCreate(); - public LLVMBasicBlockRef AppendBasicBlock(LLVMValueRef Fn, string Name) => AppendBasicBlock(Fn, Name.AsSpan()); + public readonly LLVMBasicBlockRef AppendBasicBlock(LLVMValueRef Fn, string Name) => AppendBasicBlock(Fn, Name.AsSpan()); - public LLVMBasicBlockRef AppendBasicBlock(LLVMValueRef Fn, ReadOnlySpan Name) => LLVMBasicBlockRef.AppendInContext(this, Fn, Name); + public readonly LLVMBasicBlockRef AppendBasicBlock(LLVMValueRef Fn, ReadOnlySpan Name) => LLVMBasicBlockRef.AppendInContext(this, Fn, Name); - public LLVMBasicBlockRef CreateBasicBlock(string Name) => CreateBasicBlock(Name.AsSpan()); + public readonly LLVMBasicBlockRef CreateBasicBlock(string Name) => CreateBasicBlock(Name.AsSpan()); - public LLVMBasicBlockRef CreateBasicBlock(ReadOnlySpan Name) => LLVMBasicBlockRef.CreateInContext(this, Name); + public readonly LLVMBasicBlockRef CreateBasicBlock(ReadOnlySpan Name) => LLVMBasicBlockRef.CreateInContext(this, Name); - public LLVMBuilderRef CreateBuilder() => LLVMBuilderRef.Create(this); + public readonly LLVMBuilderRef CreateBuilder() => LLVMBuilderRef.Create(this); - public LLVMMetadataRef CreateDebugLocation(uint Line, uint Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt) => LLVM.DIBuilderCreateDebugLocation(this, Line, Column, Scope, InlinedAt); + public readonly LLVMMetadataRef CreateDebugLocation(uint Line, uint Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt) => LLVM.DIBuilderCreateDebugLocation(this, Line, Column, Scope, InlinedAt); - public LLVMModuleRef CreateModuleWithName(string ModuleID) => CreateModuleWithName(ModuleID.AsSpan()); + public readonly LLVMModuleRef CreateModuleWithName(string ModuleID) => CreateModuleWithName(ModuleID.AsSpan()); - public LLVMModuleRef CreateModuleWithName(ReadOnlySpan ModuleID) + public readonly LLVMModuleRef CreateModuleWithName(ReadOnlySpan ModuleID) { using var marshaledModuleID = new MarshaledString(ModuleID); return LLVM.ModuleCreateWithNameInContext(marshaledModuleID, this); } - public LLVMTypeRef CreateNamedStruct(string Name) => CreateNamedStruct(Name.AsSpan()); + public readonly LLVMTypeRef CreateNamedStruct(string Name) => CreateNamedStruct(Name.AsSpan()); - public LLVMTypeRef CreateNamedStruct(ReadOnlySpan Name) + public readonly LLVMTypeRef CreateNamedStruct(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.StructCreateNamed(this, marshaledName); } - public LLVMAttributeRef CreateEnumAttribute(uint KindId, ulong Val) + public readonly LLVMAttributeRef CreateEnumAttribute(uint KindId, ulong Val) { return LLVM.CreateEnumAttribute(this, KindId, Val); } @@ -100,11 +95,11 @@ public void Dispose() } } - public override bool Equals(object? obj) => (obj is LLVMContextRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMContextRef other) && Equals(other); - public bool Equals(LLVMContextRef other) => this == other; + public readonly bool Equals(LLVMContextRef other) => this == other; - public LLVMModuleRef GetBitcodeModule(LLVMMemoryBufferRef MemBuf) + public readonly LLVMModuleRef GetBitcodeModule(LLVMMemoryBufferRef MemBuf) { if (!TryGetBitcodeModule(MemBuf, out LLVMModuleRef M, out string Message)) { @@ -114,17 +109,17 @@ public LLVMModuleRef GetBitcodeModule(LLVMMemoryBufferRef MemBuf) return M; } - public LLVMValueRef GetConstString(string Str, bool DontNullTerminate) => GetConstString(Str.AsSpan(), DontNullTerminate); + public readonly LLVMValueRef GetConstString(string Str, bool DontNullTerminate) => GetConstString(Str.AsSpan(), DontNullTerminate); - public LLVMValueRef GetConstString(ReadOnlySpan Str, bool DontNullTerminate) + public readonly LLVMValueRef GetConstString(ReadOnlySpan Str, bool DontNullTerminate) { using var marshaledStr = new MarshaledString(Str); return LLVM.ConstStringInContext(this, marshaledStr, (uint)marshaledStr.Length, DontNullTerminate ? 1 : 0); } - public LLVMValueRef GetConstStruct(LLVMValueRef[] ConstantVals, bool Packed) => GetConstStruct(ConstantVals.AsSpan(), Packed); + public readonly LLVMValueRef GetConstStruct(LLVMValueRef[] ConstantVals, bool Packed) => GetConstStruct(ConstantVals.AsSpan(), Packed); - public LLVMValueRef GetConstStruct(ReadOnlySpan ConstantVals, bool Packed) + public readonly LLVMValueRef GetConstStruct(ReadOnlySpan ConstantVals, bool Packed) { fixed (LLVMValueRef* pConstantVals = ConstantVals) { @@ -132,25 +127,25 @@ public LLVMValueRef GetConstStruct(ReadOnlySpan ConstantVals, bool } } - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public LLVMTypeRef GetIntPtrType(LLVMTargetDataRef TD) => LLVM.IntPtrTypeInContext(this, TD); + public readonly LLVMTypeRef GetIntPtrType(LLVMTargetDataRef TD) => LLVM.IntPtrTypeInContext(this, TD); - public LLVMTypeRef GetIntPtrTypeForAS(LLVMTargetDataRef TD, uint AS) => LLVM.IntPtrTypeForASInContext(this, TD, AS); + public readonly LLVMTypeRef GetIntPtrTypeForAS(LLVMTargetDataRef TD, uint AS) => LLVM.IntPtrTypeForASInContext(this, TD, AS); - public LLVMTypeRef GetIntType(uint NumBits) => LLVM.IntTypeInContext(this, NumBits); + public readonly LLVMTypeRef GetIntType(uint NumBits) => LLVM.IntTypeInContext(this, NumBits); - public uint GetMDKindID(string Name, uint SLen) => GetMDKindID(Name.AsSpan(0, (int)SLen)); + public readonly uint GetMDKindID(string Name, uint SLen) => GetMDKindID(Name.AsSpan(0, (int)SLen)); - public uint GetMDKindID(ReadOnlySpan Name) + public readonly uint GetMDKindID(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetMDKindIDInContext(this, marshaledName, (uint)marshaledName.Length); } - public LLVMValueRef GetMDNode(LLVMValueRef[] Vals) => GetMDNode(Vals.AsSpan()); + public readonly LLVMValueRef GetMDNode(LLVMValueRef[] Vals) => GetMDNode(Vals.AsSpan()); - public LLVMValueRef GetMDNode(ReadOnlySpan Vals) + public readonly LLVMValueRef GetMDNode(ReadOnlySpan Vals) { fixed (LLVMValueRef* pVals = Vals) { @@ -158,17 +153,17 @@ public LLVMValueRef GetMDNode(ReadOnlySpan Vals) } } - public LLVMValueRef GetMDString(string Str, uint SLen) => GetMDString(Str.AsSpan(0, (int)SLen)); + public readonly LLVMValueRef GetMDString(string Str, uint SLen) => GetMDString(Str.AsSpan(0, (int)SLen)); - public LLVMValueRef GetMDString(ReadOnlySpan Str) + public readonly LLVMValueRef GetMDString(ReadOnlySpan Str) { using var marshaledStr = new MarshaledString(Str); return LLVM.MDStringInContext(this, marshaledStr, (uint)marshaledStr.Length); } - public LLVMTypeRef GetStructType(LLVMTypeRef[] ElementTypes, bool Packed) => GetStructType(ElementTypes.AsSpan(), Packed); + public readonly LLVMTypeRef GetStructType(LLVMTypeRef[] ElementTypes, bool Packed) => GetStructType(ElementTypes.AsSpan(), Packed); - public LLVMTypeRef GetStructType(ReadOnlySpan ElementTypes, bool Packed) + public readonly LLVMTypeRef GetStructType(ReadOnlySpan ElementTypes, bool Packed) { fixed (LLVMTypeRef* pElementTypes = ElementTypes) { @@ -176,11 +171,11 @@ public LLVMTypeRef GetStructType(ReadOnlySpan ElementTypes, bool Pa } } - public LLVMBasicBlockRef InsertBasicBlock(LLVMBasicBlockRef BB, string Name) => LLVMBasicBlockRef.InsertInContext(this, BB, Name); + public readonly LLVMBasicBlockRef InsertBasicBlock(LLVMBasicBlockRef BB, string Name) => LLVMBasicBlockRef.InsertInContext(this, BB, Name); - public LLVMValueRef MetadataAsValue(LLVMMetadataRef MD) => LLVM.MetadataAsValue(this, MD); + public readonly LLVMValueRef MetadataAsValue(LLVMMetadataRef MD) => LLVM.MetadataAsValue(this, MD); - public LLVMModuleRef ParseBitcode(LLVMMemoryBufferRef MemBuf) + public readonly LLVMModuleRef ParseBitcode(LLVMMemoryBufferRef MemBuf) { if (!TryParseBitcode(MemBuf, out LLVMModuleRef M, out string Message)) { @@ -190,7 +185,7 @@ public LLVMModuleRef ParseBitcode(LLVMMemoryBufferRef MemBuf) return M; } - public LLVMModuleRef ParseIR(LLVMMemoryBufferRef MemBuf) + public readonly LLVMModuleRef ParseIR(LLVMMemoryBufferRef MemBuf) { if (!TryParseIR(MemBuf, out LLVMModuleRef M, out string Message)) { @@ -200,31 +195,31 @@ public LLVMModuleRef ParseIR(LLVMMemoryBufferRef MemBuf) return M; } - public void SetDiagnosticHandler(LLVMDiagnosticHandler Handler, void* DiagnosticContext) + public readonly void SetDiagnosticHandler(LLVMDiagnosticHandler Handler, void* DiagnosticContext) { var pHandler = (delegate* unmanaged[Cdecl] < LLVMOpaqueDiagnosticInfo *, void *, void > )Marshal.GetFunctionPointerForDelegate(Handler); SetDiagnosticHandler(pHandler, DiagnosticContext); } - public void SetDiagnosticHandler(delegate* unmanaged[Cdecl] Handler, void* DiagnosticContext) + public readonly void SetDiagnosticHandler(delegate* unmanaged[Cdecl] Handler, void* DiagnosticContext) { LLVM.ContextSetDiagnosticHandler(this, Handler, DiagnosticContext); } - public void SetYieldCallback(LLVMYieldCallback Callback, void* OpaqueHandle) + public readonly void SetYieldCallback(LLVMYieldCallback Callback, void* OpaqueHandle) { var pCallback = (delegate* unmanaged[Cdecl] < LLVMOpaqueContext *, void *, void>)Marshal.GetFunctionPointerForDelegate(Callback); SetYieldCallback(pCallback, OpaqueHandle); } - public void SetYieldCallback(delegate* unmanaged[Cdecl] Callback, void* OpaqueHandle) + public readonly void SetYieldCallback(delegate* unmanaged[Cdecl] Callback, void* OpaqueHandle) { LLVM.ContextSetYieldCallback(this, Callback, OpaqueHandle); } - public override string ToString() => $"{nameof(LLVMContextRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMContextRef)}: {Handle:X}"; - public bool TryGetBitcodeModule(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutM, out string OutMessage) + public readonly bool TryGetBitcodeModule(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutM, out string OutMessage) { fixed (LLVMModuleRef* pOutM = &OutM) { @@ -244,7 +239,7 @@ public bool TryGetBitcodeModule(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef Ou } } - public bool TryParseBitcode(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutModule, out string OutMessage) + public readonly bool TryParseBitcode(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutModule, out string OutMessage) { fixed (LLVMModuleRef* pOutModule = &OutModule) { @@ -264,7 +259,7 @@ public bool TryParseBitcode(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutMod } } - public bool TryParseIR(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutM, out string OutMessage) + public readonly bool TryParseIR(LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutM, out string OutMessage) { fixed (LLVMModuleRef* pOutM = &OutM) { diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMDIBuilderRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMDIBuilderRef.cs index bd8ed21c..c4f2413a 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMDIBuilderRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMDIBuilderRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMDIBuilderRef : IEquatable +public unsafe partial struct LLVMDIBuilderRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMDIBuilderRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMDIBuilderRef(LLVMOpaqueDIBuilder* value) => new LLVMDIBuilderRef((IntPtr)value); @@ -21,10 +16,10 @@ public LLVMDIBuilderRef(IntPtr handle) public static bool operator !=(LLVMDIBuilderRef left, LLVMDIBuilderRef right) => !(left == right); - public LLVMMetadataRef CreateCompileUnit(LLVMDWARFSourceLanguage SourceLanguage, LLVMMetadataRef FileMetadata, string Producer, int IsOptimized, string Flags, uint RuntimeVersion, + public readonly LLVMMetadataRef CreateCompileUnit(LLVMDWARFSourceLanguage SourceLanguage, LLVMMetadataRef FileMetadata, string Producer, int IsOptimized, string Flags, uint RuntimeVersion, string SplitName, LLVMDWARFEmissionKind DwarfEmissionKind, uint DWOld, int SplitDebugInlining, int DebugInfoForProfiling, string SysRoot, string SDK) => CreateCompileUnit(SourceLanguage, FileMetadata, Producer.AsSpan(), IsOptimized, Flags.AsSpan(), RuntimeVersion, SplitName.AsSpan(), DwarfEmissionKind, DWOld, SplitDebugInlining, DebugInfoForProfiling, SysRoot.AsSpan(), SDK.AsSpan()); - public LLVMMetadataRef CreateCompileUnit(LLVMDWARFSourceLanguage SourceLanguage, LLVMMetadataRef FileMetadata, ReadOnlySpan Producer, int IsOptimized, ReadOnlySpan Flags, uint RuntimeVersion, + public readonly LLVMMetadataRef CreateCompileUnit(LLVMDWARFSourceLanguage SourceLanguage, LLVMMetadataRef FileMetadata, ReadOnlySpan Producer, int IsOptimized, ReadOnlySpan Flags, uint RuntimeVersion, ReadOnlySpan SplitName, LLVMDWARFEmissionKind DwarfEmissionKind, uint DWOld, int SplitDebugInlining, int DebugInfoForProfiling, ReadOnlySpan SysRoot, ReadOnlySpan SDK) { using var marshaledProducer= new MarshaledString(Producer); @@ -37,19 +32,19 @@ public LLVMMetadataRef CreateCompileUnit(LLVMDWARFSourceLanguage SourceLanguage, RuntimeVersion, marshaledSplitNameFlags, (UIntPtr)marshaledSplitNameFlags.Length, DwarfEmissionKind, DWOld, SplitDebugInlining, DebugInfoForProfiling, marshaledSysRoot, (UIntPtr)marshaledSysRoot.Length, marshaledSDK, (UIntPtr)marshaledSDK.Length); } - public LLVMMetadataRef CreateFile(string FullPath, string Directory) => CreateFile(FullPath.AsSpan(), Directory.AsSpan()); + public readonly LLVMMetadataRef CreateFile(string FullPath, string Directory) => CreateFile(FullPath.AsSpan(), Directory.AsSpan()); - public LLVMMetadataRef CreateFile(ReadOnlySpan FullPath, ReadOnlySpan Directory) + public readonly LLVMMetadataRef CreateFile(ReadOnlySpan FullPath, ReadOnlySpan Directory) { using var marshaledFullPath = new MarshaledString(FullPath); using var marshaledDirectory = new MarshaledString(Directory); return LLVM.DIBuilderCreateFile(this, marshaledFullPath, (UIntPtr)marshaledFullPath.Length, marshaledDirectory, (UIntPtr)marshaledDirectory.Length); } - public LLVMMetadataRef CreateFunction(LLVMMetadataRef Scope, string Name, string LinkageName, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Type, int IsLocalToUnit, int IsDefinition, + public readonly LLVMMetadataRef CreateFunction(LLVMMetadataRef Scope, string Name, string LinkageName, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Type, int IsLocalToUnit, int IsDefinition, uint ScopeLine, LLVMDIFlags Flags, int IsOptimized) => CreateFunction(Scope, Name.AsSpan(), LinkageName.AsSpan(), File, LineNo, Type, IsLocalToUnit, IsDefinition, ScopeLine, Flags, IsOptimized); - public LLVMMetadataRef CreateFunction(LLVMMetadataRef Scope, ReadOnlySpan Name, ReadOnlySpan LinkageName, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Type, int IsLocalToUnit, int IsDefinition, + public readonly LLVMMetadataRef CreateFunction(LLVMMetadataRef Scope, ReadOnlySpan Name, ReadOnlySpan LinkageName, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Type, int IsLocalToUnit, int IsDefinition, uint ScopeLine, LLVMDIFlags Flags, int IsOptimized) { using var marshaledName = new MarshaledString(Name); @@ -61,9 +56,9 @@ public LLVMMetadataRef CreateFunction(LLVMMetadataRef Scope, ReadOnlySpan LineNo, Type, IsLocalToUnit, IsDefinition, ScopeLine, Flags, IsOptimized); } - public LLVMMetadataRef CreateMacro(LLVMMetadataRef ParentMacroFile, uint Line, LLVMDWARFMacinfoRecordType RecordType, string Name, string Value) => CreateMacro(ParentMacroFile, Line, RecordType, Name.AsSpan(), Value.AsSpan()); + public readonly LLVMMetadataRef CreateMacro(LLVMMetadataRef ParentMacroFile, uint Line, LLVMDWARFMacinfoRecordType RecordType, string Name, string Value) => CreateMacro(ParentMacroFile, Line, RecordType, Name.AsSpan(), Value.AsSpan()); - public LLVMMetadataRef CreateMacro(LLVMMetadataRef ParentMacroFile, uint Line, LLVMDWARFMacinfoRecordType RecordType, ReadOnlySpan Name, ReadOnlySpan Value) + public readonly LLVMMetadataRef CreateMacro(LLVMMetadataRef ParentMacroFile, uint Line, LLVMDWARFMacinfoRecordType RecordType, ReadOnlySpan Name, ReadOnlySpan Value) { using var marshaledName = new MarshaledString(Name); using var marshaledValue = new MarshaledString(Value); @@ -73,9 +68,9 @@ public LLVMMetadataRef CreateMacro(LLVMMetadataRef ParentMacroFile, uint Line, L return LLVM.DIBuilderCreateMacro(this, ParentMacroFile, Line, RecordType, marshaledName, (UIntPtr)nameLength, marshaledValue, (UIntPtr)valueLength); } - public LLVMMetadataRef CreateModule(LLVMMetadataRef ParentScope, string Name, string ConfigMacros, string IncludePath, string SysRoot) => CreateModule(ParentScope, Name.AsSpan(), ConfigMacros.AsSpan(), IncludePath.AsSpan(), SysRoot.AsSpan()); + public readonly LLVMMetadataRef CreateModule(LLVMMetadataRef ParentScope, string Name, string ConfigMacros, string IncludePath, string SysRoot) => CreateModule(ParentScope, Name.AsSpan(), ConfigMacros.AsSpan(), IncludePath.AsSpan(), SysRoot.AsSpan()); - public LLVMMetadataRef CreateModule(LLVMMetadataRef ParentScope, ReadOnlySpan Name, ReadOnlySpan ConfigMacros, ReadOnlySpan IncludePath, ReadOnlySpan SysRoot) + public readonly LLVMMetadataRef CreateModule(LLVMMetadataRef ParentScope, ReadOnlySpan Name, ReadOnlySpan ConfigMacros, ReadOnlySpan IncludePath, ReadOnlySpan SysRoot) { using var marshaledName = new MarshaledString(Name); using var marshaledConfigMacros = new MarshaledString(ConfigMacros); @@ -89,9 +84,9 @@ public LLVMMetadataRef CreateModule(LLVMMetadataRef ParentScope, ReadOnlySpan CreateSubroutineType(File, ParameterTypes.AsSpan(), Flags); + public readonly LLVMMetadataRef CreateSubroutineType(LLVMMetadataRef File, LLVMMetadataRef[] ParameterTypes, LLVMDIFlags Flags) => CreateSubroutineType(File, ParameterTypes.AsSpan(), Flags); - public LLVMMetadataRef CreateSubroutineType(LLVMMetadataRef File, ReadOnlySpan ParameterTypes, LLVMDIFlags Flags) + public readonly LLVMMetadataRef CreateSubroutineType(LLVMMetadataRef File, ReadOnlySpan ParameterTypes, LLVMDIFlags Flags) { fixed (LLVMMetadataRef* pParameterTypes = ParameterTypes) { @@ -99,11 +94,11 @@ public LLVMMetadataRef CreateSubroutineType(LLVMMetadataRef File, ReadOnlySpan LLVM.DIBuilderCreateTempMacroFile(this, ParentMacroFile, Line, File); + public readonly LLVMMetadataRef CreateTempMacroFile(LLVMMetadataRef ParentMacroFile, uint Line, LLVMMetadataRef File) => LLVM.DIBuilderCreateTempMacroFile(this, ParentMacroFile, Line, File); - public LLVMMetadataRef CreateTypedef(LLVMMetadataRef Type, string Name, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Scope, uint AlignInBits) => CreateTypedef(Type, Name.AsSpan(), File, LineNo, Scope, AlignInBits); + public readonly LLVMMetadataRef CreateTypedef(LLVMMetadataRef Type, string Name, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Scope, uint AlignInBits) => CreateTypedef(Type, Name.AsSpan(), File, LineNo, Scope, AlignInBits); - public LLVMMetadataRef CreateTypedef(LLVMMetadataRef Type, ReadOnlySpan Name, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Scope, uint AlignInBits) + public readonly LLVMMetadataRef CreateTypedef(LLVMMetadataRef Type, ReadOnlySpan Name, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Scope, uint AlignInBits) { using var marshaledName = new MarshaledString(Name); var nameLength = (uint)marshaledName.Length; @@ -111,13 +106,13 @@ public LLVMMetadataRef CreateTypedef(LLVMMetadataRef Type, ReadOnlySpan Na return LLVM.DIBuilderCreateTypedef(this, Type, marshaledName, (UIntPtr)nameLength, File, LineNo, Scope, AlignInBits); } - public void DIBuilderFinalize() => LLVM.DIBuilderFinalize(this); + public readonly void DIBuilderFinalize() => LLVM.DIBuilderFinalize(this); - public override bool Equals(object? obj) => (obj is LLVMDIBuilderRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMDIBuilderRef other) && Equals(other); - public bool Equals(LLVMDIBuilderRef other) => this == other; + public readonly bool Equals(LLVMDIBuilderRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMDIBuilderRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMDIBuilderRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMDiagnosticInfoRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMDiagnosticInfoRef.cs index f7a49c23..73a4a1ad 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMDiagnosticInfoRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMDiagnosticInfoRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMDiagnosticInfoRef : IEquatable +public unsafe partial struct LLVMDiagnosticInfoRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMDiagnosticInfoRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMDiagnosticInfoRef(LLVMOpaqueDiagnosticInfo* value) => new LLVMDiagnosticInfoRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMDiagnosticInfoRef(IntPtr handle) public static bool operator !=(LLVMDiagnosticInfoRef left, LLVMDiagnosticInfoRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMDiagnosticInfoRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMDiagnosticInfoRef other) && Equals(other); - public bool Equals(LLVMDiagnosticInfoRef other) => this == other; + public readonly bool Equals(LLVMDiagnosticInfoRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMDiagnosticInfoRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMDiagnosticInfoRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMDisasmContextRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMDisasmContextRef.cs index ce9cb261..a81fad3f 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMDisasmContextRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMDisasmContextRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMDisasmContextRef : IEquatable +public unsafe partial struct LLVMDisasmContextRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMDisasmContextRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static explicit operator LLVMDisasmContextRef(void* value) => new LLVMDisasmContextRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMDisasmContextRef(IntPtr handle) public static bool operator !=(LLVMDisasmContextRef left, LLVMDisasmContextRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMDisasmContextRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMDisasmContextRef other) && Equals(other); - public bool Equals(LLVMDisasmContextRef other) => this == other; + public readonly bool Equals(LLVMDisasmContextRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMDisasmContextRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMDisasmContextRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMErrorRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMErrorRef.cs index 7911f77d..21d0b700 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMErrorRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMErrorRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMErrorRef : IEquatable +public unsafe partial struct LLVMErrorRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMErrorRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMErrorRef(LLVMOpaqueError* value) =>new LLVMErrorRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMErrorRef(IntPtr handle) public static bool operator !=(LLVMErrorRef left, LLVMErrorRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMErrorRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMErrorRef other) && Equals(other); - public bool Equals(LLVMErrorRef other) => this == other; + public readonly bool Equals(LLVMErrorRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMErrorRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMErrorRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMErrorTypeId.cs b/sources/LLVMSharp.Interop/Extensions/LLVMErrorTypeId.cs index 41df64ce..e33db2b5 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMErrorTypeId.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMErrorTypeId.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMErrorTypeId : IEquatable +public unsafe partial struct LLVMErrorTypeId(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMErrorTypeId(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static explicit operator LLVMErrorTypeId(void* value) => new LLVMErrorTypeId((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMErrorTypeId(IntPtr handle) public static bool operator !=(LLVMErrorTypeId left, LLVMErrorTypeId right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMErrorTypeId other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMErrorTypeId other) && Equals(other); - public bool Equals(LLVMErrorTypeId other) => this == other; + public readonly bool Equals(LLVMErrorTypeId other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMErrorTypeId)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMErrorTypeId)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMExecutionEngineRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMExecutionEngineRef.cs index 4de5286d..684084f8 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMExecutionEngineRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMExecutionEngineRef.cs @@ -5,18 +5,13 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMExecutionEngineRef : IDisposable, IEquatable +public unsafe partial struct LLVMExecutionEngineRef(IntPtr handle) : IDisposable, IEquatable { - public IntPtr Handle; + public IntPtr Handle = handle; - public LLVMExecutionEngineRef(IntPtr handle) - { - Handle = handle; - } - - public LLVMTargetDataRef TargetData => (Handle != IntPtr.Zero) ? LLVM.GetExecutionEngineTargetData(this) : default; + public readonly LLVMTargetDataRef TargetData => (Handle != IntPtr.Zero) ? LLVM.GetExecutionEngineTargetData(this) : default; - public LLVMTargetMachineRef TargetMachine => (Handle != IntPtr.Zero) ? LLVM.GetExecutionEngineTargetMachine(this) : default; + public readonly LLVMTargetMachineRef TargetMachine => (Handle != IntPtr.Zero) ? LLVM.GetExecutionEngineTargetMachine(this) : default; public static implicit operator LLVMExecutionEngineRef(LLVMOpaqueExecutionEngine* value) => new LLVMExecutionEngineRef((IntPtr)value); @@ -26,9 +21,9 @@ public LLVMExecutionEngineRef(IntPtr handle) public static bool operator !=(LLVMExecutionEngineRef left, LLVMExecutionEngineRef right) => !(left == right); - public void AddGlobalMapping(LLVMValueRef Global, IntPtr Addr) => LLVM.AddGlobalMapping(this, Global, (void*)Addr); + public readonly void AddGlobalMapping(LLVMValueRef Global, IntPtr Addr) => LLVM.AddGlobalMapping(this, Global, (void*)Addr); - public void AddModule(LLVMModuleRef M) => LLVM.AddModule(this, M); + public readonly void AddModule(LLVMModuleRef M) => LLVM.AddModule(this, M); public void Dispose() { @@ -39,13 +34,13 @@ public void Dispose() } } - public override bool Equals(object? obj) => (obj is LLVMExecutionEngineRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMExecutionEngineRef other) && Equals(other); - public bool Equals(LLVMExecutionEngineRef other) => this == other; + public readonly bool Equals(LLVMExecutionEngineRef other) => this == other; - public LLVMValueRef FindFunction(string Name) => FindFunction(Name.AsSpan()); + public readonly LLVMValueRef FindFunction(string Name) => FindFunction(Name.AsSpan()); - public LLVMValueRef FindFunction(ReadOnlySpan Name) + public readonly LLVMValueRef FindFunction(ReadOnlySpan Name) { if (!TryFindFunction(Name, out var Fn)) { @@ -55,35 +50,35 @@ public LLVMValueRef FindFunction(ReadOnlySpan Name) return Fn; } - public void FreeMachineCodeForFunction(LLVMValueRef F) => LLVM.FreeMachineCodeForFunction(this, F); + public readonly void FreeMachineCodeForFunction(LLVMValueRef F) => LLVM.FreeMachineCodeForFunction(this, F); - public ulong GetFunctionAddress(string Name) => GetFunctionAddress(Name.AsSpan()); + public readonly ulong GetFunctionAddress(string Name) => GetFunctionAddress(Name.AsSpan()); - public ulong GetFunctionAddress(ReadOnlySpan Name) + public readonly ulong GetFunctionAddress(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetFunctionAddress(this, marshaledName); } - public ulong GetGlobalValueAddress(string Name) => GetGlobalValueAddress(Name.AsSpan()); + public readonly ulong GetGlobalValueAddress(string Name) => GetGlobalValueAddress(Name.AsSpan()); - public ulong GetGlobalValueAddress(ReadOnlySpan Name) + public readonly ulong GetGlobalValueAddress(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetGlobalValueAddress(this, marshaledName); } - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public IntPtr GetPointerToGlobal(LLVMValueRef Global) => (IntPtr)LLVM.GetPointerToGlobal(this, Global); + public readonly IntPtr GetPointerToGlobal(LLVMValueRef Global) => (IntPtr)LLVM.GetPointerToGlobal(this, Global); - public TDelegate GetPointerToGlobal(LLVMValueRef Global) + public readonly TDelegate GetPointerToGlobal(LLVMValueRef Global) { var pGlobal = GetPointerToGlobal(Global); return Marshal.GetDelegateForFunctionPointer(pGlobal); } - public LLVMModuleRef RemoveModule(LLVMModuleRef M) + public readonly LLVMModuleRef RemoveModule(LLVMModuleRef M) { if (!TryRemoveModule(M, out LLVMModuleRef Mod, out string Error)) { @@ -93,9 +88,9 @@ public LLVMModuleRef RemoveModule(LLVMModuleRef M) return Mod; } - public LLVMGenericValueRef RunFunction(LLVMValueRef F, LLVMGenericValueRef[] Args) => RunFunction(F, Args.AsSpan()); + public readonly LLVMGenericValueRef RunFunction(LLVMValueRef F, LLVMGenericValueRef[] Args) => RunFunction(F, Args.AsSpan()); - public LLVMGenericValueRef RunFunction(LLVMValueRef F, ReadOnlySpan Args) + public readonly LLVMGenericValueRef RunFunction(LLVMValueRef F, ReadOnlySpan Args) { fixed (LLVMGenericValueRef* pArgs = Args) { @@ -103,9 +98,9 @@ public LLVMGenericValueRef RunFunction(LLVMValueRef F, ReadOnlySpan RunFunctionAsMain(F, ArgC, ArgV.AsSpan(), EnvP.AsSpan()); + public readonly int RunFunctionAsMain(LLVMValueRef F, uint ArgC, string[] ArgV, string[] EnvP) => RunFunctionAsMain(F, ArgC, ArgV.AsSpan(), EnvP.AsSpan()); - public int RunFunctionAsMain(LLVMValueRef F, uint ArgC, ReadOnlySpan ArgV, ReadOnlySpan EnvP) + public readonly int RunFunctionAsMain(LLVMValueRef F, uint ArgC, ReadOnlySpan ArgV, ReadOnlySpan EnvP) { using var marshaledArgV = new MarshaledStringArray(ArgV); using var marshaledEnvP = new MarshaledStringArray(EnvP); @@ -119,17 +114,17 @@ public int RunFunctionAsMain(LLVMValueRef F, uint ArgC, ReadOnlySpan Arg return LLVM.RunFunctionAsMain(this, F, ArgC, pArgV, pEnvP); } - public void RunStaticConstructors() => LLVM.RunStaticConstructors(this); + public readonly void RunStaticConstructors() => LLVM.RunStaticConstructors(this); - public void RunStaticDestructors() => LLVM.RunStaticDestructors(this); + public readonly void RunStaticDestructors() => LLVM.RunStaticDestructors(this); - public IntPtr RecompileAndRelinkFunction(LLVMValueRef Fn) => (IntPtr)LLVM.RecompileAndRelinkFunction(this, Fn); + public readonly IntPtr RecompileAndRelinkFunction(LLVMValueRef Fn) => (IntPtr)LLVM.RecompileAndRelinkFunction(this, Fn); - public override string ToString() => $"{nameof(LLVMExecutionEngineRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMExecutionEngineRef)}: {Handle:X}"; - public bool TryFindFunction(string Name, out LLVMValueRef OutFn) => TryFindFunction(Name.AsSpan(), out OutFn); + public readonly bool TryFindFunction(string Name, out LLVMValueRef OutFn) => TryFindFunction(Name.AsSpan(), out OutFn); - public bool TryFindFunction(ReadOnlySpan Name, out LLVMValueRef OutFn) + public readonly bool TryFindFunction(ReadOnlySpan Name, out LLVMValueRef OutFn) { fixed (LLVMValueRef* pOutFn = &OutFn) { @@ -138,7 +133,7 @@ public bool TryFindFunction(ReadOnlySpan Name, out LLVMValueRef OutFn) } } - public bool TryRemoveModule(LLVMModuleRef M, out LLVMModuleRef OutMod, out string OutError) + public readonly bool TryRemoveModule(LLVMModuleRef M, out LLVMModuleRef OutMod, out string OutError) { fixed (LLVMModuleRef* pOutMod = &OutMod) { diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMGenericValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMGenericValueRef.cs index 88337761..87c2c37d 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMGenericValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMGenericValueRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMGenericValueRef : IEquatable +public unsafe partial struct LLVMGenericValueRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMGenericValueRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMGenericValueRef(LLVMOpaqueGenericValue* GenericValue) => new LLVMGenericValueRef((IntPtr)GenericValue); @@ -21,15 +16,15 @@ public LLVMGenericValueRef(IntPtr handle) public static bool operator !=(LLVMGenericValueRef left, LLVMGenericValueRef right) => !(left == right); - public LLVMGenericValueRef CreateInt(LLVMTypeRef Ty, ulong N, bool IsSigned) => LLVM.CreateGenericValueOfInt(Ty, N, IsSigned ? 1 : 0); + public static LLVMGenericValueRef CreateInt(LLVMTypeRef Ty, ulong N, bool IsSigned) => LLVM.CreateGenericValueOfInt(Ty, N, IsSigned ? 1 : 0); - public LLVMGenericValueRef CreateFloat(LLVMTypeRef Ty, double N) => LLVM.CreateGenericValueOfFloat(Ty, N); + public static LLVMGenericValueRef CreateFloat(LLVMTypeRef Ty, double N) => LLVM.CreateGenericValueOfFloat(Ty, N); - public override bool Equals(object? obj) => (obj is LLVMGenericValueRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMGenericValueRef other) && Equals(other); - public bool Equals(LLVMGenericValueRef other) => this == other; + public readonly bool Equals(LLVMGenericValueRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMGenericValueRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMGenericValueRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMJITEventListenerRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMJITEventListenerRef.cs index 0b939e3a..5ee2ce41 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMJITEventListenerRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMJITEventListenerRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMJITEventListenerRef : IEquatable +public unsafe partial struct LLVMJITEventListenerRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMJITEventListenerRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMJITEventListenerRef(LLVMOpaqueJITEventListener* value) => new LLVMJITEventListenerRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMJITEventListenerRef(IntPtr handle) public static bool operator !=(LLVMJITEventListenerRef left, LLVMJITEventListenerRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMJITEventListenerRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMJITEventListenerRef other) && Equals(other); - public bool Equals(LLVMJITEventListenerRef other) => this == other; + public readonly bool Equals(LLVMJITEventListenerRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMJITEventListenerRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMJITEventListenerRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMCJITCompilerOptions.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMCJITCompilerOptions.cs index db67ec3b..0bd873d2 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMCJITCompilerOptions.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMCJITCompilerOptions.cs @@ -1,8 +1,5 @@ // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -using System; -using System.Runtime.InteropServices; - namespace LLVMSharp.Interop; public unsafe partial struct LLVMMCJITCompilerOptions @@ -10,7 +7,7 @@ public unsafe partial struct LLVMMCJITCompilerOptions public static LLVMMCJITCompilerOptions Create() { LLVMMCJITCompilerOptions Options; - LLVM.InitializeMCJITCompilerOptions(&Options, (UIntPtr)Marshal.SizeOf()); + LLVM.InitializeMCJITCompilerOptions(&Options, (uint)sizeof(LLVMMCJITCompilerOptions)); return Options; } } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMCJITMemoryManagerRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMCJITMemoryManagerRef.cs index 53c4b359..84e7a36f 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMCJITMemoryManagerRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMCJITMemoryManagerRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMMCJITMemoryManagerRef : IEquatable +public unsafe partial struct LLVMMCJITMemoryManagerRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMMCJITMemoryManagerRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMMCJITMemoryManagerRef(LLVMOpaqueMCJITMemoryManager* value) => new LLVMMCJITMemoryManagerRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMMCJITMemoryManagerRef(IntPtr handle) public static bool operator !=(LLVMMCJITMemoryManagerRef left, LLVMMCJITMemoryManagerRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMMCJITMemoryManagerRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMMCJITMemoryManagerRef other) && Equals(other); - public bool Equals(LLVMMCJITMemoryManagerRef other) => this == other; + public readonly bool Equals(LLVMMCJITMemoryManagerRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMMCJITMemoryManagerRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMMCJITMemoryManagerRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMemoryBufferRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMemoryBufferRef.cs index 2c52e403..4a88b4a6 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMemoryBufferRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMemoryBufferRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMMemoryBufferRef : IEquatable +public unsafe partial struct LLVMMemoryBufferRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMMemoryBufferRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMMemoryBufferRef(LLVMOpaqueMemoryBuffer* MemoryBuffer) => new LLVMMemoryBufferRef((IntPtr)MemoryBuffer); @@ -21,11 +16,11 @@ public LLVMMemoryBufferRef(IntPtr handle) public static bool operator !=(LLVMMemoryBufferRef left, LLVMMemoryBufferRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMMemoryBufferRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMMemoryBufferRef other) && Equals(other); - public bool Equals(LLVMMemoryBufferRef other) => this == other; + public readonly bool Equals(LLVMMemoryBufferRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMMemoryBufferRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMMemoryBufferRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs index e6dc85e9..7d49e735 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMMetadataRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMMetadataRef : IEquatable +public unsafe partial struct LLVMMetadataRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMMetadataRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMMetadataRef(LLVMOpaqueMetadata* value) => new LLVMMetadataRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMMetadataRef(IntPtr handle) public static bool operator !=(LLVMMetadataRef left, LLVMMetadataRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMMetadataRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMMetadataRef other) && Equals(other); - public bool Equals(LLVMMetadataRef other) => this == other; + public readonly bool Equals(LLVMMetadataRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMMetadataRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMMetadataRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFlagEntry.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFlagEntry.cs index c515892f..dff7660c 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleFlagEntry.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleFlagEntry.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMModuleFlagEntry : IEquatable +public unsafe partial struct LLVMModuleFlagEntry(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMModuleFlagEntry(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMModuleFlagEntry(LLVMOpaqueModuleFlagEntry* Comdat) => new LLVMModuleFlagEntry((IntPtr)Comdat); @@ -21,11 +16,11 @@ public LLVMModuleFlagEntry(IntPtr handle) public static bool operator !=(LLVMModuleFlagEntry left, LLVMModuleFlagEntry right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMModuleFlagEntry other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMModuleFlagEntry other) && Equals(other); - public bool Equals(LLVMModuleFlagEntry other) => this == other; + public readonly bool Equals(LLVMModuleFlagEntry other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMModuleFlagEntry)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMModuleFlagEntry)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleProviderRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleProviderRef.cs index 8c02e76a..92a6150f 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleProviderRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleProviderRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMModuleProviderRef : IEquatable +public unsafe partial struct LLVMModuleProviderRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMModuleProviderRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMModuleProviderRef(LLVMOpaqueModuleProvider* value) => new LLVMModuleProviderRef((IntPtr)value); @@ -21,13 +16,13 @@ public LLVMModuleProviderRef(IntPtr handle) public static bool operator !=(LLVMModuleProviderRef left, LLVMModuleProviderRef right) => !(left == right); - public LLVMPassManagerRef CreateFunctionPassManager() => LLVM.CreateFunctionPassManager(this); + public readonly LLVMPassManagerRef CreateFunctionPassManager() => LLVM.CreateFunctionPassManager(this); - public override bool Equals(object? obj) => (obj is LLVMModuleProviderRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMModuleProviderRef other) && Equals(other); - public bool Equals(LLVMModuleProviderRef other) => this == other; + public readonly bool Equals(LLVMModuleProviderRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMModuleProviderRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMModuleProviderRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs index 9534200c..9f5b60fa 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs @@ -5,18 +5,13 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMModuleRef : IDisposable, IEquatable +public unsafe partial struct LLVMModuleRef(IntPtr handle) : IDisposable, IEquatable { - public IntPtr Handle; + public IntPtr Handle = handle; - public LLVMModuleRef(IntPtr handle) - { - Handle = handle; - } - - public LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetModuleContext(this) : default; + public readonly LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetModuleContext(this) : default; - public string DataLayout + public readonly string DataLayout { get { @@ -42,15 +37,15 @@ public string DataLayout } } - public LLVMValueRef FirstFunction => (Handle != IntPtr.Zero) ? LLVM.GetFirstFunction(this) : default; + public readonly LLVMValueRef FirstFunction => (Handle != IntPtr.Zero) ? LLVM.GetFirstFunction(this) : default; - public LLVMValueRef FirstGlobal => (Handle != IntPtr.Zero) ? LLVM.GetFirstGlobal(this) : default; + public readonly LLVMValueRef FirstGlobal => (Handle != IntPtr.Zero) ? LLVM.GetFirstGlobal(this) : default; - public LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default; + public readonly LLVMValueRef LastFunction => (Handle != IntPtr.Zero) ? LLVM.GetLastFunction(this) : default; - public LLVMValueRef LastGlobal => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobal(this) : default; + public readonly LLVMValueRef LastGlobal => (Handle != IntPtr.Zero) ? LLVM.GetLastGlobal(this) : default; - public string Target + public readonly string Target { get { @@ -92,73 +87,73 @@ public static LLVMModuleRef CreateWithName(ReadOnlySpan ModuleID) return LLVM.ModuleCreateWithName(marshaledModuleID); } - public LLVMValueRef AddAlias2(LLVMTypeRef ValueTy, uint AddrSpace, LLVMValueRef Aliasee, string Name) => AddAlias2(ValueTy, AddrSpace, Aliasee, Name.AsSpan()); + public readonly LLVMValueRef AddAlias2(LLVMTypeRef ValueTy, uint AddrSpace, LLVMValueRef Aliasee, string Name) => AddAlias2(ValueTy, AddrSpace, Aliasee, Name.AsSpan()); - public LLVMValueRef AddAlias2(LLVMTypeRef ValueTy, uint AddrSpace, LLVMValueRef Aliasee, ReadOnlySpan Name) + public readonly LLVMValueRef AddAlias2(LLVMTypeRef ValueTy, uint AddrSpace, LLVMValueRef Aliasee, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.AddAlias2(this, ValueTy, AddrSpace, Aliasee, marshaledName); } - public LLVMValueRef AddFunction(string Name, LLVMTypeRef FunctionTy) => AddFunction(Name.AsSpan(), FunctionTy); + public readonly LLVMValueRef AddFunction(string Name, LLVMTypeRef FunctionTy) => AddFunction(Name.AsSpan(), FunctionTy); - public LLVMValueRef AddFunction(ReadOnlySpan Name, LLVMTypeRef FunctionTy) + public readonly LLVMValueRef AddFunction(ReadOnlySpan Name, LLVMTypeRef FunctionTy) { using var marshaledName = new MarshaledString(Name); return LLVM.AddFunction(this, marshaledName, FunctionTy); } - public LLVMValueRef AddGlobal(LLVMTypeRef Ty, string Name) => AddGlobal(Ty, Name.AsSpan()); + public readonly LLVMValueRef AddGlobal(LLVMTypeRef Ty, string Name) => AddGlobal(Ty, Name.AsSpan()); - public LLVMValueRef AddGlobal(LLVMTypeRef Ty, ReadOnlySpan Name) + public readonly LLVMValueRef AddGlobal(LLVMTypeRef Ty, ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.AddGlobal(this, Ty, marshaledName); } - public LLVMValueRef AddGlobalInAddressSpace(LLVMTypeRef Ty, string Name, uint AddressSpace) => AddGlobalInAddressSpace(Ty, Name.AsSpan(), AddressSpace); + public readonly LLVMValueRef AddGlobalInAddressSpace(LLVMTypeRef Ty, string Name, uint AddressSpace) => AddGlobalInAddressSpace(Ty, Name.AsSpan(), AddressSpace); - public LLVMValueRef AddGlobalInAddressSpace(LLVMTypeRef Ty, ReadOnlySpan Name, uint AddressSpace) + public readonly LLVMValueRef AddGlobalInAddressSpace(LLVMTypeRef Ty, ReadOnlySpan Name, uint AddressSpace) { using var marshaledName = new MarshaledString(Name); return LLVM.AddGlobalInAddressSpace(this, Ty, marshaledName, AddressSpace); } - public void AddModuleFlag(string FlagName, LLVMModuleFlagBehavior Behavior, uint ValAsUInt) + public readonly void AddModuleFlag(string FlagName, LLVMModuleFlagBehavior Behavior, uint ValAsUInt) { LLVMOpaqueValue* valAsValueRef = LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, ValAsUInt); AddModuleFlag(FlagName, Behavior, valAsValueRef); } - public void AddModuleFlag(string FlagName, LLVMModuleFlagBehavior Behavior, LLVMValueRef ValAsValueRef) + public readonly void AddModuleFlag(string FlagName, LLVMModuleFlagBehavior Behavior, LLVMValueRef ValAsValueRef) { LLVMOpaqueMetadata* valAsMetadata = LLVM.ValueAsMetadata(ValAsValueRef); AddModuleFlag(FlagName, Behavior, valAsMetadata); } - public void AddModuleFlag(string FlagName, LLVMModuleFlagBehavior Behavior, LLVMMetadataRef ValAsMetadataRef) => AddModuleFlag(FlagName.AsSpan(), Behavior, ValAsMetadataRef); + public readonly void AddModuleFlag(string FlagName, LLVMModuleFlagBehavior Behavior, LLVMMetadataRef ValAsMetadataRef) => AddModuleFlag(FlagName.AsSpan(), Behavior, ValAsMetadataRef); - public void AddModuleFlag(ReadOnlySpan FlagName, LLVMModuleFlagBehavior Behavior, LLVMMetadataRef ValAsMetadataRef) + public readonly void AddModuleFlag(ReadOnlySpan FlagName, LLVMModuleFlagBehavior Behavior, LLVMMetadataRef ValAsMetadataRef) { using var marshaledName = new MarshaledString(FlagName); LLVM.AddModuleFlag(this, Behavior, marshaledName, (UIntPtr)FlagName.Length, ValAsMetadataRef); } - public void AddNamedMetadataOperand(string Name, LLVMValueRef Val) => AddNamedMetadataOperand(Name.AsSpan(), Val); + public readonly void AddNamedMetadataOperand(string Name, LLVMValueRef Val) => AddNamedMetadataOperand(Name.AsSpan(), Val); - public void AddNamedMetadataOperand(ReadOnlySpan Name, LLVMValueRef Val) + public readonly void AddNamedMetadataOperand(ReadOnlySpan Name, LLVMValueRef Val) { using var marshaledName = new MarshaledString(Name); LLVM.AddNamedMetadataOperand(this, marshaledName, Val); } - public LLVMDIBuilderRef CreateDIBuilder() + public readonly LLVMDIBuilderRef CreateDIBuilder() { return new LLVMDIBuilderRef((IntPtr)LLVM.CreateDIBuilder(this)); } - public LLVMExecutionEngineRef CreateExecutionEngine() + public readonly LLVMExecutionEngineRef CreateExecutionEngine() { if (!TryCreateExecutionEngine(out LLVMExecutionEngineRef EE, out string Error)) { @@ -168,7 +163,7 @@ public LLVMExecutionEngineRef CreateExecutionEngine() return EE; } - public LLVMExecutionEngineRef CreateInterpreter() + public readonly LLVMExecutionEngineRef CreateInterpreter() { if (!TryCreateInterpreter(out LLVMExecutionEngineRef Interp, out string Error)) { @@ -178,7 +173,7 @@ public LLVMExecutionEngineRef CreateInterpreter() return Interp; } - public LLVMExecutionEngineRef CreateMCJITCompiler() + public readonly LLVMExecutionEngineRef CreateMCJITCompiler() { if (!TryCreateMCJITCompiler(out LLVMExecutionEngineRef JIT, out string Error)) { @@ -188,7 +183,7 @@ public LLVMExecutionEngineRef CreateMCJITCompiler() return JIT; } - public LLVMExecutionEngineRef CreateMCJITCompiler(ref LLVMMCJITCompilerOptions Options) + public readonly LLVMExecutionEngineRef CreateMCJITCompiler(ref LLVMMCJITCompilerOptions Options) { if (!TryCreateMCJITCompiler(out LLVMExecutionEngineRef JIT, ref Options, out string Error)) { @@ -198,15 +193,15 @@ public LLVMExecutionEngineRef CreateMCJITCompiler(ref LLVMMCJITCompilerOptions O return JIT; } - public LLVMModuleRef Clone() => LLVM.CloneModule(this); + public readonly LLVMModuleRef Clone() => LLVM.CloneModule(this); - public LLVMPassManagerRef CreateFunctionPassManager() => LLVM.CreateFunctionPassManagerForModule(this); + public readonly LLVMPassManagerRef CreateFunctionPassManager() => LLVM.CreateFunctionPassManagerForModule(this); - public LLVMModuleProviderRef CreateModuleProvider() => LLVM.CreateModuleProviderForExistingModule(this); + public readonly LLVMModuleProviderRef CreateModuleProvider() => LLVM.CreateModuleProviderForExistingModule(this); - public void AddNamedMetadataOperand(string Name, LLVMMetadataRef CompileUnitMetadata) => AddNamedMetadataOperand(Name.AsSpan(), CompileUnitMetadata); + public readonly void AddNamedMetadataOperand(string Name, LLVMMetadataRef CompileUnitMetadata) => AddNamedMetadataOperand(Name.AsSpan(), CompileUnitMetadata); - public void AddNamedMetadataOperand(ReadOnlySpan Name, LLVMMetadataRef CompileUnitMetadata) + public readonly void AddNamedMetadataOperand(ReadOnlySpan Name, LLVMMetadataRef CompileUnitMetadata) { using var marshaledName = new MarshaledString(Name); LLVM.AddNamedMetadataOperand(this, marshaledName, LLVM.MetadataAsValue(Context, CompileUnitMetadata)); @@ -221,33 +216,33 @@ public void Dispose() } } - public void Dump() => LLVM.DumpModule(this); + public readonly void Dump() => LLVM.DumpModule(this); - public override bool Equals(object? obj) => (obj is LLVMModuleRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMModuleRef other) && Equals(other); - public bool Equals(LLVMModuleRef other) => this == other; + public readonly bool Equals(LLVMModuleRef other) => this == other; - public LLVMValueRef GetNamedFunction(string Name) => GetNamedFunction(Name.AsSpan()); + public readonly LLVMValueRef GetNamedFunction(string Name) => GetNamedFunction(Name.AsSpan()); - public LLVMValueRef GetNamedFunction(ReadOnlySpan Name) + public readonly LLVMValueRef GetNamedFunction(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetNamedFunction(this, marshaledName); } - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public LLVMValueRef GetNamedGlobal(string Name) => GetNamedGlobal(Name.AsSpan()); + public readonly LLVMValueRef GetNamedGlobal(string Name) => GetNamedGlobal(Name.AsSpan()); - public LLVMValueRef GetNamedGlobal(ReadOnlySpan Name) + public readonly LLVMValueRef GetNamedGlobal(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetNamedGlobal(this, marshaledName); } - public LLVMValueRef[] GetNamedMetadataOperands(string Name) => GetNamedMetadataOperands(Name.AsSpan()); + public readonly LLVMValueRef[] GetNamedMetadataOperands(string Name) => GetNamedMetadataOperands(Name.AsSpan()); - public LLVMValueRef[] GetNamedMetadataOperands(ReadOnlySpan Name) + public readonly LLVMValueRef[] GetNamedMetadataOperands(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); var Dest = new LLVMValueRef[LLVM.GetNamedMetadataNumOperands(this, marshaledName)]; @@ -260,25 +255,25 @@ public LLVMValueRef[] GetNamedMetadataOperands(ReadOnlySpan Name) return Dest; } - public uint GetNamedMetadataOperandsCount(string Name) => GetNamedMetadataOperandsCount(Name.AsSpan()); + public readonly uint GetNamedMetadataOperandsCount(string Name) => GetNamedMetadataOperandsCount(Name.AsSpan()); - public uint GetNamedMetadataOperandsCount(ReadOnlySpan Name) + public readonly uint GetNamedMetadataOperandsCount(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetNamedMetadataNumOperands(this, marshaledName); } - public LLVMTypeRef GetTypeByName(string Name) => GetTypeByName(Name.AsSpan()); + public readonly LLVMTypeRef GetTypeByName(string Name) => GetTypeByName(Name.AsSpan()); - public LLVMTypeRef GetTypeByName(ReadOnlySpan Name) + public readonly LLVMTypeRef GetTypeByName(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.GetTypeByName(this, marshaledName); } - public void PrintToFile(string Filename) => PrintToFile(Filename.AsSpan()); + public readonly void PrintToFile(string Filename) => PrintToFile(Filename.AsSpan()); - public void PrintToFile(ReadOnlySpan Filename) + public readonly void PrintToFile(ReadOnlySpan Filename) { if (!TryPrintToFile(Filename, out string ErrorMessage)) { @@ -286,7 +281,7 @@ public void PrintToFile(ReadOnlySpan Filename) } } - public string PrintToString() + public readonly string PrintToString() { var pStr = LLVM.PrintModuleToString(this); @@ -300,17 +295,17 @@ public string PrintToString() return result; } - public void SetModuleInlineAsm(string Asm) => SetModuleInlineAsm(Asm.AsSpan()); + public readonly void SetModuleInlineAsm(string Asm) => SetModuleInlineAsm(Asm.AsSpan()); - public void SetModuleInlineAsm(ReadOnlySpan Asm) + public readonly void SetModuleInlineAsm(ReadOnlySpan Asm) { using var marshaledAsm = new MarshaledString(Asm); LLVM.SetModuleInlineAsm(this, marshaledAsm); } - public override string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; + public override readonly string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; - public bool TryCreateExecutionEngine(out LLVMExecutionEngineRef OutEE, out string OutError) + public readonly bool TryCreateExecutionEngine(out LLVMExecutionEngineRef OutEE, out string OutError) { fixed (LLVMExecutionEngineRef* pOutEE = &OutEE) { @@ -330,7 +325,7 @@ public bool TryCreateExecutionEngine(out LLVMExecutionEngineRef OutEE, out strin } } - public bool TryCreateInterpreter(out LLVMExecutionEngineRef OutInterp, out string OutError) + public readonly bool TryCreateInterpreter(out LLVMExecutionEngineRef OutInterp, out string OutError) { fixed (LLVMExecutionEngineRef* pOutInterp = &OutInterp) { @@ -350,19 +345,19 @@ public bool TryCreateInterpreter(out LLVMExecutionEngineRef OutInterp, out strin } } - public bool TryCreateMCJITCompiler(out LLVMExecutionEngineRef OutJIT, out string OutError) + public readonly bool TryCreateMCJITCompiler(out LLVMExecutionEngineRef OutJIT, out string OutError) { var Options = LLVMMCJITCompilerOptions.Create(); return TryCreateMCJITCompiler(out OutJIT, ref Options, out OutError); } - public bool TryCreateMCJITCompiler(out LLVMExecutionEngineRef OutJIT, ref LLVMMCJITCompilerOptions Options, out string OutError) + public readonly bool TryCreateMCJITCompiler(out LLVMExecutionEngineRef OutJIT, ref LLVMMCJITCompilerOptions Options, out string OutError) { fixed (LLVMExecutionEngineRef* pOutJIT = &OutJIT) fixed (LLVMMCJITCompilerOptions* pOptions = &Options) { sbyte* pError = null; - var result = LLVM.CreateMCJITCompilerForModule((LLVMOpaqueExecutionEngine**)pOutJIT, this, pOptions, (UIntPtr)Marshal.SizeOf(), &pError); + var result = LLVM.CreateMCJITCompilerForModule((LLVMOpaqueExecutionEngine**)pOutJIT, this, pOptions, (uint)sizeof(LLVMMCJITCompilerOptions), &pError); if (pError == null) { @@ -377,9 +372,9 @@ public bool TryCreateMCJITCompiler(out LLVMExecutionEngineRef OutJIT, ref LLVMMC } } - public bool TryPrintToFile(string Filename, out string ErrorMessage) => TryPrintToFile(Filename.AsSpan(), out ErrorMessage); + public readonly bool TryPrintToFile(string Filename, out string ErrorMessage) => TryPrintToFile(Filename.AsSpan(), out ErrorMessage); - public bool TryPrintToFile(ReadOnlySpan Filename, out string ErrorMessage) + public readonly bool TryPrintToFile(ReadOnlySpan Filename, out string ErrorMessage) { using var marshaledFilename = new MarshaledString(Filename); @@ -390,11 +385,11 @@ public bool TryPrintToFile(ReadOnlySpan Filename, out string ErrorMessage) { result = LLVM.PrintModuleToFile(this, marshaledFilename, &pErrorMessage); } - catch (Exception) + catch { } - if (pErrorMessage == null) + if (pErrorMessage is null) { ErrorMessage = string.Empty; } @@ -406,7 +401,7 @@ public bool TryPrintToFile(ReadOnlySpan Filename, out string ErrorMessage) return result == 0; } - public bool TryVerify(LLVMVerifierFailureAction Action, out string OutMessage) + public readonly bool TryVerify(LLVMVerifierFailureAction Action, out string OutMessage) { sbyte* pMessage = null; var result = LLVM.VerifyModule(this, Action, &pMessage); @@ -423,7 +418,7 @@ public bool TryVerify(LLVMVerifierFailureAction Action, out string OutMessage) return result == 0; } - public void Verify(LLVMVerifierFailureAction Action) + public readonly void Verify(LLVMVerifierFailureAction Action) { if (!TryVerify(Action, out string Message)) { @@ -431,17 +426,17 @@ public void Verify(LLVMVerifierFailureAction Action) } } - public int WriteBitcodeToFile(string Path) => WriteBitcodeToFile(Path.AsSpan()); + public readonly int WriteBitcodeToFile(string Path) => WriteBitcodeToFile(Path.AsSpan()); - public int WriteBitcodeToFile(ReadOnlySpan Path) + public readonly int WriteBitcodeToFile(ReadOnlySpan Path) { using var marshaledPath = new MarshaledString(Path); return LLVM.WriteBitcodeToFile(this, marshaledPath); } - public int WriteBitcodeToFD(int FD, int ShouldClose, int Unbuffered) => LLVM.WriteBitcodeToFD(this, FD, ShouldClose, Unbuffered); + public readonly int WriteBitcodeToFD(int FD, int ShouldClose, int Unbuffered) => LLVM.WriteBitcodeToFD(this, FD, ShouldClose, Unbuffered); - public int WriteBitcodeToFileHandle(int Handle) => LLVM.WriteBitcodeToFileHandle(this, Handle); + public readonly int WriteBitcodeToFileHandle(int Handle) => LLVM.WriteBitcodeToFileHandle(this, Handle); - public LLVMMemoryBufferRef WriteBitcodeToMemoryBuffer() => LLVM.WriteBitcodeToMemoryBuffer(this); + public readonly LLVMMemoryBufferRef WriteBitcodeToMemoryBuffer() => LLVM.WriteBitcodeToMemoryBuffer(this); } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs index 7657405e..8ecdc155 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMNamedMDNodeRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMNamedMDNodeRef : IEquatable +public unsafe partial struct LLVMNamedMDNodeRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMNamedMDNodeRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMNamedMDNodeRef(LLVMOpaqueNamedMDNode* value) => new LLVMNamedMDNodeRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMNamedMDNodeRef(IntPtr handle) public static bool operator !=(LLVMNamedMDNodeRef left, LLVMNamedMDNodeRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMNamedMDNodeRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMNamedMDNodeRef other) && Equals(other); - public bool Equals(LLVMNamedMDNodeRef other) => this == other; + public readonly bool Equals(LLVMNamedMDNodeRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMNamedMDNodeRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMNamedMDNodeRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMObjectFileRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMObjectFileRef.cs index 929dc995..7e5ba418 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMObjectFileRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMObjectFileRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMObjectFileRef : IEquatable +public unsafe partial struct LLVMObjectFileRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMObjectFileRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMObjectFileRef(LLVMOpaqueObjectFile* value) => new LLVMObjectFileRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMObjectFileRef(IntPtr handle) public static bool operator !=(LLVMObjectFileRef left, LLVMObjectFileRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMObjectFileRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMObjectFileRef other) && Equals(other); - public bool Equals(LLVMObjectFileRef other) => this == other; + public readonly bool Equals(LLVMObjectFileRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMObjectFileRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMObjectFileRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerBuilderRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerBuilderRef.cs index ce67e44d..288bcf7b 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerBuilderRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerBuilderRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMPassManagerBuilderRef : IEquatable, IDisposable +public unsafe partial struct LLVMPassManagerBuilderRef(IntPtr handle) : IEquatable, IDisposable { - public IntPtr Handle; - - public LLVMPassManagerBuilderRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMPassManagerBuilderRef(LLVMOpaquePassManagerBuilder* value) => new LLVMPassManagerBuilderRef((IntPtr)value); @@ -30,25 +25,25 @@ public void Dispose() } } - public override bool Equals(object? obj) => (obj is LLVMPassManagerBuilderRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMPassManagerBuilderRef other) && Equals(other); - public bool Equals(LLVMPassManagerBuilderRef other) => this == other; + public readonly bool Equals(LLVMPassManagerBuilderRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public void PopulateFunctionPassManager(LLVMPassManagerRef PM) => LLVM.PassManagerBuilderPopulateFunctionPassManager(this, PM); + public readonly void PopulateFunctionPassManager(LLVMPassManagerRef PM) => LLVM.PassManagerBuilderPopulateFunctionPassManager(this, PM); - public void PopulateModulePassManager(LLVMPassManagerRef PM) => LLVM.PassManagerBuilderPopulateModulePassManager(this, PM); + public readonly void PopulateModulePassManager(LLVMPassManagerRef PM) => LLVM.PassManagerBuilderPopulateModulePassManager(this, PM); - public void SetSizeLevel(uint SizeLevel) => LLVM.PassManagerBuilderSetSizeLevel(this, SizeLevel); + public readonly void SetSizeLevel(uint SizeLevel) => LLVM.PassManagerBuilderSetSizeLevel(this, SizeLevel); - public void SetDisableUnitAtATime(int Value) => LLVM.PassManagerBuilderSetDisableUnitAtATime(this, Value); + public readonly void SetDisableUnitAtATime(int Value) => LLVM.PassManagerBuilderSetDisableUnitAtATime(this, Value); - public void SetDisableUnrollLoops(int Value) => LLVM.PassManagerBuilderSetDisableUnrollLoops(this, Value); + public readonly void SetDisableUnrollLoops(int Value) => LLVM.PassManagerBuilderSetDisableUnrollLoops(this, Value); - public void SetDisableSimplifyLibCalls(int Value) => LLVM.PassManagerBuilderSetDisableSimplifyLibCalls(this, Value); + public readonly void SetDisableSimplifyLibCalls(int Value) => LLVM.PassManagerBuilderSetDisableSimplifyLibCalls(this, Value); - public override string ToString() => $"{nameof(LLVMPassManagerBuilderRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMPassManagerBuilderRef)}: {Handle:X}"; - public void UseInlinerWithThreshold(uint Threshold) => LLVM.PassManagerBuilderUseInlinerWithThreshold(this, Threshold); + public readonly void UseInlinerWithThreshold(uint Threshold) => LLVM.PassManagerBuilderUseInlinerWithThreshold(this, Threshold); } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs index 75f944ba..75a835cc 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMPassManagerRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMPassManagerRef : IDisposable, IEquatable +public unsafe partial struct LLVMPassManagerRef(IntPtr handle) : IDisposable, IEquatable { - public IntPtr Handle; - - public LLVMPassManagerRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMPassManagerRef(LLVMOpaquePassManager* value) => new LLVMPassManagerRef((IntPtr)value); @@ -23,115 +18,115 @@ public LLVMPassManagerRef(IntPtr handle) public static LLVMPassManagerRef Create() => LLVM.CreatePassManager(); - public void AddAggressiveDCEPass() => LLVM.AddAggressiveDCEPass(this); + public readonly void AddAggressiveDCEPass() => LLVM.AddAggressiveDCEPass(this); - public void AddAlignmentFromAssumptionsPass() => LLVM.AddAlignmentFromAssumptionsPass(this); + public readonly void AddAlignmentFromAssumptionsPass() => LLVM.AddAlignmentFromAssumptionsPass(this); - public void AddAlwaysInlinerPass() => LLVM.AddAlwaysInlinerPass(this); + public readonly void AddAlwaysInlinerPass() => LLVM.AddAlwaysInlinerPass(this); - public void AddBasicAliasAnalysisPass() => LLVM.AddBasicAliasAnalysisPass(this); + public readonly void AddBasicAliasAnalysisPass() => LLVM.AddBasicAliasAnalysisPass(this); - public void AddBitTrackingDCEPass() => LLVM.AddBitTrackingDCEPass(this); + public readonly void AddBitTrackingDCEPass() => LLVM.AddBitTrackingDCEPass(this); - public void AddCalledValuePropagationPass() => LLVM.AddCalledValuePropagationPass(this); + public readonly void AddCalledValuePropagationPass() => LLVM.AddCalledValuePropagationPass(this); - public void AddCFGSimplificationPass() => LLVM.AddCFGSimplificationPass(this); + public readonly void AddCFGSimplificationPass() => LLVM.AddCFGSimplificationPass(this); - public void AddConstantMergePass() => LLVM.AddConstantMergePass(this); + public readonly void AddConstantMergePass() => LLVM.AddConstantMergePass(this); - public void AddCorrelatedValuePropagationPass() => LLVM.AddCorrelatedValuePropagationPass(this); + public readonly void AddCorrelatedValuePropagationPass() => LLVM.AddCorrelatedValuePropagationPass(this); - public void AddDCEPass() => LLVM.AddDCEPass(this); + public readonly void AddDCEPass() => LLVM.AddDCEPass(this); - public void AddDeadArgEliminationPass() => LLVM.AddDeadArgEliminationPass(this); + public readonly void AddDeadArgEliminationPass() => LLVM.AddDeadArgEliminationPass(this); - public void AddDeadStoreEliminationPass() => LLVM.AddDeadStoreEliminationPass(this); + public readonly void AddDeadStoreEliminationPass() => LLVM.AddDeadStoreEliminationPass(this); - public void AddDemoteMemoryToRegisterPass() => LLVM.AddDemoteMemoryToRegisterPass(this); + public readonly void AddDemoteMemoryToRegisterPass() => LLVM.AddDemoteMemoryToRegisterPass(this); - public void AddEarlyCSEMemSSAPass() => LLVM.AddEarlyCSEMemSSAPass(this); + public readonly void AddEarlyCSEMemSSAPass() => LLVM.AddEarlyCSEMemSSAPass(this); - public void AddEarlyCSEPass() => LLVM.AddEarlyCSEPass(this); + public readonly void AddEarlyCSEPass() => LLVM.AddEarlyCSEPass(this); - public void AddFunctionAttrsPass() => LLVM.AddFunctionAttrsPass(this); + public readonly void AddFunctionAttrsPass() => LLVM.AddFunctionAttrsPass(this); - public void AddFunctionInliningPass() => LLVM.AddFunctionInliningPass(this); + public readonly void AddFunctionInliningPass() => LLVM.AddFunctionInliningPass(this); - public void AddGlobalDCEPass() => LLVM.AddGlobalDCEPass(this); + public readonly void AddGlobalDCEPass() => LLVM.AddGlobalDCEPass(this); - public void AddGlobalOptimizerPass() => LLVM.AddGlobalOptimizerPass(this); + public readonly void AddGlobalOptimizerPass() => LLVM.AddGlobalOptimizerPass(this); - public void AddGVNPass() => LLVM.AddGVNPass(this); + public readonly void AddGVNPass() => LLVM.AddGVNPass(this); - public void AddIndVarSimplifyPass() => LLVM.AddIndVarSimplifyPass(this); + public readonly void AddIndVarSimplifyPass() => LLVM.AddIndVarSimplifyPass(this); - public void AddInstructionCombiningPass() => LLVM.AddInstructionCombiningPass(this); + public readonly void AddInstructionCombiningPass() => LLVM.AddInstructionCombiningPass(this); - public void AddInternalizePass(uint AllButMain) => LLVM.AddInternalizePass(this, AllButMain); + public readonly void AddInternalizePass(uint AllButMain) => LLVM.AddInternalizePass(this, AllButMain); - public void AddIPSCCPPass() => LLVM.AddIPSCCPPass(this); + public readonly void AddIPSCCPPass() => LLVM.AddIPSCCPPass(this); - public void AddJumpThreadingPass() => LLVM.AddJumpThreadingPass(this); + public readonly void AddJumpThreadingPass() => LLVM.AddJumpThreadingPass(this); - public void AddLICMPass() => LLVM.AddLICMPass(this); + public readonly void AddLICMPass() => LLVM.AddLICMPass(this); - public void AddLoopDeletionPass() => LLVM.AddLoopDeletionPass(this); + public readonly void AddLoopDeletionPass() => LLVM.AddLoopDeletionPass(this); - public void AddLoopIdiomPass() => LLVM.AddLoopIdiomPass(this); + public readonly void AddLoopIdiomPass() => LLVM.AddLoopIdiomPass(this); - public void AddLoopRerollPass() => LLVM.AddLoopRerollPass(this); + public readonly void AddLoopRerollPass() => LLVM.AddLoopRerollPass(this); - public void AddLoopRotatePass() => LLVM.AddLoopRotatePass(this); + public readonly void AddLoopRotatePass() => LLVM.AddLoopRotatePass(this); - public void AddLoopUnrollPass() => LLVM.AddLoopUnrollPass(this); + public readonly void AddLoopUnrollPass() => LLVM.AddLoopUnrollPass(this); - public void AddLoopVectorizePass() => LLVM.AddLoopVectorizePass(this); + public readonly void AddLoopVectorizePass() => LLVM.AddLoopVectorizePass(this); - public void AddLowerConstantIntrinsicsPass() => LLVM.AddLowerConstantIntrinsicsPass(this); + public readonly void AddLowerConstantIntrinsicsPass() => LLVM.AddLowerConstantIntrinsicsPass(this); - public void AddLowerExpectIntrinsicPass() => LLVM.AddLowerExpectIntrinsicPass(this); + public readonly void AddLowerExpectIntrinsicPass() => LLVM.AddLowerExpectIntrinsicPass(this); - public void AddLowerSwitchPass() => LLVM.AddLowerSwitchPass(this); + public readonly void AddLowerSwitchPass() => LLVM.AddLowerSwitchPass(this); - public void AddMemCpyOptPass() => LLVM.AddMemCpyOptPass(this); + public readonly void AddMemCpyOptPass() => LLVM.AddMemCpyOptPass(this); - public void AddMergedLoadStoreMotionPass() => LLVM.AddMergedLoadStoreMotionPass(this); + public readonly void AddMergedLoadStoreMotionPass() => LLVM.AddMergedLoadStoreMotionPass(this); - public void AddMergeFunctionsPass() => LLVM.AddMergeFunctionsPass(this); + public readonly void AddMergeFunctionsPass() => LLVM.AddMergeFunctionsPass(this); - public void AddNewGVNPass() => LLVM.AddNewGVNPass(this); + public readonly void AddNewGVNPass() => LLVM.AddNewGVNPass(this); - public void AddPartiallyInlineLibCallsPass() => LLVM.AddPartiallyInlineLibCallsPass(this); + public readonly void AddPartiallyInlineLibCallsPass() => LLVM.AddPartiallyInlineLibCallsPass(this); - public void AddPromoteMemoryToRegisterPass() => LLVM.AddPromoteMemoryToRegisterPass(this); + public readonly void AddPromoteMemoryToRegisterPass() => LLVM.AddPromoteMemoryToRegisterPass(this); - public void AddReassociatePass() => LLVM.AddReassociatePass(this); + public readonly void AddReassociatePass() => LLVM.AddReassociatePass(this); - public void AddScalarizerPass() => LLVM.AddScalarizerPass(this); + public readonly void AddScalarizerPass() => LLVM.AddScalarizerPass(this); - public void AddScalarReplAggregatesPass() => LLVM.AddScalarReplAggregatesPass(this); + public readonly void AddScalarReplAggregatesPass() => LLVM.AddScalarReplAggregatesPass(this); - public void AddScalarReplAggregatesPassSSA() => LLVM.AddScalarReplAggregatesPassSSA(this); + public readonly void AddScalarReplAggregatesPassSSA() => LLVM.AddScalarReplAggregatesPassSSA(this); - public void AddScalarReplAggregatesPassWithThreshold(int Threshold) => LLVM.AddScalarReplAggregatesPassWithThreshold(this, Threshold); + public readonly void AddScalarReplAggregatesPassWithThreshold(int Threshold) => LLVM.AddScalarReplAggregatesPassWithThreshold(this, Threshold); - public void AddSCCPPass() => LLVM.AddSCCPPass(this); + public readonly void AddSCCPPass() => LLVM.AddSCCPPass(this); - public void AddScopedNoAliasAAPass() => LLVM.AddScopedNoAliasAAPass(this); + public readonly void AddScopedNoAliasAAPass() => LLVM.AddScopedNoAliasAAPass(this); - public void AddSimplifyLibCallsPass() => LLVM.AddSimplifyLibCallsPass(this); + public readonly void AddSimplifyLibCallsPass() => LLVM.AddSimplifyLibCallsPass(this); - public void AddSLPVectorizePass() => LLVM.AddSLPVectorizePass(this); + public readonly void AddSLPVectorizePass() => LLVM.AddSLPVectorizePass(this); - public void AddStripDeadPrototypesPass() => LLVM.AddStripDeadPrototypesPass(this); + public readonly void AddStripDeadPrototypesPass() => LLVM.AddStripDeadPrototypesPass(this); - public void AddStripSymbolsPass() => LLVM.AddStripSymbolsPass(this); + public readonly void AddStripSymbolsPass() => LLVM.AddStripSymbolsPass(this); - public void AddTailCallEliminationPass() => LLVM.AddTailCallEliminationPass(this); + public readonly void AddTailCallEliminationPass() => LLVM.AddTailCallEliminationPass(this); - public void AddTypeBasedAliasAnalysisPass() => LLVM.AddTypeBasedAliasAnalysisPass(this); + public readonly void AddTypeBasedAliasAnalysisPass() => LLVM.AddTypeBasedAliasAnalysisPass(this); - public void AddVerifierPass() => LLVM.AddVerifierPass(this); + public readonly void AddVerifierPass() => LLVM.AddVerifierPass(this); public void Dispose() { @@ -142,19 +137,19 @@ public void Dispose() } } - public override bool Equals(object? obj) => (obj is LLVMPassManagerRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMPassManagerRef other) && Equals(other); - public bool Equals(LLVMPassManagerRef other) => this == other; + public readonly bool Equals(LLVMPassManagerRef other) => this == other; - public bool FinalizeFunctionPassManager() => LLVM.FinalizeFunctionPassManager(this) != 0; + public readonly bool FinalizeFunctionPassManager() => LLVM.FinalizeFunctionPassManager(this) != 0; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public bool InitializeFunctionPassManager() => LLVM.InitializeFunctionPassManager(this) != 0; + public readonly bool InitializeFunctionPassManager() => LLVM.InitializeFunctionPassManager(this) != 0; - public bool Run(LLVMModuleRef M) => LLVM.RunPassManager(this, M) != 0; + public readonly bool Run(LLVMModuleRef M) => LLVM.RunPassManager(this, M) != 0; - public bool RunFunctionPassManager(LLVMValueRef F) => LLVM.RunFunctionPassManager(this, F) != 0; + public readonly bool RunFunctionPassManager(LLVMValueRef F) => LLVM.RunFunctionPassManager(this, F) != 0; - public override string ToString() => $"{nameof(LLVMPassManagerRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMPassManagerRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMPassRegistryRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMPassRegistryRef.cs index 5f7c4e43..89010650 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMPassRegistryRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMPassRegistryRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMPassRegistryRef : IEquatable +public unsafe partial struct LLVMPassRegistryRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMPassRegistryRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMPassRegistryRef(LLVMOpaquePassRegistry* value) => new LLVMPassRegistryRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMPassRegistryRef(IntPtr handle) public static bool operator !=(LLVMPassRegistryRef left, LLVMPassRegistryRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMPassRegistryRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMPassRegistryRef other) && Equals(other); - public bool Equals(LLVMPassRegistryRef other) => this == other; + public readonly bool Equals(LLVMPassRegistryRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMPassRegistryRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMPassRegistryRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMRelocationIteratorRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMRelocationIteratorRef.cs index 9ee7ee52..e86a8266 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMRelocationIteratorRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMRelocationIteratorRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMRelocationIteratorRef : IEquatable +public unsafe partial struct LLVMRelocationIteratorRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMRelocationIteratorRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMRelocationIteratorRef(LLVMOpaqueRelocationIterator* value) => new LLVMRelocationIteratorRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMRelocationIteratorRef(IntPtr handle) public static bool operator !=(LLVMRelocationIteratorRef left, LLVMRelocationIteratorRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMRelocationIteratorRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMRelocationIteratorRef other) && Equals(other); - public bool Equals(LLVMRelocationIteratorRef other) => this == other; + public readonly bool Equals(LLVMRelocationIteratorRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMRelocationIteratorRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMRelocationIteratorRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkArgRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkArgRef.cs index d5622ac5..f2eeab95 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkArgRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkArgRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMRemarkArgRef : IEquatable +public unsafe partial struct LLVMRemarkArgRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMRemarkArgRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMRemarkArgRef(LLVMRemarkOpaqueArg* value) => new LLVMRemarkArgRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMRemarkArgRef(IntPtr handle) public static bool operator !=(LLVMRemarkArgRef left, LLVMRemarkArgRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMRemarkArgRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMRemarkArgRef other) && Equals(other); - public bool Equals(LLVMRemarkArgRef other) => this == other; + public readonly bool Equals(LLVMRemarkArgRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMRemarkArgRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMRemarkArgRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkDebugLocRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkDebugLocRef.cs index 7f27e84e..c57eab8e 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkDebugLocRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkDebugLocRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMRemarkDebugLocRef : IEquatable +public unsafe partial struct LLVMRemarkDebugLocRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMRemarkDebugLocRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMRemarkDebugLocRef(LLVMRemarkOpaqueDebugLoc* value) => new LLVMRemarkDebugLocRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMRemarkDebugLocRef(IntPtr handle) public static bool operator !=(LLVMRemarkDebugLocRef left, LLVMRemarkDebugLocRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMRemarkDebugLocRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMRemarkDebugLocRef other) && Equals(other); - public bool Equals(LLVMRemarkDebugLocRef other) => this == other; + public readonly bool Equals(LLVMRemarkDebugLocRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMRemarkDebugLocRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMRemarkDebugLocRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkEntryRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkEntryRef.cs index b0ec4c5f..e35bcd7c 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkEntryRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkEntryRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMRemarkEntryRef : IEquatable +public unsafe partial struct LLVMRemarkEntryRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMRemarkEntryRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMRemarkEntryRef(LLVMRemarkOpaqueEntry* value) => new LLVMRemarkEntryRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMRemarkEntryRef(IntPtr handle) public static bool operator !=(LLVMRemarkEntryRef left, LLVMRemarkEntryRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMRemarkEntryRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMRemarkEntryRef other) && Equals(other); - public bool Equals(LLVMRemarkEntryRef other) => this == other; + public readonly bool Equals(LLVMRemarkEntryRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMRemarkEntryRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMRemarkEntryRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkParserRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkParserRef.cs index 2aeb43d1..4bd898a9 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkParserRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkParserRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMRemarkParserRef : IEquatable +public unsafe partial struct LLVMRemarkParserRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMRemarkParserRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMRemarkParserRef(LLVMRemarkOpaqueParser* value) => new LLVMRemarkParserRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMRemarkParserRef(IntPtr handle) public static bool operator !=(LLVMRemarkParserRef left, LLVMRemarkParserRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMRemarkParserRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMRemarkParserRef other) && Equals(other); - public bool Equals(LLVMRemarkParserRef other) => this == other; + public readonly bool Equals(LLVMRemarkParserRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMRemarkParserRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMRemarkParserRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkStringRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkStringRef.cs index eef64d50..f63223d1 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMRemarkStringRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMRemarkStringRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMRemarkStringRef : IEquatable +public unsafe partial struct LLVMRemarkStringRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMRemarkStringRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMRemarkStringRef(LLVMRemarkOpaqueString* value) => new LLVMRemarkStringRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMRemarkStringRef(IntPtr handle) public static bool operator !=(LLVMRemarkStringRef left, LLVMRemarkStringRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMRemarkStringRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMRemarkStringRef other) && Equals(other); - public bool Equals(LLVMRemarkStringRef other) => this == other; + public readonly bool Equals(LLVMRemarkStringRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMRemarkStringRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMRemarkStringRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMSectionIteratorRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMSectionIteratorRef.cs index 2440241e..5e05623e 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMSectionIteratorRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMSectionIteratorRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMSectionIteratorRef : IEquatable +public unsafe partial struct LLVMSectionIteratorRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMSectionIteratorRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMSectionIteratorRef(LLVMOpaqueSectionIterator* value) => new LLVMSectionIteratorRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMSectionIteratorRef(IntPtr handle) public static bool operator !=(LLVMSectionIteratorRef left, LLVMSectionIteratorRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMSectionIteratorRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMSectionIteratorRef other) && Equals(other); - public bool Equals(LLVMSectionIteratorRef other) => this == other; + public readonly bool Equals(LLVMSectionIteratorRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMSectionIteratorRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMSectionIteratorRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMSymbolIteratorRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMSymbolIteratorRef.cs index 10eb4636..d8f7e508 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMSymbolIteratorRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMSymbolIteratorRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMSymbolIteratorRef : IEquatable +public unsafe partial struct LLVMSymbolIteratorRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMSymbolIteratorRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMSymbolIteratorRef(LLVMOpaqueSymbolIterator* value) => new LLVMSymbolIteratorRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMSymbolIteratorRef(IntPtr handle) public static bool operator !=(LLVMSymbolIteratorRef left, LLVMSymbolIteratorRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMSymbolIteratorRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMSymbolIteratorRef other) && Equals(other); - public bool Equals(LLVMSymbolIteratorRef other) => this == other; + public readonly bool Equals(LLVMSymbolIteratorRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMSymbolIteratorRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMSymbolIteratorRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMTargetDataRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMTargetDataRef.cs index d3fb7038..0e8e3aec 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMTargetDataRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMTargetDataRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMTargetDataRef : IEquatable +public unsafe partial struct LLVMTargetDataRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMTargetDataRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMTargetDataRef(LLVMOpaqueTargetData* TargetData) => new LLVMTargetDataRef((IntPtr)TargetData); @@ -23,29 +18,29 @@ public LLVMTargetDataRef(IntPtr handle) public static LLVMTargetDataRef FromStringRepresentation(ReadOnlySpan stringRep) => LLVM.CreateTargetData(new MarshaledString(stringRep)); - public override bool Equals(object? obj) => (obj is LLVMTargetDataRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMTargetDataRef other) && Equals(other); - public bool Equals(LLVMTargetDataRef other) => this == other; + public readonly bool Equals(LLVMTargetDataRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public ulong OffsetOfElement(LLVMTypeRef type, uint element) => LLVM.OffsetOfElement(this, type, element); + public readonly ulong OffsetOfElement(LLVMTypeRef type, uint element) => LLVM.OffsetOfElement(this, type, element); - public ulong ElementAtOffset(LLVMTypeRef type, ulong offset) => LLVM.ElementAtOffset(this, type, offset); + public readonly ulong ElementAtOffset(LLVMTypeRef type, ulong offset) => LLVM.ElementAtOffset(this, type, offset); - public ulong SizeOfTypeInBits(LLVMTypeRef type) => LLVM.SizeOfTypeInBits(this, type); + public readonly ulong SizeOfTypeInBits(LLVMTypeRef type) => LLVM.SizeOfTypeInBits(this, type); - public ulong StoreSizeOfType(LLVMTypeRef type) => LLVM.StoreSizeOfType(this, type); + public readonly ulong StoreSizeOfType(LLVMTypeRef type) => LLVM.StoreSizeOfType(this, type); - public ulong ABISizeOfType(LLVMTypeRef type) => LLVM.ABISizeOfType(this, type); + public readonly ulong ABISizeOfType(LLVMTypeRef type) => LLVM.ABISizeOfType(this, type); - public uint ABIAlignmentOfType(LLVMTypeRef type) => LLVM.ABIAlignmentOfType(this, type); + public readonly uint ABIAlignmentOfType(LLVMTypeRef type) => LLVM.ABIAlignmentOfType(this, type); - public uint CallFrameAlignmentOfType(LLVMTypeRef type) => LLVM.CallFrameAlignmentOfType(this, type); + public readonly uint CallFrameAlignmentOfType(LLVMTypeRef type) => LLVM.CallFrameAlignmentOfType(this, type); - public uint PreferredAlignmentOfType(LLVMTypeRef type) => LLVM.PreferredAlignmentOfType(this, type); + public readonly uint PreferredAlignmentOfType(LLVMTypeRef type) => LLVM.PreferredAlignmentOfType(this, type); - public uint PreferredAlignmentOfGlobal(LLVMValueRef globalVar) => LLVM.PreferredAlignmentOfGlobal(this, globalVar); + public readonly uint PreferredAlignmentOfGlobal(LLVMValueRef globalVar) => LLVM.PreferredAlignmentOfGlobal(this, globalVar); - public override string ToString() => $"{nameof(LLVMTargetDataRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMTargetDataRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMTargetLibraryInfoRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMTargetLibraryInfoRef.cs index 56d8c0b7..0a7dd37b 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMTargetLibraryInfoRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMTargetLibraryInfoRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMTargetLibraryInfoRef : IEquatable +public unsafe partial struct LLVMTargetLibraryInfoRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMTargetLibraryInfoRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMTargetLibraryInfoRef(LLVMOpaqueTargetLibraryInfotData* value) => new LLVMTargetLibraryInfoRef((IntPtr)value); @@ -21,11 +16,11 @@ public LLVMTargetLibraryInfoRef(IntPtr handle) public static bool operator !=(LLVMTargetLibraryInfoRef left, LLVMTargetLibraryInfoRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMTargetLibraryInfoRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMTargetLibraryInfoRef other) && Equals(other); - public bool Equals(LLVMTargetLibraryInfoRef other) => this == other; + public readonly bool Equals(LLVMTargetLibraryInfoRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMTargetLibraryInfoRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMTargetLibraryInfoRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMTargetMachineRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMTargetMachineRef.cs index f33d9e5a..1d3c8a9e 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMTargetMachineRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMTargetMachineRef.cs @@ -5,14 +5,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMTargetMachineRef : IEquatable +public unsafe partial struct LLVMTargetMachineRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMTargetMachineRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMTargetMachineRef(LLVMOpaqueTargetMachine* value) => new LLVMTargetMachineRef((IntPtr)value); @@ -22,11 +17,11 @@ public LLVMTargetMachineRef(IntPtr handle) public static bool operator !=(LLVMTargetMachineRef left, LLVMTargetMachineRef right) => !(left == right); - public LLVMTargetDataRef CreateTargetDataLayout() => LLVM.CreateTargetDataLayout(this); + public readonly LLVMTargetDataRef CreateTargetDataLayout() => LLVM.CreateTargetDataLayout(this); - public void EmitToFile(LLVMModuleRef module, string fileName, LLVMCodeGenFileType codegen) => EmitToFile(module, fileName.AsSpan(), codegen); + public readonly void EmitToFile(LLVMModuleRef module, string fileName, LLVMCodeGenFileType codegen) => EmitToFile(module, fileName.AsSpan(), codegen); - public void EmitToFile(LLVMModuleRef module, ReadOnlySpan fileName, LLVMCodeGenFileType codegen) + public readonly void EmitToFile(LLVMModuleRef module, ReadOnlySpan fileName, LLVMCodeGenFileType codegen) { if (!TryEmitToFile(module, fileName, codegen, out string Error)) { @@ -34,17 +29,17 @@ public void EmitToFile(LLVMModuleRef module, ReadOnlySpan fileName, LLVMCo } } - public override bool Equals(object? obj) => (obj is LLVMTargetMachineRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMTargetMachineRef other) && Equals(other); - public bool Equals(LLVMTargetMachineRef other) => this == other; + public readonly bool Equals(LLVMTargetMachineRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMTargetMachineRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMTargetMachineRef)}: {Handle:X}"; - public bool TryEmitToFile(LLVMModuleRef module, string fileName, LLVMCodeGenFileType codegen, out string message) => TryEmitToFile(module, fileName.AsSpan(), codegen, out message); + public readonly bool TryEmitToFile(LLVMModuleRef module, string fileName, LLVMCodeGenFileType codegen, out string message) => TryEmitToFile(module, fileName.AsSpan(), codegen, out message); - public bool TryEmitToFile(LLVMModuleRef module, ReadOnlySpan fileName, LLVMCodeGenFileType codegen, out string message) + public readonly bool TryEmitToFile(LLVMModuleRef module, ReadOnlySpan fileName, LLVMCodeGenFileType codegen, out string message) { using var marshaledFileName = new MarshaledString(fileName); diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMTargetRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMTargetRef.cs index b19691e4..042ce323 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMTargetRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMTargetRef.cs @@ -6,14 +6,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMTargetRef : IEquatable +public unsafe partial struct LLVMTargetRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMTargetRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static string DefaultTriple { @@ -80,7 +75,7 @@ public static IEnumerable Targets } } - public string Name + public readonly string Name { get { @@ -108,17 +103,17 @@ public string Name public static bool operator !=(LLVMTargetRef left, LLVMTargetRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMTargetRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMTargetRef other) && Equals(other); - public bool Equals(LLVMTargetRef other) => this == other; + public readonly bool Equals(LLVMTargetRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public LLVMTargetRef GetNext() => LLVM.GetNextTarget(this); + public readonly LLVMTargetRef GetNext() => LLVM.GetNextTarget(this); - public LLVMTargetMachineRef CreateTargetMachine(string triple, string cpu, string features, LLVMCodeGenOptLevel level, LLVMRelocMode reloc, LLVMCodeModel codeModel) => CreateTargetMachine(triple.AsSpan(), cpu.AsSpan(), features.AsSpan(), level, reloc, codeModel); + public readonly LLVMTargetMachineRef CreateTargetMachine(string triple, string cpu, string features, LLVMCodeGenOptLevel level, LLVMRelocMode reloc, LLVMCodeModel codeModel) => CreateTargetMachine(triple.AsSpan(), cpu.AsSpan(), features.AsSpan(), level, reloc, codeModel); - public LLVMTargetMachineRef CreateTargetMachine(ReadOnlySpan triple, ReadOnlySpan cpu, ReadOnlySpan features, LLVMCodeGenOptLevel level, LLVMRelocMode reloc, LLVMCodeModel codeModel) + public readonly LLVMTargetMachineRef CreateTargetMachine(ReadOnlySpan triple, ReadOnlySpan cpu, ReadOnlySpan features, LLVMCodeGenOptLevel level, LLVMRelocMode reloc, LLVMCodeModel codeModel) { using var marshaledTriple = new MarshaledString(triple); using var marshaledCPU = new MarshaledString(cpu); @@ -126,5 +121,5 @@ public LLVMTargetMachineRef CreateTargetMachine(ReadOnlySpan triple, ReadO return LLVM.CreateTargetMachine(this, marshaledTriple, marshaledCPU, marshaledFeatures, level, reloc, codeModel); } - public override string ToString() => $"{nameof(LLVMTargetRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMTargetRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMTypeRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMTypeRef.cs index 2f3be320..540a89ab 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMTypeRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMTypeRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMTypeRef : IEquatable +public unsafe partial struct LLVMTypeRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMTypeRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static LLVMTypeRef BFloat => LLVM.BFloatType(); @@ -45,79 +40,39 @@ public LLVMTypeRef(IntPtr handle) public static LLVMTypeRef X86AMX => LLVM.X86AMXType(); - public LLVMValueRef AlignOf => (Handle != IntPtr.Zero) ? LLVM.AlignOf(this) : default; - - public uint ArrayLength => (Kind == LLVMTypeKind.LLVMArrayTypeKind) ? LLVM.GetArrayLength(this) : default; - - public LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetTypeContext(this) : default; - - public LLVMTypeRef ElementType => (((Kind == LLVMTypeKind.LLVMPointerTypeKind) && (SubtypesCount != 0)) || (Kind == LLVMTypeKind.LLVMArrayTypeKind) || (Kind == LLVMTypeKind.LLVMVectorTypeKind)) ? LLVM.GetElementType(this) : default; - - public uint IntWidth => (Kind == LLVMTypeKind.LLVMIntegerTypeKind) ? LLVM.GetIntTypeWidth(this) : default; - - public bool IsFunctionVarArg => (Kind == LLVMTypeKind.LLVMFunctionTypeKind) && LLVM.IsFunctionVarArg(this) != 0; - - public bool IsOpaqueStruct => (Kind == LLVMTypeKind.LLVMStructTypeKind) && LLVM.IsOpaqueStruct(this) != 0; - - public bool IsPackedStruct => (Kind == LLVMTypeKind.LLVMStructTypeKind) && LLVM.IsPackedStruct(this) != 0; - - public bool IsSized => (Handle != IntPtr.Zero) && LLVM.TypeIsSized(this) != 0; + public readonly LLVMValueRef AlignOf => (Handle != IntPtr.Zero) ? LLVM.AlignOf(this) : default; - public LLVMTypeKind Kind => (Handle != IntPtr.Zero) ? LLVM.GetTypeKind(this) : default; + public readonly uint ArrayLength => (Kind == LLVMTypeKind.LLVMArrayTypeKind) ? LLVM.GetArrayLength(this) : default; - public LLVMTypeRef[] ParamTypes - { - get - { - if (Kind != LLVMTypeKind.LLVMFunctionTypeKind) - { - return Array.Empty(); - } + public readonly LLVMContextRef Context => (Handle != IntPtr.Zero) ? LLVM.GetTypeContext(this) : default; - var Dest = new LLVMTypeRef[ParamTypesCount]; + public readonly LLVMTypeRef ElementType => (((Kind == LLVMTypeKind.LLVMPointerTypeKind) && (SubtypesCount != 0)) || (Kind == LLVMTypeKind.LLVMArrayTypeKind) || (Kind == LLVMTypeKind.LLVMVectorTypeKind)) ? LLVM.GetElementType(this) : default; - fixed (LLVMTypeRef* pDest = Dest) - { - LLVM.GetParamTypes(this, (LLVMOpaqueType**)pDest); - } + public readonly uint IntWidth => (Kind == LLVMTypeKind.LLVMIntegerTypeKind) ? LLVM.GetIntTypeWidth(this) : default; - return Dest; - } - } + public readonly bool IsFunctionVarArg => (Kind == LLVMTypeKind.LLVMFunctionTypeKind) && LLVM.IsFunctionVarArg(this) != 0; - public uint ParamTypesCount => (Kind == LLVMTypeKind.LLVMFunctionTypeKind) ? LLVM.CountParamTypes(this) : default; + public readonly bool IsOpaqueStruct => (Kind == LLVMTypeKind.LLVMStructTypeKind) && LLVM.IsOpaqueStruct(this) != 0; - public uint PointerAddressSpace => (Kind == LLVMTypeKind.LLVMPointerTypeKind) ? LLVM.GetPointerAddressSpace(this) : default; + public readonly bool IsPackedStruct => (Kind == LLVMTypeKind.LLVMStructTypeKind) && LLVM.IsPackedStruct(this) != 0; - public LLVMValueRef Poison => (Handle != IntPtr.Zero) ? LLVM.GetPoison(this) : default; + public readonly bool IsSized => (Handle != IntPtr.Zero) && LLVM.TypeIsSized(this) != 0; - public LLVMTypeRef ReturnType => (Kind == LLVMTypeKind.LLVMFunctionTypeKind) ? LLVM.GetReturnType(this) : default; + public readonly LLVMTypeKind Kind => (Handle != IntPtr.Zero) ? LLVM.GetTypeKind(this) : default; - public LLVMValueRef SizeOf => (Handle != IntPtr.Zero) ? LLVM.SizeOf(this) : default; + public readonly uint ParamTypesCount => (Kind == LLVMTypeKind.LLVMFunctionTypeKind) ? LLVM.CountParamTypes(this) : default; - public LLVMTypeRef[] StructElementTypes - { - get - { - if (Kind != LLVMTypeKind.LLVMStructTypeKind) - { - return Array.Empty(); - } + public readonly uint PointerAddressSpace => (Kind == LLVMTypeKind.LLVMPointerTypeKind) ? LLVM.GetPointerAddressSpace(this) : default; - var Dest = new LLVMTypeRef[StructElementTypesCount]; + public readonly LLVMValueRef Poison => (Handle != IntPtr.Zero) ? LLVM.GetPoison(this) : default; - fixed (LLVMTypeRef* pDest = Dest) - { - LLVM.GetStructElementTypes(this, (LLVMOpaqueType**)pDest); - } + public readonly LLVMTypeRef ReturnType => (Kind == LLVMTypeKind.LLVMFunctionTypeKind) ? LLVM.GetReturnType(this) : default; - return Dest; - } - } + public readonly LLVMValueRef SizeOf => (Handle != IntPtr.Zero) ? LLVM.SizeOf(this) : default; - public uint StructElementTypesCount => (Kind == LLVMTypeKind.LLVMStructTypeKind) ? LLVM.CountStructElementTypes(this) : default; + public readonly uint StructElementTypesCount => (Kind == LLVMTypeKind.LLVMStructTypeKind) ? LLVM.CountStructElementTypes(this) : default; - public string StructName + public readonly string StructName { get { @@ -137,31 +92,11 @@ public string StructName } } - public LLVMTypeRef[] Subtypes - { - get - { - if (Handle == IntPtr.Zero) - { - return Array.Empty(); - } - - var Arr = new LLVMTypeRef[SubtypesCount]; - - fixed (LLVMTypeRef* pArr = Arr) - { - LLVM.GetSubtypes(this, (LLVMOpaqueType**)pArr); - } - - return Arr; - } - } - - public uint SubtypesCount => (Handle != IntPtr.Zero) ? LLVM.GetNumContainedTypes(this) : default; + public readonly uint SubtypesCount => (Handle != IntPtr.Zero) ? LLVM.GetNumContainedTypes(this) : default; - public LLVMValueRef Undef => (Handle != IntPtr.Zero) ? LLVM.GetUndef(this) : default; + public readonly LLVMValueRef Undef => (Handle != IntPtr.Zero) ? LLVM.GetUndef(this) : default; - public uint VectorSize => (Kind == LLVMTypeKind.LLVMVectorTypeKind) ? LLVM.GetVectorSize(this) : default; + public readonly uint VectorSize => (Kind == LLVMTypeKind.LLVMVectorTypeKind) ? LLVM.GetVectorSize(this) : default; public static implicit operator LLVMTypeRef(LLVMOpaqueType* value) => new LLVMTypeRef((IntPtr)value); @@ -205,17 +140,98 @@ public static LLVMTypeRef CreateStruct(ReadOnlySpan ElementTypes, b public static LLVMTypeRef CreateScalableVector(LLVMTypeRef ElementType, uint ElementCount) => LLVM.ScalableVectorType(ElementType, ElementCount); - public void Dump() => LLVM.DumpType(this); + public readonly void Dump() => LLVM.DumpType(this); + + public override readonly bool Equals(object? obj) => (obj is LLVMTypeRef other) && Equals(other); - public override bool Equals(object? obj) => (obj is LLVMTypeRef other) && Equals(other); + public readonly bool Equals(LLVMTypeRef other) => this == other; - public bool Equals(LLVMTypeRef other) => this == other; + public readonly double GenericValueToFloat(LLVMGenericValueRef GenVal) => LLVM.GenericValueToFloat(this, GenVal); - public double GenericValueToFloat(LLVMGenericValueRef GenVal) => LLVM.GenericValueToFloat(this, GenVal); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override int GetHashCode() => Handle.GetHashCode(); + public readonly LLVMTypeRef[] GetParamTypes() + { + if (Kind != LLVMTypeKind.LLVMFunctionTypeKind) + { + return []; + } + + var destination = new LLVMTypeRef[ParamTypesCount]; + GetParamTypes(destination); + return destination; + } + + public readonly void GetParamTypes(Span destination) + { + if (Kind != LLVMTypeKind.LLVMFunctionTypeKind) + { + return; + } + + ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, ParamTypesCount); + + fixed (LLVMTypeRef* pDest = destination) + { + LLVM.GetParamTypes(this, (LLVMOpaqueType**)pDest); + } + } + + public readonly LLVMTypeRef[] GetStructElementTypes() + { + if (Kind != LLVMTypeKind.LLVMStructTypeKind) + { + return []; + } + + var destination = new LLVMTypeRef[StructElementTypesCount]; + GetStructElementTypes(destination); + return destination; + } + + public readonly void GetStructElementTypes(Span destination) + { + if (Kind != LLVMTypeKind.LLVMStructTypeKind) + { + return; + } + + ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, StructElementTypesCount); + + fixed (LLVMTypeRef* pDest = destination) + { + LLVM.GetStructElementTypes(this, (LLVMOpaqueType**)pDest); + } + } + + public readonly LLVMTypeRef[] GetSubtypes() + { + if (Handle == IntPtr.Zero) + { + return []; + } + + var destination = new LLVMTypeRef[SubtypesCount]; + GetSubtypes(destination); + return destination; + } + + public readonly void GetSubtypes(Span destination) + { + if (Handle == IntPtr.Zero) + { + return; + } + + ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, SubtypesCount); + + fixed (LLVMTypeRef* pArr = destination) + { + LLVM.GetSubtypes(this, (LLVMOpaqueType**)pArr); + } + } - public string PrintToString() + public readonly string PrintToString() { var pStr = LLVM.PrintTypeToString(this); @@ -229,11 +245,11 @@ public string PrintToString() return result; } - public LLVMTypeRef StructGetTypeAtIndex(uint index) => LLVM.StructGetTypeAtIndex(this, index); + public readonly LLVMTypeRef StructGetTypeAtIndex(uint index) => LLVM.StructGetTypeAtIndex(this, index); - public void StructSetBody(LLVMTypeRef[] ElementTypes, bool Packed) => StructSetBody(ElementTypes.AsSpan(), Packed); + public readonly void StructSetBody(LLVMTypeRef[] ElementTypes, bool Packed) => StructSetBody(ElementTypes.AsSpan(), Packed); - public void StructSetBody(ReadOnlySpan ElementTypes, bool Packed) + public readonly void StructSetBody(ReadOnlySpan ElementTypes, bool Packed) { fixed (LLVMTypeRef* pElementTypes = ElementTypes) { @@ -241,5 +257,5 @@ public void StructSetBody(ReadOnlySpan ElementTypes, bool Packed) } } - public override string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; + public override readonly string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs index 98a550b9..cd81413d 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMUseRef.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMUseRef : IEquatable +public unsafe partial struct LLVMUseRef(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public LLVMUseRef(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator LLVMUseRef(LLVMOpaqueUse* Use) => new LLVMUseRef((IntPtr)Use); @@ -21,11 +16,11 @@ public LLVMUseRef(IntPtr handle) public static bool operator !=(LLVMUseRef left, LLVMUseRef right) => !(left == right); - public override bool Equals(object? obj) => (obj is LLVMUseRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMUseRef other) && Equals(other); - public bool Equals(LLVMUseRef other) => this == other; + public readonly bool Equals(LLVMUseRef other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(LLVMUseRef)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(LLVMUseRef)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs index 1c8fbf1c..68bcbe61 100644 --- a/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs +++ b/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs @@ -4,16 +4,11 @@ namespace LLVMSharp.Interop; -public unsafe partial struct LLVMValueRef : IEquatable +public unsafe partial struct LLVMValueRef(IntPtr handle) : IEquatable { - public IntPtr Handle; + public IntPtr Handle = handle; - public LLVMValueRef(IntPtr handle) - { - Handle = handle; - } - - public uint Alignment + public readonly uint Alignment { get { @@ -26,7 +21,7 @@ public uint Alignment } } - public LLVMAtomicRMWBinOp AtomicRMWBinOp + public readonly LLVMAtomicRMWBinOp AtomicRMWBinOp { get { @@ -39,29 +34,9 @@ public LLVMAtomicRMWBinOp AtomicRMWBinOp } } - public LLVMBasicBlockRef[] BasicBlocks - { - get - { - if (IsAFunction == null) - { - return Array.Empty(); - } - - var BasicBlocks = new LLVMBasicBlockRef[BasicBlocksCount]; + public readonly uint BasicBlocksCount => (IsAFunction != null) ? LLVM.CountBasicBlocks(this) : default; - fixed (LLVMBasicBlockRef* pBasicBlocks = BasicBlocks) - { - LLVM.GetBasicBlocks(this, (LLVMOpaqueBasicBlock**)pBasicBlocks); - } - - return BasicBlocks; - } - } - - public uint BasicBlocksCount => (IsAFunction != null) ? LLVM.CountBasicBlocks(this) : default; - - public LLVMValueRef Condition + public readonly LLVMValueRef Condition { get { @@ -74,13 +49,13 @@ public LLVMValueRef Condition } } - public ulong ConstIntZExt => (IsAConstantInt != null) ? LLVM.ConstIntGetZExtValue(this) : default; + public readonly ulong ConstIntZExt => (IsAConstantInt != null) ? LLVM.ConstIntGetZExtValue(this) : default; - public long ConstIntSExt => (IsAConstantInt != null) ? LLVM.ConstIntGetSExtValue(this) : default; + public readonly long ConstIntSExt => (IsAConstantInt != null) ? LLVM.ConstIntGetSExtValue(this) : default; - public LLVMOpcode ConstOpcode => (IsAConstantExpr != null) ? LLVM.GetConstOpcode(this) : default; + public readonly LLVMOpcode ConstOpcode => (IsAConstantExpr != null) ? LLVM.GetConstOpcode(this) : default; - public LLVMDLLStorageClass DLLStorageClass + public readonly LLVMDLLStorageClass DLLStorageClass { get { @@ -93,17 +68,17 @@ public LLVMDLLStorageClass DLLStorageClass } } - public LLVMBasicBlockRef EntryBasicBlock => ((IsAFunction != null) && (BasicBlocksCount != 0)) ? LLVM.GetEntryBasicBlock(this) : default; + public readonly LLVMBasicBlockRef EntryBasicBlock => ((IsAFunction != null) && (BasicBlocksCount != 0)) ? LLVM.GetEntryBasicBlock(this) : default; - public LLVMRealPredicate FCmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetFCmpPredicate(this) : default; + public readonly LLVMRealPredicate FCmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetFCmpPredicate(this) : default; - public LLVMBasicBlockRef FirstBasicBlock => (IsAFunction != null) ? LLVM.GetFirstBasicBlock(this) : default; + public readonly LLVMBasicBlockRef FirstBasicBlock => (IsAFunction != null) ? LLVM.GetFirstBasicBlock(this) : default; - public LLVMValueRef FirstParam => (IsAFunction != null) ? LLVM.GetFirstParam(this) : default; + public readonly LLVMValueRef FirstParam => (IsAFunction != null) ? LLVM.GetFirstParam(this) : default; - public LLVMUseRef FirstUse => (Handle != IntPtr.Zero) ? LLVM.GetFirstUse(this) : default; + public readonly LLVMUseRef FirstUse => (Handle != IntPtr.Zero) ? LLVM.GetFirstUse(this) : default; - public uint FunctionCallConv + public readonly uint FunctionCallConv { get { @@ -116,7 +91,7 @@ public uint FunctionCallConv } } - public string GC + public readonly string GC { get { @@ -142,13 +117,13 @@ public string GC } } - public LLVMModuleRef GlobalParent => (IsAGlobalValue != null) ? LLVM.GetGlobalParent(this) : default; + public readonly LLVMModuleRef GlobalParent => (IsAGlobalValue != null) ? LLVM.GetGlobalParent(this) : default; - public bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0; + public readonly bool HasMetadata => (IsAInstruction != null) && LLVM.HasMetadata(this) != 0; - public bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0; + public readonly bool HasPersonalityFn => (IsAFunction != null) && LLVM.HasPersonalityFn(this) != 0; - public bool HasUnnamedAddr + public readonly bool HasUnnamedAddr { get { @@ -161,11 +136,11 @@ public bool HasUnnamedAddr } } - public LLVMIntPredicate ICmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetICmpPredicate(this) : default; + public readonly LLVMIntPredicate ICmpPredicate => (Handle != IntPtr.Zero) ? LLVM.GetICmpPredicate(this) : default; - public uint IncomingCount => (IsAPHINode != null) ? LLVM.CountIncoming(this) : default; + public readonly uint IncomingCount => (IsAPHINode != null) ? LLVM.CountIncoming(this) : default; - public LLVMValueRef Initializer + public readonly LLVMValueRef Initializer { get { @@ -178,7 +153,7 @@ public LLVMValueRef Initializer } } - public uint InstructionCallConv + public readonly uint InstructionCallConv { get { @@ -191,199 +166,199 @@ public uint InstructionCallConv } } - public LLVMValueRef InstructionClone => (Handle != IntPtr.Zero) ? LLVM.InstructionClone(this) : default; + public readonly LLVMValueRef InstructionClone => (Handle != IntPtr.Zero) ? LLVM.InstructionClone(this) : default; - public LLVMOpcode InstructionOpcode => (Handle != IntPtr.Zero) ? LLVM.GetInstructionOpcode(this) : default; + public readonly LLVMOpcode InstructionOpcode => (Handle != IntPtr.Zero) ? LLVM.GetInstructionOpcode(this) : default; - public LLVMBasicBlockRef InstructionParent => (IsAInstruction != null) ? LLVM.GetInstructionParent(this) : default; + public readonly LLVMBasicBlockRef InstructionParent => (IsAInstruction != null) ? LLVM.GetInstructionParent(this) : default; - public uint IntrinsicID => (Handle != IntPtr.Zero) ? LLVM.GetIntrinsicID(this) : default; + public readonly uint IntrinsicID => (Handle != IntPtr.Zero) ? LLVM.GetIntrinsicID(this) : default; - public LLVMValueRef IsAAddrSpaceCastInst => LLVM.IsAAddrSpaceCastInst(this); + public readonly LLVMValueRef IsAAddrSpaceCastInst => LLVM.IsAAddrSpaceCastInst(this); - public LLVMValueRef IsAAllocaInst => LLVM.IsAAllocaInst(this); + public readonly LLVMValueRef IsAAllocaInst => LLVM.IsAAllocaInst(this); - public LLVMValueRef IsAArgument => LLVM.IsAArgument(this); + public readonly LLVMValueRef IsAArgument => LLVM.IsAArgument(this); - public LLVMValueRef IsAAtomicCmpXchgInst => LLVM.IsAAtomicCmpXchgInst(this); + public readonly LLVMValueRef IsAAtomicCmpXchgInst => LLVM.IsAAtomicCmpXchgInst(this); - public LLVMValueRef IsAAtomicRMWInst => LLVM.IsAAtomicRMWInst(this); + public readonly LLVMValueRef IsAAtomicRMWInst => LLVM.IsAAtomicRMWInst(this); - public LLVMValueRef IsABasicBlock => LLVM.IsABasicBlock(this); + public readonly LLVMValueRef IsABasicBlock => LLVM.IsABasicBlock(this); - public LLVMValueRef IsABinaryOperator => LLVM.IsABinaryOperator(this); + public readonly LLVMValueRef IsABinaryOperator => LLVM.IsABinaryOperator(this); - public LLVMValueRef IsABitCastInst => LLVM.IsABitCastInst(this); + public readonly LLVMValueRef IsABitCastInst => LLVM.IsABitCastInst(this); - public LLVMValueRef IsABlockAddress => LLVM.IsABlockAddress(this); + public readonly LLVMValueRef IsABlockAddress => LLVM.IsABlockAddress(this); - public LLVMValueRef IsABranchInst => LLVM.IsABranchInst(this); + public readonly LLVMValueRef IsABranchInst => LLVM.IsABranchInst(this); - public LLVMValueRef IsACallBrInst => LLVM.IsACallBrInst(this); + public readonly LLVMValueRef IsACallBrInst => LLVM.IsACallBrInst(this); - public LLVMValueRef IsACallInst => LLVM.IsACallInst(this); + public readonly LLVMValueRef IsACallInst => LLVM.IsACallInst(this); - public LLVMValueRef IsACastInst => LLVM.IsACastInst(this); + public readonly LLVMValueRef IsACastInst => LLVM.IsACastInst(this); - public LLVMValueRef IsACatchPadInst => LLVM.IsACatchPadInst(this); + public readonly LLVMValueRef IsACatchPadInst => LLVM.IsACatchPadInst(this); - public LLVMValueRef IsACatchReturnInst => LLVM.IsACatchReturnInst(this); + public readonly LLVMValueRef IsACatchReturnInst => LLVM.IsACatchReturnInst(this); - public LLVMValueRef IsACatchSwitchInst => LLVM.IsACatchSwitchInst(this); + public readonly LLVMValueRef IsACatchSwitchInst => LLVM.IsACatchSwitchInst(this); - public LLVMValueRef IsACleanupPadInst => LLVM.IsACleanupPadInst(this); + public readonly LLVMValueRef IsACleanupPadInst => LLVM.IsACleanupPadInst(this); - public LLVMValueRef IsACleanupReturnInst => LLVM.IsACleanupReturnInst(this); + public readonly LLVMValueRef IsACleanupReturnInst => LLVM.IsACleanupReturnInst(this); - public LLVMValueRef IsACmpInst => LLVM.IsACmpInst(this); + public readonly LLVMValueRef IsACmpInst => LLVM.IsACmpInst(this); - public LLVMValueRef IsAConstant => LLVM.IsAConstant(this); + public readonly LLVMValueRef IsAConstant => LLVM.IsAConstant(this); - public LLVMValueRef IsAConstantAggregateZero => LLVM.IsAConstantAggregateZero(this); + public readonly LLVMValueRef IsAConstantAggregateZero => LLVM.IsAConstantAggregateZero(this); - public LLVMValueRef IsAConstantArray => LLVM.IsAConstantArray(this); + public readonly LLVMValueRef IsAConstantArray => LLVM.IsAConstantArray(this); - public LLVMValueRef IsAConstantDataArray => LLVM.IsAConstantDataArray(this); + public readonly LLVMValueRef IsAConstantDataArray => LLVM.IsAConstantDataArray(this); - public LLVMValueRef IsAConstantDataSequential => LLVM.IsAConstantDataSequential(this); + public readonly LLVMValueRef IsAConstantDataSequential => LLVM.IsAConstantDataSequential(this); - public LLVMValueRef IsAConstantDataVector => LLVM.IsAConstantDataVector(this); + public readonly LLVMValueRef IsAConstantDataVector => LLVM.IsAConstantDataVector(this); - public LLVMValueRef IsAConstantExpr => LLVM.IsAConstantExpr(this); + public readonly LLVMValueRef IsAConstantExpr => LLVM.IsAConstantExpr(this); - public LLVMValueRef IsAConstantFP => LLVM.IsAConstantFP(this); + public readonly LLVMValueRef IsAConstantFP => LLVM.IsAConstantFP(this); - public LLVMValueRef IsAConstantInt => LLVM.IsAConstantInt(this); + public readonly LLVMValueRef IsAConstantInt => LLVM.IsAConstantInt(this); - public LLVMValueRef IsAConstantPointerNull => LLVM.IsAConstantPointerNull(this); + public readonly LLVMValueRef IsAConstantPointerNull => LLVM.IsAConstantPointerNull(this); - public LLVMValueRef IsAConstantStruct => LLVM.IsAConstantStruct(this); + public readonly LLVMValueRef IsAConstantStruct => LLVM.IsAConstantStruct(this); - public LLVMValueRef IsAConstantTokenNone => LLVM.IsAConstantTokenNone(this); + public readonly LLVMValueRef IsAConstantTokenNone => LLVM.IsAConstantTokenNone(this); - public LLVMValueRef IsAConstantVector => LLVM.IsAConstantVector(this); + public readonly LLVMValueRef IsAConstantVector => LLVM.IsAConstantVector(this); - public LLVMValueRef IsADbgDeclareInst => LLVM.IsADbgDeclareInst(this); + public readonly LLVMValueRef IsADbgDeclareInst => LLVM.IsADbgDeclareInst(this); - public LLVMValueRef IsADbgInfoIntrinsic => LLVM.IsADbgInfoIntrinsic(this); + public readonly LLVMValueRef IsADbgInfoIntrinsic => LLVM.IsADbgInfoIntrinsic(this); - public LLVMValueRef IsADbgLabelInst => LLVM.IsADbgLabelInst(this); + public readonly LLVMValueRef IsADbgLabelInst => LLVM.IsADbgLabelInst(this); - public LLVMValueRef IsADbgVariableIntrinsic => LLVM.IsADbgVariableIntrinsic(this); + public readonly LLVMValueRef IsADbgVariableIntrinsic => LLVM.IsADbgVariableIntrinsic(this); - public LLVMValueRef IsAExtractElementInst => LLVM.IsAExtractElementInst(this); + public readonly LLVMValueRef IsAExtractElementInst => LLVM.IsAExtractElementInst(this); - public LLVMValueRef IsAExtractValueInst => LLVM.IsAExtractValueInst(this); + public readonly LLVMValueRef IsAExtractValueInst => LLVM.IsAExtractValueInst(this); - public LLVMValueRef IsAFCmpInst => LLVM.IsAFCmpInst(this); + public readonly LLVMValueRef IsAFCmpInst => LLVM.IsAFCmpInst(this); - public LLVMValueRef IsAFenceInst => LLVM.IsAFenceInst(this); + public readonly LLVMValueRef IsAFenceInst => LLVM.IsAFenceInst(this); - public LLVMValueRef IsAFPExtInst => LLVM.IsAFPExtInst(this); + public readonly LLVMValueRef IsAFPExtInst => LLVM.IsAFPExtInst(this); - public LLVMValueRef IsAFPToSIInst => LLVM.IsAFPToSIInst(this); + public readonly LLVMValueRef IsAFPToSIInst => LLVM.IsAFPToSIInst(this); - public LLVMValueRef IsAFPToUIInst => LLVM.IsAFPToUIInst(this); + public readonly LLVMValueRef IsAFPToUIInst => LLVM.IsAFPToUIInst(this); - public LLVMValueRef IsAFPTruncInst => LLVM.IsAFPTruncInst(this); + public readonly LLVMValueRef IsAFPTruncInst => LLVM.IsAFPTruncInst(this); - public LLVMValueRef IsAFreezeInst => LLVM.IsAFreezeInst(this); + public readonly LLVMValueRef IsAFreezeInst => LLVM.IsAFreezeInst(this); - public LLVMValueRef IsAFuncletPadInst => LLVM.IsAFuncletPadInst(this); + public readonly LLVMValueRef IsAFuncletPadInst => LLVM.IsAFuncletPadInst(this); - public LLVMValueRef IsAFunction => LLVM.IsAFunction(this); + public readonly LLVMValueRef IsAFunction => LLVM.IsAFunction(this); - public LLVMValueRef IsAGetElementPtrInst => LLVM.IsAGetElementPtrInst(this); + public readonly LLVMValueRef IsAGetElementPtrInst => LLVM.IsAGetElementPtrInst(this); - public LLVMValueRef IsAGlobalAlias => LLVM.IsAGlobalAlias(this); + public readonly LLVMValueRef IsAGlobalAlias => LLVM.IsAGlobalAlias(this); - public LLVMValueRef IsAGlobalIFunc => LLVM.IsAGlobalIFunc(this); + public readonly LLVMValueRef IsAGlobalIFunc => LLVM.IsAGlobalIFunc(this); - public LLVMValueRef IsAGlobalObject => LLVM.IsAGlobalObject(this); + public readonly LLVMValueRef IsAGlobalObject => LLVM.IsAGlobalObject(this); - public LLVMValueRef IsAGlobalValue => LLVM.IsAGlobalValue(this); + public readonly LLVMValueRef IsAGlobalValue => LLVM.IsAGlobalValue(this); - public LLVMValueRef IsAGlobalVariable => LLVM.IsAGlobalVariable(this); + public readonly LLVMValueRef IsAGlobalVariable => LLVM.IsAGlobalVariable(this); - public LLVMValueRef IsAICmpInst => LLVM.IsAICmpInst(this); + public readonly LLVMValueRef IsAICmpInst => LLVM.IsAICmpInst(this); - public LLVMValueRef IsAIndirectBrInst => LLVM.IsAIndirectBrInst(this); + public readonly LLVMValueRef IsAIndirectBrInst => LLVM.IsAIndirectBrInst(this); - public LLVMValueRef IsAInlineAsm => LLVM.IsAInlineAsm(this); + public readonly LLVMValueRef IsAInlineAsm => LLVM.IsAInlineAsm(this); - public LLVMValueRef IsAInsertElementInst => LLVM.IsAInsertElementInst(this); + public readonly LLVMValueRef IsAInsertElementInst => LLVM.IsAInsertElementInst(this); - public LLVMValueRef IsAInsertValueInst => LLVM.IsAInsertValueInst(this); + public readonly LLVMValueRef IsAInsertValueInst => LLVM.IsAInsertValueInst(this); - public LLVMValueRef IsAInstruction => LLVM.IsAInstruction(this); + public readonly LLVMValueRef IsAInstruction => LLVM.IsAInstruction(this); - public LLVMValueRef IsAIntrinsicInst => LLVM.IsAIntrinsicInst(this); + public readonly LLVMValueRef IsAIntrinsicInst => LLVM.IsAIntrinsicInst(this); - public LLVMValueRef IsAIntToPtrInst => LLVM.IsAIntToPtrInst(this); + public readonly LLVMValueRef IsAIntToPtrInst => LLVM.IsAIntToPtrInst(this); - public LLVMValueRef IsAInvokeInst => LLVM.IsAInvokeInst(this); + public readonly LLVMValueRef IsAInvokeInst => LLVM.IsAInvokeInst(this); - public LLVMValueRef IsALandingPadInst => LLVM.IsALandingPadInst(this); + public readonly LLVMValueRef IsALandingPadInst => LLVM.IsALandingPadInst(this); - public LLVMValueRef IsALoadInst => LLVM.IsALoadInst(this); + public readonly LLVMValueRef IsALoadInst => LLVM.IsALoadInst(this); - public LLVMValueRef IsAMDNode => LLVM.IsAMDNode(this); + public readonly LLVMValueRef IsAMDNode => LLVM.IsAMDNode(this); - public LLVMValueRef IsAMDString => LLVM.IsAMDString(this); + public readonly LLVMValueRef IsAMDString => LLVM.IsAMDString(this); - public LLVMValueRef IsAMemCpyInst => LLVM.IsAMemCpyInst(this); + public readonly LLVMValueRef IsAMemCpyInst => LLVM.IsAMemCpyInst(this); - public LLVMValueRef IsAMemIntrinsic => LLVM.IsAMemIntrinsic(this); + public readonly LLVMValueRef IsAMemIntrinsic => LLVM.IsAMemIntrinsic(this); - public LLVMValueRef IsAMemMoveInst => LLVM.IsAMemMoveInst(this); + public readonly LLVMValueRef IsAMemMoveInst => LLVM.IsAMemMoveInst(this); - public LLVMValueRef IsAMemSetInst => LLVM.IsAMemSetInst(this); + public readonly LLVMValueRef IsAMemSetInst => LLVM.IsAMemSetInst(this); - public LLVMValueRef IsAPHINode => LLVM.IsAPHINode(this); + public readonly LLVMValueRef IsAPHINode => LLVM.IsAPHINode(this); - public LLVMValueRef IsAPoisonValue => LLVM.IsAPoisonValue(this); + public readonly LLVMValueRef IsAPoisonValue => LLVM.IsAPoisonValue(this); - public LLVMValueRef IsAPtrToIntInst => LLVM.IsAPtrToIntInst(this); + public readonly LLVMValueRef IsAPtrToIntInst => LLVM.IsAPtrToIntInst(this); - public LLVMValueRef IsAResumeInst => LLVM.IsAResumeInst(this); + public readonly LLVMValueRef IsAResumeInst => LLVM.IsAResumeInst(this); - public LLVMValueRef IsAReturnInst => LLVM.IsAReturnInst(this); + public readonly LLVMValueRef IsAReturnInst => LLVM.IsAReturnInst(this); - public LLVMValueRef IsASelectInst => LLVM.IsASelectInst(this); + public readonly LLVMValueRef IsASelectInst => LLVM.IsASelectInst(this); - public LLVMValueRef IsASExtInst => LLVM.IsASExtInst(this); + public readonly LLVMValueRef IsASExtInst => LLVM.IsASExtInst(this); - public LLVMValueRef IsAShuffleVectorInst => LLVM.IsAShuffleVectorInst(this); + public readonly LLVMValueRef IsAShuffleVectorInst => LLVM.IsAShuffleVectorInst(this); - public LLVMValueRef IsASIToFPInst => LLVM.IsASIToFPInst(this); + public readonly LLVMValueRef IsASIToFPInst => LLVM.IsASIToFPInst(this); - public LLVMValueRef IsAStoreInst => LLVM.IsAStoreInst(this); + public readonly LLVMValueRef IsAStoreInst => LLVM.IsAStoreInst(this); - public LLVMValueRef IsASwitchInst => LLVM.IsASwitchInst(this); + public readonly LLVMValueRef IsASwitchInst => LLVM.IsASwitchInst(this); - public LLVMValueRef IsATerminatorInst => (IsAInstruction != null) ? LLVM.IsATerminatorInst(this) : default; + public readonly LLVMValueRef IsATerminatorInst => (IsAInstruction != null) ? LLVM.IsATerminatorInst(this) : default; - public LLVMValueRef IsATruncInst => LLVM.IsATruncInst(this); + public readonly LLVMValueRef IsATruncInst => LLVM.IsATruncInst(this); - public LLVMValueRef IsAUIToFPInst => LLVM.IsAUIToFPInst(this); + public readonly LLVMValueRef IsAUIToFPInst => LLVM.IsAUIToFPInst(this); - public LLVMValueRef IsAUnaryInstruction => LLVM.IsAUnaryInstruction(this); + public readonly LLVMValueRef IsAUnaryInstruction => LLVM.IsAUnaryInstruction(this); - public LLVMValueRef IsAUnaryOperator => LLVM.IsAUnaryOperator(this); + public readonly LLVMValueRef IsAUnaryOperator => LLVM.IsAUnaryOperator(this); - public LLVMValueRef IsAUndefValue => LLVM.IsAUndefValue(this); + public readonly LLVMValueRef IsAUndefValue => LLVM.IsAUndefValue(this); - public LLVMValueRef IsAUnreachableInst => LLVM.IsAUnreachableInst(this); + public readonly LLVMValueRef IsAUnreachableInst => LLVM.IsAUnreachableInst(this); - public LLVMValueRef IsAUser => LLVM.IsAUser(this); + public readonly LLVMValueRef IsAUser => LLVM.IsAUser(this); - public LLVMValueRef IsAVAArgInst => LLVM.IsAVAArgInst(this); + public readonly LLVMValueRef IsAVAArgInst => LLVM.IsAVAArgInst(this); - public LLVMValueRef IsAZExtInst => LLVM.IsAZExtInst(this); + public readonly LLVMValueRef IsAZExtInst => LLVM.IsAZExtInst(this); - public bool IsBasicBlock => (Handle != IntPtr.Zero) && LLVM.ValueIsBasicBlock(this) != 0; + public readonly bool IsBasicBlock => (Handle != IntPtr.Zero) && LLVM.ValueIsBasicBlock(this) != 0; - public bool IsCleanup + public readonly bool IsCleanup { get { @@ -396,15 +371,15 @@ public bool IsCleanup } } - public bool IsConditional => (IsABranchInst != null) && LLVM.IsConditional(this) != 0; + public readonly bool IsConditional => (IsABranchInst != null) && LLVM.IsConditional(this) != 0; - public bool IsConstant => (Handle != IntPtr.Zero) && LLVM.IsConstant(this) != 0; + public readonly bool IsConstant => (Handle != IntPtr.Zero) && LLVM.IsConstant(this) != 0; - public bool IsConstantString => (IsAConstantDataSequential != null) && LLVM.IsConstantString(this) != 0; + public readonly bool IsConstantString => (IsAConstantDataSequential != null) && LLVM.IsConstantString(this) != 0; - public bool IsDeclaration => (IsAGlobalValue != null) && LLVM.IsDeclaration(this) != 0; + public readonly bool IsDeclaration => (IsAGlobalValue != null) && LLVM.IsDeclaration(this) != 0; - public bool IsExternallyInitialized + public readonly bool IsExternallyInitialized { get { @@ -417,7 +392,7 @@ public bool IsExternallyInitialized } } - public bool IsGlobalConstant + public readonly bool IsGlobalConstant { get { @@ -430,11 +405,11 @@ public bool IsGlobalConstant } } - public bool IsNull => (Handle != IntPtr.Zero) && LLVM.IsNull(this) != 0; + public readonly bool IsNull => (Handle != IntPtr.Zero) && LLVM.IsNull(this) != 0; - public bool IsPoison => (Handle != IntPtr.Zero) && LLVM.IsPoison(this) != 0; + public readonly bool IsPoison => (Handle != IntPtr.Zero) && LLVM.IsPoison(this) != 0; - public bool IsTailCall + public readonly bool IsTailCall { get { @@ -447,7 +422,7 @@ public bool IsTailCall } } - public bool IsThreadLocal + public readonly bool IsThreadLocal { get { @@ -460,15 +435,15 @@ public bool IsThreadLocal } } - public bool IsUndef => (Handle != IntPtr.Zero) && LLVM.IsUndef(this) != 0; + public readonly bool IsUndef => (Handle != IntPtr.Zero) && LLVM.IsUndef(this) != 0; - public LLVMValueKind Kind => (Handle != IntPtr.Zero) ? LLVM.GetValueKind(this) : default; + public readonly LLVMValueKind Kind => (Handle != IntPtr.Zero) ? LLVM.GetValueKind(this) : default; - public LLVMBasicBlockRef LastBasicBlock => (IsAFunction != null) ? LLVM.GetLastBasicBlock(this) : default; + public readonly LLVMBasicBlockRef LastBasicBlock => (IsAFunction != null) ? LLVM.GetLastBasicBlock(this) : default; - public LLVMValueRef LastParam => (IsAFunction != null) ? LLVM.GetLastParam(this) : default; + public readonly LLVMValueRef LastParam => (IsAFunction != null) ? LLVM.GetLastParam(this) : default; - public LLVMLinkage Linkage + public readonly LLVMLinkage Linkage { get { @@ -481,29 +456,9 @@ public LLVMLinkage Linkage } } - public LLVMValueRef[] MDNodeOperands - { - get - { - if (Kind != LLVMValueKind.LLVMMetadataAsValueValueKind) - { - return Array.Empty(); - } - - var Dest = new LLVMValueRef[MDNodeOperandsCount]; + public readonly uint MDNodeOperandsCount => (Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) ? LLVM.GetMDNodeNumOperands(this) : default; - fixed (LLVMValueRef* pDest = Dest) - { - LLVM.GetMDNodeOperands(this, (LLVMOpaqueValue**)pDest); - } - - return Dest; - } - } - - public uint MDNodeOperandsCount => (Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) ? LLVM.GetMDNodeNumOperands(this) : default; - - public string Name + public readonly string Name { get { @@ -529,41 +484,21 @@ public string Name } } - public LLVMValueRef NextFunction => (IsAFunction != null) ? LLVM.GetNextFunction(this) : default; - - public LLVMValueRef NextGlobal => (IsAGlobalVariable != null) ? LLVM.GetNextGlobal(this) : default; - - public LLVMValueRef NextInstruction => (IsAInstruction != null) ? LLVM.GetNextInstruction(this) : default; - - public LLVMValueRef NextParam => (IsAArgument != null) ? LLVM.GetNextParam(this) : default; - - public int OperandCount => ((Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) || (IsAUser != null)) ? LLVM.GetNumOperands(this) : default; + public readonly LLVMValueRef NextFunction => (IsAFunction != null) ? LLVM.GetNextFunction(this) : default; - public LLVMValueRef[] Params - { - get - { - if (IsAFunction == null) - { - return Array.Empty(); - } + public readonly LLVMValueRef NextGlobal => (IsAGlobalVariable != null) ? LLVM.GetNextGlobal(this) : default; - var Params = new LLVMValueRef[ParamsCount]; + public readonly LLVMValueRef NextInstruction => (IsAInstruction != null) ? LLVM.GetNextInstruction(this) : default; - fixed (LLVMValueRef* pParams = Params) - { - LLVM.GetParams(this, (LLVMOpaqueValue**)pParams); - } + public readonly LLVMValueRef NextParam => (IsAArgument != null) ? LLVM.GetNextParam(this) : default; - return Params; - } - } + public readonly int OperandCount => ((Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) || (IsAUser != null)) ? LLVM.GetNumOperands(this) : default; - public uint ParamsCount => (IsAFunction != null) ? LLVM.CountParams(this) : default; + public readonly uint ParamsCount => (IsAFunction != null) ? LLVM.CountParams(this) : default; - public LLVMValueRef ParamParent => (IsAArgument != null) ? LLVM.GetParamParent(this) : default; + public readonly LLVMValueRef ParamParent => (IsAArgument != null) ? LLVM.GetParamParent(this) : default; - public LLVMValueRef PersonalityFn + public readonly LLVMValueRef PersonalityFn { get { @@ -576,15 +511,15 @@ public LLVMValueRef PersonalityFn } } - public LLVMValueRef PreviousGlobal => (IsAGlobalVariable != null) ? LLVM.GetPreviousGlobal(this) : default; + public readonly LLVMValueRef PreviousGlobal => (IsAGlobalVariable != null) ? LLVM.GetPreviousGlobal(this) : default; - public LLVMValueRef PreviousInstruction => (IsAInstruction != null) ? LLVM.GetPreviousInstruction(this) : default; + public readonly LLVMValueRef PreviousInstruction => (IsAInstruction != null) ? LLVM.GetPreviousInstruction(this) : default; - public LLVMValueRef PreviousParam => (IsAArgument != null) ? LLVM.GetPreviousParam(this) : default; + public readonly LLVMValueRef PreviousParam => (IsAArgument != null) ? LLVM.GetPreviousParam(this) : default; - public LLVMValueRef PreviousFunction => (IsAFunction != null) ? LLVM.GetPreviousFunction(this) : default; + public readonly LLVMValueRef PreviousFunction => (IsAFunction != null) ? LLVM.GetPreviousFunction(this) : default; - public string Section + public readonly string Section { get { @@ -610,11 +545,11 @@ public string Section } } - public uint SuccessorsCount => (IsAInstruction != null) ? LLVM.GetNumSuccessors(this) : default; + public readonly uint SuccessorsCount => (IsAInstruction != null) ? LLVM.GetNumSuccessors(this) : default; - public LLVMBasicBlockRef SwitchDefaultDest => (IsASwitchInst != null) ? LLVM.GetSwitchDefaultDest(this) : default; + public readonly LLVMBasicBlockRef SwitchDefaultDest => (IsASwitchInst != null) ? LLVM.GetSwitchDefaultDest(this) : default; - public LLVMThreadLocalMode ThreadLocalMode + public readonly LLVMThreadLocalMode ThreadLocalMode { get { @@ -627,9 +562,9 @@ public LLVMThreadLocalMode ThreadLocalMode } } - public LLVMTypeRef TypeOf => (Handle != IntPtr.Zero) ? LLVM.TypeOf(this) : default; + public readonly LLVMTypeRef TypeOf => (Handle != IntPtr.Zero) ? LLVM.TypeOf(this) : default; - public LLVMVisibility Visibility + public readonly LLVMVisibility Visibility { get { @@ -642,7 +577,7 @@ public LLVMVisibility Visibility } } - public bool Volatile + public readonly bool Volatile { get { @@ -655,7 +590,7 @@ public bool Volatile } } - public bool Weak + public readonly bool Weak { get { @@ -891,15 +826,15 @@ public static LLVMValueRef CreateMDNode(ReadOnlySpan Vals) } } - public void AddCase(LLVMValueRef OnVal, LLVMBasicBlockRef Dest) => LLVM.AddCase(this, OnVal, Dest); + public readonly void AddCase(LLVMValueRef OnVal, LLVMBasicBlockRef Dest) => LLVM.AddCase(this, OnVal, Dest); - public void AddClause(LLVMValueRef ClauseVal) => LLVM.AddClause(this, ClauseVal); + public readonly void AddClause(LLVMValueRef ClauseVal) => LLVM.AddClause(this, ClauseVal); - public void AddDestination(LLVMBasicBlockRef Dest) => LLVM.AddDestination(this, Dest); + public readonly void AddDestination(LLVMBasicBlockRef Dest) => LLVM.AddDestination(this, Dest); - public void AddIncoming(LLVMValueRef[] IncomingValues, LLVMBasicBlockRef[] IncomingBlocks, uint Count) => AddIncoming(IncomingValues.AsSpan(), IncomingBlocks.AsSpan(), Count); + public readonly void AddIncoming(LLVMValueRef[] IncomingValues, LLVMBasicBlockRef[] IncomingBlocks, uint Count) => AddIncoming(IncomingValues.AsSpan(), IncomingBlocks.AsSpan(), Count); - public void AddIncoming(ReadOnlySpan IncomingValues, ReadOnlySpan IncomingBlocks, uint Count) + public readonly void AddIncoming(ReadOnlySpan IncomingValues, ReadOnlySpan IncomingBlocks, uint Count) { fixed (LLVMValueRef* pIncomingValues = IncomingValues) fixed (LLVMBasicBlockRef* pIncomingBlocks = IncomingBlocks) @@ -908,36 +843,36 @@ public void AddIncoming(ReadOnlySpan IncomingValues, ReadOnlySpan< } } - public void AddTargetDependentFunctionAttr(string A, string V) => AddTargetDependentFunctionAttr(A.AsSpan(), V.AsSpan()); + public readonly void AddTargetDependentFunctionAttr(string A, string V) => AddTargetDependentFunctionAttr(A.AsSpan(), V.AsSpan()); - public void AddTargetDependentFunctionAttr(ReadOnlySpan A, ReadOnlySpan V) + public readonly void AddTargetDependentFunctionAttr(ReadOnlySpan A, ReadOnlySpan V) { using var marshaledA = new MarshaledString(A); using var marshaledV = new MarshaledString(V); LLVM.AddTargetDependentFunctionAttr(this, marshaledA, marshaledV); } - public LLVMBasicBlockRef AppendBasicBlock(string Name) => AppendBasicBlock(Name.AsSpan()); + public readonly LLVMBasicBlockRef AppendBasicBlock(string Name) => AppendBasicBlock(Name.AsSpan()); - public LLVMBasicBlockRef AppendBasicBlock(ReadOnlySpan Name) + public readonly LLVMBasicBlockRef AppendBasicBlock(ReadOnlySpan Name) { using var marshaledName = new MarshaledString(Name); return LLVM.AppendBasicBlock(this, marshaledName); } - public LLVMBasicBlockRef AsBasicBlock() => LLVM.ValueAsBasicBlock(this); + public readonly LLVMBasicBlockRef AsBasicBlock() => LLVM.ValueAsBasicBlock(this); - public void DeleteFunction() => LLVM.DeleteFunction(this); + public readonly void DeleteFunction() => LLVM.DeleteFunction(this); - public void DeleteGlobal() => LLVM.DeleteGlobal(this); + public readonly void DeleteGlobal() => LLVM.DeleteGlobal(this); - public void Dump() => LLVM.DumpValue(this); + public readonly void Dump() => LLVM.DumpValue(this); - public override bool Equals(object? obj) => (obj is LLVMValueRef other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is LLVMValueRef other) && Equals(other); - public bool Equals(LLVMValueRef other) => this == other; + public readonly bool Equals(LLVMValueRef other) => this == other; - public string GetAsString(out UIntPtr Length) + public readonly string GetAsString(out UIntPtr Length) { fixed (UIntPtr* pLength = &Length) { @@ -953,12 +888,93 @@ public string GetAsString(out UIntPtr Length) } } - public void AddAttributeAtIndex(LLVMAttributeIndex Idx, LLVMAttributeRef A) + public readonly LLVMBasicBlockRef[] GetBasicBlocks() + { + if (IsAFunction == null) + { + return []; + } + + var destination = new LLVMBasicBlockRef[BasicBlocksCount]; + GetBasicBlocks(destination); + return destination; + } + + public readonly void GetBasicBlocks(Span destination) + { + if (IsAFunction == null) + { + return; + } + + ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, BasicBlocksCount); + + fixed (LLVMBasicBlockRef* pBasicBlocks = destination) + { + LLVM.GetBasicBlocks(this, (LLVMOpaqueBasicBlock**)pBasicBlocks); + } + } + + public readonly LLVMValueRef[] GetMDNodeOperands() + { + if (Kind != LLVMValueKind.LLVMMetadataAsValueValueKind) + { + return []; + } + + var destination = new LLVMValueRef[MDNodeOperandsCount]; + GetMDNodeOperands(destination); + return destination; + } + + public readonly void GetMDNodeOperands(Span destination) + { + if (Kind != LLVMValueKind.LLVMMetadataAsValueValueKind) + { + return; + } + + ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, MDNodeOperandsCount); + + fixed (LLVMValueRef* pDest = destination) + { + LLVM.GetMDNodeOperands(this, (LLVMOpaqueValue**)pDest); + } + } + + public readonly LLVMValueRef[] GetParams() + { + if (IsAFunction == null) + { + return []; + } + + var destination = new LLVMValueRef[ParamsCount]; + GetParams(destination); + return destination; + } + + public readonly void GetParams(Span destination) + { + if (IsAFunction == null) + { + return; + } + + ArgumentOutOfRangeException.ThrowIfLessThan((uint)destination.Length, ParamsCount); + + fixed (LLVMValueRef* pParams = destination) + { + LLVM.GetParams(this, (LLVMOpaqueValue**)pParams); + } + } + + public readonly void AddAttributeAtIndex(LLVMAttributeIndex Idx, LLVMAttributeRef A) { LLVM.AddAttributeAtIndex(this, Idx, A); } - public LLVMAttributeRef[] GetAttributesAtIndex(LLVMAttributeIndex Idx) + public readonly LLVMAttributeRef[] GetAttributesAtIndex(LLVMAttributeIndex Idx) { var Attrs = new LLVMAttributeRef[GetAttributeCountAtIndex(Idx)]; @@ -970,13 +986,13 @@ public LLVMAttributeRef[] GetAttributesAtIndex(LLVMAttributeIndex Idx) return Attrs; } - public uint GetAttributeCountAtIndex(LLVMAttributeIndex Idx) => LLVM.GetAttributeCountAtIndex(this, Idx); + public readonly uint GetAttributeCountAtIndex(LLVMAttributeIndex Idx) => LLVM.GetAttributeCountAtIndex(this, Idx); - public LLVMValueRef GetBlockAddress(LLVMBasicBlockRef BB) => LLVM.BlockAddress(this, BB); + public readonly LLVMValueRef GetBlockAddress(LLVMBasicBlockRef BB) => LLVM.BlockAddress(this, BB); - public uint GetCallSiteAttributeCount(LLVMAttributeIndex Idx) => LLVM.GetCallSiteAttributeCount(this, Idx); + public readonly uint GetCallSiteAttributeCount(LLVMAttributeIndex Idx) => LLVM.GetCallSiteAttributeCount(this, Idx); - public LLVMAttributeRef[] GetCallSiteAttributes(LLVMAttributeIndex Idx) + public readonly LLVMAttributeRef[] GetCallSiteAttributes(LLVMAttributeIndex Idx) { var Attrs = new LLVMAttributeRef[GetCallSiteAttributeCount(Idx)]; @@ -988,7 +1004,7 @@ public LLVMAttributeRef[] GetCallSiteAttributes(LLVMAttributeIndex Idx) return Attrs; } - public double GetConstRealDouble(out bool losesInfo) + public readonly double GetConstRealDouble(out bool losesInfo) { int losesInfoOut; var result = LLVM.ConstRealGetDouble(this, &losesInfoOut); @@ -997,18 +1013,18 @@ public double GetConstRealDouble(out bool losesInfo) return result; } - public LLVMValueRef GetAggregateElement(uint idx) => LLVM.GetAggregateElement(this, idx); + public readonly LLVMValueRef GetAggregateElement(uint idx) => LLVM.GetAggregateElement(this, idx); [Obsolete("Use GetAggregateElement instead")] - public LLVMValueRef GetElementAsConstant(uint idx) => LLVM.GetElementAsConstant(this, idx); + public readonly LLVMValueRef GetElementAsConstant(uint idx) => LLVM.GetElementAsConstant(this, idx); - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public LLVMBasicBlockRef GetIncomingBlock(uint Index) => LLVM.GetIncomingBlock(this, Index); + public readonly LLVMBasicBlockRef GetIncomingBlock(uint Index) => LLVM.GetIncomingBlock(this, Index); - public LLVMValueRef GetIncomingValue(uint Index) => LLVM.GetIncomingValue(this, Index); + public readonly LLVMValueRef GetIncomingValue(uint Index) => LLVM.GetIncomingValue(this, Index); - public string GetMDString(out uint Len) + public readonly string GetMDString(out uint Len) { fixed (uint* pLen = &Len) { @@ -1024,19 +1040,19 @@ public string GetMDString(out uint Len) } } - public LLVMValueRef GetMetadata(uint KindID) => LLVM.GetMetadata(this, KindID); + public readonly LLVMValueRef GetMetadata(uint KindID) => LLVM.GetMetadata(this, KindID); - public LLVMValueRef GetOperand(uint Index) => LLVM.GetOperand(this, Index); + public readonly LLVMValueRef GetOperand(uint Index) => LLVM.GetOperand(this, Index); - public LLVMUseRef GetOperandUse(uint Index) => LLVM.GetOperandUse(this, Index); + public readonly LLVMUseRef GetOperandUse(uint Index) => LLVM.GetOperandUse(this, Index); - public LLVMValueRef GetParam(uint Index) => LLVM.GetParam(this, Index); + public readonly LLVMValueRef GetParam(uint Index) => LLVM.GetParam(this, Index); - public LLVMBasicBlockRef GetSuccessor(uint i) => LLVM.GetSuccessor(this, i); + public readonly LLVMBasicBlockRef GetSuccessor(uint i) => LLVM.GetSuccessor(this, i); - public void InstructionEraseFromParent() => LLVM.InstructionEraseFromParent(this); + public readonly void InstructionEraseFromParent() => LLVM.InstructionEraseFromParent(this); - public string PrintToString() + public readonly string PrintToString() { var pStr = LLVM.PrintValueToString(this); @@ -1050,28 +1066,28 @@ public string PrintToString() return result; } - public void ReplaceAllUsesWith(LLVMValueRef NewVal) => LLVM.ReplaceAllUsesWith(this, NewVal); + public readonly void ReplaceAllUsesWith(LLVMValueRef NewVal) => LLVM.ReplaceAllUsesWith(this, NewVal); public void SetAlignment(uint Bytes) { Alignment = Bytes; } - public void SetInstrParamAlignment(LLVMAttributeIndex index, uint align) => LLVM.SetInstrParamAlignment(this, index, align); + public readonly void SetInstrParamAlignment(LLVMAttributeIndex index, uint align) => LLVM.SetInstrParamAlignment(this, index, align); - public void SetMetadata(uint KindID, LLVMValueRef Node) => LLVM.SetMetadata(this, KindID, Node); + public readonly void SetMetadata(uint KindID, LLVMValueRef Node) => LLVM.SetMetadata(this, KindID, Node); - public void SetOperand(uint Index, LLVMValueRef Val) => LLVM.SetOperand(this, Index, Val); + public readonly void SetOperand(uint Index, LLVMValueRef Val) => LLVM.SetOperand(this, Index, Val); - public void SetParamAlignment(uint align) => LLVM.SetParamAlignment(this, align); + public readonly void SetParamAlignment(uint align) => LLVM.SetParamAlignment(this, align); - public void SetSuccessor(uint i, LLVMBasicBlockRef block) => LLVM.SetSuccessor(this, i, block); + public readonly void SetSuccessor(uint i, LLVMBasicBlockRef block) => LLVM.SetSuccessor(this, i, block); - public override string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; + public override readonly string ToString() => (Handle != IntPtr.Zero) ? PrintToString() : string.Empty; - public bool VerifyFunction(LLVMVerifierFailureAction Action) => LLVM.VerifyFunction(this, Action) == 0; + public readonly bool VerifyFunction(LLVMVerifierFailureAction Action) => LLVM.VerifyFunction(this, Action) == 0; - public void ViewFunctionCFG() => LLVM.ViewFunctionCFG(this); + public readonly void ViewFunctionCFG() => LLVM.ViewFunctionCFG(this); - public void ViewFunctionCFGOnly() => LLVM.ViewFunctionCFGOnly(this); + public readonly void ViewFunctionCFGOnly() => LLVM.ViewFunctionCFGOnly(this); } diff --git a/sources/LLVMSharp.Interop/Extensions/lto_code_gen_t.cs b/sources/LLVMSharp.Interop/Extensions/lto_code_gen_t.cs index b1646b39..457f64c5 100644 --- a/sources/LLVMSharp.Interop/Extensions/lto_code_gen_t.cs +++ b/sources/LLVMSharp.Interop/Extensions/lto_code_gen_t.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct lto_code_gen_t : IEquatable +public unsafe partial struct lto_code_gen_t(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public lto_code_gen_t(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator lto_code_gen_t(LLVMOpaqueLTOCodeGenerator* Comdat) => new lto_code_gen_t((IntPtr)Comdat); @@ -21,11 +16,11 @@ public lto_code_gen_t(IntPtr handle) public static bool operator !=(lto_code_gen_t left, lto_code_gen_t right) => !(left == right); - public override bool Equals(object? obj) => (obj is lto_code_gen_t other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is lto_code_gen_t other) && Equals(other); - public bool Equals(lto_code_gen_t other) => this == other; + public readonly bool Equals(lto_code_gen_t other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(lto_code_gen_t)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(lto_code_gen_t)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/lto_input_t.cs b/sources/LLVMSharp.Interop/Extensions/lto_input_t.cs index 4ec3ab5c..a8d45d29 100644 --- a/sources/LLVMSharp.Interop/Extensions/lto_input_t.cs +++ b/sources/LLVMSharp.Interop/Extensions/lto_input_t.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct lto_input_t : IEquatable +public unsafe partial struct lto_input_t(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public lto_input_t(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator lto_input_t(LLVMOpaqueLTOInput* Comdat) => new lto_input_t((IntPtr)Comdat); @@ -21,11 +16,11 @@ public lto_input_t(IntPtr handle) public static bool operator !=(lto_input_t left, lto_input_t right) => !(left == right); - public override bool Equals(object? obj) => (obj is lto_input_t other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is lto_input_t other) && Equals(other); - public bool Equals(lto_input_t other) => this == other; + public readonly bool Equals(lto_input_t other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(lto_input_t)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(lto_input_t)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/lto_module_t.cs b/sources/LLVMSharp.Interop/Extensions/lto_module_t.cs index 4dd23f60..4d843147 100644 --- a/sources/LLVMSharp.Interop/Extensions/lto_module_t.cs +++ b/sources/LLVMSharp.Interop/Extensions/lto_module_t.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct lto_module_t : IEquatable +public unsafe partial struct lto_module_t(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public lto_module_t(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator lto_module_t(LLVMOpaqueLTOModule* Comdat) => new lto_module_t((IntPtr)Comdat); @@ -21,11 +16,11 @@ public lto_module_t(IntPtr handle) public static bool operator !=(lto_module_t left, lto_module_t right) => !(left == right); - public override bool Equals(object? obj) => (obj is lto_module_t other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is lto_module_t other) && Equals(other); - public bool Equals(lto_module_t other) => this == other; + public readonly bool Equals(lto_module_t other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(lto_module_t)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(lto_module_t)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/Extensions/thinlto_code_gen_t.cs b/sources/LLVMSharp.Interop/Extensions/thinlto_code_gen_t.cs index 68b7df13..9cf8ffd0 100644 --- a/sources/LLVMSharp.Interop/Extensions/thinlto_code_gen_t.cs +++ b/sources/LLVMSharp.Interop/Extensions/thinlto_code_gen_t.cs @@ -4,14 +4,9 @@ namespace LLVMSharp.Interop; -public unsafe partial struct thinlto_code_gen_t : IEquatable +public unsafe partial struct thinlto_code_gen_t(IntPtr handle) : IEquatable { - public IntPtr Handle; - - public thinlto_code_gen_t(IntPtr handle) - { - Handle = handle; - } + public IntPtr Handle = handle; public static implicit operator thinlto_code_gen_t(LLVMOpaqueThinLTOCodeGenerator* Comdat) => new thinlto_code_gen_t((IntPtr)Comdat); @@ -21,11 +16,11 @@ public thinlto_code_gen_t(IntPtr handle) public static bool operator !=(thinlto_code_gen_t left, thinlto_code_gen_t right) => !(left == right); - public override bool Equals(object? obj) => (obj is thinlto_code_gen_t other) && Equals(other); + public override readonly bool Equals(object? obj) => (obj is thinlto_code_gen_t other) && Equals(other); - public bool Equals(thinlto_code_gen_t other) => this == other; + public readonly bool Equals(thinlto_code_gen_t other) => this == other; - public override int GetHashCode() => Handle.GetHashCode(); + public override readonly int GetHashCode() => Handle.GetHashCode(); - public override string ToString() => $"{nameof(thinlto_code_gen_t)}: {Handle:X}"; + public override readonly string ToString() => $"{nameof(thinlto_code_gen_t)}: {Handle:X}"; } diff --git a/sources/LLVMSharp.Interop/ILLink.Substitutions.xml b/sources/LLVMSharp.Interop/ILLink.Substitutions.xml new file mode 100644 index 00000000..638af23b --- /dev/null +++ b/sources/LLVMSharp.Interop/ILLink.Substitutions.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sources/LLVMSharp.Interop/Internals/MarshaledArray`1.cs b/sources/LLVMSharp.Interop/Internals/MarshaledArray`1.cs index cf75558d..a85b17f3 100644 --- a/sources/LLVMSharp.Interop/Internals/MarshaledArray`1.cs +++ b/sources/LLVMSharp.Interop/Internals/MarshaledArray`1.cs @@ -5,11 +5,13 @@ namespace LLVMSharp.Interop; -public unsafe struct MarshaledArray : IDisposable +public unsafe ref struct MarshaledArray where U : unmanaged { public MarshaledArray(ReadOnlySpan inputs, Func marshal) { + ArgumentNullException.ThrowIfNull(marshal); + int length; U* value; @@ -22,11 +24,7 @@ public MarshaledArray(ReadOnlySpan inputs, Func marshal) { length = inputs.Length; -#if NET6_0_OR_GREATER value = (U*)NativeMemory.Alloc((uint)(length * sizeof(U))); -#else - value = (U*)Marshal.AllocHGlobal(length * sizeof(U)); -#endif for (int i = 0; i < inputs.Length; i++) { @@ -39,7 +37,7 @@ public MarshaledArray(ReadOnlySpan inputs, Func marshal) Value = value; } - public ReadOnlySpan AsSpan() => new ReadOnlySpan(Value, Length); + public readonly ReadOnlySpan AsSpan() => new ReadOnlySpan(Value, Length); public int Length { get; private set; } @@ -49,14 +47,9 @@ public MarshaledArray(ReadOnlySpan inputs, Func marshal) public void Dispose() { - if (Value != null) + if (Value is not null) { -#if NET6_0_OR_GREATER NativeMemory.Free(Value); -#else - Marshal.FreeHGlobal((IntPtr)Value); -#endif - Value = null; Length = 0; } diff --git a/sources/LLVMSharp.Interop/Internals/MarshaledString.cs b/sources/LLVMSharp.Interop/Internals/MarshaledString.cs index b552d043..a88b66f3 100644 --- a/sources/LLVMSharp.Interop/Internals/MarshaledString.cs +++ b/sources/LLVMSharp.Interop/Internals/MarshaledString.cs @@ -8,63 +8,61 @@ namespace LLVMSharp.Interop; public unsafe struct MarshaledString : IDisposable { - public MarshaledString(string? input) : this(input.AsSpan()) + public MarshaledString(string? input) { - } - - public MarshaledString(ReadOnlySpan input) - { - int length = input.Length; - sbyte* value; + int valueLength; + sbyte* pValue; - if (length != 0) + if (input is null) { - length = Encoding.UTF8.GetMaxByteCount(input.Length); + valueLength = 0; + pValue = null; } - -#if NET6_0_OR_GREATER - value = (sbyte*)NativeMemory.Alloc((uint)(length) + 1); -#else - value = (sbyte*)Marshal.AllocHGlobal(length + 1); -#endif - - if (length != 0) + else { - fixed (char* pInput = input) - { - length = Encoding.UTF8.GetBytes(pInput, input.Length, (byte*)value, length); - } + var maxValueLength = Encoding.UTF8.GetMaxByteCount(input.Length); + pValue = (sbyte*)NativeMemory.Alloc((uint)maxValueLength + 1); + valueLength = Encoding.UTF8.GetBytes(input, new Span(pValue, maxValueLength)); + pValue[valueLength] = 0; } - value[length] = 0; - Length = length; - Value = value; + Length = valueLength; + Value = pValue; } - public ReadOnlySpan AsSpan() => new ReadOnlySpan(Value, Length); + public MarshaledString(ReadOnlySpan input) + { + int valueLength; + sbyte* pValue; + + var maxValueLength = Encoding.UTF8.GetMaxByteCount(input.Length); + pValue = (sbyte*)NativeMemory.Alloc((uint)maxValueLength + 1); + valueLength = Encoding.UTF8.GetBytes(input, new Span(pValue, maxValueLength)); + pValue[valueLength] = 0; + + Length = valueLength; + Value = pValue; + } + + public readonly ReadOnlySpan AsSpan() => new ReadOnlySpan(Value, Length); public int Length { get; private set; } public sbyte* Value { get; private set; } - public static implicit operator sbyte*(MarshaledString value) => value.Value; - public void Dispose() { if (Value != null) { -#if NET6_0_OR_GREATER NativeMemory.Free(Value); -#else - Marshal.FreeHGlobal((IntPtr)Value); -#endif - Value = null; Length = 0; } } - public override string ToString() + public static implicit operator sbyte*(in MarshaledString value) => value.Value; + + public override readonly string ToString() { var span = new ReadOnlySpan(Value, Length); return span.AsString(); diff --git a/sources/LLVMSharp.Interop/Internals/MarshaledStringArray.cs b/sources/LLVMSharp.Interop/Internals/MarshaledStringArray.cs index 762f1a82..2d9211e2 100644 --- a/sources/LLVMSharp.Interop/Internals/MarshaledStringArray.cs +++ b/sources/LLVMSharp.Interop/Internals/MarshaledStringArray.cs @@ -25,9 +25,9 @@ public MarshaledStringArray(ReadOnlySpan inputs) } } - public int Count => (_values is not null) ? _values.Length : 0; + public readonly int Count => Values.Length; - public ReadOnlySpan Values => _values; + public readonly ReadOnlySpan Values => _values; public void Dispose() { @@ -42,7 +42,7 @@ public void Dispose() } } - public void Fill(sbyte** pDestination) + public readonly void Fill(sbyte** pDestination) { if (_values != null) { diff --git a/sources/LLVMSharp.Interop/Internals/NativeTypeNameAttribute.cs b/sources/LLVMSharp.Interop/Internals/NativeTypeNameAttribute.cs index ad55b2f0..aefef7ed 100644 --- a/sources/LLVMSharp.Interop/Internals/NativeTypeNameAttribute.cs +++ b/sources/LLVMSharp.Interop/Internals/NativeTypeNameAttribute.cs @@ -6,18 +6,13 @@ namespace LLVMSharp.Interop; /// Defines the type of a member as it was used in the native signature. +/// Initializes a new instance of the class. +/// The name of the type that was used in the native signature. [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] [Conditional("DEBUG")] -internal sealed partial class NativeTypeNameAttribute : Attribute +internal sealed partial class NativeTypeNameAttribute(string name) : Attribute { - private readonly string _name; - - /// Initializes a new instance of the class. - /// The name of the type that was used in the native signature. - public NativeTypeNameAttribute(string name) - { - _name = name; - } + private readonly string _name = name; /// Gets the name of the type that was used in the native signature. public string Name => _name; diff --git a/sources/LLVMSharp.Interop/Internals/SpanExtensions.cs b/sources/LLVMSharp.Interop/Internals/SpanExtensions.cs index 3efa54bd..3ec87c47 100644 --- a/sources/LLVMSharp.Interop/Internals/SpanExtensions.cs +++ b/sources/LLVMSharp.Interop/Internals/SpanExtensions.cs @@ -10,12 +10,7 @@ public static unsafe class SpanExtensions { public static string AsString(sbyte* pStr) { -#if NET6_0_OR_GREATER var span = MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)(pStr)); -#else - var span = new ReadOnlySpan(pStr, int.MaxValue); - span = span.Slice(0, span.IndexOf((byte)'\0')); -#endif return span.AsString(); } diff --git a/sources/LLVMSharp.Interop/LLVM.cs b/sources/LLVMSharp.Interop/LLVM.cs new file mode 100644 index 00000000..e69de29b diff --git a/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj b/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj index aeead678..991a10a8 100644 --- a/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj +++ b/sources/LLVMSharp.Interop/LLVMSharp.Interop.csproj @@ -2,25 +2,42 @@ - net6.0;net7.0;netstandard2.0 + net8.0 - - - - + + + + + + + + + + + + + + + + + + + + + + + + + $(NoWarn);CA1003;CA1008;CA1027;CA1031;CA1034;CA1041;CA1051;CA1069;CA1305;CA1508;CA1700;CA1707;CA1708;CA1710;CA1711;CA1712;CA1715;CA1720;CA1721;CA1724;CA1815;CA2201;CA2225 + - - + + - - - - - diff --git a/sources/LLVMSharp.Interop/Shims/SkipLocalsInitAttribute.cs b/sources/LLVMSharp.Interop/Shims/SkipLocalsInitAttribute.cs deleted file mode 100644 index d9518d5d..00000000 --- a/sources/LLVMSharp.Interop/Shims/SkipLocalsInitAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -namespace System.Runtime.CompilerServices; - -[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false)] -internal sealed class SkipLocalsInitAttribute : Attribute -{ -} diff --git a/sources/LLVMSharp/Attribute.cs b/sources/LLVMSharp/Attribute.cs index 33d7c96f..9cd8c606 100644 --- a/sources/LLVMSharp/Attribute.cs +++ b/sources/LLVMSharp/Attribute.cs @@ -24,7 +24,6 @@ public sealed class Attribute : IEquatable public enum AttributeKind { -#pragma warning disable CA1069 // Enums values should not be duplicated None, FirstEnumAttr = 1, @@ -120,5 +119,4 @@ public enum AttributeKind EndAttrKinds, EmptyKey, TombstoneKey, -#pragma warning restore CA1069 // Enums values should not be duplicated } diff --git a/sources/LLVMSharp/DataLayout.cs b/sources/LLVMSharp/DataLayout.cs index 5e42ed72..e0a72f20 100644 --- a/sources/LLVMSharp/DataLayout.cs +++ b/sources/LLVMSharp/DataLayout.cs @@ -5,28 +5,47 @@ namespace LLVMSharp; -public sealed class DataLayout : IEquatable +public sealed class DataLayout(ReadOnlySpan stringRep) : IEquatable { - public DataLayout(ReadOnlySpan stringRep) - { - Handle = LLVMTargetDataRef.FromStringRepresentation(stringRep); - } - - public LLVMTargetDataRef Handle { get; } + public LLVMTargetDataRef Handle { get; } = LLVMTargetDataRef.FromStringRepresentation(stringRep); public StructLayout GetStructLayout(StructType structType) => new StructLayout(this, structType); - public ulong GetTypeSizeInBits(Type type) => Handle.SizeOfTypeInBits(type.Handle); + public ulong GetTypeSizeInBits(Type type) + { + ArgumentNullException.ThrowIfNull(type); + return Handle.SizeOfTypeInBits(type.Handle); + } - public ulong GetTypeStoreSize(Type type) => Handle.StoreSizeOfType(type.Handle); + public ulong GetTypeStoreSize(Type type) + { + ArgumentNullException.ThrowIfNull(type); + return Handle.StoreSizeOfType(type.Handle); + } - public ulong GetTypeAllocSize(Type type) => Handle.ABISizeOfType(type.Handle); + public ulong GetTypeAllocSize(Type type) + { + ArgumentNullException.ThrowIfNull(type); + return Handle.ABISizeOfType(type.Handle); + } - public uint GetABITypeAlignment(Type type) => Handle.ABIAlignmentOfType(type.Handle); + public uint GetABITypeAlignment(Type type) + { + ArgumentNullException.ThrowIfNull(type); + return Handle.ABIAlignmentOfType(type.Handle); + } - public uint GetPrefTypeAlignment(Type type) => Handle.PreferredAlignmentOfType(type.Handle); + public uint GetPrefTypeAlignment(Type type) + { + ArgumentNullException.ThrowIfNull(type); + return Handle.PreferredAlignmentOfType(type.Handle); + } - public uint GetPreferredAlign(Value value) => Handle.PreferredAlignmentOfGlobal(value.Handle); + public uint GetPreferredAlign(Value value) + { + ArgumentNullException.ThrowIfNull(value); + return Handle.PreferredAlignmentOfGlobal(value.Handle); + } public static bool operator ==(DataLayout? left, DataLayout? right) => ReferenceEquals(left, right) || (left?.Handle == right?.Handle); diff --git a/sources/LLVMSharp/IRBuilder.cs b/sources/LLVMSharp/IRBuilder.cs index ba096148..564d7dd2 100644 --- a/sources/LLVMSharp/IRBuilder.cs +++ b/sources/LLVMSharp/IRBuilder.cs @@ -5,16 +5,15 @@ namespace LLVMSharp; -public sealed class IRBuilder : IRBuilderBase +public sealed class IRBuilder(LLVMContext c) : IRBuilderBase(c) { - public IRBuilder(LLVMContext c) : base(c) - { - } - public Value CreateAdd(Value lhs, Value rhs, string name ="") => CreateAdd(lhs, rhs, name.AsSpan()); public Value CreateAdd(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildAdd(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -23,6 +22,9 @@ public Value CreateAdd(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateAddrSpaceCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildAddrSpaceCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -40,6 +42,8 @@ public ReturnInst CreateAggregateRet(ReadOnlySpan retVals) public AllocaInst CreateAlloca(Type ty, Value? arraySize, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); + var handle = Handle.BuildArrayAlloca(ty.Handle, arraySize?.Handle ?? default, name); return Context.GetOrCreate(handle); } @@ -48,6 +52,9 @@ public AllocaInst CreateAlloca(Type ty, Value? arraySize, ReadOnlySpan nam public Value CreateAnd(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildAnd(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -56,12 +63,18 @@ public Value CreateAnd(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateAShr(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildAShr(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } public AtomicRMWInst CreateAtomicRMW(AtomicRMWInst.BinOp op, Value ptr, Value val, AtomicOrdering ordering, SyncScopeID ssid = SyncScopeID.System) { + ArgumentNullException.ThrowIfNull(ptr); + ArgumentNullException.ThrowIfNull(val); + var handle = Handle.BuildAtomicRMW((LLVMAtomicRMWBinOp)op, ptr.Handle, val.Handle, (LLVMAtomicOrdering)ordering, ssid == SyncScopeID.SingleThread); return Context.GetOrCreate(handle); } @@ -70,6 +83,9 @@ public AtomicRMWInst CreateAtomicRMW(AtomicRMWInst.BinOp op, Value ptr, Value va public Value CreateBinOp(Instruction.BinaryOps opc, Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildBinOp((LLVMOpcode)opc, lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -78,12 +94,16 @@ public Value CreateBinOp(Instruction.BinaryOps opc, Value lhs, Value rhs, ReadOn public Value CreateBitCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildBitCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } public BranchInst CreateBr(BasicBlock dest) { + ArgumentNullException.ThrowIfNull(dest); var handle = Handle.BuildBr(dest.Handle); return Context.GetOrCreate(handle); } @@ -92,6 +112,9 @@ public BranchInst CreateBr(BasicBlock dest) public CallInst CreateCall(FunctionType fTy, Value callee, ReadOnlySpan args, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(fTy); + ArgumentNullException.ThrowIfNull(callee); + using var argHandles = new MarshaledArray(args, (value) => value.Handle); var handle = Handle.BuildCall2(fTy.Handle, callee.Handle, argHandles.AsSpan(), name); return Context.GetOrCreate(handle); @@ -101,12 +124,19 @@ public CallInst CreateCall(FunctionType fTy, Value callee, ReadOnlySpan a public Value CreateCast(Instruction.CastOps op, Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildCast((LLVMOpcode)op, v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } public BranchInst CreateCondBr(Value cond, BasicBlock @true, BasicBlock @false) { + ArgumentNullException.ThrowIfNull(cond); + ArgumentNullException.ThrowIfNull(@true); + ArgumentNullException.ThrowIfNull(@false); + var handle = Handle.BuildCondBr(cond.Handle, @true.Handle, @false.Handle); return Context.GetOrCreate(handle); } @@ -115,6 +145,9 @@ public BranchInst CreateCondBr(Value cond, BasicBlock @true, BasicBlock @false) public Value CreateExactSDiv(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildExactSDiv(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -123,6 +156,9 @@ public Value CreateExactSDiv(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateExtractElement(Value vec, Value idx, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(vec); + ArgumentNullException.ThrowIfNull(idx); + var handle = Handle.BuildExtractElement(vec.Handle, idx.Handle, name); return Context.GetOrCreate(handle); } @@ -131,6 +167,7 @@ public Value CreateExtractElement(Value vec, Value idx, ReadOnlySpan name) public Value CreateExtractValue(Value agg, uint idx, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(agg); var handle = Handle.BuildExtractValue(agg.Handle, idx, name); return Context.GetOrCreate(handle); } @@ -139,6 +176,9 @@ public Value CreateExtractValue(Value agg, uint idx, ReadOnlySpan name) public Value CreateFAdd(Value l, Value r, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(l); + ArgumentNullException.ThrowIfNull(r); + var handle = Handle.BuildFAdd(l.Handle, r.Handle, name); return Context.GetOrCreate(handle); } @@ -147,6 +187,9 @@ public Value CreateFAdd(Value l, Value r, ReadOnlySpan name) public Value CreateFCmp(CmpInst.Predicate p, Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildFCmp((LLVMRealPredicate)p, lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -155,6 +198,9 @@ public Value CreateFCmp(CmpInst.Predicate p, Value lhs, Value rhs, ReadOnlySpan< public Value CreateFDiv(Value l, Value r, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(l); + ArgumentNullException.ThrowIfNull(r); + var handle = Handle.BuildFDiv(l.Handle, r.Handle, name); return Context.GetOrCreate(handle); } @@ -171,6 +217,9 @@ public FenceInst CreateFence(AtomicOrdering ordering, SyncScopeID ssid, ReadOnly public Value CreateFMul(Value l, Value r, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(l); + ArgumentNullException.ThrowIfNull(r); + var handle = Handle.BuildFMul(l.Handle, r.Handle, name); return Context.GetOrCreate(handle); } @@ -179,6 +228,7 @@ public Value CreateFMul(Value l, Value r, ReadOnlySpan name) public Value CreateFNeg(Value v, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildFNeg(v.Handle, name); return Context.GetOrCreate(handle); } @@ -187,6 +237,9 @@ public Value CreateFNeg(Value v, ReadOnlySpan name) public Value CreateFPCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildFPCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -195,6 +248,9 @@ public Value CreateFPCast(Value v, Type destTy, ReadOnlySpan name) public Value CreateFPExt(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildFPExt(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -203,6 +259,9 @@ public Value CreateFPExt(Value v, Type destTy, ReadOnlySpan name) public Value CreateFPToSI(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildFPToSI(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -211,6 +270,9 @@ public Value CreateFPToSI(Value v, Type destTy, ReadOnlySpan name) public Value CreateFPToUI(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildFPToUI(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -219,6 +281,9 @@ public Value CreateFPToUI(Value v, Type destTy, ReadOnlySpan name) public Value CreateFPTrunc(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildFPTrunc(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -227,6 +292,7 @@ public Value CreateFPTrunc(Value v, Type destTy, ReadOnlySpan name) public Value CreateFreeze(Value v, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildFreeze(v.Handle, name); return Context.GetOrCreate(handle); } @@ -235,6 +301,9 @@ public Value CreateFreeze(Value v, ReadOnlySpan name) public Value CreateFRem(Value l, Value r, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(l); + ArgumentNullException.ThrowIfNull(r); + var handle = Handle.BuildFRem(l.Handle, r.Handle, name); return Context.GetOrCreate(handle); } @@ -243,6 +312,9 @@ public Value CreateFRem(Value l, Value r, ReadOnlySpan name) public Value CreateFSub(Value l, Value r, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(l); + ArgumentNullException.ThrowIfNull(r); + var handle = Handle.BuildFSub(l.Handle, r.Handle, name); return Context.GetOrCreate(handle); } @@ -251,6 +323,9 @@ public Value CreateFSub(Value l, Value r, ReadOnlySpan name) public Value CreateGEP(Type ty, Value ptr, ReadOnlySpan idxList, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); + ArgumentNullException.ThrowIfNull(ptr); + using var idxListHandles = new MarshaledArray(idxList, (value) => value.Handle); var handle = Handle.BuildGEP2(ty.Handle, ptr.Handle, idxListHandles.AsSpan(), name); return Context.GetOrCreate(handle); @@ -268,6 +343,9 @@ public Constant CreateGlobalStringPtr(ReadOnlySpan str, ReadOnlySpan public Value CreateICmp(CmpInst.Predicate p, Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildICmp((LLVMIntPredicate)p, lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -276,6 +354,9 @@ public Value CreateICmp(CmpInst.Predicate p, Value lhs, Value rhs, ReadOnlySpan< public Value CreateInBoundsGEP(Type ty, Value ptr, ReadOnlySpan idxList, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); + ArgumentNullException.ThrowIfNull(ptr); + using var idxListHandles = new MarshaledArray(idxList, (value) => value.Handle); var handle = Handle.BuildInBoundsGEP2(ty.Handle, ptr.Handle, idxListHandles.AsSpan(), name); return Context.GetOrCreate(handle); @@ -283,6 +364,7 @@ public Value CreateInBoundsGEP(Type ty, Value ptr, ReadOnlySpan idxList, public IndirectBrInst CreateIndirectBr(Value addr, uint numDests = 10) { + ArgumentNullException.ThrowIfNull(addr); var handle = Handle.BuildIndirectBr(addr.Handle, numDests); return Context.GetOrCreate(handle); } @@ -291,6 +373,10 @@ public IndirectBrInst CreateIndirectBr(Value addr, uint numDests = 10) public Value CreateInsertElement(Value vec, Value newElt, Value idx, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(vec); + ArgumentNullException.ThrowIfNull(newElt); + ArgumentNullException.ThrowIfNull(idx); + var handle = Handle.BuildInsertElement(vec.Handle, newElt.Handle, idx.Handle, name); return Context.GetOrCreate(handle); } @@ -299,6 +385,9 @@ public Value CreateInsertElement(Value vec, Value newElt, Value idx, ReadOnlySpa public Value CreateInsertValue(Value agg, Value val, uint idx, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(agg); + ArgumentNullException.ThrowIfNull(val); + var handle = Handle.BuildInsertValue(agg.Handle, val.Handle, idx, name); return Context.GetOrCreate(handle); } @@ -307,6 +396,9 @@ public Value CreateInsertValue(Value agg, Value val, uint idx, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildIntCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -315,6 +407,9 @@ public Value CreateIntCast(Value v, Type destTy, ReadOnlySpan name) public Value CreateIntToPtr(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildIntToPtr(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -323,6 +418,12 @@ public Value CreateIntToPtr(Value v, Type destTy, ReadOnlySpan name) public InvokeInst CreateInvoke(FunctionType ty, Value callee, BasicBlock normalDest, BasicBlock unwindDest, ReadOnlySpan args, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); + ArgumentNullException.ThrowIfNull(callee); + ArgumentNullException.ThrowIfNull(normalDest); + ArgumentNullException.ThrowIfNull(unwindDest); + + using var argHandles = new MarshaledArray(args, (value) => value.Handle); var handle = Handle.BuildInvoke2(ty.Handle, callee.Handle, argHandles.AsSpan(), normalDest.Handle, unwindDest.Handle, name); return Context.GetOrCreate(handle); @@ -332,6 +433,7 @@ public InvokeInst CreateInvoke(FunctionType ty, Value callee, BasicBlock normalD public Value CreateIsNotNull(Value arg, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(arg); var handle = Handle.BuildIsNotNull(arg.Handle, name); return Context.GetOrCreate(handle); } @@ -340,6 +442,7 @@ public Value CreateIsNotNull(Value arg, ReadOnlySpan name) public Value CreateIsNull(Value arg, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(arg); var handle = Handle.BuildIsNull(arg.Handle, name); return Context.GetOrCreate(handle); } @@ -348,6 +451,7 @@ public Value CreateIsNull(Value arg, ReadOnlySpan name) public LandingPadInst CreateLandingPad(Type ty, uint numClauses, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); var handle = Handle.BuildLandingPad(ty.Handle, default, numClauses, name); return Context.GetOrCreate(handle); } @@ -356,6 +460,9 @@ public LandingPadInst CreateLandingPad(Type ty, uint numClauses, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); + ArgumentNullException.ThrowIfNull(ptr); + var handle = Handle.BuildLoad2(ty.Handle, ptr.Handle, name); return Context.GetOrCreate(handle); } @@ -364,6 +471,9 @@ public LoadInst CreateLoad(Type ty, Value ptr, ReadOnlySpan name) public Value CreateLShr(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildLShr(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -372,6 +482,9 @@ public Value CreateLShr(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateMul(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildMul(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -380,6 +493,7 @@ public Value CreateMul(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateNeg(Value v, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildNeg(v.Handle, name); return Context.GetOrCreate(handle); } @@ -388,6 +502,7 @@ public Value CreateNeg(Value v, ReadOnlySpan name) public Value CreateNot(Value v, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildNot(v.Handle, name); return Context.GetOrCreate(handle); } @@ -396,6 +511,9 @@ public Value CreateNot(Value v, ReadOnlySpan name) public Value CreateNSWAdd(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildNSWAdd(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -404,6 +522,9 @@ public Value CreateNSWAdd(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateNSWMul(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildNSWMul(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -412,6 +533,7 @@ public Value CreateNSWMul(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateNSWNeg(Value v, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildNSWNeg(v.Handle, name); return Context.GetOrCreate(handle); } @@ -420,6 +542,9 @@ public Value CreateNSWNeg(Value v, ReadOnlySpan name) public Value CreateNSWSub(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildNSWSub(lhs.Handle, rhs.Handle, name); ; return Context.GetOrCreate(handle); } @@ -428,6 +553,9 @@ public Value CreateNSWSub(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateNUWAdd(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildNUWAdd(lhs.Handle, rhs.Handle, name); ; return Context.GetOrCreate(handle); } @@ -436,6 +564,9 @@ public Value CreateNUWAdd(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateNUWMul(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildNUWMul(lhs.Handle, rhs.Handle, name); ; return Context.GetOrCreate(handle); } @@ -444,6 +575,7 @@ public Value CreateNUWMul(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateNUWNeg(Value v, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildNUWNeg(v.Handle, name); return Context.GetOrCreate(handle); } @@ -452,6 +584,9 @@ public Value CreateNUWNeg(Value v, ReadOnlySpan name) public Value CreateNUWSub(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildNUWSub(lhs.Handle, rhs.Handle, name); ; return Context.GetOrCreate(handle); } @@ -460,6 +595,9 @@ public Value CreateNUWSub(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateOr(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildOr(lhs.Handle, rhs.Handle, name); ; return Context.GetOrCreate(handle); } @@ -468,6 +606,7 @@ public Value CreateOr(Value lhs, Value rhs, ReadOnlySpan name) public PHINode CreatePHI(Type ty, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); var handle = Handle.BuildPhi(ty.Handle, name); return Context.GetOrCreate(handle); } @@ -476,6 +615,9 @@ public PHINode CreatePHI(Type ty, ReadOnlySpan name) public Value CreatePointerCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildPointerCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -484,6 +626,10 @@ public Value CreatePointerCast(Value v, Type destTy, ReadOnlySpan name) public Value CreatePtrDiff(Type elemTy, Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(elemTy); + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildPtrDiff2(elemTy.Handle, lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -492,18 +638,23 @@ public Value CreatePtrDiff(Type elemTy, Value lhs, Value rhs, ReadOnlySpan public Value CreatePtrToInt(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildPtrToInt(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } public ResumeInst CreateResume(Value exn) { + ArgumentNullException.ThrowIfNull(exn); var handle = Handle.BuildResume(exn.Handle); return Context.GetOrCreate(handle); } public ReturnInst CreateRet(Value v) { + ArgumentNullException.ThrowIfNull(v); var handle = Handle.BuildRet(v.Handle); return Context.GetOrCreate(handle); } @@ -518,6 +669,9 @@ public ReturnInst CreateRetVoid() public Value CreateSDiv(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildSDiv(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -526,6 +680,10 @@ public Value CreateSDiv(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateSelect(Value c, Value @true, Value @false, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(c); + ArgumentNullException.ThrowIfNull(@true); + ArgumentNullException.ThrowIfNull(@false); + var handle = Handle.BuildSelect(c.Handle, @true.Handle, @false.Handle, name); return Context.GetOrCreate(handle); } @@ -534,6 +692,9 @@ public Value CreateSelect(Value c, Value @true, Value @false, ReadOnlySpan public Value CreateSExt(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildSExt(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -542,6 +703,9 @@ public Value CreateSExt(Value v, Type destTy, ReadOnlySpan name) public Value CreateSExtOrBitCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildSExtOrBitCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -550,6 +714,9 @@ public Value CreateSExtOrBitCast(Value v, Type destTy, ReadOnlySpan name) public Value CreateShl(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildShl(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -558,6 +725,10 @@ public Value CreateShl(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateShuffleVector(Value v1, Value v2, Value mask, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v1); + ArgumentNullException.ThrowIfNull(v2); + ArgumentNullException.ThrowIfNull(mask); + var handle = Handle.BuildShuffleVector(v1.Handle, v2.Handle, mask.Handle, name); return Context.GetOrCreate(handle); } @@ -566,6 +737,9 @@ public Value CreateShuffleVector(Value v1, Value v2, Value mask, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildSIToFP(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -574,12 +748,18 @@ public Value CreateSIToFP(Value v, Type destTy, ReadOnlySpan name) public Value CreateSRem(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildSRem(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } public StoreInst CreateStore(Value v, Value ptr) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(ptr); + var handle = Handle.BuildStore(v.Handle, ptr.Handle); return Context.GetOrCreate(handle); } @@ -588,6 +768,9 @@ public StoreInst CreateStore(Value v, Value ptr) public Value CreateStructGEP(Type ty, Value ptr, uint idx, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(ty); + ArgumentNullException.ThrowIfNull(ptr); + var handle = Handle.BuildStructGEP2(ty.Handle, ptr.Handle, idx, name); return Context.GetOrCreate(handle); } @@ -596,12 +779,18 @@ public Value CreateStructGEP(Type ty, Value ptr, uint idx, ReadOnlySpan na public Value CreateSub(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildSub(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } public SwitchInst CreateSwitch(Value v, BasicBlock dest, uint numCases = 10) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(dest); + var handle = Handle.BuildSwitch(v.Handle, dest.Handle, numCases); return Context.GetOrCreate(handle); } @@ -610,6 +799,9 @@ public SwitchInst CreateSwitch(Value v, BasicBlock dest, uint numCases = 10) public Value CreateTrunc(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildTrunc(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -618,6 +810,9 @@ public Value CreateTrunc(Value v, Type destTy, ReadOnlySpan name) public Value CreateTruncOrBitCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildTruncOrBitCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -626,6 +821,9 @@ public Value CreateTruncOrBitCast(Value v, Type destTy, ReadOnlySpan name) public Value CreateUDiv(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildUDiv(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -634,6 +832,9 @@ public Value CreateUDiv(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateUIToFP(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildUIToFP(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -648,6 +849,9 @@ public UnreachableInst CreateUnreachable() public Value CreateURem(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildURem(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -656,6 +860,9 @@ public Value CreateURem(Value lhs, Value rhs, ReadOnlySpan name) public VAArgInst CreateVAArg(Value list, Type ty, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(list); + ArgumentNullException.ThrowIfNull(ty); + var handle = Handle.BuildVAArg(list.Handle, ty.Handle, name); return Context.GetOrCreate(handle); } @@ -664,6 +871,9 @@ public VAArgInst CreateVAArg(Value list, Type ty, ReadOnlySpan name) public Value CreateXor(Value lhs, Value rhs, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(lhs); + ArgumentNullException.ThrowIfNull(rhs); + var handle = Handle.BuildXor(lhs.Handle, rhs.Handle, name); return Context.GetOrCreate(handle); } @@ -672,6 +882,9 @@ public Value CreateXor(Value lhs, Value rhs, ReadOnlySpan name) public Value CreateZExt(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildZExt(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -680,6 +893,9 @@ public Value CreateZExt(Value v, Type destTy, ReadOnlySpan name) public Value CreateZExtOrBitCast(Value v, Type destTy, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(v); + ArgumentNullException.ThrowIfNull(destTy); + var handle = Handle.BuildZExtOrBitCast(v.Handle, destTy.Handle, name); return Context.GetOrCreate(handle); } @@ -688,6 +904,7 @@ public Value CreateZExtOrBitCast(Value v, Type destTy, ReadOnlySpan name) public Instruction Insert(Instruction i, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(i); Handle.InsertWithName(i.Handle, name); return i; } diff --git a/sources/LLVMSharp/IRBuilderBase.cs b/sources/LLVMSharp/IRBuilderBase.cs index c73c9d8f..cd7cf84a 100644 --- a/sources/LLVMSharp/IRBuilderBase.cs +++ b/sources/LLVMSharp/IRBuilderBase.cs @@ -46,9 +46,17 @@ public GlobalVariable CreateGlobalString(ReadOnlySpan str, ReadOnlySpan Handle.GetHashCode(); - public void SetInsertPoint(BasicBlock theBB) => Handle.PositionAtEnd(theBB.Handle); + public void SetInsertPoint(BasicBlock theBB) + { + ArgumentNullException.ThrowIfNull(theBB); + Handle.PositionAtEnd(theBB.Handle); + } - public void SetInstDebugLocation(Instruction i) => Handle.SetInstDebugLocation(i.Handle); + public void SetInstDebugLocation(Instruction i) + { + ArgumentNullException.ThrowIfNull(i); + Handle.SetInstDebugLocation(i.Handle); + } public override string ToString() => Handle.ToString(); } diff --git a/sources/LLVMSharp/LLVMContext.cs b/sources/LLVMSharp/LLVMContext.cs index 62769685..c9fa9065 100644 --- a/sources/LLVMSharp/LLVMContext.cs +++ b/sources/LLVMSharp/LLVMContext.cs @@ -9,8 +9,8 @@ namespace LLVMSharp; public sealed class LLVMContext : IEquatable { - private readonly Dictionary> _createdValues = new Dictionary>(); - private readonly Dictionary> _createdTypes = new Dictionary>(); + private readonly Dictionary> _createdValues = []; + private readonly Dictionary> _createdTypes = []; public LLVMContext() { diff --git a/sources/LLVMSharp/LLVMSharp.csproj b/sources/LLVMSharp/LLVMSharp.csproj index 20645082..9710c2f3 100644 --- a/sources/LLVMSharp/LLVMSharp.csproj +++ b/sources/LLVMSharp/LLVMSharp.csproj @@ -2,7 +2,18 @@ - net6.0;net7.0;netstandard2.0 + net8.0 + + + + + + + + + + + $(NoWarn);CA1027;CA1069;CA1707;CA1711;CA1716;CA1720;CA1724 diff --git a/sources/LLVMSharp/Types/StructType.cs b/sources/LLVMSharp/Types/StructType.cs index 648b42e6..e4c5d194 100644 --- a/sources/LLVMSharp/Types/StructType.cs +++ b/sources/LLVMSharp/Types/StructType.cs @@ -15,6 +15,7 @@ internal StructType(LLVMTypeRef handle) : base(handle, LLVMTypeKind.LLVMStructTy public static StructType Create(LLVMContext context, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(context); var handle = context.Handle.CreateNamedStruct(name); return context.GetOrCreate(handle); } diff --git a/sources/LLVMSharp/Types/Type.cs b/sources/LLVMSharp/Types/Type.cs index 8ddbed57..28126436 100644 --- a/sources/LLVMSharp/Types/Type.cs +++ b/sources/LLVMSharp/Types/Type.cs @@ -11,7 +11,7 @@ private protected Type(LLVMTypeRef handle, LLVMTypeKind expectedTypeKind) { if (handle.Kind != expectedTypeKind) { - throw new ArgumentException(nameof(handle)); + throw new ArgumentOutOfRangeException(nameof(handle)); } Handle = handle; } @@ -24,90 +24,105 @@ private protected Type(LLVMTypeRef handle, LLVMTypeKind expectedTypeKind) public static Type GetBFloatTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.BFloatType; return c.GetOrCreate(handle); } public static Type GetDoubleTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.DoubleType; return c.GetOrCreate(handle); } public static Type GetFloatTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.FloatType; return c.GetOrCreate(handle); } public static Type GetHalfTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.HalfType; return c.GetOrCreate(handle); } public static IntegerType GetInt1Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.Int1Type; return c.GetOrCreate(handle); } public static IntegerType GetInt8Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.Int8Type; return c.GetOrCreate(handle); } public static IntegerType GetInt16Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.Int16Type; return c.GetOrCreate(handle); } public static IntegerType GetInt32Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.Int32Type; return c.GetOrCreate(handle); } public static IntegerType GetInt64Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.Int64Type; return c.GetOrCreate(handle); } public static Type GetFP128Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.FP128Type; return c.GetOrCreate(handle); } public static Type GetLabelTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.LabelType; return c.GetOrCreate(handle); } public static Type GetPPC_FP128Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.PPCFP128Type; return c.GetOrCreate(handle); } public static Type GetVoidTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.VoidType; return c.GetOrCreate(handle); } public static Type GetX86_FP80Ty(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.X86FP80Type; return c.GetOrCreate(handle); } public static Type GetX86_MMXTy(LLVMContext c) { + ArgumentNullException.ThrowIfNull(c); var handle = c.Handle.X86MMXType; return c.GetOrCreate(handle); } diff --git a/sources/LLVMSharp/Values/BasicBlock.cs b/sources/LLVMSharp/Values/BasicBlock.cs index 89ba5800..f5db5bd8 100644 --- a/sources/LLVMSharp/Values/BasicBlock.cs +++ b/sources/LLVMSharp/Values/BasicBlock.cs @@ -20,6 +20,7 @@ internal BasicBlock(LLVMValueRef handle) : base(handle.IsABasicBlock, LLVMValueK public static BasicBlock Create(LLVMContext context, ReadOnlySpan name) { + ArgumentNullException.ThrowIfNull(context); var handle = LLVMBasicBlockRef.CreateInContext(context.Handle, name); return new BasicBlock(handle); } @@ -28,6 +29,9 @@ public static BasicBlock Create(LLVMContext context, ReadOnlySpan name) public static BasicBlock Create(LLVMContext context, ReadOnlySpan name, Function parent) { + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(parent); + var handle = LLVMBasicBlockRef.AppendInContext(context.Handle, parent.Handle, name); return new BasicBlock(handle); } @@ -36,6 +40,9 @@ public static BasicBlock Create(LLVMContext context, ReadOnlySpan name, Fu public static BasicBlock Create(LLVMContext context, ReadOnlySpan name, BasicBlock insertBefore) { + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(insertBefore); + var handle = LLVMBasicBlockRef.InsertInContext(context.Handle, insertBefore.Handle, name); return new BasicBlock(handle); } diff --git a/sources/LLVMSharp/Values/Users/Constants/ConstantAggregates/ConstantStruct.cs b/sources/LLVMSharp/Values/Users/Constants/ConstantAggregates/ConstantStruct.cs index 2a73530d..919ddc7c 100644 --- a/sources/LLVMSharp/Values/Users/Constants/ConstantAggregates/ConstantStruct.cs +++ b/sources/LLVMSharp/Values/Users/Constants/ConstantAggregates/ConstantStruct.cs @@ -15,6 +15,7 @@ internal ConstantStruct(LLVMValueRef handle) : base(handle.IsAConstantStruct, LL public static Constant GetAnon(LLVMContext ctx, ReadOnlySpan v, bool packed) { + ArgumentNullException.ThrowIfNull(ctx); using var marshaledV = new MarshaledArray(v, (value) => value.Handle); var handle = ctx.Handle.GetConstStruct(marshaledV.AsSpan(), packed); return ctx.GetOrCreate(handle); diff --git a/sources/LLVMSharp/Values/Users/Constants/ConstantDatas/ConstantDataArray.cs b/sources/LLVMSharp/Values/Users/Constants/ConstantDatas/ConstantDataArray.cs index 8002f961..73b4c3c1 100644 --- a/sources/LLVMSharp/Values/Users/Constants/ConstantDatas/ConstantDataArray.cs +++ b/sources/LLVMSharp/Values/Users/Constants/ConstantDatas/ConstantDataArray.cs @@ -15,6 +15,7 @@ internal ConstantDataArray(LLVMValueRef handle) : base(handle.IsAConstantDataArr public static Constant GetString(LLVMContext context, ReadOnlySpan initializer, bool addNull) { + ArgumentNullException.ThrowIfNull(context); var handle = context.Handle.GetConstString(initializer, !addNull); return context.GetOrCreate(handle); } diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.BinaryOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.BinaryOps.cs index 9a597ccf..d041463e 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.BinaryOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.BinaryOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum BinaryOps { + Unknown = 0, Add = LLVMOpcode.LLVMAdd, FAdd = LLVMOpcode.LLVMFAdd, Sub = LLVMOpcode.LLVMSub, diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.CastOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.CastOps.cs index 8a0c96b9..8cda2eec 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.CastOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.CastOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum CastOps { + Unknown = 0, Trunc = LLVMOpcode.LLVMTrunc, ZExt = LLVMOpcode.LLVMZExt, SExt = LLVMOpcode.LLVMSExt, diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.FuncletPadOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.FuncletPadOps.cs index dfcd0f31..0ec885dd 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.FuncletPadOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.FuncletPadOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum FuncletPadOps { + Unknown = 0, CleanupPad = LLVMOpcode.LLVMCleanupPad, CatchPad = LLVMOpcode.LLVMCatchPad, } diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.MemoryOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.MemoryOps.cs index d18da6cc..100bea90 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.MemoryOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.MemoryOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum MemoryOps { + Unknown = 0, Alloca = LLVMOpcode.LLVMAlloca, Load = LLVMOpcode.LLVMLoad, Store = LLVMOpcode.LLVMStore, diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.OtherOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.OtherOps.cs index f73776ec..4a7ee23f 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.OtherOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.OtherOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum OtherOps { + Unknown = 0, ICmp = LLVMOpcode.LLVMICmp, FCmp = LLVMOpcode.LLVMFCmp, PHI = LLVMOpcode.LLVMPHI, diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.TermOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.TermOps.cs index d3fc6e33..e1f45ec4 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.TermOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.TermOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum TermOps { + Unknown = 0, Ret = LLVMOpcode.LLVMRet, Br = LLVMOpcode.LLVMBr, Switch = LLVMOpcode.LLVMSwitch, diff --git a/sources/LLVMSharp/Values/Users/Instructions/Instruction.UnaryOps.cs b/sources/LLVMSharp/Values/Users/Instructions/Instruction.UnaryOps.cs index d9bb91a4..3562f1bc 100644 --- a/sources/LLVMSharp/Values/Users/Instructions/Instruction.UnaryOps.cs +++ b/sources/LLVMSharp/Values/Users/Instructions/Instruction.UnaryOps.cs @@ -8,6 +8,7 @@ public partial class Instruction { public enum UnaryOps { + Unknown = 0, FNeg = LLVMOpcode.LLVMFNeg, } } diff --git a/sources/LLVMSharp/Values/Value.cs b/sources/LLVMSharp/Values/Value.cs index a12e896f..f29680fc 100644 --- a/sources/LLVMSharp/Values/Value.cs +++ b/sources/LLVMSharp/Values/Value.cs @@ -11,7 +11,7 @@ private protected Value(LLVMValueRef handle, LLVMValueKind expectedValueKind) { if (handle.Kind != expectedValueKind) { - throw new ArgumentException(nameof(handle)); + throw new ArgumentOutOfRangeException(nameof(handle)); } Handle = handle; } diff --git a/tests/LLVMSharp.UnitTests/DIBuilder.cs b/tests/LLVMSharp.UnitTests/DIBuilder.cs index d545b4b1..e9375fd5 100644 --- a/tests/LLVMSharp.UnitTests/DIBuilder.cs +++ b/tests/LLVMSharp.UnitTests/DIBuilder.cs @@ -25,7 +25,7 @@ public void CreateDebugLocation() module.AddNamedMetadataOperand("llvm.dbg.cu", compileUnitMetadata); var functionMetaType = dIBuilder.CreateSubroutineType(fileMetadata, - ReadOnlySpan.Empty, LLVMDIFlags.LLVMDIFlagZero); + [], LLVMDIFlags.LLVMDIFlagZero); uint lineNumber = 1; var debugFunction = dIBuilder.CreateFunction(fileMetadata, "CreateDebugLocation", "CreateDebugLocation", @@ -34,7 +34,7 @@ public void CreateDebugLocation() var currentLine = module.Context.CreateDebugLocation(lineNumber, 0, debugFunction, default); - LLVMTypeRef[] fooParamTys = {LLVMTypeRef.Int64, LLVMTypeRef.Int64,}; + LLVMTypeRef[] fooParamTys = [LLVMTypeRef.Int64, LLVMTypeRef.Int64,]; var fooFuncTy = LLVMTypeRef.CreateFunction(LLVMTypeRef.Int64, fooParamTys); var fooFunction = module.AddFunction("foo", fooFuncTy); diff --git a/tests/LLVMSharp.UnitTests/Examples.cs b/tests/LLVMSharp.UnitTests/Examples.cs index 86b229b1..13c55739 100644 --- a/tests/LLVMSharp.UnitTests/Examples.cs +++ b/tests/LLVMSharp.UnitTests/Examples.cs @@ -18,10 +18,10 @@ public void Intro() using var module = LLVMModuleRef.CreateWithName("LLVMSharpIntro"); (_, var def) = module.AddFunction( - LLVMTypeRef.Int32, "sum", new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, (f, b) => + LLVMTypeRef.Int32, "sum", [LLVMTypeRef.Int32, LLVMTypeRef.Int32], (f, b) => { - var p1 = f.Params[0]; - var p2 = f.Params[1]; + var p1 = f.GetParam(0); + var p2 = f.GetParam(1); var add = b.BuildAdd(p1, p2); var ret = b.BuildRet(add); }); diff --git a/tests/LLVMSharp.UnitTests/Functions.cs b/tests/LLVMSharp.UnitTests/Functions.cs index 7bea0049..2cd7648f 100644 --- a/tests/LLVMSharp.UnitTests/Functions.cs +++ b/tests/LLVMSharp.UnitTests/Functions.cs @@ -13,14 +13,14 @@ public void ParamTypesRoundtrip() var returnType = LLVMTypeRef.Int8; var parameterTypes = new[] { LLVMTypeRef.Double }; var functionType = LLVMTypeRef.CreateFunction(returnType, parameterTypes); - Assert.AreEqual(parameterTypes, functionType.ParamTypes); + Assert.AreEqual(parameterTypes, functionType.GetParamTypes()); } [Test] public void AddsAttributeAtIndex() { var module = LLVMModuleRef.CreateWithName("Test Module"); - var functionType = LLVMTypeRef.CreateFunction(LLVMTypeRef.Int8, new[] { LLVMTypeRef.Double }); + var functionType = LLVMTypeRef.CreateFunction(LLVMTypeRef.Int8, [LLVMTypeRef.Double]); var functionValue = module.AddFunction("test", functionType); var attr = module.Context.CreateEnumAttribute((uint)AttributeKind.ByVal, default); functionValue.AddAttributeAtIndex((LLVMAttributeIndex)1, attr); diff --git a/tests/LLVMSharp.UnitTests/IR.cs b/tests/LLVMSharp.UnitTests/IR.cs index 04f6215a..7c78f126 100644 --- a/tests/LLVMSharp.UnitTests/IR.cs +++ b/tests/LLVMSharp.UnitTests/IR.cs @@ -18,10 +18,10 @@ public void AddsSigned() using var module = LLVMModuleRef.CreateWithName("test_add"); (_, var def) = module.AddFunction( - LLVMTypeRef.Int32, "add", new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, (f, b) => + LLVMTypeRef.Int32, "add", [LLVMTypeRef.Int32, LLVMTypeRef.Int32], (f, b) => { - var p1 = f.Params[0]; - var p2 = f.Params[1]; + var p1 = f.GetParam(0); + var p2 = f.GetParam(1); var add = b.BuildAdd(p1, p2); var ret = b.BuildRet(add); }); @@ -43,10 +43,10 @@ public void ShiftsRight([Range(0, 256)] int op1, [Range(0, 8)] int op2) using var module = LLVMModuleRef.CreateWithName("test_lshift"); (_, var def) = module.AddFunction( - LLVMTypeRef.Int32, "lshift", new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, (f, b) => + LLVMTypeRef.Int32, "lshift", [LLVMTypeRef.Int32, LLVMTypeRef.Int32], (f, b) => { - var p1 = f.Params[0]; - var p2 = f.Params[1]; + var p1 = f.GetParam(0); + var p2 = f.GetParam(1); var shift = b.BuildLShr(p1, p2); var ret = b.BuildRet(shift); }); @@ -68,10 +68,10 @@ public void ComparesGreaterThan([Range(0, 10)] int op1, [Range(0, 10)] int op2) using var module = LLVMModuleRef.CreateWithName("test_greaterthan"); (_, var def) = module.AddFunction( - LLVMTypeRef.Int1, "greaterthan", new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, (f, b) => + LLVMTypeRef.Int1, "greaterthan", [LLVMTypeRef.Int32, LLVMTypeRef.Int32], (f, b) => { - var p1 = f.Params[0]; - var p2 = f.Params[1]; + var p1 = f.GetParam(0); + var p2 = f.GetParam(1); var cmp = b.BuildICmp(LLVMIntPredicate.LLVMIntSGT, p1, p2); var ret = b.BuildRet(cmp); }); @@ -93,17 +93,17 @@ public void CallsFunction([Range(0, 10)] int op1, [Range(0, 10)] int op2) using var module = LLVMModuleRef.CreateWithName("test_call"); (var addType, var addDef) = module.AddFunction( - LLVMTypeRef.Int32, "add", new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, (f, b) => + LLVMTypeRef.Int32, "add", [LLVMTypeRef.Int32, LLVMTypeRef.Int32], (f, b) => { - var p1 = f.Params[0]; - var p2 = f.Params[1]; + var p1 = f.GetParam(0); + var p2 = f.GetParam(1); var add = b.BuildAdd(p1, p2); var ret = b.BuildRet(add); }); (_, var entryDef) = module.AddFunction( - LLVMTypeRef.Int32, "entry", new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, (f, b) => + LLVMTypeRef.Int32, "entry", [LLVMTypeRef.Int32, LLVMTypeRef.Int32], (f, b) => { - var call = b.BuildCall2(addType, addDef, f.Params, ReadOnlySpan.Empty); + var call = b.BuildCall2(addType, addDef, f.GetParams(), ""); var ret = b.BuildRet(call); }); module.Verify(LLVMVerifierFailureAction.LLVMPrintMessageAction); @@ -125,7 +125,7 @@ public void ReturnsConstant([Range(0, 10)] int input) using var module = LLVMModuleRef.CreateWithName("test_constant"); (_, var def) = module.AddFunction( - LLVMTypeRef.Int32, "constant", Array.Empty(), (f, b) => + LLVMTypeRef.Int32, "constant", [], (f, b) => { var value = LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, uInput); var ret = b.BuildRet(value); @@ -148,7 +148,7 @@ public void ReturnsSizeOf() var str = LLVMTypeRef.CreateStruct(new[] { LLVMTypeRef.Int32, LLVMTypeRef.Int32 }, true); (_, var def) = module.AddFunction( - LLVMTypeRef.Int32, "structure", Array.Empty(), (f, b) => + LLVMTypeRef.Int32, "structure", [], (f, b) => { var sz = str.SizeOf; var sz32 = b.BuildIntCast(sz, LLVMTypeRef.Int32); diff --git a/tests/LLVMSharp.UnitTests/LLVMSharp.UnitTests.csproj b/tests/LLVMSharp.UnitTests/LLVMSharp.UnitTests.csproj index 19f0fc2a..a32cc4f3 100644 --- a/tests/LLVMSharp.UnitTests/LLVMSharp.UnitTests.csproj +++ b/tests/LLVMSharp.UnitTests/LLVMSharp.UnitTests.csproj @@ -2,9 +2,16 @@ - net6.0;net7.0 + net8.0 + + + + + $(NoWarn);CA1707;CA1711;CA1724 + + diff --git a/tests/LLVMSharp.UnitTests/TargetData.cs b/tests/LLVMSharp.UnitTests/TargetData.cs index b6b97cd1..a3100943 100644 --- a/tests/LLVMSharp.UnitTests/TargetData.cs +++ b/tests/LLVMSharp.UnitTests/TargetData.cs @@ -68,7 +68,7 @@ public void AlignmentTest() Assert.AreEqual(4, target.PreferredAlignmentOfGlobal(global)); } - private LLVMTargetDataRef TargetDataFromTriple(string triple) + private static LLVMTargetDataRef TargetDataFromTriple(string triple) { var target = LLVMTargetRef.GetTargetFromTriple(triple); var targetMachine = target.CreateTargetMachine(triple, "", "", diff --git a/tests/LLVMSharp.UnitTests/Targets.cs b/tests/LLVMSharp.UnitTests/Targets.cs index 0d1a3c0e..a37e7248 100644 --- a/tests/LLVMSharp.UnitTests/Targets.cs +++ b/tests/LLVMSharp.UnitTests/Targets.cs @@ -17,7 +17,7 @@ public void InitializeX86Targets() => InitializeTargets(() => LLVM.InitializeX86TargetMC(); LLVM.InitializeX86AsmParser(); LLVM.InitializeX86AsmPrinter(); - }, new[] { "x86" }); + }, ["x86"]); [Test] public void InitializeARMTargets() => InitializeTargets(() => @@ -27,9 +27,9 @@ public void InitializeARMTargets() => InitializeTargets(() => LLVM.InitializeARMTargetMC(); LLVM.InitializeARMAsmParser(); LLVM.InitializeARMAsmPrinter(); - }, new[] { "arm" }); + }, ["arm"]); - private void InitializeTargets(Action init, string[] expectedTargets) + private static void InitializeTargets(Action init, string[] expectedTargets) { init(); diff --git a/tests/LLVMSharp.UnitTests/Utilities.cs b/tests/LLVMSharp.UnitTests/Utilities.cs index 7275b0b5..04609cda 100644 --- a/tests/LLVMSharp.UnitTests/Utilities.cs +++ b/tests/LLVMSharp.UnitTests/Utilities.cs @@ -11,6 +11,8 @@ public static class Utilities { public static void EnsurePropertiesWork(this object obj) { + ArgumentNullException.ThrowIfNull(obj); + var map = new Dictionary(); foreach(var p in obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) @@ -21,6 +23,8 @@ public static void EnsurePropertiesWork(this object obj) public static (LLVMTypeRef functionType, LLVMValueRef function) AddFunction(this LLVMModuleRef module, LLVMTypeRef returnType, string name, LLVMTypeRef[] parameterTypes, Action action) { + ArgumentNullException.ThrowIfNull(action); + var type = LLVMTypeRef.CreateFunction(returnType, parameterTypes); var func = module.AddFunction(name, type); var block = func.AppendBasicBlock(string.Empty);