diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..717b7d7ac --- /dev/null +++ b/.editorconfig @@ -0,0 +1,58 @@ +#Primary settings apply to all files unless overridden below +root = true + +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true + +# match VS generated formatting for MSBuild project files +[*.*proj,*.props,*.targets] +indent_size = 2 + +# match ISO standard requirement for C/C++ +[*.c,*.h,*.cpp] +insert_final_newline = true + +[*.cs] +csharp_style_conditional_delegate_call = true:warning +csharp_style_expression_bodied_accessors = true:suggestion +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_operators = true:suggestion +csharp_style_expression_bodied_properties = true:warning +csharp_style_inlined_variable_declaration = true:warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_throw_expression = true:warning +csharp_style_var_for_built_in_types = false:error +csharp_style_var_when_type_is_apparent = true:warning +csharp_style_var_elsewhere = false:none +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true +dotnet_sort_system_directives_first = true +dotnet_style_coalesce_expression = true:warning +dotnet_style_collection_initializer = true:warning +dotnet_style_explicit_tuple_names = true:warning +dotnet_style_null_propagation = true:warning +dotnet_style_qualification_for_event = false:error +dotnet_style_qualification_for_field = false:error +dotnet_style_qualification_for_property = false:error +csharp_indent_block_contents = true +csharp_indent_case_contents = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = false +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_keywords_in_control_flow_statements = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_around_declaration_statements = ignore +csharp_space_between_method_call_parameter_list_parentheses = true +csharp_space_between_square_brackets = true diff --git a/.gitignore b/.gitignore index 49556461c..214c1c7e6 100644 --- a/.gitignore +++ b/.gitignore @@ -128,7 +128,7 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj @@ -203,10 +203,10 @@ FakesAssemblies/ # VS2015 support file *.opendb -/src/.tools /src/LibLLVM/generatedversioninfo.h *.db -/src/Llvm.NETTests/TestDebugInfo/test.s -/src/Llvm.NETTests/TestDebugInfo/test.o -/src/Llvm.NETTests/TestDebugInfo/test.ll -/src/Llvm.NETTests/TestDebugInfo/test.bc +*.exe +**/launchSettings.json +*.bc +*.o +*.s diff --git a/BuildAll.ps1 b/BuildAll.ps1 new file mode 100644 index 000000000..ae2c504fa --- /dev/null +++ b/BuildAll.ps1 @@ -0,0 +1,181 @@ +# invokes nuget.exe, handles downloading it to the script root if it isn't already on the path +function Invoke-Nuget +{ + #update system search path to include the directory of this script for nuget.exe + $oldPath = $env:Path + $env:Path = "$PSScriptRoot;$env:Path" + try + { + $nugetPaths = where.exe nuget.exe 2>$null + if( !$nugetPaths ) + { + # Download it from official nuget release location + Invoke-WebRequest -UseBasicParsing -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile "$PSScriptRoot\nuget.exe" + } + Write-Information "nuget $args" + nuget $args + $err = $LASTEXITCODE + if($err -ne 0) + { + throw "Error running nuget: $err" + } + } + finally + { + $env:Path = $oldPath + } +} + +function Invoke-msbuild([string]$project, [hashtable]$properties, [string[]]$targets, [string[]]$loggerArgs=@(), [string[]]$additionalArgs=@()) +{ + $msbuildArgs = @($project) + $loggerArgs + $additionalArgs + @("/t:$($targets -join ';')") + if( $properties ) + { + $msbuildArgs += @( "/p:$(ConvertTo-PropertyList $properties)" ) + } + Write-Information "msbuild $($msbuildArgs -join ' ')" + msbuild $msbuildArgs + if($LASTEXITCODE -ne 0) + { + throw "Error running msbuild: $LASTEXITCODE" + } +} + +function Normalize-Path([string]$path) +{ + $path = [System.IO.Path]::GetFullPath($path) + if( !$path.EndsWith([System.IO.Path]::DirectorySeparatorChar) ) + { + $path += [System.IO.Path]::DirectorySeparatorChar + } + return $path +} + +function Get-BuildPaths( [string]$repoRoot) +{ + $buildPaths = @{} + $buildPaths.RepoRoot = $repoRoot + $buildPaths.BuildOutputPath = Normalize-Path (Join-Path $repoRoot 'BuildOutput') + $buildPaths.NugetRepositoryPath = Normalize-Path (Join-Path $buildPaths.BuildOutputPath 'packages') + $buildPaths.NugetOutputPath = Normalize-Path (Join-Path $buildPaths.BuildOutputPath 'Nuget') + $buildPaths.SrcRoot = Normalize-Path (Join-Path $repoRoot 'src') + $buildPaths.LibLLVMSrcRoot = Normalize-Path (Join-Path $buildPaths.SrcRoot 'LibLLVM') + $buildPaths.BuildTaskProjRoot = ([IO.Path]::Combine( $repoRoot, 'BuildExtensions', 'Llvm.NET.BuildTasks') ) + $buildPaths.BuildTaskProj = ([IO.Path]::Combine( $buildPaths.BuildTaskProjRoot, 'Llvm.NET.BuildTasks.csproj') ) + $buildPaths.BuildTaskBin = ([IO.Path]::Combine( $repoRoot, 'BuildOutput', 'bin', 'Release', 'net47', 'Llvm.NET.BuildTasks.dll') ) + return $buildPaths +} + +function Get-BuildInformation($buildPaths) +{ + Write-Information "Computing Build information" + # Run as distinct job to control 32 bit context and to unload the DLL on completion + # this prevents it from remaining loaded in the current session, which would prevent + # rebuild or deletes. + Start-Job -RunAs32 -ScriptBlock { + Write-Information "Computing Build information" + $buildPaths = $args[0] + + Add-Type -Path $buildPaths.BuildTaskBin + $buildVersionData = [Llvm.NET.BuildTasks.BuildVersionData]::Load( (Join-Path $buildPaths.RepoRoot BuildVersion.xml ) ) + $semver = $buildVersionData.CreateSemVer(!!$env:APPVEYOR, !!$env:APPVEYOR_PULL_REQUEST_NUMBER, [DateTime]::UtcNow) + + return @{ + FullBuildNumber = $semVer.ToString($true) + PackageVersion = $semVer.ToString($false) + FileVersionMajor = $semVer.FileVersion.Major + FileVersionMinor = $semVer.FileVersion.Minor + FileVersionBuild = $semVer.FileVersion.Build + FileVersionRevision = $semver.FileVersion.Revision + FileVersion= "$($semVer.FileVersion.Major).$($semVer.FileVersion.Minor).$($semVer.FileVersion.Build).$($semVer.FileVersion.Revision)" + LlvmVersion = "$($buildVersionData.AdditionalProperties['LlvmVersionMajor']).$($buildVersionData.AdditionalProperties['LlvmVersionMinor']).$($buildVersionData.AdditionalProperties['LlvmVersionPatch'])" + } + } -ArgumentList @($buildPaths) | Receive-Job -Wait -AutoRemoveJob +} + +function ConvertTo-PropertyList([hashtable]$table) +{ + (($table.GetEnumerator() | %{ "$($_.Key)=$($_.Value)" }) -join ';') +} + +# Main Script entry point ----------- + +pushd $PSScriptRoot +try +{ + # setup standard MSBuild logging for this build + $msbuildLoggerArgs = @('/clp:Verbosity=Minimal') + + if (Test-Path "C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll") + { + $msbuildLoggerArgs = $msbuildLoggerArgs + @("/logger:`"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll`"") + } + + $buildPaths = Get-BuildPaths $PSScriptRoot + + Write-Information "Build Paths:" + Write-Information ($buildPaths | Format-Table | Out-String) + + if( Test-Path -PathType Container $buildPaths.BuildOutputPath ) + { + Write-Information "Cleaning output folder from previous builds" + rd -Recurse -Force -Path $buildPaths.BuildOutputPath + } + + md BuildOutput\NuGet\ | Out-Null + + Write-Information "Restoring NUGET for internal build task" + invoke-msbuild -Targets Restore -Project $buildPaths.BuildTaskProj -LoggerArgs $msbuildLoggerArgs + + Write-Information "Building internal build task and NuGetPackage" + Invoke-MSBuild -Targets Build -Properties @{Configuration='Release';} -Project $buildPaths.BuildTaskProj -LoggerArgs $msbuildLoggerArgs + + $BuildInfo = Get-BuildInformation $buildPaths + if($env:APPVEYOR) + { + Update-AppVeyorBuild -Version $BuildInfo.FullBuildNumber + } + + $packProperties = @{ version=$($BuildInfo.PackageVersion); + llvmversion=$($BuildInfo.LlvmVersion); + buildbinoutput=(normalize-path (Join-path $($buildPaths.BuildOutputPath) 'bin')); + configuration='Release' + } + + $msBuildProperties = @{ Configuration = 'Release'; + FullBuildNumber = $BuildInfo.FullBuildNumber; + PackageVersion = $BuildInfo.PackageVersion; + FileVersionMajor = $BuildInfo.FileVersionMajor; + FileVersionMinor = $BuildInfo.FileVersionMinor; + FileVersionBuild = $BuildInfo.FileVersionBuild; + FileVersionRevision = $BuildInfo.FileVersionRevision; + FileVersion = $BuildInfo.FileVersion; + LlvmVersion = $BuildInfo.LlvmVersion; + } + + Write-Information "Build Parameters:" + Write-Information ($BuildInfo | Format-Table | Out-String) + + # Need to invoke NuGet directly for restore of vcxproj as there is no /t:Restore target support + Write-Information "Restoring Nuget Packages for LibLLVM.vcxproj" + Invoke-NuGet restore src\LibLLVM\LibLLVM.vcxproj -PackagesDirectory $buildPaths.NuGetRepositoryPath + + Write-Information "Building LibLLVM" + Invoke-MSBuild -Targets Build -Project src\LibLLVM\MultiPlatformBuild.vcxproj -Properties $msBuildProperties -LoggerArgs $msbuildLoggerArgs + + Write-Information "Restoring Nuget Packages for Llvm.NET" + Invoke-MSBuild -Targets Restore -Project src\Llvm.NET\Llvm.NET.csproj -Properties $msBuildProperties -LoggerArgs $msbuildLoggerArgs + + Write-Information "Building Llvm.NET" + Invoke-MSBuild -Targets Build -Project src\Llvm.NET\Llvm.NET.csproj -Properties $msBuildProperties -LoggerArgs $msbuildLoggerArgs + + Write-Information "Running Nuget Restore for Llvm.NET Tests" + Invoke-MSBuild -Targets Restore -Project src\Llvm.NETTests\LLVM.NETTests.csproj -Properties $msBuildProperties -LoggerArgs $msbuildLoggerArgs + + Write-Information "Building Llvm.NET Tests" + Invoke-MSBuild -Targets Build -Project src\Llvm.NETTests\LLVM.NETTests.csproj -Properties $msBuildProperties -LoggerArgs $msbuildLoggerArgs +} +finally +{ + popd +} \ No newline at end of file diff --git a/BuildAll.slnproj b/BuildAll.slnproj deleted file mode 100644 index 629402e85..000000000 --- a/BuildAll.slnproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - LibLLVM.dll - - - - Llvm.NET.dll - - - - Llvm.NETTests.dll - - - - - - - - \ No newline at end of file diff --git a/BuildEnv.props b/BuildEnv.props deleted file mode 100644 index a8cc73002..000000000 --- a/BuildEnv.props +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - x64 - Debug - - - $(MSBuildThisFileDirectory) - $(BuildRootDir)\ - - - $(BuildRootDir)BuildOutput - $(BaseBuildOutputPath)\ - - $(BaseBuildOutputPath)Intermediate\$(MSBuildProjectName)\ - $(BaseIntermediateOutputPath)$(Platform)\$(Configuration)\ - - $(BaseBuildOutputPath)Unsigned\ - $(BaseOutputPath)$(Platform)\$(Configuration)\ - $(OutputPath)\ - - $(OutputPath) - - $(BaseBuildOutputPath)Signed\ - $(BaseSignedOutputPath)$(Platform)\$(Configuration)\ - $(SignedOutputPath)\ - - - 3 - 9 - - $(BuildRootDir)BuildExtensions\ - $(SolutionBuildExtensionsDir) - $(BaseBuildOutputPath)\packages\ - - \ No newline at end of file diff --git a/BuildExtensions/EnlistmentBuildVersion.targets b/BuildExtensions/EnlistmentBuildVersion.targets deleted file mode 100644 index 3acfe165a..000000000 --- a/BuildExtensions/EnlistmentBuildVersion.targets +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(_GeneratedBuildNumber) - $(_GeneratedBuildRevision) - - - - $(_GeneratedBuildRevision) - - - $(BuildMajor).$(BuildMinor).$(BuildNumber).$(BuildRevision)$(BuildSuffix) - - - - diff --git a/BuildExtensions/InlineBuildTasks.targets b/BuildExtensions/InlineBuildTasks.targets deleted file mode 100644 index 104cdbda2..000000000 --- a/BuildExtensions/InlineBuildTasks.targets +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - - - - - - - - - 4 ) - BuildSuffix = FullBuildNumber.Substring( FullBuildNumber.IndexOf( '-' ) ); - else - BuildSuffix = string.Empty; - - Log.LogMessage( MessageImportance.High, "FullVersion: {0}.{1}.{2}.{3}{4}", BuildMajor, BuildMinor, BuildNumber, BuildRevision, BuildSuffix ); - } - catch - { - Log.LogError( "Invalid build version number format. Expected: MMMM.mmmm.nnnn.rrrr[-*]"); - } - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SplitArgs( string inputList ) - { - - if( string.IsNullOrWhiteSpace( inputList ) ) - return Enumerable.Empty(); - - return inputList.Split( ';' ); - } - } - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/BuildExtensions/Llvm.NET.BuildTasks.sln b/BuildExtensions/Llvm.NET.BuildTasks.sln new file mode 100644 index 000000000..cd7688984 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.8 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llvm.NET.BuildTasks", "Llvm.NET.BuildTasks\Llvm.NET.BuildTasks.csproj", "{24DF1C65-2726-4E11-8F42-30ED2A1D0C8D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {24DF1C65-2726-4E11-8F42-30ED2A1D0C8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24DF1C65-2726-4E11-8F42-30ED2A1D0C8D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24DF1C65-2726-4E11-8F42-30ED2A1D0C8D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24DF1C65-2726-4E11-8F42-30ED2A1D0C8D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EF28D186-279B-4E91-9BE8-644B6E018432} + EndGlobalSection +EndGlobal diff --git a/BuildExtensions/Llvm.NET.BuildTasks/BuildVersionData.cs b/BuildExtensions/Llvm.NET.BuildTasks/BuildVersionData.cs new file mode 100644 index 000000000..90d643e38 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/BuildVersionData.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.IO; +using LibGit2Sharp; + +namespace Llvm.NET.BuildTasks +{ + internal enum BuildMode + { + LocalDev, + PullRequest, + ContinuousIntegration, + + // official release published publicly, may be a pre-release version but not a CI build + OfficialRelease + } + + public class BuildVersionData + { + public UInt16 BuildMajor { get; private set; } + + public UInt16 BuildMinor { get; private set; } + + public UInt16 BuildPatch { get; private set; } + + public string PreReleaseName { get; private set; } + + public byte PreReleaseNumber { get; private set; } + + public byte PreReleaseFix { get; private set; } + + public string ReleaseBranch { get; private set; } + + public IReadOnlyDictionary AdditionalProperties => ExtraPropertyMap; + + public string BuildVersionXmlFile { get; private set; } + + public CSemVer CreateSemVer( bool isAutomatedBuild, bool isPullRequestBuild, DateTime timeStamp ) + { + using( var repo = new LibGit2Sharp.Repository( Path.GetDirectoryName( BuildVersionXmlFile ) ) ) + { + Commit head = repo.Head.Tip; + + IPrereleaseVersion preReleaseInfo = null; + var buildMode = repo.GetBuildMode( isAutomatedBuild, isPullRequestBuild, ReleaseBranch ); + switch( buildMode ) + { + case BuildMode.LocalDev: + // local dev builds are always newer than any other builds + preReleaseInfo = new CIPreReleaseVersion( "DEV", GetBuildIndexFromUtc( timeStamp.ToUniversalTime() ), "zz" ); + break; + + case BuildMode.PullRequest: + // PR builds should have a higher precedence than CI or release so that the + // builds pull in the components built in previous stages of the current build + // instead of the official CI or released builds. + preReleaseInfo = new CIPreReleaseVersion( "PRQ", GetBuildIndexFromUtc( head.Author.When.UtcDateTime ), "pr" ); + break; + + case BuildMode.ContinuousIntegration: + preReleaseInfo = new CIPreReleaseVersion( "BLD", GetBuildIndexFromUtc(timeStamp.ToUniversalTime() ) ); + break; + + case BuildMode.OfficialRelease: + if( !string.IsNullOrWhiteSpace( PreReleaseName ) ) + { + preReleaseInfo = new OfficialPreRelease( PreReleaseName, PreReleaseNumber, PreReleaseFix ); + } + + break; + + default: + throw new InvalidOperationException( "Unexpected/Unsupported repository state" ); + } + + return new CSemVer( BuildMajor, BuildMinor, BuildPatch, preReleaseInfo, head.Id.Sha.Substring( 0, 8 ) ); + } + } + + public static BuildVersionData Load( string path ) + { + var retVal = new BuildVersionData( ); + using( var stream = File.OpenText( path ) ) + { + var xdoc = System.Xml.Linq.XDocument.Load( stream, System.Xml.Linq.LoadOptions.None ); + var data = xdoc.Element( "BuildVersionData" ); + + retVal.BuildVersionXmlFile = path; + + foreach( var attrib in data.Attributes() ) + { + switch( attrib.Name.LocalName ) + { + case "BuildMajor": + retVal.BuildMajor = Convert.ToUInt16( attrib.Value ); + break; + + case "BuildMinor": + retVal.BuildMinor = Convert.ToUInt16( attrib.Value ); + break; + + case "BuildPatch": + retVal.BuildPatch = Convert.ToUInt16( attrib.Value ); + break; + + case "ReleaseBranch": + retVal.ReleaseBranch = attrib.Value; + break; + + case "PreReleaseName": + retVal.PreReleaseName = attrib.Value; + break; + + case "PreReleaseNumber": + retVal.PreReleaseNumber = Convert.ToByte( attrib.Value ); + break; + + case "PreReleaseFix": + retVal.PreReleaseFix = Convert.ToByte( attrib.Value ); + break; + + default: + retVal.ExtraPropertyMap.Add( attrib.Name.LocalName, attrib.Value ); + break; + } + } + + // correct malformed values + if( string.IsNullOrWhiteSpace( retVal.PreReleaseName ) ) + { + retVal.PreReleaseNumber = 0; + retVal.PreReleaseFix = 0; + } + + if( retVal.PreReleaseNumber == 0 ) + { + retVal.PreReleaseFix = 0; + } + } + + return retVal; + } + + // For details on the general algorithm used for computing the numbers here see: + // https://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute(v=vs.140).aspx + // Only difference is this uses UTC as the basis to ensure the numbers consistently increase independent of locale. + private static string GetBuildIndexFromUtc( DateTime timeStamp ) + { + var midnightTodayUtc = new DateTime( timeStamp.Year, timeStamp.Month, timeStamp.Day, 0, 0, 0, DateTimeKind.Utc ); + var baseDate = new DateTime( 2000, 1, 1, 0, 0, 0, DateTimeKind.Utc ); + uint buildNumber = ( ( uint )( timeStamp - baseDate ).Days ) << 16; + buildNumber += ( ushort )( ( timeStamp - midnightTodayUtc ).TotalSeconds / 2 ); + return buildNumber.ToString( "X08" ); + } + + private Dictionary ExtraPropertyMap = new Dictionary(); + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/DownloadFile.cs b/BuildExtensions/Llvm.NET.BuildTasks/DownloadFile.cs new file mode 100644 index 000000000..5f4d12a25 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/DownloadFile.cs @@ -0,0 +1,23 @@ +using System.Net; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Llvm.NET.BuildTasks +{ + public class DownloadFile + : Task + { + [Required] + public string SourceUrl { get; set; } + + [Required] + public string DestinationPath { get; set; } + + public override bool Execute( ) + { + var client = new WebClient( ); + client.DownloadFile( SourceUrl, DestinationPath ); + return true; + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/GenerateSha256File.cs b/BuildExtensions/Llvm.NET.BuildTasks/GenerateSha256File.cs new file mode 100644 index 000000000..9c43bd04a --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/GenerateSha256File.cs @@ -0,0 +1,41 @@ +using System.IO; +using System.Security.Cryptography; +using System.Text; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Llvm.NET.BuildTasks +{ + public class GenerateSha256File + : Task + { + [Required] + public ITaskItem[ ] Files { get; set; } + + public override bool Execute( ) + { + using( var algo = SHA256.Create( ) ) + { + foreach( var item in Files ) + { + string fullPath = item.GetMetadata( "FullPath" ); + using( var stream = new FileStream( fullPath, FileMode.Open ) ) + { + var fileHash = algo.ComputeHash( stream ); + var bldr = new StringBuilder( ); + foreach( byte value in fileHash ) + { + bldr.AppendFormat( "{0:X02}", value ); + } + + string hashFileName = fullPath + ".sha256"; + File.WriteAllText( hashFileName, bldr.ToString( ) ); + Log.LogMessage( MessageImportance.High, "Generated: {0}", hashFileName ); + } + } + } + + return true; + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/GetRepositoryVersionInfo.cs b/BuildExtensions/Llvm.NET.BuildTasks/GetRepositoryVersionInfo.cs new file mode 100644 index 000000000..5ec95699b --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/GetRepositoryVersionInfo.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Llvm.NET.BuildTasks +{ + public class GetRepositoryVersionInfo + : Task + { + [Required] + public string BuildVersionXmlFile { get; set; } + + [Required] + public bool IsAutomatedBuild { get; set; } + + public bool IsPullRequestBuild { get; set; } + + public DateTime BuildTimeStamp { get; set; } = DateTime.UtcNow; + + [Output] + public string SemVer { get; set; } + + [Output] + public string NuGetVersion { get; set; } + + [Output] + public ushort FileVersionMajor { get; set; } + + [Output] + public ushort FileVersionMinor { get; set; } + + [Output] + public ushort FileVersionBuild { get; set; } + + [Output] + public ushort FileVersionRevision { get; set; } + + [Output] + public ITaskItem[] ExtraProperties { get; set; } + + public override bool Execute( ) + { + var baseBuildVersionData = BuildVersionData.Load( BuildVersionXmlFile ); + CSemVer fullVersion = baseBuildVersionData.CreateSemVer( IsAutomatedBuild, IsPullRequestBuild, BuildTimeStamp ); + + SemVer = fullVersion.ToString( true ); + NuGetVersion = fullVersion.ToString( false ); + FileVersionMajor = ( ushort )fullVersion.FileVersion.Major; + FileVersionMinor = ( ushort )fullVersion.FileVersion.Minor; + FileVersionBuild = ( ushort )fullVersion.FileVersion.Build; + FileVersionRevision = ( ushort )fullVersion.FileVersion.Revision; + + ExtraProperties = ( from kvp in baseBuildVersionData.AdditionalProperties + select new TaskItem( "ExtraProperties", new Dictionary { { "Name", kvp.Key }, { "Value", kvp.Value } } ) + ).ToArray( ); + + return true; + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Llvm.NET.BuildTasks.csproj b/BuildExtensions/Llvm.NET.BuildTasks/Llvm.NET.BuildTasks.csproj new file mode 100644 index 000000000..a4c9f68d2 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Llvm.NET.BuildTasks.csproj @@ -0,0 +1,89 @@ + + + + net47 + true + true + + true + tasks + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <__PackNone Include="@(None)" Condition="'%(None.CopyToOutputDirectory)' == 'PreserveNewest'" /> + + + + + + + + + + + diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Llvm.NET.BuildTasks.sln b/BuildExtensions/Llvm.NET.BuildTasks/Llvm.NET.BuildTasks.sln new file mode 100644 index 000000000..88e58cf1b --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Llvm.NET.BuildTasks.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llvm.NET.BuildTasks", "Llvm.NET.BuildTasks.csproj", "{DAC91FAD-ABD2-4F1F-900C-19110D68D9B9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DAC91FAD-ABD2-4F1F-900C-19110D68D9B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAC91FAD-ABD2-4F1F-900C-19110D68D9B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAC91FAD-ABD2-4F1F-900C-19110D68D9B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DAC91FAD-ABD2-4F1F-900C-19110D68D9B9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Properties/launchSettings.json b/BuildExtensions/Llvm.NET.BuildTasks/Properties/launchSettings.json new file mode 100644 index 000000000..a289571e9 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Llvm.NET.BuildTasks": { + "commandName": "Executable", + "executablePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Preview\\Community\\MSBuild\\15.0\\bin\\msbuild.exe", + "commandLineArgs": "/t:GetRepositoryInfo src\\LibLLVM\\LibLLVM.vcxproj", + "workingDirectory": "D:\\GitHub\\NETMF\\Llvm.NET" + } + } +} \ No newline at end of file diff --git a/BuildExtensions/Llvm.NET.BuildTasks/RepositoryExtensions.cs b/BuildExtensions/Llvm.NET.BuildTasks/RepositoryExtensions.cs new file mode 100644 index 000000000..df1cdb4ca --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/RepositoryExtensions.cs @@ -0,0 +1,28 @@ +using LibGit2Sharp; + +namespace Llvm.NET.BuildTasks +{ + internal static class RepositoryExtensions + { + internal static BuildMode GetBuildMode( this Repository repo, bool buildServer, bool pullRequest, string officialBranch) + { + RepositoryStatus repoStatus = repo.RetrieveStatus( ); + if( repoStatus.IsDirty || !buildServer ) + { + return BuildMode.LocalDev; + } + + if( pullRequest ) + { + return BuildMode.PullRequest; + } + + if( string.CompareOrdinal( repo.Head.FriendlyName, officialBranch ) == 0 ) + { + return BuildMode.OfficialRelease; + } + + return BuildMode.ContinuousIntegration; + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Validators.cs b/BuildExtensions/Llvm.NET.BuildTasks/Validators.cs new file mode 100644 index 000000000..af27f51c7 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Validators.cs @@ -0,0 +1,66 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using JetBrains.Annotations; + +namespace Llvm.NET.BuildTasks +{ + [SuppressMessage( "", "SA1402", Justification = "Closely related to the static validators" )] + [AttributeUsage( AttributeTargets.Parameter, Inherited = true, AllowMultiple = false )] + internal sealed class ValidatedNotNullAttribute + : Attribute + { + } + + internal static class Validators + { + [ContractAnnotation( "obj:null => halt" )] + public static void ValidateNotNull( [ValidatedNotNull] this object obj, [InvokerParameterName] string paramName ) + { + if( obj == null ) + { + throw new ArgumentNullException( paramName ); + } + } + + [ContractAnnotation( "str:null => halt" )] + public static void ValidateNotNullOrWhiteSpace( [ValidatedNotNull] this string str, [InvokerParameterName] string paramName ) + { + if( string.IsNullOrWhiteSpace( str ) ) + { + throw new ArgumentException( "Must not be null or whitespace", paramName ); + } + } + + public static void ValidateRange( this T i, T min, T max, [InvokerParameterName] string paramName ) + where T : struct, IComparable + { + if( min.CompareTo( i ) > 0 || i.CompareTo( max ) > 0 ) + { + throw new ArgumentOutOfRangeException( paramName, i, $"Accepted range: [{min}, {max}]" ); + } + } + + [ContractAnnotation( "value:null => halt" )] + public static void ValidatePattern( [ValidatedNotNull] this string value, [RegexPattern] string pattern, [InvokerParameterName] string paramName ) + { + value.ValidateNotNullOrWhiteSpace( nameof( value ) ); + pattern.ValidateNotNullOrWhiteSpace( nameof( pattern ) ); + var regEx = new System.Text.RegularExpressions.Regex( pattern ); + var match = regEx.Match( value ); + if( !match.Success ) + { + throw new ArgumentException( $"Value does not conform to required format: {pattern}", paramName ); + } + } + + [ContractAnnotation( "value:null => halt" )] + public static void ValidateLength( [ValidatedNotNull] this string value, int min, int max, [InvokerParameterName] string paramName ) + { + value.ValidateNotNull( paramName ); + if( value.Length < min || value.Length > max ) + { + throw new ArgumentException( $"Expected string with length in the range [{min}, {max}]", paramName ); + } + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CIPreReleaseVersion.cs b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CIPreReleaseVersion.cs new file mode 100644 index 000000000..0ccb2e6e0 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CIPreReleaseVersion.cs @@ -0,0 +1,57 @@ +using JetBrains.Annotations; + +namespace Llvm.NET.BuildTasks +{ + // CSemVer-CI style pre-release version with an extension + // to enable choosing the pre-release marker 'ci'. CSemVer-CI + // specifies a pre-release version in the form: + // '--ci-CIBuildName.CIBuildIndex' + // This class allows substituting alternate values for the + // 'ci' to enable additional scenarios. These are essentially + // a different namespace for regular builds that allows for + // local builds, PR Validation (auto buddy) builds, and official + // CI builds to have distinct versions with the local builds by + // choosing two letter markers with appropriate ASCII lexical + // sort ordering. (e.g. local built versions should have the + // highest precedence, then auto buddy builds, then CIbuilds, + // and official releases) + internal class CIPreReleaseVersion + : IPrereleaseVersion + { + public const string DefaultCIMarker = "ci"; + + public CIPreReleaseVersion( [NotNull] string buildName, [NotNull] string buildIndex ) + : this( buildName, buildIndex, DefaultCIMarker ) + { + } + + public CIPreReleaseVersion( [NotNull] string buildName, [NotNull] string buildIndex, [NotNull] string ciMarker ) + { + buildName.ValidatePattern( @"[a-zA-z0-9\-]+", nameof( buildName ) ); + buildIndex.ValidatePattern( @"[a-zA-z0-9\-]+", nameof( buildIndex ) ); + ciMarker.ValidatePattern( @"[a-z]{2}", nameof( ciMarker ) ); + + BuildName = buildName; + BuildIndex = buildIndex; + CIMarker = ciMarker; + } + + public string BuildName { get; } + + public string BuildIndex { get; } + + public string CIMarker { get; } + + public (int NameIndex, byte Number, byte Fix) Version => (NameIndex: -1, Number: 0, Fix: 0); + + public override string ToString( ) + { + return $"--{CIMarker}-{BuildName}.{BuildIndex}"; + } + + public string ToString( bool useFullPreRelNames ) + { + return ToString( ); + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CSemVer.cs b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CSemVer.cs new file mode 100644 index 000000000..3021dc7af --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CSemVer.cs @@ -0,0 +1,108 @@ +using System; +using JetBrains.Annotations; + +namespace Llvm.NET.BuildTasks +{ + public class CSemVer + { + public int Major { get; } + + public int Minor { get; } + + public int Patch { get; } + + [CanBeNull] + public IPrereleaseVersion PrereleaseVersion { get; } + + [CanBeNull] + public string BuildMetadata { get; } + + public CSemVer( int major, int minor , int patch, [CanBeNull] IPrereleaseVersion preRelVer = null, [CanBeNull] string buildmeta = null ) + { + major.ValidateRange( 0, 99999, nameof( major ) ); + minor.ValidateRange( 0, 49999, nameof( minor ) ); + patch.ValidateRange( 0, 9999, nameof( patch ) ); + if( buildmeta != null ) + { + buildmeta.ValidateLength( 0, 20, nameof( buildmeta ) ); + } + + Major = major; + Minor = minor; + Patch = patch; + PrereleaseVersion = preRelVer; + BuildMetadata = buildmeta; + } + + public override string ToString( ) + { + return ToString( false ); + } + + [NotNull] + public string ToString( bool fullName ) + { + var bldr = new System.Text.StringBuilder( ); + bldr.AppendFormat( "{0}.{1}.{2}", Major, Minor, Patch ); + + if( PrereleaseVersion != null ) + { + bldr.Append( PrereleaseVersion.ToString( fullName ) ); + } + + if( BuildMetadata != null ) + { + bldr.AppendFormat( "+{0}", BuildMetadata ); + } + + return bldr.ToString( ); + } + + [NotNull] + public Version FileVersion + { + get + { + ulong orderedNum = OrderedVersion << 1; + + ushort fileRevision = ( ushort )( orderedNum % 65536 ); + ulong rem = ( orderedNum - fileRevision ) / 65536; + + ushort fileBuild = ( ushort )( rem % 65536 ); + rem = ( rem - fileBuild ) / 65536; + + ushort fileMinor = ( ushort )( rem % 65536 ); + rem = ( rem - fileMinor ) / 65536; + + ushort fileMajor = ( ushort )( rem % 65536 ); + + return new Version( fileMajor, fileMinor, fileBuild, fileRevision ); + } + } + + public ulong OrderedVersion + { + get + { + ulong retVal = ( ( ulong )Major * MulMajor ) + ( ( ulong )Minor * MulMinor ) + ( ( ( ulong )Patch + 1 ) * MulPatch ); + + if( PrereleaseVersion != null && PrereleaseVersion.Version.NameIndex > 0 ) + { + var preRelVer = PrereleaseVersion.Version; + retVal -= MulPatch - 1; + retVal += ( ulong )preRelVer.NameIndex * MulName; + retVal += preRelVer.Number * MulNum; + retVal += preRelVer.Fix; + } + + return retVal; + } + } + + private const ulong MulNum = 100; + private const ulong MulName = MulNum* 100; + private const ulong MulPatch = (MulName * 8) + 1; + private const ulong MulMinor = MulPatch * 10000; + private const ulong MulMajor = MulMinor * 50000; + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CSemVerCI.cs b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CSemVerCI.cs new file mode 100644 index 000000000..082bb6b2f --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/CSemVerCI.cs @@ -0,0 +1,15 @@ +namespace Llvm.NET.BuildTasks +{ + internal class CSemVerCI : CSemVer + { + public CSemVerCI( CSemVer baseVer, string buildName, string buildIndex ) + : base( baseVer.Major, baseVer.Minor, baseVer.Patch, new CIPreReleaseVersion( buildName, buildIndex ), baseVer.BuildMetadata ) + { + } + + public CSemVerCI( CSemVer baseVer, string buildName, string buildIndex, string ciMarker ) + : base( baseVer.Major, baseVer.Minor, baseVer.Patch, new CIPreReleaseVersion( buildName, buildIndex, ciMarker ), baseVer.BuildMetadata ) + { + } + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Versioning/IPrereleaseVersion.cs b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/IPrereleaseVersion.cs new file mode 100644 index 000000000..58012fb5b --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/IPrereleaseVersion.cs @@ -0,0 +1,9 @@ +namespace Llvm.NET.BuildTasks +{ + public interface IPrereleaseVersion + { + (int NameIndex, byte Number, byte Fix) Version { get; } + + string ToString( bool useFullPrerelNames ); + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/Versioning/OfficialPreRelease.cs b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/OfficialPreRelease.cs new file mode 100644 index 000000000..49710c8b7 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/Versioning/OfficialPreRelease.cs @@ -0,0 +1,69 @@ +using System; +using System.Linq; +using System.Text; +using JetBrains.Annotations; + +namespace Llvm.NET.BuildTasks +{ + internal class OfficialPreRelease + : IPrereleaseVersion + { + public OfficialPreRelease( [NotNull] string preRelName, int preRelNumber = 0, int preRelFix = 0 ) + : this( GetPreReleaseIndex( preRelName, nameof( preRelName ) ), preRelNumber, preRelFix ) + { + } + + public OfficialPreRelease( int preRelNameIndex, int preRelNumber = 0, int preRelFix = 0 ) + { + preRelNameIndex.ValidateRange( 0, 7, nameof( preRelNameIndex ) ); + preRelNumber.ValidateRange( 0, 99, nameof( preRelNumber ) ); + preRelFix.ValidateRange( 0, 99, nameof( preRelFix ) ); + + Version = (NameIndex: preRelNameIndex, Number: (byte)preRelNumber, Fix: (byte)preRelFix); + } + + public int PreReleaseIndex { get; } + + public int PreReleaseNumber { get; } + + public int PreReleaseFix { get; } + + public string PreReleaseName => PreReleaseNames[ PreReleaseIndex ]; + + public (int NameIndex, byte Number, byte Fix) Version { get; } + + public override string ToString( ) + { + return ToString( false ); + } + + public string ToString( bool useFullPreRelNames ) + { + var bldr = new StringBuilder( "-" ); + bldr.Append( PreReleaseName ); + if( PreReleaseNumber > 0 ) + { + bldr.AppendFormat( ".{0}", PreReleaseNumber ); + if( PreReleaseFix > 0 ) + { + bldr.AppendFormat( ".{0}", PreReleaseFix ); + } + } + + return bldr.ToString( ); + } + + private static int GetPreReleaseIndex( [NotNull] string preRelName, [InvokerParameterNameAttribute] string paramName ) + { + preRelName.ValidateNotNullOrWhiteSpace( paramName ); + var q = from name in PreReleaseNames.Select( ( n, i ) => (Name: n, Index: i) ) + where 0 == string.Compare( name.Name, preRelName, StringComparison.OrdinalIgnoreCase ) + select name; + + var nameIndex = q.FirstOrDefault( ); + return nameIndex.Name == null ? -1 : nameIndex.Index; + } + + private static readonly string[] PreReleaseNames = { "alpha", "beta", "delta", "epsilon", "gamma", "kappa", "prerelease", "rc" }; + } +} diff --git a/BuildExtensions/Llvm.NET.BuildTasks/build/Llvm.NET.BuildTasks.props b/BuildExtensions/Llvm.NET.BuildTasks/build/Llvm.NET.BuildTasks.props new file mode 100644 index 000000000..666870942 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/build/Llvm.NET.BuildTasks.props @@ -0,0 +1,7 @@ + + + <_TaskFolder Condition="'$(MSBuildRunTimeType)'=='Core'">netstandard2.0 + <_TaskFolder Condition="'$(MSBuildRunTimeType)'!='Core'">net47 + $([MSBuild]::NormalizePath("$(MSBuildThisFileDirectory)", "..", "tasks", "$(_TaskFolder)", "Llvm.NET.BuildTasks.dll")) + + diff --git a/BuildExtensions/Llvm.NET.BuildTasks/build/Llvm.NET.BuildTasks.targets b/BuildExtensions/Llvm.NET.BuildTasks/build/Llvm.NET.BuildTasks.targets new file mode 100644 index 000000000..c8bc013aa --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/build/Llvm.NET.BuildTasks.targets @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(_FullBuildNumber) + $(_PackageVersion) + $(_FileVersionMajor) + $(_FileVersionMinor) + $(_FileVersionBuild) + $(_FileVersionRevision) + + + + + + + + + + $(LlvmVersionMajor).$(LlvmVersionMinor).$(LlvmVersionPatch) + $(FileVersionMajor).$(FileVersionMinor).$(FileVersionBuild).$(FileVersionRevision) + $(FileVersion) + $(FullBuildNumber) + version=$(PackageVersion);llvmversion=$(LlvmVersion);buildbinoutput=$(BaseOutputPath);configuration=$(Configuration);$(NuspecProperties) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BuildExtensions/Llvm.NET.BuildTasks/buildMultiTargeting/Llvm.NET.BuildTasks.props b/BuildExtensions/Llvm.NET.BuildTasks/buildMultiTargeting/Llvm.NET.BuildTasks.props new file mode 100644 index 000000000..ba5421cac --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/buildMultiTargeting/Llvm.NET.BuildTasks.props @@ -0,0 +1,13 @@ + + + <_ThisPackageRoot>$([MSBuild]::NormalizeDirectory("$(MSBuildThisFileDirectory)","..")) + + + + + diff --git a/BuildExtensions/Llvm.NET.BuildTasks/buildMultiTargeting/Llvm.NET.BuildTasks.targets b/BuildExtensions/Llvm.NET.BuildTasks/buildMultiTargeting/Llvm.NET.BuildTasks.targets new file mode 100644 index 000000000..d08dabff8 --- /dev/null +++ b/BuildExtensions/Llvm.NET.BuildTasks/buildMultiTargeting/Llvm.NET.BuildTasks.targets @@ -0,0 +1,14 @@ + + + <_ThisPackageRoot>$([MSBuild]::NormalizeDirectory("$(MSBuildThisFileDirectory)","..")) + + + + + + diff --git a/BuildExtensions/SolutionProj.Common.props b/BuildExtensions/SolutionProj.Common.props deleted file mode 100644 index 3207a8083..000000000 --- a/BuildExtensions/SolutionProj.Common.props +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - EnsureBuildNumbers; - CleanOutputFolders; - CreateOutputFolders; - NugetRestore; - BuildContentBinaries; - SignContent; - PackageContent; - SignPackage - - - - - - $(BaseBuildOutputPath)\Tools\nuget.exe - - - - - - x64;Win32 - Debug;Release - - - - - 14 - $(BuildOutputPackagesDir) - src\ - - - \ No newline at end of file diff --git a/BuildExtensions/SolutionProj.Common.targets b/BuildExtensions/SolutionProj.Common.targets deleted file mode 100644 index adab048d6..000000000 --- a/BuildExtensions/SolutionProj.Common.targets +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - - - - CreateBuildNumbers - - - - - _ParseFullBuildNumber - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_FilesToClean Include="$(BaseBuildOutputPath)\**\*" /> - - - <_FoldersToClean Include="@(_FilesToClean->'%(RootDir)%(Directory)')"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/BuildVersion.xml b/BuildVersion.xml new file mode 100644 index 000000000..7eccb1280 --- /dev/null +++ b/BuildVersion.xml @@ -0,0 +1,48 @@ + + diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 000000000..4e82a0001 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,84 @@ + + + + + + AnyCPU + Win32 + Win32 + $(Platform) + x86 + x86 + + Debug + + + $(MSBuildThisFileDirectory) + $([MSBuild]::EnsureTrailingSlash("$(BuildRootDir)")) + + + $([MSBuild]::NormalizeDirectory("$(BuildRootDir)", "BuildOutput")) + $([MSBuild]::EnsureTrailingSlash("$(BaseBuildOutputPath)")) + + $([MSBuild]::NormalizeDirectory("$(BaseBuildOutputPath)", "Intermediate", "$(MSBuildProjectName)")) + $([MSBuild]::NormalizeDirectory("$(BaseIntermediateOutputPath)", "$(UnifiedPlatformPathName)", "$(Configuration)")) + $([MSBuild]::NormalizeDirectory("$(BaseBuildOutputPath)","bin")) + $([MSBuild]::NormalizeDirectory("$(BaseBuildOutputPath)","NuGet")) + + $(BaseBuildOutputPath)packages\ + + $(MSBuildThisFileDirectory)BuildVersion.xml + true + false + + true + false + + + + + + $(MSBuildThisFileDirectory)Llvm.NET.ruleset + false + true + + + + + + + + + + + + + + + + + + $([MSBuild]::NormalizeDirectory("$(BaseOutputPath)", "$(Configuration)", "native", "$(UnifiedPlatformPathName)")) + $([MSBuild]::EnsureTrailingSlash("$(OutputPath)")) + $(OutputPath) + + + + diff --git a/LICENSE b/LICENSE index 909e92ceb..cd10d6977 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 NETMF +Copyright (c) 2015 .NET Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Llvm.NET.ruleset b/Llvm.NET.ruleset new file mode 100644 index 000000000..c88eb3ad4 --- /dev/null +++ b/Llvm.NET.ruleset @@ -0,0 +1,668 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 000000000..6b9705e70 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index b2399192c..b74f170c4 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,86 @@ ## Llvm.NET -![Build status](https://telliam.visualstudio.com/DefaultCollection/_apis/public/build/definitions/fb2ef014-95d6-4df2-a906-2b1187e8f36f/2/badge) + +Build Status: + +Branch | Status +-------|------- +dev | [![Build status](https://ci.appveyor.com/api/projects/status/0xh262rwvbardsrm/branch/dev?svg=true)](https://ci.appveyor.com/project/StevenMaillet/llvm-net/branch/dev) +LLVM_4_0_1 | [![Build status](https://ci.appveyor.com/api/projects/status/0xh262rwvbardsrm/branch/LLVM_4_0_1?svg=true)](https://ci.appveyor.com/project/StevenMaillet/llvm-net/branch/LLVM_4_0_1) +LLVM_5_0_0 | [![Build status](https://ci.appveyor.com/api/projects/status/0xh262rwvbardsrm/branch/LLVM_5_0_0?svg=true)](https://ci.appveyor.com/project/StevenMaillet/llvm-net/branch/LLVM_5_0_0) ### Welcome to Llvm.NET! -Llvm.NET provides LLVM language and runtime bindings for .NET based applications. Llvm.NET's goal is to provide as robust Class library that -accurately reflects the underlying LLVM C++ model. This is done through an extend LLVM-C API bundled as a native windows DLL (LibLLVM.DLL). Llvm.NET -uses the support of LibLLVM to gain access to the LLVM class library and project it into a .NET managed library that reflects the original class library +Llvm.NET provides LLVM language and runtime bindings for .NET based applications. Llvm.NET's goal is to provide +as robust Class library thataccurately reflects the underlying LLVM C++ model. This is done through an extend +LLVM-C API bundled as a native windows DLL (LibLLVM.DLL). Llvm.NET uses the support of LibLLVM to gain access +to the LLVM class library and project it into a .NET managed library that reflects the original class library design. -The goal is to match the original class model as closely as possible, while providing an object model to .NET applications that feels familiar and consistent -with common styles and patterns in .NET Framework applications. Thus, while class, method and enumeration names are similar to their counterparts in LLVM, they -are not always identical. +The goal is to match the original class model as closely as possible, while providing an object model to .NET +applications that feels familiar and consistent with common styles and patterns in .NET Framework applications. +Thus, while class, method and enumeration names are similar to their counterparts in LLVM, they are not always +identical. -Documentation for the Llvm.NET class library is located at [http://netmf.github.io/Llvm.NET](http://netmf.github.io/Llvm.NET) +### Documentation +Documentation for using the Llvm.NET class library is located at [http://netmf.github.io/Llvm.NET](http://netmf.github.io/Llvm.NET) ### Why Llvm.NET? -Llvm.NET was developed as a means to leverage LLVM as the back-end for an Ahead-Of-Time (AOT) compilation tool for .NET applications targeting micro controllers -(e.g. An AOT compiler for the [.NET Micro Framework](http://www.netmf.com) ). The initial proof of concept built on Llvm.NET was successful in delivering on a -basic application that could implement the micro controller equivalent of the classic "Hello World!" application (e.g. Blinky - an app that blinks an LED) using -LLVM as the back-end code generator. This led to the revival of a former project doing AOT with its own code generator that was tied to the ARMv4 Instruction set. -Thus the [Llilum](https://www.github.com/netmf/Llilum) project was born. Llvm.NET has continued to evolve and improve along with Llilum, though it remains a distinct -project as it has no dependencies on Llilum or any of its components. Llvm.NET is viable for any .NET applications wishing to leverage the functionality of the LLVM -libraries from .NET applications. +Llvm.NET was initially developed as a means to leverage LLVM as the back-end for an Ahead-Of-Time (AOT) compilation +tool for .NET applications targeting micro controllers (e.g. An AOT compiler for the [.NET Micro Framework](http://www.netmf.com) ). +The initial proof of concept built on Llvm.NET was successful in delivering on a basic application that could +implement the micro controller equivalent of the classic "Hello World!" application (e.g. Blinky - an app that +blinks an LED) using LLVM as the back-end code generator. This led to the revival of a former project doing AOT +with its own code generator that was tied to the ARMv4 Instruction set. ([Llilum](https://www.github.com/netmf/Llilum)). +Llvm.NET has continued to evolve and improve and remains a distinct project as it has no dependencies on Llilum +or any of its components. Llvm.NET is viable for any .NET applications wishing to leverage the functionality of +the LLVM libraries from .NET applications. ### Brief History -Llvm.NET began with LLVM 3.4 as a C++/CLI wrapper which enabled a closer binding to the original C++ object model then the official LLVM-C API supported. -As Llvm.NET progressed so to did LLVM. Eventually the LLVM code base migrated to requiring C++11 support in the language to build. This became an issue for -the C++/CLI wrapper as the Microsoft C++/CLI compiler didn't support the C++11 syntax. Thus a change was made to Llvm.NET to move to an extended C API with -a C# adapter layer to provide the full experience .NET developers expect. While the transition was a tedious one very little application code required changes. +Llvm.NET began with LLVM 3.4 as a C++/CLI wrapper which enabled a closer binding to the original C++ object model +then the official LLVM-C API supported. As Llvm.NET progressed so to did LLVM. Eventually the LLVM code base +migrated to requiring C++11 support in the language to build. This became an issue for the C++/CLI wrapper as the +Microsoft C++/CLI compiler didn't support the C++11 syntax. Thus a change was made to Llvm.NET to move to an extended +C API with a C# adapter layer to provide the full experience .NET developers expect. While the transition was a +tedious one very little application code required changes. ### Platform Support -Currently LLVM.NET supports Win32 and x64 buids targeting the full desktop framework v4.5. To keep life simpler the nuget package contains both native platform -binaries and Llvm.NET itself is built for the "AnyCPU" platform. Llvm.NET contains code to dynamically detect the platform it is running on and load the appropriate -DLL. This allows applications to build for AnyCPU without creating multiple build configurations and release vehicles for applications. However, if your application -has other needs that require a specific platform target, then LlVM.NET can still function. +Currently LLVM.NET supports Win32 and x64 buids targeting the full desktop framework v4.7, though it is intended +to support .NET Standard 2.0 so that more platforms are possible in the future. To keep life simpler the Llvm.NET +nuget package is built for the "AnyCPU" platform and references the LibLLVM.NET package to bring in the native +binary support. Llvm.NET contains code to dynamically detect the platform it is running on and load the appropriate +DLL. This allows applications to build for AnyCPU without creating multiple build configurations and release vehicles +for applications. ### Building Llvm.NET #### Pre-requsites -* Download [LLVM source for 3.9.1 ](http://llvm.org/releases/3.9.1/llvm-3.9.1.src.tar.xz) (At this time LLVM is 3.9.1 ) +* Download LLVM [4.0.1](http://releases.llvm.org/4.0.1/llvm-4.0.1.src.tar.xz) * You will need a tool to extract files from that archive format. On Windows the recommended tool is [7zip](http://7-zip.org/) * Build of LLVM libraries -To Build the LLVM libraries you can use the [Build-LlvmWithVS](https://github.com/NETMF/Llvm.NET/blob/dev/src/LibLLVM/Build-LlvmWithVS.ps1) PowerShell script provided. -For more information on using the script open a PowerShell command prompt in the Llvm.NET source directory and run `PS> Get-Help .\Build-LlvmWithVs.ps1`. +To Build the LLVM libraries you can use the [Build-LlvmWithVS](https://github.com/NETMF/Llvm.NET/tree/LLVM_4_0_1/src/NugetPkg/LLVM) +PowerShell script provided. For more information on using the script open a PowerShell command prompt in the Llvm.NET +source directory and run `PS> Get-Help .\Build-LlvmWithVs.ps1`. -_NOTE: On a typical developer machines the LLVM library build takes approximately 1.5 hours so letting it run overnight or when you are otherwise away from your computer -is usually a good idea. Fortunately this only needs to be done once for a given release of LLVM._ +_NOTE: On a typical developer machines the LLVM library build takes approximately 1.5 hours so letting it run overnight +or when you are otherwise away from your computer is usually a good idea. Fortunately this only needs to be done once +for a given release of LLVM._ -If you have -Visual Studio 2017 RC (or RTM when available) with the [Visual C++ Tools for CMake](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/), -you can build the LLVM libs in VS. However, the default behavior is to build everything, which can take upwards of 6 hours on most typical machines. Instead of doing a -full build you can use the [Build-LlvmWithVS](https://github.com/NETMF/Llvm.NET/blob/dev/src/LibLLVM/Build-LlvmWithVS.ps1) PowerShell script with the `-CreateSettingsJson` -to create the [CMakeSettings.json](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/#configure-cmake) file that VS will use to configure -VS to reduce what is built to just the libraries needed for Llvm.NET. +If you have Visual Studio 2017 RC (or RTM when available) with the [Visual C++ Tools for CMake](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/), +you can build the LLVM libs in VS. However, the default behavior is to build everything, which can take upwards of 6 +hours on most typical machines. Instead of doing a full build you can use the [Build-LlvmWithVS](https://github.com/NETMF/Llvm.NET/blob/dev/src/LibLLVM/Build-LlvmWithVS.ps1) +PowerShell script with the `-CreateSettingsJson` to create the [CMakeSettings.json](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/#configure-cmake) +file that VS will use to configure VS to reduce what is built to just the libraries needed for Llvm.NET. #### Using Visual Studio -The repository contains a Visual Studio solution file that allows building Llvm.NET and LibLLVM for a single platform configuration, as well as running the available -unit tests. This is the primary mode of working with the Llvm.NET source code duing development. +The repository contains a Visual Studio solution files that allow building the components individually for modifying +Llvm.NET and LibLLVM, as well as running the available unit tests. This is the primary mode of working with the +Llvm.NET source code duing development. #### Replicating the automated build -The Automated build support for Llvm.NET uses BuildAll.slnproj to build all the binaries, sign them [signing not yet supported], and generate a nuget package. To build -the full package simply run `msbuild BuildAll.slnproj` +The Automated build support for Llvm.NET uses BuildAll.ps1 powershell script to build all the binaries, sign them +[SHA256 hash only at present], and generate a nuget package. To build the full package simply run `BuildAll.ps1` +from a powershell command prompt with msbuild tools on the system search path. #### Sample Application -The [TestDebugInfo](https://github.com/NETMF/Llvm.NET/tree/dev/src/Llvm.NETTests/TestDebugInfo) sample application provides an example of using Llvm.NET to generate -LLVM Bit code equivalent to what the Clang compiler generates for a [simple C language file](https://github.com/NETMF/Llvm.NET/blob/dev/src/Llvm.NETTests/TestDebugInfo/test.c). +The [CodeGenWithDebugInfo](https://github.com/NETMF/Llvm.NET/tree/LLVM_4_0_1/Samples/CodeGenWithDebugInfo) sample application provides an example of using Llvm.NET to generate +LLVM Bit code equivalent to what the Clang compiler generates for a [simple C language file](https://github.com/NETMF/Llvm.NET/tree/LLVM_4_0_1/Samples/CodeGenWithDebugInfo/Support%20Files/test.c). TestDebugInfo doesn't actually parse the source, instead it is a manually constructed and documented example of how to use Llvm.NET to accomplish the bit-code generation. #### Code of Conduct diff --git a/Samples/CodeGenWithDebugInfo/CodeGenWithDebugInfo.csproj b/Samples/CodeGenWithDebugInfo/CodeGenWithDebugInfo.csproj new file mode 100644 index 000000000..2fa9b2619 --- /dev/null +++ b/Samples/CodeGenWithDebugInfo/CodeGenWithDebugInfo.csproj @@ -0,0 +1,41 @@ + + + + 0.0.1.0 + net47;netstandard2.0 + false + exe + exe + false + bin\$(Configuration)\$(TargetFramework)\$(Platform) + + + + + + + + + + + + + + + + + Never + + + Never + + + + + + diff --git a/src/Llvm.NETTests/TestDebugInfo/CortexM3Details.cs b/Samples/CodeGenWithDebugInfo/CortexM3Details.cs similarity index 58% rename from src/Llvm.NETTests/TestDebugInfo/CortexM3Details.cs rename to Samples/CodeGenWithDebugInfo/CortexM3Details.cs index 1cb5f026d..138ddc5f8 100644 --- a/src/Llvm.NETTests/TestDebugInfo/CortexM3Details.cs +++ b/Samples/CodeGenWithDebugInfo/CortexM3Details.cs @@ -1,16 +1,20 @@ using System; +using System.Collections.Generic; using Llvm.NET; using Llvm.NET.Types; using Llvm.NET.Values; namespace TestDebugInfo { - class CortexM3Details + internal class CortexM3Details : ITargetDependentDetails { public string Cpu => "cortex-m3"; + public string Features => "+hwdiv,+strict-align"; + public string ShortName => "M3"; + public string Triple => "thumbv7m-none--eabi"; public void AddABIAttributesForByValueStructure( Function function, int paramIndex ) @@ -24,15 +28,16 @@ public void AddABIAttributesForByValueStructure( Function function, int paramInd // it, for Cortex-Mx it seems to use it only for larger structs, otherwise it uses an [ n x i32]. (Max // value of n is not known) and performs casts. Thus, on cortex-m the function parameters are handled // quite differently by clang, which seems odd to put such target dependent differences into the front-end. - var argType = function.Parameters[ paramIndex ].NativeType as IPointerType; if( argType == null || !argType.ElementType.IsStruct ) + { throw new ArgumentException( "Signature for specified parameter must be a pointer to a structure" ); + } var layout = function.ParentModule.Layout; function.AddAttributes( FunctionAttributeIndex.Parameter0 + paramIndex - , AttributeKind.ByVal.ToAttributeValue( function.Context ) - , new AttributeValue( function.Context, AttributeKind.Alignment, layout.AbiAlignmentOf( argType.ElementType ) ) + , function.Context.CreateAttribute( AttributeKind.ByVal ) + , function.Context.CreateAttribute( AttributeKind.Alignment, layout.AbiAlignmentOf( argType.ElementType ) ) ); } @@ -43,22 +48,24 @@ public void AddModuleFlags( NativeModule module ) module.AddModuleFlag( ModuleFlagBehavior.Error, "min_enum_size", 4 ); } - public AttributeSet BuildTargetDependentFunctionAttributes( Context ctx ) - { - var bldr = new AttributeBuilder( ); - - bldr.Add( "disable-tail-calls", "false" ); - bldr.Add( "less-precise-fpmad", "false" ); - bldr.Add( "no-frame-pointer-elim", "true" ); - bldr.Add( "no-frame-pointer-elim-non-leaf" ); - bldr.Add( "no-infs-fp-math", "false" ); - bldr.Add( "no-nans-fp-math", "false" ); - bldr.Add( "stack-protector-buffer-size", "8" ); - bldr.Add( "target-cpu", Cpu ); - bldr.Add( "target-features", Features ); - bldr.Add( "unsafe-fp-math", "false" ); - bldr.Add( "use-soft-float", "false" ); - return bldr.ToAttributeSet( FunctionAttributeIndex.Function, ctx ); - } + public IEnumerable BuildTargetDependentFunctionAttributes( Context ctx ) + => new AttributeValue[] + { + ctx.CreateAttribute( "correctly-rounded-divide-sqrt-fp-math", "false" ), + ctx.CreateAttribute( "disable-tail-calls", "false" ), + ctx.CreateAttribute( "less-precise-fpmad", "false" ), + ctx.CreateAttribute( "no-frame-pointer-elim", "true" ), + ctx.CreateAttribute( "no-frame-pointer-elim-non-leaf" ), + ctx.CreateAttribute( "no-infs-fp-math", "false" ), + ctx.CreateAttribute( "no-jump-tables", "false" ), + ctx.CreateAttribute( "no-nans-fp-math", "false" ), + ctx.CreateAttribute( "no-signed-zeros-fp-math", "false" ), + ctx.CreateAttribute( "no-trapping-math", "false" ), + ctx.CreateAttribute( "stack-protector-buffer-size", "8" ), + ctx.CreateAttribute( "target-cpu", Cpu ), + ctx.CreateAttribute( "target-features", Features ), + ctx.CreateAttribute( "unsafe-fp-math", "false" ), + ctx.CreateAttribute( "use-soft-float", "false" ) + }; } -} \ No newline at end of file +} diff --git a/src/Llvm.NETTests/TestDebugInfo/Program.cs b/Samples/CodeGenWithDebugInfo/Program.cs similarity index 88% rename from src/Llvm.NETTests/TestDebugInfo/Program.cs rename to Samples/CodeGenWithDebugInfo/Program.cs index cc29ef260..b178a567b 100644 --- a/src/Llvm.NETTests/TestDebugInfo/Program.cs +++ b/Samples/CodeGenWithDebugInfo/Program.cs @@ -1,40 +1,35 @@ -using Llvm.NET; +using System; +using System.Collections.Generic; +using System.IO; +using Llvm.NET; using Llvm.NET.DebugInfo; using Llvm.NET.Instructions; using Llvm.NET.Types; using Llvm.NET.Values; -using System; -using System.IO; namespace TestDebugInfo { /// Program to test/demonstrate Aspects of debug information generation with Llvm.NET - class Program + public static class Program { - static ITargetDependentDetails TargetDetails; - - static AttributeSet TargetDependentAttributes { get; set; } - - // obviously this is not clang but using an identical name helps in diff with actual clang output - const string VersionIdentString = "clang version 3.8.0 (branches/release_38)"; - /// Creates a test LLVM module with debug information /// ignored /// /// /// - static void Main( string[ ] args ) + public static void Main( string[ ] args ) { TargetDetails = new CortexM3Details(); - var srcPath = args[ 0 ]; + string srcPath = args[ 0 ]; if( !File.Exists( srcPath ) ) { Console.Error.WriteLine( "Src file not found: '{0}'", srcPath ); return; } + srcPath = Path.GetFullPath( srcPath ); - var moduleName = $"test_{TargetDetails.ShortName}.bc"; + string moduleName = $"test_{TargetDetails.ShortName}.bc"; StaticState.RegisterAll( ); var target = Target.FromTriple( TargetDetails.Triple ); @@ -54,7 +49,7 @@ static void Main( string[ ] args ) , Path.GetDirectoryName( srcPath ) , VersionIdentString , false - , "" + , string.Empty , 0 ); var diFile = module.DIBuilder.CreateFile( srcPath ); @@ -65,18 +60,15 @@ static void Main( string[ ] args ) var voidType = DebugType.Create( module.Context.VoidType, ( DIType )null ); var i32Array_0_32 = i32.CreateArrayType( module, 0, 32 ); - // create the LLVM structure type and body - // The full body is used with targetMachine.TargetData to determine size, alignment and element offsets - // in a target independent manner. - var fooType = new DebugStructType( module, "struct.foo", cu, "foo" ); - - // Create concrete debug type with full debug information + // create the LLVM structure type and body with full debug information +#pragma warning disable SA1500 // "Warning SA1500 Braces for multi - line statements must not share line" (simple table format) var fooBody = new[ ] { new DebugMemberInfo { File = diFile, Line = 3, Name = "a", DebugType = i32, Index = 0 } , new DebugMemberInfo { File = diFile, Line = 4, Name = "b", DebugType = f32, Index = 1 } , new DebugMemberInfo { File = diFile, Line = 5, Name = "c", DebugType = i32Array_0_32, Index = 2 } }; - fooType.SetBody( false, module, cu, diFile, 1, 0, fooBody ); +#pragma warning restore + var fooType = new DebugStructType( module, "struct.foo", cu, "foo", diFile, 1, DebugInfoFlags.None, fooBody ); // add global variables and constants var constArray = ConstantArray.From( i32, 32, module.Context.CreateConstant( 3 ), module.Context.CreateConstant( 4 ) ); @@ -88,15 +80,15 @@ static void Main( string[ ] args ) var bar = module.AddGlobal( fooType, false, 0, barValue, "bar" ); bar.Alignment = targetData.AbiAlignmentOf( fooType ); - module.DIBuilder.CreateGlobalVariable( cu, "bar", string.Empty, diFile, 8, fooType.DIType, false, bar ); + bar.AddDebugInfo( module.DIBuilder.CreateGlobalVariableExpression( cu, "bar", string.Empty, diFile, 8, fooType.DIType, false, null ) ); var baz = module.AddGlobal( fooType, false, Linkage.Common, Constant.NullValueFor( fooType ), "baz" ); baz.Alignment = targetData.AbiAlignmentOf( fooType ); - module.DIBuilder.CreateGlobalVariable( cu, "baz", string.Empty, diFile, 9, fooType.DIType, false, baz ); + baz.AddDebugInfo( module.DIBuilder.CreateGlobalVariableExpression( cu, "baz", string.Empty, diFile, 9, fooType.DIType, false, null ) ); // add module flags and compiler identifiers... // this can technically occur at any point, though placing it here makes - // comparing against clang generated files possible + // comparing against clang generated files easier AddModuleFlags( module ); // create types for function args @@ -120,15 +112,15 @@ static void Main( string[ ] args ) module.DIBuilder.Finish( ); // verify the module is still good and print any errors found - string msg; - if( !module.Verify( out msg ) ) + if( !module.Verify( out string msg ) ) { Console.Error.WriteLine( "ERROR: {0}", msg ); } else { - //test optimization works,but don't save it as that makes it harder to do a diff with official clang builds - {// force a GC to verify callback delegate for diagnostics is still valid + // test optimization works, but don't save it as that makes it harder to do a diff with official clang builds + {// force a GC to verify callback delegate for diagnostics is still valid, this is for test only and wouldn't + // normally be done in production code. GC.Collect( GC.MaxGeneration ); StaticState.ParseCommandLineOptions( new string[ ] { "TestDebugInfo.exe", "-O3" }, "Test Application" ); var modForOpt = module.Clone( ); @@ -159,7 +151,7 @@ private static Function DeclareDoCopyFunc( NativeModule module, DIFile diFile, I , scopeLine: 24 , debugFlags: DebugInfoFlags.None , isOptimized: false - ).AddAttributes( AttributeKind.NoUnwind ) + ).AddAttributes( FunctionAttributeIndex.Function, AttributeKind.NoInline, AttributeKind.NoUnwind ) .AddAttributes( FunctionAttributeIndex.Function, TargetDependentAttributes ); return doCopyFunc; } @@ -171,7 +163,7 @@ private static Function DeclareCopyFunc( NativeModule module , DebugPointerType fooPtr ) { - // Since the first parameter is passed by value + // Since the first parameter is passed by value // using the pointer + alloca + memcopy pattern, the actual // source, and therefore debug, signature is NOT a pointer. // However, that usage would create a signature with two @@ -197,7 +189,7 @@ private static Function DeclareCopyFunc( NativeModule module , debugFlags: DebugInfoFlags.Prototyped , isOptimized: false ).Linkage( Linkage.Internal ) // static function - .AddAttributes( AttributeKind.NoUnwind, AttributeKind.InlineHint ) + .AddAttributes( FunctionAttributeIndex.Function, AttributeKind.NoUnwind, AttributeKind.NoInline ) .AddAttributes( FunctionAttributeIndex.Function, TargetDependentAttributes ); TargetDetails.AddABIAttributesForByValueStructure( copyFunc, 0 ); @@ -237,7 +229,7 @@ private static void CreateCopyFunctionBody( NativeModule module var paramSrc = diBuilder.CreateArgument( copyFunc.DISubProgram, "src", diFile, 11, constFooType, false, 0, 1 ); var paramDst = diBuilder.CreateArgument( copyFunc.DISubProgram, "pDst", diFile, 12, fooPtr.DIType, false, 0, 2 ); - var ptrAlign = layout.CallFrameAlignmentOf( fooPtr ); + uint ptrAlign = layout.CallFrameAlignmentOf( fooPtr ); // create Locals // NOTE: There's no debug location attached to these instructions. @@ -246,7 +238,7 @@ private static void CreateCopyFunctionBody( NativeModule module .RegisterName( "pDst.addr" ) .Alignment( ptrAlign ); - var param0ByVal = copyFunc.Attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ); + bool param0ByVal = copyFunc.Attributes[ FunctionAttributeIndex.Parameter0 ].Contains( AttributeKind.ByVal ); if( param0ByVal ) { diBuilder.InsertDeclare( copyFunc.Parameters[ 0 ] @@ -255,6 +247,7 @@ private static void CreateCopyFunctionBody( NativeModule module , blk ); } + instBuilder.Store( copyFunc.Parameters[ 1 ], dstAddr ) .Alignment( ptrAlign ); @@ -283,7 +276,7 @@ private static void CreateCopyFunctionBody( NativeModule module var srcPtr = instBuilder.BitCast( copyFunc.Parameters[ 0 ], module.Context.Int8Type.CreatePointerType( ) ) .SetDebugLocation( 15, 13, copyFunc.DISubProgram ); - var pointerSize = layout.IntPtrType( ).IntegerBitWidth; + uint pointerSize = layout.IntPtrType( ).IntegerBitWidth; instBuilder.MemCpy( module , dstPtr , srcPtr @@ -313,7 +306,7 @@ private static void CreateDoCopyFunctionBody( NativeModule module // create instruction builder to build the body var instBuilder = new InstructionBuilder( blk ); - var param0ByVal = copyFunc.Attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ); + bool param0ByVal = copyFunc.Attributes[ FunctionAttributeIndex.Parameter0 ].Contains( AttributeKind.ByVal ); if( !param0ByVal ) { // create a temp local copy of the global structure @@ -342,10 +335,18 @@ private static void CreateDoCopyFunctionBody( NativeModule module { instBuilder.Call( copyFunc, bar, baz ) .SetDebugLocation( 25, 5, doCopyFunc.DISubProgram ) - .AddAttributes( FunctionAttributeIndex.Parameter0, copyFunc.Attributes.ParameterAttributes( 0 ) ); + .AddAttributes( FunctionAttributeIndex.Parameter0, copyFunc.Parameters[0].Attributes ); } + instBuilder.Return( ) .SetDebugLocation( 26, 1, doCopyFunc.DISubProgram ); } + + // obviously this is not clang but using an identical name helps in diff with actual clang output + private const string VersionIdentString = "clang version 4.0.1 (tags/RELEASE_401/final)"; + + private static ITargetDependentDetails TargetDetails; + + private static IEnumerable TargetDependentAttributes { get; set; } } } diff --git a/Samples/CodeGenWithDebugInfo/Properties/AssemblyInfo.cs b/Samples/CodeGenWithDebugInfo/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..ca75f856d --- /dev/null +++ b/Samples/CodeGenWithDebugInfo/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +using System.Runtime.InteropServices; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible( false )] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid( "f9914a60-2e4b-472f-b1f3-bd08fd23ca92" )] diff --git a/src/Llvm.NETTests/TestDebugInfo/ClangCompile.cmd b/Samples/CodeGenWithDebugInfo/Support Files/ClangCompile.cmd similarity index 52% rename from src/Llvm.NETTests/TestDebugInfo/ClangCompile.cmd rename to Samples/CodeGenWithDebugInfo/Support Files/ClangCompile.cmd index 0b50f7286..7f6380c3a 100644 --- a/src/Llvm.NETTests/TestDebugInfo/ClangCompile.cmd +++ b/Samples/CodeGenWithDebugInfo/Support Files/ClangCompile.cmd @@ -6,23 +6,11 @@ Call :GenerateCode x86_64-pc-windows-msvc18.0.0 test.c test_x86 @REM -- Generate bitcode for Cortex-M3 from test.c Call :GenerateCode thumbv7m-none-eabi test.c test_M3 -@REM -- Generate bitcode for x86 from test2.cpp -Call :GenerateCode x86_64-pc-windows-msvc18.0.0 test2.cpp test2_x86 - -@REM -- Generate bitcode for Cortex-M3 from test2.cpp -Call :GenerateCode thumbv7m-none-eabi test2.cpp test2_M3 - -@REM -- Generate bitcode for Cortex-M3 from TestInline.cpp -Call :GenerateCode thumbv7m-none-eabi TestInline.cpp TestInline_M3 - -@REM -- Generate bitcode for Cortex-M3 from TestEx.cpp -Call :GenerateCode thumbv7m-none-eabi TestEx.cpp TestEx_M3 - goto :EOF -@REM - %1 = Triple (i.e. x86_64-pc-windows-msvc18.0.0,thumbv7m-none-eabi) +@REM - %1 = Triple (i.e. x86_64-pc-windows-msvc18.0.0,thumbv7m-none-eabi) @REM - %2 = Source File (C/C++) -@REM - %3 = Output files base name +@REM - %3 = Output files base name :GenerateCode @echo Compiling '%2' for %1 clang -c -g -emit-llvm --target=%1 %2 diff --git a/src/Llvm.NETTests/TestDebugInfo/test.c b/Samples/CodeGenWithDebugInfo/Support Files/test.c similarity index 97% rename from src/Llvm.NETTests/TestDebugInfo/test.c rename to Samples/CodeGenWithDebugInfo/Support Files/test.c index 93e753a7c..e3fac2ac2 100644 --- a/src/Llvm.NETTests/TestDebugInfo/test.c +++ b/Samples/CodeGenWithDebugInfo/Support Files/test.c @@ -8,7 +8,7 @@ struct foo bar = { 1, 2.0, { 3, 4 } }; struct foo baz; -inline static void copy( struct foo const src // function line here +inline static void copy( struct foo const src // function line here , struct foo* pDst ) { // function's ScopeLine here diff --git a/src/Llvm.NETTests/TestDebugInfo/TargetDependentDetails.cs b/Samples/CodeGenWithDebugInfo/TargetDependentDetails.cs similarity index 62% rename from src/Llvm.NETTests/TestDebugInfo/TargetDependentDetails.cs rename to Samples/CodeGenWithDebugInfo/TargetDependentDetails.cs index 83d166467..9f94dca90 100644 --- a/src/Llvm.NETTests/TestDebugInfo/TargetDependentDetails.cs +++ b/Samples/CodeGenWithDebugInfo/TargetDependentDetails.cs @@ -1,16 +1,23 @@ -using Llvm.NET; +using System.Collections.Generic; +using Llvm.NET; using Llvm.NET.Values; namespace TestDebugInfo { - interface ITargetDependentDetails + internal interface ITargetDependentDetails { string ShortName { get; } + string Triple { get; } + string Cpu { get; } + string Features { get; } - AttributeSet BuildTargetDependentFunctionAttributes( Context ctx ); + + IEnumerable BuildTargetDependentFunctionAttributes( Context ctx ); + void AddABIAttributesForByValueStructure( Function function, int paramIndex ); + void AddModuleFlags( NativeModule module ); } } diff --git a/Samples/CodeGenWithDebugInfo/X64Details.cs b/Samples/CodeGenWithDebugInfo/X64Details.cs new file mode 100644 index 000000000..c289d483c --- /dev/null +++ b/Samples/CodeGenWithDebugInfo/X64Details.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using Llvm.NET; +using Llvm.NET.Types; +using Llvm.NET.Values; + +namespace TestDebugInfo +{ + internal class X64Details + : ITargetDependentDetails + { + public string Cpu => "x86-64"; + + public string Features => "+sse,+sse2"; + + public string ShortName => "x86"; + + public string Triple => "x86_64-pc-windows-msvc18.0.0"; + + public void AddABIAttributesForByValueStructure( Function function, int paramIndex ) + { + var argType = function.Parameters[ paramIndex ].NativeType as IPointerType; + if( argType == null || !argType.ElementType.IsStruct ) + { + throw new ArgumentException( "Signature for specified parameter must be a pointer to a structure" ); + } + } + + public void AddModuleFlags( NativeModule module ) + { + module.AddModuleFlag( ModuleFlagBehavior.Error, "PIC Level", 2 ); + } + + public IEnumerable BuildTargetDependentFunctionAttributes( Context ctx ) + => new List + { + ctx.CreateAttribute("disable-tail-calls", "false" ), + ctx.CreateAttribute( "less-precise-fpmad", "false" ), + ctx.CreateAttribute( "no-frame-pointer-elim", "false" ), + ctx.CreateAttribute( "no-infs-fp-math", "false" ), + ctx.CreateAttribute( "no-nans-fp-math", "false" ), + ctx.CreateAttribute( "stack-protector-buffer-size", "8" ), + ctx.CreateAttribute( "target-cpu", Cpu ), + ctx.CreateAttribute( "target-features", Features ), + ctx.CreateAttribute( "unsafe-fp-math", "false" ), + ctx.CreateAttribute( "use-soft-float", "false" ), + ctx.CreateAttribute( AttributeKind.UWTable ), + }; + } +} diff --git a/src/Llvm.NETTests/TestDebugInfo/app.config b/Samples/CodeGenWithDebugInfo/app.config similarity index 73% rename from src/Llvm.NETTests/TestDebugInfo/app.config rename to Samples/CodeGenWithDebugInfo/app.config index e6ca62e77..245587d76 100644 --- a/src/Llvm.NETTests/TestDebugInfo/app.config +++ b/Samples/CodeGenWithDebugInfo/app.config @@ -1,3 +1,3 @@ - - - + + + diff --git a/Samples/Samples.sln b/Samples/Samples.sln new file mode 100644 index 000000000..5ec49416f --- /dev/null +++ b/Samples/Samples.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGenWithDebugInfo", "CodeGenWithDebugInfo\CodeGenWithDebugInfo.csproj", "{127F92E3-A556-4E10-9FE6-D1AB863A63B5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {127F92E3-A556-4E10-9FE6-D1AB863A63B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {127F92E3-A556-4E10-9FE6-D1AB863A63B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {127F92E3-A556-4E10-9FE6-D1AB863A63B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {127F92E3-A556-4E10-9FE6-D1AB863A63B5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/VsoUpdateVersion.ps1 b/VsoUpdateVersion.ps1 deleted file mode 100644 index ede252c21..000000000 --- a/VsoUpdateVersion.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -# Script to set the buildNumber to a Nuget/NuSPec compatible Semantic version -# Nuget doesn't fully support full semantic version numbers. In particular, it -# doesn't support use of the '.' in parts after a '-' is used. So, this creates -# a semantic version number that uses additional '-' characters instead of '.' -# -# For details on the general algorithm used for computing the numbers here see: -# https://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute(v=vs.110).aspx -# The only difference from the AssemblyVersionAttribute algorithm is that this -# uses UTC for the reference times, thus ensuring that all builds are consistent -# no matter what locale the build agent or developer machine is set up for. -# -$now = [DateTime]::Now -$midnightToday = New-Object DateTime( $now.Year,$now.Month,$now.Day,0,0,0,[DateTimeKind]::Utc) -$basedate = New-Object DateTime(2000,1,1,0,0,0,[DateTimeKind]::Utc) -$buildNum = [int]($now - $basedate).Days -$buildRevision = [int]((($now - $midnightToday).TotalSeconds) / 2) -Write-Verbose -Verbose ([String]::Format( "##vso[build.updatebuildnumber]3.9.{0}.{1}-pre",$buildNum,$buildRevision)) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..190998120 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,25 @@ +version: 4.0.1.{build} + +pull_requests: + do_not_increment_build_number: true + +branches: + only: + - LLVM_4_0_1 + +image: Visual Studio 2017 + +skip_commits: + files: + - '**\*.md' + +nuget: + disable_publish_on_pr: true + account_feed: false + project_feed: true + +build_script: + - ps: .\BuildAll.ps1 + +artifacts: + - path: .\BuildOutput\Nuget\*.nupkg diff --git a/src/CustomDictionary.xml b/src/CustomDictionary.xml index 979116f8e..9a22d8cab 100644 --- a/src/CustomDictionary.xml +++ b/src/CustomDictionary.xml @@ -18,6 +18,7 @@ pointee Subrange LibLLVM + bitcode diff --git a/src/Design.md b/src/Design.md new file mode 100644 index 000000000..480d4bca7 --- /dev/null +++ b/src/Design.md @@ -0,0 +1,56 @@ +# General Design Notes for Llvm.NET +## Guiding principles +1) Mirror the underlying LLVM model as much as possible while +providing a well behaved .NET projection including: + 1) Class names and hierarchies + 1) Object identity and reference equality + 3) [Fluent](https://en.wikipedia.org/wiki/Fluent_interface) APIs when plausible and appropriate +1) Hide low-level interop details and the raw LLVM-C API. +The native model for LLVM is a C++ class hierarchy and not the LLVM-C API. +Llvm.NET is designed to provide an OO model that faithfully reflects the +underlying LLVM model while fitting naturally into .NET programming patterns. +1) FxCop Clean +4) Leverage existing LLVM-C APIs underneath whenever possible + 1) Extend only when needed with custom wrappers + +# Details +## Interning (Uniquing in LLVM) +Many if the underlying object instances in LLVM are interned/Uniqued. That is, +there will only be one instance of a type with a given value within some scope. + +In LLVM the most common scope for uniquing is the LLVMContext type. In essence +this class is an interning class factory for the LLVM IR system for a given thread. +Most object instances are ultimately owned by the context. LLVM-C APIs provide use +opaque pointers for LLVM objects. This is projected to the low level Llvm.NET.Native +namespace as structs that wrap an IntPtr to enforce some type safety. Furthermore, +the LLVM-C API uses the highest level of an object inheritance graph that it can when +declaring the opaque type for the return or arguments of functions. Thus, it is not +possible to know the exact derived type from the base opaque pointer alone. + +In addition to opaque pointers an additional challenge exists in mapping such pointers +to projected instances. Any projection is essentially a wrapper around the opaque +pointer. However, when an API returns an opaque pointer the interop layer needs to +determine what to do with it. A naive first approach (actually used in Llvm.NET early + boot strapping) is to simply create a new instance of the wrapper type giving it the +opaque pointer to work from. This will work for a while, until the code needs to compare +two instances. Ordinarily reference types are compared with reference equality. However, +if two projected instances share the same opaque pointer then reference equality will fail. +Furthermore for instances that may be enumerated multiple times (i.e. in a tree +traversal or visitor pattern) multiple instances of wrappers for the same underlying +instance would be created, thus wasting memory. + +To solve these problems Llvm.NET uses an interning approach that maintains a mapping of +the raw opaque pointers to a single instance. Thus whenever an interop API retrieves an +opaque pointer it can look up the wrapper and provide that to the caller. Thus, reference +equality "Just works". If there was no instance then the interning system will create one. +In order to create one it must know the concrete most derived type for the opaque pointer +to construct the wrapper type. Fortunately, LLVM uses a custom type tagging mechanism to +optimize such cases internally (e.g. safe dynamic down casting by keeping a TypeKind value). +The actual implementation in LLVM is not as simplistic as that but for the purposes of +projection that's enough to get to the correct type. Llvm.NET uses this to manage the +mapping and creation of types. + +To keep the interning factory from becoming over blown with type dependencies the actual +construction of new types is performed by the base type and not the factory. Instead the +intern factory for a type will call a delegate provided to create the item if needed. + diff --git a/src/LibLLVM/AnalysisBindings.cpp b/src/LibLLVM/AnalysisBindings.cpp index b3fe8d1e7..94f8ac463 100644 --- a/src/LibLLVM/AnalysisBindings.cpp +++ b/src/LibLLVM/AnalysisBindings.cpp @@ -13,7 +13,7 @@ extern "C" // The standard LLVMVerifyFunction (unlike LLVMVerifyModule) doesn't provide // a way to capture error message strings (only success/fail or print to // stderr is available). This provides a version that matches the general - // pattern established by LLVMVerifyModule(). + // pattern established by LLVMVerifyModule(). LLVMBool LLVMVerifyFunctionEx( LLVMValueRef Fn , LLVMVerifierFailureAction Action , char **OutMessages diff --git a/src/LibLLVM/AnalysisBindings.h b/src/LibLLVM/AnalysisBindings.h index c8bb608bd..312683670 100644 --- a/src/LibLLVM/AnalysisBindings.h +++ b/src/LibLLVM/AnalysisBindings.h @@ -1,8 +1,8 @@ #ifndef _ANALYSIS_BINDINGS_H_ #define _ANALYSIS_BINDINGS_H_ -#include "llvm-c/Core.h" -#include "llvm-c/Analysis.h" +#include +#include #ifdef __cplusplus extern "C" { @@ -16,4 +16,4 @@ extern "C" { } #endif -#endif \ No newline at end of file +#endif diff --git a/src/LibLLVM/AttributeBindings.cpp b/src/LibLLVM/AttributeBindings.cpp index 620f9701e..ddad67935 100644 --- a/src/LibLLVM/AttributeBindings.cpp +++ b/src/LibLLVM/AttributeBindings.cpp @@ -9,379 +9,11 @@ using namespace llvm; -DEFINE_SIMPLE_CONVERSION_FUNCTIONS( AttrBuilder, LLVMAttributeBuilderRef ) - -static_assert( sizeof( std::uintptr_t ) == sizeof( AttributeSet ), "ERROR: Size mismatch on AttributeSet" ); -static_assert( std::is_trivially_copy_constructible::value, "ERROR: AttributeSet cannot be trivially copy constructed" ); -static_assert( std::is_standard_layout::value, "ERROR: AttributeSet is not a 'C' compatible standard layout" ); - -LLVMAttributeSet wrap( AttributeSet attribute ) -{ - return *reinterpret_cast< LLVMAttributeSet* >( &attribute ); -} - -AttributeSet AsAttributeSet( LLVMAttributeSet attribute ) -{ - return *reinterpret_cast< AttributeSet* >( &attribute ); -} - -static_assert( sizeof( ArrayRef::iterator ) == sizeof( uintptr_t ), "ERROR: Size mismatch on ArrayRef::iterator" ); - extern "C" { - //--- AttributeSet wrappers - LLVMAttributeSet LLVMCreateEmptyAttributeSet( ) - { - return wrap( AttributeSet( ) ); - } - - LLVMAttributeSet LLVMCreateAttributeSetFromKindArray( LLVMContextRef context, unsigned index, LLVMAttrKind* pKinds, uint64_t len ) - { - auto attributes = ArrayRef( reinterpret_cast< Attribute::AttrKind* >( pKinds ), static_cast< size_t >( len ) ); - return wrap( AttributeSet::get( *unwrap( context ), index, attributes ) ); - } - - LLVMAttributeSet LLVMCreateAttributeSetFromAttributeSetArray( LLVMContextRef context, LLVMAttributeSet* pAttributes, uint64_t len ) - { - auto attributeSets = ArrayRef( reinterpret_cast< AttributeSet* >( pAttributes ), static_cast< size_t >( len ) ); - return wrap( AttributeSet::get( *unwrap( context ), attributeSets ) ); - } - - LLVMAttributeSet LLVMCreateAttributeSetFromBuilder( LLVMContextRef context, unsigned index, LLVMAttributeBuilderRef bldr ) - { - return wrap( AttributeSet::get( *unwrap( context ), index, *unwrap( bldr ) ) ); - } - - LLVMAttributeSet LLVMAttributeSetAddKind( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, LLVMAttrKind kind ) - { - auto attributes = AsAttributeSet( attributeSet ); - return wrap( attributes.addAttribute( *unwrap( context ), index, ( Attribute::AttrKind )kind ) ); - } - - LLVMAttributeSet LLVMAttributeSetAddString( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, char const*name ) - { - auto attributes = AsAttributeSet( attributeSet ); - return wrap( attributes.addAttribute( *unwrap( context ), index, name ) ); - } - - LLVMAttributeSet LLVMAttributeSetAddStringValue( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, char const* name, char const* value ) - { - auto attributes = AsAttributeSet( attributeSet ); - return wrap( attributes.addAttribute( *unwrap( context ), index, name, value ) ); - } - - LLVMAttributeSet LLVMAttributeSetAddAttributes( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, LLVMAttributeSet otherAttributeSet ) - { - auto attributes = AsAttributeSet( attributeSet ); - auto otherAttributes = AsAttributeSet( otherAttributeSet ); - return wrap( attributes.addAttributes( *unwrap( context ), index, otherAttributes ) ); - } - - LLVMAttributeSet LLVMAttributeSetRemoveAttributeKind( LLVMAttributeSet attributeSet, unsigned index, LLVMAttrKind kind ) - { - auto attributes = AsAttributeSet( attributeSet ); - if( attributes.isEmpty( ) ) - return attributeSet; - - return wrap( attributes.removeAttribute( attributes.getContext(), index, (Attribute::AttrKind )kind ) ); - } - - LLVMAttributeSet LLVMAttributeSetRemoveAttributeSet( LLVMAttributeSet attributeSet, unsigned index, LLVMAttributeSet attributesToRemove ) - { - auto attributes = AsAttributeSet( attributeSet ); - auto attributeSetToRemove = AsAttributeSet( attributesToRemove ); - if( attributes.isEmpty( ) || attributeSetToRemove.isEmpty( ) ) - return attributeSet; - - assert( &attributes.getContext( ) == &attributeSetToRemove.getContext( ) && "Mismatched contexts on AttributeSet" ); - return wrap( attributes.removeAttributes( attributes.getContext(), index, attributeSetToRemove ) ); - } - - LLVMAttributeSet LLVMAttributeSetRemoveAttributeBuilder( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, LLVMAttributeBuilderRef bldr ) - { - LLVMContext* pContext = unwrap( context ); - auto attributes = AsAttributeSet( attributeSet ); - AttrBuilder& attributeBuilder = *unwrap( bldr ); - - assert( ( attributes.isEmpty() || &attributes.getContext( ) == pContext ) && "Mismatched contexts on AttributeSet" ); - - return wrap( attributes.removeAttributes( *pContext, index, attributeBuilder ) ); - } - - LLVMContextRef LLVMAttributeSetGetContext( LLVMAttributeSet attributeSet ) - { - return wrap( &AsAttributeSet( attributeSet ).getContext( ) ); - } - - LLVMAttributeSet LLVMAttributeGetAttributes( LLVMAttributeSet attributeSet, unsigned index ) - { - auto attributes = AsAttributeSet( attributeSet ); - switch( index ) - { - case AttributeSet::AttrIndex::FunctionIndex: - return wrap( attributes.getFnAttributes( ) ); - - case AttributeSet::AttrIndex::ReturnIndex: - return wrap( attributes.getRetAttributes( ) ); - - default: - return wrap( attributes.getParamAttributes( index ) ); - } - } - - LLVMBool LLVMAttributeSetHasAttributeKind( LLVMAttributeSet attributeSet, unsigned index, LLVMAttrKind kind ) - { - auto attributes = AsAttributeSet( attributeSet ); - return attributes.hasAttribute( index, ( Attribute::AttrKind )kind ); - } - - LLVMBool LLVMAttributeSetHasStringAttribute( LLVMAttributeSet attributeSet, unsigned index, char const* name ) - { - auto attributes = AsAttributeSet( attributeSet ); - return attributes.hasAttribute( index, name ); - } - - LLVMBool LLVMAttributeSetHasAttributes( LLVMAttributeSet attributeSet, unsigned index ) - { - auto attributes = AsAttributeSet( attributeSet ); - return attributes.hasAttributes( index ); - } - - LLVMBool LLVMAttributeSetHasAttributeSomewhere( LLVMAttributeSet attributeSet, LLVMAttrKind kind ) - { - auto attributes = AsAttributeSet( attributeSet ); - return attributes.hasAttrSomewhere( ( Attribute::AttrKind )kind ); - } - - LLVMAttributeRef LLVMAttributeSetGetAttributeByKind( LLVMAttributeSet attributeSet, unsigned index, LLVMAttrKind kind ) - { - auto attributes = AsAttributeSet( attributeSet ); - return wrap( attributes.getAttribute( index, ( Attribute::AttrKind )kind ) ); - } - - LLVMAttributeRef LLVMAttributeSetGetAttributeByName( LLVMAttributeSet attributeSet, unsigned index, char const* name ) - { - auto attributes = AsAttributeSet( attributeSet ); - return wrap( attributes.getAttribute( index, name ) ); - } - - char const* LLVMAttributeSetToString( LLVMAttributeSet attributeSet, unsigned index, LLVMBool inGroup ) - { - auto attributes = AsAttributeSet( attributeSet ); - return LLVMCreateMessage( attributes.getAsString( index, inGroup != 0 ).c_str() ); - } - - unsigned LLVMAttributeSetGetNumSlots( LLVMAttributeSet attributeSet ) - { - auto attributes = AsAttributeSet( attributeSet ); - return attributes.getNumSlots( ); - } - - LLVMAttributeSet LLVMAttributeSetGetSlotAttributes( LLVMAttributeSet attributeSet, unsigned slot ) - { - auto attributes = AsAttributeSet( attributeSet ); - return wrap( attributes.getSlotAttributes( slot ) ); - } - - unsigned LLVMAttributeSetGetSlotIndex( LLVMAttributeSet attributeSet, unsigned slot ) - { - auto attributes = AsAttributeSet( attributeSet ); - return attributes.getSlotIndex( slot ); - } - - LLVMAttributeSet LLVMGetFunctionAttributeSet( LLVMValueRef /*Function*/ function ) - { - auto func = unwrap( function ); - return wrap( func->getAttributes() ); - } - - void LLVMSetFunctionAttributeSet( LLVMValueRef /*Function*/ function, LLVMAttributeSet attributeSet ) - { - auto func = unwrap( function ); - func->setAttributes( AsAttributeSet( attributeSet ) ); - } - - LLVMAttributeSet LLVMGetCallSiteAttributeSet( LLVMValueRef /*Instruction*/ instruction ) - { - CallSite call = CallSite( unwrap( instruction ) ); - - return wrap( call.getAttributes( ) ); - } - - void LLVMSetCallSiteAttributeSet( LLVMValueRef /*Instruction*/ instruction, LLVMAttributeSet attributeSet ) - { - CallSite call = CallSite( unwrap( instruction ) ); - call.setAttributes( AsAttributeSet( attributeSet ) ); - } - - uintptr_t LLVMAttributeSetGetIteratorStartToken( LLVMAttributeSet attributeSet, unsigned slot ) - { - auto attributes = AsAttributeSet( attributeSet ); - return reinterpret_cast( attributes.begin( slot ) ); - } - - LLVMAttributeRef LLVMAttributeSetIteratorGetNext( LLVMAttributeSet attributeSet, unsigned slot, uintptr_t* pToken ) - { - auto attributes = AsAttributeSet( attributeSet ); - auto it = *reinterpret_cast< Attribute**>( pToken ); - if( it >= attributes.end( slot ) || it < attributes.begin( slot ) ) - return wrap( Attribute( ) ); - - auto retVal = wrap( *it ); - *pToken = reinterpret_cast( ++it ); - return retVal; - } - - //--- Attribute Wrappers - LLVMBool LLVMIsIntAttribute( LLVMAttributeRef attribute ) - { - return unwrap( attribute ).isIntAttribute( ); - } - - LLVMBool LLVMHasAttributeKind( LLVMAttributeRef attribute, LLVMAttrKind kind ) - { - return unwrap( attribute ).hasAttribute( ( llvm::Attribute::AttrKind )kind ); - } - - LLVMBool LLVMHasAttributeString( LLVMAttributeRef attribute, char const* name ) - { - return unwrap( attribute ).hasAttribute( name ); - } - - LLVMAttrKind LLVMGetAttributeKind( LLVMAttributeRef attribute ) - { - return ( LLVMAttrKind )unwrap( attribute ).getKindAsEnum( ); - } - - uint64_t LLVMGetAttributeValue( LLVMAttributeRef attribute ) - { - return unwrap( attribute ).getValueAsInt( ); - } - - char const* LLVMGetAttributeName( LLVMAttributeRef attribute ) - { - return unwrap( attribute ).getKindAsString( ).data(); - } - - char const* LLVMGetAttributeStringValue( LLVMAttributeRef attribute ) - { - return unwrap( attribute ).getValueAsString( ).data(); - } - char const* LLVMAttributeToString( LLVMAttributeRef attribute ) { return LLVMCreateMessage( unwrap( attribute ).getAsString( ).c_str( ) ); } - LLVMAttributeRef LLVMCreateAttribute( LLVMContextRef ctx, LLVMAttrKind kind, uint64_t value ) - { - return wrap( llvm::Attribute::get( *unwrap( ctx ), ( llvm::Attribute::AttrKind )kind, value ) ); - } - - LLVMAttributeRef LVMCreateTargetDependentAttribute( LLVMContextRef ctx, char const* name, char const* value ) - { - return wrap( llvm::Attribute::get( *unwrap( ctx ), name, value ) ); - } - - //--- AttrBuilder Wrappers - - LLVMAttributeBuilderRef LLVMCreateAttributeBuilder( ) - { - return wrap( new AttrBuilder( ) ); - } - - LLVMAttributeBuilderRef LLVMCreateAttributeBuilder2( LLVMAttributeRef value ) - { - return wrap( new AttrBuilder( unwrap( value ) ) ); - } - - LLVMAttributeBuilderRef LLVMCreateAttributeBuilder3( LLVMAttributeSet attributeSet, unsigned index ) - { - return wrap( new AttrBuilder( AsAttributeSet( attributeSet ), index ) ); - } - - void LLVMAttributeBuilderDispose( LLVMAttributeBuilderRef bldr ) - { - delete unwrap( bldr ); - } - - void LLVMAttributeBuilderClear( LLVMAttributeBuilderRef bldr ) - { - unwrap( bldr )->clear( ); - } - - void LLVMAttributeBuilderAddEnum( LLVMAttributeBuilderRef bldr, LLVMAttrKind kind ) - { - unwrap( bldr )->addAttribute( ( Attribute::AttrKind )kind ); - } - - void LLVMAttributeBuilderAddAttribute( LLVMAttributeBuilderRef bldr, LLVMAttributeRef value ) - { - unwrap( bldr )->addAttribute( unwrap( value ) ); - } - - void LLVMAttributeBuilderAddStringAttribute( LLVMAttributeBuilderRef bldr, char const* name, char const* value ) - { - unwrap( bldr )->addAttribute( name, value ); - } - - void LLVMAttributeBuilderRemoveEnum( LLVMAttributeBuilderRef bldr, LLVMAttrKind kind ) - { - unwrap( bldr )->removeAttribute( ( Attribute::AttrKind )kind ); - } - - void LLVMAttributeBuilderRemoveAttributes( LLVMAttributeBuilderRef bldr, LLVMAttributeSet attributeSet, unsigned index ) - { - unwrap( bldr )->removeAttributes( AsAttributeSet( attributeSet ), index ); - } - - void LLVMAttributeBuilderRemoveAttribute( LLVMAttributeBuilderRef bldr, char const* name ) - { - unwrap( bldr )->removeAttribute( name ); - } - - void LLVMAttributeBuilderRemoveBldr( LLVMAttributeBuilderRef bldr, LLVMAttributeBuilderRef other ) - { - unwrap( bldr )->remove( *unwrap( other ) ); - } - - void LLVMAttributeBuilderMerge( LLVMAttributeBuilderRef bldr, LLVMAttributeBuilderRef other ) - { - unwrap( bldr )->merge( *unwrap( other ) ); - } - - LLVMBool LLVMAttributeBuilderOverlaps( LLVMAttributeBuilderRef bldr, LLVMAttributeBuilderRef other ) - { - return unwrap( bldr )->overlaps( *unwrap( other ) ); - } - - LLVMBool LLVMAttributeBuilderContainsEnum( LLVMAttributeBuilderRef bldr, LLVMAttrKind kind ) - { - return unwrap( bldr )->contains( ( Attribute::AttrKind )kind ); - } - - LLVMBool LLVMAttributeBuilderContainsName( LLVMAttributeBuilderRef bldr, char const* name ) - { - return unwrap( bldr )->contains( name ); - } - - LLVMBool LLVMAttributeBuilderHasAnyAttributes( LLVMAttributeBuilderRef bldr ) - { - return unwrap( bldr )->hasAttributes( ); - } - - LLVMBool LLVMAttributeBuilderHasAttributes( LLVMAttributeBuilderRef bldr, LLVMAttributeSet attributeset, unsigned index ) - { - return unwrap( bldr )->hasAttributes( AsAttributeSet( attributeset ), index ); - } - - LLVMBool LLVMAttributeBuilderHasTargetIndependentAttrs( LLVMAttributeBuilderRef bldr ) - { - return !unwrap( bldr )->empty( ); - } - - LLVMBool LLVMAttributeBuilderHasTargetDependentAttrs( LLVMAttributeBuilderRef bldr ) - { - return !unwrap( bldr )->td_empty( ); - } } diff --git a/src/LibLLVM/AttributeBindings.h b/src/LibLLVM/AttributeBindings.h index 00dc824f3..895ee7e49 100644 --- a/src/LibLLVM/AttributeBindings.h +++ b/src/LibLLVM/AttributeBindings.h @@ -14,8 +14,8 @@ #ifndef LLVM_BINDINGS_LLVM_ATTRIBUTEBINDINGS_H #define LLVM_BINDINGS_LLVM_ATTRIBUTEBINDINGS_H -#include "llvm-c/Core.h" -#include "llvm-c/Types.h" +#include +#include #include @@ -23,196 +23,8 @@ extern "C" { #endif - enum LLVMAttrKind - { - // IR-Level Attributes - LLVMAttrKindNone, - LLVMAttrKindAlignment, - LLVMAttrKindAllocSize, - LLVMAttrKindAlwaysInline, - LLVMAttrKindArgMemOnly, - LLVMAttrKindBuiltin, - LLVMAttrKindByVal, - LLVMAttrKindCold, - LLVMAttrKindConvergent, - LLVMAttrKindDereferenceable, - LLVMAttrKindDereferenceableOrNull, - LLVMAttrKindInAlloca, - LLVMAttrKindInReg, - LLVMAttrKindInaccessibleMemOnly, - LLVMAttrKindInaccessibleMemOrArgMemOnly, - LLVMAttrKindInlineHint, - LLVMAttrKindJumpTable, - LLVMAttrKindMinSize, - LLVMAttrKindNaked, - LLVMAttrKindNest, - LLVMAttrKindNoAlias, - LLVMAttrKindNoBuiltin, - LLVMAttrKindNoCapture, - LLVMAttrKindNoDuplicate, - LLVMAttrKindNoImplicitFloat, - LLVMAttrKindNoInline, - LLVMAttrKindNoRecurse, - LLVMAttrKindNoRedZone, - LLVMAttrKindNoReturn, - LLVMAttrKindNoUnwind, - LLVMAttrKindNonLazyBind, - LLVMAttrKindNonNull, - LLVMAttrKindOptimizeForSize, - LLVMAttrKindOptimizeNone, - LLVMAttrKindReadNone, - LLVMAttrKindReadOnly, - LLVMAttrKindReturned, - LLVMAttrKindReturnsTwice, - LLVMAttrKindSExt, - LLVMAttrKindSafeStack, - LLVMAttrKindSanitizeAddress, - LLVMAttrKindSanitizeMemory, - LLVMAttrKindSanitizeThread, - LLVMAttrKindStackAlignment, - LLVMAttrKindStackProtect, - LLVMAttrKindStackProtectReq, - LLVMAttrKindStackProtectStrong, - LLVMAttrKindStructRet, - LLVMAttrKindSwiftError, - LLVMAttrKindSwiftSelf, - LLVMAttrKindUWTable, - LLVMAttrKindZExt, - EndAttrKinds /// Sentinal value useful for loops - }; - - // These functions replace the LLVM*FunctionAttr functions in the stable C API - // since the underlying attribute support has changed dramatically in 3.7.0 - - /** - * @defgroup LibLLVM Attributes - * - * Attributes are available for functions, function return types and parameters. - * In previous releases of LLVM attributes were essentially a bit field. However, - * as more attributes were added the number of bits had to grow. Furthermore, some - * of the attributes such as stack alignment require a parameter value. Thus, the - * attribute system evolved. Unfortunately the C API did not. Moving towards version - * 4.0 of LLVM the entire bitfield approach is being deprecated. Thus these APIs - * make the functionality of Attribute, AttributeSet and, AttrBuilder available - * to language bindings based on a C-API - * - * The Attribute and AttributeSet classes are somewhat problematic to expose in - * "C" as they are not officially POD types and therefore have limited defined - * portable usage in "C". However, they are officially standard layout and trivially - * copy constructible. The reason they are not POD is that they have a custom default - * constructor. Thus construction cannot be assumed as trivially zero initializing - * the memory for the type. To manage that with projections to "C" and other languages - * this API exposes the underlying class constructors as "C" functions returning an - * instance of the constructed type. Furthermore this API assumes that llvm::Attribute - * and llvm::AttributeSet are defined using the Pointer to Implementation (PIMPL) - * pattern and are entirely representable in a LLVMAttributeSet. (This is statically checked - * in the AttributeBindings.cpp file along with the trivial copy construction and - * standard layout type traits. Any changes in LLVM that would invalidate these assumptions - * will trigger a compilation error, rather than failing in inexplicable ways at runtime.) - * @{ - */ - typedef uintptr_t LLVMAttributeSet; - typedef struct LLVMOpaqueAttributeBuilder* LLVMAttributeBuilderRef; - - /** @name AttributeSet - * @{ - */ - LLVMAttributeSet LLVMCreateEmptyAttributeSet( ); - LLVMAttributeSet LLVMCreateAttributeSetFromKindArray( LLVMContextRef context, unsigned index, LLVMAttrKind* pKinds, uint64_t len ); - LLVMAttributeSet LLVMCreateAttributeSetFromAttributeSetArray( LLVMContextRef context, LLVMAttributeSet* pAttributes, uint64_t len ); - LLVMAttributeSet LLVMCreateAttributeSetFromBuilder( LLVMContextRef context, unsigned index, LLVMAttributeBuilderRef bldr ); - - LLVMAttributeSet LLVMAttributeSetAddKind( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, LLVMAttrKind kind ); - LLVMAttributeSet LLVMAttributeSetAddString( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, char const*name ); - LLVMAttributeSet LLVMAttributeSetAddStringValue( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, char const* name, char const* value ); - LLVMAttributeSet LLVMAttributeSetAddAttributes( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, LLVMAttributeSet otherAttributeSet ); - - LLVMAttributeSet LLVMAttributeSetRemoveAttributeKind( LLVMAttributeSet attributeSet, unsigned index, LLVMAttrKind kind ); - LLVMAttributeSet LLVMAttributeSetRemoveAttributeSet( LLVMAttributeSet attributeSet, unsigned index, LLVMAttributeSet attributes ); - LLVMAttributeSet LLVMAttributeSetRemoveAttributeBuilder( LLVMAttributeSet attributeSet, LLVMContextRef context, unsigned index, LLVMAttributeBuilderRef bldr ); - - LLVMContextRef LLVMAttributeSetGetContext( LLVMAttributeSet attributeSet ); - LLVMAttributeSet LLVMAttributeGetAttributes( LLVMAttributeSet attributeSet, unsigned index ); - LLVMBool LLVMAttributeSetHasAttributeKind( LLVMAttributeSet attributeSet, unsigned index, LLVMAttrKind kind ); - LLVMBool LLVMAttributeSetHasStringAttribute( LLVMAttributeSet attributeSet, unsigned index, char const* name ); - LLVMBool LLVMAttributeSetHasAttributes( LLVMAttributeSet attributeSet, unsigned index ); - LLVMBool LLVMAttributeSetHasAttributeSomewhere( LLVMAttributeSet attributeSet, LLVMAttrKind kind ); - - LLVMAttributeRef LLVMAttributeSetGetAttributeByKind( LLVMAttributeSet attributeSet, unsigned index, LLVMAttrKind kind ); - LLVMAttributeRef LLVMAttributeSetGetAttributeByName( LLVMAttributeSet attributeSet, unsigned index, char const* name ); - char const* LLVMAttributeSetToString( LLVMAttributeSet attributeSet, unsigned index, LLVMBool inGroup ); - - unsigned LLVMAttributeSetGetNumSlots( LLVMAttributeSet attributeSet ); - LLVMAttributeSet LLVMAttributeSetGetSlotAttributes( LLVMAttributeSet attributeSet, unsigned slot ); - unsigned LLVMAttributeSetGetSlotIndex( LLVMAttributeSet attributeSet, unsigned slot ); - - LLVMAttributeSet LLVMGetFunctionAttributeSet( LLVMValueRef /*Function*/ function ); - void LLVMSetFunctionAttributeSet( LLVMValueRef /*Function*/ function, LLVMAttributeSet attributeSet ); - LLVMAttributeSet LLVMGetCallSiteAttributeSet( LLVMValueRef /*Instruction*/ instruction ); - void LLVMSetCallSiteAttributeSet( LLVMValueRef /*Instruction*/ instruction, LLVMAttributeSet attributeSet ); - - uintptr_t LLVMAttributeSetGetIteratorStartToken( LLVMAttributeSet attributeSet, unsigned slot ); - LLVMAttributeRef LLVMAttributeSetIteratorGetNext( LLVMAttributeSet attributeSet, unsigned slot, uintptr_t* pToken ); - - /** - * @} - */ - - /** @name Attribute - * @{ - */ - LLVMBool LLVMIsEnumAttribute( LLVMAttributeRef attribute ); - LLVMBool LLVMIsIntAttribute( LLVMAttributeRef attribute ); - LLVMBool LLVMIsStringAttribute( LLVMAttributeRef attribute ); - LLVMBool LLVMHasAttributeKind( LLVMAttributeRef attribute, LLVMAttrKind kind ); - LLVMBool LLVMHasAttributeString( LLVMAttributeRef attribute, char const* name ); - LLVMAttrKind LLVMGetAttributeKind( LLVMAttributeRef attribute ); - uint64_t LLVMGetAttributeValue( LLVMAttributeRef attribute ); - char const* LLVMGetAttributeName( LLVMAttributeRef attribute ); - char const* LLVMGetAttributeStringValue( LLVMAttributeRef attribute ); char const* LLVMAttributeToString( LLVMAttributeRef attribute ); - LLVMAttributeRef LLVMCreateAttribute( LLVMContextRef ctx, LLVMAttrKind kind, uint64_t value ); - LLVMAttributeRef LVMCreateTargetDependentAttribute( LLVMContextRef ctx, char const* name, char const* value ); - /** - * @} - */ - - /** @name AttrBuilder - * @{ - */ - LLVMAttributeBuilderRef LLVMCreateAttributeBuilder( ); - LLVMAttributeBuilderRef LLVMCreateAttributeBuilder2( LLVMAttributeRef value ); - LLVMAttributeBuilderRef LLVMCreateAttributeBuilder3( LLVMAttributeSet attributeSet, unsigned index ); - void LLVMAttributeBuilderDispose( LLVMAttributeBuilderRef bldr ); - - void LLVMAttributeBuilderClear( LLVMAttributeBuilderRef bldr ); - - void LLVMAttributeBuilderAddEnum( LLVMAttributeBuilderRef bldr, LLVMAttrKind kind ); - void LLVMAttributeBuilderAddAttribute( LLVMAttributeBuilderRef bldr, LLVMAttributeRef value ); - void LLVMAttributeBuilderAddStringAttribute( LLVMAttributeBuilderRef bldr, char const* name, char const* value ); - void LLVMAttributeBuilderRemoveEnum( LLVMAttributeBuilderRef bldr, LLVMAttrKind kind ); - void LLVMAttributeBuilderRemoveAttributes( LLVMAttributeBuilderRef bldr, LLVMAttributeSet attributeSet, unsigned index ); - void LLVMAttributeBuilderRemoveAttribute( LLVMAttributeBuilderRef bldr, char const* name ); - void LLVMAttributeBuilderRemoveBldr( LLVMAttributeBuilderRef bldr, LLVMAttributeBuilderRef ohter ); - - void LLVMAttributeBuilderMerge( LLVMAttributeBuilderRef bldr, LLVMAttributeBuilderRef ohter ); - LLVMBool LLVMAttributeBuilderOverlaps( LLVMAttributeBuilderRef bldr, LLVMAttributeBuilderRef other ); - LLVMBool LLVMAttributeBuilderContainsEnum( LLVMAttributeBuilderRef bldr, LLVMAttrKind kind ); - LLVMBool LLVMAttributeBuilderContainsName( LLVMAttributeBuilderRef bldr, char const* name ); - LLVMBool LLVMAttributeBuilderHasAnyAttributes( LLVMAttributeBuilderRef bldr ); - LLVMBool LLVMAttributeBuilderHasAttributes( LLVMAttributeBuilderRef bldr, LLVMAttributeSet attributeset, unsigned index ); - LLVMBool LLVMAttributeBuilderHasTargetIndependentAttrs( LLVMAttributeBuilderRef bldr ); - LLVMBool LLVMAttributeBuilderHasTargetDependentAttrs( LLVMAttributeBuilderRef bldr ); - - // TODO: Define support for iterators over target dependent attributes - /** - * @} - */ - - /** - * @} - */ #ifdef __cplusplus } #endif diff --git a/src/LibLLVM/Build-LlvmWithVs.ps1 b/src/LibLLVM/Build-LlvmWithVs.ps1 deleted file mode 100644 index c48352aaf..000000000 --- a/src/LibLLVM/Build-LlvmWithVs.ps1 +++ /dev/null @@ -1,281 +0,0 @@ -<# -.SYNOPSIS - Wraps CMake Visual Studio solution generation and build for LLVM as used by the LLVM.NET project - -.PARAMETER BuildOutputPath - The path to where the projects are generated and the binaries they build will be located. - -.PARAMETER Generate - Switch to run CMAKE configuration and project/solution generation - -.PARAMETER Build - Switch to Build the projects generated by the -Generate option - -.PARAMETER Register - Add Registry entries for the location of binaries built and the LLVM header files so that projects using the libraries generated can locate them - -.PARAMETER LlvmRoot - This specifies the root of the LLVM source tree to build. The default value is the folder containing this script, but if the script is not placed - into the LLVM source tree the path must be specified. - -.PARAMETER BaseVsGenerator - This specifies the base name of the CMAKE Visual Studio Generator. This script will add the "Win64" part of the name when generating 64bit projects. - The default value is for Visual Studio 2017 as LLVM.NET is migrating to Full VS 2017 support. - -.PARAMETER CreateSettingsJson - This flag generates the VS CMakeSettings.json file with all the CMAKE settings for LLVM as needed by LLVM.NET with Visual C++ tools for CMake in - Visual Studio 2017. -#> -[CmdletBinding()] -param( [Parameter(Mandatory)] - [string] - $BuildOutputPath, - - [switch] - $Generate, - - [switch] - $Build, - - [switch] - $Register, - - [switch] - $CreateSettingsJson, - - [ValidateNotNullOrEmpty()] - [string]$LlvmRoot=$PSScriptRoot, - - [ValidateNotNullOrEmpty()] - [string] - $BaseVsGenerator="Visual Studio 15 2017" - ) - -function Get-CmakeInfo([int]$minMajor, [int]$minMinor, [int]$minPatch) -{ - $cmakePath = where.exe cmake.exe 2>&1 | %{$_.ToString} - if( $LASTEXITCODE -ne 0 ) - { - throw "CMAKE.EXE not found - Version {1}.{2}.{3} or later is required and should be in the search path" -f($minMajor,$minMinor,$minPatch) - } - - $cmakeInfo = cmake -E capabilities | ConvertFrom-Json - $cmakeVer = $cmakeInfo.version - if( ($cmakeVer.major -lt $minMajor) -or ($cmakeVer.minor -lt $minMinor) -or ($cmakeVer.patch -lt $minPatch) ) - { - throw "CMake version not supported. Found: {0}; Require >= {1}.{2}.{3}" -f($cmakeInfo.version.string,$minMajor,$minMinor,$minPatch) - } -} - -function Generate-CMake( $config, [string]$llvmroot ) -{ - $activity = "Generating solution for {0}" -f($config.name) - Write-Information $activity - if(!(Test-Path -PathType Container $config.buildRoot )) - { - New-Item -ItemType Container $config.buildRoot | Out-Null - } - - # Construct full set of args from fixed options and configuration variables - $cmakeArgs = New-Object System.Collections.ArrayList - $cmakeArgs.Add("-G`"{0}`"" -f($config.generator)) | Out-Null - foreach( $var in $config.variables ) - { - $cmakeArgs.Add( "-D{0}={1}" -f($var.name,$var.value) ) | Out-Null - } - - $cmakeArgs.Add( $llvmRoot ) | Out-Null - - pushd $config.buildRoot - $timer = [System.Diagnostics.Stopwatch]::StartNew() - try - { - Write-Verbose "cmake $cmakeArgs" - & cmake $cmakeArgs | %{Write-Progress -Activity $activity -PercentComplete (-1) -SecondsRemaining (-1) -Status ([string]$_) } - - if($LASTEXITCODE -ne 0 ) - { - throw ("Cmake generation exited with non-zero exit code: {0}" -f($LASTEXITCODE)) - } - } - finally - { - $timer.Stop() - Write-Progress -Activity $activity -Completed - Write-Verbose ("Generation Time: {0}" -f($timer.Elapsed.ToString())) - popd - } -} - -function Build-Cmake($config) -{ - $activity = "Building LLVM for {0}" -f($config.name) - Write-Information $activity - - $timer = [System.Diagnostics.Stopwatch]::StartNew() - try - { - cmake --build $config.buildRoot --config $config.configurationType -- ($config.buildCommandArgs.Split(' ')) - if($LASTEXITCODE -ne 0 ) - { - throw "Cmake build exited with non-zero exit code: {0}" -f($LASTEXITCODE) - } - } - finally - { - $timer.Stop() - Write-Verbose ("Build Time: {0}" -f($timer.Elapsed.ToString())) - } -} - -function Register-Llvm( [string]$llvmVersion, [string] $llvmRoot, [string] $buildRoot ) -{ - $regPath = "Software\LLVM\$llvmVersion" - if( !( Test-Path HKCU:$regPath ) ) - { - New-Item HKCU:$regPath | Out-Null - } - - New-ItemProperty -Path HKCU:$regPath -Name "SrcRoot" -Value $llvmRoot -Force | Out-Null - New-ItemProperty -Path HKCU:$regPath -Name "BuildRoot" -Value $buildRoot -Force | Out-Null - - try - { - if( !( Test-Path HKLM:$regPath ) ) - { - New-Item HKLM:$regPath | Out-Null - } - New-ItemProperty -Path HKLM:$regPath -Name "SrcRoot" -Value $llvmRoot -Force -ErrorAction Stop | Out-Null - New-ItemProperty -Path HKLM:$regPath -Name "BuildRoot" -Value $buildRoot -Force -ErrorAction Stop | Out-Null - } - catch [System.Security.SecurityException] - { - Write-Warning "Registration of LLVM in System wide registry not set due to access permissions. To register the LLVM source root for the system, run this script with the -Register switch elevated with admin priviliges." - } -} - -function New-CmakeConfig([string]$platform, [string]$config, [string]$BaseGenerator, [string]$baseBuild ) -{ - $generator = $BaseGenerator - # normalize platform name and create final generator name - $Platform = $Platform.ToLowerInvariant() - switch($Platform) - { - "x86" {} - "x64" {$generator="{0} Win64" -f($BaseGenerator)} - default {throw "Invalid Platform" } - } - - # build a config object suitable for conversion to JSON for VS CMakeSettings.json - # This is used in the project generation and build as well, since it contains all - # the information needed for each of those cases. - [PSCustomObject]@{ - name = "$platform-$config" - generator = $generator - configurationType = $config - buildRoot = (Join-Path $baseBuild "$platform-$config") - cmakeCommandArgs = "" - buildCommandArgs = "-m -v:minimal" - variables = @( - @{name = "LLVM_ENABLE_RTTI"; value = "ON" }, - @{name = "LLVM_BUILD_TOOLS"; value = "OFF"}, - @{name = "LLVM_BUILD_TESTS"; value = "OFF"}, - @{name = "LLVM_BUILD_EXAMPLES"; value = "OFF"}, - @{name = "LLVM_BUILD_DOCS"; value = "OFF"}, - @{name = "LLVM_BUILD_RUNTIME"; value = "OFF"}, - @{name = "CMAKE_INSTALL_PREFIX"; value = "Install"}, - @{name = "CMAKE_CONFIGURATION_TYPES"; value = "$config"} - ) - } -} - -function New-CmakeSettings( $configurations ) -{ - ConvertTo-Json -Depth 4 ([PSCustomObject]@{ configurations = $configurations }) -} - -function Normalize-Path([string]$path ) -{ - $path = [System.IO.Path]::Combine((pwd).Path,$path) - return [System.IO.Path]::GetFullPath($path) -} - -function Get-LlvmVersion( [string] $cmakeListPath ) -{ - $props = @{} - $matches = Select-String -Path $cmakeListPath -Pattern "set\(LLVM_VERSION_(MAJOR|MINOR|PATCH) ([0-9])+\)" | %{$_.Matches} - foreach( $match in $matches ) - { - $props = $props + @{$match.Groups[1].Value = [Convert]::ToInt32($match.Groups[2].Value)} - } - $versionObj = [PsCustomObject]($props) - "{0}.{1}.{2}" -f($versionObj.MAJOR,$versionObj.Minor,$versionObj.Patch) -} - -#--- Main Script Body - -# Force absolute paths for input params dealing in paths -$Script:LlvmRoot = Normalize-Path $Script:LlvmRoot -$Script:BuildOutputPath = Normalize-Path $Script:BuildOutputPath - -# Verify Cmake version info -$CmakeInfo = Get-CmakeInfo 3 7 1 - -Write-Information "LLVM Source Root: $Script:LlvmRoot" -$cmakeListPath = Join-Path $Script:LlvmRoot CMakeLists.txt -if( !( Test-Path -PathType Leaf $cmakeListPath ) ) -{ - throw "'$cmakeListPath' is missing, the current directory does not appear to be a valid source directory" -} - -# Construct array of configurations to deal with -$configurations = ( (New-CmakeConfig x86 "Release" $BaseVsGenerator $Script:BuildOutputPath), - (New-CmakeConfig x86 "Debug" $BaseVsGenerator $Script:BuildOutputPath), - (New-CmakeConfig x64 "Release" $BaseVsGenerator $Script:BuildOutputPath), - (New-CmakeConfig x64 "Debug" $BaseVsGenerator $Script:BuildOutputPath) - ) - -if( $Generate ) -{ - $timer = [System.Diagnostics.Stopwatch]::StartNew() - try - { - foreach( $config in $configurations ) - { - Generate-CMake $config $Script:LlvmRoot - } - } - finally - { - $timer.Stop() - Write-Information ("Total Generation Time: {0}" -f($timer.Elapsed.ToString())) - } -} - -if( $Build ) -{ - $timer = [System.Diagnostics.Stopwatch]::StartNew() - try - { - foreach( $config in $configurations ) - { - Build-Cmake $config - } - } - finally - { - $timer.Stop() - Write-Information ("Total Build Time: {0}" -f($timer.Elapsed.ToString())) - } -} - -if( $Register ) -{ - $llvmVersion = Get-LlvmVersion $Script:cmakeListPath - Register-Llvm $llvmVersion $Script:LlvmRoot $Script:BuildOutputPath -} - -if( $CreateSettingsJson ) -{ - New-CmakeSettings $configurations | Out-File (join-path $Script:LlvmRoot CMakeSettings.json) -} diff --git a/src/LibLLVM/BuildLlvmWithVS.cmd b/src/LibLLVM/BuildLlvmWithVS.cmd deleted file mode 100644 index 479d22f55..000000000 --- a/src/LibLLVM/BuildLlvmWithVS.cmd +++ /dev/null @@ -1,134 +0,0 @@ -@echo off -@REM - This script file should be placed into the root of the LLVM source tree -@REM - It can be run from there, with no parameters to generate all the -@REM - Libs for Win32 and x64 with the Debug, RelWithDebInfo, and Release -@REM - configurations. - -setlocal -set LLVM_ROOT=%~d0%~p0 - -@REM By default do the following: -@REM 1 - Generate the build project and solutions from CMake -@REM 2 - Build all the Platform\configuration combos (2x3) -@REM 3 - Register the output location in registry -set GENERATE=1 -set BUILD=1 -set REGISTER=1 -set LlvmVersion=3.9.0 - -@REM - Allow overriding default version and disabling any of the stages via parameters -:arg_loop -if /i "%1"=="-g-" set GENERATE=0 -if /i "%1"=="-b-" set BUILD=0 -if /i "%1"=="-r-" set REGISTER=0 -if /i "%1"=="-v" ( - set LlvmVersion=%2 - shift -) -if /i "%1"=="-?" goto :ShowUsage -if /i "%1"=="/?" goto :ShowUsage -if /i "%1"=="/h" goto :ShowUsage -if /i "%1"=="-h" goto :ShowUsage -if /i "%1"=="/help" goto :ShowUsage -if /i "%1"=="/-help" goto :ShowUsage - -@rem - move to next arg and loop back around if it isn't empty -shift -if NOT "%1"=="" goto :arg_loop -@REM - End of args parsing - -@REM - Verification -if NOT EXIST %LLVM_ROOT%CMakeLists.txt ( - @echo CMakeLists.txt is missing, the current directory does not appear to be an LLVM source directory - goto :exit -) - -@REM - Execution -if %GENERATE%==1 ( - where cmake | findstr "cmake.exe" - if %ERRORLEVEL% GTR 0 ( - @echo cmake.exe not found, you must have cmake 3.2.3 installed and available on your PATH variable - goto :exit - ) - call :CongigureLLVMBuild "Visual Studio 14 2015 Win64" x64 - if %ERRORLEVEL% GTR 0 goto :exit - - call :CongigureLLVMBuild "Visual Studio 14 2015" Win32 - if %ERRORLEVEL% GTR 0 goto :exit -) -if %BUILD%==1 ( - call :BuildLLVMPlatform x64 - if %ERRORLEVEL% GTR 0 goto :exit - call :BuildLLVMPlatform Win32 - if %ERRORLEVEL% GTR 0 goto :exit -) - -if %REGISTER%==1 ( - @echo registering LLVM path in registry - reg add HKCU\Software\LLVM\%LlvmVersion% /v SrcRoot /d %LLVM_ROOT% /f - echo Setting per machine rigistry path - echo NOTE: Administrator permissions required to set per machine registry settings. - echo If you get 'ERROR: Access is denied.' the per machine registration is not available - reg add HKLM\Software\LLVM\%LlvmVersion% /v SrcRoot /d %LLVM_ROOT% /f - @REM - Sadly, despite documentation to the contrary, reg won't set ERRORLEVEL on failure... -) -goto :exit - -:ShowUsage -@echo. -@echo Description: -@echo Builds LLVM libraries using the Microsoft Visual Studio 2015 compilers with the following basic steps -@echo 1) Generates the VS projects from LLVM source via CMake -@echo 2) Builds the sources for win32 and x64 platforms with the Debug,Release, and RelWithDebInfo configurations -@echo 3) Adds a registry entry for the location of the src and build output HKCU\SOFTWARE\LLVM\^\SrcRoot -@echo 4) Adds a registry entry for the location of the src and build output HKLM\SOFTWARE\LLVM\^\SrcRoot -@echo. -@echo Usage: -@echo BuildLlvmWithVS [-g-][-b-][-r-][-v ^] -@echo. -@echo Where: -@echo -g- disables the cmake project generation phase -@echo -b- disables the code build phase -@echo -r- disables the registry update -@echo -v ^ sets the LLVM version number used for the registry entry (Default is 3.9.0) -@echo. -@echo The registry entry is used by the LlvmApplication.props Propertysheet for VC projects to locate the various -@echo LLVM headers and libs. Alternatively, if LLVM_SRCROOT_DIR is provided either as an environment variable -@echo or as an MsBuild property for the application's build then LlvmApplication.props will use it and the registry -@echo entry is not required. This is to support automated build servers where this script may be run on a machine -@echo sharing out the results and the application build server is run from a different account and machine where -@echo settings are different. -@echo. -goto :exit - -:CongigureLLVMBuild - @echo __--== Generating build configuration of LLVM For %2 ==--__ - if NOT EXIST "build\%2" md build\%2 - pushd build\%2 - @rem - NOTE: Enabling RTTI allows for extended C API projections to use RTTI even on classes where the LLVM custom RTTI support isn't defined - cmake -G"%~1" -DLLVM_ENABLE_RTTI=1 -DCMAKE_INSTALL_PREFIX=Install ..\.. - popd - if %ERRORLEVEL% GTR 0 exit /B %ERRORLEVEL% - - goto :EOF - -:BuildLLVMPlatform - @echo __--== Building LLVM For %1 ==--__ - - @echo __--== Building Release configuration For %1 ==--__ - cmake --build build\%1. --config Release - if %ERRORLEVEL% GTR 0 exit /B %ERRORLEVEL% - -@REM @echo __--== Building Checked configuration For %1 ==--__ -@REM cmake --build build\%1 --config RelWithDebInfo -@REM if %ERRORLEVEL% GTR 0 exit /B %ERRORLEVEL% - - @echo __--== Building Debug configuration For %1 ==--__ - cmake --build build\%1 --config Debug - if %ERRORLEVEL% GTR 0 exit /B %ERRORLEVEL% - - goto :EOF - -:exit -endlocal -goto :EOF diff --git a/src/LibLLVM/DIBuilderBindings.cpp b/src/LibLLVM/DIBuilderBindings.cpp index 8ac920608..713df3044 100644 --- a/src/LibLLVM/DIBuilderBindings.cpp +++ b/src/LibLLVM/DIBuilderBindings.cpp @@ -114,8 +114,7 @@ extern "C" { DIBuilder *D = unwrap( Dref ); DICompileUnit* CU = D->createCompileUnit( Lang - , File - , Dir + , D->createFile(File, Dir ) , Producer , Optimized , Flags @@ -190,7 +189,7 @@ extern "C" , IsLocalToUnit , IsDefinition , ScopeLine - , Flags + , static_cast( Flags ) , IsOptimized , TParams ? DITemplateParameterArray( unwrap( TParams ) ) : nullptr , Decl ? unwrap( Decl ) : nullptr @@ -224,7 +223,7 @@ extern "C" , isLocalToUnit , isDefinition , ScopeLine - , Flags + , static_cast( Flags ) , isOptimized , TParams ? DITemplateParameterArray( unwrap( TParams ) ) : nullptr , Decl ? unwrap( Decl ) : nullptr @@ -249,7 +248,7 @@ extern "C" , Line , unwrap( Ty ) , AlwaysPreserve - , Flags + , static_cast( Flags ) ); return wrap( V ); } @@ -273,7 +272,7 @@ extern "C" , Line , unwrap( Ty ) , AlwaysPreserve - , Flags + , static_cast( Flags ) ); return wrap( V ); } @@ -281,19 +280,18 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateBasicType( LLVMDIBuilderRef Dref , const char *Name , uint64_t SizeInBits - , uint64_t AlignInBits , unsigned Encoding ) { DIBuilder *D = unwrap( Dref ); - DIBasicType* T = D->createBasicType( Name, SizeInBits, AlignInBits, Encoding ); + DIBasicType* T = D->createBasicType( Name, SizeInBits, Encoding ); return wrap( T ); } LLVMMetadataRef LLVMDIBuilderCreatePointerType( LLVMDIBuilderRef Dref , LLVMMetadataRef PointeeType , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , const char *Name ) { @@ -324,7 +322,7 @@ extern "C" { DIBuilder *D = unwrap( Dref ); DISubroutineType* sub = D->createSubroutineType( DITypeRefArray( unwrap( ParameterTypes ) ) - , Flags + , static_cast( Flags ) ); return wrap( sub ); } @@ -335,7 +333,7 @@ extern "C" , LLVMMetadataRef File , unsigned Line , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , unsigned Flags , LLVMMetadataRef DerivedFrom , LLVMMetadataRef ElementTypes @@ -348,7 +346,7 @@ extern "C" , Line , SizeInBits , AlignInBits - , Flags + , static_cast( Flags ) , DerivedFrom ? unwrap( DerivedFrom ) : nullptr , ElementTypes ? DINodeArray( unwrap( ElementTypes ) ) : nullptr ); @@ -361,7 +359,7 @@ extern "C" , LLVMMetadataRef File , unsigned Line , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , unsigned Flags , LLVMMetadataRef ElementTypes ) @@ -373,7 +371,7 @@ extern "C" , Line , SizeInBits , AlignInBits - , Flags + , static_cast( Flags ) , ElementTypes ? DINodeArray( unwrap( ElementTypes ) ) : nullptr ); return wrap( CT ); @@ -387,7 +385,7 @@ extern "C" , unsigned Line , unsigned RuntimeLang , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , unsigned Flags ) { @@ -400,7 +398,7 @@ extern "C" , RuntimeLang , SizeInBits , AlignInBits - , Flags + , static_cast( Flags ) ); return wrap( type ); } @@ -411,7 +409,7 @@ extern "C" , LLVMMetadataRef File , unsigned Line , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , uint64_t OffsetInBits , unsigned Flags , LLVMMetadataRef Ty @@ -425,7 +423,7 @@ extern "C" , SizeInBits , AlignInBits , OffsetInBits - , Flags + , static_cast( Flags ) , unwrap( Ty ) ); return wrap( DT ); @@ -433,7 +431,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateArrayType( LLVMDIBuilderRef Dref , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , LLVMMetadataRef ElementType , LLVMMetadataRef Subscripts ) @@ -449,7 +447,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVectorType( LLVMDIBuilderRef Dref , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , LLVMMetadataRef ElementType , LLVMMetadataRef Subscripts ) @@ -569,7 +567,7 @@ extern "C" , LLVMMetadataRef File // DIFile , unsigned LineNumber , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , LLVMMetadataRef Elements // DINodeArray , LLVMMetadataRef UnderlyingType // DIType , char const* UniqueId @@ -604,28 +602,30 @@ extern "C" return ( LLVMDwarfTag )desc->getTag( ); } - LLVMMetadataRef LLVMDIBuilderCreateGlobalVariable( LLVMDIBuilderRef Dref - , LLVMMetadataRef Context - , char const* Name - , char const* LinkageName - , LLVMMetadataRef File // DIFile - , unsigned LineNo - , LLVMMetadataRef Ty //DITypeRef - , LLVMBool isLocalToUnit - , LLVMValueRef Val - , LLVMMetadataRef Decl // = nullptr - ) + LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression( LLVMDIBuilderRef Dref + , LLVMMetadataRef Context //DIScope + , char const* Name + , char const* LinkageName + , LLVMMetadataRef File // DIFile + , unsigned LineNo + , LLVMMetadataRef Ty //DIType + , LLVMBool isLocalToUnit + , LLVMMetadataRef expression // DIExpression + , LLVMMetadataRef Decl // MDNode = nullptr + , uint32_t AlignInBits + ) { DIBuilder* D = unwrap( Dref ); - DIGlobalVariable* globalVar = D->createGlobalVariable( unwrap( Context ) + auto globalVar = D->createGlobalVariableExpression( unwrap( Context ) , Name , LinkageName , File ? unwrap( File ) : nullptr , LineNo , unwrap( Ty ) , isLocalToUnit - , unwrap( Val ) + , expression ? unwrap( expression ) : nullptr , Decl ? unwrap( Decl ) : nullptr + , AlignInBits ); return wrap( globalVar ); } @@ -701,13 +701,14 @@ extern "C" return pSub->describes( unwrap( F ) ); } - LLVMMetadataRef LLVMDIBuilderCreateNamespace( LLVMDIBuilderRef Dref, LLVMMetadataRef scope, char const* name, LLVMMetadataRef file, unsigned line ) + LLVMMetadataRef LLVMDIBuilderCreateNamespace( LLVMDIBuilderRef Dref, LLVMMetadataRef scope, char const* name, LLVMBool exportSymbols) { DIBuilder* D = unwrap( Dref ); DINamespace* pNamespace = D->createNameSpace( scope ? unwrap( scope ) : nullptr , name - , file ? unwrap( file ) : nullptr - , line + , nullptr + , 0 + , exportSymbols ); return wrap( pNamespace ); } diff --git a/src/LibLLVM/DIBuilderBindings.h b/src/LibLLVM/DIBuilderBindings.h index 10f01dd30..7de71219a 100644 --- a/src/LibLLVM/DIBuilderBindings.h +++ b/src/LibLLVM/DIBuilderBindings.h @@ -238,17 +238,16 @@ extern "C" { , unsigned Flags ); - LLVMMetadataRef LLVMDIBuilderCreateBasicType( LLVMDIBuilderRef D + LLVMMetadataRef LLVMDIBuilderCreateBasicType( LLVMDIBuilderRef Dref , const char *Name , uint64_t SizeInBits - , uint64_t AlignInBits , unsigned Encoding ); - LLVMMetadataRef LLVMDIBuilderCreatePointerType( LLVMDIBuilderRef D + LLVMMetadataRef LLVMDIBuilderCreatePointerType( LLVMDIBuilderRef Dref , LLVMMetadataRef PointeeType , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , const char *Name ); @@ -268,7 +267,7 @@ extern "C" { , LLVMMetadataRef File , unsigned Line , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , unsigned Flags , LLVMMetadataRef DerivedFrom , LLVMMetadataRef ElementTypes @@ -280,7 +279,7 @@ extern "C" { , LLVMMetadataRef File , unsigned Line , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , unsigned Flags , LLVMMetadataRef ElementTypes ); @@ -293,7 +292,7 @@ extern "C" { , unsigned Line , unsigned RuntimeLang , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , unsigned Flags ); @@ -303,7 +302,7 @@ extern "C" { , LLVMMetadataRef File , unsigned Line , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , uint64_t OffsetInBits , unsigned Flags , LLVMMetadataRef Ty @@ -311,14 +310,14 @@ extern "C" { LLVMMetadataRef LLVMDIBuilderCreateArrayType( LLVMDIBuilderRef D , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , LLVMMetadataRef ElementType , LLVMMetadataRef Subscripts ); LLVMMetadataRef LLVMDIBuilderCreateVectorType( LLVMDIBuilderRef D , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , LLVMMetadataRef ElementType , LLVMMetadataRef Subscripts ); @@ -385,7 +384,7 @@ extern "C" { , LLVMMetadataRef File // DIFile , unsigned LineNumber , uint64_t SizeInBits - , uint64_t AlignInBits + , uint32_t AlignInBits , LLVMMetadataRef Elements // DIArray , LLVMMetadataRef UnderlyingType // DIType , char const* @@ -460,7 +459,7 @@ extern "C" { LLVMMetadataRef LLVMDILocation( LLVMContextRef context, unsigned Line, unsigned Column, LLVMMetadataRef scope, LLVMMetadataRef InlinedAt ); LLVMBool LLVMSubProgramDescribes( LLVMMetadataRef subProgram, LLVMValueRef /*const Function **/F ); - LLVMMetadataRef LLVMDIBuilderCreateNamespace( LLVMDIBuilderRef Dref, LLVMMetadataRef scope, char const* name, LLVMMetadataRef file, unsigned line ); + LLVMMetadataRef LLVMDIBuilderCreateNamespace( LLVMDIBuilderRef Dref, LLVMMetadataRef scope, char const* name, LLVMBool exportSymbols ); LLVMContextRef LLVMGetNodeContext( LLVMMetadataRef /*MDNode*/ node ); LLVMMetadataKind LLVMGetMetadataID( LLVMMetadataRef /*Metadata*/ md ); diff --git a/src/LibLLVM/EXPORTS.DEF b/src/LibLLVM/EXPORTS.DEF index 185705a9f..5eae50b5b 100644 --- a/src/LibLLVM/EXPORTS.DEF +++ b/src/LibLLVM/EXPORTS.DEF @@ -1,1074 +1,1047 @@ -EXPORTS -; extensions to standard LLVM-C API -LLVMParseTriple -LLVMDisposeTriple -LLVMTripleOpEqual -LLVMTripleGetArchType -LLVMTripleGetSubArchType -LLVMTripleGetVendorType -LLVMTripleGetOsType -LLVMTripleHasEnvironment -LLVMTripleGetEnvironmentType -LLVMTripleGetEnvironmentVersion -LLVMTripleGetObjectFormatType -LLVMTripleAsString -LLVMTripleGetArchTypeName -LLVMTripleGetSubArchTypeName -LLVMTripleGetVendorTypeName -LLVMTripleGetOsTypeName -LLVMTripleGetEnvironmentTypeName -LLVMTripleGetObjectFormatTypeName -LLVMNormalizeTriple - -LLVMModuleEnumerateComdats -LLVMModuleInsertOrUpdateComdat -LLVMModuleComdatRemove -LLVMModuleComdatClear -LLVMComdatGetKind -LLVMComdatSetKind -LLVMComdatGetName -LLVMGlobalObjectGetComdat -LLVMGlobalObjectSetComdat - -LLVMInitializePassesForLegacyOpt -LLVMRunLegacyOptimizer -LLVMRunPassPipeline -LLVMInitializeCodeGenForOpt -LLVMCreatePassRegistry -LLVMPassRegistryDispose -LLVMAddModuleFlag -LLVMAddModuleFlagMetadata -LLVMModuleGetModuleFlagsMetadata -LLVMNamedMDNodeGetNumOperands -LLVMNamedMDNodeGetOperand -LLVMNamedMDNodeGetParentModule -LLVMVerifyFunctionEx -LLVMConstantAsMetadata -LLVMMDString2 -LLVMMDNode2 -LLVMTemporaryMDNode -LLVMAddNamedMetadataOperand2 -LLVMSetMetadata2 -LLVMMetadataReplaceAllUsesWith -LLVMSetCurrentDebugLocation2 -LLVMIsConstantZeroValue -LLVMRemoveGlobalFromParent -LLVMGetOrInsertFunction -LLVMBuildIntCast2 -LLVMGetValueID -LLVMMetadataAsValue -LLVMGetModuleName -LLVMIsTemporary -LLVMIsResolved -LLVMIsUniqued -LLVMIsDistinct -LLVMGetMDStringText -LLVMGetGlobalAlias -LLVMGetAliasee -LLVMMDNodeResolveCycles -LLVMGetArgumentIndex -LLVMGetVersionInfo -LLVMFunctionHasPersonalityFunction - -; Debug info functions not part of standard LLVM-C API -LLVMDIScopeGetFile -LLVMFunctionGetSubprogram -LLVMFunctionSetSubprogram -LLVMGetMetadataID -LLVMGetNodeContext -LLVMGetDIFileName -LLVMGetDIFileDirectory -LLVMGetDILocationScope -LLVMGetDILocationLine -LLVMGetDILocationColumn -LLVMGetDILocationInlinedAt -LLVMDILocationGetInlinedAtScope -LLVMSetDILocation -LLVMSetDebugLoc -LLVMNewDIBuilder -LLVMDIBuilderDestroy -LLVMDIBuilderFinalize -LLVMDIBuilderCreateCompileUnit -LLVMDIBuilderCreateFile -LLVMDIBuilderCreateLexicalBlock -LLVMDIBuilderCreateLexicalBlockFile -LLVMDIBuilderCreateFunction -LLVMDIBuilderCreateTempFunctionFwdDecl -LLVMDIBuilderCreateAutoVariable -LLVMDIBuilderCreateParameterVariable -LLVMDIBuilderCreateBasicType -LLVMDIBuilderCreatePointerType -LLVMDIBuilderCreateQualifiedType -LLVMDIBuilderCreateSubroutineType -LLVMDIBuilderCreateStructType -LLVMDIBuilderCreateUnionType -LLVMDIBuilderCreateReplaceableCompositeType -LLVMDIBuilderCreateMemberType -LLVMDIBuilderCreateArrayType -LLVMDIBuilderCreateVectorType -LLVMDIBuilderCreateTypedef -LLVMDIBuilderGetOrCreateSubrange -LLVMDIBuilderGetOrCreateArray -LLVMDIBuilderGetOrCreateTypeArray -LLVMDIBuilderCreateExpression -LLVMDIBuilderInsertDeclareAtEnd -LLVMDIBuilderInsertValueAtEnd -LLVMDIBuilderCreateEnumerationType -LLVMDIBuilderCreateEnumeratorValue -LLVMDIDescriptorGetTag -LLVMDIBuilderCreateGlobalVariable -LLVMDIBuilderInsertDeclareBefore -LLVMDIBuilderInsertValueBefore -LLVMDIBuilderCreateNamespace -LLVMMetadataAsString -LLVMMDNodeReplaceAllUsesWith -LLVMDILocation -LLVMSubProgramDescribes - -LLVMDITypeGetLine -LLVMDITypeGetSizeInBits -LLVMDITypeGetAlignInBits -LLVMDITypeGetOffsetInBits -LLVMDITypeGetFlags -LLVMDITypeGetScope -LLVMDITypeGetName - -LLVMMDNodeGetNumOperands -LLVMMDNodeGetOperand -LLVMGetOperandNode -LLVMDILocalScopeGetSubProgram - -; AttributeSet manipulation -LLVMCreateEmptyAttributeSet -LLVMCreateAttributeSetFromKindArray -LLVMCreateAttributeSetFromAttributeSetArray -LLVMCreateAttributeSetFromBuilder -LLVMAttributeSetAddKind -LLVMAttributeSetAddString -LLVMAttributeSetAddStringValue -LLVMAttributeSetAddAttributes -LLVMAttributeSetRemoveAttributeKind -LLVMAttributeSetRemoveAttributeSet -LLVMAttributeSetRemoveAttributeBuilder -LLVMAttributeSetGetContext -LLVMAttributeGetAttributes -LLVMAttributeSetHasAttributeKind -LLVMAttributeSetHasStringAttribute -LLVMAttributeSetHasAttributes -LLVMAttributeSetHasAttributeSomewhere -LLVMAttributeSetGetAttributeByKind -LLVMAttributeSetGetAttributeByName -LLVMAttributeSetToString -LLVMAttributeSetGetNumSlots -LLVMAttributeSetGetSlotAttributes -LLVMAttributeSetGetSlotIndex -LLVMGetFunctionAttributeSet -LLVMSetFunctionAttributeSet -LLVMGetCallSiteAttributeSet -LLVMSetCallSiteAttributeSet -LLVMAttributeSetGetIteratorStartToken -LLVMAttributeSetIteratorGetNext - -LLVMIsEnumAttribute -LLVMIsIntAttribute -LLVMIsStringAttribute -LLVMHasAttributeKind -LLVMHasAttributeString -LLVMGetAttributeKind -LLVMGetAttributeValue -LLVMGetAttributeName -LLVMGetAttributeStringValue -LLVMAttributeToString -LLVMCreateAttribute -LVMCreateTargetDependentAttribute - -;Attribute class wrappers -LLVMIsEnumAttribute -LLVMIsIntAttribute -LLVMIsStringAttribute -LLVMHasAttributeKind -LLVMHasAttributeString -LLVMGetAttributeKind -LLVMGetAttributeValue -LLVMGetAttributeName -LLVMGetAttributeStringValue -LLVMAttributeToString -LLVMCreateAttribute -LVMCreateTargetDependentAttribute - -LLVMCreateAttributeBuilder -LLVMCreateAttributeBuilder2 -LLVMCreateAttributeBuilder3 -LLVMAttributeBuilderDispose -LLVMAttributeBuilderClear - -LLVMAttributeBuilderAddEnum -LLVMAttributeBuilderAddAttribute -LLVMAttributeBuilderAddStringAttribute -LLVMAttributeBuilderRemoveEnum -LLVMAttributeBuilderRemoveAttributes -LLVMAttributeBuilderRemoveAttribute -LLVMAttributeBuilderRemoveBldr - -LLVMAttributeBuilderMerge -LLVMAttributeBuilderOverlaps -LLVMAttributeBuilderContainsEnum -LLVMAttributeBuilderContainsName -LLVMAttributeBuilderHasAnyAttributes -LLVMAttributeBuilderHasAttributes -LLVMAttributeBuilderHasTargetIndependentAttrs -LLVMAttributeBuilderHasTargetDependentAttrs - - -; Instrumentation Bindings -LLVMAddAddressSanitizerFunctionPass -LLVMAddAddressSanitizerModulePass -LLVMAddThreadSanitizerPass -LLVMAddMemorySanitizerPass -LLVMAddDataFlowSanitizerPass - -; Redirecting to non-inlined functions for inlined LLVM-C APIs -LLVMInitializeAllAsmParsers = LLVMInitializeAllAsmParsersExport -LLVMInitializeAllAsmPrinters = LLVMInitializeAllAsmPrintersExport -LLVMInitializeAllTargets = LLVMInitializeAllTargetsExport -LLVMInitializeAllTargetMCs = LLVMInitializeAllTargetMCsExport -LLVMInitializeAllDisassemblers = LLVMInitializeAllDisassemblersExport -LLVMInitializeAllTargetInfos = LLVMInitializeAllTargetInfosExport -LLVMInitializeNativeTarget = LLVMInitializeNativeTargetExport -LLVMInitializeNativeAsmParser = LLVMInitializeNativeAsmParserExport -LLVMInitializeNativeAsmPrinter = LLVMInitializeNativeAsmPrinterExport -LLVMInitializeNativeDisassembler = LLVMInitializeNativeDisassemblerExport - -;LTO APIs -;llvm_create_optimizer -;llvm_destroy_optimizer -;llvm_read_object_file -;llvm_optimize_modules -;lto_get_version -;lto_get_error_message -;lto_module_is_object_file -;lto_module_is_object_file_for_target -;lto_module_is_object_file_in_memory -;lto_module_is_object_file_in_memory_for_target -;lto_module_create -;lto_module_create_from_memory -;lto_module_create_from_memory_with_path -;lto_module_create_in_local_context -;lto_module_create_in_codegen_context -;lto_module_create_from_fd -;lto_module_create_from_fd_at_offset -;lto_module_dispose -;lto_module_get_target_triple -;lto_module_set_target_triple -;lto_module_get_num_symbols -;lto_module_get_symbol_name -;lto_module_get_symbol_attribute -;lto_module_get_num_deplibs -;lto_module_get_deplib -;lto_module_get_num_linkeropts -;lto_module_get_linkeropt -;lto_codegen_set_diagnostic_handler -;lto_codegen_create -;lto_codegen_create_in_local_context -;lto_codegen_dispose -;lto_codegen_add_module -;lto_codegen_set_debug_model -;lto_codegen_set_pic_model -;lto_codegen_set_cpu -;lto_codegen_set_assembler_path -;lto_codegen_set_assembler_args -;lto_codegen_add_must_preserve_symbol -;lto_codegen_write_merged_modules -;lto_codegen_compile -;lto_codegen_compile_to_file -;lto_codegen_debug_options -;lto_initialize_disassembler - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; standard LLVM-C API exports -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -LLVMInitializeAArch64AsmParser -LLVMInitializeAArch64AsmPrinter -LLVMInitializeAArch64Target -LLVMInitializeAArch64TargetMC -LLVMInitializeAArch64Disassembler -LLVMInitializeAArch64TargetInfo -LLVMInitializeAnalysis -LLVMVerifyFunction -LLVMVerifyModule -LLVMViewFunctionCFG -LLVMViewFunctionCFGOnly -LLVMInitializeARMAsmParser -LLVMInitializeARMAsmPrinter -LLVMInitializeARMTarget -LLVMInitializeARMTargetMC -LLVMInitializeARMDisassembler -LLVMInitializeARMTargetInfo -LLVMGetBitcodeModule -LLVMGetBitcodeModuleInContext -LLVMParseBitcode -LLVMParseBitcodeInContext -LLVMWriteBitcodeToFD -LLVMWriteBitcodeToFile -LLVMWriteBitcodeToFileHandle -LLVMWriteBitcodeToMemoryBuffer -LLVMInitializeCodeGen -LLVMAddAlias -LLVMAddCase -LLVMAddClause -LLVMAddDestination -LLVMAddFunction -LLVMAddGlobal -LLVMAddGlobalInAddressSpace -LLVMAddIncoming -LLVMAddNamedMetadataOperand -LLVMAlignOf -LLVMAppendBasicBlock -LLVMAppendBasicBlockInContext -LLVMArrayType -LLVMBasicBlockAsValue -LLVMBlockAddress -LLVMBuildAShr -LLVMBuildAdd -LLVMBuildAddrSpaceCast -LLVMBuildAggregateRet -LLVMBuildAlloca -LLVMBuildAnd -LLVMBuildArrayAlloca -LLVMBuildArrayMalloc -LLVMBuildAtomicCmpXchg -LLVMBuildAtomicRMW -LLVMBuildBinOp -LLVMBuildBitCast -LLVMBuildBr -LLVMBuildCall -LLVMBuildCast -LLVMBuildCondBr -LLVMBuildExactSDiv -LLVMBuildExtractElement -LLVMBuildExtractValue -LLVMBuildFAdd -LLVMBuildFCmp -LLVMBuildFDiv -LLVMBuildFMul -LLVMBuildFNeg -LLVMBuildFPCast -LLVMBuildFPExt -LLVMBuildFPToSI -LLVMBuildFPToUI -LLVMBuildFPTrunc -LLVMBuildFRem -LLVMBuildFSub -LLVMBuildFence -LLVMBuildFree -LLVMBuildGEP -LLVMBuildGlobalString -LLVMBuildGlobalStringPtr -LLVMBuildICmp -LLVMBuildInBoundsGEP -LLVMBuildIndirectBr -LLVMBuildInsertElement -LLVMBuildInsertValue -LLVMBuildIntCast -LLVMBuildIntToPtr -LLVMBuildInvoke -LLVMBuildIsNotNull -LLVMBuildIsNull -LLVMBuildLShr -LLVMBuildLandingPad -LLVMBuildLoad -LLVMBuildMalloc -LLVMBuildMul -LLVMBuildNSWAdd -LLVMBuildNSWMul -LLVMBuildNSWNeg -LLVMBuildNSWSub -LLVMBuildNUWAdd -LLVMBuildNUWMul -LLVMBuildNUWNeg -LLVMBuildNUWSub -LLVMBuildNeg -LLVMBuildNot -LLVMBuildOr -LLVMBuildPhi -LLVMBuildPointerCast -LLVMBuildPtrDiff -LLVMBuildPtrToInt -LLVMBuildResume -LLVMBuildRet -LLVMBuildRetVoid -LLVMBuildSDiv -LLVMBuildSExt -LLVMBuildSExtOrBitCast -LLVMBuildSIToFP -LLVMBuildSRem -LLVMBuildSelect -LLVMBuildShl -LLVMBuildShuffleVector -LLVMBuildStore -LLVMBuildStructGEP -LLVMBuildSub -LLVMBuildSwitch -LLVMBuildTrunc -LLVMBuildTruncOrBitCast -LLVMBuildUDiv -LLVMBuildUIToFP -LLVMBuildURem -LLVMBuildUnreachable -LLVMBuildVAArg -LLVMBuildXor -LLVMBuildZExt -LLVMBuildZExtOrBitCast -LLVMClearInsertionPosition -LLVMConstAShr -LLVMConstAdd -LLVMConstAddrSpaceCast -LLVMConstAllOnes -LLVMConstAnd -LLVMConstArray -LLVMConstBitCast -LLVMConstExactSDiv -LLVMConstExtractElement -LLVMConstExtractValue -LLVMConstFAdd -LLVMConstFCmp -LLVMConstFDiv -LLVMConstFMul -LLVMConstFNeg -LLVMConstFPCast -LLVMConstFPExt -LLVMConstFPToSI -LLVMConstFPToUI -LLVMConstFPTrunc -LLVMConstFRem -LLVMConstFSub -LLVMConstGEP -LLVMConstICmp -LLVMConstInBoundsGEP -LLVMConstInlineAsm -LLVMConstInsertElement -LLVMConstInsertValue -LLVMConstInt -LLVMConstIntCast -LLVMConstIntGetSExtValue -LLVMConstIntGetZExtValue -LLVMConstIntOfArbitraryPrecision -LLVMConstIntOfString -LLVMConstIntOfStringAndSize -LLVMConstIntToPtr -LLVMConstLShr -LLVMConstMul -LLVMConstNSWAdd -LLVMConstNSWMul -LLVMConstNSWNeg -LLVMConstNSWSub -LLVMConstNUWAdd -LLVMConstNUWMul -LLVMConstNUWNeg -LLVMConstNUWSub -LLVMConstNamedStruct -LLVMConstNeg -LLVMConstNot -LLVMConstNull -LLVMConstOr -LLVMConstPointerCast -LLVMConstPointerNull -LLVMConstPtrToInt -LLVMConstReal -LLVMConstRealGetDouble -LLVMConstRealOfString -LLVMConstRealOfStringAndSize -LLVMConstSDiv -LLVMConstSExt -LLVMConstSExtOrBitCast -LLVMConstSIToFP -LLVMConstSRem -LLVMConstSelect -LLVMConstShl -LLVMConstShuffleVector -LLVMConstString -LLVMConstStringInContext -LLVMConstStruct -LLVMConstStructInContext -LLVMConstSub -LLVMConstTrunc -LLVMConstTruncOrBitCast -LLVMConstUDiv -LLVMConstUIToFP -LLVMConstURem -LLVMConstVector -LLVMConstXor -LLVMConstZExt -LLVMConstZExtOrBitCast -LLVMContextCreate -LLVMContextDispose -LLVMContextSetDiagnosticHandler -LLVMContextSetYieldCallback -LLVMCountBasicBlocks -LLVMCountIncoming -LLVMCountParamTypes -LLVMCountParams -LLVMCountStructElementTypes -LLVMCreateBuilder -LLVMCreateBuilderInContext -LLVMCreateFunctionPassManager -LLVMCreateFunctionPassManagerForModule -LLVMCreateMemoryBufferWithContentsOfFile -LLVMCreateMemoryBufferWithMemoryRange -LLVMCreateMemoryBufferWithMemoryRangeCopy -LLVMCreateMemoryBufferWithSTDIN -LLVMCreateMessage -LLVMCreateModuleProviderForExistingModule -LLVMCreatePassManager -LLVMDeleteBasicBlock -LLVMDeleteFunction -LLVMDeleteGlobal -LLVMDisposeBuilder -LLVMDisposeMemoryBuffer -LLVMDisposeMessage -LLVMDisposeModule -LLVMDisposeModuleProvider -LLVMDisposePassManager -LLVMDoubleType -LLVMDoubleTypeInContext -LLVMDumpModule -LLVMDumpType -LLVMDumpValue -LLVMFP128Type -LLVMFP128TypeInContext -LLVMFinalizeFunctionPassManager -LLVMFloatType -LLVMFloatTypeInContext -LLVMFunctionType -LLVMGetAlignment -LLVMGetArrayLength -LLVMGetAsString -LLVMGetBasicBlockParent -LLVMGetBasicBlockTerminator -LLVMGetBasicBlocks -LLVMGetBufferSize -LLVMGetBufferStart -LLVMGetCondition -LLVMGetConstOpcode -LLVMGetCurrentDebugLocation -LLVMGetDLLStorageClass -LLVMGetDataLayout -LLVMGetDiagInfoDescription -LLVMGetDiagInfoSeverity -LLVMGetElementAsConstant -LLVMGetElementType -LLVMGetEntryBasicBlock -LLVMGetFCmpPredicate -LLVMGetFirstBasicBlock -LLVMGetFirstFunction -LLVMGetFirstGlobal -LLVMGetFirstInstruction -LLVMGetFirstParam -LLVMGetFirstUse -LLVMGetFunctionCallConv -LLVMGetGC -LLVMGetGlobalContext -LLVMGetGlobalParent -LLVMGetGlobalPassRegistry -LLVMGetICmpPredicate -LLVMGetIncomingBlock -LLVMGetIncomingValue -LLVMGetInitializer -LLVMGetInsertBlock -LLVMGetInstructionCallConv -LLVMGetInstructionOpcode -LLVMGetInstructionParent -LLVMGetIntTypeWidth -LLVMGetIntrinsicID -LLVMGetLastBasicBlock -LLVMGetLastFunction -LLVMGetLastGlobal -LLVMGetLastInstruction -LLVMGetLastParam -LLVMGetLinkage -LLVMGetMDKindID -LLVMGetMDKindIDInContext -LLVMGetMDNodeNumOperands -LLVMGetMDNodeOperands -LLVMGetMDString -LLVMGetMetadata -LLVMGetModuleContext -LLVMGetNamedFunction -LLVMGetNamedGlobal -LLVMGetNamedMetadataNumOperands -LLVMGetNamedMetadataOperands -LLVMGetNextBasicBlock -LLVMGetNextFunction -LLVMGetNextGlobal -LLVMGetNextInstruction -LLVMGetNextParam -LLVMGetNextUse -LLVMGetNumOperands -LLVMGetNumSuccessors -LLVMGetOperand -LLVMGetOperandUse -LLVMGetParam -LLVMGetParamParent -LLVMGetParamTypes -LLVMGetParams -LLVMGetPersonalityFn -LLVMGetPointerAddressSpace -LLVMGetPreviousBasicBlock -LLVMGetPreviousFunction -LLVMGetPreviousGlobal -LLVMGetPreviousInstruction -LLVMGetPreviousParam -LLVMGetReturnType -LLVMGetSection -LLVMGetStructElementTypes -LLVMGetStructName -LLVMGetSuccessor -LLVMGetSwitchDefaultDest -LLVMGetTarget -LLVMGetThreadLocalMode -LLVMGetTypeByName -LLVMGetTypeContext -LLVMGetTypeKind -LLVMGetUndef -LLVMGetUsedValue -LLVMGetUser -LLVMGetValueName -LLVMGetVectorSize -LLVMGetVisibility -LLVMGetVolatile -LLVMGetOrdering -LLVMHalfType -LLVMHalfTypeInContext -LLVMHasMetadata -LLVMHasUnnamedAddr -LLVMInitializeCore -LLVMInitializeFunctionPassManager -LLVMInsertBasicBlock -LLVMInsertBasicBlockInContext -LLVMInsertIntoBuilder -LLVMInsertIntoBuilderWithName -LLVMInstructionClone -LLVMInstructionEraseFromParent -LLVMInt16Type -LLVMInt16TypeInContext -LLVMInt1Type -LLVMInt1TypeInContext -LLVMInt32Type -LLVMInt32TypeInContext -LLVMInt64Type -LLVMInt64TypeInContext -LLVMInt128Type -LLVMInt128TypeInContext -LLVMInt8Type -LLVMInt8TypeInContext -LLVMIntType -LLVMIntTypeInContext -LLVMIsAAddrSpaceCastInst -LLVMIsAAllocaInst -LLVMIsAArgument -LLVMIsABasicBlock -LLVMIsABinaryOperator -LLVMIsABitCastInst -LLVMIsABlockAddress -LLVMIsABranchInst -LLVMIsACallInst -LLVMIsACastInst -LLVMIsACmpInst -LLVMIsAConstant -LLVMIsAConstantAggregateZero -LLVMIsAConstantArray -LLVMIsAConstantDataArray -LLVMIsAConstantDataSequential -LLVMIsAConstantDataVector -LLVMIsAConstantExpr -LLVMIsAConstantFP -LLVMIsAConstantInt -LLVMIsAConstantPointerNull -LLVMIsAConstantStruct -LLVMIsAConstantVector -LLVMIsADbgDeclareInst -LLVMIsADbgInfoIntrinsic -LLVMIsAExtractElementInst -LLVMIsAExtractValueInst -LLVMIsAFCmpInst -LLVMIsAFPExtInst -LLVMIsAFPToSIInst -LLVMIsAFPToUIInst -LLVMIsAFPTruncInst -LLVMIsAFunction -LLVMIsAGetElementPtrInst -LLVMIsAGlobalAlias -LLVMIsAGlobalObject -LLVMIsAGlobalValue -LLVMIsAGlobalVariable -LLVMIsAICmpInst -LLVMIsAIndirectBrInst -LLVMIsAInlineAsm -LLVMIsAInsertElementInst -LLVMIsAInsertValueInst -LLVMIsAInstruction -LLVMIsAIntToPtrInst -LLVMIsAIntrinsicInst -LLVMIsAInvokeInst -LLVMIsALandingPadInst -LLVMIsALoadInst -LLVMIsAMDNode -LLVMIsAMDString -LLVMIsAMemCpyInst -LLVMIsAMemIntrinsic -LLVMIsAMemMoveInst -LLVMIsAMemSetInst -LLVMIsAPHINode -LLVMIsAPtrToIntInst -LLVMIsAResumeInst -LLVMIsAReturnInst -LLVMIsASExtInst -LLVMIsASIToFPInst -LLVMIsASelectInst -LLVMIsAShuffleVectorInst -LLVMIsAStoreInst -LLVMIsASwitchInst -LLVMIsATerminatorInst -LLVMIsATruncInst -LLVMIsAUIToFPInst -LLVMIsAUnaryInstruction -LLVMIsAUndefValue -LLVMIsAUnreachableInst -LLVMIsAUser -LLVMIsAVAArgInst -LLVMIsAZExtInst -LLVMIsConditional -LLVMIsConstant -LLVMIsConstantString -LLVMIsDeclaration -LLVMIsExternallyInitialized -LLVMIsFunctionVarArg -LLVMIsGlobalConstant -LLVMIsMultithreaded -LLVMIsNull -LLVMIsOpaqueStruct -LLVMIsPackedStruct -LLVMIsTailCall -LLVMIsThreadLocal -LLVMIsUndef -LLVMLabelType -LLVMLabelTypeInContext -LLVMMDNode -LLVMMDNodeInContext -LLVMMDString -LLVMMDStringInContext -LLVMModuleCreateWithName -LLVMModuleCreateWithNameInContext -LLVMMoveBasicBlockAfter -LLVMMoveBasicBlockBefore -LLVMPPCFP128Type -LLVMPPCFP128TypeInContext -LLVMPointerType -LLVMPositionBuilder -LLVMPositionBuilderAtEnd -LLVMPositionBuilderBefore -LLVMPrintModuleToFile -LLVMPrintModuleToString -LLVMPrintTypeToString -LLVMPrintValueToString -LLVMRemoveBasicBlockFromParent -LLVMReplaceAllUsesWith -LLVMRunFunctionPassManager -LLVMRunPassManager -LLVMSetAlignment -LLVMSetCleanup -LLVMSetCondition -LLVMSetCurrentDebugLocation -LLVMSetDLLStorageClass -LLVMSetDataLayout -LLVMSetExternallyInitialized -LLVMSetFunctionCallConv -LLVMSetGC -LLVMSetGlobalConstant -LLVMSetInitializer -LLVMSetInstDebugLocation -LLVMSetInstrParamAlignment -LLVMSetInstructionCallConv -LLVMSetLinkage -LLVMSetMetadata -LLVMSetModuleInlineAsm -LLVMSetOperand -LLVMSetParamAlignment -LLVMSetPersonalityFn -LLVMSetSection -LLVMSetSuccessor -LLVMSetTailCall -LLVMSetTarget -LLVMSetThreadLocal -LLVMSetThreadLocalMode -LLVMSetUnnamedAddr -LLVMSetValueName -LLVMSetVisibility -LLVMSetVolatile -LLVMSetOrdering -LLVMShutdown -LLVMSizeOf -LLVMStartMultithreaded -LLVMStopMultithreaded -LLVMStructCreateNamed -LLVMStructSetBody -LLVMStructType -LLVMStructTypeInContext -LLVMTypeIsSized -LLVMTypeOf -LLVMValueAsBasicBlock -LLVMValueIsBasicBlock -LLVMVectorType -LLVMVoidType -LLVMVoidTypeInContext -LLVMX86FP80Type -LLVMX86FP80TypeInContext -LLVMX86MMXType -LLVMX86MMXTypeInContext -;LLVMInitializeCppBackendTarget -;LLVMInitializeCppBackendTargetInfo -;LLVMInitializeCppBackendTargetMC -LLVMAddGlobalMapping -LLVMAddModule -LLVMCreateExecutionEngineForModule -LLVMCreateGenericValueOfFloat -LLVMCreateGenericValueOfInt -LLVMCreateGenericValueOfPointer -LLVMCreateInterpreterForModule -LLVMCreateJITCompilerForModule -LLVMCreateMCJITCompilerForModule -LLVMCreateSimpleMCJITMemoryManager -LLVMDisposeExecutionEngine -LLVMDisposeGenericValue -LLVMDisposeMCJITMemoryManager -LLVMFindFunction -LLVMFreeMachineCodeForFunction -LLVMGenericValueIntWidth -LLVMGenericValueToFloat -LLVMGenericValueToInt -LLVMGenericValueToPointer -LLVMGetExecutionEngineTargetData -LLVMGetExecutionEngineTargetMachine -LLVMGetFunctionAddress -LLVMGetGlobalValueAddress -LLVMGetPointerToGlobal -LLVMInitializeMCJITCompilerOptions -LLVMRecompileAndRelinkFunction -LLVMRemoveModule -LLVMRunFunction -LLVMRunFunctionAsMain -LLVMRunStaticConstructors -LLVMRunStaticDestructors -LLVMInitializeHexagonAsmPrinter -LLVMInitializeHexagonTarget -LLVMInitializeHexagonTargetMC -LLVMInitializeHexagonDisassembler -LLVMInitializeHexagonTargetInfo -LLVMInitializeInstCombine -LLVMInitializeInstrumentation -LLVMLinkInInterpreter -LLVMInitializeIPA -LLVMAddAlwaysInlinerPass -LLVMAddArgumentPromotionPass -LLVMAddConstantMergePass -LLVMAddDeadArgEliminationPass -LLVMAddFunctionAttrsPass -LLVMAddFunctionInliningPass -LLVMAddGlobalDCEPass -LLVMAddGlobalOptimizerPass -LLVMAddIPConstantPropagationPass -LLVMAddIPSCCPPass -LLVMAddInternalizePass -LLVMAddPruneEHPass -LLVMAddStripDeadPrototypesPass -LLVMAddStripSymbolsPass -LLVMInitializeIPO -LLVMPassManagerBuilderCreate -LLVMPassManagerBuilderDispose -LLVMPassManagerBuilderPopulateFunctionPassManager -LLVMPassManagerBuilderPopulateLTOPassManager -LLVMPassManagerBuilderPopulateModulePassManager -LLVMPassManagerBuilderSetDisableSimplifyLibCalls -LLVMPassManagerBuilderSetDisableUnitAtATime -LLVMPassManagerBuilderSetDisableUnrollLoops -LLVMPassManagerBuilderSetOptLevel -LLVMPassManagerBuilderSetSizeLevel -LLVMPassManagerBuilderUseInlinerWithThreshold -LLVMParseIRInContext -LLVMLinkModules2 ; Previous version was deprecated in 3.8 and replaced, 3.90 removes it -LLVMCreateDisasm -LLVMCreateDisasmCPU -LLVMCreateDisasmCPUFeatures -LLVMDisasmDispose -LLVMDisasmInstruction -LLVMSetDisasmOptions -LLVMLinkInMCJIT -LLVMInitializeMipsAsmParser -LLVMInitializeMipsAsmPrinter -LLVMInitializeMipsTarget -LLVMInitializeMipsTargetMC -LLVMInitializeMipsDisassembler -LLVMInitializeMipsTargetInfo -LLVMInitializeMSP430Target -LLVMInitializeMSP430AsmPrinter -LLVMInitializeMSP430TargetMC -LLVMInitializeMSP430TargetInfo -LLVMInitializeNVPTXAsmPrinter -LLVMInitializeNVPTXTarget -LLVMInitializeNVPTXTargetMC -LLVMInitializeNVPTXTargetInfo -LLVMInitializeObjCARCOpts -LLVMCreateObjectFile -LLVMDisposeObjectFile -LLVMDisposeRelocationIterator -LLVMDisposeSectionIterator -LLVMDisposeSymbolIterator -LLVMGetRelocationOffset -LLVMGetRelocationSymbol -LLVMGetRelocationType -LLVMGetRelocationTypeName -LLVMGetRelocationValueString -LLVMGetRelocations -LLVMGetSectionAddress -LLVMGetSectionContainsSymbol -LLVMGetSectionContents -LLVMGetSectionName -LLVMGetSectionSize -LLVMGetSections -LLVMGetSymbolAddress -LLVMGetSymbolName -LLVMGetSymbolSize -LLVMGetSymbols -LLVMIsRelocationIteratorAtEnd -LLVMIsSectionIteratorAtEnd -LLVMIsSymbolIteratorAtEnd -LLVMMoveToContainingSection -LLVMMoveToNextRelocation -LLVMMoveToNextSection -LLVMMoveToNextSymbol -LLVMInitializePowerPCAsmParser -LLVMInitializePowerPCAsmPrinter -LLVMInitializePowerPCTarget -LLVMInitializePowerPCTargetMC -LLVMInitializePowerPCDisassembler -LLVMInitializePowerPCTargetInfo -LLVMInitializeAMDGPUAsmParser -LLVMInitializeAMDGPUAsmPrinter -LLVMInitializeAMDGPUTarget -LLVMInitializeAMDGPUTargetMC -LLVMInitializeAMDGPUTargetInfo -LLVMAddAggressiveDCEPass -LLVMAddAlignmentFromAssumptionsPass -LLVMAddBasicAliasAnalysisPass -LLVMAddCFGSimplificationPass -LLVMAddConstantPropagationPass -LLVMAddCorrelatedValuePropagationPass -LLVMAddDeadStoreEliminationPass -LLVMAddDemoteMemoryToRegisterPass -LLVMAddEarlyCSEPass -LLVMAddGVNPass -LLVMAddIndVarSimplifyPass -LLVMAddInstructionCombiningPass -LLVMAddJumpThreadingPass -LLVMAddLICMPass -LLVMAddLoopDeletionPass -LLVMAddLoopIdiomPass -LLVMAddLoopRerollPass -LLVMAddLoopRotatePass -LLVMAddLoopUnrollPass -LLVMAddLoopUnswitchPass -LLVMAddLowerExpectIntrinsicPass -LLVMAddLowerSwitchPass -LLVMAddMemCpyOptPass -LLVMAddMergedLoadStoreMotionPass -LLVMAddPartiallyInlineLibCallsPass -LLVMAddPromoteMemoryToRegisterPass -LLVMAddReassociatePass -LLVMAddSCCPPass -LLVMAddScalarReplAggregatesPass -LLVMAddScalarReplAggregatesPassSSA -LLVMAddScalarReplAggregatesPassWithThreshold -LLVMAddScalarizerPass -LLVMAddScopedNoAliasAAPass -LLVMAddSimplifyLibCallsPass -LLVMAddTailCallEliminationPass -LLVMAddTypeBasedAliasAnalysisPass -LLVMAddVerifierPass -LLVMInitializeScalarOpts -LLVMInitializeSparcAsmParser -LLVMInitializeSparcAsmPrinter -LLVMInitializeSparcTarget -LLVMInitializeSparcTargetMC -LLVMInitializeSparcDisassembler -LLVMInitializeSparcTargetInfo -LLVMParseCommandLineOptions -LLVMInstallFatalErrorHandler -LLVMResetFatalErrorHandler -LLVMEnablePrettyStackTrace -LLVMLoadLibraryPermanently -LLVMInitializeSystemZAsmParser -LLVMInitializeSystemZAsmPrinter -LLVMInitializeSystemZTarget -LLVMInitializeSystemZTargetMC -LLVMInitializeSystemZDisassembler -LLVMInitializeSystemZTargetInfo -LLVMABIAlignmentOfType -LLVMABISizeOfType -;LLVMAddTargetData ; removed in 3.9.0 -LLVMAddTargetLibraryInfo -LLVMByteOrder -LLVMCallFrameAlignmentOfType -LLVMCopyStringRepOfTargetData -LLVMCreateTargetData -LLVMDisposeTargetData -LLVMElementAtOffset -LLVMInitializeTarget -LLVMIntPtrType -LLVMIntPtrTypeForAS -LLVMIntPtrTypeForASInContext -LLVMIntPtrTypeInContext -LLVMOffsetOfElement -LLVMPointerSize -LLVMPointerSizeForAS -LLVMPreferredAlignmentOfGlobal -LLVMPreferredAlignmentOfType -LLVMSizeOfTypeInBits -LLVMStoreSizeOfType -LLVMAddAnalysisPasses -LLVMCreateTargetMachine -LLVMDisposeTargetMachine -LLVMGetDefaultTargetTriple -LLVMGetFirstTarget -LLVMGetNextTarget -LLVMGetTargetDescription -LLVMGetTargetFromName -LLVMGetTargetFromTriple -LLVMGetTargetMachineCPU -LLVMCreateTargetDataLayout; LLVMGetTargetMachineData - renamed in 3.9.0 -LLVMGetTargetMachineFeatureString -LLVMGetTargetMachineTarget -LLVMGetTargetMachineTriple -LLVMGetTargetName -LLVMSetTargetMachineAsmVerbosity -LLVMTargetHasAsmBackend -LLVMTargetHasJIT -LLVMTargetHasTargetMachine -LLVMTargetMachineEmitToFile -LLVMTargetMachineEmitToMemoryBuffer -LLVMCloneModule -LLVMInitializeTransformUtils -LLVMAddBBVectorizePass -LLVMAddLoopVectorizePass -LLVMAddSLPVectorizePass -LLVMInitializeVectorization -LLVMInitializeX86AsmParser -LLVMInitializeX86AsmPrinter -LLVMInitializeX86Target -LLVMInitializeX86TargetMC -LLVMInitializeX86Disassembler -LLVMInitializeX86TargetInfo -LLVMInitializeXCoreAsmPrinter -LLVMInitializeXCoreTarget -LLVMInitializeXCoreTargetMC -LLVMInitializeXCoreDisassembler -LLVMInitializeXCoreTargetInfo +EXPORTS +; extensions to standard LLVM-C API +LLVMParseTriple +LLVMDisposeTriple +LLVMTripleOpEqual +LLVMTripleGetArchType +LLVMTripleGetSubArchType +LLVMTripleGetVendorType +LLVMTripleGetOsType +LLVMTripleHasEnvironment +LLVMTripleGetEnvironmentType +LLVMTripleGetEnvironmentVersion +LLVMTripleGetObjectFormatType +LLVMTripleAsString +LLVMTripleGetArchTypeName +LLVMTripleGetSubArchTypeName +LLVMTripleGetVendorTypeName +LLVMTripleGetOsTypeName +LLVMTripleGetEnvironmentTypeName +LLVMTripleGetObjectFormatTypeName +LLVMNormalizeTriple + +LLVMModuleEnumerateComdats +LLVMModuleInsertOrUpdateComdat +LLVMModuleComdatRemove +LLVMModuleComdatClear +LLVMComdatGetKind +LLVMComdatSetKind +LLVMComdatGetName +LLVMGlobalObjectGetComdat +LLVMGlobalObjectSetComdat + +LLVMInitializePassesForLegacyOpt +LLVMRunLegacyOptimizer +LLVMRunPassPipeline +LLVMInitializeCodeGenForOpt +LLVMCreatePassRegistry +LLVMPassRegistryDispose +LLVMAddModuleFlag +LLVMAddModuleFlagMetadata +LLVMModuleGetModuleFlagsMetadata +LLVMNamedMDNodeGetNumOperands +LLVMNamedMDNodeGetOperand +LLVMNamedMDNodeGetParentModule +LLVMVerifyFunctionEx +LLVMConstantAsMetadata +LLVMMDString2 +LLVMMDNode2 +LLVMTemporaryMDNode +LLVMAddNamedMetadataOperand2 +LLVMSetMetadata2 +LLVMMetadataReplaceAllUsesWith +LLVMSetCurrentDebugLocation2 +LLVMIsConstantZeroValue +LLVMRemoveGlobalFromParent +LLVMGetOrInsertFunction +LLVMBuildIntCast2 +LLVMGetValueID +LLVMMetadataAsValue +LLVMGetModuleName +LLVMIsTemporary +LLVMIsResolved +LLVMIsUniqued +LLVMIsDistinct +LLVMGetMDStringText +LLVMGetGlobalAlias +LLVMGetAliasee +LLVMMDNodeResolveCycles +LLVMGetArgumentIndex +LLVMGetVersionInfo +LLVMDIGlobalVarExpGetVariable +LLVMGlobalVariableAddDebugExpression + +LLVMAttributeToString + +; Debug info functions not part of standard LLVM-C API +LLVMDIScopeGetFile +LLVMFunctionGetSubprogram +LLVMFunctionSetSubprogram +LLVMGetMetadataID +LLVMGetNodeContext +LLVMGetDIFileName +LLVMGetDIFileDirectory +LLVMGetDILocationScope +LLVMGetDILocationLine +LLVMGetDILocationColumn +LLVMGetDILocationInlinedAt +LLVMDILocationGetInlinedAtScope +LLVMSetDILocation +LLVMSetDebugLoc +LLVMNewDIBuilder +LLVMDIBuilderDestroy +LLVMDIBuilderFinalize +LLVMDIBuilderCreateCompileUnit +LLVMDIBuilderCreateFile +LLVMDIBuilderCreateLexicalBlock +LLVMDIBuilderCreateLexicalBlockFile +LLVMDIBuilderCreateFunction +LLVMDIBuilderCreateTempFunctionFwdDecl +LLVMDIBuilderCreateAutoVariable +LLVMDIBuilderCreateParameterVariable +LLVMDIBuilderCreateBasicType +LLVMDIBuilderCreatePointerType +LLVMDIBuilderCreateQualifiedType +LLVMDIBuilderCreateSubroutineType +LLVMDIBuilderCreateStructType +LLVMDIBuilderCreateUnionType +LLVMDIBuilderCreateReplaceableCompositeType +LLVMDIBuilderCreateMemberType +LLVMDIBuilderCreateArrayType +LLVMDIBuilderCreateVectorType +LLVMDIBuilderCreateTypedef +LLVMDIBuilderGetOrCreateSubrange +LLVMDIBuilderGetOrCreateArray +LLVMDIBuilderGetOrCreateTypeArray +LLVMDIBuilderCreateExpression +LLVMDIBuilderInsertDeclareAtEnd +LLVMDIBuilderInsertValueAtEnd +LLVMDIBuilderCreateEnumerationType +LLVMDIBuilderCreateEnumeratorValue +LLVMDIDescriptorGetTag +LLVMDIBuilderCreateGlobalVariableExpression +LLVMDIBuilderInsertDeclareBefore +LLVMDIBuilderInsertValueBefore +LLVMDIBuilderCreateNamespace +LLVMMetadataAsString +LLVMMDNodeReplaceAllUsesWith +LLVMDILocation +LLVMSubProgramDescribes + +LLVMDITypeGetLine +LLVMDITypeGetSizeInBits +LLVMDITypeGetAlignInBits +LLVMDITypeGetOffsetInBits +LLVMDITypeGetFlags +LLVMDITypeGetScope +LLVMDITypeGetName + +LLVMMDNodeGetNumOperands +LLVMMDNodeGetOperand +LLVMGetOperandNode +LLVMDILocalScopeGetSubProgram + +; Instrumentation Bindings +LLVMAddAddressSanitizerFunctionPass +LLVMAddAddressSanitizerModulePass +LLVMAddThreadSanitizerPass +LLVMAddMemorySanitizerPass +LLVMAddDataFlowSanitizerPass + +; Redirecting to non-inlined functions for inlined LLVM-C APIs +LLVMInitializeAllAsmParsers = LLVMInitializeAllAsmParsersExport +LLVMInitializeAllAsmPrinters = LLVMInitializeAllAsmPrintersExport +LLVMInitializeAllTargets = LLVMInitializeAllTargetsExport +LLVMInitializeAllTargetMCs = LLVMInitializeAllTargetMCsExport +LLVMInitializeAllDisassemblers = LLVMInitializeAllDisassemblersExport +LLVMInitializeAllTargetInfos = LLVMInitializeAllTargetInfosExport +LLVMInitializeNativeTarget = LLVMInitializeNativeTargetExport +LLVMInitializeNativeAsmParser = LLVMInitializeNativeAsmParserExport +LLVMInitializeNativeAsmPrinter = LLVMInitializeNativeAsmPrinterExport +LLVMInitializeNativeDisassembler = LLVMInitializeNativeDisassemblerExport + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; standard LLVM-C API exports +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +LLVMInitializeAArch64AsmParser +LLVMInitializeAArch64AsmPrinter +LLVMInitializeAArch64Target +LLVMInitializeAArch64TargetMC +LLVMInitializeAArch64Disassembler +LLVMInitializeAArch64TargetInfo +LLVMInitializeAMDGPUAsmParser +LLVMInitializeAMDGPUAsmPrinter +LLVMInitializeAMDGPUTarget +LLVMInitializeAMDGPUTargetMC +LLVMInitializeAMDGPUDisassembler +LLVMInitializeAMDGPUTargetInfo +LLVMInitializeAnalysis +LLVMInitializeIPA +LLVMVerifyFunction +LLVMVerifyModule +LLVMViewFunctionCFG +LLVMViewFunctionCFGOnly +LLVMInitializeARMAsmParser +LLVMInitializeARMAsmPrinter +LLVMInitializeARMTarget +LLVMInitializeARMTargetMC +LLVMInitializeARMDisassembler +LLVMInitializeARMTargetInfo +LLVMGetBitcodeModule +LLVMGetBitcodeModule2 +LLVMGetBitcodeModuleInContext +LLVMGetBitcodeModuleInContext2 +LLVMParseBitcode +LLVMParseBitcode2 +LLVMParseBitcodeInContext +LLVMParseBitcodeInContext2 +LLVMWriteBitcodeToFD +LLVMWriteBitcodeToFile +LLVMWriteBitcodeToFileHandle +LLVMWriteBitcodeToMemoryBuffer +LLVMInitializeBPFAsmPrinter +LLVMInitializeBPFTarget +LLVMInitializeBPFTargetMC +LLVMInitializeBPFTargetInfo +LLVMInitializeCodeGen +LLVMAddAlias +LLVMAddAttributeAtIndex +LLVMAddCallSiteAttribute +LLVMAddCase +LLVMAddClause +LLVMAddDestination +LLVMAddFunction +LLVMAddGlobal +LLVMAddGlobalInAddressSpace +LLVMAddIncoming +LLVMAddNamedMetadataOperand +LLVMAddTargetDependentFunctionAttr +LLVMAlignOf +LLVMAppendBasicBlock +LLVMAppendBasicBlockInContext +LLVMArrayType +LLVMBasicBlockAsValue +LLVMBlockAddress +LLVMBuildAShr +LLVMBuildAdd +LLVMBuildAddrSpaceCast +LLVMBuildAggregateRet +LLVMBuildAlloca +LLVMBuildAnd +LLVMBuildArrayAlloca +LLVMBuildArrayMalloc +LLVMBuildAtomicCmpXchg +LLVMBuildAtomicRMW +LLVMBuildBinOp +LLVMBuildBitCast +LLVMBuildBr +LLVMBuildCall +LLVMBuildCast +LLVMBuildCondBr +LLVMBuildExactSDiv +LLVMBuildExtractElement +LLVMBuildExtractValue +LLVMBuildFAdd +LLVMBuildFCmp +LLVMBuildFDiv +LLVMBuildFMul +LLVMBuildFNeg +LLVMBuildFPCast +LLVMBuildFPExt +LLVMBuildFPToSI +LLVMBuildFPToUI +LLVMBuildFPTrunc +LLVMBuildFRem +LLVMBuildFSub +LLVMBuildFence +LLVMBuildFree +LLVMBuildGEP +LLVMBuildGlobalString +LLVMBuildGlobalStringPtr +LLVMBuildICmp +LLVMBuildInBoundsGEP +LLVMBuildIndirectBr +LLVMBuildInsertElement +LLVMBuildInsertValue +LLVMBuildIntCast +LLVMBuildIntToPtr +LLVMBuildInvoke +LLVMBuildIsNotNull +LLVMBuildIsNull +LLVMBuildLShr +LLVMBuildLandingPad +LLVMBuildLoad +LLVMBuildMalloc +LLVMBuildMul +LLVMBuildNSWAdd +LLVMBuildNSWMul +LLVMBuildNSWNeg +LLVMBuildNSWSub +LLVMBuildNUWAdd +LLVMBuildNUWMul +LLVMBuildNUWNeg +LLVMBuildNUWSub +LLVMBuildNeg +LLVMBuildNot +LLVMBuildOr +LLVMBuildPhi +LLVMBuildPointerCast +LLVMBuildPtrDiff +LLVMBuildPtrToInt +LLVMBuildResume +LLVMBuildRet +LLVMBuildRetVoid +LLVMBuildSDiv +LLVMBuildSExt +LLVMBuildSExtOrBitCast +LLVMBuildSIToFP +LLVMBuildSRem +LLVMBuildSelect +LLVMBuildShl +LLVMBuildShuffleVector +LLVMBuildStore +LLVMBuildStructGEP +LLVMBuildSub +LLVMBuildSwitch +LLVMBuildTrunc +LLVMBuildTruncOrBitCast +LLVMBuildExactUDiv +LLVMBuildUDiv +LLVMBuildUIToFP +LLVMBuildURem +LLVMBuildUnreachable +LLVMBuildVAArg +LLVMBuildXor +LLVMBuildZExt +LLVMBuildZExtOrBitCast +LLVMClearInsertionPosition +LLVMConstAShr +LLVMConstAdd +LLVMConstAddrSpaceCast +LLVMConstAllOnes +LLVMConstAnd +LLVMConstArray +LLVMConstBitCast +LLVMConstExactSDiv +LLVMConstExtractElement +LLVMConstExtractValue +LLVMConstFAdd +LLVMConstFCmp +LLVMConstFDiv +LLVMConstFMul +LLVMConstFNeg +LLVMConstFPCast +LLVMConstFPExt +LLVMConstFPToSI +LLVMConstFPToUI +LLVMConstFPTrunc +LLVMConstFRem +LLVMConstFSub +LLVMConstGEP +LLVMConstICmp +LLVMConstInBoundsGEP +LLVMConstInlineAsm +LLVMConstInsertElement +LLVMConstInsertValue +LLVMConstInt +LLVMConstIntCast +LLVMConstIntGetSExtValue +LLVMConstIntGetZExtValue +LLVMConstIntOfArbitraryPrecision +LLVMConstIntOfString +LLVMConstIntOfStringAndSize +LLVMConstIntToPtr +LLVMConstLShr +LLVMConstMul +LLVMConstNSWAdd +LLVMConstNSWMul +LLVMConstNSWNeg +LLVMConstNSWSub +LLVMConstNUWAdd +LLVMConstNUWMul +LLVMConstNUWNeg +LLVMConstNUWSub +LLVMConstNamedStruct +LLVMConstNeg +LLVMConstNot +LLVMConstNull +LLVMConstOr +LLVMConstPointerCast +LLVMConstPointerNull +LLVMConstPtrToInt +LLVMConstReal +LLVMConstRealGetDouble +LLVMConstRealOfString +LLVMConstRealOfStringAndSize +LLVMConstSDiv +LLVMConstSExt +LLVMConstSExtOrBitCast +LLVMConstSIToFP +LLVMConstSRem +LLVMConstSelect +LLVMConstShl +LLVMConstShuffleVector +LLVMConstString +LLVMConstStringInContext +LLVMConstStruct +LLVMConstStructInContext +LLVMConstSub +LLVMConstTrunc +LLVMConstTruncOrBitCast +LLVMConstUDiv +LLVMConstExactUDiv +LLVMConstUIToFP +LLVMConstURem +LLVMConstVector +LLVMConstXor +LLVMConstZExt +LLVMConstZExtOrBitCast +LLVMContextCreate +LLVMContextDispose +LLVMContextGetDiagnosticContext +LLVMContextGetDiagnosticHandler +LLVMContextSetDiagnosticHandler +LLVMContextSetYieldCallback +LLVMCountBasicBlocks +LLVMCountIncoming +LLVMCountParamTypes +LLVMCountParams +LLVMCountStructElementTypes +LLVMCreateBuilder +LLVMCreateBuilderInContext +LLVMCreateEnumAttribute +LLVMCreateFunctionPassManager +LLVMCreateFunctionPassManagerForModule +LLVMCreateMemoryBufferWithContentsOfFile +LLVMCreateMemoryBufferWithMemoryRange +LLVMCreateMemoryBufferWithMemoryRangeCopy +LLVMCreateMemoryBufferWithSTDIN +LLVMCreateMessage +LLVMCreateModuleProviderForExistingModule +LLVMCreatePassManager +LLVMCreateStringAttribute +LLVMDeleteBasicBlock +LLVMDeleteFunction +LLVMDeleteGlobal +LLVMDisposeBuilder +LLVMDisposeMemoryBuffer +LLVMDisposeMessage +LLVMDisposeModule +LLVMDisposeModuleProvider +LLVMDisposePassManager +LLVMDoubleType +LLVMDoubleTypeInContext +LLVMDumpModule +LLVMDumpType +LLVMDumpValue +LLVMFP128Type +LLVMFP128TypeInContext +LLVMFinalizeFunctionPassManager +LLVMFloatType +LLVMFloatTypeInContext +LLVMFunctionType +LLVMGetAlignment +LLVMGetAllocatedType +LLVMGetArrayLength +LLVMGetAsString +LLVMGetAttributesAtIndex +LLVMGetAttributeCountAtIndex +LLVMGetBasicBlockName +LLVMGetBasicBlockParent +LLVMGetBasicBlockTerminator +LLVMGetBasicBlocks +LLVMGetBufferSize +LLVMGetBufferStart +LLVMGetCallSiteAttributes +LLVMGetCallSiteAttributeCount +LLVMGetCallSiteEnumAttribute +LLVMGetCallSiteStringAttribute +LLVMGetCalledValue +LLVMGetClause +LLVMGetCmpXchgFailureOrdering +LLVMGetCmpXchgSuccessOrdering +LLVMGetCondition +LLVMGetConstOpcode +LLVMGetCurrentDebugLocation +LLVMGetDLLStorageClass +LLVMGetDataLayout +LLVMGetDataLayoutStr +LLVMGetDiagInfoDescription +LLVMGetDiagInfoSeverity +LLVMGetElementAsConstant +LLVMGetElementType +;LLVMGetSubtypes +;LLVMGetNumContainedTypes +LLVMGetEntryBasicBlock +LLVMGetEnumAttributeAtIndex +LLVMGetEnumAttributeKind +LLVMGetEnumAttributeKindForName +LLVMGetEnumAttributeValue +LLVMGetFCmpPredicate +LLVMGetFirstBasicBlock +LLVMGetFirstFunction +LLVMGetFirstGlobal +LLVMGetFirstInstruction +LLVMGetFirstParam +LLVMGetFirstUse +LLVMGetFunctionCallConv +LLVMGetGC +LLVMGetGlobalContext +LLVMGetGlobalParent +LLVMGetGlobalPassRegistry +LLVMGetICmpPredicate +LLVMGetIncomingBlock +LLVMGetIncomingValue +LLVMGetIndices +LLVMGetInitializer +LLVMGetInsertBlock +LLVMGetInstructionCallConv +LLVMGetInstructionOpcode +LLVMGetInstructionParent +LLVMGetIntTypeWidth +LLVMGetIntrinsicID +LLVMGetLastBasicBlock +LLVMGetLastEnumAttributeKind +LLVMGetLastFunction +LLVMGetLastGlobal +LLVMGetLastInstruction +LLVMGetLastParam +LLVMGetLinkage +LLVMGetMDKindID +LLVMGetMDKindIDInContext +LLVMGetMDNodeNumOperands +LLVMGetMDNodeOperands +LLVMGetMDString +LLVMGetMetadata +LLVMGetModuleContext +LLVMGetModuleIdentifier +LLVMGetNamedFunction +LLVMGetNamedGlobal +LLVMGetNamedMetadataNumOperands +LLVMGetNamedMetadataOperands +LLVMGetNextBasicBlock +LLVMGetNextFunction +LLVMGetNextGlobal +LLVMGetNextInstruction +LLVMGetNextParam +LLVMGetNextUse +LLVMGetNormalDest +LLVMGetNumArgOperands +LLVMGetNumClauses +LLVMGetNumIndices +LLVMGetNumOperands +LLVMGetNumSuccessors +LLVMGetOperand +LLVMGetOperandUse +LLVMGetOrdering +LLVMGetParam +LLVMGetParamParent +LLVMGetParamTypes +LLVMGetParams +LLVMGetPersonalityFn +LLVMGetPointerAddressSpace +LLVMGetPreviousBasicBlock +LLVMGetPreviousFunction +LLVMGetPreviousGlobal +LLVMGetPreviousInstruction +LLVMGetPreviousParam +LLVMGetReturnType +LLVMGetSection +LLVMGetStringAttributeAtIndex +LLVMGetStringAttributeKind +LLVMGetStringAttributeValue +LLVMGetStructElementTypes +LLVMGetStructName +LLVMGetSuccessor +LLVMGetSwitchDefaultDest +LLVMGetTarget +LLVMGetThreadLocalMode +LLVMGetTypeByName +LLVMGetTypeContext +LLVMGetTypeKind +LLVMGetUndef +LLVMGetUnwindDest +LLVMGetUsedValue +LLVMGetUser +LLVMGetValueKind +LLVMGetValueName +LLVMGetVectorSize +LLVMGetVisibility +LLVMGetVolatile +LLVMHalfType +LLVMHalfTypeInContext +LLVMHasMetadata +LLVMHasPersonalityFn +LLVMHasUnnamedAddr +LLVMInitializeCore +LLVMInitializeFunctionPassManager +LLVMInsertBasicBlock +LLVMInsertBasicBlockInContext +LLVMInsertIntoBuilder +LLVMInsertIntoBuilderWithName +LLVMInstructionClone +LLVMInstructionEraseFromParent +LLVMInstructionRemoveFromParent +LLVMInt128Type +LLVMInt128TypeInContext +LLVMInt16Type +LLVMInt16TypeInContext +LLVMInt1Type +LLVMInt1TypeInContext +LLVMInt32Type +LLVMInt32TypeInContext +LLVMInt64Type +LLVMInt64TypeInContext +LLVMInt8Type +LLVMInt8TypeInContext +LLVMIntType +LLVMIntTypeInContext +LLVMIsAAddrSpaceCastInst +LLVMIsAAllocaInst +LLVMIsAArgument +LLVMIsABasicBlock +LLVMIsABinaryOperator +LLVMIsABitCastInst +LLVMIsABlockAddress +LLVMIsABranchInst +LLVMIsACallInst +LLVMIsACastInst +LLVMIsACatchPadInst +LLVMIsACatchReturnInst +LLVMIsACleanupPadInst +LLVMIsACleanupReturnInst +LLVMIsACmpInst +LLVMIsAConstant +LLVMIsAConstantAggregateZero +LLVMIsAConstantArray +LLVMIsAConstantDataArray +LLVMIsAConstantDataSequential +LLVMIsAConstantDataVector +LLVMIsAConstantExpr +LLVMIsAConstantFP +LLVMIsAConstantInt +LLVMIsAConstantPointerNull +LLVMIsAConstantStruct +LLVMIsAConstantTokenNone +LLVMIsAConstantVector +LLVMIsADbgDeclareInst +LLVMIsADbgInfoIntrinsic +LLVMIsAExtractElementInst +LLVMIsAExtractValueInst +LLVMIsAFCmpInst +LLVMIsAFPExtInst +LLVMIsAFPToSIInst +LLVMIsAFPToUIInst +LLVMIsAFPTruncInst +LLVMIsAFuncletPadInst +LLVMIsAFunction +LLVMIsAGetElementPtrInst +LLVMIsAGlobalAlias +LLVMIsAGlobalObject +LLVMIsAGlobalValue +LLVMIsAGlobalVariable +LLVMIsAICmpInst +LLVMIsAIndirectBrInst +LLVMIsAInlineAsm +LLVMIsAInsertElementInst +LLVMIsAInsertValueInst +LLVMIsAInstruction +LLVMIsAIntToPtrInst +LLVMIsAIntrinsicInst +LLVMIsAInvokeInst +LLVMIsALandingPadInst +LLVMIsALoadInst +LLVMIsAMDNode +LLVMIsAMDString +LLVMIsAMemCpyInst +LLVMIsAMemIntrinsic +LLVMIsAMemMoveInst +LLVMIsAMemSetInst +LLVMIsAPHINode +LLVMIsAPtrToIntInst +LLVMIsAResumeInst +LLVMIsAReturnInst +LLVMIsASExtInst +LLVMIsASIToFPInst +LLVMIsASelectInst +LLVMIsAShuffleVectorInst +LLVMIsAStoreInst +LLVMIsASwitchInst +LLVMIsATerminatorInst +LLVMIsATruncInst +LLVMIsAUIToFPInst +LLVMIsAUnaryInstruction +LLVMIsAUndefValue +LLVMIsAUnreachableInst +LLVMIsAUser +LLVMIsAVAArgInst +LLVMIsAZExtInst +LLVMIsAtomicSingleThread +LLVMIsCleanup +LLVMIsConditional +LLVMIsConstant +LLVMIsConstantString +LLVMIsDeclaration +LLVMIsEnumAttribute +LLVMIsExternallyInitialized +LLVMIsFunctionVarArg +LLVMIsGlobalConstant +LLVMIsInBounds +LLVMIsMultithreaded +LLVMIsNull +LLVMIsOpaqueStruct +LLVMIsPackedStruct +LLVMIsStringAttribute +LLVMIsTailCall +LLVMIsThreadLocal +LLVMIsUndef +LLVMLabelType +LLVMLabelTypeInContext +LLVMMDNode +LLVMMDNodeInContext +LLVMMDString +LLVMMDStringInContext +LLVMModuleCreateWithName +LLVMModuleCreateWithNameInContext +LLVMMoveBasicBlockAfter +LLVMMoveBasicBlockBefore +LLVMPPCFP128Type +LLVMPPCFP128TypeInContext +LLVMPointerType +LLVMPositionBuilder +LLVMPositionBuilderAtEnd +LLVMPositionBuilderBefore +LLVMPrintModuleToFile +LLVMPrintModuleToString +LLVMPrintTypeToString +LLVMPrintValueToString +LLVMRemoveBasicBlockFromParent +LLVMRemoveCallSiteEnumAttribute +LLVMRemoveCallSiteStringAttribute +LLVMRemoveEnumAttributeAtIndex +LLVMRemoveStringAttributeAtIndex +LLVMReplaceAllUsesWith +LLVMRunFunctionPassManager +LLVMRunPassManager +LLVMSetAlignment +LLVMSetAtomicSingleThread +LLVMSetCleanup +LLVMSetCmpXchgFailureOrdering +LLVMSetCmpXchgSuccessOrdering +LLVMSetCondition +LLVMSetCurrentDebugLocation +LLVMSetDLLStorageClass +LLVMSetDataLayout +LLVMSetExternallyInitialized +LLVMSetFunctionCallConv +LLVMSetGC +LLVMSetGlobalConstant +LLVMSetInitializer +LLVMSetInstDebugLocation +LLVMSetInstrParamAlignment +LLVMSetInstructionCallConv +LLVMSetIsInBounds +LLVMSetLinkage +LLVMSetMetadata +LLVMSetModuleIdentifier +LLVMSetModuleInlineAsm +LLVMSetNormalDest +LLVMSetOperand +LLVMSetOrdering +LLVMSetParamAlignment +LLVMSetPersonalityFn +LLVMSetSection +LLVMSetSuccessor +LLVMSetTailCall +LLVMSetTarget +LLVMSetThreadLocal +LLVMSetThreadLocalMode +LLVMSetUnnamedAddr +LLVMSetUnwindDest +LLVMSetValueName +LLVMSetVisibility +LLVMSetVolatile +LLVMShutdown +LLVMSizeOf +LLVMStartMultithreaded +LLVMStopMultithreaded +LLVMStructCreateNamed +LLVMStructGetTypeAtIndex +LLVMStructSetBody +LLVMStructType +LLVMStructTypeInContext +LLVMTypeIsSized +LLVMTypeOf +LLVMValueAsBasicBlock +;LLVMValueAsMetadata +LLVMValueIsBasicBlock +LLVMVectorType +LLVMVoidType +LLVMVoidTypeInContext +LLVMX86FP80Type +LLVMX86FP80TypeInContext +LLVMX86MMXType +LLVMX86MMXTypeInContext +LLVMAddGlobalMapping +LLVMAddModule +LLVMCreateExecutionEngineForModule +LLVMCreateGenericValueOfFloat +LLVMCreateGenericValueOfInt +LLVMCreateGenericValueOfPointer +LLVMCreateInterpreterForModule +LLVMCreateJITCompilerForModule +LLVMCreateMCJITCompilerForModule +LLVMCreateSimpleMCJITMemoryManager +LLVMDisposeExecutionEngine +LLVMDisposeGenericValue +LLVMDisposeMCJITMemoryManager +LLVMFindFunction +LLVMFreeMachineCodeForFunction +LLVMGenericValueIntWidth +LLVMGenericValueToFloat +LLVMGenericValueToInt +LLVMGenericValueToPointer +LLVMGetExecutionEngineTargetData +LLVMGetExecutionEngineTargetMachine +LLVMGetFunctionAddress +LLVMGetGlobalValueAddress +LLVMGetPointerToGlobal +LLVMInitializeMCJITCompilerOptions +LLVMRecompileAndRelinkFunction +LLVMRemoveModule +LLVMRunFunction +LLVMRunFunctionAsMain +LLVMRunStaticConstructors +LLVMRunStaticDestructors +LLVMInitializeHexagonAsmParser +LLVMInitializeHexagonAsmPrinter +LLVMInitializeHexagonTarget +LLVMInitializeHexagonTargetMC +LLVMInitializeHexagonDisassembler +LLVMInitializeHexagonTargetInfo +LLVMInitializeInstCombine +LLVMInitializeInstrumentation +LLVMLinkInInterpreter +LLVMAddAlwaysInlinerPass +LLVMAddArgumentPromotionPass +LLVMAddConstantMergePass +LLVMAddDeadArgEliminationPass +LLVMAddFunctionAttrsPass +LLVMAddFunctionInliningPass +LLVMAddGlobalDCEPass +LLVMAddGlobalOptimizerPass +LLVMAddIPConstantPropagationPass +LLVMAddIPSCCPPass +LLVMAddInternalizePass +LLVMAddPruneEHPass +LLVMAddStripDeadPrototypesPass +LLVMAddStripSymbolsPass +LLVMInitializeIPO +LLVMPassManagerBuilderCreate +LLVMPassManagerBuilderDispose +LLVMPassManagerBuilderPopulateFunctionPassManager +LLVMPassManagerBuilderPopulateLTOPassManager +LLVMPassManagerBuilderPopulateModulePassManager +LLVMPassManagerBuilderSetDisableSimplifyLibCalls +LLVMPassManagerBuilderSetDisableUnitAtATime +LLVMPassManagerBuilderSetDisableUnrollLoops +LLVMPassManagerBuilderSetOptLevel +LLVMPassManagerBuilderSetSizeLevel +LLVMPassManagerBuilderUseInlinerWithThreshold +LLVMParseIRInContext +LLVMLinkModules2 +LLVMCreateDisasm +LLVMCreateDisasmCPU +LLVMCreateDisasmCPUFeatures +LLVMDisasmDispose +LLVMDisasmInstruction +LLVMSetDisasmOptions +LLVMLinkInMCJIT +LLVMInitializeMipsAsmParser +LLVMInitializeMipsAsmPrinter +LLVMInitializeMipsTarget +LLVMInitializeMipsTargetMC +LLVMInitializeMipsDisassembler +LLVMInitializeMipsTargetInfo +LLVMInitializeMSP430Target +LLVMInitializeMSP430AsmPrinter +LLVMInitializeMSP430TargetMC +LLVMInitializeMSP430TargetInfo +LLVMInitializeNVPTXAsmPrinter +LLVMInitializeNVPTXTarget +LLVMInitializeNVPTXTargetMC +LLVMInitializeNVPTXTargetInfo +LLVMInitializeObjCARCOpts +LLVMCreateObjectFile +LLVMDisposeObjectFile +LLVMDisposeRelocationIterator +LLVMDisposeSectionIterator +LLVMDisposeSymbolIterator +LLVMGetRelocationOffset +LLVMGetRelocationSymbol +LLVMGetRelocationType +LLVMGetRelocationTypeName +LLVMGetRelocationValueString +LLVMGetRelocations +LLVMGetSectionAddress +LLVMGetSectionContainsSymbol +LLVMGetSectionContents +LLVMGetSectionName +LLVMGetSectionSize +LLVMGetSections +LLVMGetSymbolAddress +LLVMGetSymbolName +LLVMGetSymbolSize +LLVMGetSymbols +LLVMIsRelocationIteratorAtEnd +LLVMIsSectionIteratorAtEnd +LLVMIsSymbolIteratorAtEnd +LLVMMoveToContainingSection +LLVMMoveToNextRelocation +LLVMMoveToNextSection +LLVMMoveToNextSymbol +LLVMOrcAddEagerlyCompiledIR +LLVMOrcAddLazilyCompiledIR +LLVMOrcCreateIndirectStub +LLVMOrcCreateInstance +LLVMOrcCreateLazyCompileCallback +LLVMOrcDisposeInstance +LLVMOrcDisposeMangledSymbol +LLVMOrcGetErrorMsg +LLVMOrcGetMangledSymbol +LLVMOrcGetSymbolAddress +;LLVMOrcMakeSharedModule +;LLVMOrcDisposeSharedModuleRef +;LLVMOrcMakeSharedObjectBuffer +;LLVMOrcDisposeSharedObjectBufferRef +LLVMOrcRemoveModule +LLVMOrcSetIndirectStubPointer +LLVMLinkInOrcMCJITReplacement +LLVMInitializePowerPCAsmParser +LLVMInitializePowerPCAsmPrinter +LLVMInitializePowerPCTarget +LLVMInitializePowerPCTargetMC +LLVMInitializePowerPCDisassembler +LLVMInitializePowerPCTargetInfo +LLVMAddAggressiveDCEPass +LLVMAddAlignmentFromAssumptionsPass +LLVMAddBasicAliasAnalysisPass +LLVMAddBitTrackingDCEPass +LLVMAddCFGSimplificationPass +;LLVMAddLateCFGSimplificationPass +LLVMAddConstantPropagationPass +LLVMAddCorrelatedValuePropagationPass +LLVMAddDeadStoreEliminationPass +LLVMAddDemoteMemoryToRegisterPass +LLVMAddEarlyCSEPass +LLVMAddEarlyCSEMemSSAPass +LLVMAddGVNPass +LLVMAddNewGVNPass +LLVMAddIndVarSimplifyPass +LLVMAddInstructionCombiningPass +LLVMAddJumpThreadingPass +LLVMAddLICMPass +LLVMAddLoopDeletionPass +LLVMAddLoopIdiomPass +LLVMAddLoopRerollPass +LLVMAddLoopRotatePass +LLVMAddLoopUnrollPass +LLVMAddLoopUnswitchPass +LLVMAddLowerExpectIntrinsicPass +LLVMAddLowerSwitchPass +LLVMAddMemCpyOptPass +LLVMAddMergedLoadStoreMotionPass +LLVMAddPartiallyInlineLibCallsPass +LLVMAddPromoteMemoryToRegisterPass +LLVMAddReassociatePass +LLVMAddSCCPPass +LLVMAddScalarReplAggregatesPass +LLVMAddScalarReplAggregatesPassSSA +LLVMAddScalarReplAggregatesPassWithThreshold +LLVMAddScalarizerPass +LLVMAddScopedNoAliasAAPass +LLVMAddSimplifyLibCallsPass +LLVMAddTailCallEliminationPass +LLVMAddTypeBasedAliasAnalysisPass +LLVMAddVerifierPass +LLVMInitializeScalarOpts +LLVMInitializeSparcAsmParser +LLVMInitializeSparcAsmPrinter +LLVMInitializeSparcTarget +LLVMInitializeSparcTargetMC +LLVMInitializeSparcDisassembler +LLVMInitializeSparcTargetInfo +LLVMParseCommandLineOptions +LLVMInstallFatalErrorHandler +LLVMResetFatalErrorHandler +LLVMEnablePrettyStackTrace +LLVMAddSymbol +LLVMLoadLibraryPermanently +LLVMSearchForAddressOfSymbol +LLVMInitializeSystemZAsmParser +LLVMInitializeSystemZAsmPrinter +LLVMInitializeSystemZTarget +LLVMInitializeSystemZTargetMC +LLVMInitializeSystemZDisassembler +LLVMInitializeSystemZTargetInfo +LLVMABIAlignmentOfType +LLVMABISizeOfType +LLVMAddTargetLibraryInfo +LLVMByteOrder +LLVMCallFrameAlignmentOfType +LLVMCopyStringRepOfTargetData +LLVMCreateTargetData +LLVMDisposeTargetData +LLVMElementAtOffset +LLVMGetModuleDataLayout +LLVMInitializeTarget +LLVMIntPtrType +LLVMIntPtrTypeForAS +LLVMIntPtrTypeForASInContext +LLVMIntPtrTypeInContext +LLVMOffsetOfElement +LLVMPointerSize +LLVMPointerSizeForAS +LLVMPreferredAlignmentOfGlobal +LLVMPreferredAlignmentOfType +LLVMSetModuleDataLayout +LLVMSizeOfTypeInBits +LLVMStoreSizeOfType +LLVMAddAnalysisPasses +LLVMCreateTargetDataLayout +LLVMCreateTargetMachine +LLVMDisposeTargetMachine +LLVMGetDefaultTargetTriple +LLVMGetFirstTarget +LLVMGetNextTarget +LLVMGetTargetDescription +LLVMGetTargetFromName +LLVMGetTargetFromTriple +LLVMGetTargetMachineCPU +LLVMGetTargetMachineFeatureString +LLVMGetTargetMachineTarget +LLVMGetTargetMachineTriple +LLVMGetTargetName +LLVMSetTargetMachineAsmVerbosity +LLVMTargetHasAsmBackend +LLVMTargetHasJIT +LLVMTargetHasTargetMachine +LLVMTargetMachineEmitToFile +LLVMTargetMachineEmitToMemoryBuffer +LLVMCloneModule +LLVMInitializeTransformUtils +LLVMAddBBVectorizePass +LLVMAddLoopVectorizePass +LLVMAddSLPVectorizePass +LLVMInitializeVectorization +LLVMInitializeX86AsmParser +LLVMInitializeX86AsmPrinter +LLVMInitializeX86Target +LLVMInitializeX86TargetMC +LLVMInitializeX86Disassembler +LLVMInitializeX86TargetInfo +LLVMInitializeXCoreAsmPrinter +LLVMInitializeXCoreTarget +LLVMInitializeXCoreTargetMC +LLVMInitializeXCoreDisassembler +LLVMInitializeXCoreTargetInfo diff --git a/src/LibLLVM/IRBindings.cpp b/src/LibLLVM/IRBindings.cpp index c5ffc8714..574e17aa9 100644 --- a/src/LibLLVM/IRBindings.cpp +++ b/src/LibLLVM/IRBindings.cpp @@ -159,32 +159,9 @@ extern "C" pFunction->setSubprogram( unwrap( subprogram ) ); } - static AtomicOrdering mapFromLLVMOrdering( LLVMAtomicOrdering Ordering ) - { - switch( Ordering ) - { - case LLVMAtomicOrderingNotAtomic: - return AtomicOrdering::NotAtomic; - case LLVMAtomicOrderingUnordered: - return AtomicOrdering::Unordered; - case LLVMAtomicOrderingMonotonic: - return AtomicOrdering::Monotonic; - case LLVMAtomicOrderingAcquire: - return AtomicOrdering::Acquire; - case LLVMAtomicOrderingRelease: - return AtomicOrdering::Release; - case LLVMAtomicOrderingAcquireRelease: - return AtomicOrdering::AcquireRelease; - case LLVMAtomicOrderingSequentiallyConsistent: - return AtomicOrdering::SequentiallyConsistent; - } - - llvm_unreachable( "Invalid LLVMAtomicOrdering value!" ); - } - - LLVMBool LLVMFunctionHasPersonalityFunction( LLVMValueRef function ) - { - Function* pFunc = unwrap( function ); - return pFunc->hasPersonalityFn( ); + LLVMMetadataRef LLVMDIGlobalVarExpGetVariable( LLVMMetadataRef metadataHandle ) + { + auto pExp = unwrap( metadataHandle ); + return wrap( pExp->getVariable( ) ); } } diff --git a/src/LibLLVM/IRBindings.h b/src/LibLLVM/IRBindings.h index c4fdf08a8..e5617b628 100644 --- a/src/LibLLVM/IRBindings.h +++ b/src/LibLLVM/IRBindings.h @@ -14,10 +14,10 @@ #ifndef LLVM_BINDINGS_LLVM_IRBINDINGS_H #define LLVM_BINDINGS_LLVM_IRBINDINGS_H -#include "llvm-c/Core.h" +#include #ifdef __cplusplus -#include "llvm/IR/Metadata.h" -#include "llvm/Support/CBindingWrapping.h" +#include +#include #endif #include @@ -26,57 +26,55 @@ extern "C" { #endif -typedef struct LLVMVersionInfo -{ - int Major; - int Minor; - int Patch; - char const* VersionString; -}LLVMVersionInfo; + typedef struct LLVMVersionInfo + { + int Major; + int Minor; + int Patch; + char const* VersionString; + }LLVMVersionInfo; -void LLVMGetVersionInfo( LLVMVersionInfo* pVersionInfo ); + void LLVMGetVersionInfo( LLVMVersionInfo* pVersionInfo ); -typedef struct LLVMOpaqueMetadata* LLVMMetadataRef; -typedef struct LLVMOpaqueMDOperand* LLVMMDOperandRef; + typedef struct LLVMOpaqueMetadata* LLVMMetadataRef; + typedef struct LLVMOpaqueMDOperand* LLVMMDOperandRef; -LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef Val); -LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen); -LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs, unsigned Count); -LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs, unsigned Count); + LLVMMetadataRef LLVMConstantAsMetadata( LLVMValueRef Val ); + LLVMMetadataRef LLVMMDString2( LLVMContextRef C, const char *Str, unsigned SLen ); + LLVMMetadataRef LLVMMDNode2( LLVMContextRef C, LLVMMetadataRef *MDs, unsigned Count ); + LLVMMetadataRef LLVMTemporaryMDNode( LLVMContextRef C, LLVMMetadataRef *MDs, unsigned Count ); -char const* LLVMGetMDStringText( LLVMMetadataRef mdstring, unsigned* len ); + char const* LLVMGetMDStringText( LLVMMetadataRef mdstring, unsigned* len ); -void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name, LLVMMetadataRef Val); -void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD); -void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New); -void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt); + void LLVMAddNamedMetadataOperand2( LLVMModuleRef M, const char *name, LLVMMetadataRef Val ); + void LLVMSetMetadata2( LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD ); + void LLVMMetadataReplaceAllUsesWith( LLVMMetadataRef MD, LLVMMetadataRef New ); + void LLVMSetCurrentDebugLocation2( LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt ); -LLVMBool LLVMIsTemporary( LLVMMetadataRef M ); -LLVMBool LLVMIsResolved( LLVMMetadataRef M ); -LLVMBool LLVMIsUniqued( LLVMMetadataRef M ); -LLVMBool LLVMIsDistinct( LLVMMetadataRef M ); + LLVMBool LLVMIsTemporary( LLVMMetadataRef M ); + LLVMBool LLVMIsResolved( LLVMMetadataRef M ); + LLVMBool LLVMIsUniqued( LLVMMetadataRef M ); + LLVMBool LLVMIsDistinct( LLVMMetadataRef M ); -void LLVMMDNodeResolveCycles( LLVMMetadataRef M ); -char const* LLVMGetDIFileName( LLVMMetadataRef /*DIFile*/ file ); -char const* LLVMGetDIFileDirectory( LLVMMetadataRef /*DIFile*/ file ); + void LLVMMDNodeResolveCycles( LLVMMetadataRef M ); + char const* LLVMGetDIFileName( LLVMMetadataRef /*DIFile*/ file ); + char const* LLVMGetDIFileDirectory( LLVMMetadataRef /*DIFile*/ file ); -LLVMValueRef LLVMBuildAtomicCmpXchg( LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Cmp, LLVMValueRef New, LLVMAtomicOrdering successOrdering, LLVMAtomicOrdering failureOrdering, LLVMBool singleThread ); - -LLVMMetadataRef LLVMFunctionGetSubprogram( LLVMValueRef function ); -void LLVMFunctionSetSubprogram( LLVMValueRef function, LLVMMetadataRef subprogram ); -LLVMBool LLVMFunctionHasPersonalityFunction( LLVMValueRef function ); + LLVMMetadataRef LLVMFunctionGetSubprogram( LLVMValueRef function ); + void LLVMFunctionSetSubprogram( LLVMValueRef function, LLVMMetadataRef subprogram ); + LLVMMetadataRef LLVMDIGlobalVarExpGetVariable( LLVMMetadataRef /*DIGlobalVariableExpression*/ metadataHandle ); #ifdef __cplusplus } namespace llvm { -DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef) + DEFINE_ISA_CONVERSION_FUNCTIONS( Metadata, LLVMMetadataRef ) -inline Metadata **unwrap(LLVMMetadataRef *Vals) { - return reinterpret_cast(Vals); -} + inline Metadata **unwrap( LLVMMetadataRef *Vals ) { + return reinterpret_cast( Vals ); + } } diff --git a/src/LibLLVM/InlinedExports.cpp b/src/LibLLVM/InlinedExports.cpp index 2fdcb1c13..1ad05e03c 100644 --- a/src/LibLLVM/InlinedExports.cpp +++ b/src/LibLLVM/InlinedExports.cpp @@ -1,16 +1,16 @@ -#include "llvm-c/Target.h" +#include extern "C" { // exportable wrappers around static in-lined functions // EXPORTS.DEF uses aliasing to export these as the standard name - // (e.g. dropping the trailing "Export" from the name.) This + // (e.g. dropping the trailing "Export" from the name.) This // mechanism is needed since the in-lined functions are marked static // and therefore the linker doesn't see them as externally visible - // so it can't export them. + // so it can't export them. /** LLVMInitializeAllTargetInfos - The main program should call this function if - it wants access to all available targets that LLVM is configured to + it wants access to initialize all available targets that LLVM is configured to support. */ void LLVMInitializeAllTargetInfosExport( void ) { diff --git a/src/LibLLVM/InlinedExports.h b/src/LibLLVM/InlinedExports.h index 02598fad0..fb3b90d62 100644 --- a/src/LibLLVM/InlinedExports.h +++ b/src/LibLLVM/InlinedExports.h @@ -8,10 +8,10 @@ extern "C" { #endif // exportable wrappers around static inlined functions // EXPORTS.DEF uses aliasing to export these as the standard name - // (e.g. dropping the trailing "Export" from the name.) This + // (e.g. dropping the trailing "Export" from the name.) This // mechanism is needed since the inlined functions are marked static // and therefore the linker doesn't see them as externally visible - // so it can't export them. + // so it can't export them. /** LLVMInitializeAllTargetInfos - The main program should call this function if it wants access to all available targets that LLVM is configured to diff --git a/src/LibLLVM/LegacyPassManagerOpt.cpp b/src/LibLLVM/LegacyPassManagerOpt.cpp index 63cdf2db4..fee76214e 100644 --- a/src/LibLLVM/LegacyPassManagerOpt.cpp +++ b/src/LibLLVM/LegacyPassManagerOpt.cpp @@ -16,44 +16,48 @@ // ported and modified from opt.cpp in LLVM to allow for use as an API instead of trying to expose all of // the legacy pass manager support, since the pass management is undergoing a significant transition // it is best not to build out projectionts to depend on the legacy variant. -#include "llvm/ADT/Triple.h" -#include "llvm/Analysis/CallGraph.h" -#include "llvm/Analysis/CallGraphSCCPass.h" -#include "llvm/Analysis/LoopPass.h" -#include "llvm/Analysis/RegionPass.h" -#include "llvm/Analysis/TargetLibraryInfo.h" -#include "llvm/Analysis/TargetTransformInfo.h" -#include "llvm/Bitcode/BitcodeWriterPass.h" -#include "llvm/CodeGen/CommandFlags.h" -#include "llvm/IR/DataLayout.h" -#include "llvm/IR/DebugInfo.h" -#include "llvm/IR/IRPrintingPasses.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/IR/LegacyPassNameParser.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/Verifier.h" -#include "llvm/IRReader/IRReader.h" -#include "llvm/InitializePasses.h" -#include "llvm/LinkAllIR.h" -#include "llvm/LinkAllPasses.h" -#include "llvm/MC/SubtargetFeature.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/Host.h" -#include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/PluginLoader.h" -#include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Support/Signals.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/SystemUtils.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Support/ToolOutputFile.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" -#include "llvm/Transforms/Utils/Cloning.h" -#include "llvm-c\TargetMachine.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include #include #include using namespace llvm; @@ -152,6 +156,11 @@ static cl::opt DiscardValueNames( cl::desc( "Discard names from Value (other than GlobalValue)." ), cl::init( false ), cl::Hidden ); +static cl::opt Coroutines( + "enable-coroutines", + cl::desc( "Enable coroutine passes." ), + cl::init( false ), cl::Hidden ); + static cl::opt PassRemarksWithHotness( "pass-remarks-with-hotness", cl::desc( "With PGO, include profile count in optimization remarks" ), @@ -165,16 +174,21 @@ static void AddOptimizationPasses( legacy::PassManagerBase &MPM, legacy::FunctionPassManager &FPM, TargetMachine *TM, unsigned OptLevel, unsigned SizeLevel ) { + //if( !NoVerify || VerifyEach ) + // FPM.add( createVerifierPass( ) ); // Verify that input is correct PassManagerBuilder Builder; Builder.OptLevel = OptLevel; Builder.SizeLevel = SizeLevel; - if( OptLevel > 1 ) { + /*if( DisableInline ) { + // No inlining pass + } + else*/ if( OptLevel > 1 ) { Builder.Inliner = createFunctionInliningPass( OptLevel, SizeLevel ); } else { - Builder.Inliner = createAlwaysInlinerPass( ); + Builder.Inliner = createAlwaysInlinerLegacyPass( ); } Builder.DisableUnitAtATime = !UnitAtATime; Builder.DisableUnrollLoops = ( DisableLoopUnrolling.getNumOccurrences( ) > 0 ) ? @@ -199,10 +213,14 @@ static void AddOptimizationPasses( legacy::PassManagerBase &MPM, TM->addEarlyAsPossiblePasses( PM ); } ); + if( Coroutines ) + addCoroutinePassesToExtensionPoints( Builder ); + Builder.populateFunctionPassManager( FPM ); Builder.populateModulePassManager( MPM ); } + static void AddStandardLinkPasses( legacy::PassManagerBase &PM ) { PassManagerBuilder Builder; Builder.VerifyInput = true; @@ -215,6 +233,7 @@ void LLVMInitializePassesForLegacyOpt( ) { PassRegistry &Registry = *PassRegistry::getPassRegistry( ); initializeCore( Registry ); + initializeCoroutines( Registry ); initializeScalarOpts( Registry ); initializeObjCARCOpts( Registry ); initializeVectorization( Registry ); @@ -228,7 +247,7 @@ void LLVMInitializePassesForLegacyOpt( ) // supported. initializeCodeGenPreparePass( Registry ); initializeAtomicExpandPass( Registry ); - initializeRewriteSymbolsPass( Registry ); + initializeRewriteSymbolsLegacyPassPass( Registry ); initializeWinEHPreparePass( Registry ); initializeDwarfEHPreparePass( Registry ); initializeSafeStackPass( Registry ); @@ -236,10 +255,11 @@ void LLVMInitializePassesForLegacyOpt( ) initializePreISelIntrinsicLoweringLegacyPassPass( Registry ); initializeGlobalMergePass( Registry ); initializeInterleavedAccessPass( Registry ); + initializeCountingFunctionInserterPass( Registry ); initializeUnreachableBlockElimLegacyPassPass( Registry ); } -void LLVMRunLegacyOptimizer( LLVMModuleRef Mref, LLVMTargetMachineRef TMref) { +void LLVMRunLegacyOptimizer( LLVMModuleRef Mref, LLVMTargetMachineRef TMref ) { SMDiagnostic Err; LLVMContext Context; diff --git a/src/LibLLVM/LibLLVM.vcxproj b/src/LibLLVM/LibLLVM.vcxproj index 4e368201b..1c33b9981 100644 --- a/src/LibLLVM/LibLLVM.vcxproj +++ b/src/LibLLVM/LibLLVM.vcxproj @@ -1,6 +1,6 @@  - - + + Debug @@ -27,36 +27,51 @@ 8.1 @(AllLlvmLibs);$(AdditionalDependencies) true + 8.1 + + + + + + + + + + + + DynamicLibrary true - v140 + v141 Unicode DynamicLibrary true - v140 + v141 Unicode DynamicLibrary false - v140 + v141 true Unicode DynamicLibrary false - v140 + v141 true Unicode + + @@ -93,13 +108,11 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBLLVM_EXPORTS;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) Windows true EXPORTS.DEF - $(AllLlvmStaticLibs);%(AdditionalDependencies) @@ -108,13 +121,11 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBLLVM_EXPORTS;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) Windows true EXPORTS.DEF - $(AllLlvmStaticLibs);%(AdditionalDependencies) @@ -125,7 +136,6 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBLLVM_EXPORTS;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) Windows @@ -133,7 +143,6 @@ true true EXPORTS.DEF - $(AllLlvmStaticLibs);%(AdditionalDependencies) @@ -144,7 +153,6 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBLLVM_EXPORTS;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) Windows @@ -152,32 +160,15 @@ true true EXPORTS.DEF - $(AllLlvmStaticLibs);%(AdditionalDependencies) - + + - - true - false - true - false - true - false - true - false - - + + Designer - true - false - true - false - true - false - true - false @@ -210,10 +201,32 @@ - + + $(IntermediateOutputPath);%(AdditionalIncludeDirectories) + $(IntermediateOutputPath);%(AdditionalIncludeDirectories) + $(IntermediateOutputPath);%(AdditionalIncludeDirectories) + $(IntermediateOutputPath);%(AdditionalIncludeDirectories) + - - - - \ No newline at end of file + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + diff --git a/src/LibLLVM/LibLLVM.vcxproj.filters b/src/LibLLVM/LibLLVM.vcxproj.filters index 2d6c99438..506ce3863 100644 --- a/src/LibLLVM/LibLLVM.vcxproj.filters +++ b/src/LibLLVM/LibLLVM.vcxproj.filters @@ -13,14 +13,22 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {d424e6d7-8fc8-40b0-b029-d66974c207a1} + Source Files - - + + Build + + + Build + + @@ -44,9 +52,6 @@ Source Files - - Source Files - Source Files @@ -59,6 +64,9 @@ Source Files + + Source Files + @@ -82,9 +90,6 @@ Header Files - - Header Files - Header Files @@ -100,6 +105,9 @@ Header Files + + Header Files + diff --git a/src/LibLLVM/LlvmApplication.props b/src/LibLLVM/LlvmApplication.props index 2af882e8f..e7dc5117c 100644 --- a/src/LibLLVM/LlvmApplication.props +++ b/src/LibLLVM/LlvmApplication.props @@ -1,102 +1,21 @@ - - + + - - 3 - 9 - 1 - $(LlvmVersionMajor).$(llvmVersionMinor).$(LlvmVersionBuild) - - $([MSBuild]::GetRegistryValue(`HKEY_CURRENT_USER\Software\LLVM\$(LLVM_VERSION)\`, `SrcRoot`)) - $([MSBuild]::GetRegistryValueFromView(`HKEY_LOCAL_MACHINE\Software\LLVM\$(LLVM_VERSION)\`, `SrcRoot`, null, RegistryView.Registry64, RegistryView.Registry32)) - $(LLVM_SRCROOT_DIR)\ - - - $([MSBuild]::GetRegistryValue(`HKEY_CURRENT_USER\Software\LLVM\$(LLVM_VERSION)\`, `BuildRoot`)) - $([MSBuild]::GetRegistryValueFromView(`HKEY_LOCAL_MACHINE\Software\LLVM\$(LLVM_VERSION)\`, `BuildRoot`, null, RegistryView.Registry64, RegistryView.Registry32)) - - - $(LLVM_SRCROOT_DIR)Build\ - $(LLVM_BUILD_DIR)\ - generatedversioninfo.h $(LlvmVersionMajor) $(LlvmVersionMinor) $(LlvmVersionBuild) - + 0 1 - + $(ProductVersionMajor) $(ProductVersionMinor) - - - $(Platform) - x86 - - - - $(LLVM_SRCROOT_DIR)Include - - - - - $(LLVM_BUILD_DIR)$(LLVM_PLATFORM)-$(Configuration)\ - - - $(LLVM_CONFIG_DIR)Include\ - - - $(LLVM_CONFIG_DIR)$(Configuration)\bin\ - - - $(LLVM_CONFIG_DIR)$(Configuration)\lib\ - - - - - - @(AllLlvmLibs) - - - $(AdditionalOptions) /Zc:sizedDealloc- - $(LLVM_CONFIG_INCLUDE);$(LLVM_INCLUDE);%(AdditionalIncludeDirectories) - 4141;4146;4267;4244;4800;4291;4996;4624 - - - $(AllLlvmStaticLibs);$(AdditionalDependencies) - - - $(IntermediateOutputPath);%(AdditionalIncludeDirectories) - - - - - - - - - - - - \ No newline at end of file + diff --git a/src/LibLLVM/ModuleBindings.h b/src/LibLLVM/ModuleBindings.h index 9f365f039..a1953a3dd 100644 --- a/src/LibLLVM/ModuleBindings.h +++ b/src/LibLLVM/ModuleBindings.h @@ -67,7 +67,7 @@ extern "C" { LLVMComdatRef LLVMModuleInsertOrUpdateComdat( LLVMModuleRef module, char const* name, LLVMComdatSelectionKind kind ); void LLVMModuleComdatRemove( LLVMModuleRef module, LLVMComdatRef comdatRef ); void LLVMModuleComdatClear( LLVMModuleRef module ); - + // Comdat accessors LLVMComdatSelectionKind LLVMComdatGetKind( LLVMComdatRef comdatRef ); void LLVMComdatSetKind( LLVMComdatRef comdatRef, LLVMComdatSelectionKind kind ); diff --git a/src/LibLLVM/MultiPlatformBuild.vcxproj b/src/LibLLVM/MultiPlatformBuild.vcxproj new file mode 100644 index 000000000..b10d6c3bb --- /dev/null +++ b/src/LibLLVM/MultiPlatformBuild.vcxproj @@ -0,0 +1,69 @@ + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC} + Win32Proj + Makefile + v141 + + + + + + x86 + + + x64 + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + diff --git a/src/LibLLVM/MultiPlatformBuild.vcxproj.filters b/src/LibLLVM/MultiPlatformBuild.vcxproj.filters new file mode 100644 index 000000000..97d0c5178 --- /dev/null +++ b/src/LibLLVM/MultiPlatformBuild.vcxproj.filters @@ -0,0 +1,20 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + \ No newline at end of file diff --git a/src/LibLLVM/MultiTarget.proj b/src/LibLLVM/MultiTarget.proj new file mode 100644 index 000000000..0eec6da38 --- /dev/null +++ b/src/LibLLVM/MultiTarget.proj @@ -0,0 +1,13 @@ + + + + + x86 + + + x64 + + + + + diff --git a/src/LibLLVM/NewOptPassDriver.cpp b/src/LibLLVM/NewOptPassDriver.cpp index bbfec5add..6f95d472b 100644 --- a/src/LibLLVM/NewOptPassDriver.cpp +++ b/src/LibLLVM/NewOptPassDriver.cpp @@ -17,7 +17,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CGSCCPassManager.h" -#include "llvm/Analysis/LoopPassManager.h" +#include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/IRPrintingPasses.h" diff --git a/src/LibLLVM/NewOptPassDriver.h b/src/LibLLVM/NewOptPassDriver.h index 7e4f8ee10..44cd05b2a 100644 --- a/src/LibLLVM/NewOptPassDriver.h +++ b/src/LibLLVM/NewOptPassDriver.h @@ -18,8 +18,8 @@ //===----------------------------------------------------------------------===// #pragma once -#include "llvm-c\Core.h" -#include "llvm-c\TargetMachine.h" +#include +#include enum LLVMOptVerifierKind { diff --git a/src/LibLLVM/NugetPkg/LibLLVM.NET.nuspec b/src/LibLLVM/NugetPkg/LibLLVM.NET.nuspec new file mode 100644 index 000000000..08cb51aeb --- /dev/null +++ b/src/LibLLVM/NugetPkg/LibLLVM.NET.nuspec @@ -0,0 +1,23 @@ + + + + LibLLVM.NET + $version$ + LLVM.NET + false + Extended LLVM-C API DLLs for LLVM v$llvmversion$ + true + http://github.com/netmf/LLVM.NET + http://releases.llvm.org/$llvmversion$/LICENSE.TXT + LLVM,compiler,native + + + + + + + + + + + diff --git a/src/LibLLVM/NugetPkg/build/LibLlvm.NET.props b/src/LibLLVM/NugetPkg/build/LibLlvm.NET.props new file mode 100644 index 000000000..92763dd17 --- /dev/null +++ b/src/LibLLVM/NugetPkg/build/LibLlvm.NET.props @@ -0,0 +1,26 @@ + + + $([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)..')) + $(Platform) + x86 + + + + + LibLLVM\x64\LibLLVM.dll + PreserveNewest + + + LibLLVM\x64\LibLLVM.pdb + PreserveNewest + + + LibLLVM\x86\LibLLVM.dll + PreserveNewest + + + LibLLVM\x86\LibLLVM.pdb + PreserveNewest + + + diff --git a/src/LibLLVM/PassManagerBindings.cpp b/src/LibLLVM/PassManagerBindings.cpp index 77f68f2f4..785954da0 100644 --- a/src/LibLLVM/PassManagerBindings.cpp +++ b/src/LibLLVM/PassManagerBindings.cpp @@ -56,12 +56,12 @@ extern "C" void LLVMAddDataFlowSanitizerPass( LLVMPassManagerRef PM, int ABIListFilesNum, const char **ABIListFiles ) { std::vector ABIListFilesVec; - for (int i = 0; i != ABIListFilesNum; ++i) + for( int i = 0; i != ABIListFilesNum; ++i ) { - ABIListFilesVec.push_back(ABIListFiles[i]); + ABIListFilesVec.push_back( ABIListFiles[ i ] ); } - unwrap(PM)->add(createDataFlowSanitizerPass(ABIListFilesVec)); + unwrap( PM )->add( createDataFlowSanitizerPass( ABIListFilesVec ) ); } // For codegen passes, only passes that do IR to IR transformation are @@ -69,9 +69,22 @@ extern "C" void LLVMInitializeCodeGenForOpt( LLVMPassRegistryRef R ) { PassRegistry& Registry = *unwrap( R ); + initializeCore( Registry ); + initializeCoroutines( Registry ); + initializeScalarOpts( Registry ); + initializeObjCARCOpts( Registry ); + initializeVectorization( Registry ); + initializeIPO( Registry ); + initializeAnalysis( Registry ); + initializeTransformUtils( Registry ); + initializeInstCombine( Registry ); + initializeInstrumentation( Registry ); + initializeTarget( Registry ); + // For codegen passes, only passes that do IR to IR transformation are + // supported. initializeCodeGenPreparePass( Registry ); initializeAtomicExpandPass( Registry ); - initializeRewriteSymbolsPass( Registry ); + initializeRewriteSymbolsLegacyPassPass( Registry ); initializeWinEHPreparePass( Registry ); initializeDwarfEHPreparePass( Registry ); initializeSafeStackPass( Registry ); @@ -79,6 +92,7 @@ extern "C" initializePreISelIntrinsicLoweringLegacyPassPass( Registry ); initializeGlobalMergePass( Registry ); initializeInterleavedAccessPass( Registry ); + initializeCountingFunctionInserterPass( Registry ); initializeUnreachableBlockElimLegacyPassPass( Registry ); } } \ No newline at end of file diff --git a/src/LibLLVM/PassManagerBindings.h b/src/LibLLVM/PassManagerBindings.h index d7f045ab1..d87f684d9 100644 --- a/src/LibLLVM/PassManagerBindings.h +++ b/src/LibLLVM/PassManagerBindings.h @@ -14,7 +14,7 @@ #ifndef LLVM_BINDINGS_LLVM_INSTRUMENTATIONBINDINGS_H #define LLVM_BINDINGS_LLVM_INSTRUMENTATIONBINDINGS_H -#include "llvm-c/Core.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/LibLLVM/TripleBindings.cpp b/src/LibLLVM/TripleBindings.cpp index 4ddf22e91..d1237723d 100644 --- a/src/LibLLVM/TripleBindings.cpp +++ b/src/LibLLVM/TripleBindings.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "llvm/Support/TargetParser.h" +#include +#include +#include +#include #include "TripleBindings.h" @@ -73,6 +73,9 @@ ARM::ArchKind MapEnum( LLVMTripleSubArchType from ) case LlvmTripleSubArchType_ARMSubArch_v8: return ARM::ArchKind::AK_ARMV8A; + case LlvmTripleSubArchType_ARMSubArch_v8r: + return ARM::ArchKind::AK_ARMV8R; + case LlvmTripleSubArchType_ARMSubArch_v8m_baseline: return ARM::ArchKind::AK_ARMV8MBaseline; @@ -197,7 +200,7 @@ char const* LLVMTripleGetArchTypeName( LLVMTripleArchType type ) if( llvmArchType > Triple::ArchType::LastArchType ) llvmArchType = Triple::ArchType::UnknownArch; - return LLVMCreateMessage( Triple::getArchTypeName( llvmArchType ) ); + return LLVMCreateMessage( Triple::getArchTypeName( llvmArchType ).data() ); } char const* LLVMTripleGetSubArchTypeName( LLVMTripleSubArchType type ) @@ -227,7 +230,7 @@ char const* LLVMTripleGetVendorTypeName( LLVMTripleVendorType vendor ) if( llvmVendorType > Triple::VendorType::LastVendorType ) llvmVendorType = Triple::VendorType::UnknownVendor; - return LLVMCreateMessage( Triple::getVendorTypeName( llvmVendorType ) ); + return LLVMCreateMessage( Triple::getVendorTypeName( llvmVendorType ).data() ); } char const* LLVMTripleGetOsTypeName( LLVMTripleOSType osType ) @@ -236,7 +239,7 @@ char const* LLVMTripleGetOsTypeName( LLVMTripleOSType osType ) if( llvmOsType > Triple::OSType::LastOSType ) llvmOsType = Triple::OSType::UnknownOS; - return LLVMCreateMessage( Triple::getOSTypeName( llvmOsType ) ); + return LLVMCreateMessage( Triple::getOSTypeName( llvmOsType ).data() ); } char const* LLVMTripleGetEnvironmentTypeName( LLVMTripleEnvironmentType environmentType ) @@ -245,7 +248,7 @@ char const* LLVMTripleGetEnvironmentTypeName( LLVMTripleEnvironmentType environm if( llvmEnvironmentType > Triple::EnvironmentType::LastEnvironmentType ) llvmEnvironmentType = Triple::EnvironmentType::UnknownEnvironment; - return LLVMCreateMessage( Triple::getEnvironmentTypeName( llvmEnvironmentType ) ); + return LLVMCreateMessage( Triple::getEnvironmentTypeName( llvmEnvironmentType ).data() ); } char const* LLVMTripleGetObjectFormatTypeName( LLVMTripleObjectFormatType objectFormatType ) diff --git a/src/LibLLVM/TripleBindings.h b/src/LibLLVM/TripleBindings.h index cb47c4c36..7555d7841 100644 --- a/src/LibLLVM/TripleBindings.h +++ b/src/LibLLVM/TripleBindings.h @@ -59,6 +59,7 @@ enum LLVMTripleSubArchType LlvmTripleSubArchType_ARMSubArch_v8_2a, LlvmTripleSubArchType_ARMSubArch_v8_1a, LlvmTripleSubArchType_ARMSubArch_v8, + LlvmTripleSubArchType_ARMSubArch_v8r, LlvmTripleSubArchType_ARMSubArch_v8m_baseline, LlvmTripleSubArchType_ARMSubArch_v8m_mainline, LlvmTripleSubArchType_ARMSubArch_v7, diff --git a/src/LibLLVM/ValueBindings.cpp b/src/LibLLVM/ValueBindings.cpp index e3a41dcdc..278820a0d 100644 --- a/src/LibLLVM/ValueBindings.cpp +++ b/src/LibLLVM/ValueBindings.cpp @@ -69,5 +69,10 @@ extern "C" auto pAlias = unwrap( Val ); return wrap( pAlias->getAliasee( ) ); } -} + void LLVMGlobalVariableAddDebugExpression( LLVMValueRef /*GlobalVariable*/ globalVar, LLVMMetadataRef exp ) + { + auto gv = unwrap( globalVar ); + gv->addDebugInfo( unwrap( exp )); + } +} diff --git a/src/LibLLVM/ValueBindings.h b/src/LibLLVM/ValueBindings.h index 51025ef8a..1ec49dec1 100644 --- a/src/LibLLVM/ValueBindings.h +++ b/src/LibLLVM/ValueBindings.h @@ -11,7 +11,7 @@ extern "C" { LLVMBool LLVMIsConstantZeroValue( LLVMValueRef valueRef ); void LLVMRemoveGlobalFromParent( LLVMValueRef valueRef ); - + LLVMValueRef LLVMBuildIntCast2( LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, LLVMBool isSigned, const char *Name ); int LLVMGetValueID( LLVMValueRef valueRef); LLVMValueRef LLVMMetadataAsValue( LLVMContextRef context, LLVMMetadataRef metadataRef ); @@ -22,6 +22,7 @@ extern "C" { LLVMComdatRef LLVMGlobalObjectGetComdat( LLVMValueRef Val ); void LLVMGlobalObjectSetComdat( LLVMValueRef Val, LLVMComdatRef comdatRef ); + void LLVMGlobalVariableAddDebugExpression( LLVMValueRef /*GlobalVariable*/ globalVar, LLVMMetadataRef exp ); #ifdef __cplusplus } #endif diff --git a/src/LibLLVM/packages.config b/src/LibLLVM/packages.config new file mode 100644 index 000000000..b43193f99 --- /dev/null +++ b/src/LibLLVM/packages.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/LibLlvm.sln b/src/LibLlvm.sln new file mode 100644 index 000000000..7edc5e261 --- /dev/null +++ b/src/LibLlvm.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibLLVM", "LibLLVM\LibLLVM.vcxproj", "{6C77A7DE-D464-430F-96A9-A64768763B5F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiPlatformBuild", "LibLLVM\MultiPlatformBuild.vcxproj", "{C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|x64.ActiveCfg = Debug|x64 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|x64.Build.0 = Debug|x64 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|x86.ActiveCfg = Debug|Win32 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|x86.Build.0 = Debug|Win32 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|x64.ActiveCfg = Release|x64 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|x64.Build.0 = Release|x64 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|x86.ActiveCfg = Release|Win32 + {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|x86.Build.0 = Release|Win32 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Debug|x64.ActiveCfg = Debug|x64 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Debug|x64.Build.0 = Debug|x64 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Debug|x86.ActiveCfg = Debug|Win32 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Debug|x86.Build.0 = Debug|Win32 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Release|x64.ActiveCfg = Release|x64 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Release|x64.Build.0 = Release|x64 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Release|x86.ActiveCfg = Release|Win32 + {C182D24F-0A4C-4A60-B6F5-CFD8D99329AC}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EF28D186-279B-4E91-9BE8-644B6E018432} + EndGlobalSection +EndGlobal diff --git a/src/Llvm.NET.sln b/src/Llvm.NET.sln index 96a77e5fd..3654f2937 100644 --- a/src/Llvm.NET.sln +++ b/src/Llvm.NET.sln @@ -1,92 +1,31 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.3 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibLLVM", "LibLLVM\LibLLVM.vcxproj", "{6C77A7DE-D464-430F-96A9-A64768763B5F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llvm.NET", "Llvm.NET\Llvm.NET.csproj", "{0162C8CE-6641-4922-8664-F8A44356FBF7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Llvm.NET", "Llvm.NET\Llvm.NET.csproj", "{0162C8CE-6641-4922-8664-F8A44356FBF7}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Llvm.NETTests", "Llvm.NETTests\LLVM.NETTests\Llvm.NETTests.csproj", "{826ADB1C-4BDC-4A89-836B-87088E511D6A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDebugInfo", "Llvm.NETTests\TestDebugInfo\TestDebugInfo.csproj", "{F9914A60-2E4B-472F-B1F3-BD08FD23CA92}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{07FDA2D2-771E-44F4-8862-2E6FCB0E722E}" - ProjectSection(SolutionItems) = preProject - ..\BuildAll.slnproj = ..\BuildAll.slnproj - ..\BuildEnv.props = ..\BuildEnv.props - CustomDictionary.xml = CustomDictionary.xml - ..\LICENSE = ..\LICENSE - NugetPkg\Llvm.NET.nuspec = NugetPkg\Llvm.NET.nuspec - ..\README.md = ..\README.md - ..\VsoUpdateVersion.ps1 = ..\VsoUpdateVersion.ps1 - win32.runsettings = win32.runsettings - x64.runsettings = x64.runsettings - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildExtensions", "BuildExtensions", "{7B7EC2B9-EA80-4F8D-9654-E63C91158B28}" - ProjectSection(SolutionItems) = preProject - ..\BuildExtensions\EnlistmentBuildVersion.targets = ..\BuildExtensions\EnlistmentBuildVersion.targets - ..\BuildExtensions\InlineBuildTasks.targets = ..\BuildExtensions\InlineBuildTasks.targets - ..\BuildExtensions\SolutionProj.Common.props = ..\BuildExtensions\SolutionProj.Common.props - ..\BuildExtensions\SolutionProj.Common.targets = ..\BuildExtensions\SolutionProj.Common.targets - EndProjectSection +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Llvm.NETTests", "Llvm.NETTests\Llvm.NETTests.csproj", "{826ADB1C-4BDC-4A89-836B-87088E511D6A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|Win32.ActiveCfg = Debug|Win32 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|Win32.Build.0 = Debug|Win32 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|x64.ActiveCfg = Debug|x64 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Debug|x64.Build.0 = Debug|x64 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|Any CPU.ActiveCfg = Release|Win32 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|Win32.ActiveCfg = Release|Win32 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|Win32.Build.0 = Release|Win32 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|x64.ActiveCfg = Release|x64 - {6C77A7DE-D464-430F-96A9-A64768763B5F}.Release|x64.Build.0 = Release|x64 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|Win32.ActiveCfg = Debug|Win32 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|Win32.Build.0 = Debug|Win32 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|x64.ActiveCfg = Debug|x64 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|x64.Build.0 = Debug|x64 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|Any CPU.ActiveCfg = Release|Win32 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|Win32.ActiveCfg = Release|Win32 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|Win32.Build.0 = Release|Win32 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|x64.ActiveCfg = Release|x64 - {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|x64.Build.0 = Release|x64 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|Win32.ActiveCfg = Debug|Win32 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|Win32.Build.0 = Debug|Win32 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|x64.ActiveCfg = Debug|x64 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|x64.Build.0 = Debug|x64 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|Any CPU.ActiveCfg = Release|Win32 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|Win32.ActiveCfg = Release|Win32 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|Win32.Build.0 = Release|Win32 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|x64.ActiveCfg = Release|x64 - {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|x64.Build.0 = Release|x64 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Debug|Win32.ActiveCfg = Debug|Win32 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Debug|Win32.Build.0 = Debug|Win32 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Debug|x64.ActiveCfg = Debug|x64 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Debug|x64.Build.0 = Debug|x64 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Release|Any CPU.ActiveCfg = Release|Win32 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Release|Win32.ActiveCfg = Release|Win32 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Release|Win32.Build.0 = Release|Win32 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Release|x64.ActiveCfg = Release|x64 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92}.Release|x64.Build.0 = Release|x64 + {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0162C8CE-6641-4922-8664-F8A44356FBF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0162C8CE-6641-4922-8664-F8A44356FBF7}.Release|Any CPU.Build.0 = Release|Any CPU + {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {826ADB1C-4BDC-4A89-836B-87088E511D6A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {7B7EC2B9-EA80-4F8D-9654-E63C91158B28} = {07FDA2D2-771E-44F4-8862-2E6FCB0E722E} + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EF28D186-279B-4E91-9BE8-644B6E018432} EndGlobalSection EndGlobal diff --git a/src/Llvm.NET/ArgValidationExtensions.cs b/src/Llvm.NET/ArgValidationExtensions.cs index 05cc2ea79..8fff5fb8b 100644 --- a/src/Llvm.NET/ArgValidationExtensions.cs +++ b/src/Llvm.NET/ArgValidationExtensions.cs @@ -20,7 +20,9 @@ internal static T VerifyArgNotNull( this T self, string name ) where T : class { if( self == null ) + { throw new ArgumentNullException( name ); + } return self; } diff --git a/src/Llvm.NET/Comdat.cs b/src/Llvm.NET/Comdat.cs index a66053c46..ab798d8a0 100644 --- a/src/Llvm.NET/Comdat.cs +++ b/src/Llvm.NET/Comdat.cs @@ -18,15 +18,17 @@ internal Comdat( NativeModule module, LLVMComdatRef comdatRef ) Module = module; ComdatHandle = comdatRef; } - + public string Name { get { if( Module.IsDisposed ) + { return string.Empty; - else - return NativeMethods.MarshalMsg( NativeMethods.ComdatGetName( ComdatHandle ) ); + } + + return NativeMethods.ComdatGetName( ComdatHandle ); } } @@ -35,21 +37,26 @@ public ComdatKind Kind get { if( Module.IsDisposed ) + { return default( ComdatKind ); - else - return (ComdatKind)NativeMethods.ComdatGetKind( ComdatHandle ); + } + + return ( ComdatKind )NativeMethods.ComdatGetKind( ComdatHandle ); } set { if( Module.IsDisposed ) + { return; + } NativeMethods.ComdatSetKind( ComdatHandle, ( LLVMComdatSelectionKind )value ); } } - internal readonly LLVMComdatRef ComdatHandle; - internal readonly NativeModule Module; + internal LLVMComdatRef ComdatHandle { get; } + + internal NativeModule Module { get; } } } diff --git a/src/Llvm.NET/ComdatCollection.cs b/src/Llvm.NET/ComdatCollection.cs index 6c4f0fd1e..a2cedf94c 100644 --- a/src/Llvm.NET/ComdatCollection.cs +++ b/src/Llvm.NET/ComdatCollection.cs @@ -1,8 +1,8 @@ -using Llvm.NET.Native; -using Llvm.NET.Values; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Linq; +using Llvm.NET.Native; +using Llvm.NET.Values; namespace Llvm.NET { @@ -15,32 +15,28 @@ internal ComdatCollection( NativeModule module ) NativeMethods.ModuleEnumerateComdats( Module.ModuleHandle, AddComdat ); } - public Comdat this[ string key ] - { - get - { - return InternalComdatMap[ key ]; - } - } + public Comdat this[ string key ] => InternalComdatMap[ key ]; public int Count => InternalComdatMap.Count; public Comdat Add( string key, ComdatKind kind ) { LLVMComdatRef comdatRef = NativeMethods.ModuleInsertOrUpdateComdat( Module.ModuleHandle, key, ( LLVMComdatSelectionKind )kind ); - Comdat retVal; - if( !InternalComdatMap.TryGetValue( key, out retVal ) ) + if(!InternalComdatMap.TryGetValue( key, out Comdat retVal )) { retVal = new Comdat( Module, comdatRef ); InternalComdatMap.Add( retVal.Name, retVal ); } + return retVal; } public void Clear( ) { - foreach( var obj in ModuleGlobalObjects() ) + foreach( var obj in GetModuleGlobalObjects() ) + { obj.Comdat = null; + } InternalComdatMap.Clear( ); NativeMethods.ModuleComdatClear( Module.ModuleHandle ); @@ -49,30 +45,44 @@ public void Clear( ) public bool Contains( string key ) => InternalComdatMap.ContainsKey( key ); public IEnumerator GetEnumerator( ) => InternalComdatMap.Values.GetEnumerator( ); + IEnumerator IEnumerable.GetEnumerator( ) => InternalComdatMap.Values.GetEnumerator( ); public bool Remove( string key ) { - Comdat value; - if( !InternalComdatMap.TryGetValue( key, out value ) ) + if(!InternalComdatMap.TryGetValue( key, out Comdat value )) { return false; } - var retVal = InternalComdatMap.Remove( key ); + bool retVal = InternalComdatMap.Remove( key ); if( retVal ) { ClearComdatFromGlobals( key ); NativeMethods.ModuleComdatRemove( Module.ModuleHandle, value.ComdatHandle ); } + return retVal; } public bool TryGetValue( string key, out Comdat value ) => InternalComdatMap.TryGetValue( key, out value ); + private IEnumerable GetModuleGlobalObjects() + { + foreach( var gv in Module.Globals.OfType( ) ) + { + yield return gv; + } + + foreach( var func in Module.Functions ) + { + yield return func; + } + } + private void ClearComdatFromGlobals( string name ) { - var matchingGlobals = from gv in ModuleGlobalObjects( ) + var matchingGlobals = from gv in GetModuleGlobalObjects() where gv.Comdat.Name == name select gv; @@ -89,15 +99,6 @@ private bool AddComdat( LLVMComdatRef comdatRef ) return true; } - IEnumerable ModuleGlobalObjects() - { - foreach( var gv in Module.Globals.OfType( ) ) - yield return gv; - - foreach( var func in Module.Functions ) - yield return func; - } - private NativeModule Module; private Dictionary InternalComdatMap = new Dictionary( ); } diff --git a/src/Llvm.NET/Context.cs b/src/Llvm.NET/Context.cs index 314f67b34..1e7b6e401 100644 --- a/src/Llvm.NET/Context.cs +++ b/src/Llvm.NET/Context.cs @@ -1,13 +1,15 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using Llvm.NET.DebugInfo; using Llvm.NET.Native; using Llvm.NET.Types; using Llvm.NET.Values; -using System.Diagnostics.CodeAnalysis; + +#pragma warning disable SA1124 // DoNotUseRegions namespace Llvm.NET { @@ -19,7 +21,7 @@ namespace Llvm.NET /// without causing them to collide namespaces and types even if they use /// the same name (e.g. module one may have a type Foo, and so does module /// two but they are completely distinct from each other) - /// + /// /// LLVM Debug information is ultimately all parented to a top level /// as the scope, and a compilation /// unit is bound to a , even though, technically @@ -33,7 +35,8 @@ namespace Llvm.NET /// LLVM objects from multiple threads may lead to race conditions corrupted /// state and any number of other undefined issues. /// - public sealed class Context : IDisposable + public sealed class Context + : IDisposable { /// Creates a new context public Context( ) @@ -41,6 +44,18 @@ public Context( ) { } + ~Context( ) + { + DisposeContext( ); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose( ) + { + DisposeContext( ); + GC.SuppressFinalize( this ); + } + /// Flag to indicate if this instance is still valid public bool IsDisposed => ContextHandle.Pointer == IntPtr.Zero; @@ -80,10 +95,14 @@ public Context( ) public IPointerType GetPointerTypeFor( ITypeRef elementType ) { if( elementType == null ) + { throw new ArgumentNullException( nameof( elementType ) ); + } if( elementType.Context != this ) + { throw new ArgumentException( "Cannot mix types from different contexts", nameof( elementType ) ); + } return TypeRef.FromHandle( NativeMethods.PointerType( elementType.GetTypeRef( ), 0 ) ); } @@ -98,7 +117,9 @@ public IPointerType GetPointerTypeFor( ITypeRef elementType ) public ITypeRef GetIntType( uint bitWidth ) { if( bitWidth == 0 ) + { throw new ArgumentException( "integer bit width must be greater than 0" ); + } switch( bitWidth ) { @@ -145,17 +166,24 @@ public IFunctionType GetFunctionType( ITypeRef returnType, IEnumerable public IFunctionType GetFunctionType( ITypeRef returnType, IEnumerable args, bool isVarArgs ) { if( returnType == null ) + { throw new ArgumentNullException( nameof( returnType ) ); + } if( ContextHandle.Pointer != returnType.Context.ContextHandle.Pointer ) + { throw new ArgumentException( "Mismatched context", nameof( returnType ) ); + } LLVMTypeRef[ ] llvmArgs = args.Select( a => a.GetTypeRef( ) ).ToArray( ); - var argCount = llvmArgs.Length; + int argCount = llvmArgs.Length; + // have to pass a valid addressable object to native interop // so allocate space for a single value but tell LLVM the length is 0 if( llvmArgs.Length == 0 ) + { llvmArgs = new LLVMTypeRef[ 1 ]; + } var signature = NativeMethods.FunctionType( returnType.GetTypeRef( ), out llvmArgs[ 0 ], ( uint )argCount, isVarArgs ); return TypeRef.FromHandle( signature ); @@ -218,15 +246,19 @@ public DebugFunctionType CreateFunctionType( DebugInfoBuilder diBuilder ) { if( diBuilder == null ) + { throw new ArgumentNullException( nameof( diBuilder ) ); + } if( !retType.HasDebugInfo( ) ) + { throw new ArgumentNullException( nameof( retType ), "Return type does not have debug information" ); + } var nativeArgTypes = new List( ); var debugArgTypes = new List( ); var msg = new StringBuilder( "One or more parameter types ar not valid:\n" ); - var hasParamErrors = false; + bool hasParamErrors = false; foreach( var indexedPair in argTypes.Select( ( t, i ) => new { Type = t, Index = i } ) ) { @@ -240,7 +272,9 @@ public DebugFunctionType CreateFunctionType( DebugInfoBuilder diBuilder nativeArgTypes.Add( indexedPair.Type.NativeType ); debugArgTypes.Add( indexedPair.Type.DIType ); if( indexedPair.Type.HasDebugInfo( ) ) + { continue; + } msg.AppendFormat( "\tArgument {0} does not contain debug type information", indexedPair.Index ); hasParamErrors = true; @@ -249,7 +283,9 @@ public DebugFunctionType CreateFunctionType( DebugInfoBuilder diBuilder // if any parameters don't have errors, then provide a hopefully helpful message indicating which one(s) if( hasParamErrors ) + { throw new ArgumentException( msg.ToString( ), nameof( argTypes ) ); + } var llvmType = GetFunctionType( retType.NativeType, nativeArgTypes, isVarArg ); @@ -275,7 +311,6 @@ public DebugFunctionType CreateFunctionType( DebugInfoBuilder diBuilder /// /// /// - [SuppressMessage( "Language", "CSE0003:Use expression-bodied members", Justification = "Line too long" )] public Constant CreateConstantStruct( bool packed, params Constant[ ] values ) { return CreateConstantStruct( packed, ( IEnumerable )values ); @@ -301,7 +336,9 @@ public Constant CreateConstantStruct( bool packed, IEnumerable values { var valueHandles = values.Select( v => v.ValueHandle ).ToArray( ); if( valueHandles.Length == 0 ) + { throw new ArgumentException( "structure must have at least one element", nameof( values ) ); + } var handle = NativeMethods.ConstStructInContext( ContextHandle, out valueHandles[ 0 ], ( uint )valueHandles.Length, packed ); return Value.FromHandle( handle ); @@ -323,7 +360,6 @@ public Constant CreateConstantStruct( bool packed, IEnumerable values /// /// /// - [SuppressMessage( "Language", "CSE0003:Use expression-bodied members", Justification = "Line too long" )] public Constant CreateNamedConstantStruct( IStructType type, params Constant[ ] values ) { return CreateNamedConstantStruct( type, ( IEnumerable )values ); @@ -348,15 +384,21 @@ public Constant CreateNamedConstantStruct( IStructType type, params Constant[ ] public Constant CreateNamedConstantStruct( IStructType type, IEnumerable values ) { if( type == null ) + { throw new ArgumentNullException( nameof( type ) ); + } if( type.Context != this ) + { throw new ArgumentException( "Cannot create named constant struct with type from another context", nameof( type ) ); + } var valueList = values as IList ?? values.ToList( ); var valueHandles = valueList.Select( v => v.ValueHandle ).ToArray( ); if( type.Members.Count != valueHandles.Length ) + { throw new ArgumentException( "Number of values provided must match the number of elements in the specified type" ); + } var mismatchedTypes = from indexedVal in valueList.Select( ( v, i ) => new { Value = v, Index = i } ) where indexedVal.Value.NativeType != type.Members[ indexedVal.Index ] @@ -374,6 +416,7 @@ public Constant CreateNamedConstantStruct( IStructType type, IEnumerable( handle ); @@ -410,12 +455,16 @@ public IStructType CreateStructType( string name ) public IStructType CreateStructType( bool packed, ITypeRef element0, params ITypeRef[ ] elements ) { if( elements == null ) + { throw new ArgumentNullException( nameof( elements ) ); + } LLVMTypeRef[ ] llvmArgs = new LLVMTypeRef[ elements.Length + 1 ]; llvmArgs[ 0 ] = element0.GetTypeRef( ); for( int i = 1; i < llvmArgs.Length; ++i ) + { llvmArgs[ i ] = elements[ i - 1 ].GetTypeRef( ); + } var handle = NativeMethods.StructTypeInContext( ContextHandle, out llvmArgs[ 0 ], ( uint )llvmArgs.Length, packed ); return TypeRef.FromHandle( handle ); @@ -432,18 +481,21 @@ public IStructType CreateStructType( bool packed, ITypeRef element0, params ITyp /// If the elements argument list is empty then an opaque type is created (e.g. a forward reference) /// The method provides a means to add a body to /// an opaque type at a later time if the details of the body are required. (If only pointers to - /// to the type are required the body isn't required) + /// to the type are required the body isn't required) /// public IStructType CreateStructType( string name, bool packed, params ITypeRef[ ] elements ) { if( elements == null ) + { throw new ArgumentNullException( nameof( elements ) ); + } var retVal = TypeRef.FromHandle( NativeMethods.StructCreateNamed( ContextHandle, name ) ); if( elements.Length > 0 ) { retVal.SetBody( packed, elements ); } + return retVal; } @@ -461,13 +513,15 @@ public MDString CreateMetadataString( string value ) /// string to convert into an LLVM constant value /// new /// - /// This converts th string to ANSI form and creates an LLVM constant array of i8 + /// This converts th string to ANSI form and creates an LLVM constant array of i8 /// characters for the data without any terminating null character. /// public ConstantDataArray CreateConstantString( string value ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } var handle = NativeMethods.ConstStringInContext( ContextHandle, value, ( uint )value.Length, true ); return Value.FromHandle( handle ); @@ -478,13 +532,15 @@ public ConstantDataArray CreateConstantString( string value ) /// flag to indicate if the string should include a null terminator /// new /// - /// This converts the string to ANSI form and creates an LLVM constant array of i8 + /// This converts the string to ANSI form and creates an LLVM constant array of i8 /// characters for the data without any terminating null character. /// public ConstantDataArray CreateConstantString( string value, bool nullTerminate ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } var handle = NativeMethods.ConstStringInContext( ContextHandle, value, ( uint )value.Length, !nullTerminate ); return Value.FromHandle( handle ); @@ -497,7 +553,7 @@ public Constant CreateConstant( bool constValue ) { var handle = NativeMethods.ConstInt( BoolType.GetTypeRef( ) , ( ulong )( constValue ? 1 : 0 ) - , new LLVMBool( 0 ) + , false ); return Value.FromHandle( handle ); } @@ -507,7 +563,7 @@ public Constant CreateConstant( bool constValue ) /// representing the value public Constant CreateConstant( byte constValue ) { - var handle = NativeMethods.ConstInt( Int8Type.GetTypeRef( ), constValue, new LLVMBool( 0 ) ); + var handle = NativeMethods.ConstInt( Int8Type.GetTypeRef( ), constValue, false ); return Value.FromHandle( handle ); } @@ -516,7 +572,7 @@ public Constant CreateConstant( byte constValue ) /// representing the value public Constant CreateConstant( sbyte constValue ) { - var handle = NativeMethods.ConstInt( Int8Type.GetTypeRef( ), ( ulong )constValue, new LLVMBool( 1 ) ); + var handle = NativeMethods.ConstInt( Int8Type.GetTypeRef( ), ( ulong )constValue, true ); return Value.FromHandle( handle ); } @@ -525,7 +581,7 @@ public Constant CreateConstant( sbyte constValue ) /// representing the value public Constant CreateConstant( Int16 constValue ) { - var handle = NativeMethods.ConstInt( Int16Type.GetTypeRef( ), ( ulong )constValue, new LLVMBool( 1 ) ); + var handle = NativeMethods.ConstInt( Int16Type.GetTypeRef( ), ( ulong )constValue, true ); return Value.FromHandle( handle ); } @@ -534,7 +590,7 @@ public Constant CreateConstant( Int16 constValue ) /// representing the value public Constant CreateConstant( UInt16 constValue ) { - var handle = NativeMethods.ConstInt( Int16Type.GetTypeRef( ), constValue, new LLVMBool( 0 ) ); + var handle = NativeMethods.ConstInt( Int16Type.GetTypeRef( ), constValue, false ); return Value.FromHandle( handle ); } @@ -543,7 +599,7 @@ public Constant CreateConstant( UInt16 constValue ) /// representing the value public Constant CreateConstant( Int32 constValue ) { - var handle = NativeMethods.ConstInt( Int32Type.GetTypeRef( ), ( ulong )constValue, new LLVMBool( 1 ) ); + var handle = NativeMethods.ConstInt( Int32Type.GetTypeRef( ), ( ulong )constValue, true ); return Value.FromHandle( handle ); } @@ -552,7 +608,7 @@ public Constant CreateConstant( Int32 constValue ) /// representing the value public Constant CreateConstant( UInt32 constValue ) { - var handle = NativeMethods.ConstInt( Int32Type.GetTypeRef( ), constValue, new LLVMBool( 0 ) ); + var handle = NativeMethods.ConstInt( Int32Type.GetTypeRef( ), constValue, false ); return Value.FromHandle( handle ); } @@ -561,7 +617,7 @@ public Constant CreateConstant( UInt32 constValue ) /// representing the value public Constant CreateConstant( Int64 constValue ) { - var handle = NativeMethods.ConstInt( Int64Type.GetTypeRef( ), ( ulong )constValue, new LLVMBool( 1 ) ); + var handle = NativeMethods.ConstInt( Int64Type.GetTypeRef( ), ( ulong )constValue, true ); return Value.FromHandle( handle ); } @@ -570,7 +626,7 @@ public Constant CreateConstant( Int64 constValue ) /// representing the value public Constant CreateConstant( UInt64 constValue ) { - var handle = NativeMethods.ConstInt( Int64Type.GetTypeRef( ), constValue, new LLVMBool( 0 ) ); + var handle = NativeMethods.ConstInt( Int64Type.GetTypeRef( ), constValue, false ); return Value.FromHandle( handle ); } @@ -593,13 +649,19 @@ public Constant CreateConstant( uint bitWidth, UInt64 constValue, bool signExten public Constant CreateConstant( ITypeRef intType, UInt64 constValue, bool signExtend ) { if( intType == null ) + { throw new ArgumentNullException( nameof( intType ) ); + } if( intType.Context != this ) + { throw new ArgumentException( "Cannot mix types from different contexts", nameof( intType ) ); + } if( intType.Kind != TypeKind.Integer ) + { throw new ArgumentException( "Integer type required", nameof( intType ) ); + } return Value.FromHandle( NativeMethods.ConstInt( intType.GetTypeRef( ), constValue, signExtend ) ); } @@ -622,41 +684,113 @@ public ConstantFP CreateConstant( double constValue ) return Value.FromHandle( NativeMethods.ConstReal( DoubleType.GetTypeRef( ), constValue ) ); } - // These methods provide unique mapping between the .NET wrappers and the underlying LLVM instances - // The mapping ensures that any LibLLVM handle is always re-mappable to a exactly one wrapper instance. - // This helps reduce the number of wrapper instances created and also allows reference equality to work - // as expected for managed types. - #region Interning Factories - internal void AddModule( NativeModule module ) + /// Creates a simple boolean attribute + /// Kind of attribute + public AttributeValue CreateAttribute( AttributeKind kind ) { - ModuleCache.Add( module.ModuleHandle.Pointer, module ); + if( kind.RequiresIntValue( ) ) + { + throw new ArgumentException( $"Attribute {kind} requires a value", nameof( kind ) ); + } + + return CreateAttribute( kind, 0ul ); } - internal void RemoveModule( NativeModule module ) + /// Creates an attribute with an integer value parameter + /// The kind of attribute + /// Value for the attribute + /// + /// Not all attributes support a value and those that do don't all support + /// a full 64bit value. The following table provides the kinds of attributes + /// accepting a value and the allowed size of the values. + /// + /// Bit Length + /// 32 + /// 32 + /// 64 + /// 64 + /// + /// + public AttributeValue CreateAttribute( AttributeKind kind, UInt64 value ) { - ModuleCache.Remove( module.ModuleHandle.Pointer ); + var handle = NativeMethods.CreateEnumAttribute( ContextHandle + , kind.GetEnumAttributeId( ) + , value + ); + return AttributeValue.FromHandle( this, handle ); } - internal NativeModule GetModuleFor( LLVMModuleRef moduleRef ) + /// Adds a valueless named attribute + /// Attribute name + public AttributeValue CreateAttribute( string name ) => CreateAttribute( name, string.Empty); + + /// Adds a Target specific named attribute with value + /// Name of the attribute + /// Value of the attribute + public AttributeValue CreateAttribute( string name, string value ) { - if( moduleRef.Pointer == IntPtr.Zero ) - throw new ArgumentNullException( nameof( moduleRef ) ); + if(string.IsNullOrEmpty(name)) + { + throw new ArgumentException( "Cannot be null or empty", nameof( name ) ); + } - var hModuleContext = NativeMethods.GetModuleContext( moduleRef ); - if( hModuleContext.Pointer != ContextHandle.Pointer ) - throw new ArgumentException( "Incorrect context for module" ); + var handle = NativeMethods.CreateStringAttribute( ContextHandle, name, ( uint )name.Length, value, ( uint )( value?.Length ?? 0 ) ); + return AttributeValue.FromHandle(this, handle ); + } - NativeModule retVal; - if( !ModuleCache.TryGetValue( moduleRef.Pointer, out retVal ) ) - retVal = new NativeModule( moduleRef ); + // looks up an attribute by it's handle, if none is found a new manaeged wrapper is created + // The factory as a Func<> allows for the constructor to remain private so that the only + // way to create an AttributeValue is via the containing context. This ensures that the + // proper ownership is maintained. (LLVM has no method of retrieving the context that owns an attribute) + internal AttributeValue GetAttributeFor( LLVMAttributeRef handle, Func factory ) + { + if( handle.Pointer.IsNull( ) ) + { + return default( AttributeValue ); + } + + if( AttributeValueCache.TryGetValue( handle.Pointer, out AttributeValue retVal ) ) + { + return retVal; + } + retVal = factory( this, handle ); + AttributeValueCache.Add( handle.Pointer, retVal ); return retVal; } + // These interning methods provide unique mapping between the .NET wrappers and the underlying LLVM instances + // The mapping ensures that any LibLLVM handle is always re-mappable to a exactly one wrapper instance. + // This helps reduce the number of wrapper instances created and also allows reference equality to work + // as expected for managed types. + // TODO: Refactor the interning to class dedicated to managing the mappings, this can allow looking up the + // context from handles where ther isn't any APIs to retrieve the Context. + #region LLVM handle Interning + + internal static Context GetContextFor( LLVMContextRef contextRef ) + { + if( contextRef.Pointer == IntPtr.Zero ) + { + return null; + } + + lock( ContextCache ) + { + if( ContextCache.TryGetValue( contextRef, out Context retVal ) ) + { + return retVal; + } + + return new Context( contextRef ); + } + } + internal static Context GetContextFor( LLVMModuleRef moduleRef ) { if( moduleRef.Pointer == IntPtr.Zero ) + { return null; + } var hContext = NativeMethods.GetModuleContext( moduleRef ); Debug.Assert( hContext.Pointer != IntPtr.Zero ); @@ -666,7 +800,9 @@ internal static Context GetContextFor( LLVMModuleRef moduleRef ) internal static Context GetContextFor( LLVMValueRef valueRef ) { if( valueRef.Pointer == IntPtr.Zero ) + { return null; + } var hType = NativeMethods.TypeOf( valueRef ); Debug.Assert( hType.Pointer != IntPtr.Zero ); @@ -676,46 +812,64 @@ internal static Context GetContextFor( LLVMValueRef valueRef ) internal static Context GetContextFor( LLVMTypeRef typeRef ) { if( typeRef.Pointer == IntPtr.Zero ) + { return null; + } var hContext = NativeMethods.GetTypeContext( typeRef ); Debug.Assert( hContext.Pointer != IntPtr.Zero ); return GetContextFor( hContext ); } - internal static Context GetContextFor( LLVMContextRef contextRef ) - { - if( contextRef.Pointer == IntPtr.Zero ) - return null; - - lock ( ContextCache ) - { - Context retVal; - if( ContextCache.TryGetValue( contextRef, out retVal ) ) - return retVal; - - return new Context( contextRef ); - } - } - internal static Context GetContextFor( LLVMMetadataRef handle ) { if( handle == LLVMMetadataRef.Zero ) + { return null; + } var hContext = NativeMethods.GetNodeContext( handle ); Debug.Assert( hContext.Pointer != IntPtr.Zero ); return GetContextFor( hContext ); } + internal void AddModule( NativeModule module ) + { + ModuleCache.Add( module.ModuleHandle.Pointer, module ); + } + + internal void RemoveModule( NativeModule module ) + { + ModuleCache.Remove( module.ModuleHandle.Pointer ); + } + + internal NativeModule GetModuleFor( LLVMModuleRef moduleRef ) + { + if( moduleRef.Pointer == IntPtr.Zero ) + { + throw new ArgumentNullException( nameof( moduleRef ) ); + } + + var hModuleContext = NativeMethods.GetModuleContext( moduleRef ); + if( hModuleContext.Pointer != ContextHandle.Pointer ) + { + throw new ArgumentException( "Incorrect context for module" ); + } + + if( !ModuleCache.TryGetValue( moduleRef.Pointer, out NativeModule retVal ) ) + { + retVal = new NativeModule( moduleRef ); + } + + return retVal; + } + internal void RemoveDeletedNode( MDNode node ) { MetadataCache.Remove( node.MetadataHandle ); } - internal LLVMContextRef ContextHandle { get; private set; } - - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Conditional attribute makes this an empty method in release builds" )] + [SuppressMessage( "Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Conditional attribute makes this an empty method in release builds" )] [Conditional( "DEBUG" )] internal void AssertValueNotInterned( LLVMValueRef valueRef ) { @@ -725,11 +879,14 @@ internal void AssertValueNotInterned( LLVMValueRef valueRef ) internal Value GetValueFor( LLVMValueRef valueRef, Func constructor ) { if( valueRef.Pointer == IntPtr.Zero ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } - Value retVal = null; - if( ValueCache.TryGetValue( valueRef.Pointer, out retVal ) ) + if( ValueCache.TryGetValue( valueRef.Pointer, out Value retVal ) ) + { return retVal; + } retVal = constructor( valueRef ); ValueCache.Add( valueRef.Pointer, retVal ); @@ -739,11 +896,14 @@ internal Value GetValueFor( LLVMValueRef valueRef, Func con internal LlvmMetadata GetNodeFor( LLVMMetadataRef handle, Func staticFactory ) { if( handle == LLVMMetadataRef.Zero ) + { throw new ArgumentNullException( nameof( handle ) ); + } - LlvmMetadata retVal = null; - if( MetadataCache.TryGetValue( handle, out retVal ) ) + if( MetadataCache.TryGetValue( handle, out LlvmMetadata retVal ) ) + { return retVal; + } retVal = staticFactory( handle ); MetadataCache.Add( handle, retVal ); @@ -753,21 +913,26 @@ internal LlvmMetadata GetNodeFor( LLVMMetadataRef handle, Func constructor ) { if( valueRef.Pointer == IntPtr.Zero ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } - ITypeRef retVal; - if( TypeCache.TryGetValue( valueRef.Pointer, out retVal ) ) + if( TypeCache.TryGetValue( valueRef.Pointer, out ITypeRef retVal ) ) + { return retVal; + } retVal = constructor( valueRef ); TypeCache.Add( valueRef.Pointer, retVal ); @@ -789,11 +957,9 @@ internal ITypeRef GetTypeFor( LLVMTypeRef valueRef, Func } #endregion - #region IDisposable Support - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "disposing" )] - void Dispose( bool disposing ) + private void DisposeContext( ) { - if( ContextHandle.Pointer != IntPtr.Zero ) + if( !ContextHandle.Pointer.IsNull() ) { NativeMethods.ContextSetDiagnosticHandler( ContextHandle, IntPtr.Zero, IntPtr.Zero ); ActiveHandler.Dispose( ); @@ -802,24 +968,12 @@ void Dispose( bool disposing ) { ContextCache.Remove( ContextHandle ); } + NativeMethods.ContextDispose( ContextHandle ); ContextHandle = default( LLVMContextRef ); } } - ~Context( ) - { - Dispose( false ); - } - - // This code added to correctly implement the disposable pattern. - public void Dispose( ) - { - Dispose( true ); - GC.SuppressFinalize( this ); - } - #endregion - private Context( LLVMContextRef contextRef ) { ContextHandle = contextRef; @@ -832,21 +986,28 @@ private Context( LLVMContextRef contextRef ) NativeMethods.ContextSetDiagnosticHandler( ContextHandle, ActiveHandler.GetFuncPointer( ), IntPtr.Zero ); } - WrappedNativeCallback ActiveHandler; - - private void DiagnosticHandler( LLVMDiagnosticInfoRef param0, IntPtr param1 ) { - var msg = NativeMethods.MarshalMsg( NativeMethods.GetDiagInfoDescription( param0 ) ); + string msg = NativeMethods.GetDiagInfoDescription( param0 ); var level = NativeMethods.GetDiagInfoSeverity( param0 ); Debug.WriteLine( "{0}: {1}", level, msg ); Debug.Assert( level != LLVMDiagnosticSeverity.LLVMDSError ); } + internal LLVMContextRef ContextHandle { get; private set; } + + private WrappedNativeCallback ActiveHandler; + private readonly Dictionary< IntPtr, Value > ValueCache = new Dictionary< IntPtr, Value >( ); + private readonly Dictionary< IntPtr, ITypeRef > TypeCache = new Dictionary< IntPtr, ITypeRef >( ); + private readonly Dictionary< IntPtr, NativeModule > ModuleCache = new Dictionary< IntPtr, NativeModule >( ); + + private readonly Dictionary AttributeValueCache = new Dictionary( ); + private readonly Dictionary< LLVMMetadataRef, LlvmMetadata > MetadataCache = new Dictionary< LLVMMetadataRef, LlvmMetadata >( ); + private readonly Dictionary< LLVMMDOperandRef, MDOperand > MDOperandCache = new Dictionary< LLVMMDOperandRef, MDOperand >( ); private static Dictionary ContextCache = new Dictionary( ); diff --git a/src/Llvm.NET/ContextValidator.cs b/src/Llvm.NET/ContextValidator.cs index 00cfd4416..a42255d2d 100644 --- a/src/Llvm.NET/ContextValidator.cs +++ b/src/Llvm.NET/ContextValidator.cs @@ -46,12 +46,15 @@ public static Context VerifyOperation( this Context context, string message ) public static Context Verify( this Context context, string name, string message, Action failAction ) { if( failAction == null ) + { throw new ArgumentNullException( nameof( failAction ) ); + } if( context == null || context.IsDisposed ) { failAction( name, message ); } + return context; } diff --git a/src/Llvm.NET/DataLayout.cs b/src/Llvm.NET/DataLayout.cs index d1149acd0..7e3b5b109 100644 --- a/src/Llvm.NET/DataLayout.cs +++ b/src/Llvm.NET/DataLayout.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; using Llvm.NET.Types; using Llvm.NET.Values; @@ -37,6 +38,20 @@ namespace Llvm.NET public class DataLayout : IDisposable { + ~DataLayout( ) + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose( false ); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose( ) + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose( true ); + GC.SuppressFinalize( this ); + } + /// Context used for this data (in particular, for retrieving pointer types) public Context Context { get; } @@ -72,7 +87,7 @@ public ITypeRef IntPtrType( uint addressSpace ) /// This method determines the bit size of a type (e.g. the minimum number of /// bits required to represent any value of the given type.) This is distinct from the storage /// and stack size due to various target alignment requirements. - /// + /// public ulong BitSizeOf( ITypeRef typeRef ) { VerifySized( typeRef, nameof( typeRef ) ); @@ -130,31 +145,29 @@ public uint PreferredAlignmentOf( ITypeRef typeRef ) public uint PreferredAlignmentOf( Value value ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } VerifySized( value.NativeType, nameof( value ) ); return NativeMethods.PreferredAlignmentOfGlobal( DataLayoutHandle, value.ValueHandle ); } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] public uint ElementAtOffset( IStructType structType, ulong offset ) { VerifySized( structType, nameof( structType ) ); return NativeMethods.ElementAtOffset( DataLayoutHandle, structType.GetTypeRef( ), offset ); } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] public ulong OffsetOfElement( IStructType structType, uint element ) { VerifySized( structType, nameof( structType ) ); return NativeMethods.OffsetOfElement( DataLayoutHandle, structType.GetTypeRef( ), element ); } - public override string ToString( ) - { - IntPtr msgPtr = NativeMethods.CopyStringRepOfTargetData( DataLayoutHandle ); - return NativeMethods.MarshalMsg( msgPtr ); - } + public override string ToString( ) => NativeMethods.CopyStringRepOfTargetData( DataLayoutHandle ); public ulong ByteSizeOf( ITypeRef llvmType ) => BitSizeOf( llvmType ) / 8u; @@ -176,9 +189,6 @@ public static DataLayout Parse( Context context, string layout ) return FromHandle( context, handle, true ); } - #region IDisposable Support - private readonly bool IsDisposable; - protected virtual void Dispose( bool disposing ) { if( DataLayoutHandle.Pointer != IntPtr.Zero && IsDisposable ) @@ -188,21 +198,6 @@ protected virtual void Dispose( bool disposing ) } } - ~DataLayout( ) - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose( false ); - } - - // This code added to correctly implement the disposable pattern. - public void Dispose( ) - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose( true ); - GC.SuppressFinalize( this ); - } - #endregion - internal DataLayout( Context context, LLVMTargetDataRef targetDataHandle, bool isDisposable ) { DataLayoutHandle = targetDataHandle; @@ -214,12 +209,27 @@ internal static DataLayout FromHandle( Context context, LLVMTargetDataRef target { lock ( TargetDataMap ) { - DataLayout retVal; - if( TargetDataMap.TryGetValue( targetDataRef.Pointer, out retVal ) ) + if( TargetDataMap.TryGetValue( targetDataRef.Pointer, out DataLayout retVal ) ) + { return retVal; + } retVal = new DataLayout( context, targetDataRef, isDisposable ); - TargetDataMap.Add( targetDataRef.Pointer, retVal ); + Func cleanOnException = ( ) => + { + retVal.Dispose( ); + return true; + }; + + try + { + TargetDataMap.Add( targetDataRef.Pointer, retVal ); + } + catch when (cleanOnException()) + { + // NOP + } + return retVal; } } @@ -229,9 +239,13 @@ internal static DataLayout FromHandle( Context context, LLVMTargetDataRef target private static void VerifySized( ITypeRef type, string name ) { if( !type.IsSized ) + { throw new ArgumentException( "Type must be sized to get target size information", name ); + } } + // inidcates if this instance is disposable + private readonly bool IsDisposable; private static readonly Dictionary TargetDataMap = new Dictionary( ); } } diff --git a/src/Llvm.NET/DebugInfo/DIBasicType.cs b/src/Llvm.NET/DebugInfo/DIBasicType.cs index 35da7a870..74aa93ea4 100644 --- a/src/Llvm.NET/DebugInfo/DIBasicType.cs +++ b/src/Llvm.NET/DebugInfo/DIBasicType.cs @@ -3,7 +3,7 @@ namespace Llvm.NET.DebugInfo { /// Debug information for a basic type - /// + /// public class DIBasicType : DIType { internal DIBasicType( LLVMMetadataRef handle ) diff --git a/src/Llvm.NET/DebugInfo/DICompositeType.cs b/src/Llvm.NET/DebugInfo/DICompositeType.cs index 8adb9afbb..d9ae80782 100644 --- a/src/Llvm.NET/DebugInfo/DICompositeType.cs +++ b/src/Llvm.NET/DebugInfo/DICompositeType.cs @@ -12,7 +12,9 @@ internal DICompositeType( LLVMMetadataRef handle ) } public DIType BaseType => Operands[ 3 ].Metadata as DIType; + public IReadOnlyList Elements => new TupleTypedArrayWrapper( Operands[ 4 ].Metadata as MDTuple ); + // TODO: VTableHolder Operands[5] // TODO: TemplateParams Operands[6] // TODO: Identifier Operands[7] diff --git a/src/Llvm.NET/DebugInfo/DIDerivedType.cs b/src/Llvm.NET/DebugInfo/DIDerivedType.cs index e2ff47740..be66b0d17 100644 --- a/src/Llvm.NET/DebugInfo/DIDerivedType.cs +++ b/src/Llvm.NET/DebugInfo/DIDerivedType.cs @@ -9,14 +9,13 @@ internal DIDerivedType( LLVMMetadataRef handle ) : base( handle ) { } - + // operannds: // 0 - File // 1 - Scope // 2 - Name // 3 - Base Type // 4 - Extra data - public DIType BaseType => Operands[ 3 ].Metadata as DIType; } } diff --git a/src/Llvm.NET/DebugInfo/DIFile.cs b/src/Llvm.NET/DebugInfo/DIFile.cs index cfe46d23b..c606c74b2 100644 --- a/src/Llvm.NET/DebugInfo/DIFile.cs +++ b/src/Llvm.NET/DebugInfo/DIFile.cs @@ -1,11 +1,9 @@ -using System; -using System.Runtime.InteropServices; -using Llvm.NET.Native; +using Llvm.NET.Native; namespace Llvm.NET.DebugInfo { /// see - public class DIFile + public class DIFile : DIScope { internal DIFile( LLVMMetadataRef handle ) @@ -13,23 +11,9 @@ internal DIFile( LLVMMetadataRef handle ) { } - public string FileName - { - get - { - IntPtr name = NativeMethods.GetDIFileName( MetadataHandle ); - return Marshal.PtrToStringAnsi( name ); - } - } + public string FileName => NativeMethods.GetDIFileName( MetadataHandle ); - public string Directory - { - get - { - IntPtr dir = NativeMethods.GetDIFileDirectory( MetadataHandle ); - return Marshal.PtrToStringAnsi( dir ); - } - } + public string Directory => NativeMethods.GetDIFileDirectory( MetadataHandle ); public string Path => System.IO.Path.Combine( Directory, FileName ); } diff --git a/src/Llvm.NET/DebugInfo/DIGlobalVariableExpression.cs b/src/Llvm.NET/DebugInfo/DIGlobalVariableExpression.cs new file mode 100644 index 000000000..472fcd62b --- /dev/null +++ b/src/Llvm.NET/DebugInfo/DIGlobalVariableExpression.cs @@ -0,0 +1,29 @@ +using Llvm.NET.Native; + +namespace Llvm.NET.DebugInfo +{ + public class DIGlobalVariableExpression + : MDNode + { + public DIGlobalVariable Variable + { + get + { + LLVMMetadataRef handle = NativeMethods.DIGlobalVarExpGetVariable( MetadataHandle ); + if( handle.Pointer.IsNull( ) ) + { + return null; + } + + return FromHandle( handle ); + } + } + + public DIExpression Expression { get; } + + internal DIGlobalVariableExpression( LLVMMetadataRef handle ) + : base( handle ) + { + } + } +} diff --git a/src/Llvm.NET/DebugInfo/DILocalScope.cs b/src/Llvm.NET/DebugInfo/DILocalScope.cs index 708b8458f..4e8714205 100644 --- a/src/Llvm.NET/DebugInfo/DILocalScope.cs +++ b/src/Llvm.NET/DebugInfo/DILocalScope.cs @@ -10,8 +10,8 @@ internal DILocalScope( LLVMMetadataRef handle ) { } - // returns "this" if the scope is a subprogram, otherwise walks up the scopes to find + // returns "this" if the scope is a subprogram, otherwise walks up the scopes to find // the containing subprogram. - public DISubProgram SubProgram => FromHandle< DISubProgram>( NativeMethods.DILocalScopeGetSubProgram(MetadataHandle) ); + public DISubProgram SubProgram => FromHandle( NativeMethods.DILocalScopeGetSubProgram( MetadataHandle ) ); } } diff --git a/src/Llvm.NET/DebugInfo/DILocation.cs b/src/Llvm.NET/DebugInfo/DILocation.cs index 252685d39..5be194ad6 100644 --- a/src/Llvm.NET/DebugInfo/DILocation.cs +++ b/src/Llvm.NET/DebugInfo/DILocation.cs @@ -15,13 +15,13 @@ public DILocation( Context context, uint line, uint column, DILocalScope scope, , line , column , scope.VerifyArgNotNull(nameof(scope)).MetadataHandle - , inlinedAt?.MetadataHandle ?? LLVMMetadataRef.Zero + , inlinedAt?.MetadataHandle ?? LLVMMetadataRef.Zero ) ) { } - public DILocalScope Scope => FromHandle< DILocalScope >( NativeMethods.GetDILocationScope( MetadataHandle ) ); + public DILocalScope Scope => FromHandle( NativeMethods.GetDILocationScope( MetadataHandle ) ); public uint Line => NativeMethods.GetDILocationLine( MetadataHandle ); @@ -54,7 +54,6 @@ public bool Describes( Function function ) { return Scope.SubProgram.Describes( function ) || InlinedAtScope.SubProgram.Describes( function ); - } internal DILocation( LLVMMetadataRef handle ) diff --git a/src/Llvm.NET/DebugInfo/DINode.cs b/src/Llvm.NET/DebugInfo/DINode.cs index 997424951..7b033f013 100644 --- a/src/Llvm.NET/DebugInfo/DINode.cs +++ b/src/Llvm.NET/DebugInfo/DINode.cs @@ -12,7 +12,9 @@ public Tag Tag get { if( MetadataHandle.Pointer == IntPtr.Zero ) - return (Tag)(ushort.MaxValue); + { + return (Tag)ushort.MaxValue; + } return ( Tag )NativeMethods.DIDescriptorGetTag( MetadataHandle ); } diff --git a/src/Llvm.NET/DebugInfo/DINodeArray.cs b/src/Llvm.NET/DebugInfo/DINodeArray.cs index c126e281d..54ac696ba 100644 --- a/src/Llvm.NET/DebugInfo/DINodeArray.cs +++ b/src/Llvm.NET/DebugInfo/DINodeArray.cs @@ -1,60 +1,11 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Llvm.NET.DebugInfo { - /// Generic wrapper to treat an MDTuple as an array of elements of specific type - /// Type of elements - /// - /// This treats the operands of a tuple as the elements of the array - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix" )] - public class TupleTypedArrayWrapper - : IReadOnlyList - where T : LlvmMetadata - - { - public TupleTypedArrayWrapper( MDTuple tuple ) - { - Tuple = tuple; - } - - public MDTuple Tuple { get; } - - public int Count => Tuple.Operands.Count; - - public T this[ int index ] - { - get - { - if( Tuple == null ) - throw new InvalidOperationException( "Wrapped node is null" ); - - if( index > Tuple.Operands.Count ) - throw new ArgumentOutOfRangeException( nameof( index ) ); - - return Tuple.Operands[ index ].Metadata as T; - } - } - - public IEnumerator GetEnumerator( ) - { - return Tuple.Operands - .Select( n => n.Metadata as T ) - .GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator( ) - { - return GetEnumerator(); - } - } - /// Array of debug information nodes for use with methods /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix" )] + [SuppressMessage( "Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "This matches the wrapped native type" )] public class DINodeArray : TupleTypedArrayWrapper { internal DINodeArray( MDTuple tuple ) diff --git a/src/Llvm.NET/DebugInfo/DIScope.cs b/src/Llvm.NET/DebugInfo/DIScope.cs index 1afbd680e..1cf3c9c23 100644 --- a/src/Llvm.NET/DebugInfo/DIScope.cs +++ b/src/Llvm.NET/DebugInfo/DIScope.cs @@ -16,7 +16,9 @@ public DIFile File { var handle = NativeMethods.DIScopeGetFile( MetadataHandle ); if( handle == LLVMMetadataRef.Zero ) + { return null; + } return MDNode.FromHandle( handle ); } diff --git a/src/Llvm.NET/DebugInfo/DISubProgram.cs b/src/Llvm.NET/DebugInfo/DISubProgram.cs index 0a324cdde..58d73be75 100644 --- a/src/Llvm.NET/DebugInfo/DISubProgram.cs +++ b/src/Llvm.NET/DebugInfo/DISubProgram.cs @@ -1,10 +1,11 @@ -using Llvm.NET.Native; +using System.Diagnostics.CodeAnalysis; +using Llvm.NET.Native; using Llvm.NET.Values; namespace Llvm.NET.DebugInfo { /// see - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "SubProgram" )] + [SuppressMessage( "Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", Justification = "It is already correct 8^)" )] public class DISubProgram : DILocalScope { internal DISubProgram( LLVMMetadataRef handle ) @@ -12,7 +13,8 @@ internal DISubProgram( LLVMMetadataRef handle ) { } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public bool Describes( Function function ) => NativeMethods.SubProgramDescribes( MetadataHandle, function.VerifyArgNotNull( nameof( function )).ValueHandle ); + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + public bool Describes( Function function ) + => NativeMethods.SubProgramDescribes( MetadataHandle, function.VerifyArgNotNull( nameof( function )).ValueHandle ); } } diff --git a/src/Llvm.NET/DebugInfo/DIType.cs b/src/Llvm.NET/DebugInfo/DIType.cs index 65c828bb5..df93b45db 100644 --- a/src/Llvm.NET/DebugInfo/DIType.cs +++ b/src/Llvm.NET/DebugInfo/DIType.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using Llvm.NET.Native; namespace Llvm.NET.DebugInfo @@ -17,7 +16,9 @@ public DebugInfoFlags DebugInfoFlags get { if( MetadataHandle.Pointer == IntPtr.Zero ) + { return 0; + } return ( DebugInfoFlags )NativeMethods.DITypeGetFlags( MetadataHandle ); } @@ -29,31 +30,50 @@ public DIScope Scope { var handle = NativeMethods.DITypeGetScope( MetadataHandle ); if( handle.Pointer == IntPtr.Zero ) + { return null; + } return FromHandle< DIScope >( handle ); } } public UInt32 Line => NativeMethods.DITypeGetLine( MetadataHandle ); + public UInt64 BitSize => NativeMethods.DITypeGetSizeInBits( MetadataHandle ); + public UInt64 BitAlignment => NativeMethods.DITypeGetAlignInBits( MetadataHandle ); + public UInt64 BitOffset => NativeMethods.DITypeGetOffsetInBits( MetadataHandle ); + public bool IsPrivate => ( DebugInfoFlags & DebugInfoFlags.AccessibilityMask ) == DebugInfoFlags.Private; + public bool IsProtected => ( DebugInfoFlags & DebugInfoFlags.AccessibilityMask ) == DebugInfoFlags.Protected; + public bool IsPublic => ( DebugInfoFlags & DebugInfoFlags.AccessibilityMask ) == DebugInfoFlags.Public; + public bool IsForwardDeclaration => DebugInfoFlags.HasFlag( DebugInfoFlags.ForwardDeclaration ); + public bool IsAppleBlockExtension => DebugInfoFlags.HasFlag( DebugInfoFlags.AppleBlock ); + public bool IsBlockByRefStruct => DebugInfoFlags.HasFlag( DebugInfoFlags.BlockByrefStruct ); + public bool IsVirtual => DebugInfoFlags.HasFlag( DebugInfoFlags.Virtual ); + public bool IsArtificial => DebugInfoFlags.HasFlag( DebugInfoFlags.Artificial ); + public bool IsObjectPointer => DebugInfoFlags.HasFlag( DebugInfoFlags.ObjectPointer ); + public bool IsObjClassComplete => DebugInfoFlags.HasFlag( DebugInfoFlags.ObjcClassComplete ); + public bool IsVector => DebugInfoFlags.HasFlag( DebugInfoFlags.Vector ); + public bool IsStaticMember => DebugInfoFlags.HasFlag( DebugInfoFlags.StaticMember ); + public bool IsLvalueReference => DebugInfoFlags.HasFlag( DebugInfoFlags.LValueReference ); + public bool IsRvalueReference => DebugInfoFlags.HasFlag( DebugInfoFlags.RValueReference ); - public string Name => Marshal.PtrToStringAnsi( NativeMethods.DITypeGetName( MetadataHandle ) ); + public string Name => NativeMethods.DITypeGetName( MetadataHandle ); } } diff --git a/src/Llvm.NET/DebugInfo/DIVariable.cs b/src/Llvm.NET/DebugInfo/DIVariable.cs index d55d882d8..f2a7c8190 100644 --- a/src/Llvm.NET/DebugInfo/DIVariable.cs +++ b/src/Llvm.NET/DebugInfo/DIVariable.cs @@ -1,4 +1,5 @@ -using Llvm.NET.Native; +using System.Diagnostics.CodeAnalysis; +using Llvm.NET.Native; namespace Llvm.NET.DebugInfo { @@ -8,8 +9,8 @@ internal DIVariable( LLVMMetadataRef handle ) : base( handle ) { } - - // TODO: UInt32 Line => NativeMethods.DIVariableGetLine( MetadataHandle ); + + /* TODO: UInt32 Line => NativeMethods.DIVariableGetLine( MetadataHandle ); */ public DIScope Scope => Operands[ 0 ]?.Metadata as DIScope; @@ -17,7 +18,7 @@ internal DIVariable( LLVMMetadataRef handle ) public DIFile File => Operands[ 2 ]?.Metadata as DIFile; - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods" )] + [SuppressMessage( "Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "There isn't a better name" )] public DIType Type => Operands[ 3 ]?.Metadata as DIType; } } diff --git a/src/Llvm.NET/DebugInfo/DebugArrayType.cs b/src/Llvm.NET/DebugInfo/DebugArrayType.cs index d371be0d1..9cb12533e 100644 --- a/src/Llvm.NET/DebugInfo/DebugArrayType.cs +++ b/src/Llvm.NET/DebugInfo/DebugArrayType.cs @@ -14,24 +14,32 @@ public class DebugArrayType /// module to use for creating debug information /// Number of elements in the array /// Lower bound of the array [default = 0] + /// Alignment for the type public DebugArrayType( IArrayType llvmType , IDebugType elementType , NativeModule module , uint count , uint lowerBound = 0 + , uint alignment = 0 ) : base( llvmType ) { if( llvmType == null ) + { throw new ArgumentNullException( nameof( llvmType ) ); + } if( elementType == null ) + { throw new ArgumentNullException( nameof( elementType ) ); + } if( llvmType.ElementType.TypeHandle != elementType.TypeHandle ) + { throw new ArgumentException( "elementType doesn't match array element type" ); + } - DIType = CreateDebugInfoForArray( llvmType, elementType, module, count, lowerBound ); + DIType = CreateDebugInfoForArray( llvmType, elementType, module, count, lowerBound, alignment ); DebugElementType = elementType; } @@ -67,7 +75,7 @@ public DebugArrayType( IArrayType llvmType, NativeModule module, DIType elementT /// public ITypeRef ElementType => DebugElementType; - /// + /// public uint Length => NativeType.Length; /// Lower bound of the array, usually but not always zero @@ -79,10 +87,14 @@ public DebugArrayType( IArrayType llvmType, NativeModule module, DIType elementT public void ResolveTemporary( DataLayout layout, DebugInfoBuilder diBuilder ) { if( layout == null ) + { throw new ArgumentNullException( nameof( layout ) ); + } if( diBuilder == null ) + { throw new ArgumentNullException( nameof( diBuilder ) ); + } if( DIType.IsTemporary && !DIType.IsResolved ) { @@ -99,12 +111,13 @@ private static DICompositeType CreateDebugInfoForArray( IArrayType llvmType , NativeModule module , uint count , uint lowerBound + , uint alignment ) { if( llvmType.IsSized ) { return module.DIBuilder.CreateArrayType( module.Layout.BitSizeOf( llvmType ) - , module.Layout.AbiBitAlignmentOf( llvmType ) + , alignment , elementType.DIType , module.DIBuilder.CreateSubRange( lowerBound, count ) ); diff --git a/src/Llvm.NET/DebugInfo/DebugBasicType.cs b/src/Llvm.NET/DebugInfo/DebugBasicType.cs index b48a20b31..c83c7cfc4 100644 --- a/src/Llvm.NET/DebugInfo/DebugBasicType.cs +++ b/src/Llvm.NET/DebugInfo/DebugBasicType.cs @@ -7,7 +7,7 @@ namespace Llvm.NET.DebugInfo /// /// This class provides a binding between an LLVM type and a corresponding . /// In LLVM all primitive types are unnamed and interned. That is, any use of an i8 is always the same - /// type. However, at the source language level it is common to have named primitive types that map + /// type. However, at the source language level it is common to have named primitive types that map /// to the same underlying LLVM. For example, in C and C++ char maps to i8 but so does unsigned char /// (LLVM integral types don't have signed vs unsigned). This class is designed to handle this sort /// of one to many mapping of the lower level LLVM types to source level debugging types. Each @@ -25,16 +25,24 @@ public class DebugBasicType public DebugBasicType( ITypeRef llvmType, NativeModule module, string name, DiTypeKind encoding ) { if( llvmType == null ) + { throw new ArgumentNullException( nameof( llvmType ) ); + } if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( string.IsNullOrWhiteSpace(name) ) + { throw new ArgumentException("non-null non-empty string required", nameof( name ) ); + } if( module.Layout == null ) + { throw new ArgumentException( "Module needs Layout to build basic types", nameof( module ) ); + } switch( llvmType.Kind ) { @@ -56,7 +64,6 @@ public DebugBasicType( ITypeRef llvmType, NativeModule module, string name, DiTy DIType = module.DIBuilder .CreateBasicType( name , module.Layout.BitSizeOf( llvmType ) - , module.Layout.AbiBitAlignmentOf( llvmType ) , encoding ); } @@ -66,7 +73,9 @@ public DebugBasicType( ITypeRef llvmType, NativeModule module, string name, DiTy private static ITypeRef ValidateType( ITypeRef typeRef ) { if( typeRef == null ) + { throw new ArgumentNullException( nameof( typeRef ) ); + } switch( typeRef.Kind ) { diff --git a/src/Llvm.NET/DebugInfo/DebugFunctionType.cs b/src/Llvm.NET/DebugInfo/DebugFunctionType.cs index 47aa867aa..1a3caa868 100644 --- a/src/Llvm.NET/DebugInfo/DebugFunctionType.cs +++ b/src/Llvm.NET/DebugInfo/DebugFunctionType.cs @@ -1,6 +1,6 @@ -using Llvm.NET.Types; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; +using Llvm.NET.Types; namespace Llvm.NET.DebugInfo { diff --git a/src/Llvm.NET/DebugInfo/DebugInfoBuilder.cs b/src/Llvm.NET/DebugInfo/DebugInfoBuilder.cs index 28a94b795..66c801c6d 100644 --- a/src/Llvm.NET/DebugInfo/DebugInfoBuilder.cs +++ b/src/Llvm.NET/DebugInfo/DebugInfoBuilder.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; -using System.Linq; -using Llvm.NET.Values; -using Llvm.NET.Instructions; +using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Linq; using System.Text; +using Llvm.NET.Instructions; using Llvm.NET.Native; +using Llvm.NET.Values; namespace Llvm.NET.DebugInfo { @@ -57,7 +58,7 @@ public DICompileUnit CreateCompileUnit( SourceLanguage language /// Additional tool specific flags /// Runtime version /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "DICompileUnit" )] + [SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "DICompileUnit", Justification = "It is spelled correctly 8^)" )] public DICompileUnit CreateCompileUnit( SourceLanguage language , string fileName , string fileDirectory @@ -68,7 +69,9 @@ public DICompileUnit CreateCompileUnit( SourceLanguage language ) { if( OwningModule.DICompileUnit != null ) + { throw new InvalidOperationException( "LLVM only allows one DICompileUnit per module" ); + } var handle = NativeMethods.DIBuilderCreateCompileUnit( BuilderHandle , ( uint )language @@ -87,20 +90,20 @@ public DICompileUnit CreateCompileUnit( SourceLanguage language /// Creates a /// Containing scope for the namespace or null if the namespace is a global one /// Name of the namespace - /// Source file containing the declaration (may be null if more than one or not known) - /// Line number of the namespace declaration + /// export symbols /// [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public DINamespace CreateNamespace( DIScope scope, string name, DIFile file, uint line ) + public DINamespace CreateNamespace( DIScope scope, string name, bool exportSymbols ) { if( string.IsNullOrWhiteSpace( name ) ) + { throw new ArgumentException( "name cannot be null or empty", nameof( name ) ); + } var handle = NativeMethods.DIBuilderCreateNamespace( BuilderHandle , scope?.MetadataHandle ?? LLVMMetadataRef.Zero , name - , file?.MetadataHandle ?? LLVMMetadataRef.Zero - , line + , exportSymbols ); return MDNode.FromHandle( handle ); } @@ -114,7 +117,9 @@ public DINamespace CreateNamespace( DIScope scope, string name, DIFile file, uin public DIFile CreateFile( string path ) { if( string.IsNullOrWhiteSpace( path ) ) + { return null; + } return CreateFile( Path.GetFileName( path ), Path.GetDirectoryName( path ) ); } @@ -129,7 +134,9 @@ public DIFile CreateFile( string path ) public DIFile CreateFile( string fileName, string directory ) { if( string.IsNullOrWhiteSpace( fileName ) ) + { return null; + } var handle = NativeMethods.DIBuilderCreateFile( BuilderHandle, fileName, directory ?? string.Empty ); return MDNode.FromHandle( handle ); @@ -147,7 +154,9 @@ public DIFile CreateFile( string fileName, string directory ) public DILexicalBlock CreateLexicalBlock( DIScope scope, DIFile file, uint line, uint column ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } var handle = NativeMethods.DIBuilderCreateLexicalBlock( BuilderHandle , scope.MetadataHandle @@ -169,10 +178,14 @@ public DILexicalBlock CreateLexicalBlock( DIScope scope, DIFile file, uint line, public DILexicalBlockFile CreateLexicalBlockFile( DIScope scope, DIFile file, uint discriminator ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( file == null ) + { throw new ArgumentNullException( nameof( file ) ); + } var handle = NativeMethods.DIBuilderCreateLexicalBlockFile( BuilderHandle, scope.MetadataHandle, file.MetadataHandle, discriminator ); return MDNode.FromHandle( handle ); @@ -211,19 +224,29 @@ public DISubProgram CreateFunction( DIScope scope ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( string.IsNullOrWhiteSpace( name ) ) + { name = string.Empty; + } if( string.IsNullOrWhiteSpace( mangledName ) ) + { mangledName = string.Empty; + } if( signatureType == null ) + { throw new ArgumentNullException( nameof( signatureType ) ); + } if( function == null ) + { throw new ArgumentNullException( nameof( function ) ); + } var handle = NativeMethods.DIBuilderCreateFunction( BuilderHandle , scope.MetadataHandle @@ -271,16 +294,24 @@ public DISubProgram ForwardDeclareFunction( DIScope scope ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( subroutineType == null ) + { throw new ArgumentNullException( nameof( subroutineType ) ); + } if( string.IsNullOrWhiteSpace( name ) ) + { name = string.Empty; + } if( string.IsNullOrWhiteSpace( mangledName ) ) + { mangledName = string.Empty; + } var handle = NativeMethods.DIBuilderCreateTempFunctionFwdDecl( BuilderHandle , scope.MetadataHandle @@ -300,7 +331,7 @@ public DISubProgram ForwardDeclareFunction( DIScope scope return MDNode.FromHandle( handle ); } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters" )] + [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] public DILocalVariable CreateLocalVariable( DIScope scope , string name , DIFile file @@ -311,10 +342,14 @@ public DILocalVariable CreateLocalVariable( DIScope scope ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( type == null ) + { throw new ArgumentNullException( nameof( type ) ); + } var handle = NativeMethods.DIBuilderCreateAutoVariable( BuilderHandle , scope.MetadataHandle @@ -338,7 +373,7 @@ public DILocalVariable CreateLocalVariable( DIScope scope /// for this argument /// One based argument index on the method (e.g the first argument is 1 not 0 ) /// representing the function argument - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] public DILocalVariable CreateArgument( DIScope scope , string name , DIFile file @@ -350,10 +385,14 @@ public DILocalVariable CreateArgument( DIScope scope ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( type == null ) + { throw new ArgumentNullException( nameof( type ) ); + } var handle = NativeMethods.DIBuilderCreateParameterVariable( BuilderHandle , scope.MetadataHandle @@ -371,17 +410,16 @@ public DILocalVariable CreateArgument( DIScope scope /// Construct debug information for a basic type (a.k.a. primitive type) /// Name of the type /// Bit size for the type - /// Bit alignment for the type /// encoding for the type /// - public DIBasicType CreateBasicType( string name, ulong bitSize, ulong bitAlign, DiTypeKind encoding ) + public DIBasicType CreateBasicType( string name, UInt64 bitSize, DiTypeKind encoding ) { - var handle = NativeMethods.DIBuilderCreateBasicType( BuilderHandle, name, bitSize, bitAlign, ( uint )encoding ); + var handle = NativeMethods.DIBuilderCreateBasicType( BuilderHandle, name, bitSize, ( uint )encoding ); return MDNode.FromHandle( handle ); } [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public DIDerivedType CreatePointerType( DIType pointeeType, string name, ulong bitSize, ulong bitAlign ) + public DIDerivedType CreatePointerType( DIType pointeeType, string name, UInt64 bitSize, UInt32 bitAlign = 0 ) { var handle = NativeMethods.DIBuilderCreatePointerType( BuilderHandle , pointeeType?.MetadataHandle ?? LLVMMetadataRef.Zero // null == void @@ -396,7 +434,9 @@ public DIDerivedType CreatePointerType( DIType pointeeType, string name, ulong b public DIDerivedType CreateQualifiedType( DIType baseType, QualifiedTypeTag tag ) { if( baseType == null ) + { throw new ArgumentNullException( nameof( baseType ) ); + } var handle = NativeMethods.DIBuilderCreateQualifiedType( BuilderHandle, ( uint )tag, baseType.MetadataHandle ); return MDNode.FromHandle( handle ); @@ -407,11 +447,13 @@ public DIDerivedType CreateQualifiedType( DIType baseType, QualifiedTypeTag tag public DITypeArray CreateTypeArray( IEnumerable types ) { var handles = types.Select( t => t.MetadataHandle ).ToArray( ); - var count = handles.LongLength; + long count = handles.LongLength; if( count == 0 ) + { handles = new[ ] { default( LLVMMetadataRef ) }; + } - var handle = NativeMethods.DIBuilderGetOrCreateTypeArray( BuilderHandle, out handles[ 0 ], ( ulong )count ); + var handle = NativeMethods.DIBuilderGetOrCreateTypeArray( BuilderHandle, out handles[ 0 ], ( UInt64 )count ); return new DITypeArray( handle ); } @@ -419,7 +461,9 @@ public DITypeArray CreateTypeArray( IEnumerable types ) public DISubroutineType CreateSubroutineType( DebugInfoFlags debugFlags, DITypeArray types ) { if( types == null ) + { throw new ArgumentNullException( nameof( types ) ); + } var handle = NativeMethods.DIBuilderCreateSubroutineType( BuilderHandle , types.MetadataHandle @@ -445,18 +489,22 @@ public DICompositeType CreateStructType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign + , UInt64 bitSize + , UInt32 bitAlign , uint flags , DIType derivedFrom , DINodeArray elements ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( elements == null ) + { throw new ArgumentNullException( nameof( elements ) ); + } var handle = NativeMethods.DIBuilderCreateStructType( BuilderHandle , scope.MetadataHandle @@ -476,8 +524,8 @@ public DICompositeType CreateStructType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign + , UInt64 bitSize + , UInt32 bitAlign , DebugInfoFlags debugFlags , DIType derivedFrom , params DINode[ ] elements @@ -490,8 +538,8 @@ public DICompositeType CreateStructType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign + , UInt64 bitSize + , UInt32 bitAlign , DebugInfoFlags debugFlags , DIType derivedFrom , IEnumerable elements @@ -505,17 +553,21 @@ public DICompositeType CreateUnionType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign + , UInt64 bitSize + , UInt32 bitAlign , uint flags , DINodeArray elements ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( elements == null ) + { throw new ArgumentNullException( nameof( elements ) ); + } var handle = NativeMethods.DIBuilderCreateUnionType( BuilderHandle , scope.MetadataHandle @@ -534,8 +586,8 @@ public DICompositeType CreateUnionType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign + , UInt64 bitSize + , UInt32 bitAlign , DebugInfoFlags debugFlags , params DINode[ ] elements ) @@ -547,8 +599,8 @@ public DICompositeType CreateUnionType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign + , UInt64 bitSize + , UInt32 bitAlign , DebugInfoFlags debugFlags , IEnumerable elements ) @@ -561,18 +613,22 @@ public DIDerivedType CreateMemberType( DIScope scope , string name , DIFile file , uint line - , ulong bitSize - , ulong bitAlign - , ulong bitOffset + , UInt64 bitSize + , UInt32 bitAlign + , UInt64 bitOffset , DebugInfoFlags debugFlags , DIType type ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( type == null ) + { throw new ArgumentNullException( nameof( type ) ); + } var handle = NativeMethods.DIBuilderCreateMemberType( BuilderHandle , scope.MetadataHandle @@ -589,19 +645,23 @@ public DIDerivedType CreateMemberType( DIScope scope } [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public DICompositeType CreateArrayType( ulong bitSize, ulong bitAlign, DIType elementType, DINodeArray subscripts ) + public DICompositeType CreateArrayType( UInt64 bitSize, UInt32 bitAlign, DIType elementType, DINodeArray subscripts ) { if( elementType == null ) + { throw new ArgumentNullException( nameof( elementType ) ); + } if( subscripts == null ) + { throw new ArgumentNullException( nameof( subscripts ) ); + } var handle = NativeMethods.DIBuilderCreateArrayType( BuilderHandle, bitSize, bitAlign, elementType.MetadataHandle, subscripts.Tuple.MetadataHandle ); return MDNode.FromHandle( handle ); } - public DICompositeType CreateArrayType( ulong bitSize, ulong bitAlign, DIType elementType, params DINode[ ] subscripts ) + public DICompositeType CreateArrayType( UInt64 bitSize, UInt32 bitAlign, DIType elementType, params DINode[ ] subscripts ) { return CreateArrayType( bitSize, bitAlign, elementType, GetOrCreateArray( subscripts ) ); } @@ -628,20 +688,24 @@ public DISubRange CreateSubRange( long lo, long count ) public DINodeArray GetOrCreateArray( IEnumerable elements ) { var buf = elements.Select( d => d?.MetadataHandle ?? LLVMMetadataRef.Zero ).ToArray( ); - var actualLen = buf.LongLength; + long actualLen = buf.LongLength; + // for the out parameter trick to work - need to have a valid array with at least one element if( buf.LongLength == 0 ) + { buf = new LLVMMetadataRef[ 1 ]; + } - var handle = NativeMethods.DIBuilderGetOrCreateArray( BuilderHandle, out buf[ 0 ], ( ulong )actualLen ); + var handle = NativeMethods.DIBuilderGetOrCreateArray( BuilderHandle, out buf[ 0 ], ( UInt64 )actualLen ); return new DINodeArray( LlvmMetadata.FromHandle( OwningModule.Context, handle ) ); } public DITypeArray GetOrCreateTypeArray( params DIType[ ] types ) => GetOrCreateTypeArray( ( IEnumerable )types ); + public DITypeArray GetOrCreateTypeArray( IEnumerable types ) { var buf = types.Select( t => t?.MetadataHandle ?? LLVMMetadataRef.Zero ).ToArray( ); - var handle = NativeMethods.DIBuilderGetOrCreateTypeArray( BuilderHandle, out buf[ 0 ], ( ulong )buf.LongLength ); + var handle = NativeMethods.DIBuilderGetOrCreateTypeArray( BuilderHandle, out buf[ 0 ], ( UInt64 )buf.LongLength ); return new DITypeArray( handle ); } @@ -656,21 +720,25 @@ public DICompositeType CreateEnumerationType( DIScope scope , string name , DIFile file , uint lineNumber - , ulong sizeInBits - , ulong alignInBits + , UInt64 sizeInBits + , UInt32 alignInBits , IEnumerable elements , DIType underlyingType , string uniqueId = "" ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( underlyingType == null ) + { throw new ArgumentNullException( nameof( underlyingType ) ); + } var elementHandles = elements.Select( e => e.MetadataHandle ).ToArray( ); - var elementArray = NativeMethods.DIBuilderGetOrCreateArray( BuilderHandle, out elementHandles[ 0 ], ( ulong )elementHandles.LongLength ); + var elementArray = NativeMethods.DIBuilderGetOrCreateArray( BuilderHandle, out elementHandles[ 0 ], ( UInt64 )elementHandles.LongLength ); var handle = NativeMethods.DIBuilderCreateEnumerationType( BuilderHandle , scope.MetadataHandle , name @@ -686,38 +754,41 @@ public DICompositeType CreateEnumerationType( DIScope scope } [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public DIGlobalVariable CreateGlobalVariable( DINode scope - , string name - , string linkageName - , DIFile file - , uint lineNo - , DIType type - , bool isLocalToUnit - , Value value - , DINode declaration = null - ) + public DIGlobalVariableExpression CreateGlobalVariableExpression( DINode scope + , string name + , string linkageName + , DIFile file + , uint lineNo + , DIType type + , bool isLocalToUnit + , DIExpression value + , DINode declaration = null + , UInt32 bitAlign = 0 + ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( type == null ) + { throw new ArgumentNullException( nameof( type ) ); + } - if( value == null ) - throw new ArgumentNullException( nameof( value ) ); - - var handle = NativeMethods.DIBuilderCreateGlobalVariable( BuilderHandle - , scope.MetadataHandle - , name - , linkageName - , file?.MetadataHandle ?? LLVMMetadataRef.Zero - , lineNo - , type.MetadataHandle - , isLocalToUnit - , value.ValueHandle - , declaration?.MetadataHandle ?? LLVMMetadataRef.Zero - ); - return MDNode.FromHandle( handle ); + var handle = NativeMethods.DIBuilderCreateGlobalVariableExpression( BuilderHandle + , scope.MetadataHandle + , name + , linkageName + , file?.MetadataHandle ?? LLVMMetadataRef.Zero + , lineNo + , type.MetadataHandle + , isLocalToUnit + , value?.MetadataHandle ?? LLVMMetadataRef.Zero + , declaration?.MetadataHandle ?? LLVMMetadataRef.Zero + , bitAlign + ); + return MDNode.FromHandle( handle ); } public void Finish( ) @@ -732,7 +803,9 @@ where node.IsTemporary && !node.IsResolved { var bldr = new StringBuilder( "Temporaries must be resolved before finalizing debug information:\n" ); foreach( var node in unresolvedTemps ) + { bldr.AppendFormat( "\t{0}\n", node.ToString( ) ); + } throw new InvalidOperationException( bldr.ToString( ) ); } @@ -751,19 +824,29 @@ public Instruction InsertDeclare( Value storage, DILocalVariable varInfo, DILoca public Instruction InsertDeclare( Value storage, DILocalVariable varInfo, DIExpression expression, DILocation location, Instruction insertBefore ) { if( storage == null ) + { throw new ArgumentNullException( nameof( storage ) ); + } if( varInfo == null ) + { throw new ArgumentNullException( nameof( varInfo ) ); + } if( expression == null ) + { throw new ArgumentNullException( nameof( expression ) ); + } if( location == null ) + { throw new ArgumentNullException( nameof( location ) ); + } if( insertBefore == null ) + { throw new ArgumentNullException( nameof( insertBefore ) ); + } var handle = NativeMethods.DIBuilderInsertDeclareBefore( BuilderHandle , storage.ValueHandle @@ -784,22 +867,34 @@ public CallInstruction InsertDeclare( Value storage, DILocalVariable varInfo, DI public CallInstruction InsertDeclare( Value storage, DILocalVariable varInfo, DIExpression espression, DILocation location, BasicBlock insertAtEnd ) { if( storage == null ) + { throw new ArgumentNullException( nameof( storage ) ); + } if( varInfo == null ) + { throw new ArgumentNullException( nameof( varInfo ) ); + } if( espression == null ) + { throw new ArgumentNullException( nameof( espression ) ); + } if( location == null ) + { throw new ArgumentNullException( nameof( location ) ); + } if( insertAtEnd == null ) + { throw new ArgumentNullException( nameof( insertAtEnd ) ); + } if( location.Scope.SubProgram != varInfo.Scope.SubProgram ) + { throw new ArgumentException( "Mismatched scopes for location and variable" ); + } var handle = NativeMethods.DIBuilderInsertDeclareAtEnd( BuilderHandle , storage.ValueHandle @@ -821,7 +916,7 @@ public CallInstruction InsertValue( Value value return InsertValue( value, offset, varInfo, null, location, insertBefore ); } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Interop API requires specific derived type" )] public CallInstruction InsertValue( Value value , UInt64 offset , DILocalVariable varInfo @@ -831,19 +926,29 @@ public CallInstruction InsertValue( Value value ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } if( varInfo == null ) + { throw new ArgumentNullException( nameof( varInfo ) ); + } if( expression == null ) + { throw new ArgumentNullException( nameof( expression ) ); + } if( location == null ) + { throw new ArgumentNullException( nameof( location ) ); + } if( insertBefore == null ) + { throw new ArgumentNullException( nameof( insertBefore ) ); + } var handle = NativeMethods.DIBuilderInsertValueBefore( BuilderHandle , value.ValueHandle @@ -868,7 +973,7 @@ public CallInstruction InsertValue( Value value return InsertValue( value, offset, varInfo, null, location, insertAtEnd ); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Interop API requires specific derived type" )] public CallInstruction InsertValue(Value value , DILocalVariable varInfo , DIExpression expression @@ -879,7 +984,7 @@ public CallInstruction InsertValue(Value value return InsertValue(value, 0, varInfo, expression, location, insertAtEnd); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Interop API requires specific derived type" )] public CallInstruction InsertValue( Value value , UInt64 offset , DILocalVariable varInfo @@ -889,25 +994,39 @@ public CallInstruction InsertValue( Value value ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } if( varInfo == null ) + { throw new ArgumentNullException( nameof( varInfo ) ); + } if( expression == null ) + { throw new ArgumentNullException( nameof( expression ) ); + } if( location == null ) + { throw new ArgumentNullException( nameof( location ) ); + } if( insertAtEnd == null ) + { throw new ArgumentNullException( nameof( insertAtEnd ) ); + } if( location.Scope != varInfo.Scope ) + { throw new ArgumentException( "mismatched scopes" ); + } if( !location.Describes(insertAtEnd.ContainingFunction ) ) + { throw new ArgumentException( "location does not describe the specified block's containing function" ); + } var handle = NativeMethods.DIBuilderInsertValueAtEnd( BuilderHandle , value.ValueHandle @@ -928,23 +1047,25 @@ public CallInstruction InsertValue( Value value public DIExpression CreateExpression( IEnumerable operations ) { var args = operations.Cast( ).ToArray( ); - var actualCount = args.LongLength; + long actualCount = args.LongLength; if( args.Length == 0 ) + { args = new long[ 1 ]; + } - var handle = NativeMethods.DIBuilderCreateExpression( BuilderHandle, out args[ 0 ], ( ulong )actualCount ); + var handle = NativeMethods.DIBuilderCreateExpression( BuilderHandle, out args[ 0 ], ( UInt64 )actualCount ); return new DIExpression( handle ); } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] public DICompositeType CreateReplaceableCompositeType( Tag tag , string name , DINode scope , DIFile file , uint line , uint lang = 0 - , ulong sizeInBits = 0 - , ulong alignBits = 0 + , UInt64 sizeInBits = 0 + , UInt64 alignBits = 0 , DebugInfoFlags flags = DebugInfoFlags.None ) { @@ -981,13 +1102,16 @@ internal DebugInfoBuilder( NativeModule owningModule ) private DebugInfoBuilder( NativeModule owningModule, bool allowUnresolved ) { if( owningModule == null ) + { throw new ArgumentNullException( nameof( owningModule ) ); + } BuilderHandle = NativeMethods.NewDIBuilder( owningModule.ModuleHandle, allowUnresolved ); OwningModule = owningModule; } private bool IsFinished; + internal LLVMDIBuilderRef BuilderHandle { get; private set; } } } diff --git a/src/Llvm.NET/DebugInfo/DebugMemberInfo.cs b/src/Llvm.NET/DebugInfo/DebugMemberInfo.cs index 88f9fa4ab..03c67f178 100644 --- a/src/Llvm.NET/DebugInfo/DebugMemberInfo.cs +++ b/src/Llvm.NET/DebugInfo/DebugMemberInfo.cs @@ -2,45 +2,16 @@ namespace Llvm.NET.DebugInfo { - /// DebugMemberLayout is used to define custom layout information for structure members - /// - /// Ordinarily layout information is handle automatically in - /// - /// however in cases where explicitly controlled (or "packed") layout is required, instances of DebugMemberLayout are - /// used to provide the information necessary to generate a proper type and debug information. - /// - public class DebugMemberLayout - { - /// Constructs a new - /// Size of the member in bits - /// Alignment of the member in bits - /// Offset of the member in bits - public DebugMemberLayout( ulong bitSize, uint bitAlignment, ulong bitOffset ) - { - BitSize = bitSize; - BitAlignment = bitAlignment; - BitOffset = bitOffset; - } - - /// Bit size for the field - public ulong BitSize { get; } - - /// Bit alignment for the field - public uint BitAlignment { get; } - - /// Bit offset for the field in it's containing type - public ulong BitOffset { get; } - } - +#pragma warning disable RECS0013 // Nullable Type can be simplified (It's a full ref in a comment - DUH!) /// Describes a member/field of a type for creating debug information /// - /// This class is used with - /// to provide debug information for a type. + /// This class is used with to provide debug information for a type. /// In order to support explicit layout structures the members relating to layout are all . - /// When they are null then modules target specific layout information is used to determine + /// When they are null then modules target specific layout information is used to determine /// layout details. Setting the layout members of this class to non-null will override that behavior to define explicit /// layout details. /// +#pragma warning restore RECS0013 public class DebugMemberInfo { /// LLVM structure element index this descriptor describes @@ -68,7 +39,7 @@ public class DebugMemberInfo /// If this property is provided (e.g. is not ) for any member of a type, then /// it must be set for all members. In other words explicit layout must be defined for all members /// or none. Furthermore, for types using explicit layout, the type containing this member must - /// include the "packed" modifier. + /// include the "packed" modifier. /// /// public DebugMemberLayout ExplicitLayout { get; set; } diff --git a/src/Llvm.NET/DebugInfo/DebugMemberLayout.cs b/src/Llvm.NET/DebugInfo/DebugMemberLayout.cs new file mode 100644 index 000000000..6d36341df --- /dev/null +++ b/src/Llvm.NET/DebugInfo/DebugMemberLayout.cs @@ -0,0 +1,34 @@ +using Llvm.NET.Types; + +namespace Llvm.NET.DebugInfo +{ + /// DebugMemberLayout is used to define custom layout information for structure members + /// + /// Ordinarily layout information is handle automatically in + /// + /// however in cases where explicitly controlled (or "packed") layout is required, instances of DebugMemberLayout are + /// used to provide the information necessary to generate a proper type and debug information. + /// + public class DebugMemberLayout + { + /// Constructs a new + /// Size of the member in bits + /// Alignment of the member in bits + /// Offset of the member in bits + public DebugMemberLayout( ulong bitSize, uint bitAlignment, ulong bitOffset ) + { + BitSize = bitSize; + BitAlignment = bitAlignment; + BitOffset = bitOffset; + } + + /// Bit size for the field + public ulong BitSize { get; } + + /// Bit alignment for the field + public uint BitAlignment { get; } + + /// Bit offset for the field in it's containing type + public ulong BitOffset { get; } + } +} diff --git a/src/Llvm.NET/DebugInfo/DebugPointerType.cs b/src/Llvm.NET/DebugInfo/DebugPointerType.cs index 8501894ab..8565d9459 100644 --- a/src/Llvm.NET/DebugInfo/DebugPointerType.cs +++ b/src/Llvm.NET/DebugInfo/DebugPointerType.cs @@ -1,4 +1,5 @@ -using Llvm.NET.Types; +using System.Diagnostics.CodeAnalysis; +using Llvm.NET.Types; namespace Llvm.NET.DebugInfo { @@ -12,12 +13,14 @@ public class DebugPointerType /// used for creating the pointer type and debug information /// Target address space for the pointer [Default: 0] /// Name of the type [Default: null] - public DebugPointerType( IDebugType debugElementType, NativeModule module, uint addressSpace = 0, string name = null ) + /// Alignment on pointer + public DebugPointerType( IDebugType debugElementType, NativeModule module, uint addressSpace = 0, string name = null, uint alignment = 0 ) : this( debugElementType.VerifyArgNotNull( nameof( debugElementType ) ).NativeType , module , debugElementType.VerifyArgNotNull( nameof( debugElementType ) ).DIType , addressSpace , name + , alignment ) { } @@ -28,11 +31,13 @@ public DebugPointerType( IDebugType debugElementType, NativeMo /// Debug type of the pointee /// Target address space for the pointer [Default: 0] /// Name of the type [Default: null] - public DebugPointerType( ITypeRef llvmElementType, NativeModule module, DIType elementType, uint addressSpace = 0, string name = null ) + /// Alignment of pointer + public DebugPointerType( ITypeRef llvmElementType, NativeModule module, DIType elementType, uint addressSpace = 0, string name = null, uint alignment = 0 ) : this( llvmElementType.VerifyArgNotNull( nameof( llvmElementType ) ).CreatePointerType( addressSpace ) , module , elementType , name + , alignment ) { } @@ -42,15 +47,17 @@ public DebugPointerType( ITypeRef llvmElementType, NativeModule module, DIType e /// used for creating the pointer type and debug information /// Debug type of the pointee /// Name of the type [Default: null] - public DebugPointerType( IPointerType llvmPtrType, NativeModule module, DIType elementType, string name = null ) + /// Alignment for pointer type + [SuppressMessage( "Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Justification = "VerifyArgNotNull" )] + public DebugPointerType( IPointerType llvmPtrType, NativeModule module, DIType elementType, string name = null, uint alignment = 0 ) : base( llvmPtrType ) { - DIType = module.VerifyArgNotNull( nameof( module ) ) - .DIBuilder + module.VerifyArgNotNull( nameof( module ) ); + DIType = module.DIBuilder .CreatePointerType( elementType , name - , module.VerifyArgNotNull( nameof( module ) ).Layout.BitSizeOf( llvmPtrType ) - , module.VerifyArgNotNull( nameof( module ) ).Layout.AbiBitAlignmentOf( llvmPtrType ) + , module.Layout.BitSizeOf( llvmPtrType ) + , alignment ); } diff --git a/src/Llvm.NET/DebugInfo/DebugStructType.cs b/src/Llvm.NET/DebugInfo/DebugStructType.cs index ef4dab886..9b91e5e87 100644 --- a/src/Llvm.NET/DebugInfo/DebugStructType.cs +++ b/src/Llvm.NET/DebugInfo/DebugStructType.cs @@ -1,7 +1,8 @@ -using Llvm.NET.Types; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using Llvm.NET.Types; namespace Llvm.NET.DebugInfo { @@ -9,6 +10,50 @@ public class DebugStructType : DebugType , IStructType { + public DebugStructType( NativeModule module + , string nativeName + , DIScope scope + , string name + , DIFile diFile + , uint line + , DebugInfoFlags debugFlags + , IEnumerable debugElements + , DIType derivedFrom = null + , bool packed = false + , uint? bitSize = null + , uint bitAlignment = 0 + ) + { + module.VerifyArgNotNull( nameof( module ) ); + DebugMembers = new ReadOnlyCollection( debugElements as IList ?? debugElements.ToList( ) ); + + NativeType = module.Context.CreateStructType( nativeName, packed, debugElements.Select( e => e.DebugType ).ToArray( ) ); + DIType = module.DIBuilder.CreateReplaceableCompositeType( Tag.StructureType + , name + , scope + , diFile + , line + ); + + var memberTypes = from memberInfo in DebugMembers + select CreateMemberType( module, memberInfo ); + + var concreteType = module.DIBuilder.CreateStructType( scope: scope + , name: name + , file: diFile + , line: line + , bitSize: bitSize ?? module.Layout.BitSizeOf( NativeType ) + , bitAlign: bitAlignment + , debugFlags: debugFlags + , derivedFrom: derivedFrom + , elements: memberTypes + ); + + // assignment performs RAUW + DIType = concreteType; + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Justification = "VerifyArgNotNull" )] public DebugStructType( IStructType llvmType , NativeModule module , DIScope scope @@ -18,17 +63,18 @@ public DebugStructType( IStructType llvmType , DebugInfoFlags debugFlags , DIType derivedFrom , IEnumerable elements + , uint alignment = 0 ) : base( llvmType ) { - DIType = module.VerifyArgNotNull( nameof( module ) ) - .DIBuilder + module.VerifyArgNotNull( nameof( module ) ); + DIType = module.DIBuilder .CreateStructType( scope , name , file , line - , module.VerifyArgNotNull( nameof( module ) ).Layout.BitSizeOf( llvmType ) - , module.VerifyArgNotNull( nameof( module ) ).Layout.AbiBitAlignmentOf( llvmType ) + , module.Layout.BitSizeOf( llvmType ) + , alignment , debugFlags , derivedFrom , elements @@ -106,8 +152,9 @@ public void SetBody( bool packed , DebugInfoFlags debugFlags , IEnumerable nativeElements , IEnumerable debugElements + , DIType derivedFrom = null , uint? bitSize = null - , uint? bitAlignment = null + , uint bitAlignment = 0 ) { DebugMembers = new ReadOnlyCollection( debugElements as IList ?? debugElements.ToList( ) ); @@ -120,9 +167,9 @@ public void SetBody( bool packed , file: diFile , line: line , bitSize: bitSize ?? module.Layout.BitSizeOf( NativeType ) - , bitAlign: bitAlignment ?? module.Layout.AbiBitAlignmentOf( NativeType ) + , bitAlign: bitAlignment , debugFlags: debugFlags - , derivedFrom: null + , derivedFrom: derivedFrom , elements: memberTypes ); DIType = concreteType; @@ -130,9 +177,9 @@ public void SetBody( bool packed private DIDerivedType CreateMemberType( NativeModule module, DebugMemberInfo memberInfo ) { - ulong bitSize; - ulong bitAlign; - ulong bitOffset; + UInt64 bitSize; + UInt32 bitAlign; + UInt64 bitOffset; // if explicit layout info provided, use it; // otherwise use module.Layout as the default @@ -145,7 +192,7 @@ private DIDerivedType CreateMemberType( NativeModule module, DebugMemberInfo mem else { bitSize = module.Layout.BitSizeOf( memberInfo.DebugType.NativeType ); - bitAlign = module.Layout.AbiBitAlignmentOf( memberInfo.DebugType.NativeType ); + bitAlign = 0; bitOffset = module.Layout.BitOffsetOfElement( NativeType, memberInfo.Index ); } diff --git a/src/Llvm.NET/DebugInfo/DebugType.cs b/src/Llvm.NET/DebugInfo/DebugType.cs index 379e970f4..a6a3336dd 100644 --- a/src/Llvm.NET/DebugInfo/DebugType.cs +++ b/src/Llvm.NET/DebugInfo/DebugType.cs @@ -12,13 +12,13 @@ namespace Llvm.NET.DebugInfo /// type. (e.g. unsigned char, char, byte and signed byte might all be 8 bit integer values as far /// as LLVM is concerned. Also, when using the pointer+alloca+memcpy pattern to pass by value the /// actual source debug info type is different than the LLVM function signature. This class is used - /// to construct native type and debug info pairing to allow applications to maintain a link from + /// to construct native type and debug info pairing to allow applications to maintain a link from /// their AST or IR types into the LLVM native type and debug information. /// /// /// It is important to note that the relationship between the to it's /// properties is strictly one way. That is, there is no way to take an arbitrary and re-associate - /// it with the DIType or an implementation of this interface as there may be many such mappings to choose from. + /// it with the DIType or an implementation of this interface as there may be many such mappings to choose from. /// /// public interface IDebugType @@ -33,6 +33,7 @@ public interface IDebugType TDebug DIType { get; } } + [SuppressMessage( "StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single class", Justification = "Interface, Generic type and static extension methods form a common type interface" )] public class DebugType : IDebugType , ITypeRef @@ -45,16 +46,14 @@ internal DebugType() internal DebugType( TNative llvmType ) { - if( llvmType == null ) - throw new ArgumentNullException( nameof( llvmType ) ); - - NativeType = llvmType; + NativeType = llvmType ?? throw new ArgumentNullException( nameof( llvmType ) ); } - [SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "DIType" )] + // Re-assignment will perform RAUW on the current value + [SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "DIType", Justification = "It is spelled correctly 8^)" )] public TDebug DIType { - get { return DIType_; } + get => DIType_; set { if( DIType_ == null ) @@ -64,31 +63,47 @@ public TDebug DIType else if( DIType_.IsTemporary ) { if( value.IsTemporary ) + { throw new InvalidOperationException( "Cannot replace a temporary with another temporary" ); + } DIType_.ReplaceAllUsesWith( value ); DIType_ = value; } else + { throw new InvalidOperationException( "Cannot replace non temporary DIType with a new Type" ); + } } } + + [SuppressMessage( "StyleCop.CSharp.NamingRules" + , "SA1310:Field names must not contain underscore" + , Justification = "Trailing _ indicates value MUST NOT be written to directly, even internally" + ) + ] private TDebug DIType_; public TNative NativeType { - get - { - return NativeType_; - } + get => NativeType_; protected set { if( NativeType_ != null ) + { throw new InvalidOperationException( "Once the native type is set it cannot be changed" ); + } + NativeType_ = value; } } + + [SuppressMessage( "StyleCop.CSharp.NamingRules" + , "SA1310:Field names must not contain underscore" + , Justification = "Trailing _ indicates value MUST NOT be written to directly, even internally" + ) + ] private TNative NativeType_; public IntPtr TypeHandle => NativeType.TypeHandle; @@ -130,7 +145,9 @@ protected set public DebugPointerType CreatePointerType( NativeModule module, uint addressSpace ) { if( DIType == null ) + { throw new ArgumentException( "Type does not have associated Debug type from which to construct a pointer type" ); + } var nativePointer = NativeType.CreatePointerType( addressSpace ); return new DebugPointerType( nativePointer, module, DIType, string.Empty ); @@ -139,7 +156,9 @@ public DebugPointerType CreatePointerType( NativeModule module, uint addressSpac public DebugArrayType CreateArrayType( NativeModule module, uint lowerBound, uint count ) { if( DIType == null ) + { throw new ArgumentException( "Type does not have associated Debug type from which to construct an array type" ); + } var llvmArray = NativeType.CreateArrayType( count ); return new DebugArrayType( llvmArray, module, DIType, count, lowerBound ); @@ -148,7 +167,9 @@ public DebugArrayType CreateArrayType( NativeModule module, uint lowerBound, uin public bool TryGetExtendedPropertyValue( string id, out TProperty value ) { if( PropertyContainer.TryGetExtendedPropertyValue( id, out value ) ) + { return true; + } return NativeType.TryGetExtendedPropertyValue( id, out value ); } @@ -185,13 +206,15 @@ public static IDebugType Create( TNative nativ /// /// In LLVM Debug information a is /// used to represent the void type. Thus, looking only at the property is - /// insufficient to distinguish between a type with no debug information and one representing the void - /// type. This property is used to disambiguate the two possibilities. + /// insufficient to distinguish between a type with no debug information and one representing the void + /// type. This property is used to disambiguate the two possibilities. /// public static bool HasDebugInfo( this IDebugType debugType ) { if( debugType == null ) + { throw new ArgumentNullException( nameof( debugType ) ); + } return debugType.DIType != null || debugType.NativeType.IsVoid; } diff --git a/src/Llvm.NET/DebugInfo/DebugUnionType.cs b/src/Llvm.NET/DebugInfo/DebugUnionType.cs index 604c39d46..f027fa951 100644 --- a/src/Llvm.NET/DebugInfo/DebugUnionType.cs +++ b/src/Llvm.NET/DebugInfo/DebugUnionType.cs @@ -1,8 +1,8 @@ -using Llvm.NET.Types; -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using Llvm.NET.Types; namespace Llvm.NET.DebugInfo { @@ -24,19 +24,29 @@ public DebugUnionType( IStructType llvmType : base( llvmType ) { if( llvmType == null ) + { throw new ArgumentNullException( nameof( llvmType ) ); + } if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( file == null ) + { throw new ArgumentNullException( nameof( file ) ); + } if( !llvmType.IsOpaque ) + { throw new ArgumentException( "Struct type used as basis for a union must not have a body", nameof( llvmType ) ); + } DIType = module.DIBuilder .CreateReplaceableCompositeType( Tag.UnionType @@ -57,10 +67,14 @@ public DebugUnionType( NativeModule module ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( file == null ) + { throw new ArgumentNullException( nameof( file ) ); + } NativeType = module.Context.CreateStructType( nativeName ); DIType = module.DIBuilder @@ -70,7 +84,6 @@ public DebugUnionType( NativeModule module , file , line ); - } public bool IsOpaque => NativeType.IsOpaque; @@ -90,25 +103,35 @@ public void SetBody( NativeModule module ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( debugElements == null ) + { throw new ArgumentNullException( nameof( debugElements ) ); + } if( module.Layout == null ) + { throw new ArgumentException( "Module needs Layout to build basic types", nameof( module ) ); + } // Native body is a single element of a type with the largest size - var maxSize = 0UL; + ulong maxSize = 0UL; ITypeRef[ ] nativeMembers = { null }; foreach( var elem in debugElements ) { var bitSize = elem.ExplicitLayout?.BitSize ?? module.Layout?.BitSizeOf( elem.DebugType ); if( !bitSize.HasValue ) + { throw new ArgumentException( "Cannot determine layout for element; The element must have an explicit layout or the module has a layout to use", nameof( debugElements ) ); + } if( maxSize < bitSize.Value ) { @@ -128,7 +151,7 @@ select module.DIBuilder.CreateMemberType( scope: DIType , file: memberInfo.File , line: memberInfo.Line , bitSize: ( memberInfo.ExplicitLayout?.BitSize ?? module.Layout?.BitSizeOf( memberInfo.DebugType ) ).Value - , bitAlign: ( memberInfo.ExplicitLayout?.BitAlignment ?? module.Layout?.AbiBitAlignmentOf( memberInfo.DebugType ) ).Value + , bitAlign: memberInfo.ExplicitLayout?.BitAlignment ?? 0 , bitOffset: 0 , debugFlags: memberInfo.DebugInfoFlags , type: memberInfo.DebugType.DIType diff --git a/src/Llvm.NET/DebugInfo/DwarfEnumerations.cs b/src/Llvm.NET/DebugInfo/DwarfEnumerations.cs index 2d069e895..a037477ad 100644 --- a/src/Llvm.NET/DebugInfo/DwarfEnumerations.cs +++ b/src/Llvm.NET/DebugInfo/DwarfEnumerations.cs @@ -1,5 +1,5 @@ - -using System; +using System; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; namespace Llvm.NET.DebugInfo @@ -7,6 +7,7 @@ namespace Llvm.NET.DebugInfo public enum SourceLanguage { Invalid = 0, + // Language names C89 = 0x0001, C = 0x0002, @@ -45,75 +46,75 @@ public enum SourceLanguage UserMax = 0xffff } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] + [SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32", Justification = "matches interop type from native code" )] public enum Tag : ushort { Invalid = 0, - ArrayType = LLVMDwarfTag.LLVMDwarfTagArrayType, - ClassType= LLVMDwarfTag.LLVMDwarfTagClassType, - EntryPoint= LLVMDwarfTag.LLVMDwarfTagEntryPoint, - EnumerationType= LLVMDwarfTag.LLVMDwarfTagEnumerationType, - FormalParameter= LLVMDwarfTag.LLVMDwarfTagFormalParameter, - ImportedDeclaration= LLVMDwarfTag.LLVMDwarfTagImportedDeclaration, - Label= LLVMDwarfTag.LLVMDwarfTagLabel, - LexicalBlock= LLVMDwarfTag.LLVMDwarfTagLexicalBlock, - Member= LLVMDwarfTag.LLVMDwarfTagMember, - PointerType= LLVMDwarfTag.LLVMDwarfTagPointerType, - ReferenceType= LLVMDwarfTag.LLVMDwarfTagReferenceType, - CompileUnit= LLVMDwarfTag.LLVMDwarfTagCompileUnit, - StringType= LLVMDwarfTag.LLVMDwarfTagStringType, - StructureType= LLVMDwarfTag.LLVMDwarfTagStructureType, - SubroutineType= LLVMDwarfTag.LLVMDwarfTagSubroutineType, - TypeDef= LLVMDwarfTag.LLVMDwarfTagTypeDef, - UnionType= LLVMDwarfTag.LLVMDwarfTagUnionType, - UnspecifiedParameters= LLVMDwarfTag.LLVMDwarfTagUnspecifiedParameters, - Variant= LLVMDwarfTag.LLVMDwarfTagVariant, - CommonBlock= LLVMDwarfTag.LLVMDwarfTagCommonBlock, - CommonInclusion= LLVMDwarfTag.LLVMDwarfTagCommonInclusion, - Inheritance= LLVMDwarfTag.LLVMDwarfTagInheritance, - InlinedSubroutine= LLVMDwarfTag.LLVMDwarfTagInlinedSubroutine, - Module= LLVMDwarfTag.LLVMDwarfTagModule, - PtrToMemberType= LLVMDwarfTag.LLVMDwarfTagPtrToMemberType, - SetType= LLVMDwarfTag.LLVMDwarfTagSetType, - SubrangeType= LLVMDwarfTag.LLVMDwarfTagSubrangeType, - WithStatement= LLVMDwarfTag.LLVMDwarfTagWithStatement, - AccessDeclaration= LLVMDwarfTag.LLVMDwarfTagAccessDeclaration, - BaseType= LLVMDwarfTag.LLVMDwarfTagBaseType, - CatchBlock= LLVMDwarfTag.LLVMDwarfTagCatchBlock, - ConstType= LLVMDwarfTag.LLVMDwarfTagConstType, - Constant= LLVMDwarfTag.LLVMDwarfTagConstant, - Enumerator= LLVMDwarfTag.LLVMDwarfTagEnumerator, - FileType= LLVMDwarfTag.LLVMDwarfTagFileType, - Friend= LLVMDwarfTag.LLVMDwarfTagFriend, - NameList= LLVMDwarfTag.LLVMDwarfTagNameList, - NameListItem= LLVMDwarfTag.LLVMDwarfTagNameListItem, - PackedType= LLVMDwarfTag.LLVMDwarfTagPackedType, - SubProgram = LLVMDwarfTag.LLVMDwarfTagSubProgram, - TemplateTypeParameter= LLVMDwarfTag.LLVMDwarfTagTemplateTypeParameter, - TemplateValueParameter= LLVMDwarfTag.LLVMDwarfTagTemplateValueParameter, - ThrownType= LLVMDwarfTag.LLVMDwarfTagThrownType, - TryBlock= LLVMDwarfTag.LLVMDwarfTagTryBlock, - VariantPart= LLVMDwarfTag.LLVMDwarfTagVariantPart, - Variable= LLVMDwarfTag.LLVMDwarfTagVariable, - VolatileType= LLVMDwarfTag.LLVMDwarfTagVolatileType, - DwarfProcedure= LLVMDwarfTag.LLVMDwarfTagDwarfProcedure, - RestrictType= LLVMDwarfTag.LLVMDwarfTagRestrictType, - InterfaceType= LLVMDwarfTag.LLVMDwarfTagInterfaceType, - Namespace= LLVMDwarfTag.LLVMDwarfTagNamespace, - ImportedModule= LLVMDwarfTag.LLVMDwarfTagImportedModule, - UnspecifiedType= LLVMDwarfTag.LLVMDwarfTagUnspecifiedType, - PartialUnit= LLVMDwarfTag.LLVMDwarfTagPartialUnit, - ImportedUnit= LLVMDwarfTag.LLVMDwarfTagImportedUnit, - Condition= LLVMDwarfTag.LLVMDwarfTagCondition, - SharedType= LLVMDwarfTag.LLVMDwarfTagSharedType, - TypeUnit= LLVMDwarfTag.LLVMDwarfTagTypeUnit, - RValueReferenceType= LLVMDwarfTag.LLVMDwarfTagRValueReferenceType, - TemplateAlias= LLVMDwarfTag.LLVMDwarfTagTemplateAlias, - + ArrayType = LLVMDwarfTag.ArrayType, + ClassType= LLVMDwarfTag.ClassType, + EntryPoint= LLVMDwarfTag.EntryPoint, + EnumerationType= LLVMDwarfTag.EnumerationType, + FormalParameter= LLVMDwarfTag.FormalParameter, + ImportedDeclaration= LLVMDwarfTag.ImportedDeclaration, + Label= LLVMDwarfTag.Label, + LexicalBlock= LLVMDwarfTag.LexicalBlock, + Member= LLVMDwarfTag.Member, + PointerType= LLVMDwarfTag.PointerType, + ReferenceType= LLVMDwarfTag.ReferenceType, + CompileUnit= LLVMDwarfTag.CompileUnit, + StringType= LLVMDwarfTag.StringType, + StructureType= LLVMDwarfTag.StructureType, + SubroutineType= LLVMDwarfTag.SubroutineType, + TypeDef= LLVMDwarfTag.TypeDef, + UnionType= LLVMDwarfTag.UnionType, + UnspecifiedParameters= LLVMDwarfTag.UnspecifiedParameters, + Variant= LLVMDwarfTag.Variant, + CommonBlock= LLVMDwarfTag.CommonBlock, + CommonInclusion= LLVMDwarfTag.CommonInclusion, + Inheritance= LLVMDwarfTag.Inheritance, + InlinedSubroutine= LLVMDwarfTag.InlinedSubroutine, + Module= LLVMDwarfTag.Module, + PtrToMemberType= LLVMDwarfTag.PtrToMemberType, + SetType= LLVMDwarfTag.SetType, + SubrangeType= LLVMDwarfTag.SubrangeType, + WithStatement= LLVMDwarfTag.WithStatement, + AccessDeclaration= LLVMDwarfTag.AccessDeclaration, + BaseType= LLVMDwarfTag.BaseType, + CatchBlock= LLVMDwarfTag.CatchBlock, + ConstType= LLVMDwarfTag.ConstType, + Constant= LLVMDwarfTag.Constant, + Enumerator= LLVMDwarfTag.Enumerator, + FileType= LLVMDwarfTag.FileType, + Friend= LLVMDwarfTag.Friend, + NameList= LLVMDwarfTag.NameList, + NameListItem= LLVMDwarfTag.NameListItem, + PackedType= LLVMDwarfTag.PackedType, + SubProgram = LLVMDwarfTag.SubProgram, + TemplateTypeParameter= LLVMDwarfTag.TemplateTypeParameter, + TemplateValueParameter= LLVMDwarfTag.TemplateValueParameter, + ThrownType= LLVMDwarfTag.ThrownType, + TryBlock= LLVMDwarfTag.TryBlock, + VariantPart= LLVMDwarfTag.VariantPart, + Variable= LLVMDwarfTag.Variable, + VolatileType= LLVMDwarfTag.VolatileType, + DwarfProcedure= LLVMDwarfTag.DwarfProcedure, + RestrictType= LLVMDwarfTag.RestrictType, + InterfaceType= LLVMDwarfTag.InterfaceType, + Namespace= LLVMDwarfTag.Namespace, + ImportedModule= LLVMDwarfTag.ImportedModule, + UnspecifiedType= LLVMDwarfTag.UnspecifiedType, + PartialUnit= LLVMDwarfTag.PartialUnit, + ImportedUnit= LLVMDwarfTag.ImportedUnit, + Condition= LLVMDwarfTag.Condition, + SharedType= LLVMDwarfTag.SharedType, + TypeUnit= LLVMDwarfTag.TypeUnit, + RValueReferenceType= LLVMDwarfTag.RValueReferenceType, + TemplateAlias= LLVMDwarfTag.TemplateAlias, + // New in DWARF 5: // New in DWARF 5: - CoArrayType= LLVMDwarfTag.LLVMDwarfTagCoArrayType, - GenericSubrange= LLVMDwarfTag.LLVMDwarfTagGenericSubrange, - DynamicType= LLVMDwarfTag.LLVMDwarfTagDynamicType, + CoArrayType= LLVMDwarfTag.CoArrayType, + GenericSubrange= LLVMDwarfTag.GenericSubrange, + DynamicType= LLVMDwarfTag.DynamicType, // LLVM Custom constants AutoVariable = 0x100, // Tag for local (auto) variables. @@ -122,16 +123,16 @@ public enum Tag : ushort UserBase = 0x1000, // Recommended base for user tags. - MipsLoop = LLVMDwarfTag.LLVMDwarfTagMipsLoop, - FormatLabel= LLVMDwarfTag.LLVMDwarfTagFormatLabel, - FunctionTemplate= LLVMDwarfTag.LLVMDwarfTagFunctionTemplate, - ClassTemplate= LLVMDwarfTag.LLVMDwarfTagClassTemplate, - GnuTemplateTemplateParameter = LLVMDwarfTag.LLVMDwarfTagGnuTemplateTemplateParam, - GnuTemplateParameterPack= LLVMDwarfTag.LLVMDwarfTagGnuTemplateParameterPack, - GnuFormalParameterPack= LLVMDwarfTag.LLVMDwarfTagGnuFormalParameterPack, - LoUser= LLVMDwarfTag.LLVMDwarfTagLoUser, - AppleProperty= LLVMDwarfTag.LLVMDwarfTagAppleProperty, - HiUser = LLVMDwarfTag.LLVMDwarfTagHiUser + MipsLoop = LLVMDwarfTag.MipsLoop, + FormatLabel= LLVMDwarfTag.FormatLabel, + FunctionTemplate= LLVMDwarfTag.FunctionTemplate, + ClassTemplate= LLVMDwarfTag.ClassTemplate, + GnuTemplateTemplateParameter = LLVMDwarfTag.GnuTemplateTemplateParam, + GnuTemplateParameterPack= LLVMDwarfTag.GnuTemplateParameterPack, + GnuFormalParameterPack= LLVMDwarfTag.GnuFormalParameterPack, + LoUser= LLVMDwarfTag.LoUser, + AppleProperty= LLVMDwarfTag.AppleProperty, + HiUser = LLVMDwarfTag.HiUser } public enum QualifiedTypeTag @@ -141,10 +142,10 @@ public enum QualifiedTypeTag Volatile = Tag.VolatileType, } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum DiTypeKind : uint + public enum DiTypeKind { Invalid = 0, + // Encoding attribute values Address = 0x01, Boolean = 0x02, @@ -171,7 +172,7 @@ public enum DiTypeKind : uint /// The three accessibility flags are mutually exclusive and rolled together /// in the first two bits. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags" )] + [SuppressMessage( "Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags", Justification = "Matches the undelying wrapped API" )] [Flags] public enum DebugInfoFlags { @@ -197,7 +198,8 @@ public enum DebugInfoFlags RValueReference = 1 << 15 } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] +#pragma warning disable SA1300 // Element must begin with upper-case letter + [SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32", Justification = "Mathces underlying interop type" )] public enum ExpressionOp : long { Invalid = 0, @@ -363,4 +365,5 @@ public enum ExpressionOp : long GNU_addr_index = 0xfb, GNU_const_index = 0xfc, } +#pragma warning restore SA1300 // Element must begin with upper-case letter } diff --git a/src/Llvm.NET/DebugInfo/TupleTypedArrayWrapper.cs b/src/Llvm.NET/DebugInfo/TupleTypedArrayWrapper.cs new file mode 100644 index 000000000..3c167a213 --- /dev/null +++ b/src/Llvm.NET/DebugInfo/TupleTypedArrayWrapper.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; + +namespace Llvm.NET.DebugInfo +{ + /// Generic wrapper to treat an MDTuple as an array of elements of specific type + /// Type of elements + /// + /// This treats the operands of a tuple as the elements of the array + /// + [SuppressMessage( "Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Collection doesn't make sense for this type" )] + public class TupleTypedArrayWrapper + : IReadOnlyList + where T : LlvmMetadata + { + public TupleTypedArrayWrapper( MDTuple tuple ) + { + Tuple = tuple; + } + + public MDTuple Tuple { get; } + + public int Count => Tuple.Operands.Count; + + public T this[ int index ] + { + get + { + if( Tuple == null ) + { + throw new InvalidOperationException( "Wrapped node is null" ); + } + + if( index > Tuple.Operands.Count ) + { + throw new ArgumentOutOfRangeException( nameof( index ) ); + } + + return Tuple.Operands[ index ].Metadata as T; + } + } + + public IEnumerator GetEnumerator( ) + { + return Tuple.Operands + .Select( n => n.Metadata as T ) + .GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator( ) => GetEnumerator(); + } +} diff --git a/src/Llvm.NET/EnumerableExtensions.cs b/src/Llvm.NET/EnumerableExtensions.cs index c8da5f189..548f00878 100644 --- a/src/Llvm.NET/EnumerableExtensions.cs +++ b/src/Llvm.NET/EnumerableExtensions.cs @@ -14,33 +14,41 @@ internal static class EnumerableExtensions public static IEnumerable Append( this IEnumerable source, TSource element ) { if( source == null ) + { throw new ArgumentNullException( nameof( source ) ); + } return AppendIterator( source, element ); } - private static IEnumerable AppendIterator( IEnumerable source, TSource element ) - { - foreach( TSource e1 in source ) - yield return e1; - - yield return element; - } - public static IEnumerable Prepend( this IEnumerable source, TSource element ) { if( source == null ) + { throw new ArgumentNullException( nameof( source ) ); + } return PrependIterator( source, element ); } + private static IEnumerable AppendIterator( IEnumerable source, TSource element ) + { + foreach( TSource e1 in source ) + { + yield return e1; + } + + yield return element; + } + private static IEnumerable PrependIterator( IEnumerable source, TSource element ) { yield return element; foreach( TSource e1 in source ) + { yield return e1; + } } } } diff --git a/src/Llvm.NET/Enumerations.cs b/src/Llvm.NET/Enumerations.cs index 594799a2d..e27c49b39 100644 --- a/src/Llvm.NET/Enumerations.cs +++ b/src/Llvm.NET/Enumerations.cs @@ -1,24 +1,27 @@ -// This file maps the lower level internal LLVM enumeration names to something +// This file maps the lower level LLVM.NET.Native.LLVM enumeration names to something // more compatible with the styles, patterns and conventions familiar to .NET Developers. -// This also keeping the lower level interop namespace internal to prevent mis-use or -// violations of uniqueness rules. Furthermore, this helps insulate the managed code -// realm insulated from the sometimes fluid nature of the underlying LLVM changes. +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; namespace Llvm.NET { /// Enumeration to indicate the behavior of module level flags metadata sharing the same name in a - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flag" )] - public enum ModuleFlagBehavior : uint + [SuppressMessage( "Microsoft.Naming" + , "CA1726:UsePreferredTerms" + , MessageId = "Flag" + , Justification = "Enum for the behavior of the LLVM ModuleFlag (Flag in middle doesn't imply the enum is Bit Flags)" )] + public enum ModuleFlagBehavior { /// Invalid value (default value for this enumeration) Invalid = 0, + /// Emits an error if two values disagree, otherwise the resulting value is that of the operands Error = LLVMModFlagBehavior.Error, + /// Emits a warning if two values disagree. The result will be the operand for the flag from the first module being linked Warning = LLVMModFlagBehavior.Warning, + /// Adds a requirement that another module flag be present and have a specified value after linking is performed /// /// The value must be a metadata pair, where the first element of the pair is the ID of the module flag to be restricted, and the @@ -26,22 +29,27 @@ public enum ModuleFlagBehavior : uint /// allowable results (via triggering of an error) of linking IDs with the behavior /// Require = LLVMModFlagBehavior.Require, + /// Uses the specified value, regardless of the behavior or value of the other module /// If both modules specify Override, but the values differ, and error will be emitted Override = LLVMModFlagBehavior.Override, + /// Appends the two values, which are required to be metadata nodes Append = LLVMModFlagBehavior.Append, + /// Appends the two values, which are required to be metadata nodes dropping duplicate entries in the second list - AppendUnique = LLVMModFlagBehavior.AppendUnique - }; + AppendUnique = LLVMModFlagBehavior.AppendUnique, + + /// Takes the max of the two values, which are required to be integers + Max = 7 /*LLVMModFlagBehavior.Max*/ + } /// LLVM Instruction opcodes /// /// These are based on the "C" API and therefore more stable as changes in the underlying instruction ids are remapped in the C API layer /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "Not actually flags" )] - public enum OpCode : uint + [SuppressMessage( "Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "Not actually flags" )] + public enum OpCode { Invalid = 0, /* Terminator Instructions */ @@ -121,95 +129,130 @@ public enum OpCode : uint CleanupRet = LLVMOpcode.LLVMCleanupRet, CatchRet = LLVMOpcode.LLVMCatchRet, CatchPad = LLVMOpcode.LLVMCatchPad, - CleanupPad = LLVMOpcode.LLVMCleandupPad, + CleanupPad = LLVMOpcode.LLVMCleanupPad, CatchSwitch = LLVMOpcode.LLVMCatchSwitch } /// Basic kind of a type - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum TypeKind : uint + public enum TypeKind { /// Type with no size Void = LLVMTypeKind.LLVMVoidTypeKind, + /// 16 bit floating point type Float16 = LLVMTypeKind.LLVMHalfTypeKind, + /// 32 bit floating point type Float32 = LLVMTypeKind.LLVMFloatTypeKind, + /// 64 bit floating point type Float64 = LLVMTypeKind.LLVMDoubleTypeKind, + /// 80 bit floating point type (X87) X86Float80 = LLVMTypeKind.LLVMX86_FP80TypeKind, + /// 128 bit floating point type (112-bit mantissa) Float128m112 = LLVMTypeKind.LLVMFP128TypeKind, + /// 128 bit floating point type (two 64-bits) Float128 = LLVMTypeKind.LLVMPPC_FP128TypeKind, + /// instruction label Label = LLVMTypeKind.LLVMLabelTypeKind, + /// Arbitrary bit width integers Integer = LLVMTypeKind.LLVMIntegerTypeKind, + /// Function = LLVMTypeKind.LLVMFunctionTypeKind, + /// Struct = LLVMTypeKind.LLVMStructTypeKind, + /// Array = LLVMTypeKind.LLVMArrayTypeKind, + /// Pointer = LLVMTypeKind.LLVMPointerTypeKind, + /// SIMD 'packed' format, or other implementation Vector = LLVMTypeKind.LLVMVectorTypeKind, + /// Metadata = LLVMTypeKind.LLVMMetadataTypeKind, + /// x86 MMX data type X86MMX = LLVMTypeKind.LLVMX86_MMXTypeKind, + /// Exception handler token Token = LLVMTypeKind.LLVMTokenTypeKind } + /* valuse for this enum come directly from LLVM's CallingConv.h + // rather then the mapped C API version as the C version is not + // a complete set. + */ + /// Calling Convention for functions - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum CallingConvention : uint + public enum LlvmCallingConvention { - C = LLVMCallConv.LLVMCCallConv, - FastCall = LLVMCallConv.LLVMFastCallConv, - ColdCall = LLVMCallConv.LLVMColdCallConv, - GlasgowHaskellCompiler = LLVMCallConv.LLVMGHCCallConv, - HiPE = LLVMCallConv.LLVMHiPECallConv, - WebKitJS = LLVMCallConv.LLVMWebKitJSCallConv, - AnyReg = LLVMCallConv.LLVMAnyRegCallConv, - PreserveMost = LLVMCallConv.LLVMPreserveMostCallConv, - PreserveSwift = LLVMCallConv.LLVMPreserveSwiftCallConv, - CxxFastTls = LLVMCallConv.LLVMCxxFasTlsCallConv, - FirstTargetSPecific = LLVMCallConv.LLVMFirstTargetCallConv, - X86StdCall = LLVMCallConv.LLVMX86StdcallCallConv, - X86FastCall = LLVMCallConv.LLVMX86FastcallCallConv, - ArmAPCS = LLVMCallConv.LLVMArmAPCSCallConv, - ArmAAPCS = LLVMCallConv.LLVMArmAAPCSCallConv, - ArmAAPCSVfp = LLVMCallConv.LLVMArmAAPCSVfpCallConv, - MPS430Interrupt = LLVMCallConv.LLVMMSP430IntrCallConv, - X86ThisCall = LLVMCallConv.LLVMx86ThisCallConv, - PtxKernel = LLVMCallConv.LLVMPTXKernelCallConv, - PtxDevice = LLVMCallConv.LLVMPTXDeviceCallConv, - SpirFunction = LLVMCallConv.LLVMSpirFuncCallConv, - SpirKernel = LLVMCallConv.LLVMSpirKernelCallConv, - IntelOpenCLBuiltIn = LLVMCallConv.LLVMIntelOCLBICallConv, - X86x64SysV = LLVMCallConv.LLVMx86_64SysVCallConv, - X86x64Win64 = LLVMCallConv.LLVMx86_64Win64CallConv, - X86VectorCall = LLVMCallConv.LLVMx86_VectorCallCallConv, - HHVM = LLVMCallConv.LLVM_HHVMCallConv, - HHVMCCall = LLVMCallConv.LLVM_HHVM_C_CallConv, - X86Interrupt = LLVMCallConv.LLVMx86IntrCallConv, - MaxCallingConvention = LLVMCallConv.LLVM_MaxIDCallConv + C = 0, + + // [gap] + FastCall = 8, + ColdCall = 9, + GlasgowHaskellCompiler = 10, + HiPE = 11, + WebKitJS = 12, + AnyReg = 13, + PreserveMost = 14, + PreserveAll = 15, + Swift = 16, + CxxFastTls = 17, + + // [Gap] + FirstTargetSPecific = 64, // [marker] + X86StdCall = 64, + X86FastCall = 65, + ArmAPCS = 66, // Generally considered obsolete but some older targets use this + ArmAAPCS = 67, + ArmAAPCSVfp = 68, + MSP430Interrupt = 69, + X86ThisCall = 70, + PtxKernel = 71, + PtxDevice = 72, + SpirFunction = 75, + SpirKernel = 76, + IntelOpenCLBuiltIn = 77, + X86x64SysV = 78, + X86x64Win64 = 79, + X86VectorCall = 80, + HHVM = 81, + HHVMCCall = 82, + X86Interrupt = 83, + AVRInterrupt = 84, + AVRSignal = 85, + AVRBuiltIn = 86, + AMDGpuVetexShader = 87, + AMDGpuGeometryShader = 88, + AMDGpuPixelShader = 89, + AMDGpuComputeShader = 90, + AMDGpuKernel = 91, + X86RegCall = 92, + AMDGpuHullShader = 93, + MSP430BuiltIn = 94, + MaxCallingConvention = 1023 } /// Linkage specification for functions and globals - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum Linkage : uint + public enum Linkage { External = LLVMLinkage.LLVMExternalLinkage, /*< Externally visible function */ AvailableExternally = LLVMLinkage.LLVMAvailableExternallyLinkage, LinkOnceAny = LLVMLinkage.LLVMLinkOnceAnyLinkage, /*< Keep one copy of function when linking (inline)*/ LinkOnceODR = LLVMLinkage.LLVMLinkOnceODRLinkage, /*< Same, but only replaced by something equivalent. */ - //LLVMLinkage.LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */ + + // LLVMLinkage.LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */ Weak = LLVMLinkage.LLVMWeakAnyLinkage, /*< Keep one copy of function when linking (weak) */ WeakODR = LLVMLinkage.LLVMWeakODRLinkage, /*< Same, but only replaced by something equivalent. */ Append = LLVMLinkage.LLVMAppendingLinkage, /*< Special purpose, only applies to global arrays */ @@ -218,15 +261,15 @@ public enum Linkage : uint DllImport = LLVMLinkage.LLVMDLLImportLinkage, /*< Function to be imported from DLL */ DllExport = LLVMLinkage.LLVMDLLExportLinkage, /*< Function to be accessible from DLL */ ExternalWeak = LLVMLinkage.LLVMExternalWeakLinkage,/*< ExternalWeak linkage description */ - //LLVMLinkage.LLVMGhostLinkage, /*< Obsolete */ + + // LLVMLinkage.LLVMGhostLinkage, /*< Obsolete */ Common = LLVMLinkage.LLVMCommonLinkage, /*< Tentative definitions */ LinkerPrivate = LLVMLinkage.LLVMLinkerPrivateLinkage, /*< Like Private, but linker removes. */ LinkerPrivateWeak = LLVMLinkage.LLVMLinkerPrivateWeakLinkage /*< Like LinkerPrivate, but is weak. */ } - ///Enumeration for the visibility of a global value - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum Visibility : uint + /// Enumeration for the visibility of a global value + public enum Visibility { Default = LLVMVisibility.LLVMDefaultVisibility, /*< The GV is visible */ Hidden = LLVMVisibility.LLVMHiddenVisibility, /*< The GV is hidden */ @@ -238,9 +281,8 @@ public enum Visibility : uint /// Underneath the C API this is what LLVM uses. For some reason the C API /// split it into the integer and float predicate enumerations. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1027:MarkEnumsWithFlags" )] - public enum Predicate : uint + [SuppressMessage( "Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "Not flags and shouldn't be marked as such" )] + public enum Predicate { False = LLVMRealPredicate.LLVMRealPredicateFalse, OrderedAndEqual = LLVMRealPredicate.LLVMRealOEQ, @@ -260,6 +302,7 @@ public enum Predicate : uint True = LLVMRealPredicate.LLVMRealPredicateTrue, FirstFcmpPredicate = False, LastFcmpPredicate = True, + /// Any value Greater than or equal to this is not valid for Fcmp operations BadFcmpPredicate = LastFcmpPredicate + 1, @@ -275,13 +318,13 @@ public enum Predicate : uint SignedLessOrEqual = LLVMIntPredicate.LLVMIntSLE, FirstIcmpPredicate = Equal, LastIcmpPredicate = SignedLessOrEqual, + /// Any value Greater than or equal to this is not valid for Icmp operations BadIcmpPredicate = LastIcmpPredicate + 1 } - ///Predicate enumeration for integer comparison - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum IntPredicate : uint + /// Predicate enumeration for integer comparison + public enum IntPredicate { False = LLVMRealPredicate.LLVMRealPredicateFalse, Equal = LLVMIntPredicate.LLVMIntEQ, @@ -296,9 +339,8 @@ public enum IntPredicate : uint SignedLessOrEqual = LLVMIntPredicate.LLVMIntSLE } - ///Predicate enumeration for integer comparison - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum RealPredicate : uint + /// Predicate enumeration for integer comparison + public enum RealPredicate { False = LLVMRealPredicate.LLVMRealPredicateFalse, OrderedAndEqual = LLVMRealPredicate.LLVMRealOEQ, @@ -319,8 +361,7 @@ public enum RealPredicate : uint } /// Optimization level for target code generation - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum CodeGenOpt : uint + public enum CodeGenOpt { None = LLVMCodeGenOptLevel.LLVMCodeGenLevelNone, Less = LLVMCodeGenOptLevel.LLVMCodeGenLevelLess, @@ -329,8 +370,7 @@ public enum CodeGenOpt : uint } /// Relocation type for target code generation - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum Reloc : uint + public enum Reloc { Default = LLVMRelocMode.LLVMRelocDefault, Static = LLVMRelocMode.LLVMRelocStatic, @@ -339,8 +379,7 @@ public enum Reloc : uint } /// Code model to use for target code generation - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum CodeModel : uint + public enum CodeModel { Default = LLVMCodeModel.LLVMCodeModelDefault, JitDefault = LLVMCodeModel.LLVMCodeModelJITDefault, @@ -351,361 +390,213 @@ public enum CodeModel : uint } /// Output file type for target code generation - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum CodeGenFileType : uint + public enum CodeGenFileType { AssemblySource = LLVMCodeGenFileType.LLVMAssemblyFile, ObjectFile = LLVMCodeGenFileType.LLVMObjectFile } /// Byte ordering for target code generation and data type layout - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1028:EnumStorageShouldBeInt32" )] - public enum ByteOrdering : uint + public enum ByteOrdering { LittleEndian = LLVMByteOrdering.LLVMLittleEndian, BigEndian = LLVMByteOrdering.LLVMBigEndian } - /// Enumeration for well known attribute kinds - /// - /// The numeric value of the members of this enumeration are subject - /// to change from version to version. Therefore code must never - /// rely on the actual underlying value and use only the symbolic name - /// - /// - /// For details on what the values should be see attributes.def in - /// the LLVM source. This was added in v3.8.0 along with a change in - /// the numerical values. (in V3.9.0 it is Attributes.inc) - /// - public enum AttributeKind - { - None = LLVMAttrKind.None, - Alignment = LLVMAttrKind.Alignment, - AlwaysInline = LLVMAttrKind.AlwaysInline, - ArgMemOnly = LLVMAttrKind.ArgMemOnly, - Builtin = LLVMAttrKind.Builtin, - ByVal = LLVMAttrKind.ByVal, - Cold = LLVMAttrKind.Cold, - Convergent = LLVMAttrKind.Convergent, - Dereferenceable = LLVMAttrKind.Dereferenceable, - DereferenceableOrNull = LLVMAttrKind.DereferenceableOrNull, - InAlloca = LLVMAttrKind.InAlloca, - InReg = LLVMAttrKind.InReg, - InaccessibleMemOnly = LLVMAttrKind.InaccessibleMemOnly, - InaccessibleMemOrArgMemOnly = LLVMAttrKind.InaccessibleMemOrArgMemOnly, - InlineHint = LLVMAttrKind.InlineHint, - JumpTable = LLVMAttrKind.JumpTable, - MinSize = LLVMAttrKind.MinSize, - Naked = LLVMAttrKind.Naked, - Nest = LLVMAttrKind.Nest, - NoAlias = LLVMAttrKind.NoAlias, - NoBuiltin = LLVMAttrKind.NoBuiltin, - NoCapture = LLVMAttrKind.NoCapture, - NoDuplicate = LLVMAttrKind.NoDuplicate, - NoImplicitFloat = LLVMAttrKind.NoImplicitFloat, - NoInline = LLVMAttrKind.NoInline, - NoRecurse = LLVMAttrKind.NoRecurse, - NoRedZone = LLVMAttrKind.NoRedZone, - NoReturn = LLVMAttrKind.NoReturn, - NoUnwind = LLVMAttrKind.NoUnwind, - NonLazyBind = LLVMAttrKind.NonLazyBind, - NonNull = LLVMAttrKind.NonNull, - OptimizeForSize = LLVMAttrKind.OptimizeForSize, - OptimizeNone = LLVMAttrKind.OptimizeNone, - ReadNone = LLVMAttrKind.ReadNone, - ReadOnly = LLVMAttrKind.ReadOnly, - Returned = LLVMAttrKind.Returned, - ReturnsTwice = LLVMAttrKind.ReturnsTwice, - SExt = LLVMAttrKind.SExt, - SafeStack = LLVMAttrKind.SafeStack, - SanitizeAddress = LLVMAttrKind.SanitizeAddress, - SanitizeMemory = LLVMAttrKind.SanitizeMemory, - SanitizeThread = LLVMAttrKind.SanitizeThread, - StackAlignment = LLVMAttrKind.StackAlignment, - StackProtect = LLVMAttrKind.StackProtect, - StackProtectReq = LLVMAttrKind.StackProtectReq, - StackProtectStrong = LLVMAttrKind.StackProtectStrong, - StructRet = LLVMAttrKind.StructRet, - SwiftError = LLVMAttrKind.SwiftError, - SwiftSelf = LLVMAttrKind.SwiftSelf, - UWTable = LLVMAttrKind.UWTable, - ZExt = LLVMAttrKind.ZExt, - EndAttrKinds // Sentinel value useful for loops - }; - /// Function index for attributes /// /// Attributes on functions apply to the function itself, the return type - /// or one of the function's parameters. This enumeration is used to + /// or one of the function's parameters. This enumeration is used to /// identify where the attribute applies. /// public enum FunctionAttributeIndex { /// The attribute applies to the function itself Function = -1, + /// The attribute applies to the return type of the function ReturnType = 0, + /// The attribute applies to the first parameter of the function /// /// Additional parameters can identified by simply adding an integer value to /// this value. (i.e. FunctionAttributeIndex.Parameter0 + 1 ) /// - Parameter0 = 1 + Parameter0 = 1 } + [SuppressMessage( "Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "Not actually flags" )] public enum TripleArchType { - UnknownArch = LLVMTripleArchType.LlvmTripleArchType_UnknownArch, - - // ARM (little endian): arm, armv.*, xscale - arm = LLVMTripleArchType.LlvmTripleArchType_arm, - - // ARM (big endian): armeb - armeb = LLVMTripleArchType.LlvmTripleArchType_armeb, - - // AArch64 (little endian): aarch64 - aarch64 = LLVMTripleArchType.LlvmTripleArchType_aarch64, - - // AArch64 (big endian): aarch64_be - aarch64_be = LLVMTripleArchType.LlvmTripleArchType_aarch64_be, - - // AVR: Atmel AVR microcontroller - avr = LLVMTripleArchType.LlvmTripleArchType_avr, - - // eBPF or extended BPF or 64-bit BPF (little endian) - bpfel = LLVMTripleArchType.LlvmTripleArchType_bpfel, - - // eBPF or extended BPF or 64-bit BPF (big endian) - bpfeb = LLVMTripleArchType.LlvmTripleArchType_bpfeb, - - // Hexagon: hexagon - hexagon = LLVMTripleArchType.LlvmTripleArchType_hexagon, - - // MIPS: mips, mipsallegrex - mips = LLVMTripleArchType.LlvmTripleArchType_mips, - - // MIPSEL: mipsel, mipsallegrexel - mipsel = LLVMTripleArchType.LlvmTripleArchType_mipsel, - - // MIPS64: mips64 - mips64 = LLVMTripleArchType.LlvmTripleArchType_mips64, - - // MIPS64EL: mips64el - mips64el = LLVMTripleArchType.LlvmTripleArchType_mips64el, - - // MSP430: msp430 - msp430 = LLVMTripleArchType.LlvmTripleArchType_msp430, - - // PPC: powerpc - ppc = LLVMTripleArchType.LlvmTripleArchType_ppc, - - // PPC64: powerpc64, ppu - ppc64 = LLVMTripleArchType.LlvmTripleArchType_ppc64, - - // PPC64LE: powerpc64le - ppc64le = LLVMTripleArchType.LlvmTripleArchType_ppc64le, - - // R600: AMD GPUs HD2XXX - HD6XXX - r600 = LLVMTripleArchType.LlvmTripleArchType_r600, - - // AMDGCN: AMD GCN GPUs - amdgcn = LLVMTripleArchType.LlvmTripleArchType_amdgcn, - - // Sparc: sparc - sparc = LLVMTripleArchType.LlvmTripleArchType_sparc, - - // Sparcv9: Sparcv9 - sparcv9 = LLVMTripleArchType.LlvmTripleArchType_sparcv9, - - // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant - sparcel = LLVMTripleArchType.LlvmTripleArchType_sparcel, - - // SystemZ: s390x - systemz = LLVMTripleArchType.LlvmTripleArchType_systemz, - - // TCE (http://tce.cs.tut.fi/): tce - tce = LLVMTripleArchType.LlvmTripleArchType_tce, - - // Thumb (little endian): thumb, thumbv.* - thumb = LLVMTripleArchType.LlvmTripleArchType_thumb, - - // Thumb (big endian): thumbeb - thumbeb = LLVMTripleArchType.LlvmTripleArchType_thumbeb, - - // X86: i[3-9]86 - x86 = LLVMTripleArchType.LlvmTripleArchType_x86, - - // X86-64: amd64, x86_64 - x86_64 = LLVMTripleArchType.LlvmTripleArchType_x86_64, - - // XCore: xcore - xcore = LLVMTripleArchType.LlvmTripleArchType_xcore, - - // NVPTX: 32-bit - nvptx = LLVMTripleArchType.LlvmTripleArchType_nvptx, - - // NVPTX: 64-bit - nvptx64 = LLVMTripleArchType.LlvmTripleArchType_nvptx64, - - // le32: generic little-endian 32-bit CPU (PNaCl) - le32 = LLVMTripleArchType.LlvmTripleArchType_le32, - - // le64: generic little-endian 64-bit CPU (PNaCl) - le64 = LLVMTripleArchType.LlvmTripleArchType_le64, - - // AMDIL - amdil = LLVMTripleArchType.LlvmTripleArchType_amdil, - - // AMDIL with 64-bit pointers - amdil64 = LLVMTripleArchType.LlvmTripleArchType_amdil64, - - // AMD HSAIL - hsail = LLVMTripleArchType.LlvmTripleArchType_hsail, - - // AMD HSAIL with 64-bit pointers - hsail64 = LLVMTripleArchType.LlvmTripleArchType_hsail64, - - // SPIR: standard portable IR for OpenCL 32-bit version - spir = LLVMTripleArchType.LlvmTripleArchType_spir, - - // SPIR: standard portable IR for OpenCL 64-bit version - spir64 = LLVMTripleArchType.LlvmTripleArchType_spir64, - - // Kalimba: generic kalimba - kalimba = LLVMTripleArchType.LlvmTripleArchType_kalimba, - - // SHAVE: Movidius vector VLIW processors - shave = LLVMTripleArchType.LlvmTripleArchType_shave, - - // Lanai: Lanai 32-bit - lanai = LLVMTripleArchType.LlvmTripleArchType_lanai, - - // WebAssembly with 32-bit pointers - wasm32 = LLVMTripleArchType.LlvmTripleArchType_wasm32, - - // WebAssembly with 64-bit pointers - wasm64 = LLVMTripleArchType.LlvmTripleArchType_wasm64, - - // 32-bit RenderScript - renderscript32 = LLVMTripleArchType.LlvmTripleArchType_renderscript32, - - // 64-bit RenderScript - renderscript64 = LLVMTripleArchType.LlvmTripleArchType_renderscript64, - }; + UnknownArch = LLVMTripleArchType.UnknownArch, + Arm = LLVMTripleArchType.arm, // ARM (little endian): arm, armv.*, xscale + Armeb = LLVMTripleArchType.armeb, // ARM (big endian): armeb + Aarch64 = LLVMTripleArchType.aarch64, // AArch64 (little endian): aarch64 + Aarch64_be = LLVMTripleArchType.aarch64_be, // AArch64 (big endian): aarch64_be + Avr = LLVMTripleArchType.avr, // AVR: Atmel AVR microcontroller + BPFel = LLVMTripleArchType.bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) + BPFeb = LLVMTripleArchType.bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) + Hexagon = LLVMTripleArchType.hexagon, // Hexagon: hexagon + MIPS = LLVMTripleArchType.mips, // MIPS: mips, mipsallegrex + MIPSel = LLVMTripleArchType.mipsel, // MIPSEL: mipsel, mipsallegrexel + MIPS64 = LLVMTripleArchType.mips64, // MIPS64: mips64 + MIPS64el = LLVMTripleArchType.mips64el, // MIPS64EL: mips64el + MSP430 = LLVMTripleArchType.msp430, // MSP430: msp430 + PPC = LLVMTripleArchType.ppc, // PPC: powerpc + PPC64 = LLVMTripleArchType.ppc64, // PPC64: powerpc64, ppu + PPC64le = LLVMTripleArchType.ppc64le, // PPC64LE: powerpc64le + R600 = LLVMTripleArchType.r600, // R600: AMD GPUs HD2XXX - HD6XXX + AMDGCN = LLVMTripleArchType.amdgcn, // AMDGCN: AMD GCN GPUs + RiscV32 = LLVMTripleArchType.riscV32, // RISC-V (32-bit): riscv32 + RiscV64 = LLVMTripleArchType.riscV64, // RISC-V (64-bit): riscv64 + Sparc = LLVMTripleArchType.sparc, // Sparc: sparc + Sparcv9 = LLVMTripleArchType.sparcv9, // Sparcv9: Sparcv9 + Sparcel = LLVMTripleArchType.sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant + SystemZ = LLVMTripleArchType.systemz, // SystemZ: s390x + TCE = LLVMTripleArchType.tce, // TCE (http://tce.cs.tut.fi/): tce + TCEle = LLVMTripleArchType.tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele + Thumb = LLVMTripleArchType.thumb, // Thumb (little endian): thumb, thumbv.* + Thumbeb = LLVMTripleArchType.thumbeb, // Thumb (big endian): thumbeb + X86 = LLVMTripleArchType.x86, // X86: i[3-9]86 + X86_64 = LLVMTripleArchType.x86_64, // X86-64: amd64, x86_64 + Xcore = LLVMTripleArchType.xcore, // XCore: xcore + Nvptx = LLVMTripleArchType.nvptx, // NVPTX: 32-bit + Nvptx64 = LLVMTripleArchType.nvptx64, // NVPTX: 64-bit + Le32 = LLVMTripleArchType.le32, // le32: generic little-endian 32-bit CPU (PNaCl) + Le64 = LLVMTripleArchType.le64, // le64: generic little-endian 64-bit CPU (PNaCl) + Amdil = LLVMTripleArchType.amdil, // AMDIL + Amdil64 = LLVMTripleArchType.amdil64, // AMDIL with 64-bit pointers + Hsail = LLVMTripleArchType.hsail, // AMD HSAIL + Hsail64 = LLVMTripleArchType.hsail64, // AMD HSAIL with 64-bit pointers + Spir = LLVMTripleArchType.spir, // SPIR: standard portable IR for OpenCL 32-bit version + Spir64 = LLVMTripleArchType.spir64, // SPIR: standard portable IR for OpenCL 64-bit version + Kalimba = LLVMTripleArchType.kalimba, // Kalimba: generic kalimba + Shave = LLVMTripleArchType.shave, // SHAVE: Movidius vector VLIW processors + Lanai = LLVMTripleArchType.lanai, // Lanai: Lanai 32-bit + Wasm32 = LLVMTripleArchType.wasm32, // WebAssembly with 32-bit pointers + Wasm64 = LLVMTripleArchType.wasm64, // WebAssembly with 64-bit pointers + Renderscript32 = LLVMTripleArchType.renderscript32, // 32-bit RenderScript + Renderscript64 = LLVMTripleArchType.renderscript64, // 64-bit RenderScript + LastArchType = Renderscript64 + } public enum TripleSubArchType { - NoSubArch = LLVMTripleSubArchType.LlvmTripleSubArchType_NoSubArch, - ARMSubArch_v8_2a = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v8_2a, - ARMSubArch_v8_1a = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v8_1a, - ARMSubArch_v8 = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v8, - ARMSubArch_v8m_baseline = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v8m_baseline, - ARMSubArch_v8m_mainline = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v8m_mainline, - ARMSubArch_v7 = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v7, - ARMSubArch_v7em = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v7em, - ARMSubArch_v7m = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v7m, - ARMSubArch_v7s = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v7s, - ARMSubArch_v7k = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v7k, - ARMSubArch_v6 = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v6, - ARMSubArch_v6m = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v6m, - ARMSubArch_v6k = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v6k, - ARMSubArch_v6t2 = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v6t2, - ARMSubArch_v5 = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v5, - ARMSubArch_v5te = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v5te, - ARMSubArch_v4t = LLVMTripleSubArchType.LlvmTripleSubArchType_ARMSubArch_v4t, - KalimbaSubArch_v3 = LLVMTripleSubArchType.LlvmTripleSubArchType_KalimbaSubArch_v3, - KalimbaSubArch_v4 = LLVMTripleSubArchType.LlvmTripleSubArchType_KalimbaSubArch_v4, - KalimbaSubArch_v5 = LLVMTripleSubArchType.LlvmTripleSubArchType_KalimbaSubArch_v5 - }; + NoSubArch = LLVMTripleSubArchType.NoSubArch, + ARMSubArch_v8_2a = LLVMTripleSubArchType.ARMSubArch_v8_2a, + ARMSubArch_v8_1a = LLVMTripleSubArchType.ARMSubArch_v8_1a, + ARMSubArch_v8 = LLVMTripleSubArchType.ARMSubArch_v8, + ARMSubArch_v8r = LLVMTripleSubArchType.ARMSubArch_v8r, + ARMSubArch_v8m_baseline = LLVMTripleSubArchType.ARMSubArch_v8m_baseline, + ARMSubArch_v8m_mainline = LLVMTripleSubArchType.ARMSubArch_v8m_mainline, + ARMSubArch_v7 = LLVMTripleSubArchType.ARMSubArch_v7, + ARMSubArch_v7em = LLVMTripleSubArchType.ARMSubArch_v7em, + ARMSubArch_v7m = LLVMTripleSubArchType.ARMSubArch_v7m, + ARMSubArch_v7s = LLVMTripleSubArchType.ARMSubArch_v7s, + ARMSubArch_v7k = LLVMTripleSubArchType.ARMSubArch_v7k, + ARMSubArch_v6 = LLVMTripleSubArchType.ARMSubArch_v6, + ARMSubArch_v6m = LLVMTripleSubArchType.ARMSubArch_v6m, + ARMSubArch_v6k = LLVMTripleSubArchType.ARMSubArch_v6k, + ARMSubArch_v6t2 = LLVMTripleSubArchType.ARMSubArch_v6t2, + ARMSubArch_v5 = LLVMTripleSubArchType.ARMSubArch_v5, + ARMSubArch_v5te = LLVMTripleSubArchType.ARMSubArch_v5te, + ARMSubArch_v4t = LLVMTripleSubArchType.ARMSubArch_v4t, + KalimbaSubArch_v3 = LLVMTripleSubArchType.KalimbaSubArch_v3, + KalimbaSubArch_v4 = LLVMTripleSubArchType.KalimbaSubArch_v4, + KalimbaSubArch_v5 = LLVMTripleSubArchType.KalimbaSubArch_v5 + } public enum TripleVendorType { - UnknownVendor = LLVMTripleVendorType.LlvmTripleVendorType_UnknownVendor, - Apple = LLVMTripleVendorType.LlvmTripleVendorType_Apple, - PC = LLVMTripleVendorType.LlvmTripleVendorType_PC, - SCEI = LLVMTripleVendorType.LlvmTripleVendorType_SCEI, - BGP = LLVMTripleVendorType.LlvmTripleVendorType_BGP, - BGQ = LLVMTripleVendorType.LlvmTripleVendorType_BGQ, - Freescale = LLVMTripleVendorType.LlvmTripleVendorType_Freescale, - IBM = LLVMTripleVendorType.LlvmTripleVendorType_IBM, - ImaginationTechnologies = LLVMTripleVendorType.LlvmTripleVendorType_ImaginationTechnologies, - MipsTechnologies = LLVMTripleVendorType.LlvmTripleVendorType_MipsTechnologies, - NVIDIA = LLVMTripleVendorType.LlvmTripleVendorType_NVIDIA, - CSR = LLVMTripleVendorType.LlvmTripleVendorType_CSR, - Myriad = LLVMTripleVendorType.LlvmTripleVendorType_Myriad, - AMD = LLVMTripleVendorType.LlvmTripleVendorType_AMD, - Mesa = LLVMTripleVendorType.LlvmTripleVendorType_Mesa, - }; + UnknownVendor = LLVMTripleVendorType.UnknownVendor, + Apple = LLVMTripleVendorType.Apple, + PC = LLVMTripleVendorType.PC, + SCEI = LLVMTripleVendorType.SCEI, + BGP = LLVMTripleVendorType.BGP, + BGQ = LLVMTripleVendorType.BGQ, + Freescale = LLVMTripleVendorType.Freescale, + IBM = LLVMTripleVendorType.IBM, + ImaginationTechnologies = LLVMTripleVendorType.ImaginationTechnologies, + MipsTechnologies = LLVMTripleVendorType.MipsTechnologies, + NVIDIA = LLVMTripleVendorType.NVIDIA, + CSR = LLVMTripleVendorType.CSR, + Myriad = LLVMTripleVendorType.Myriad, + AMD = LLVMTripleVendorType.AMD, + Mesa = LLVMTripleVendorType.Mesa, + } public enum TripleOSType { - UnknownOS = LLVMTripleOSType.LlvmTripleOSType_UnknownOS, - CloudABI = LLVMTripleOSType.LlvmTripleOSType_CloudABI, - Darwin = LLVMTripleOSType.LlvmTripleOSType_Darwin, - DragonFly = LLVMTripleOSType.LlvmTripleOSType_DragonFly, - FreeBSD = LLVMTripleOSType.LlvmTripleOSType_FreeBSD, - IOS = LLVMTripleOSType.LlvmTripleOSType_IOS, - KFreeBSD = LLVMTripleOSType.LlvmTripleOSType_KFreeBSD, - Linux = LLVMTripleOSType.LlvmTripleOSType_Linux, - Lv2 = LLVMTripleOSType.LlvmTripleOSType_Lv2, - MacOSX = LLVMTripleOSType.LlvmTripleOSType_MacOSX, - NetBSD = LLVMTripleOSType.LlvmTripleOSType_NetBSD, - OpenBSD = LLVMTripleOSType.LlvmTripleOSType_OpenBSD, - Solaris = LLVMTripleOSType.LlvmTripleOSType_Solaris, - Win32 = LLVMTripleOSType.LlvmTripleOSType_Win32, - Haiku = LLVMTripleOSType.LlvmTripleOSType_Haiku, - Minix = LLVMTripleOSType.LlvmTripleOSType_Minix, - RTEMS = LLVMTripleOSType.LlvmTripleOSType_RTEMS, - NaCl = LLVMTripleOSType.LlvmTripleOSType_NaCl, - CNK = LLVMTripleOSType.LlvmTripleOSType_CNK, - Bitrig = LLVMTripleOSType.LlvmTripleOSType_Bitrig, - AIX = LLVMTripleOSType.LlvmTripleOSType_AIX, - CUDA = LLVMTripleOSType.LlvmTripleOSType_CUDA, - NVCL = LLVMTripleOSType.LlvmTripleOSType_NVCL, - AMDHSA = LLVMTripleOSType.LlvmTripleOSType_AMDHSA, - PS4 = LLVMTripleOSType.LlvmTripleOSType_PS4, - ELFIAMCU = LLVMTripleOSType.LlvmTripleOSType_ELFIAMCU, - TvOS = LLVMTripleOSType.LlvmTripleOSType_TvOS, - WatchOS = LLVMTripleOSType.LlvmTripleOSType_WatchOS, - Mesa3D = LLVMTripleOSType.LlvmTripleOSType_Mesa3D, - }; + UnknownOS = LLVMTripleOSType.UnknownOS, + CloudABI = LLVMTripleOSType.CloudABI, + Darwin = LLVMTripleOSType.Darwin, + DragonFly = LLVMTripleOSType.DragonFly, + FreeBSD = LLVMTripleOSType.FreeBSD, + Fuchsia = LLVMTripleOSType.Fuchsia, + IOS = LLVMTripleOSType.IOS, + KFreeBSD = LLVMTripleOSType.KFreeBSD, + Linux = LLVMTripleOSType.Linux, + Lv2 = LLVMTripleOSType.Lv2, + MacOSX = LLVMTripleOSType.MacOSX, + NetBSD = LLVMTripleOSType.NetBSD, + OpenBSD = LLVMTripleOSType.OpenBSD, + Solaris = LLVMTripleOSType.Solaris, + Win32 = LLVMTripleOSType.Win32, + Haiku = LLVMTripleOSType.Haiku, + Minix = LLVMTripleOSType.Minix, + RTEMS = LLVMTripleOSType.RTEMS, + NaCl = LLVMTripleOSType.NaCl, + CNK = LLVMTripleOSType.CNK, + Bitrig = LLVMTripleOSType.Bitrig, + AIX = LLVMTripleOSType.AIX, + CUDA = LLVMTripleOSType.CUDA, + NVCL = LLVMTripleOSType.NVCL, + AMDHSA = LLVMTripleOSType.AMDHSA, + PS4 = LLVMTripleOSType.PS4, + ELFIAMCU = LLVMTripleOSType.ELFIAMCU, + TvOS = LLVMTripleOSType.TvOS, + WatchOS = LLVMTripleOSType.WatchOS, + Mesa3D = LLVMTripleOSType.Mesa3D, + Contiki = LLVMTripleOSType.Contiki, + } public enum TripleEnvironmentType { - UnknownEnvironment = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_UnknownEnvironment, - GNU = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_GNU, - GNUABI64 = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_GNUABI64, - GNUEABI = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_GNUEABI, - GNUEABIHF = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_GNUEABIHF, - GNUX32 = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_GNUX32, - CODE16 = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_CODE16, - EABI = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_EABI, - EABIHF = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_EABIHF, - Android = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_Android, - Musl = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_Musl, - MuslEABI = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_MuslEABI, - MuslEABIHF = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_MuslEABIHF, - MSVC = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_MSVC, - Itanium = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_Itanium, - Cygnus = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_Cygnus, - AMDOpenCL = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_AMDOpenCL, - CoreCLR = LLVMTripleEnvironmentType.LlvmTripleEnvironmentType_CoreCLR, - }; + UnknownEnvironment = LLVMTripleEnvironmentType.UnknownEnvironment, + GNU = LLVMTripleEnvironmentType.GNU, + GNUABI64 = LLVMTripleEnvironmentType.GNUABI64, + GNUEABI = LLVMTripleEnvironmentType.GNUEABI, + GNUEABIHF = LLVMTripleEnvironmentType.GNUEABIHF, + GNUX32 = LLVMTripleEnvironmentType.GNUX32, + CODE16 = LLVMTripleEnvironmentType.CODE16, + EABI = LLVMTripleEnvironmentType.EABI, + EABIHF = LLVMTripleEnvironmentType.EABIHF, + Android = LLVMTripleEnvironmentType.Android, + Musl = LLVMTripleEnvironmentType.Musl, + MuslEABI = LLVMTripleEnvironmentType.MuslEABI, + MuslEABIHF = LLVMTripleEnvironmentType.MuslEABIHF, + MSVC = LLVMTripleEnvironmentType.MSVC, + Itanium = LLVMTripleEnvironmentType.Itanium, + Cygnus = LLVMTripleEnvironmentType.Cygnus, + AMDOpenCL = LLVMTripleEnvironmentType.AMDOpenCL, + CoreCLR = LLVMTripleEnvironmentType.CoreCLR, + OpenCL = LLVMTripleEnvironmentType.OpenCL, + } public enum TripleObjectFormatType { - UnknownObjectFormat = LLVMTripleObjectFormatType.LlvmTripleObjectFormatType_UnknownObjectFormat, - COFF = LLVMTripleObjectFormatType.LlvmTripleObjectFormatType_COFF, - ELF = LLVMTripleObjectFormatType.LlvmTripleObjectFormatType_ELF, - MachO = LLVMTripleObjectFormatType.LlvmTripleObjectFormatType_MachO, - }; + UnknownObjectFormat = LLVMTripleObjectFormatType.UnknownObjectFormat, + COFF = LLVMTripleObjectFormatType.COFF, + ELF = LLVMTripleObjectFormatType.ELF, + MachO = LLVMTripleObjectFormatType.MachO, + } public enum ComdatKind { - Any = LLVMComdatSelectionKind.COMDAT_ANY, - ExactMatch = LLVMComdatSelectionKind.COMDAT_EXACTMATCH, - Largest = LLVMComdatSelectionKind.COMDAT_LARGEST, - NoDuplicates = LLVMComdatSelectionKind.COMDAT_NODUPLICATES, - SameSize = LLVMComdatSelectionKind.COMDAT_SAMESIZE - }; + Any = LLVMComdatSelectionKind.ANY, + ExactMatch = LLVMComdatSelectionKind.EXACTMATCH, + Largest = LLVMComdatSelectionKind.LARGEST, + NoDuplicates = LLVMComdatSelectionKind.NODUPLICATES, + SameSize = LLVMComdatSelectionKind.SAMESIZE + } } \ No newline at end of file diff --git a/src/Llvm.NET/ExtensiblePropertyContainer.cs b/src/Llvm.NET/ExtensiblePropertyContainer.cs new file mode 100644 index 000000000..0454f2af8 --- /dev/null +++ b/src/Llvm.NET/ExtensiblePropertyContainer.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; + +namespace Llvm.NET +{ + /// Common implementation of + /// + /// This class implements through an + /// internal + /// + public class ExtensiblePropertyContainer + : IExtensiblePropertyContainer + { + /// + public void AddExtendedPropertyValue( string id, object value ) + { + lock ( Items ) + { + if( Items.TryGetValue( id, out object currentValue ) ) + { + if( currentValue != null && value != null && currentValue.GetType( ) != value.GetType( ) ) + { + throw new ArgumentException( " Cannot change type of an extended property once set", nameof( value ) ); + } + } + + Items[ id ] = value; + } + } + + /// + public bool TryGetExtendedPropertyValue( string id, out T value ) + { + value = default( T ); + object item; + lock ( Items ) + { + if( !Items.TryGetValue( id, out item ) ) + { + return false; + } + } + + if( !( item is T ) ) + { + return false; + } + + value = ( T )item; + return true; + } + + private readonly Dictionary Items = new Dictionary(); + } +} diff --git a/src/Llvm.NET/ExtensiblePropertyDescriptor.cs b/src/Llvm.NET/ExtensiblePropertyDescriptor.cs new file mode 100644 index 000000000..23ce4efcc --- /dev/null +++ b/src/Llvm.NET/ExtensiblePropertyDescriptor.cs @@ -0,0 +1,86 @@ +using System; + +namespace Llvm.NET +{ + /// Provides consistent accessors for an extended property + /// Type of values stored in the property + /// + /// This class is used to describe a property stored in a class implementing + /// . Using a single, typically + /// , instance of this class to describe and access + /// an extended property helps to encapsulate the type casting and property + /// ID into a single place. Making calling code easier to comprehend and + /// less prone to typographical errors that a compiler can't catch ahead of + /// time. + /// + public class ExtensiblePropertyDescriptor + { + /// Creates a new instance of a property descriptor + /// Name of the extended property + public ExtensiblePropertyDescriptor( string name ) + { + Name = name; + } + + /// Gets a value for the property from the container + /// container + /// Value retrieved from the property or the default value of type + public T GetValueFrom( IExtensiblePropertyContainer container ) + { + return GetValueFrom( container, default( T ) ); + } + + /// Gets a value for the property from the container + /// container + /// default value if the value is not yet present as an extended property + /// Value retrieved from the property or if it wasn't found + /// If the value didn't exist a new value with is added to the container + public T GetValueFrom( IExtensiblePropertyContainer container, T defaultValue ) + { + return GetValueFrom( container, ( ) => defaultValue ); + } + + /// Gets a value for the property from the container + /// container + /// default value factory delegate to create the default value if the value is not yet present as an extended property + /// Value retrieved from the property or default value created by if it wasn't found + /// If the value didn't exist a new value created by calling with is added to the container + public T GetValueFrom( IExtensiblePropertyContainer container, Func lazyDefaultFactory ) + { + if( container == null ) + { + throw new ArgumentNullException( nameof( container ) ); + } + + if( lazyDefaultFactory == null ) + { + throw new ArgumentNullException( nameof( lazyDefaultFactory ) ); + } + + if( container.TryGetExtendedPropertyValue( Name, out T retVal ) ) + { + return retVal; + } + + retVal = lazyDefaultFactory( ); + container.AddExtendedPropertyValue( Name, retVal ); + return retVal; + } + + /// Sets the value of an extended property in a container + /// Container to set the value in + /// value of the property + public void SetValueIn( IExtensiblePropertyContainer container, T value ) + { + if( container == null ) + { + throw new ArgumentNullException( nameof( container ) ); + } + + container.AddExtendedPropertyValue( Name, value ); + } + + /// Name of the property + public string Name { get; } + } +} diff --git a/src/Llvm.NET/IExtensiblePropertyContainer.cs b/src/Llvm.NET/IExtensiblePropertyContainer.cs index c9a8de4ce..47b78e2f2 100644 --- a/src/Llvm.NET/IExtensiblePropertyContainer.cs +++ b/src/Llvm.NET/IExtensiblePropertyContainer.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; - -namespace Llvm.NET +namespace Llvm.NET { /// Interface to allow adding arbitrary named data items to an object /// @@ -31,123 +28,4 @@ public interface IExtensiblePropertyContainer /// void AddExtendedPropertyValue( string id, object value ); } - - /// Provides consistent accessors for an extended property - /// Type of values stored in the property - /// - /// This class is used to describe a property stored in a class implementing - /// . Using a single, typically - /// , instance of this class to describe and access - /// an extended property helps to encapsulate the type casting and property - /// ID into a single place. Making calling code easier to comprehend and - /// less prone to typographical errors that a compiler can't catch ahead of - /// time. - /// - public class ExtensiblePropertyDescriptor - { - /// Creates a new instance of a property descriptor - /// Name of the extended property - public ExtensiblePropertyDescriptor( string name ) - { - Name = name; - } - - /// Gets a value for the property from the container - /// container - /// Value retrieved from the property or the default value of type - public T GetValueFrom( IExtensiblePropertyContainer container ) - { - return GetValueFrom( container, default( T ) ); - } - - /// Gets a value for the property from the container - /// container - /// default value if the value is not yet present as an extended property - /// Value retrieved from the property or if it wasn't found - /// If the value didn't exist a new value with is added to the container - public T GetValueFrom( IExtensiblePropertyContainer container, T defaultValue ) - { - return GetValueFrom( container, ( ) => defaultValue ); - } - - /// Gets a value for the property from the container - /// container - /// default value factory delegate to create the default value if the value is not yet present as an extended property - /// Value retrieved from the property or default value created by if it wasn't found - /// If the value didn't exist a new value created by calling with is added to the container - public T GetValueFrom( IExtensiblePropertyContainer container, Func lazyDefaultFactory ) - { - if( container == null ) - throw new ArgumentNullException( nameof( container ) ); - - if( lazyDefaultFactory == null ) - throw new ArgumentNullException( nameof( lazyDefaultFactory ) ); - - T retVal; - if( container.TryGetExtendedPropertyValue( Name, out retVal ) ) - return retVal; - - retVal = lazyDefaultFactory( ); - container.AddExtendedPropertyValue( Name, retVal ); - return retVal; - } - - /// Sets the value of an extended property in a container - /// Container to set the value in - /// value of the property - public void SetValueIn( IExtensiblePropertyContainer container, T value ) - { - if( container == null ) - throw new ArgumentNullException( nameof( container ) ); - - container.AddExtendedPropertyValue( Name, value ); - } - - /// Name of the property - public string Name { get; } - } - - /// Common implementation of - /// - /// This class implements through an - /// internal - /// - public class ExtensiblePropertyContainer - : IExtensiblePropertyContainer - { - /// - public void AddExtendedPropertyValue( string id, object value ) - { - lock ( Items ) - { - object currentValue; - if( Items.TryGetValue( id, out currentValue ) ) - { - if( currentValue != null && value != null && currentValue.GetType( ) != value.GetType( ) ) - throw new ArgumentException( " Cannot change type of an extended property once set", nameof( value ) ); - } - Items[ id ] = value; - } - } - - /// - public bool TryGetExtendedPropertyValue( string id, out T value ) - { - value = default( T ); - object item; - lock ( Items ) - { - if( !Items.TryGetValue( id, out item ) ) - return false; - } - - if( !( item is T ) ) - return false; - - value = ( T )item; - return true; - } - - readonly Dictionary Items = new Dictionary(); - } } diff --git a/src/Llvm.NET/Instructions/AddressSpaceCast.cs b/src/Llvm.NET/Instructions/AddressSpaceCast.cs index a7592c0f1..423648914 100644 --- a/src/Llvm.NET/Instructions/AddressSpaceCast.cs +++ b/src/Llvm.NET/Instructions/AddressSpaceCast.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class AddressSpaceCast : Cast + public class AddressSpaceCast : Cast { internal AddressSpaceCast( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/Call.cs b/src/Llvm.NET/Instructions/Call.cs index cd3d28b7d..d8712cba3 100644 --- a/src/Llvm.NET/Instructions/Call.cs +++ b/src/Llvm.NET/Instructions/Call.cs @@ -1,56 +1,81 @@ -using Llvm.NET.Native; +using System; +using System.Collections.Generic; +using System.Linq; +using Llvm.NET.Native; using Llvm.NET.Values; namespace Llvm.NET.Instructions { public class CallInstruction : Instruction - , IAttributeSetContainer + , IAttributeAccessor { - public AttributeSet Attributes + public Function TargetFunction => FromHandle( NativeMethods.GetCalledValue( ValueHandle ) ); + + public bool IsTailCall { - get - { - if( TargetFunction == null ) - return new AttributeSet( ); + get => NativeMethods.IsTailCall( ValueHandle ); + set => NativeMethods.SetTailCall( ValueHandle, value ); + } - return new AttributeSet( NativeMethods.GetCallSiteAttributeSet( ValueHandle ) ); - } + public IAttributeDictionary Attributes { get; } - set - { - NativeMethods.SetCallSiteAttributeSet( ValueHandle, value.NativeAttributeSet ); - } + public void AddAttributeAtIndex( FunctionAttributeIndex index, AttributeValue attrib ) + { + attrib.VerifyValidOn( index, this ); + NativeMethods.AddCallSiteAttribute( ValueHandle, ( LLVMAttributeIndex )index, attrib.NativeAttribute ); } - public Function TargetFunction + public uint GetAttributeCountAtIndex( FunctionAttributeIndex index ) { - get - { - if( Operands.Count < 1 ) - return null; - - // last Operand is the target function - return Operands[ Operands.Count - 1 ] as Function; - } + return NativeMethods.GetCallSiteAttributeCount( ValueHandle, ( LLVMAttributeIndex )index ); } - public bool IsTailCall + public IEnumerable GetAttributesAtIndex( FunctionAttributeIndex index ) { - get + uint count = GetAttributeCountAtIndex( index ); + if( count == 0 ) { - return NativeMethods.IsTailCall( ValueHandle ); + return Enumerable.Empty(); } - set + var buffer = new LLVMAttributeRef[ count ]; + NativeMethods.GetCallSiteAttributes( ValueHandle, ( LLVMAttributeIndex )index, out buffer[ 0 ] ); + return from attribRef in buffer + select AttributeValue.FromHandle( Context, attribRef ); + } + + public AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ) + { + var handle = NativeMethods.GetCallSiteEnumAttribute( ValueHandle, ( LLVMAttributeIndex )index, kind.GetEnumAttributeId( ) ); + return AttributeValue.FromHandle( Context, handle ); + } + + public AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, string name ) + { + if( string.IsNullOrWhiteSpace( name ) ) { - NativeMethods.SetTailCall( ValueHandle, value ); + throw new ArgumentException( "name cannot be null or empty", nameof( name ) ); } + + var handle = NativeMethods.GetCallSiteStringAttribute( ValueHandle, ( LLVMAttributeIndex )index, name, ( uint )name.Length ); + return AttributeValue.FromHandle( Context, handle ); + } + + public void RemoveAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ) + { + NativeMethods.RemoveCallSiteEnumAttribute( ValueHandle, ( LLVMAttributeIndex )index, kind.GetEnumAttributeId( ) ); + } + + public void RemoveAttributeAtIndex( FunctionAttributeIndex index, string name ) + { + NativeMethods.RemoveCallSiteStringAttribute( ValueHandle, ( LLVMAttributeIndex )index, name, ( uint )name.Length ); } internal CallInstruction( LLVMValueRef valueRef ) : base( valueRef ) { + Attributes = new ValueAttributeDictionary( this, ()=>TargetFunction ); } } } diff --git a/src/Llvm.NET/Instructions/DebugInfoIntrinsic.cs b/src/Llvm.NET/Instructions/DebugInfoIntrinsic.cs index 611bbb270..5c889ebff 100644 --- a/src/Llvm.NET/Instructions/DebugInfoIntrinsic.cs +++ b/src/Llvm.NET/Instructions/DebugInfoIntrinsic.cs @@ -7,7 +7,7 @@ public class DebugInfoIntrinsic { internal DebugInfoIntrinsic( LLVMValueRef valueRef ) : base( valueRef ) - { + { } } } diff --git a/src/Llvm.NET/Instructions/FPExt.cs b/src/Llvm.NET/Instructions/FPExt.cs index 7cbccd206..e88795505 100644 --- a/src/Llvm.NET/Instructions/FPExt.cs +++ b/src/Llvm.NET/Instructions/FPExt.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class FPExt : Cast + public class FPExt : Cast { internal FPExt( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/FPToSI.cs b/src/Llvm.NET/Instructions/FPToSI.cs index 36a885dd9..ce8d20cf5 100644 --- a/src/Llvm.NET/Instructions/FPToSI.cs +++ b/src/Llvm.NET/Instructions/FPToSI.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class FPToSI : Cast + public class FPToSI : Cast { internal FPToSI( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/FPToUI.cs b/src/Llvm.NET/Instructions/FPToUI.cs index 90d086299..7f5e02f3b 100644 --- a/src/Llvm.NET/Instructions/FPToUI.cs +++ b/src/Llvm.NET/Instructions/FPToUI.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class FPToUI : Cast + public class FPToUI : Cast { internal FPToUI( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/FPTrunc.cs b/src/Llvm.NET/Instructions/FPTrunc.cs index c35f9bcbf..1c58aa2de 100644 --- a/src/Llvm.NET/Instructions/FPTrunc.cs +++ b/src/Llvm.NET/Instructions/FPTrunc.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class FPTrunc : Cast + public class FPTrunc : Cast { internal FPTrunc( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/Instruction.cs b/src/Llvm.NET/Instructions/Instruction.cs index 9f1597b5e..35c0aa3cf 100644 --- a/src/Llvm.NET/Instructions/Instruction.cs +++ b/src/Llvm.NET/Instructions/Instruction.cs @@ -14,7 +14,7 @@ public class Instruction /// Gets the LLVM opcode for the instruction public OpCode Opcode => ( OpCode )NativeMethods.GetInstructionOpcode( ValueHandle ); - /// FLag to indicate if the opcode is for a memory access , , + /// Flag to indicate if the opcode is for a memory access , , public bool IsMemoryAccess { get @@ -34,15 +34,15 @@ public bool IsMemoryAccess /// public uint Alignment { - get - { - return IsMemoryAccess ? NativeMethods.GetAlignment( ValueHandle ) : 0; - } + get => IsMemoryAccess ? NativeMethods.GetAlignment( ValueHandle ) : 0; set { if( !IsMemoryAccess ) + { throw new InvalidOperationException( "Alignment can only be set for instructions dealing with memory read/write (alloca, load, store)" ); + } + NativeMethods.SetAlignment( ValueHandle, value ); } } @@ -52,52 +52,4 @@ internal Instruction( LLVMValueRef valueRef ) { } } - - /// Provides extension methods to that cannot be achieved as members of the class - /// - /// Using generic static extension methods allows for fluent coding while retaining the type of the "this" parameter. - /// If these were members of the class then the only return type could be - /// thus losing the original type and requiring a cast to get back to it, thereby defeating the purpose of the fluent style. - /// - public static class InstructionExtensions - { - /// Fluent style extension method to set the for an instruction - /// Type of the instruction (usually implicitly inferred from usage) - /// Instruction to set the for - /// New alignment for the instruction - /// To allow fluent style coding this returns the parameter - public static T Alignment( this T self, uint value ) - where T : Instruction - { - if( self.IsMemoryAccess ) - self.Alignment = value; - - return self; - } - - /// Fluent style extension method to set the Volatile property of a or instruction - /// Type of the instruction (usually implicitly inferred from usage) - /// Instruction to set the Volatile property for - /// Flag to indicate if the instruction's operation is volatile - /// To allow fluent style coding this returns the parameter - public static T IsVolatile( this T self, bool value ) - where T : Instruction - { - if( self.IsMemoryAccess ) - { - // only load and store instructions have the volatile property - var loadInst = self as Load; - if( loadInst != null ) - loadInst.IsVolatile = value; - else - { - var storeinst = self as Store; - if( storeinst != null ) - storeinst.IsVolatile = value; - } - } - - return self; - } - } } diff --git a/src/Llvm.NET/Instructions/InstructionBuilder.cs b/src/Llvm.NET/Instructions/InstructionBuilder.cs index 0952a755c..3e935c91b 100644 --- a/src/Llvm.NET/Instructions/InstructionBuilder.cs +++ b/src/Llvm.NET/Instructions/InstructionBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Llvm.NET.Native; using Llvm.NET.Types; @@ -8,21 +9,18 @@ namespace Llvm.NET.Instructions { - ///LLVM Instruction builder allowing managed code to generate IR instructions + /// LLVM Instruction builder allowing managed code to generate IR instructions public sealed class InstructionBuilder { - /// Creates an for a given context + /// Initializes a new instance of the class for a given /// Context used for creating instructions public InstructionBuilder( Context context ) { - if( context == null ) - throw new ArgumentNullException( nameof( context ) ); - - Context = context; + Context = context ?? throw new ArgumentNullException( nameof( context ) ); BuilderHandle = NativeMethods.CreateBuilderInContext( context.ContextHandle ); } - /// Creates an for a + /// Initializes a new instance of the class for a /// Block this builder is initially attached to public InstructionBuilder( BasicBlock block ) : this( block.VerifyArgNotNull( nameof( block ) ).ContainingFunction.ParentModule.Context ) @@ -30,28 +28,37 @@ public InstructionBuilder( BasicBlock block ) PositionAtEnd( block ); } + ~InstructionBuilder( ) + { + BuilderHandle.Close( ); + } + /// Gets the context this builder is creating instructions for public Context Context { get; } - /// Retrieves the this builder is building instructions for + /// Gets the this builder is building instructions for public BasicBlock InsertBlock { get { var handle = NativeMethods.GetInsertBlock( BuilderHandle ); if( handle.Pointer.IsNull( ) ) + { return null; + } return BasicBlock.FromHandle( NativeMethods.GetInsertBlock( BuilderHandle ) ); - } + } } /// Positions the builder at the end of a given - /// + /// Block to set the poition of public void PositionAtEnd( BasicBlock basicBlock ) { if( basicBlock == null ) + { throw new ArgumentNullException( nameof( basicBlock ) ); + } NativeMethods.PositionBuilderAtEnd( BuilderHandle, basicBlock.BlockHandle ); } @@ -69,7 +76,9 @@ public void PositionAtEnd( BasicBlock basicBlock ) public void PositionBefore( Instruction instr ) { if( instr == null ) + { throw new ArgumentNullException( nameof( instr ) ); + } NativeMethods.PositionBuilderBefore( BuilderHandle, instr.ValueHandle ); } @@ -126,10 +135,14 @@ public Alloca Alloca( ITypeRef typeRef ) public Alloca Alloca( ITypeRef typeRef, ConstantInt elements ) { if( typeRef == null ) + { throw new ArgumentNullException( nameof( typeRef ) ); + } if( elements == null ) + { throw new ArgumentNullException( nameof( elements ) ); + } var instHandle = NativeMethods.BuildArrayAlloca( BuilderHandle, typeRef.GetTypeRef( ), elements.ValueHandle, string.Empty ); return Value.FromHandle( instHandle ); @@ -138,7 +151,9 @@ public Alloca Alloca( ITypeRef typeRef, ConstantInt elements ) public ReturnInstruction Return( ) { if( !InsertBlock.ContainingFunction.ReturnType.IsVoid ) + { throw new ArgumentException( "Return instruction for non-void function must have a value" ); + } return Value.FromHandle( NativeMethods.BuildRetVoid( BuilderHandle ) ); } @@ -146,20 +161,27 @@ public ReturnInstruction Return( ) public ReturnInstruction Return( Value value ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } var retType = InsertBlock.ContainingFunction.ReturnType; if( retType.IsVoid ) + { throw new ArgumentException( "Return instruction for void function must not have a value", nameof( value ) ); + } if( retType != value.NativeType ) + { throw new ArgumentException( "Value for return must match the function signature's return type", nameof( value ) ); + } var handle = NativeMethods.BuildRet( BuilderHandle, value.ValueHandle ); return Value.FromHandle( handle ); } public CallInstruction Call( Value func, params Value[ ] args ) => Call( func, ( IReadOnlyList )args ); + public CallInstruction Call( Value func, IReadOnlyList args ) { LLVMValueRef hCall = BuildCall( func, args ); @@ -170,10 +192,14 @@ public CallInstruction Call( Value func, IReadOnlyList args ) public Invoke Invoke( Value func, IReadOnlyList args, BasicBlock then, BasicBlock catchBlock ) { if( then == null ) + { throw new ArgumentNullException( nameof( then ) ); + } if( catchBlock == null ) + { throw new ArgumentNullException( nameof( catchBlock ) ); + } ValidateCallArgs( func, args ); @@ -194,6 +220,7 @@ public Invoke Invoke( Value func, IReadOnlyList args, BasicBlock then, Ba , catchBlock.BlockHandle , string.Empty ); + return Value.FromHandle( invoke ); } @@ -201,17 +228,20 @@ public LandingPad LandingPad( ITypeRef resultType ) { LLVMValueRef landingPad = NativeMethods.BuildLandingPad( BuilderHandle , resultType.GetTypeRef() - , LLVMValueRef.Zero // personality function no longer part of instruction + , new LLVMValueRef( IntPtr.Zero ) // personality function no longer part of instruction , 0 , string.Empty ); + return Value.FromHandle( landingPad ); } public ResumeInstruction Resume( Value exception ) { if( exception == null ) + { throw new ArgumentNullException( nameof( exception ) ); + } LLVMValueRef resume = NativeMethods.BuildResume( BuilderHandle, exception.ValueHandle ); return Value.FromHandle( resume ); @@ -230,14 +260,20 @@ public ResumeInstruction Resume( Value exception ) public Store Store( Value value, Value destination ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } if( destination == null ) + { throw new ArgumentNullException( nameof( destination ) ); + } var ptrType = destination.NativeType as IPointerType; if( ptrType == null ) + { throw new ArgumentException( "Expected pointer value", nameof( destination ) ); + } if( !ptrType.ElementType.Equals( value.NativeType ) || ( value.NativeType.Kind == TypeKind.Integer && value.NativeType.IntegerBitWidth != ptrType.ElementType.IntegerBitWidth ) @@ -252,44 +288,68 @@ public Store Store( Value value, Value destination ) public Load Load( Value sourcePtr ) { if( sourcePtr == null ) + { throw new ArgumentNullException( nameof( sourcePtr ) ); + } var handle = NativeMethods.BuildLoad( BuilderHandle, sourcePtr.ValueHandle, string.Empty ); return Value.FromHandle( handle ); } public Value AtomicXchg( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpXchg, ptr, val ); + public Value AtomicAdd( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpAdd, ptr, val ); + public Value AtomicSub( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpSub, ptr, val ); + public Value AtomicAnd( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpAnd, ptr, val ); + public Value AtomicNand( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpNand, ptr, val ); + public Value AtomicOr( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpOr, ptr, val ); + public Value AtomicXor( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpXor, ptr, val ); + public Value AtomicMax( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpMax, ptr, val ); + public Value AtomicMin( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpMin, ptr, val ); + public Value AtomicUMax( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpUMax, ptr, val ); + public Value AtomicUMin( Value ptr, Value val ) => BuildAtomicBinOp( LLVMAtomicRMWBinOp.LLVMAtomicRMWBinOpUMin, ptr, val ); public Value AtomicCmpXchg( Value ptr, Value cmp, Value value ) { if( ptr == null ) + { throw new ArgumentNullException( nameof( ptr ) ); + } if( cmp == null ) + { throw new ArgumentNullException( nameof( cmp ) ); + } if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } var ptrType = ptr.NativeType as IPointerType; if( ptrType == null ) + { throw new ArgumentException( "Expected pointer value", nameof( ptr ) ); + } if( ptrType.ElementType != cmp.NativeType ) + { throw new ArgumentException( string.Format( IncompatibleTypeMsgFmt, ptrType.ElementType, cmp.NativeType ) ); + } if( ptrType.ElementType != value.NativeType ) + { throw new ArgumentException( string.Format( IncompatibleTypeMsgFmt, ptrType.ElementType, value.NativeType ) ); + } var handle = NativeMethods.BuildAtomicCmpXchg( BuilderHandle , ptr.ValueHandle @@ -316,21 +376,31 @@ public Value AtomicCmpXchg( Value ptr, Value cmp, Value value ) public Value GetStructElementPointer( Value pointer, uint index ) { if( pointer == null ) + { throw new ArgumentNullException( nameof( pointer ) ); + } var ptrType = pointer.NativeType as IPointerType; if( ptrType == null ) + { throw new ArgumentException( "Pointer value expected", nameof( pointer ) ); + } var elementStructType = ptrType.ElementType as IStructType; if( elementStructType == null ) + { throw new ArgumentException( "Pointer to a structure expected", nameof( pointer ) ); + } if( !elementStructType.IsSized && index > 0 ) + { throw new ArgumentException( "Cannot get element of unsized/opaque structures" ); + } if( index >= elementStructType.Members.Count ) + { throw new ArgumentException( "Index exceeds number of members in the type", nameof( index ) ); + } var handle = NativeMethods.BuildStructGEP( BuilderHandle, pointer.ValueHandle, index, string.Empty ); return Value.FromHandle( handle ); @@ -341,7 +411,7 @@ public Value GetStructElementPointer( Value pointer, uint index ) /// additional indices for computing the resulting pointer /// /// for the member access. This is a - /// as LLVM may optimize the expression to a if it + /// as LLVM may optimize the expression to a if it /// can so the actual type of the result may be /// or . /// Note that must be a pointer to a structure @@ -374,7 +444,7 @@ public Value GetElementPtr( Value pointer, IEnumerable args ) /// additional indices for computing the resulting pointer /// /// for the member access. This is a - /// as LLVM may optimize the expression to a if it + /// as LLVM may optimize the expression to a if it /// can so the actual type of the result may be /// or . /// Note that must be a pointer to a structure @@ -397,7 +467,7 @@ public Value GetElementPtr( Value pointer, IEnumerable args ) /// additional indices for computing the resulting pointer /// /// for the member access. This is a - /// as LLVM may optimize the expression to a if it + /// as LLVM may optimize the expression to a if it /// can so the actual type of the result may be /// or . /// Note that must be a pointer to a structure @@ -429,8 +499,8 @@ public Value GetElementPtrInBounds( Value pointer, IEnumerable args ) /// pointer to get an element from /// additional indices for computing the resulting pointer /// - /// for the member access. This is a User as LLVM may - /// optimize the expression to a if it + /// for the member access. This is a User as LLVM may + /// optimize the expression to a if it /// can so the actual type of the result may be /// or . /// Note that must be a pointer to a structure @@ -446,8 +516,7 @@ public Value GetElementPtrInBounds( Value pointer, IEnumerable args ) /// former makes the first index explicit. LLVM requires an explicit first index even if it is /// zero, in order to properly compute the offset for a given element in an aggregate type. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1822:MarkMembersAsStatic" )] - public Value ConstGetElementPtrInBounds( Value pointer, params Value[ ] args ) + public static Value ConstGetElementPtrInBounds( Value pointer, params Value[ ] args ) { var llvmArgs = GetValidatedGEPArgs( pointer, args ); var handle = NativeMethods.ConstInBoundsGEP( pointer.ValueHandle, out llvmArgs[ 0 ], ( uint )llvmArgs.Length ); @@ -463,17 +532,23 @@ public Value ConstGetElementPtrInBounds( Value pointer, params Value[ ] args ) /// and is either a or an /// instruction. Conversion to a constant expression is performed whenever possible. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] public Value IntToPointer( Value intValue, IPointerType ptrType ) { if( intValue == null ) + { throw new ArgumentNullException( nameof( intValue ) ); + } if( ptrType == null ) + { throw new ArgumentNullException( nameof( ptrType ) ); + } if( intValue is Constant ) + { return Value.FromHandle( NativeMethods.ConstIntToPtr( intValue.ValueHandle, ptrType.GetTypeRef( ) ) ); + } var handle = NativeMethods.BuildIntToPtr( BuilderHandle, intValue.ValueHandle, ptrType.GetTypeRef( ), string.Empty ); return Value.FromHandle( handle ); @@ -491,36 +566,53 @@ public Value IntToPointer( Value intValue, IPointerType ptrType ) public Value PointerToInt( Value ptrValue, ITypeRef intType ) { if( ptrValue == null ) + { throw new ArgumentNullException( nameof( ptrValue ) ); + } if( intType == null ) + { throw new ArgumentNullException( nameof( intType ) ); + } if( ptrValue.NativeType.Kind != TypeKind.Pointer ) + { throw new ArgumentException( "Expected a pointer value", nameof( ptrValue ) ); + } if( intType.Kind != TypeKind.Integer ) + { throw new ArgumentException( "Expected pointer to integral type", nameof( intType ) ); + } if( ptrValue is Constant ) + { return Value.FromHandle( NativeMethods.ConstPtrToInt( ptrValue.ValueHandle, intType.GetTypeRef( ) ) ); + } var handle = NativeMethods.BuildPtrToInt( BuilderHandle, ptrValue.ValueHandle, intType.GetTypeRef( ), string.Empty ); return Value.FromHandle( handle ); } - public Branch Branch( BasicBlock target ) => Value.FromHandle( NativeMethods.BuildBr( BuilderHandle, target.VerifyArgNotNull( nameof( target ) ).BlockHandle ) ); + public Branch Branch( BasicBlock target ) + => Value.FromHandle( NativeMethods.BuildBr( BuilderHandle, target.VerifyArgNotNull( nameof( target ) ).BlockHandle ) ); public Branch Branch( Value ifCondition, BasicBlock thenTarget, BasicBlock elseTarget ) { if( ifCondition == null ) + { throw new ArgumentNullException( nameof( ifCondition ) ); + } if( thenTarget == null ) + { throw new ArgumentNullException( nameof( thenTarget ) ); + } if( elseTarget == null ) + { throw new ArgumentNullException( nameof( elseTarget ) ); + } var handle = NativeMethods.BuildCondBr( BuilderHandle , ifCondition.ValueHandle @@ -541,16 +633,24 @@ public Branch Branch( Value ifCondition, BasicBlock thenTarget, BasicBlock elseT public Value Compare( IntPredicate predicate, Value lhs, Value rhs ) { if( lhs == null ) + { throw new ArgumentNullException( nameof( lhs ) ); + } if( rhs == null ) + { throw new ArgumentNullException( nameof( rhs ) ); + } if( !lhs.NativeType.IsInteger && !lhs.NativeType.IsPointer ) + { throw new ArgumentException( "Expecting an integer or pointer type", nameof( lhs ) ); + } if( !rhs.NativeType.IsInteger && !lhs.NativeType.IsPointer ) + { throw new ArgumentException( "Expecting an integer or pointer type", nameof( rhs ) ); + } var handle = NativeMethods.BuildICmp( BuilderHandle, ( LLVMIntPredicate )predicate, lhs.ValueHandle, rhs.ValueHandle, string.Empty ); return Value.FromHandle( handle ); @@ -564,16 +664,24 @@ public Value Compare( IntPredicate predicate, Value lhs, Value rhs ) public Value Compare( RealPredicate predicate, Value lhs, Value rhs ) { if( lhs == null ) + { throw new ArgumentNullException( nameof( lhs ) ); + } if( rhs == null ) + { throw new ArgumentNullException( nameof( rhs ) ); + } if( !lhs.NativeType.IsFloatingPoint ) + { throw new ArgumentException( "Expecting an integer type", nameof( lhs ) ); + } if( !rhs.NativeType.IsFloatingPoint ) + { throw new ArgumentException( "Expecting an integer type", nameof( rhs ) ); + } var handle = NativeMethods.BuildFCmp( BuilderHandle , ( LLVMRealPredicate )predicate @@ -592,10 +700,14 @@ public Value Compare( RealPredicate predicate, Value lhs, Value rhs ) public Value Compare( Predicate predicate, Value lhs, Value rhs ) { if( predicate <= Predicate.LastFcmpPredicate ) + { return Compare( ( RealPredicate )predicate, lhs, rhs ); + } if( predicate >= Predicate.FirstIcmpPredicate && predicate <= Predicate.LastIcmpPredicate ) + { return Compare( ( IntPredicate )predicate, lhs, rhs ); + } throw new ArgumentOutOfRangeException( nameof( predicate ), $"'{predicate}' is not a valid value for a compare predicate" ); } @@ -603,20 +715,30 @@ public Value Compare( Predicate predicate, Value lhs, Value rhs ) public Value ZeroExtendOrBitCast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } // short circuit cast to same type as it won't be a Constant or a BitCast if( valueRef.NativeType == targetType ) + { return valueRef; + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstZExtOrBitCast( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildZExtOrBitCast( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -624,20 +746,30 @@ public Value ZeroExtendOrBitCast( Value valueRef, ITypeRef targetType ) public Value SignExtendOrBitCast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } // short circuit cast to same type as it won't be a Constant or a BitCast if( valueRef.NativeType == targetType ) + { return valueRef; + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstSExtOrBitCast( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildSExtOrBitCast( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -645,20 +777,30 @@ public Value SignExtendOrBitCast( Value valueRef, ITypeRef targetType ) public Value TruncOrBitCast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } // short circuit cast to same type as it won't be a Constant or a BitCast if( valueRef.NativeType == targetType ) + { return valueRef; + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstTruncOrBitCast( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildTruncOrBitCast( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -666,16 +808,24 @@ public Value TruncOrBitCast( Value valueRef, ITypeRef targetType ) public Value ZeroExtend( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstZExt( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildZExt( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -683,13 +833,19 @@ public Value ZeroExtend( Value valueRef, ITypeRef targetType ) public Value SignExtend( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } if( valueRef is Constant ) + { return Value.FromHandle( NativeMethods.ConstSExt( valueRef.ValueHandle, targetType.GetTypeRef( ) ) ); + } var retValueRef = NativeMethods.BuildSExt( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); return Value.FromHandle( retValueRef ); @@ -698,20 +854,30 @@ public Value SignExtend( Value valueRef, ITypeRef targetType ) public Value BitCast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } // short circuit cast to same type as it won't be a Constant or a BitCast if( valueRef.NativeType == targetType ) + { return valueRef; + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstBitCast( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildBitCast( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -719,16 +885,24 @@ public Value BitCast( Value valueRef, ITypeRef targetType ) public Value IntCast( Value valueRef, ITypeRef targetType, bool isSigned ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstIntCast( valueRef.ValueHandle, targetType.GetTypeRef( ), isSigned ); + } else + { handle = NativeMethods.BuildIntCast( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -736,13 +910,19 @@ public Value IntCast( Value valueRef, ITypeRef targetType, bool isSigned ) public Value Trunc( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } if( valueRef is Constant ) + { return Value.FromHandle( NativeMethods.ConstTrunc( valueRef.ValueHandle, targetType.GetTypeRef( ) ) ); + } return Value.FromHandle( NativeMethods.BuildTrunc( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ) ); } @@ -750,16 +930,24 @@ public Value Trunc( Value valueRef, ITypeRef targetType ) public Value SIToFPCast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstSIToFP( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildSIToFP( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -767,16 +955,24 @@ public Value SIToFPCast( Value valueRef, ITypeRef targetType ) public Value UIToFPCast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstUIToFP( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildUIToFP( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -784,16 +980,24 @@ public Value UIToFPCast( Value valueRef, ITypeRef targetType ) public Value FPToUICast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstFPToUI( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildFPToUI( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -801,16 +1005,24 @@ public Value FPToUICast( Value valueRef, ITypeRef targetType ) public Value FPToSICast( Value valueRef, ITypeRef targetType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( targetType == null ) + { throw new ArgumentNullException( nameof( targetType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstFPToSI( valueRef.ValueHandle, targetType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildFPToSI( BuilderHandle, valueRef.ValueHandle, targetType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -818,16 +1030,24 @@ public Value FPToSICast( Value valueRef, ITypeRef targetType ) public Value FPExt( Value valueRef, ITypeRef toType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( toType == null ) + { throw new ArgumentNullException( nameof( toType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstFPExt( valueRef.ValueHandle, toType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildFPExt( BuilderHandle, valueRef.ValueHandle, toType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -835,16 +1055,24 @@ public Value FPExt( Value valueRef, ITypeRef toType ) public Value FPTrunc( Value valueRef, ITypeRef toType ) { if( valueRef == null ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } if( toType == null ) + { throw new ArgumentNullException( nameof( toType ) ); + } LLVMValueRef handle; if( valueRef is Constant ) + { handle = NativeMethods.ConstFPTrunc( valueRef.ValueHandle, toType.GetTypeRef( ) ); + } else + { handle = NativeMethods.BuildFPTrunc( BuilderHandle, valueRef.ValueHandle, toType.GetTypeRef( ), string.Empty ); + } return Value.FromHandle( handle ); } @@ -861,13 +1089,19 @@ public Value FPTrunc( Value valueRef, ITypeRef toType ) public Value Select( Value ifCondition, Value thenValue, Value elseValue ) { if( ifCondition == null ) + { throw new ArgumentNullException( nameof( ifCondition ) ); + } if( thenValue == null ) + { throw new ArgumentNullException( nameof( thenValue ) ); + } if( elseValue == null ) + { throw new ArgumentNullException( nameof( elseValue ) ); + } var conditionVectorType = ifCondition.NativeType as IVectorType; var thenVector = thenValue.NativeType as IVectorType; @@ -882,17 +1116,29 @@ public Value Select( Value ifCondition, Value thenValue, Value elseValue ) { const string errMsg = "When condition is a vector, selected values must be a vector of the same size"; if( thenVector == null || thenVector.Size != conditionVectorType.Size ) + { throw new ArgumentException( errMsg, nameof( thenValue ) ); + } if( elseValue == null || elseVector.Size != conditionVectorType.Size ) + { throw new ArgumentException( errMsg, nameof( elseValue ) ); + } } else { if( elseValue.NativeType != thenValue.NativeType ) + { throw new ArgumentException( "Selected values must have the same type" ); + } } - var handle = NativeMethods.BuildSelect( BuilderHandle, ifCondition.ValueHandle, thenValue.ValueHandle, elseValue.ValueHandle, string.Empty ); + + var handle = NativeMethods.BuildSelect( BuilderHandle + , ifCondition.ValueHandle + , thenValue.ValueHandle + , elseValue.ValueHandle + , string.Empty + ); return Value.FromHandle( handle ); } @@ -905,7 +1151,9 @@ public PhiNode PhiNode( ITypeRef resultType ) public Value ExtractValue( Value instance, uint index ) { if( instance == null ) + { throw new ArgumentNullException( nameof( instance ) ); + } var handle = NativeMethods.BuildExtractValue( BuilderHandle, instance.ValueHandle, index, string.Empty ); return Value.FromHandle( handle ); @@ -914,10 +1162,14 @@ public Value ExtractValue( Value instance, uint index ) public Instructions.Switch Switch( Value value, BasicBlock defaultCase, uint numCases ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } if( defaultCase == null ) + { throw new ArgumentNullException( nameof( defaultCase ) ); + } var handle = NativeMethods.BuildSwitch( BuilderHandle, value.ValueHandle, defaultCase.BlockHandle, numCases ); return Value.FromHandle( handle ); @@ -927,14 +1179,19 @@ public Value DoNothing( ) { var module = InsertBlock?.ContainingFunction?.ParentModule; if( module == null ) + { throw new InvalidOperationException( "Cannot insert when no block/module is available" ); + } + return DoNothing( module ); } public Value DoNothing( NativeModule module ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } var func = module.GetFunction( Intrinsic.DoNothingName ); if( func == null ) @@ -952,7 +1209,9 @@ public Value DebugTrap( ) { var module = InsertBlock?.ContainingFunction?.ParentModule; if( module == null ) + { throw new InvalidOperationException( "Cannot insert when no block/module is available" ); + } return DebugTrap( module ); } @@ -960,7 +1219,9 @@ public Value DebugTrap( ) public Value DebugTrap( NativeModule module ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } var func = module.GetFunction( Intrinsic.DebugTrapName ); if( func == null ) @@ -970,10 +1231,10 @@ public Value DebugTrap( NativeModule module ) func = module.AddFunction( Intrinsic.DebugTrapName, signature ); } - LLVMValueRef args; - var hCall = NativeMethods.BuildCall( BuilderHandle, func.ValueHandle, out args, 0U, string.Empty ); + var hCall = NativeMethods.BuildCall( BuilderHandle, func.ValueHandle, out LLVMValueRef args, 0U, string.Empty ); return Value.FromHandle( hCall ); } + /// Builds a memcpy intrinsic call /// Destination pointer of the memcpy /// Source pointer of the memcpy @@ -990,7 +1251,9 @@ public Value MemCpy( Value destination, Value source, Value len, Int32 align, bo { var module = InsertBlock?.ContainingFunction?.ParentModule; if( module == null ) + { throw new InvalidOperationException( "Cannot insert when no block/module is available" ); + } return MemCpy( module, destination, source, len, align, isVolatile ); } @@ -1011,33 +1274,51 @@ public Value MemCpy( Value destination, Value source, Value len, Int32 align, bo public Value MemCpy( NativeModule module, Value destination, Value source, Value len, Int32 align, bool isVolatile ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( destination == null ) + { throw new ArgumentNullException( nameof( destination ) ); + } if( source == null ) + { throw new ArgumentNullException( nameof( source ) ); + } if( len == null ) + { throw new ArgumentNullException( nameof( len ) ); + } if( destination == source ) + { throw new InvalidOperationException( "Source and destination arguments are the same value" ); + } var dstPtrType = destination.NativeType as IPointerType; if( dstPtrType == null ) + { throw new ArgumentException( "Pointer type expected", nameof( destination ) ); + } var srcPtrType = source.NativeType as IPointerType; if( srcPtrType == null ) + { throw new ArgumentException( "Pointer type expected", nameof( source ) ); + } if( !len.NativeType.IsInteger ) + { throw new ArgumentException( "Integer type expected", nameof( len ) ); + } if( Context != module.Context ) + { throw new ArgumentException( "Module and instruction builder must come from the same context" ); + } if( !dstPtrType.ElementType.IsInteger ) { @@ -1052,7 +1333,7 @@ public Value MemCpy( NativeModule module, Value destination, Value source, Value } // find the name of the appropriate overloaded form - var intrinsicName = Instructions.MemCpy.GetIntrinsicNameForArgs( dstPtrType, srcPtrType, len.NativeType ); + string intrinsicName = Instructions.MemCpy.GetIntrinsicNameForArgs( dstPtrType, srcPtrType, len.NativeType ); var func = module.GetFunction( intrinsicName ); if( func == null ) { @@ -1084,17 +1365,19 @@ public Value MemCpy( NativeModule module, Value destination, Value source, Value /// Flag to indicate if the copy involves volatile data such as physical registers /// call for the memmov /// - /// LLVM has many overloaded variants of the memmov intrinsic, this implementation currently assumes the + /// LLVM has many overloaded variants of the memmov intrinsic, this implementation currently assumes the /// single form defined by , which matches the classic "C" style memmov /// function. However future implementations should be able to deduce the types from the provided values - /// and generate a more specific call without changing any caller code (as is done with + /// and generate a more specific call without changing any caller code (as is done with /// .) /// public Value MemMove( Value destination, Value source, Value len, Int32 align, bool isVolatile ) { var module = InsertBlock?.ContainingFunction?.ParentModule; if( module == null ) + { throw new InvalidOperationException( "Cannot insert when no block/module is available" ); + } return MemMove( module, destination, source, len, align, isVolatile ); } @@ -1108,35 +1391,49 @@ public Value MemMove( Value destination, Value source, Value len, Int32 align, b /// Flag to indicate if the copy involves volatile data such as physical registers /// call for the memmov /// - /// LLVM has many overloaded variants of the memmov intrinsic, this implementation currently assumes the + /// LLVM has many overloaded variants of the memmov intrinsic, this implementation currently assumes the /// single form defined by , which matches the classic "C" style memmov /// function. However future implementations should be able to deduce the types from the provided values - /// and generate a more specific call without changing any caller code (as is done with + /// and generate a more specific call without changing any caller code (as is done with /// .) /// public Value MemMove( NativeModule module, Value destination, Value source, Value len, Int32 align, bool isVolatile ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( destination == null ) + { throw new ArgumentNullException( nameof( destination ) ); + } if( source == null ) + { throw new ArgumentNullException( nameof( source ) ); + } if( len == null ) + { throw new ArgumentNullException( nameof( len ) ); + } - //TODO: make this auto select the LLVM intrinsic signature like memcpy... + // TODO: make this auto select the LLVM intrinsic signature like memcpy... if( !destination.NativeType.IsPointer ) + { throw new ArgumentException( "Pointer type expected", nameof( destination ) ); + } if( !source.NativeType.IsPointer ) + { throw new ArgumentException( "Pointer type expected", nameof( source ) ); + } if( !len.NativeType.IsInteger ) + { throw new ArgumentException( "Integer type expected", nameof( len ) ); + } var ctx = module.Context; @@ -1168,7 +1465,7 @@ public Value MemMove( NativeModule module, Value destination, Value source, Valu /// Flag to indicate if the fill involves volatile data such as physical registers /// call for the memset /// - /// LLVM has many overloaded variants of the memset intrinsic, this implementation currently assumes the + /// LLVM has many overloaded variants of the memset intrinsic, this implementation currently assumes the /// single form defined by , which matches the classic "C" style memset /// function. However future implementations should be able to deduce the types from the provided values /// and generate a more specific call without changing any caller code (as is done with @@ -1178,7 +1475,9 @@ public Value MemSet( Value destination, Value value, Value len, Int32 align, boo { var module = InsertBlock?.ContainingFunction?.ParentModule; if( module == null ) + { throw new InvalidOperationException( "Cannot insert when no block/module is available" ); + } return MemSet( module, destination, value, len, align, isVolatile ); } @@ -1192,7 +1491,7 @@ public Value MemSet( Value destination, Value value, Value len, Int32 align, boo /// Flag to indicate if the fill involves volatile data such as physical registers /// call for the memset /// - /// LLVM has many overloaded variants of the memset intrinsic, this implementation currently assumes the + /// LLVM has many overloaded variants of the memset intrinsic, this implementation currently assumes the /// single form defined by , which matches the classic "C" style memset /// function. However future implementations should be able to deduce the types from the provided values /// and generate a more specific call without changing any caller code (as is done with @@ -1201,22 +1500,34 @@ public Value MemSet( Value destination, Value value, Value len, Int32 align, boo public Value MemSet( NativeModule module, Value destination, Value value, Value len, Int32 align, bool isVolatile ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( destination == null ) + { throw new ArgumentNullException( nameof( destination ) ); + } if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } if( len == null ) + { throw new ArgumentNullException( nameof( len ) ); + } if( destination.NativeType.Kind != TypeKind.Pointer ) + { throw new ArgumentException( "Pointer type expected", nameof( destination ) ); + } if( value.NativeType.IntegerBitWidth != 8 ) + { throw new ArgumentException( "8bit value expected", nameof( value ) ); + } var ctx = module.Context; @@ -1249,46 +1560,51 @@ public Value MemSet( NativeModule module, Value destination, Value value, Value public Value InsertValue( Value aggValue, Value elementValue, uint index ) { if( aggValue == null ) + { throw new ArgumentNullException( nameof( aggValue ) ); + } if( elementValue == null ) + { throw new ArgumentNullException( nameof( elementValue ) ); + } var handle = NativeMethods.BuildInsertValue( BuilderHandle, aggValue.ValueHandle, elementValue.ValueHandle, index, string.Empty ); return Value.FromHandle( handle ); } - ~InstructionBuilder( ) - { - BuilderHandle.Close( ); - } - internal static LLVMValueRef[ ] GetValidatedGEPArgs( Value pointer, IEnumerable args ) { if( pointer == null ) + { throw new ArgumentNullException( nameof( pointer ) ); + } if( pointer.NativeType.Kind != TypeKind.Pointer ) + { throw new ArgumentException( "Pointer value expected", nameof( pointer ) ); + } // if not an array already, pull from source enumerable into an array only once var argsArray = args as Value[ ] ?? args.ToArray( ); if( argsArray.Any( a => !a.NativeType.IsInteger ) ) + { throw new ArgumentException( $"GEP index arguments must be integers" ); + } LLVMValueRef[ ] llvmArgs = argsArray.Select( a => a.ValueHandle ).ToArray( ); if( llvmArgs.Length == 0 ) + { throw new ArgumentException( "There must be at least one index argument", nameof( args ) ); + } return llvmArgs; } - internal InstructionBuilderHandle BuilderHandle { get; } - // LLVM will automatically perform constant folding, thus the result of applying // a unary operator instruction may actually be a constant value and not an instruction // this deals with that to produce a correct managed wrapper type - private Value BuildUnaryOp( Func opFactory + private Value BuildUnaryOp( Func opFactory , Value operand ) { @@ -1299,13 +1615,15 @@ private Value BuildUnaryOp( Func opFactory + private Value BuildBinOp( Func opFactory , Value lhs , Value rhs ) { if( lhs.NativeType != rhs.NativeType ) + { throw new ArgumentException( "Types of binary operators must be identical" ); + } var valueRef = opFactory( BuilderHandle, lhs.ValueHandle, rhs.ValueHandle, string.Empty ); return Value.FromHandle( valueRef ); @@ -1318,6 +1636,7 @@ private Value BuildAtomicBinOp( LLVMAtomicRMWBinOp op, Value ptr, Value val ) { throw new ArgumentException( "Expected pointer type", nameof( ptr ) ); } + if( ptrType.ElementType != val.NativeType ) { throw new ArgumentException( string.Format( IncompatibleTypeMsgFmt, ptrType.ElementType, val.NativeType ) ); @@ -1330,24 +1649,32 @@ private Value BuildAtomicBinOp( LLVMAtomicRMWBinOp op, Value ptr, Value val ) private static void ValidateCallArgs( Value func, IReadOnlyList args ) { if( func == null ) + { throw new ArgumentNullException( nameof( func ) ); + } var funcPtrType = func.NativeType as IPointerType; if( funcPtrType == null ) + { throw new ArgumentException( "Expected pointer to function", nameof( func ) ); + } var elementType = funcPtrType.ElementType as FunctionType; if( elementType == null ) + { throw new ArgumentException( "A pointer to a function is required for an indirect call", nameof( func ) ); + } if( args.Count != elementType.ParameterTypes.Count ) + { throw new ArgumentException( "Mismatched parameter count with call site", nameof( args ) ); + } for( int i = 0; i < args.Count; ++i ) { if( args[ i ].NativeType != elementType.ParameterTypes[ i ] ) { - var msg = $"Call site argument type mismatch for function {func} at index {i}; argType={args[ i ].NativeType}; signatureType={elementType.ParameterTypes[ i ]}"; + string msg = $"Call site argument type mismatch for function {func} at index {i}; argType={args[ i ].NativeType}; signatureType={elementType.ParameterTypes[ i ]}"; Debug.WriteLine( msg ); throw new ArgumentException( msg, nameof( args ) ); } @@ -1367,12 +1694,16 @@ private LLVMValueRef BuildCall( Value func, IReadOnlyList args ) // must always provide at least one element for successful marshaling/interop, but tell LLVM there are none if( argCount == 0 ) + { llvmArgs = new LLVMValueRef[ 1 ]; + } return NativeMethods.BuildCall( BuilderHandle, func.ValueHandle, out llvmArgs[ 0 ], ( uint )argCount, string.Empty ); } - const string IncompatibleTypeMsgFmt = "Incompatible types: destination pointer must be of the same type as the value stored.\n" + internal LLVMBuilderRef BuilderHandle { get; } + + private const string IncompatibleTypeMsgFmt = "Incompatible types: destination pointer must be of the same type as the value stored.\n" + "Types are:\n" + "\tDestination: {0}\n" + "\tValue: {1}"; diff --git a/src/Llvm.NET/Instructions/InstructionExtensions.cs b/src/Llvm.NET/Instructions/InstructionExtensions.cs new file mode 100644 index 000000000..2fad9f746 --- /dev/null +++ b/src/Llvm.NET/Instructions/InstructionExtensions.cs @@ -0,0 +1,59 @@ +namespace Llvm.NET.Instructions +{ + /// Provides extension methods to that cannot be achieved as members of the class + /// + /// Using generic static extension methods allows for fluent coding while retaining the type of the "this" parameter. + /// If these were members of the class then the only return type could be + /// thus losing the original type and requiring a cast to get back to it, thereby defeating the purpose of the fluent style. + /// + public static class InstructionExtensions + { + /// Fluent style extension method to set the for an instruction + /// Type of the instruction (usually implicitly inferred from usage) + /// Instruction to set the for + /// New alignment for the instruction + /// To allow fluent style coding this returns the parameter + public static T Alignment( this T self, uint value ) + where T : Instruction + { + if( self.IsMemoryAccess ) + { + self.Alignment = value; + } + + return self; + } + +#pragma warning disable IDE0019 // Use Pattern matching - doesn't work for generics (Expected in C#7.X) + + /// Fluent style extension method to set the Volatile property of a or instruction + /// Type of the instruction (usually implicitly inferred from usage) + /// Instruction to set the Volatile property for + /// Flag to indicate if the instruction's operation is volatile + /// To allow fluent style coding this returns the parameter + public static T IsVolatile( this T self, bool value ) + where T : Instruction + { + if( self.IsMemoryAccess ) + { + // only load and store instructions have the volatile property + var loadInst = self as Load; + if( loadInst != null ) + { + loadInst.IsVolatile = value; + } + else + { + var storeinst = self as Store; + if( storeinst != null ) + { + storeinst.IsVolatile = value; + } + } + } + + return self; + } + } +#pragma warning restore IDE0019 // Use Pattern matching - doesn't work for generics (Expected in C#7.X) +} diff --git a/src/Llvm.NET/Instructions/Intrinsic.cs b/src/Llvm.NET/Instructions/Intrinsic.cs index 1d4c5ae6c..2358dbaf2 100644 --- a/src/Llvm.NET/Instructions/Intrinsic.cs +++ b/src/Llvm.NET/Instructions/Intrinsic.cs @@ -7,14 +7,14 @@ public class Intrinsic { internal Intrinsic( LLVMValueRef valueRef ) : base( valueRef ) - { + { } internal const string DoNothingName = "llvm.donothing"; internal const string DebugTrapName = "llvm.debugtrap"; - + // TODO: move these out of here to follow pattern in MemCpy internal const string MemMoveName = "llvm.memmove.p0i8.p0i8.i32"; internal const string MemSetName = "llvm.memset.p0i8.i32"; - }; + } } diff --git a/src/Llvm.NET/Instructions/Invoke.cs b/src/Llvm.NET/Instructions/Invoke.cs index d2b75d60c..804a93a7a 100644 --- a/src/Llvm.NET/Instructions/Invoke.cs +++ b/src/Llvm.NET/Instructions/Invoke.cs @@ -1,44 +1,76 @@ -using Llvm.NET.Native; +using System; +using System.Collections.Generic; +using System.Linq; +using Llvm.NET.Native; using Llvm.NET.Values; namespace Llvm.NET.Instructions { public class Invoke : Terminator - , IAttributeSetContainer + , IAttributeAccessor { - public AttributeSet Attributes + public Function TargetFunction => FromHandle( NativeMethods.GetCalledValue( ValueHandle ) ); + + public IAttributeDictionary Attributes { get; } + + public void AddAttributeAtIndex( FunctionAttributeIndex index, AttributeValue attrib ) { - get - { - if( TargetFunction == null ) - return new AttributeSet( ); + attrib.VerifyValidOn( index, this ); - return new AttributeSet( NativeMethods.GetCallSiteAttributeSet( ValueHandle )); - } + NativeMethods.AddCallSiteAttribute( ValueHandle, ( LLVMAttributeIndex )index, attrib.NativeAttribute ); + } - set + public uint GetAttributeCountAtIndex( FunctionAttributeIndex index ) + { + return NativeMethods.GetCallSiteAttributeCount( ValueHandle, ( LLVMAttributeIndex )index ); + } + + public IEnumerable GetAttributesAtIndex( FunctionAttributeIndex index ) + { + uint count = GetAttributeCountAtIndex( index ); + if( count == 0 ) { - // TODO: Verify the attributeSet doesn't contain any parameter indices not supported by the TargetFunction - NativeMethods.SetCallSiteAttributeSet( ValueHandle, value.NativeAttributeSet ); + return Enumerable.Empty( ); } + + var buffer = new LLVMAttributeRef[ count ]; + NativeMethods.GetCallSiteAttributes( ValueHandle, ( LLVMAttributeIndex )index, out buffer[ 0 ] ); + return from attribRef in buffer + select AttributeValue.FromHandle( Context, attribRef ); } - public Function TargetFunction + public AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ) { - get - { - if( Operands.Count < 1 ) - return null; + var handle = NativeMethods.GetCallSiteEnumAttribute( ValueHandle, ( LLVMAttributeIndex )index, kind.GetEnumAttributeId( ) ); + return AttributeValue.FromHandle( Context, handle ); + } - // last Operand of the instruction is the target function - return Operands[ Operands.Count - 1 ] as Function; + public AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, string name ) + { + if( string.IsNullOrWhiteSpace( name ) ) + { + throw new ArgumentException( "name cannot be null or empty", nameof( name ) ); } + + var handle = NativeMethods.GetCallSiteStringAttribute( ValueHandle, ( LLVMAttributeIndex )index, name, ( uint )name.Length ); + return AttributeValue.FromHandle( Context, handle ); + } + + public void RemoveAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ) + { + NativeMethods.RemoveCallSiteEnumAttribute( ValueHandle, ( LLVMAttributeIndex )index, kind.GetEnumAttributeId( ) ); + } + + public void RemoveAttributeAtIndex( FunctionAttributeIndex index, string name ) + { + NativeMethods.RemoveCallSiteStringAttribute( ValueHandle, ( LLVMAttributeIndex )index, name, ( uint )name.Length ); } internal Invoke( LLVMValueRef valueRef ) : base( valueRef ) { + Attributes = new ValueAttributeDictionary( this, ()=>TargetFunction ); } } } diff --git a/src/Llvm.NET/Instructions/LandingPad.cs b/src/Llvm.NET/Instructions/LandingPad.cs index c12f308b9..b2efc0ada 100644 --- a/src/Llvm.NET/Instructions/LandingPad.cs +++ b/src/Llvm.NET/Instructions/LandingPad.cs @@ -1,6 +1,6 @@ -using Llvm.NET.Values; -using System; +using System; using Llvm.NET.Native; +using Llvm.NET.Values; namespace Llvm.NET.Instructions { @@ -15,9 +15,11 @@ internal LandingPad( LLVMValueRef valueRef ) public void AddClause(Value clause) { if( clause == null ) + { throw new ArgumentNullException( nameof( clause ) ); + } - NativeMethods.AddClause(ValueHandle, clause.ValueHandle); + NativeMethods.AddClause( ValueHandle, clause.ValueHandle); } public void SetCleanup( bool value ) => NativeMethods.SetCleanup( ValueHandle, value ); diff --git a/src/Llvm.NET/Instructions/PhiNode.cs b/src/Llvm.NET/Instructions/PhiNode.cs index 91dd57270..b3651a52d 100644 --- a/src/Llvm.NET/Instructions/PhiNode.cs +++ b/src/Llvm.NET/Instructions/PhiNode.cs @@ -15,20 +15,28 @@ public void AddIncoming( Value value, BasicBlock srcBlock ) public void AddIncoming( Tuple firstIncoming, params Tuple[ ] additionalIncoming ) { if( firstIncoming == null ) + { throw new ArgumentNullException( nameof( firstIncoming ) ); + } if( additionalIncoming == null ) + { throw new ArgumentNullException( nameof( additionalIncoming ) ); + } LLVMValueRef[ ] llvmValues = new LLVMValueRef[ additionalIncoming.Length + 1 ]; llvmValues[ 0 ] = firstIncoming.Item1.ValueHandle; for( int i = 0; i < additionalIncoming.Length; ++i ) + { llvmValues[ i + i ] = additionalIncoming[ i ].Item1.ValueHandle; + } LLVMBasicBlockRef[ ] llvmBlocks = new LLVMBasicBlockRef[ additionalIncoming.Length + 1 ]; llvmBlocks[ 0 ] = firstIncoming.Item2.BlockHandle; for( int i = 0; i < additionalIncoming.Length; ++i ) + { llvmBlocks[ i + i ] = additionalIncoming[ i ].Item2.BlockHandle; + } NativeMethods.AddIncoming( ValueHandle, out llvmValues[ 0 ], out llvmBlocks[ 0 ], ( uint )llvmValues.Length ); } diff --git a/src/Llvm.NET/Instructions/SIToFP.cs b/src/Llvm.NET/Instructions/SIToFP.cs index c39df49c0..535014057 100644 --- a/src/Llvm.NET/Instructions/SIToFP.cs +++ b/src/Llvm.NET/Instructions/SIToFP.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class SIToFP : Cast + public class SIToFP : Cast { internal SIToFP( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/Switch.cs b/src/Llvm.NET/Instructions/Switch.cs index e73b6a6e3..4843496c2 100644 --- a/src/Llvm.NET/Instructions/Switch.cs +++ b/src/Llvm.NET/Instructions/Switch.cs @@ -15,10 +15,14 @@ public class Switch public void AddCase( Value onVal, BasicBlock destination ) { if( onVal == null ) + { throw new System.ArgumentNullException( nameof( onVal ) ); + } if( destination == null ) + { throw new System.ArgumentNullException( nameof( destination ) ); + } NativeMethods.AddCase( ValueHandle, onVal.ValueHandle, destination.BlockHandle ); } @@ -27,6 +31,5 @@ internal Switch( LLVMValueRef valueRef ) : base( valueRef ) { } - } } diff --git a/src/Llvm.NET/Instructions/UIToFP.cs b/src/Llvm.NET/Instructions/UIToFP.cs index e534c76ae..39ee2d0c2 100644 --- a/src/Llvm.NET/Instructions/UIToFP.cs +++ b/src/Llvm.NET/Instructions/UIToFP.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class UIToFP : Cast + public class UIToFP : Cast { internal UIToFP( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/UserOp1.cs b/src/Llvm.NET/Instructions/UserOp1.cs index 6c51ef7c1..58e23ab68 100644 --- a/src/Llvm.NET/Instructions/UserOp1.cs +++ b/src/Llvm.NET/Instructions/UserOp1.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class UserOp1 : Instruction + public class UserOp1 : Instruction { internal UserOp1( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/UserOp2.cs b/src/Llvm.NET/Instructions/UserOp2.cs index 4d6afe5c1..4ceffbc8c 100644 --- a/src/Llvm.NET/Instructions/UserOp2.cs +++ b/src/Llvm.NET/Instructions/UserOp2.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class UserOp2 : Instruction + public class UserOp2 : Instruction { internal UserOp2( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/VAArg.cs b/src/Llvm.NET/Instructions/VAArg.cs index 90ccac067..ab896b5b3 100644 --- a/src/Llvm.NET/Instructions/VAArg.cs +++ b/src/Llvm.NET/Instructions/VAArg.cs @@ -2,7 +2,7 @@ namespace Llvm.NET.Instructions { - class VaArg : UnaryInstruction + public class VaArg : UnaryInstruction { internal VaArg( LLVMValueRef valueRef ) : base( valueRef ) diff --git a/src/Llvm.NET/Instructions/ZeroExtend.cs b/src/Llvm.NET/Instructions/ZeroExtend.cs index 049c55663..12d692684 100644 --- a/src/Llvm.NET/Instructions/ZeroExtend.cs +++ b/src/Llvm.NET/Instructions/ZeroExtend.cs @@ -1,5 +1,4 @@ - -using Llvm.NET.Native; +using Llvm.NET.Native; namespace Llvm.NET.Instructions { diff --git a/src/Llvm.NET/InternalCodeGeneratorException.cs b/src/Llvm.NET/InternalCodeGeneratorException.cs index 913181912..aaa2f44e8 100644 --- a/src/Llvm.NET/InternalCodeGeneratorException.cs +++ b/src/Llvm.NET/InternalCodeGeneratorException.cs @@ -1,10 +1,8 @@ using System; -using System.Runtime.Serialization; namespace Llvm.NET { /// Exception generated when the internal state of the code generation cannot proceed due to an internal error - [Serializable] public class InternalCodeGeneratorException : Exception { public InternalCodeGeneratorException( ) @@ -16,16 +14,9 @@ public InternalCodeGeneratorException( string message ) { } - public InternalCodeGeneratorException( string message, Exception inner ) + public InternalCodeGeneratorException( string message, Exception inner ) : base( message, inner ) { } - - protected InternalCodeGeneratorException( SerializationInfo info - , StreamingContext context - ) - : base( info, context ) - { - } } } diff --git a/src/Llvm.NET/LLVM/Generated.cs b/src/Llvm.NET/LLVM/Generated.cs deleted file mode 100644 index f15be7996..000000000 --- a/src/Llvm.NET/LLVM/Generated.cs +++ /dev/null @@ -1,3259 +0,0 @@ -// This file was generated from LLVM 3.6.1 llvm-c API using ClangSharp -// it was further modified in the following ways: -// - removed most uses of the partial keyword except for LLVMNative static class and LLVMBool -// - added warning disable to avoid benign compiler warnings about fields only set by native code -// - modified all elements to be internal instead of public -// - modified PInvoke attributes to use fully qualified name for CallingConvention to avoid conflicts -// - Added Missing LLVMLinkerMode enumeration -// - Fixed signature of LLVMLinkModules to use new enum -// - modified all LLVMNative.* functions returning a string to return IntPtr -// as using string with default CLR marshaling was causing run-time -// Heap Corruption. [Reason unknown] Calling these functions requires calling -// Marshal.PtrToAnsi( x ) manually, which is handled by the OO wrappers. -// - made Value field of LLVMBool private to help prevent confusion on use the Value. For status -// code values code should use the Success/Failure properties (added to partial implementation) -// and implicit casts to/from bool for actual boolean. Unfortunately nothing in LLVM or the -// value of a LLVMBool can help in identifying which form one should use. The only way to know -// at this point is to read the LLVM-C API documentation. In the Future it may be good to Create -// an LLVMStatusResult type for those function returning a status and use standard marshaling -// techniques for actual boolean values... -// - manually updated to 3.8.0 APIs - -using System; -using System.Runtime.InteropServices; - -//warning CS0649: Field 'xxx' is never assigned to, and will always have its default value 0 -#pragma warning disable 649 - -namespace Llvm.NET.Native -{ - internal struct LLVMOpaqueMemoryBuffer - { - } - - internal struct LLVMOpaqueContext - { - } - - internal struct LLVMOpaqueModule - { - } - - internal struct LLVMOpaqueType - { - } - - internal struct LLVMOpaqueValue - { - } - - internal struct LLVMOpaqueBasicBlock - { - } - - internal struct LLVMOpaqueBuilder - { - } - - internal struct LLVMOpaqueModuleProvider - { - } - - internal struct LLVMOpaquePassManager - { - } - - internal struct LLVMOpaquePassRegistry - { - } - - internal struct LLVMOpaqueUse - { - } - - internal struct LLVMOpaqueDiagnosticInfo - { - } - - internal struct LLVMOpInfoSymbol1 - { - public int @Present; - [MarshalAs(UnmanagedType.LPStr)] public string @Name; - public int @Value; - } - - internal struct LLVMOpInfo1 - { - public LLVMOpInfoSymbol1 @AddSymbol; - public LLVMOpInfoSymbol1 @SubtractSymbol; - public int @Value; - public int @VariantKind; - } - - internal struct LLVMOpaqueTargetData - { - } - - internal struct LLVMOpaqueTargetLibraryInfotData - { - } - - internal struct LLVMOpaqueTargetMachine - { - } - - internal struct LLVMTarget - { - } - - internal struct LLVMOpaqueGenericValue - { - } - - internal struct LLVMOpaqueExecutionEngine - { - } - - internal struct LLVMOpaqueMCJITMemoryManager - { - } - - internal struct LLVMMCJITCompilerOptions - { - public uint @OptLevel; - public LLVMCodeModel @CodeModel; - public int @NoFramePointerElim; - public int @EnableFastISel; - public IntPtr @MCJMM; - } - - internal struct LLVMOpaqueLTOModule - { - } - - internal struct LLVMOpaqueLTOCodeGenerator - { - } - - internal struct LLVMOpaqueObjectFile - { - } - - internal struct LLVMOpaqueSectionIterator - { - } - - internal struct LLVMOpaqueSymbolIterator - { - } - - internal struct LLVMOpaqueRelocationIterator - { - } - - internal struct LLVMOpaquePassManagerBuilder - { - } - - internal partial struct LLVMBool - { - public LLVMBool(int value) - { - Value = value; - } - - internal int Value; - } - - internal struct LLVMMemoryBufferRef - { - public LLVMMemoryBufferRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMContextRef - { - public LLVMContextRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMModuleRef - { - public LLVMModuleRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - public readonly static LLVMModuleRef Zero = new LLVMModuleRef( IntPtr.Zero ); - } - - internal struct LLVMTypeRef - { - public LLVMTypeRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMValueRef - { - public LLVMValueRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - - public readonly static LLVMValueRef Zero = new LLVMValueRef( IntPtr.Zero ); - } - - internal struct LLVMBasicBlockRef - { - public LLVMBasicBlockRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMModuleProviderRef - { - public LLVMModuleProviderRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMPassManagerRef - { - public LLVMPassManagerRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMUseRef - { - public LLVMUseRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - internal struct LLVMDiagnosticInfoRef - { - public LLVMDiagnosticInfoRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer { get; } - } - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate void LLVMFatalErrorHandler([MarshalAs(UnmanagedType.LPStr)] string @Reason); - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate void LLVMDiagnosticHandler( LLVMDiagnosticInfoRef @param0, IntPtr @param1); - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate void LLVMYieldCallback(LLVMContextRef @param0, IntPtr @param1); - - internal struct LLVMDisasmContextRef - { - public LLVMDisasmContextRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate int LLVMOpInfoCallback(IntPtr @DisInfo, int @PC, int @Offset, int @Size, int @TagType, IntPtr @TagBuf); - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate string LLVMSymbolLookupCallback(IntPtr @DisInfo, int @ReferenceValue, out int @ReferenceType, int @ReferencePC, out IntPtr @ReferenceName); - - internal struct LLVMTargetDataRef - { - public LLVMTargetDataRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMTargetLibraryInfoRef - { - public LLVMTargetLibraryInfoRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMTargetMachineRef - { - public LLVMTargetMachineRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMTargetRef - { - public LLVMTargetRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMGenericValueRef - { - public LLVMGenericValueRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMExecutionEngineRef - { - public LLVMExecutionEngineRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMMCJITMemoryManagerRef - { - public LLVMMCJITMemoryManagerRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate IntPtr LLVMMemoryManagerAllocateCodeSectionCallback(IntPtr @Opaque, int @Size, uint @Alignment, uint @SectionID, [MarshalAs(UnmanagedType.LPStr)] string @SectionName); - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate IntPtr LLVMMemoryManagerAllocateDataSectionCallback(IntPtr @Opaque, int @Size, uint @Alignment, uint @SectionID, [MarshalAs(UnmanagedType.LPStr)] string @SectionName, int @IsReadOnly); - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate int LLVMMemoryManagerFinalizeMemoryCallback(IntPtr @Opaque, out IntPtr @ErrMsg); - - [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal delegate void LLVMMemoryManagerDestroyCallback(IntPtr @Opaque); - - //internal struct llvm_lto_t - //{ - // public llvm_lto_t(IntPtr pointer) - // { - // this.Pointer = pointer; - // } - - // public IntPtr Pointer; - //} - - //internal struct lto_bool_t - //{ - // public lto_bool_t(bool value) - // { - // this.Value = value; - // } - - // public bool Value; - //} - - //internal struct lto_module_t - //{ - // public lto_module_t(IntPtr pointer) - // { - // this.Pointer = pointer; - // } - - // public IntPtr Pointer; - //} - - //internal struct lto_code_gen_t - //{ - // public lto_code_gen_t(IntPtr pointer) - // { - // this.Pointer = pointer; - // } - - // public IntPtr Pointer; - //} - - //[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal delegate void lto_diagnostic_handler_t(lto_codegen_diagnostic_severity_t @severity, [MarshalAs(UnmanagedType.LPStr)] string @diag, IntPtr @ctxt); - - internal struct LLVMObjectFileRef - { - public LLVMObjectFileRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMSectionIteratorRef - { - public LLVMSectionIteratorRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMSymbolIteratorRef - { - public LLVMSymbolIteratorRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMRelocationIteratorRef - { - public LLVMRelocationIteratorRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal struct LLVMPassManagerBuilderRef - { - public LLVMPassManagerBuilderRef(IntPtr pointer) - { - Pointer = pointer; - } - - public IntPtr Pointer; - } - - internal enum LLVMAttribute : int - { - @LLVMZExtAttribute = 1, - @LLVMSExtAttribute = 2, - @LLVMNoReturnAttribute = 4, - @LLVMInRegAttribute = 8, - @LLVMStructRetAttribute = 16, - @LLVMNoUnwindAttribute = 32, - @LLVMNoAliasAttribute = 64, - @LLVMByValAttribute = 128, - @LLVMNestAttribute = 256, - @LLVMReadNoneAttribute = 512, - @LLVMReadOnlyAttribute = 1024, - @LLVMNoInlineAttribute = 2048, - @LLVMAlwaysInlineAttribute = 4096, - @LLVMOptimizeForSizeAttribute = 8192, - @LLVMStackProtectAttribute = 16384, - @LLVMStackProtectReqAttribute = 32768, - @LLVMAlignment = 2031616, - @LLVMNoCaptureAttribute = 2097152, - @LLVMNoRedZoneAttribute = 4194304, - @LLVMNoImplicitFloatAttribute = 8388608, - @LLVMNakedAttribute = 16777216, - @LLVMInlineHintAttribute = 33554432, - @LLVMStackAlignment = 469762048, - @LLVMReturnsTwice = 536870912, - @LLVMUWTable = 1073741824, - @LLVMNonLazyBind = -2147483648, - } - - internal enum LLVMOpcode : uint - { - @LLVMRet = 1, - @LLVMBr = 2, - @LLVMSwitch = 3, - @LLVMIndirectBr = 4, - @LLVMInvoke = 5, - @LLVMUnreachable = 7, - @LLVMAdd = 8, - @LLVMFAdd = 9, - @LLVMSub = 10, - @LLVMFSub = 11, - @LLVMMul = 12, - @LLVMFMul = 13, - @LLVMUDiv = 14, - @LLVMSDiv = 15, - @LLVMFDiv = 16, - @LLVMURem = 17, - @LLVMSRem = 18, - @LLVMFRem = 19, - @LLVMShl = 20, - @LLVMLShr = 21, - @LLVMAShr = 22, - @LLVMAnd = 23, - @LLVMOr = 24, - @LLVMXor = 25, - @LLVMAlloca = 26, - @LLVMLoad = 27, - @LLVMStore = 28, - @LLVMGetElementPtr = 29, - @LLVMTrunc = 30, - @LLVMZExt = 31, - @LLVMSExt = 32, - @LLVMFPToUI = 33, - @LLVMFPToSI = 34, - @LLVMUIToFP = 35, - @LLVMSIToFP = 36, - @LLVMFPTrunc = 37, - @LLVMFPExt = 38, - @LLVMPtrToInt = 39, - @LLVMIntToPtr = 40, - @LLVMBitCast = 41, - @LLVMAddrSpaceCast = 60, - @LLVMICmp = 42, - @LLVMFCmp = 43, - @LLVMPHI = 44, - @LLVMCall = 45, - @LLVMSelect = 46, - @LLVMUserOp1 = 47, - @LLVMUserOp2 = 48, - @LLVMVAArg = 49, - @LLVMExtractElement = 50, - @LLVMInsertElement = 51, - @LLVMShuffleVector = 52, - @LLVMExtractValue = 53, - @LLVMInsertValue = 54, - @LLVMFence = 55, - @LLVMAtomicCmpXchg = 56, - @LLVMAtomicRMW = 57, - @LLVMResume = 58, - @LLVMLandingPad = 59, - // Gap = 60 - @LLVMCleanupRet = 61, - @LLVMCatchRet = 62, - @LLVMCatchPad = 63, - @LLVMCleandupPad = 64, - @LLVMCatchSwitch = 65 - } - - internal enum LLVMTypeKind : uint - { - @LLVMVoidTypeKind = 0, - @LLVMHalfTypeKind = 1, - @LLVMFloatTypeKind = 2, - @LLVMDoubleTypeKind = 3, - @LLVMX86_FP80TypeKind = 4, - @LLVMFP128TypeKind = 5, - @LLVMPPC_FP128TypeKind = 6, - @LLVMLabelTypeKind = 7, - @LLVMIntegerTypeKind = 8, - @LLVMFunctionTypeKind = 9, - @LLVMStructTypeKind = 10, - @LLVMArrayTypeKind = 11, - @LLVMPointerTypeKind = 12, - @LLVMVectorTypeKind = 13, - @LLVMMetadataTypeKind = 14, - @LLVMX86_MMXTypeKind = 15, - @LLVMTokenTypeKind = 16, - } - - internal enum LLVMLinkage : uint - { - @LLVMExternalLinkage = 0, - @LLVMAvailableExternallyLinkage = 1, - @LLVMLinkOnceAnyLinkage = 2, - @LLVMLinkOnceODRLinkage = 3, - @LLVMLinkOnceODRAutoHideLinkage = 4, - @LLVMWeakAnyLinkage = 5, - @LLVMWeakODRLinkage = 6, - @LLVMAppendingLinkage = 7, - @LLVMInternalLinkage = 8, - @LLVMPrivateLinkage = 9, - @LLVMDLLImportLinkage = 10, - @LLVMDLLExportLinkage = 11, - @LLVMExternalWeakLinkage = 12, - @LLVMGhostLinkage = 13, - @LLVMCommonLinkage = 14, - @LLVMLinkerPrivateLinkage = 15, - @LLVMLinkerPrivateWeakLinkage = 16, - } - - internal enum LLVMVisibility : uint - { - @LLVMDefaultVisibility = 0, - @LLVMHiddenVisibility = 1, - @LLVMProtectedVisibility = 2, - } - - internal enum LLVMDLLStorageClass : uint - { - @LLVMDefaultStorageClass = 0, - @LLVMDLLImportStorageClass = 1, - @LLVMDLLExportStorageClass = 2, - } - - internal enum LLVMCallConv : uint - { - @LLVMCCallConv = 0, - // [gap] - @LLVMFastCallConv = 8, - @LLVMColdCallConv = 9, - @LLVMGHCCallConv = 10, - @LLVMHiPECallConv = 11, - @LLVMWebKitJSCallConv = 12, - @LLVMAnyRegCallConv = 13, - @LLVMPreserveMostCallConv = 14, - @LLVMPreserveAllCallConv = 15, - @LLVMPreserveSwiftCallConv = 16, - @LLVMCxxFasTlsCallConv = 17, - // [gap] - @LLVMFirstTargetCallConv = 64, - @LLVMX86StdcallCallConv = 64, - @LLVMX86FastcallCallConv = 65, - @LLVMArmAPCSCallConv = 66, - @LLVMArmAAPCSCallConv = 67, - @LLVMArmAAPCSVfpCallConv = 68, - @LLVMMSP430IntrCallConv = 69, - @LLVMx86ThisCallConv = 70, - @LLVMPTXKernelCallConv = 71, - @LLVMPTXDeviceCallConv = 72, - // [gap] - @LLVMSpirFuncCallConv = 75, - @LLVMSpirKernelCallConv = 76, - @LLVMIntelOCLBICallConv = 77, - @LLVMx86_64SysVCallConv = 78, - @LLVMx86_64Win64CallConv = 79, - @LLVMx86_VectorCallCallConv = 80, - @LLVM_HHVMCallConv = 81, - @LLVM_HHVM_C_CallConv = 82, - @LLVMx86IntrCallConv = 83, - @LLVM_MaxIDCallConv = 1023, - } - - internal enum LLVMIntPredicate : uint - { - @LLVMIntEQ = 32, - @LLVMIntNE = 33, - @LLVMIntUGT = 34, - @LLVMIntUGE = 35, - @LLVMIntULT = 36, - @LLVMIntULE = 37, - @LLVMIntSGT = 38, - @LLVMIntSGE = 39, - @LLVMIntSLT = 40, - @LLVMIntSLE = 41, - } - - internal enum LLVMRealPredicate : uint - { - @LLVMRealPredicateFalse = 0, - @LLVMRealOEQ = 1, - @LLVMRealOGT = 2, - @LLVMRealOGE = 3, - @LLVMRealOLT = 4, - @LLVMRealOLE = 5, - @LLVMRealONE = 6, - @LLVMRealORD = 7, - @LLVMRealUNO = 8, - @LLVMRealUEQ = 9, - @LLVMRealUGT = 10, - @LLVMRealUGE = 11, - @LLVMRealULT = 12, - @LLVMRealULE = 13, - @LLVMRealUNE = 14, - @LLVMRealPredicateTrue = 15, - } - - internal enum LLVMLandingPadClauseTy : uint - { - @LLVMLandingPadCatch = 0, - @LLVMLandingPadFilter = 1, - } - - internal enum LLVMThreadLocalMode : uint - { - @LLVMNotThreadLocal = 0, - @LLVMGeneralDynamicTLSModel = 1, - @LLVMLocalDynamicTLSModel = 2, - @LLVMInitialExecTLSModel = 3, - @LLVMLocalExecTLSModel = 4, - } - - internal enum LLVMAtomicOrdering : uint - { - @LLVMAtomicOrderingNotAtomic = 0, - @LLVMAtomicOrderingUnordered = 1, - @LLVMAtomicOrderingMonotonic = 2, - @LLVMAtomicOrderingAcquire = 4, - @LLVMAtomicOrderingRelease = 5, - @LLVMAtomicOrderingAcquireRelease = 6, - @LLVMAtomicOrderingSequentiallyConsistent = 7, - } - - internal enum LLVMAtomicRMWBinOp : uint - { - @LLVMAtomicRMWBinOpXchg = 0, - @LLVMAtomicRMWBinOpAdd = 1, - @LLVMAtomicRMWBinOpSub = 2, - @LLVMAtomicRMWBinOpAnd = 3, - @LLVMAtomicRMWBinOpNand = 4, - @LLVMAtomicRMWBinOpOr = 5, - @LLVMAtomicRMWBinOpXor = 6, - @LLVMAtomicRMWBinOpMax = 7, - @LLVMAtomicRMWBinOpMin = 8, - @LLVMAtomicRMWBinOpUMax = 9, - @LLVMAtomicRMWBinOpUMin = 10, - } - - internal enum LLVMDiagnosticSeverity : uint - { - @LLVMDSError = 0, - @LLVMDSWarning = 1, - @LLVMDSRemark = 2, - @LLVMDSNote = 3, - } - - internal enum LLVMVerifierFailureAction : uint - { - @LLVMAbortProcessAction = 0, - @LLVMPrintMessageAction = 1, - @LLVMReturnStatusAction = 2, - } - - internal enum LLVMByteOrdering : uint - { - @LLVMBigEndian = 0, - @LLVMLittleEndian = 1, - } - - internal enum LLVMCodeGenOptLevel : uint - { - @LLVMCodeGenLevelNone = 0, - @LLVMCodeGenLevelLess = 1, - @LLVMCodeGenLevelDefault = 2, - @LLVMCodeGenLevelAggressive = 3, - } - - internal enum LLVMRelocMode : uint - { - @LLVMRelocDefault = 0, - @LLVMRelocStatic = 1, - @LLVMRelocPIC = 2, - @LLVMRelocDynamicNoPic = 3, - } - - internal enum LLVMCodeModel : uint - { - @LLVMCodeModelDefault = 0, - @LLVMCodeModelJITDefault = 1, - @LLVMCodeModelSmall = 2, - @LLVMCodeModelKernel = 3, - @LLVMCodeModelMedium = 4, - @LLVMCodeModelLarge = 5, - } - - internal enum LLVMCodeGenFileType : uint - { - @LLVMAssemblyFile = 0, - @LLVMObjectFile = 1, - } - - internal enum llvm_lto_status : uint - { - @LLVM_LTO_UNKNOWN = 0, - @LLVM_LTO_OPT_SUCCESS = 1, - @LLVM_LTO_READ_SUCCESS = 2, - @LLVM_LTO_READ_FAILURE = 3, - @LLVM_LTO_WRITE_FAILURE = 4, - @LLVM_LTO_NO_TARGET = 5, - @LLVM_LTO_NO_WORK = 6, - @LLVM_LTO_MODULE_MERGE_FAILURE = 7, - @LLVM_LTO_ASM_FAILURE = 8, - @LLVM_LTO_NULL_OBJECT = 9, - } - - internal enum lto_symbol_attributes : uint - { - @LTO_SYMBOL_ALIGNMENT_MASK = 31, - @LTO_SYMBOL_PERMISSIONS_MASK = 224, - @LTO_SYMBOL_PERMISSIONS_CODE = 160, - @LTO_SYMBOL_PERMISSIONS_DATA = 192, - @LTO_SYMBOL_PERMISSIONS_RODATA = 128, - @LTO_SYMBOL_DEFINITION_MASK = 1792, - @LTO_SYMBOL_DEFINITION_REGULAR = 256, - @LTO_SYMBOL_DEFINITION_TENTATIVE = 512, - @LTO_SYMBOL_DEFINITION_WEAK = 768, - @LTO_SYMBOL_DEFINITION_UNDEFINED = 1024, - @LTO_SYMBOL_DEFINITION_WEAKUNDEF = 1280, - @LTO_SYMBOL_SCOPE_MASK = 14336, - @LTO_SYMBOL_SCOPE_INTERNAL = 2048, - @LTO_SYMBOL_SCOPE_HIDDEN = 4096, - @LTO_SYMBOL_SCOPE_PROTECTED = 8192, - @LTO_SYMBOL_SCOPE_DEFAULT = 6144, - @LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 10240, - } - - internal enum lto_debug_model : uint - { - @LTO_DEBUG_MODEL_NONE = 0, - @LTO_DEBUG_MODEL_DWARF = 1, - } - - internal enum lto_codegen_model : uint - { - @LTO_CODEGEN_PIC_MODEL_STATIC = 0, - @LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, - @LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, - @LTO_CODEGEN_PIC_MODEL_DEFAULT = 3, - } - - internal enum lto_codegen_diagnostic_severity_t : uint - { - @LTO_DS_ERROR = 0, - @LTO_DS_WARNING = 1, - @LTO_DS_REMARK = 3, - @LTO_DS_NOTE = 2, - } - - internal static partial class NativeMethods - { - private const string libraryPath = "LibLlvm.dll"; - - [DllImport(libraryPath, EntryPoint = "LLVMLoadLibraryPermanently", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool LoadLibraryPermanently([MarshalAs(UnmanagedType.LPStr)] string @Filename); - - [DllImport(libraryPath, EntryPoint = "LLVMParseCommandLineOptions", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ParseCommandLineOptions(int @argc, string[] @argv, [MarshalAs(UnmanagedType.LPStr)] string @Overview); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeCore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeCore(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMShutdown", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void Shutdown(); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateMessage", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr CreateMessage([MarshalAs(UnmanagedType.LPStr)] string @Message); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeMessage", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeMessage(IntPtr @Message); - - [DllImport(libraryPath, EntryPoint = "LLVMInstallFatalErrorHandler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InstallFatalErrorHandler(LLVMFatalErrorHandler @Handler); - - [DllImport(libraryPath, EntryPoint = "LLVMResetFatalErrorHandler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ResetFatalErrorHandler(); - - [DllImport(libraryPath, EntryPoint = "LLVMEnablePrettyStackTrace", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void EnablePrettyStackTrace(); - - [DllImport(libraryPath, EntryPoint = "LLVMContextCreate", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMContextRef ContextCreate(); - - //[DllImport(libraryPath, EntryPoint = "LLVMGetGlobalContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMContextRef GetGlobalContext(); - - [DllImport(libraryPath, EntryPoint = "LLVMContextSetDiagnosticHandler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ContextSetDiagnosticHandler(LLVMContextRef @C, IntPtr @Handler, IntPtr @DiagnosticContext); - - [DllImport(libraryPath, EntryPoint = "LLVMContextSetYieldCallback", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ContextSetYieldCallback(LLVMContextRef @C, LLVMYieldCallback @Callback, IntPtr @OpaqueHandle); - - [DllImport(libraryPath, EntryPoint = "LLVMContextDispose", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ContextDispose(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMGetDiagInfoDescription", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetDiagInfoDescription(LLVMDiagnosticInfoRef @DI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetDiagInfoSeverity", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDiagnosticSeverity GetDiagInfoSeverity(LLVMDiagnosticInfoRef @DI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetMDKindIDInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetMDKindIDInContext(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Name, uint @SLen); - - [DllImport(libraryPath, EntryPoint = "LLVMGetMDKindID", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetMDKindID([MarshalAs(UnmanagedType.LPStr)] string @Name, uint @SLen); - - [DllImport(libraryPath, EntryPoint = "LLVMModuleCreateWithName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMModuleRef ModuleCreateWithName([MarshalAs(UnmanagedType.LPStr)] string @ModuleID); - - [DllImport(libraryPath, EntryPoint = "LLVMModuleCreateWithNameInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMModuleRef ModuleCreateWithNameInContext([MarshalAs(UnmanagedType.LPStr)] string @ModuleID, LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMCloneModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMModuleRef CloneModule(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeModule(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMGetDataLayout", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetDataLayout(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMSetDataLayout", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetDataLayout(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Triple); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetTarget(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMSetTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetTarget(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Triple); - - [DllImport(libraryPath, EntryPoint = "LLVMDumpModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DumpModule(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMPrintModuleToFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool PrintModuleToFile(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Filename, out IntPtr @ErrorMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMPrintModuleToString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr PrintModuleToString(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMSetModuleInlineAsm", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetModuleInlineAsm(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Asm); - - [DllImport(libraryPath, EntryPoint = "LLVMGetModuleContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMContextRef GetModuleContext(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTypeByName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef GetTypeByName(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNamedMetadataNumOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetNamedMetadataNumOperands(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNamedMetadataOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void GetNamedMetadataOperands(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name, out LLVMValueRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMAddNamedMetadataOperand", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddNamedMetadataOperand(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name, LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMAddFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef AddFunction(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMTypeRef @FunctionTy); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNamedFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetNamedFunction(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetFirstFunction(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMGetLastFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetLastFunction(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetNextFunction(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPreviousFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetPreviousFunction(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTypeKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeKind GetTypeKind(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMTypeIsSized", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool TypeIsSized(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTypeContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMContextRef GetTypeContext(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMDumpType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DumpType(LLVMTypeRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMPrintTypeToString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr PrintTypeToString(LLVMTypeRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMInt1TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef Int1TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMInt8TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef Int8TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMInt16TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef Int16TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMInt32TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef Int32TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMInt64TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef Int64TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMIntTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef IntTypeInContext(LLVMContextRef @C, uint @NumBits); - - //[DllImport(libraryPath, EntryPoint = "LLVMInt1Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef Int1Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInt8Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef Int8Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInt16Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef Int16Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInt32Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef Int32Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInt64Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef Int64Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMIntType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef IntType(uint @NumBits); - - [DllImport(libraryPath, EntryPoint = "LLVMGetIntTypeWidth", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetIntTypeWidth(LLVMTypeRef @IntegerTy); - - [DllImport(libraryPath, EntryPoint = "LLVMHalfTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef HalfTypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMFloatTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef FloatTypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMDoubleTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef DoubleTypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMX86FP80TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef X86FP80TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMFP128TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef FP128TypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMPPCFP128TypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef PPCFP128TypeInContext(LLVMContextRef @C); - - //[DllImport(libraryPath, EntryPoint = "LLVMHalfType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef HalfType(); - - //[DllImport(libraryPath, EntryPoint = "LLVMFloatType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef FloatType(); - - //[DllImport(libraryPath, EntryPoint = "LLVMDoubleType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef DoubleType(); - - //[DllImport(libraryPath, EntryPoint = "LLVMX86FP80Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef X86FP80Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMFP128Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef FP128Type(); - - //[DllImport(libraryPath, EntryPoint = "LLVMPPCFP128Type", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef PPCFP128Type(); - - [DllImport(libraryPath, EntryPoint = "LLVMFunctionType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef FunctionType(LLVMTypeRef @ReturnType, out LLVMTypeRef @ParamTypes, uint @ParamCount, LLVMBool @IsVarArg); - - [DllImport(libraryPath, EntryPoint = "LLVMIsFunctionVarArg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsFunctionVarArg(LLVMTypeRef @FunctionTy); - - [DllImport(libraryPath, EntryPoint = "LLVMGetReturnType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef GetReturnType(LLVMTypeRef @FunctionTy); - - [DllImport(libraryPath, EntryPoint = "LLVMCountParamTypes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint CountParamTypes(LLVMTypeRef @FunctionTy); - - [DllImport(libraryPath, EntryPoint = "LLVMGetParamTypes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void GetParamTypes(LLVMTypeRef @FunctionTy, out LLVMTypeRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMStructTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef StructTypeInContext(LLVMContextRef @C, out LLVMTypeRef @ElementTypes, uint @ElementCount, LLVMBool @Packed); - - //[DllImport(libraryPath, EntryPoint = "LLVMStructType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef StructType(out LLVMTypeRef @ElementTypes, uint @ElementCount, LLVMBool @Packed); - - [DllImport(libraryPath, EntryPoint = "LLVMStructCreateNamed", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef StructCreateNamed(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetStructName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetStructName(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMStructSetBody", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void StructSetBody(LLVMTypeRef @StructTy, out LLVMTypeRef @ElementTypes, uint @ElementCount, LLVMBool @Packed); - - [DllImport(libraryPath, EntryPoint = "LLVMCountStructElementTypes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint CountStructElementTypes(LLVMTypeRef @StructTy); - - [DllImport(libraryPath, EntryPoint = "LLVMGetStructElementTypes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void GetStructElementTypes(LLVMTypeRef @StructTy, out LLVMTypeRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMIsPackedStruct", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsPackedStruct(LLVMTypeRef @StructTy); - - [DllImport(libraryPath, EntryPoint = "LLVMIsOpaqueStruct", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsOpaqueStruct(LLVMTypeRef @StructTy); - - [DllImport(libraryPath, EntryPoint = "LLVMGetElementType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef GetElementType(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMArrayType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef ArrayType(LLVMTypeRef @ElementType, uint @ElementCount); - - [DllImport(libraryPath, EntryPoint = "LLVMGetArrayLength", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetArrayLength(LLVMTypeRef @ArrayTy); - - [DllImport(libraryPath, EntryPoint = "LLVMPointerType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef PointerType(LLVMTypeRef @ElementType, uint @AddressSpace); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPointerAddressSpace", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetPointerAddressSpace(LLVMTypeRef @PointerTy); - - [DllImport(libraryPath, EntryPoint = "LLVMVectorType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef VectorType(LLVMTypeRef @ElementType, uint @ElementCount); - - [DllImport(libraryPath, EntryPoint = "LLVMGetVectorSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetVectorSize(LLVMTypeRef @VectorTy); - - [DllImport(libraryPath, EntryPoint = "LLVMVoidTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef VoidTypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMLabelTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef LabelTypeInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMX86MMXTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef X86MMXTypeInContext(LLVMContextRef @C); - - //[DllImport(libraryPath, EntryPoint = "LLVMVoidType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef VoidType(); - - //[DllImport(libraryPath, EntryPoint = "LLVMLabelType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef LabelType(); - - //[DllImport(libraryPath, EntryPoint = "LLVMX86MMXType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMTypeRef X86MMXType(); - - [DllImport(libraryPath, EntryPoint = "LLVMTypeOf", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef TypeOf(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMGetValueName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetValueName(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMSetValueName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetValueName(LLVMValueRef @Val, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMDumpValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DumpValue(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMPrintValueToString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr PrintValueToString(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMReplaceAllUsesWith", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ReplaceAllUsesWith(LLVMValueRef @OldVal, LLVMValueRef @NewVal); - - [DllImport(libraryPath, EntryPoint = "LLVMIsConstant", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsConstant(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsUndef", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsUndef(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAArgument", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAArgument(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsABasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsABasicBlock(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAInlineAsm", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAInlineAsm(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAUser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAUser(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstant", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstant(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsABlockAddress", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsABlockAddress(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantAggregateZero", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantAggregateZero(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantArray(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantDataSequential", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantDataSequential(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantDataArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantDataArray(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantDataVector", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantDataVector(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantExpr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantExpr(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantFP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantFP(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantInt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantInt(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantPointerNull", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantPointerNull(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantStruct", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantStruct(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAConstantVector", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAConstantVector(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAGlobalValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAGlobalValue(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAGlobalAlias", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAGlobalAlias(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAGlobalObject", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAGlobalObject(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAFunction(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAGlobalVariable", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAGlobalVariable(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAUndefValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAUndefValue(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAInstruction(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsABinaryOperator", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsABinaryOperator(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsACallInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsACallInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAIntrinsicInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAIntrinsicInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsADbgInfoIntrinsic", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsADbgInfoIntrinsic(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsADbgDeclareInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsADbgDeclareInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAMemIntrinsic", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAMemIntrinsic(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAMemCpyInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAMemCpyInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAMemMoveInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAMemMoveInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAMemSetInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAMemSetInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsACmpInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsACmpInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAFCmpInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAFCmpInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAICmpInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAICmpInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAExtractElementInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAExtractElementInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAGetElementPtrInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAGetElementPtrInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAInsertElementInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAInsertElementInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAInsertValueInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAInsertValueInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsALandingPadInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsALandingPadInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAPHINode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAPHINode(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsASelectInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsASelectInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAShuffleVectorInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAShuffleVectorInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAStoreInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAStoreInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsATerminatorInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsATerminatorInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsABranchInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsABranchInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAIndirectBrInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAIndirectBrInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAInvokeInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAInvokeInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAReturnInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAReturnInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsASwitchInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsASwitchInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAUnreachableInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAUnreachableInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAResumeInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAResumeInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAUnaryInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAUnaryInstruction(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAAllocaInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAAllocaInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsACastInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsACastInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAAddrSpaceCastInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAAddrSpaceCastInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsABitCastInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsABitCastInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAFPExtInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAFPExtInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAFPToSIInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAFPToSIInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAFPToUIInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAFPToUIInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAFPTruncInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAFPTruncInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAIntToPtrInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAIntToPtrInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAPtrToIntInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAPtrToIntInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsASExtInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsASExtInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsASIToFPInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsASIToFPInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsATruncInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsATruncInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAUIToFPInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAUIToFPInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAZExtInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAZExtInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAExtractValueInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAExtractValueInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsALoadInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsALoadInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAVAArgInst", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAVAArgInst(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAMDNode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAMDNode(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMIsAMDString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef IsAMDString(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstUse", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMUseRef GetFirstUse(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextUse", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMUseRef GetNextUse(LLVMUseRef @U); - - [DllImport(libraryPath, EntryPoint = "LLVMGetUser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetUser(LLVMUseRef @U); - - [DllImport(libraryPath, EntryPoint = "LLVMGetUsedValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetUsedValue(LLVMUseRef @U); - - [DllImport(libraryPath, EntryPoint = "LLVMGetOperand", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetOperand(LLVMValueRef @Val, uint @Index); - - [DllImport(libraryPath, EntryPoint = "LLVMGetOperandUse", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMUseRef GetOperandUse(LLVMValueRef @Val, uint @Index); - - [DllImport(libraryPath, EntryPoint = "LLVMSetOperand", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetOperand(LLVMValueRef @User, uint @Index, LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNumOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetNumOperands(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNull", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNull(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMConstAllOnes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstAllOnes(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMGetUndef", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetUndef(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMIsNull", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsNull(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMConstPointerNull", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstPointerNull(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMConstInt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstInt(LLVMTypeRef @IntTy, ulong @N, LLVMBool @SignExtend); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntOfArbitraryPrecision", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstIntOfArbitraryPrecision(LLVMTypeRef @IntTy, uint @NumWords, int[] @Words); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntOfString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstIntOfString(LLVMTypeRef @IntTy, [MarshalAs(UnmanagedType.LPStr)] string @Text, char @Radix); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntOfStringAndSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstIntOfStringAndSize(LLVMTypeRef @IntTy, [MarshalAs(UnmanagedType.LPStr)] string @Text, uint @SLen, char @Radix); - - [DllImport(libraryPath, EntryPoint = "LLVMConstReal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstReal(LLVMTypeRef @RealTy, double @N); - - [DllImport(libraryPath, EntryPoint = "LLVMConstRealOfString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstRealOfString(LLVMTypeRef @RealTy, [MarshalAs(UnmanagedType.LPStr)] string @Text); - - [DllImport(libraryPath, EntryPoint = "LLVMConstRealOfStringAndSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstRealOfStringAndSize(LLVMTypeRef @RealTy, [MarshalAs(UnmanagedType.LPStr)] string @Text, uint @SLen); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntGetZExtValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern ulong ConstIntGetZExtValue(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntGetSExtValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern long ConstIntGetSExtValue(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstRealGetDouble", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern double ConstRealGetDouble(LLVMValueRef @ConstantVal, out LLVMBool @losesInfo); - - [DllImport(libraryPath, EntryPoint = "LLVMConstStringInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstStringInContext(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Str, uint @Length, LLVMBool @DontNullTerminate); - - //[DllImport(libraryPath, EntryPoint = "LLVMConstString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMValueRef ConstString([MarshalAs(UnmanagedType.LPStr)] string @Str, uint @Length, LLVMBool @DontNullTerminate); - - [DllImport(libraryPath, EntryPoint = "LLVMIsConstantString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsConstantString(LLVMValueRef @c); - - [DllImport(libraryPath, EntryPoint = "LLVMGetAsString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetAsString(LLVMValueRef @c, out int @out); - - [DllImport(libraryPath, EntryPoint = "LLVMConstStructInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstStructInContext(LLVMContextRef @C, out LLVMValueRef @ConstantVals, uint @Count, LLVMBool @Packed); - - //[DllImport(libraryPath, EntryPoint = "LLVMConstStruct", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMValueRef ConstStruct(out LLVMValueRef @ConstantVals, uint @Count, LLVMBool @Packed); - - [DllImport(libraryPath, EntryPoint = "LLVMConstArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstArray(LLVMTypeRef @ElementTy, out LLVMValueRef @ConstantVals, uint @Length); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNamedStruct", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNamedStruct(LLVMTypeRef @StructTy, out LLVMValueRef @ConstantVals, uint @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMGetElementAsConstant", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetElementAsConstant(LLVMValueRef @c, uint @idx); - - [DllImport(libraryPath, EntryPoint = "LLVMConstVector", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstVector(out LLVMValueRef @ScalarConstantVals, uint @Size); - - [DllImport(libraryPath, EntryPoint = "LLVMGetConstOpcode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMOpcode GetConstOpcode(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMAlignOf", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef AlignOf(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMSizeOf", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef SizeOf(LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNeg(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNSWNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNSWNeg(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNUWNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNUWNeg(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFNeg(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNot", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNot(LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMConstAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstAdd(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNSWAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNSWAdd(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNUWAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNUWAdd(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFAdd(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSub(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNSWSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNSWSub(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNUWSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNUWSub(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFSub(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstMul(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNSWMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNSWMul(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstNUWMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstNUWMul(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFMul(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstUDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstUDiv(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSDiv(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstExactSDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstExactSDiv(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFDiv(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstURem", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstURem(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSRem", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSRem(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFRem", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFRem(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstAnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstAnd(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstOr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstOr(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstXor", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstXor(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstICmp", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstICmp(LLVMIntPredicate @Predicate, LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFCmp", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFCmp(LLVMRealPredicate @Predicate, LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstShl", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstShl(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstLShr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstLShr(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstAShr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstAShr(LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstGEP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstGEP(LLVMValueRef @ConstantVal, out LLVMValueRef @ConstantIndices, uint @NumIndices); - - [DllImport(libraryPath, EntryPoint = "LLVMConstInBoundsGEP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstInBoundsGEP(LLVMValueRef @ConstantVal, out LLVMValueRef @ConstantIndices, uint @NumIndices); - - [DllImport(libraryPath, EntryPoint = "LLVMConstTrunc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstTrunc(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSExt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSExt(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstZExt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstZExt(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFPTrunc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFPTrunc(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFPExt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFPExt(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstUIToFP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstUIToFP(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSIToFP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSIToFP(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFPToUI", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFPToUI(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFPToSI", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFPToSI(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstPtrToInt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstPtrToInt(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntToPtr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstIntToPtr(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstBitCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstAddrSpaceCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstAddrSpaceCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstZExtOrBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstZExtOrBitCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSExtOrBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSExtOrBitCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstTruncOrBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstTruncOrBitCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstPointerCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstPointerCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstIntCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstIntCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType, LLVMBool @isSigned); - - [DllImport(libraryPath, EntryPoint = "LLVMConstFPCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstFPCast(LLVMValueRef @ConstantVal, LLVMTypeRef @ToType); - - [DllImport(libraryPath, EntryPoint = "LLVMConstSelect", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstSelect(LLVMValueRef @ConstantCondition, LLVMValueRef @ConstantIfTrue, LLVMValueRef @ConstantIfFalse); - - [DllImport(libraryPath, EntryPoint = "LLVMConstExtractElement", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstExtractElement(LLVMValueRef @VectorConstant, LLVMValueRef @IndexConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstInsertElement", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstInsertElement(LLVMValueRef @VectorConstant, LLVMValueRef @ElementValueConstant, LLVMValueRef @IndexConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstShuffleVector", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstShuffleVector(LLVMValueRef @VectorAConstant, LLVMValueRef @VectorBConstant, LLVMValueRef @MaskConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMConstExtractValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstExtractValue(LLVMValueRef @AggConstant, out uint @IdxList, uint @NumIdx); - - [DllImport(libraryPath, EntryPoint = "LLVMConstInsertValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstInsertValue(LLVMValueRef @AggConstant, LLVMValueRef @ElementValueConstant, out uint @IdxList, uint @NumIdx); - - [DllImport(libraryPath, EntryPoint = "LLVMConstInlineAsm", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef ConstInlineAsm(LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @AsmString, [MarshalAs(UnmanagedType.LPStr)] string @Constraints, LLVMBool @HasSideEffects, LLVMBool @IsAlignStack); - - [DllImport(libraryPath, EntryPoint = "LLVMBlockAddress", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BlockAddress(LLVMValueRef @F, LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMGetGlobalParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMModuleRef GetGlobalParent(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMIsDeclaration", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsDeclaration(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMGetLinkage", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMLinkage GetLinkage(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMSetLinkage", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetLinkage(LLVMValueRef @Global, LLVMLinkage @Linkage); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSection", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetSection(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMSetSection", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetSection(LLVMValueRef @Global, [MarshalAs(UnmanagedType.LPStr)] string @Section); - - [DllImport(libraryPath, EntryPoint = "LLVMGetVisibility", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMVisibility GetVisibility(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMSetVisibility", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetVisibility(LLVMValueRef @Global, LLVMVisibility @Viz); - - [DllImport(libraryPath, EntryPoint = "LLVMGetDLLStorageClass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDLLStorageClass GetDLLStorageClass(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMSetDLLStorageClass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetDLLStorageClass(LLVMValueRef @Global, LLVMDLLStorageClass @Class); - - [DllImport(libraryPath, EntryPoint = "LLVMHasUnnamedAddr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool HasUnnamedAddr(LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMSetUnnamedAddr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetUnnamedAddr(LLVMValueRef @Global, LLVMBool @HasUnnamedAddr); - - [DllImport(libraryPath, EntryPoint = "LLVMGetAlignment", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetAlignment(LLVMValueRef @V); - - [DllImport(libraryPath, EntryPoint = "LLVMSetAlignment", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetAlignment(LLVMValueRef @V, uint @Bytes); - - [DllImport(libraryPath, EntryPoint = "LLVMAddGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef AddGlobal(LLVMModuleRef @M, LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMAddGlobalInAddressSpace", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef AddGlobalInAddressSpace(LLVMModuleRef @M, LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name, uint @AddressSpace); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNamedGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetNamedGlobal(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetFirstGlobal(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMGetLastGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetLastGlobal(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetNextGlobal(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPreviousGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetPreviousGlobal(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMDeleteGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DeleteGlobal(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMGetInitializer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetInitializer(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMSetInitializer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetInitializer(LLVMValueRef @GlobalVar, LLVMValueRef @ConstantVal); - - [DllImport(libraryPath, EntryPoint = "LLVMIsThreadLocal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsThreadLocal(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMSetThreadLocal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetThreadLocal(LLVMValueRef @GlobalVar, LLVMBool @IsThreadLocal); - - [DllImport(libraryPath, EntryPoint = "LLVMIsGlobalConstant", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsGlobalConstant(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMSetGlobalConstant", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetGlobalConstant(LLVMValueRef @GlobalVar, LLVMBool @IsConstant); - - [DllImport(libraryPath, EntryPoint = "LLVMGetThreadLocalMode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMThreadLocalMode GetThreadLocalMode(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMSetThreadLocalMode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetThreadLocalMode(LLVMValueRef @GlobalVar, LLVMThreadLocalMode @Mode); - - [DllImport(libraryPath, EntryPoint = "LLVMIsExternallyInitialized", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsExternallyInitialized(LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMSetExternallyInitialized", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetExternallyInitialized(LLVMValueRef @GlobalVar, LLVMBool @IsExtInit); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAlias", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef AddAlias(LLVMModuleRef @M, LLVMTypeRef @Ty, LLVMValueRef @Aliasee, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMDeleteFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DeleteFunction(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetIntrinsicID", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetIntrinsicID(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFunctionCallConv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetFunctionCallConv(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMSetFunctionCallConv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetFunctionCallConv(LLVMValueRef @Fn, uint @CC); - - [DllImport(libraryPath, EntryPoint = "LLVMGetGC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetGC(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMSetGC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetGC(LLVMValueRef @Fn, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - // legacy attribute manipulation is deprecated - use the LLVMAttributeXXX APIs in GeneratedExtensions.cs instead - // attribute support was fairly significantly reworked in LLVM 3.6+ - //[DllImport(libraryPath, EntryPoint = "LLVMAddFunctionAttr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void AddFunctionAttr(LLVMValueRef @Fn, LLVMAttribute @PA); - - //[DllImport(libraryPath, EntryPoint = "LLVMAddTargetDependentFunctionAttr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void AddTargetDependentFunctionAttr(LLVMValueRef @Fn, [MarshalAs(UnmanagedType.LPStr)] string @A, [MarshalAs(UnmanagedType.LPStr)] string @V); - - //[DllImport(libraryPath, EntryPoint = "LLVMGetFunctionAttr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMAttribute GetFunctionAttr(LLVMValueRef @Fn); - - //[DllImport(libraryPath, EntryPoint = "LLVMRemoveFunctionAttr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void RemoveFunctionAttr(LLVMValueRef @Fn, LLVMAttribute @PA); - - //[DllImport(libraryPath, EntryPoint = "LLVMAddAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void AddAttribute(LLVMValueRef @Arg, LLVMAttribute @PA); - - //[DllImport(libraryPath, EntryPoint = "LLVMRemoveAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void RemoveAttribute(LLVMValueRef @Arg, LLVMAttribute @PA); - - //[DllImport(libraryPath, EntryPoint = "LLVMGetAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMAttribute GetAttribute(LLVMValueRef @Arg); - - //[DllImport(libraryPath, EntryPoint = "LLVMAddInstrAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void AddInstrAttribute(LLVMValueRef @Instr, uint @index, LLVMAttribute @param2); - - //[DllImport(libraryPath, EntryPoint = "LLVMRemoveInstrAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void RemoveInstrAttribute(LLVMValueRef @Instr, uint @index, LLVMAttribute @param2); - - [DllImport(libraryPath, EntryPoint = "LLVMCountParams", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint CountParams(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetParams", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void GetParams(LLVMValueRef @Fn, out LLVMValueRef @Params); - - [DllImport(libraryPath, EntryPoint = "LLVMGetParam", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetParam(LLVMValueRef @Fn, uint @Index); - - [DllImport(libraryPath, EntryPoint = "LLVMGetParamParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetParamParent(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstParam", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetFirstParam(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetLastParam", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetLastParam(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextParam", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetNextParam(LLVMValueRef @Arg); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPreviousParam", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetPreviousParam(LLVMValueRef @Arg); - - [DllImport(libraryPath, EntryPoint = "LLVMSetParamAlignment", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetParamAlignment(LLVMValueRef @Arg, uint @align); - - [DllImport(libraryPath, EntryPoint = "LLVMMDStringInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef MDStringInContext(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Str, uint @SLen); - - [DllImport(libraryPath, EntryPoint = "LLVMMDString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef MDString([MarshalAs(UnmanagedType.LPStr)] string @Str, uint @SLen); - - [DllImport(libraryPath, EntryPoint = "LLVMMDNodeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef MDNodeInContext(LLVMContextRef @C, out LLVMValueRef @Vals, uint @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMMDNode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef MDNode(out LLVMValueRef @Vals, uint @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMGetMDString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetMDString(LLVMValueRef @V, out uint @Len); - - [DllImport(libraryPath, EntryPoint = "LLVMGetMDNodeNumOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetMDNodeNumOperands(LLVMValueRef @V); - - [DllImport(libraryPath, EntryPoint = "LLVMGetMDNodeOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void GetMDNodeOperands(LLVMValueRef @V, out LLVMValueRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMBasicBlockAsValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BasicBlockAsValue(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMValueIsBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool ValueIsBasicBlock(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMValueAsBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef ValueAsBasicBlock(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMGetBasicBlockParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetBasicBlockParent(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMGetBasicBlockTerminator", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetBasicBlockTerminator(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMCountBasicBlocks", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint CountBasicBlocks(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetBasicBlocks", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void GetBasicBlocks(LLVMValueRef @Fn, out LLVMBasicBlockRef @BasicBlocks); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetFirstBasicBlock(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetLastBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetLastBasicBlock(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetNextBasicBlock(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPreviousBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetPreviousBasicBlock(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMGetEntryBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetEntryBasicBlock(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMAppendBasicBlockInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef AppendBasicBlockInContext(LLVMContextRef @C, LLVMValueRef @Fn, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMAppendBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef AppendBasicBlock(LLVMValueRef @Fn, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMInsertBasicBlockInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef InsertBasicBlockInContext(LLVMContextRef @C, LLVMBasicBlockRef @BB, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMInsertBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef InsertBasicBlock(LLVMBasicBlockRef @InsertBeforeBB, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMDeleteBasicBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DeleteBasicBlock(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMRemoveBasicBlockFromParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void RemoveBasicBlockFromParent(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMMoveBasicBlockBefore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MoveBasicBlockBefore(LLVMBasicBlockRef @BB, LLVMBasicBlockRef @MovePos); - - [DllImport(libraryPath, EntryPoint = "LLVMMoveBasicBlockAfter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MoveBasicBlockAfter(LLVMBasicBlockRef @BB, LLVMBasicBlockRef @MovePos); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetFirstInstruction(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMGetLastInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetLastInstruction(LLVMBasicBlockRef @BB); - - [DllImport(libraryPath, EntryPoint = "LLVMHasMetadata", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int HasMetadata(LLVMValueRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMGetMetadata", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetMetadata(LLVMValueRef @Val, uint @KindID); - - [DllImport(libraryPath, EntryPoint = "LLVMSetMetadata", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetMetadata(LLVMValueRef @Val, uint @KindID, LLVMValueRef @Node); - - [DllImport(libraryPath, EntryPoint = "LLVMGetInstructionParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetInstructionParent(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetNextInstruction(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPreviousInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetPreviousInstruction(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMInstructionEraseFromParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InstructionEraseFromParent(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMGetInstructionOpcode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMOpcode GetInstructionOpcode(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMGetICmpPredicate", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMIntPredicate GetICmpPredicate(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFCmpPredicate", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMRealPredicate GetFCmpPredicate(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMInstructionClone", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef InstructionClone(LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMSetInstructionCallConv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetInstructionCallConv(LLVMValueRef @Instr, uint @CC); - - [DllImport(libraryPath, EntryPoint = "LLVMGetInstructionCallConv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetInstructionCallConv(LLVMValueRef @Instr); - - [DllImport(libraryPath, EntryPoint = "LLVMSetInstrParamAlignment", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetInstrParamAlignment(LLVMValueRef @Instr, uint @index, uint @align); - - [DllImport(libraryPath, EntryPoint = "LLVMIsTailCall", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsTailCall(LLVMValueRef @CallInst); - - [DllImport(libraryPath, EntryPoint = "LLVMSetTailCall", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetTailCall(LLVMValueRef @CallInst, LLVMBool @IsTailCall); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNumSuccessors", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GetNumSuccessors(LLVMValueRef @Term); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSuccessor", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetSuccessor(LLVMValueRef @Term, uint @i); - - [DllImport(libraryPath, EntryPoint = "LLVMSetSuccessor", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetSuccessor(LLVMValueRef @Term, uint @i, LLVMBasicBlockRef @block); - - [DllImport(libraryPath, EntryPoint = "LLVMIsConditional", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsConditional(LLVMValueRef @Branch); - - [DllImport(libraryPath, EntryPoint = "LLVMGetCondition", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetCondition(LLVMValueRef @Branch); - - [DllImport(libraryPath, EntryPoint = "LLVMSetCondition", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetCondition(LLVMValueRef @Branch, LLVMValueRef @Cond); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSwitchDefaultDest", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetSwitchDefaultDest(LLVMValueRef @SwitchInstr); - - [DllImport(libraryPath, EntryPoint = "LLVMAddIncoming", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddIncoming(LLVMValueRef @PhiNode, out LLVMValueRef @IncomingValues, out LLVMBasicBlockRef @IncomingBlocks, uint @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMCountIncoming", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint CountIncoming(LLVMValueRef @PhiNode); - - [DllImport(libraryPath, EntryPoint = "LLVMGetIncomingValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetIncomingValue(LLVMValueRef @PhiNode, uint @Index); - - [DllImport(libraryPath, EntryPoint = "LLVMGetIncomingBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetIncomingBlock(LLVMValueRef @PhiNode, uint @Index); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateBuilderInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern InstructionBuilderHandle CreateBuilderInContext(LLVMContextRef @C); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern InstructionBuilderHandle CreateBuilder(); - - [DllImport(libraryPath, EntryPoint = "LLVMPositionBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PositionBuilder(InstructionBuilderHandle @Builder, LLVMBasicBlockRef @Block, LLVMValueRef @Instr); - - [DllImport(libraryPath, EntryPoint = "LLVMPositionBuilderBefore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PositionBuilderBefore(InstructionBuilderHandle @Builder, LLVMValueRef @Instr); - - [DllImport(libraryPath, EntryPoint = "LLVMPositionBuilderAtEnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PositionBuilderAtEnd(InstructionBuilderHandle @Builder, LLVMBasicBlockRef @Block); - - [DllImport(libraryPath, EntryPoint = "LLVMGetInsertBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBasicBlockRef GetInsertBlock(InstructionBuilderHandle @Builder); - - [DllImport(libraryPath, EntryPoint = "LLVMClearInsertionPosition", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ClearInsertionPosition(InstructionBuilderHandle @Builder); - - [DllImport(libraryPath, EntryPoint = "LLVMInsertIntoBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InsertIntoBuilder(InstructionBuilderHandle @Builder, LLVMValueRef @Instr); - - [DllImport(libraryPath, EntryPoint = "LLVMInsertIntoBuilderWithName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InsertIntoBuilderWithName(InstructionBuilderHandle @Builder, LLVMValueRef @Instr, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeBuilder(IntPtr @Builder); - - [DllImport(libraryPath, EntryPoint = "LLVMSetCurrentDebugLocation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetCurrentDebugLocation(InstructionBuilderHandle @Builder, LLVMValueRef @L); - - [DllImport(libraryPath, EntryPoint = "LLVMGetCurrentDebugLocation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetCurrentDebugLocation(InstructionBuilderHandle @Builder); - - [DllImport(libraryPath, EntryPoint = "LLVMSetInstDebugLocation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetInstDebugLocation(InstructionBuilderHandle @Builder, LLVMValueRef @Inst); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildRetVoid", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildRetVoid(InstructionBuilderHandle @param0); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildRet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildRet(InstructionBuilderHandle @param0, LLVMValueRef @V); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAggregateRet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAggregateRet(InstructionBuilderHandle @param0, out LLVMValueRef @RetVals, uint @N); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildBr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildBr(InstructionBuilderHandle @param0, LLVMBasicBlockRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildCondBr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildCondBr(InstructionBuilderHandle @param0, LLVMValueRef @If, LLVMBasicBlockRef @Then, LLVMBasicBlockRef @Else); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSwitch", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSwitch(InstructionBuilderHandle @param0, LLVMValueRef @V, LLVMBasicBlockRef @Else, uint @NumCases); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildIndirectBr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildIndirectBr(InstructionBuilderHandle @B, LLVMValueRef @Addr, uint @NumDests); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildInvoke", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildInvoke(InstructionBuilderHandle @param0, LLVMValueRef @Fn, out LLVMValueRef @Args, uint @NumArgs, LLVMBasicBlockRef @Then, LLVMBasicBlockRef @Catch, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildLandingPad", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildLandingPad(InstructionBuilderHandle @B, LLVMTypeRef @Ty, LLVMValueRef PersFn, uint @NumClauses, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildResume", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildResume(InstructionBuilderHandle @B, LLVMValueRef @Exn); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildUnreachable", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildUnreachable(InstructionBuilderHandle @param0); - - [DllImport(libraryPath, EntryPoint = "LLVMAddCase", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddCase(LLVMValueRef @Switch, LLVMValueRef @OnVal, LLVMBasicBlockRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMAddDestination", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddDestination(LLVMValueRef @IndirectBr, LLVMBasicBlockRef @Dest); - - [DllImport(libraryPath, EntryPoint = "LLVMAddClause", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddClause(LLVMValueRef @LandingPad, LLVMValueRef @ClauseVal); - - [DllImport(libraryPath, EntryPoint = "LLVMSetCleanup", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetCleanup(LLVMValueRef @LandingPad, LLVMBool @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAdd(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNSWAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNSWAdd(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNUWAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNUWAdd(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFAdd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFAdd(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSub(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNSWSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNSWSub(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNUWSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNUWSub(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFSub", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFSub(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildMul(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNSWMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNSWMul(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNUWMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNUWMul(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFMul", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFMul(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildUDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildUDiv(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSDiv(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildExactSDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildExactSDiv(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFDiv", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFDiv(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildURem", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildURem(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSRem", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSRem(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFRem", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFRem(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildShl", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildShl(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildLShr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildLShr(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAShr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAShr(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAnd(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildOr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildOr(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildXor", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildXor(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildBinOp", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildBinOp(InstructionBuilderHandle @B, LLVMOpcode @Op, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNeg(InstructionBuilderHandle @param0, LLVMValueRef @V, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNSWNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNSWNeg(InstructionBuilderHandle @B, LLVMValueRef @V, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNUWNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNUWNeg(InstructionBuilderHandle @B, LLVMValueRef @V, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFNeg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFNeg(InstructionBuilderHandle @param0, LLVMValueRef @V, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildNot", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildNot(InstructionBuilderHandle @param0, LLVMValueRef @V, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildMalloc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildMalloc(InstructionBuilderHandle @param0, LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildArrayMalloc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildArrayMalloc(InstructionBuilderHandle @param0, LLVMTypeRef @Ty, LLVMValueRef @Val, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAlloca", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAlloca(InstructionBuilderHandle @param0, LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildArrayAlloca", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildArrayAlloca(InstructionBuilderHandle @param0, LLVMTypeRef @Ty, LLVMValueRef @Val, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFree", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFree(InstructionBuilderHandle @param0, LLVMValueRef @PointerVal); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildLoad", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildLoad(InstructionBuilderHandle @param0, LLVMValueRef @PointerVal, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildStore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildStore(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMValueRef @Ptr); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildGEP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildGEP(InstructionBuilderHandle @B, LLVMValueRef @Pointer, out LLVMValueRef @Indices, uint @NumIndices, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildInBoundsGEP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildInBoundsGEP(InstructionBuilderHandle @B, LLVMValueRef @Pointer, out LLVMValueRef @Indices, uint @NumIndices, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildStructGEP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildStructGEP(InstructionBuilderHandle @B, LLVMValueRef @Pointer, uint @Idx, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildGlobalString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildGlobalString(InstructionBuilderHandle @B, [MarshalAs(UnmanagedType.LPStr)] string @Str, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildGlobalStringPtr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildGlobalStringPtr(InstructionBuilderHandle @B, [MarshalAs(UnmanagedType.LPStr)] string @Str, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetVolatile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool GetVolatile(LLVMValueRef @MemoryAccessInst); - - [DllImport(libraryPath, EntryPoint = "LLVMSetVolatile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetVolatile(LLVMValueRef @MemoryAccessInst, LLVMBool @IsVolatile); - - [DllImport( libraryPath, EntryPoint = "LLVMGetOrdering", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMAtomicOrdering GetOrdering( LLVMValueRef @MemoryAccessInst ); - - [DllImport( libraryPath, EntryPoint = "LLVMSetOrdering", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void SetOrdering( LLVMValueRef @MemoryAccessInst, LLVMAtomicOrdering @Ordering ); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildTrunc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildTrunc(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildZExt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildZExt(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSExt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSExt(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFPToUI", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFPToUI(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFPToSI", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFPToSI(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildUIToFP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildUIToFP(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSIToFP", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSIToFP(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFPTrunc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFPTrunc(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFPExt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFPExt(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildPtrToInt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildPtrToInt(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildIntToPtr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildIntToPtr(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildBitCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAddrSpaceCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAddrSpaceCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildZExtOrBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildZExtOrBitCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSExtOrBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSExtOrBitCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildTruncOrBitCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildTruncOrBitCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildCast(InstructionBuilderHandle @B, LLVMOpcode @Op, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildPointerCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildPointerCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildIntCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildIntCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFPCast", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFPCast(InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildICmp", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildICmp(InstructionBuilderHandle @param0, LLVMIntPredicate @Op, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFCmp", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFCmp(InstructionBuilderHandle @param0, LLVMRealPredicate @Op, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildPhi", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildPhi(InstructionBuilderHandle @param0, LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildCall", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildCall(InstructionBuilderHandle @param0, LLVMValueRef @Fn, out LLVMValueRef @Args, uint @NumArgs, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildSelect", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildSelect(InstructionBuilderHandle @param0, LLVMValueRef @If, LLVMValueRef @Then, LLVMValueRef @Else, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildVAArg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildVAArg(InstructionBuilderHandle @param0, LLVMValueRef @List, LLVMTypeRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildExtractElement", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildExtractElement(InstructionBuilderHandle @param0, LLVMValueRef @VecVal, LLVMValueRef @Index, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildInsertElement", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildInsertElement(InstructionBuilderHandle @param0, LLVMValueRef @VecVal, LLVMValueRef @EltVal, LLVMValueRef @Index, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildShuffleVector", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildShuffleVector(InstructionBuilderHandle @param0, LLVMValueRef @V1, LLVMValueRef @V2, LLVMValueRef @Mask, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildExtractValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildExtractValue(InstructionBuilderHandle @param0, LLVMValueRef @AggVal, uint @Index, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildInsertValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildInsertValue(InstructionBuilderHandle @param0, LLVMValueRef @AggVal, LLVMValueRef @EltVal, uint @Index, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildIsNull", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildIsNull(InstructionBuilderHandle @param0, LLVMValueRef @Val, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildIsNotNull", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildIsNotNull(InstructionBuilderHandle @param0, LLVMValueRef @Val, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildPtrDiff", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildPtrDiff(InstructionBuilderHandle @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildFence", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildFence(InstructionBuilderHandle @B, LLVMAtomicOrdering @ordering, LLVMBool @singleThread, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMBuildAtomicRMW", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef BuildAtomicRMW(InstructionBuilderHandle @B, LLVMAtomicRMWBinOp @op, LLVMValueRef @PTR, LLVMValueRef @Val, LLVMAtomicOrdering @ordering, LLVMBool @singleThread); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateModuleProviderForExistingModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMModuleProviderRef CreateModuleProviderForExistingModule(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeModuleProvider", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeModuleProvider(LLVMModuleProviderRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithContentsOfFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool CreateMemoryBufferWithContentsOfFile([MarshalAs(UnmanagedType.LPStr)] string @Path, out LLVMMemoryBufferRef @OutMemBuf, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithSTDIN", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool CreateMemoryBufferWithSTDIN(out LLVMMemoryBufferRef @OutMemBuf, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithMemoryRange", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMemoryBufferRef CreateMemoryBufferWithMemoryRange([MarshalAs(UnmanagedType.LPStr)] string @InputData, int @InputDataLength, [MarshalAs(UnmanagedType.LPStr)] string @BufferName, LLVMBool @RequiresNullTerminator); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithMemoryRangeCopy", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMemoryBufferRef CreateMemoryBufferWithMemoryRangeCopy([MarshalAs(UnmanagedType.LPStr)] string @InputData, int @InputDataLength, [MarshalAs(UnmanagedType.LPStr)] string @BufferName); - - [DllImport(libraryPath, EntryPoint = "LLVMGetBufferStart", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetBufferStart(LLVMMemoryBufferRef @MemBuf); - - [DllImport(libraryPath, EntryPoint = "LLVMGetBufferSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetBufferSize(LLVMMemoryBufferRef @MemBuf); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeMemoryBuffer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeMemoryBuffer(LLVMMemoryBufferRef @MemBuf); - - [DllImport(libraryPath, EntryPoint = "LLVMGetGlobalPassRegistry", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern PassRegistryHandle GetGlobalPassRegistry(); - - [DllImport(libraryPath, EntryPoint = "LLVMCreatePassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMPassManagerRef CreatePassManager(); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateFunctionPassManagerForModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMPassManagerRef CreateFunctionPassManagerForModule(LLVMModuleRef @M); - - [Obsolete( "Use CreateFunctionPassManagerForModule instead", true)] - [DllImport(libraryPath, EntryPoint = "LLVMCreateFunctionPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMPassManagerRef CreateFunctionPassManager(LLVMModuleProviderRef @MP); - - [DllImport(libraryPath, EntryPoint = "LLVMRunPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool RunPassManager(LLVMPassManagerRef @PM, LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeFunctionPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool InitializeFunctionPassManager(LLVMPassManagerRef @FPM); - - [DllImport(libraryPath, EntryPoint = "LLVMRunFunctionPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool RunFunctionPassManager(LLVMPassManagerRef @FPM, LLVMValueRef @F); - - [DllImport(libraryPath, EntryPoint = "LLVMFinalizeFunctionPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool FinalizeFunctionPassManager(LLVMPassManagerRef @FPM); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposePassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposePassManager(LLVMPassManagerRef @PM); - - //[DllImport(libraryPath, EntryPoint = "LLVMStartMultithreaded", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMBool StartMultithreaded(); - - //[DllImport(libraryPath, EntryPoint = "LLVMStopMultithreaded", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void StopMultithreaded(); - - //[DllImport(libraryPath, EntryPoint = "LLVMIsMultithreaded", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMBool IsMultithreaded(); - - [DllImport(libraryPath, EntryPoint = "LLVMVerifyModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool VerifyModule(LLVMModuleRef @M, LLVMVerifierFailureAction @Action, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMVerifyFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool VerifyFunction(LLVMValueRef @Fn, LLVMVerifierFailureAction @Action); - - [DllImport(libraryPath, EntryPoint = "LLVMViewFunctionCFG", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ViewFunctionCFG(LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMViewFunctionCFGOnly", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void ViewFunctionCFGOnly(LLVMValueRef @Fn); - - //[DllImport(libraryPath, EntryPoint = "LLVMParseBitcode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMBool ParseBitcode(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMParseBitcodeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool ParseBitcodeInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMGetBitcodeModuleInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool GetBitcodeModuleInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage); - - //[DllImport(libraryPath, EntryPoint = "LLVMGetBitcodeModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern LLVMBool GetBitcodeModule(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMWriteBitcodeToFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int WriteBitcodeToFile(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Path); - - [DllImport(libraryPath, EntryPoint = "LLVMWriteBitcodeToFD", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int WriteBitcodeToFD(LLVMModuleRef @M, int @FD, int @ShouldClose, int @Unbuffered); - - [DllImport(libraryPath, EntryPoint = "LLVMWriteBitcodeToFileHandle", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int WriteBitcodeToFileHandle(LLVMModuleRef @M, int @Handle); - - [DllImport(libraryPath, EntryPoint = "LLVMWriteBitcodeToMemoryBuffer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMemoryBufferRef WriteBitcodeToMemoryBuffer(LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateDisasm", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDisasmContextRef CreateDisasm([MarshalAs(UnmanagedType.LPStr)] string @TripleName, IntPtr @DisInfo, int @TagType, LLVMOpInfoCallback @GetOpInfo, LLVMSymbolLookupCallback @SymbolLookUp); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateDisasmCPU", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDisasmContextRef CreateDisasmCPU([MarshalAs(UnmanagedType.LPStr)] string @Triple, [MarshalAs(UnmanagedType.LPStr)] string @CPU, IntPtr @DisInfo, int @TagType, LLVMOpInfoCallback @GetOpInfo, LLVMSymbolLookupCallback @SymbolLookUp); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateDisasmCPUFeatures", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDisasmContextRef CreateDisasmCPUFeatures([MarshalAs(UnmanagedType.LPStr)] string @Triple, [MarshalAs(UnmanagedType.LPStr)] string @CPU, [MarshalAs(UnmanagedType.LPStr)] string @Features, IntPtr @DisInfo, int @TagType, LLVMOpInfoCallback @GetOpInfo, LLVMSymbolLookupCallback @SymbolLookUp); - - [DllImport(libraryPath, EntryPoint = "LLVMSetDisasmOptions", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int SetDisasmOptions(LLVMDisasmContextRef @DC, int @Options); - - [DllImport(libraryPath, EntryPoint = "LLVMDisasmDispose", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisasmDispose(LLVMDisasmContextRef @DC); - - [DllImport(libraryPath, EntryPoint = "LLVMDisasmInstruction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int DisasmInstruction(LLVMDisasmContextRef @DC, out char @Bytes, int @BytesSize, int @PC, IntPtr @OutString, int @OutStringSize); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAMDGPUTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAMDGPUTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSystemZTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSystemZTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeHexagonTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeHexagonTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNVPTXTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeNVPTXTargetInfo(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInitializeCppBackendTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void InitializeCppBackendTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMSP430TargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMSP430TargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeXCoreTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeXCoreTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMipsTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMipsTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAArch64TargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAArch64TargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeARMTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeARMTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializePowerPCTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializePowerPCTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSparcTargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSparcTargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeX86TargetInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeX86TargetInfo(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAMDGPUTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAMDGPUTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSystemZTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSystemZTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeHexagonTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeHexagonTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNVPTXTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeNVPTXTarget(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInitializeCppBackendTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void InitializeCppBackendTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMSP430Target", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMSP430Target(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeXCoreTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeXCoreTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMipsTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMipsTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAArch64Target", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAArch64Target(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeARMTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeARMTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializePowerPCTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializePowerPCTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSparcTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSparcTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeX86Target", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeX86Target(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAMDGPUTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAMDGPUTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSystemZTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSystemZTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeHexagonTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeHexagonTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNVPTXTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeNVPTXTargetMC(); - - //[DllImport(libraryPath, EntryPoint = "LLVMInitializeCppBackendTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void InitializeCppBackendTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMSP430TargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMSP430TargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeXCoreTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeXCoreTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMipsTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMipsTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAArch64TargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAArch64TargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeARMTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeARMTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializePowerPCTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializePowerPCTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSparcTargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSparcTargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeX86TargetMC", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeX86TargetMC(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAMDGPUAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAMDGPUAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSystemZAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSystemZAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeHexagonAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeHexagonAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNVPTXAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeNVPTXAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMSP430AsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMSP430AsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeXCoreAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeXCoreAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMipsAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMipsAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAArch64AsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAArch64AsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeARMAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeARMAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializePowerPCAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializePowerPCAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSparcAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSparcAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeX86AsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeX86AsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAMDGPUAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAMDGPUAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSystemZAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSystemZAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMipsAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMipsAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAArch64AsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAArch64AsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeARMAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeARMAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializePowerPCAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializePowerPCAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSparcAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSparcAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeX86AsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeX86AsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSystemZDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSystemZDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeHexagonDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeHexagonDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeXCoreDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeXCoreDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMipsDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMipsDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAArch64Disassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAArch64Disassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeARMDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeARMDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializePowerPCDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializePowerPCDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeSparcDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeSparcDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeX86Disassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeX86Disassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAllTargetInfos", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAllTargetInfos(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAllTargets", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAllTargets(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAllTargetMCs", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAllTargetMCs(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAllAsmPrinters", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAllAsmPrinters(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAllAsmParsers", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAllAsmParsers(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAllDisassemblers", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAllDisassemblers(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNativeTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool InitializeNativeTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNativeAsmParser", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool InitializeNativeAsmParser(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNativeAsmPrinter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool InitializeNativeAsmPrinter(); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeNativeDisassembler", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool InitializeNativeDisassembler(); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateTargetData", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetDataRef CreateTargetData([MarshalAs(UnmanagedType.LPStr)] string @StringRep); - - //[DllImport(libraryPath, EntryPoint = "LLVMAddTargetData", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - //internal static extern void AddTargetData(LLVMTargetDataRef @TD, LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddTargetLibraryInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddTargetLibraryInfo(LLVMTargetLibraryInfoRef @TLI, LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMCopyStringRepOfTargetData", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr CopyStringRepOfTargetData(LLVMTargetDataRef @TD); - - [DllImport(libraryPath, EntryPoint = "LLVMByteOrder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMByteOrdering ByteOrder(LLVMTargetDataRef @TD); - - [DllImport(libraryPath, EntryPoint = "LLVMPointerSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint PointerSize(LLVMTargetDataRef @TD); - - [DllImport( libraryPath, EntryPoint = "LLVMPointerSizeForAS", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern uint PointerSizeForAS( LLVMTargetDataRef @TD, uint @AS ); - - [DllImport( libraryPath, EntryPoint = "LLVMIntPtrType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTypeRef IntPtrType( LLVMTargetDataRef @TD ); - - [DllImport(libraryPath, EntryPoint = "LLVMIntPtrTypeForAS", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef IntPtrTypeForAS(LLVMTargetDataRef @TD, uint @AS); - - [DllImport(libraryPath, EntryPoint = "LLVMIntPtrTypeInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef IntPtrTypeInContext(LLVMContextRef @C, LLVMTargetDataRef @TD); - - [DllImport(libraryPath, EntryPoint = "LLVMIntPtrTypeForASInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTypeRef IntPtrTypeForASInContext(LLVMContextRef @C, LLVMTargetDataRef @TD, uint @AS); - - [DllImport(libraryPath, EntryPoint = "LLVMSizeOfTypeInBits", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern ulong SizeOfTypeInBits(LLVMTargetDataRef @TD, LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMStoreSizeOfType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern ulong StoreSizeOfType(LLVMTargetDataRef @TD, LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMABISizeOfType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern ulong ABISizeOfType(LLVMTargetDataRef @TD, LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMABIAlignmentOfType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint ABIAlignmentOfType(LLVMTargetDataRef @TD, LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMCallFrameAlignmentOfType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint CallFrameAlignmentOfType(LLVMTargetDataRef @TD, LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMPreferredAlignmentOfType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint PreferredAlignmentOfType(LLVMTargetDataRef @TD, LLVMTypeRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMPreferredAlignmentOfGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint PreferredAlignmentOfGlobal(LLVMTargetDataRef @TD, LLVMValueRef @GlobalVar); - - [DllImport(libraryPath, EntryPoint = "LLVMElementAtOffset", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint ElementAtOffset(LLVMTargetDataRef @TD, LLVMTypeRef @StructTy, ulong @Offset); - - [DllImport(libraryPath, EntryPoint = "LLVMOffsetOfElement", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern ulong OffsetOfElement(LLVMTargetDataRef @TD, LLVMTypeRef @StructTy, uint @Element); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeTargetData", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeTargetData(LLVMTargetDataRef @TD); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFirstTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetRef GetFirstTarget(); - - [DllImport(libraryPath, EntryPoint = "LLVMGetNextTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetRef GetNextTarget(LLVMTargetRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetFromName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetRef GetTargetFromName([MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetFromTriple", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool GetTargetFromTriple([MarshalAs(UnmanagedType.LPStr)] string @Triple, out LLVMTargetRef @T, out IntPtr @ErrorMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetTargetName(LLVMTargetRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetDescription", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetTargetDescription(LLVMTargetRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMTargetHasJIT", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool TargetHasJIT(LLVMTargetRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMTargetHasTargetMachine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool TargetHasTargetMachine(LLVMTargetRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMTargetHasAsmBackend", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool TargetHasAsmBackend(LLVMTargetRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateTargetMachine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetMachineRef CreateTargetMachine(LLVMTargetRef @T, [MarshalAs(UnmanagedType.LPStr)] string @Triple, [MarshalAs(UnmanagedType.LPStr)] string @CPU, [MarshalAs(UnmanagedType.LPStr)] string @Features, LLVMCodeGenOptLevel @Level, LLVMRelocMode @Reloc, LLVMCodeModel @CodeModel); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeTargetMachine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeTargetMachine(LLVMTargetMachineRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetMachineTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetRef GetTargetMachineTarget(LLVMTargetMachineRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetMachineTriple", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetTargetMachineTriple(LLVMTargetMachineRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetMachineCPU", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetTargetMachineCPU(LLVMTargetMachineRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMGetTargetMachineFeatureString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetTargetMachineFeatureString(LLVMTargetMachineRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateTargetDataLayout", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetDataRef CreateTargetDataLayout(LLVMTargetMachineRef @T); - - [DllImport(libraryPath, EntryPoint = "LLVMSetTargetMachineAsmVerbosity", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetTargetMachineAsmVerbosity(LLVMTargetMachineRef @T, LLVMBool @VerboseAsm); - - [DllImport(libraryPath, EntryPoint = "LLVMTargetMachineEmitToFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool TargetMachineEmitToFile(LLVMTargetMachineRef @T, LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Filename, LLVMCodeGenFileType @codegen, out IntPtr @ErrorMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMTargetMachineEmitToMemoryBuffer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool TargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef @T, LLVMModuleRef @M, LLVMCodeGenFileType @codegen, out IntPtr @ErrorMessage, out LLVMMemoryBufferRef @OutMemBuf); - - [DllImport(libraryPath, EntryPoint = "LLVMGetDefaultTargetTriple", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetDefaultTargetTriple(); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAnalysisPasses", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddAnalysisPasses(LLVMTargetMachineRef @T, LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMLinkInMCJIT", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void LinkInMCJIT(); - - [DllImport(libraryPath, EntryPoint = "LLVMLinkInInterpreter", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void LinkInInterpreter(); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateGenericValueOfInt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMGenericValueRef CreateGenericValueOfInt(LLVMTypeRef @Ty, ulong @N, LLVMBool @IsSigned); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateGenericValueOfPointer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMGenericValueRef CreateGenericValueOfPointer(IntPtr @P); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateGenericValueOfFloat", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMGenericValueRef CreateGenericValueOfFloat(LLVMTypeRef @Ty, double @N); - - [DllImport(libraryPath, EntryPoint = "LLVMGenericValueIntWidth", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern uint GenericValueIntWidth(LLVMGenericValueRef @GenValRef); - - [DllImport(libraryPath, EntryPoint = "LLVMGenericValueToInt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern ulong GenericValueToInt(LLVMGenericValueRef @GenVal, LLVMBool @IsSigned); - - [DllImport(libraryPath, EntryPoint = "LLVMGenericValueToPointer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GenericValueToPointer(LLVMGenericValueRef @GenVal); - - [DllImport(libraryPath, EntryPoint = "LLVMGenericValueToFloat", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern double GenericValueToFloat(LLVMTypeRef @TyRef, LLVMGenericValueRef @GenVal); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeGenericValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeGenericValue(LLVMGenericValueRef @GenVal); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateExecutionEngineForModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool CreateExecutionEngineForModule(out LLVMExecutionEngineRef @OutEE, LLVMModuleRef @M, out IntPtr @OutError); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateInterpreterForModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool CreateInterpreterForModule(out LLVMExecutionEngineRef @OutInterp, LLVMModuleRef @M, out IntPtr @OutError); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateJITCompilerForModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool CreateJITCompilerForModule(out LLVMExecutionEngineRef @OutJIT, LLVMModuleRef @M, uint @OptLevel, out IntPtr @OutError); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeMCJITCompilerOptions", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeMCJITCompilerOptions(out LLVMMCJITCompilerOptions @Options, int @SizeOfOptions); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateMCJITCompilerForModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool CreateMCJITCompilerForModule(out LLVMExecutionEngineRef @OutJIT, LLVMModuleRef @M, out LLVMMCJITCompilerOptions @Options, int @SizeOfOptions, out IntPtr @OutError); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeExecutionEngine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeExecutionEngine(LLVMExecutionEngineRef @EE); - - [DllImport(libraryPath, EntryPoint = "LLVMRunStaticConstructors", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void RunStaticConstructors(LLVMExecutionEngineRef @EE); - - [DllImport(libraryPath, EntryPoint = "LLVMRunStaticDestructors", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void RunStaticDestructors(LLVMExecutionEngineRef @EE); - - [DllImport(libraryPath, EntryPoint = "LLVMRunFunctionAsMain", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int RunFunctionAsMain(LLVMExecutionEngineRef @EE, LLVMValueRef @F, uint @ArgC, string[] @ArgV, string[] @EnvP); - - [DllImport(libraryPath, EntryPoint = "LLVMRunFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMGenericValueRef RunFunction(LLVMExecutionEngineRef @EE, LLVMValueRef @F, uint @NumArgs, out LLVMGenericValueRef @Args); - - [DllImport(libraryPath, EntryPoint = "LLVMFreeMachineCodeForFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void FreeMachineCodeForFunction(LLVMExecutionEngineRef @EE, LLVMValueRef @F); - - [DllImport(libraryPath, EntryPoint = "LLVMAddModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddModule(LLVMExecutionEngineRef @EE, LLVMModuleRef @M); - - [DllImport(libraryPath, EntryPoint = "LLVMRemoveModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool RemoveModule(LLVMExecutionEngineRef @EE, LLVMModuleRef @M, out LLVMModuleRef @OutMod, out IntPtr @OutError); - - [DllImport(libraryPath, EntryPoint = "LLVMFindFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool FindFunction(LLVMExecutionEngineRef @EE, [MarshalAs(UnmanagedType.LPStr)] string @Name, out LLVMValueRef @OutFn); - - [DllImport(libraryPath, EntryPoint = "LLVMRecompileAndRelinkFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr RecompileAndRelinkFunction(LLVMExecutionEngineRef @EE, LLVMValueRef @Fn); - - [DllImport(libraryPath, EntryPoint = "LLVMGetExecutionEngineTargetData", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetDataRef GetExecutionEngineTargetData(LLVMExecutionEngineRef @EE); - - [DllImport(libraryPath, EntryPoint = "LLVMGetExecutionEngineTargetMachine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMTargetMachineRef GetExecutionEngineTargetMachine(LLVMExecutionEngineRef @EE); - - [DllImport(libraryPath, EntryPoint = "LLVMAddGlobalMapping", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddGlobalMapping(LLVMExecutionEngineRef @EE, LLVMValueRef @Global, IntPtr @Addr); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPointerToGlobal", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetPointerToGlobal(LLVMExecutionEngineRef @EE, LLVMValueRef @Global); - - [DllImport(libraryPath, EntryPoint = "LLVMGetGlobalValueAddress", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetGlobalValueAddress(LLVMExecutionEngineRef @EE, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMGetFunctionAddress", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetFunctionAddress(LLVMExecutionEngineRef @EE, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateSimpleMCJITMemoryManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMCJITMemoryManagerRef CreateSimpleMCJITMemoryManager(IntPtr @Opaque, LLVMMemoryManagerAllocateCodeSectionCallback @AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback @AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback @FinalizeMemory, LLVMMemoryManagerDestroyCallback @Destroy); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeMCJITMemoryManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef @MM); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeTransformUtils", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeTransformUtils(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeScalarOpts", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeScalarOpts(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeObjCARCOpts", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeObjCARCOpts(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeVectorization", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeVectorization(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeInstCombine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeInstCombine(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeIPO", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeIPO(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeInstrumentation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeInstrumentation(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeAnalysis", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeAnalysis(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeIPA", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeIPA(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeCodeGen", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeCodeGen(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMInitializeTarget", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void InitializeTarget(PassRegistryHandle @R); - - [DllImport(libraryPath, EntryPoint = "LLVMParseIRInContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool ParseIRInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage); - - [DllImport(libraryPath, EntryPoint = "LLVMLinkModules2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool LinkModules(LLVMModuleRef @Dest, LLVMModuleRef @Src ); - - [DllImport(libraryPath, EntryPoint = "LLVMCreateObjectFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMObjectFileRef CreateObjectFile(LLVMMemoryBufferRef @MemBuf); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeObjectFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeObjectFile(LLVMObjectFileRef @ObjectFile); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSections", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMSectionIteratorRef GetSections(LLVMObjectFileRef @ObjectFile); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeSectionIterator", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeSectionIterator(LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMIsSectionIteratorAtEnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsSectionIteratorAtEnd(LLVMObjectFileRef @ObjectFile, LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMMoveToNextSection", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MoveToNextSection(LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMMoveToContainingSection", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MoveToContainingSection(LLVMSectionIteratorRef @Sect, LLVMSymbolIteratorRef @Sym); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSymbols", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMSymbolIteratorRef GetSymbols(LLVMObjectFileRef @ObjectFile); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeSymbolIterator", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeSymbolIterator(LLVMSymbolIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMIsSymbolIteratorAtEnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsSymbolIteratorAtEnd(LLVMObjectFileRef @ObjectFile, LLVMSymbolIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMMoveToNextSymbol", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MoveToNextSymbol(LLVMSymbolIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSectionName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetSectionName(LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSectionSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetSectionSize(LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSectionContents", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetSectionContents(LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSectionAddress", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetSectionAddress(LLVMSectionIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSectionContainsSymbol", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool GetSectionContainsSymbol(LLVMSectionIteratorRef @SI, LLVMSymbolIteratorRef @Sym); - - [DllImport(libraryPath, EntryPoint = "LLVMGetRelocations", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMRelocationIteratorRef GetRelocations(LLVMSectionIteratorRef @Section); - - [DllImport(libraryPath, EntryPoint = "LLVMDisposeRelocationIterator", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DisposeRelocationIterator(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMIsRelocationIteratorAtEnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsRelocationIteratorAtEnd(LLVMSectionIteratorRef @Section, LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMMoveToNextRelocation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MoveToNextRelocation(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSymbolName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetSymbolName(LLVMSymbolIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSymbolAddress", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetSymbolAddress(LLVMSymbolIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetSymbolSize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetSymbolSize(LLVMSymbolIteratorRef @SI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetRelocationOffset", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetRelocationOffset(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetRelocationSymbol", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMSymbolIteratorRef GetRelocationSymbol(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetRelocationType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int GetRelocationType(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetRelocationTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetRelocationTypeName(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMGetRelocationValueString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetRelocationValueString(LLVMRelocationIteratorRef @RI); - - [DllImport(libraryPath, EntryPoint = "LLVMAddArgumentPromotionPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddArgumentPromotionPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddConstantMergePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddConstantMergePass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddDeadArgEliminationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddDeadArgEliminationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddFunctionAttrsPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddFunctionAttrsPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddFunctionInliningPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddFunctionInliningPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAlwaysInlinerPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddAlwaysInlinerPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddGlobalDCEPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddGlobalDCEPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddGlobalOptimizerPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddGlobalOptimizerPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddIPConstantPropagationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddIPConstantPropagationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddPruneEHPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddPruneEHPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddIPSCCPPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddIPSCCPPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddInternalizePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddInternalizePass(LLVMPassManagerRef @param0, uint @AllButMain); - - [DllImport(libraryPath, EntryPoint = "LLVMAddStripDeadPrototypesPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddStripDeadPrototypesPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddStripSymbolsPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddStripSymbolsPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderCreate", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMPassManagerBuilderRef PassManagerBuilderCreate(); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderDispose", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderDispose(LLVMPassManagerBuilderRef @PMB); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderSetOptLevel", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef @PMB, uint @OptLevel); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderSetSizeLevel", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef @PMB, uint @SizeLevel); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderSetDisableUnitAtATime", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef @PMB, LLVMBool @Value); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderSetDisableUnrollLoops", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef @PMB, LLVMBool @Value); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderSetDisableSimplifyLibCalls", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef @PMB, LLVMBool @Value); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderUseInlinerWithThreshold", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef @PMB, uint @Threshold); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderPopulateFunctionPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef @PMB, LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderPopulateModulePassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef @PMB, LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMPassManagerBuilderPopulateLTOPassManager", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void PassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef @PMB, LLVMPassManagerRef @PM, LLVMBool @Internalize, LLVMBool @RunInliner); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAggressiveDCEPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddAggressiveDCEPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAlignmentFromAssumptionsPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddAlignmentFromAssumptionsPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddCFGSimplificationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddCFGSimplificationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddDeadStoreEliminationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddDeadStoreEliminationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddScalarizerPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddScalarizerPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddMergedLoadStoreMotionPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddMergedLoadStoreMotionPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddGVNPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddGVNPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddIndVarSimplifyPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddIndVarSimplifyPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddInstructionCombiningPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddInstructionCombiningPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddJumpThreadingPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddJumpThreadingPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLICMPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLICMPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopDeletionPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopDeletionPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopIdiomPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopIdiomPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopRotatePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopRotatePass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopRerollPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopRerollPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopUnrollPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopUnrollPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopUnswitchPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopUnswitchPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddMemCpyOptPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddMemCpyOptPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddPartiallyInlineLibCallsPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddPartiallyInlineLibCallsPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLowerSwitchPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLowerSwitchPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddPromoteMemoryToRegisterPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddPromoteMemoryToRegisterPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddReassociatePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddReassociatePass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddSCCPPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddSCCPPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddScalarReplAggregatesPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddScalarReplAggregatesPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddScalarReplAggregatesPassSSA", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddScalarReplAggregatesPassSSA(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddScalarReplAggregatesPassWithThreshold", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef @PM, int @Threshold); - - [DllImport(libraryPath, EntryPoint = "LLVMAddSimplifyLibCallsPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddSimplifyLibCallsPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddTailCallEliminationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddTailCallEliminationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddConstantPropagationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddConstantPropagationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddDemoteMemoryToRegisterPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddDemoteMemoryToRegisterPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddVerifierPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddVerifierPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddCorrelatedValuePropagationPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddCorrelatedValuePropagationPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddEarlyCSEPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddEarlyCSEPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLowerExpectIntrinsicPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLowerExpectIntrinsicPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddTypeBasedAliasAnalysisPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddTypeBasedAliasAnalysisPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddScopedNoAliasAAPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddScopedNoAliasAAPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddBasicAliasAnalysisPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddBasicAliasAnalysisPass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddBBVectorizePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddBBVectorizePass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddLoopVectorizePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddLoopVectorizePass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMAddSLPVectorizePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddSLPVectorizePass(LLVMPassManagerRef @PM); - - [DllImport(libraryPath, EntryPoint = "LLVMGetPersonalityFn", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetPersonalityFunction(LLVMValueRef function); - - [DllImport(libraryPath, EntryPoint = "LLVMSetPersonalityFn", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetPersonalityFunction(LLVMValueRef function, LLVMValueRef personalityFunction); - } -} diff --git a/src/Llvm.NET/LLVM/GeneratedExtensions.cs b/src/Llvm.NET/LLVM/GeneratedExtensions.cs deleted file mode 100644 index 31743767c..000000000 --- a/src/Llvm.NET/LLVM/GeneratedExtensions.cs +++ /dev/null @@ -1,1070 +0,0 @@ -// This file was generated from LLVMLib.3.6.1 Extended API using ClangSharp P/Invoke generator -// it was further modified in the following ways: -// - removed most uses of the partial keyword except for LLVMNative static class -// - added warning disable to avoid benign compiler warnings about fields only set by native code -// - modified all elements to be internal instead of public -// - modified PInvoke attributes to use fully qualified name for CallingConvention to avoid conflicts -// - removed C++ function unwrap() -// - removed DEFINE_ISA_CONVERSION_FUNCTIONS which was erroneously mis-identified as a function -// declaration rather than a preprocessor macro instantiation -// - converted several int return and parameter types to proper LLVMxxxRef types not handled correctly -// by the ClangSharp code generator -// - numerous additional extension methods added manually. (e.g. as new APIs are added they are done so -// manually rather than re-running a tool and then fixing everything up again ) -// - manually updated to 3.7.0 APIs -// - added BestFitMapping = false, ThrowOnUnmappableChar = true to resolve FxCop issue CA2101 -using System; -using System.Runtime.InteropServices; - -namespace Llvm.NET.Native -{ - internal partial struct LLVMMetadataRef - { - internal LLVMMetadataRef(IntPtr pointer) - { - Pointer = pointer; - } - - internal readonly IntPtr Pointer; - } - - internal partial struct LLVMDIBuilderRef - { - internal LLVMDIBuilderRef(IntPtr pointer) - { - Pointer = pointer; - } - - internal readonly IntPtr Pointer; - } - - internal partial struct LLVMMDOperandRef - { - internal LLVMMDOperandRef(IntPtr pointer) - { - Pointer = pointer; - } - - internal readonly IntPtr Pointer; - } - - internal partial struct LLVMNamedMDNodeRef - { - internal LLVMNamedMDNodeRef(IntPtr pointer) - { - Pointer = pointer; - } - - internal readonly IntPtr Pointer; - } - - internal partial struct LLVMComdatRef - { - internal LLVMComdatRef( IntPtr pointer ) - { - Pointer = pointer; - } - - internal readonly IntPtr Pointer; - } - - internal partial struct LLVMVersionInfo - { - internal readonly int Major; - internal readonly int Minor; - internal readonly int Patch; - readonly IntPtr VersionString; - } - - internal enum LLVMModFlagBehavior - { - @Error = 1, - @Warning = 2, - @Require = 3, - @Override = 4, - @Append = 5, - @AppendUnique = 6, - @ModFlagBehaviorFirstVal = Error, - @ModFlagBehaviorLastVal = AppendUnique - } - - internal enum LLVMValueKind - { - LLVMArgumentValueKind, - LLVMBasicBlockValueKind, - LLVMMemoryUseValueKind, - LLVMMemoryDefValueKind, - LLVMMemoryPhiValueKind, - - LLVMFunctionValueKind, - LLVMGlobalAliasValueKind, - LLVMGlobalIFuncValueKind, - LLVMGlobalVariableValueKind, - LLVMBlockAddressValueKind, - LLVMConstantExprValueKind, - LLVMConstantArrayValueKind, - LLVMConstantStructValueKind, - LLVMConstantVectorValueKind, - - LLVMUndefValueValueKind, - LLVMConstantAggregateZeroValueKind, - LLVMConstantDataArrayValueKind, - LLVMConstantDataVectorValueKind, - LLVMConstantIntValueKind, - LLVMConstantFPValueKind, - LLVMConstantPointerNullValueKind, - LLVMConstantTokenNoneValueKind, - - LLVMMetadataAsValueValueKind, - LLVMInlineAsmValueKind, - - LLVMInstructionValueKind, - } - - enum LLVMDwarfTag : ushort - { - LLVMDwarfTagArrayType = 0x01, - LLVMDwarfTagClassType = 0x02, - LLVMDwarfTagEntryPoint = 0x03, - LLVMDwarfTagEnumerationType = 0x04, - LLVMDwarfTagFormalParameter = 0x05, - LLVMDwarfTagImportedDeclaration = 0x08, - LLVMDwarfTagLabel = 0x0a, - LLVMDwarfTagLexicalBlock = 0x0b, - LLVMDwarfTagMember = 0x0d, - LLVMDwarfTagPointerType = 0x0f, - LLVMDwarfTagReferenceType = 0x10, - LLVMDwarfTagCompileUnit = 0x11, - LLVMDwarfTagStringType = 0x12, - LLVMDwarfTagStructureType = 0x13, - LLVMDwarfTagSubroutineType = 0x15, - LLVMDwarfTagTypeDef = 0x16, - LLVMDwarfTagUnionType = 0x17, - LLVMDwarfTagUnspecifiedParameters = 0x18, - LLVMDwarfTagVariant = 0x19, - LLVMDwarfTagCommonBlock = 0x1a, - LLVMDwarfTagCommonInclusion = 0x1b, - LLVMDwarfTagInheritance = 0x1c, - LLVMDwarfTagInlinedSubroutine = 0x1d, - LLVMDwarfTagModule = 0x1e, - LLVMDwarfTagPtrToMemberType = 0x1f, - LLVMDwarfTagSetType = 0x20, - LLVMDwarfTagSubrangeType = 0x21, - LLVMDwarfTagWithStatement = 0x22, - LLVMDwarfTagAccessDeclaration = 0x23, - LLVMDwarfTagBaseType = 0x24, - LLVMDwarfTagCatchBlock = 0x25, - LLVMDwarfTagConstType = 0x26, - LLVMDwarfTagConstant = 0x27, - LLVMDwarfTagEnumerator = 0x28, - LLVMDwarfTagFileType = 0x29, - LLVMDwarfTagFriend = 0x2a, - LLVMDwarfTagNameList = 0x2b, - LLVMDwarfTagNameListItem = 0x2c, - LLVMDwarfTagPackedType = 0x2d, - LLVMDwarfTagSubProgram = 0x2e, - LLVMDwarfTagTemplateTypeParameter = 0x2f, - LLVMDwarfTagTemplateValueParameter = 0x30, - LLVMDwarfTagThrownType = 0x31, - LLVMDwarfTagTryBlock = 0x32, - LLVMDwarfTagVariantPart = 0x33, - LLVMDwarfTagVariable = 0x34, - LLVMDwarfTagVolatileType = 0x35, - LLVMDwarfTagDwarfProcedure = 0x36, - LLVMDwarfTagRestrictType = 0x37, - LLVMDwarfTagInterfaceType = 0x38, - LLVMDwarfTagNamespace = 0x39, - LLVMDwarfTagImportedModule = 0x3a, - LLVMDwarfTagUnspecifiedType = 0x3b, - LLVMDwarfTagPartialUnit = 0x3c, - LLVMDwarfTagImportedUnit = 0x3d, - LLVMDwarfTagCondition = 0x3f, - LLVMDwarfTagSharedType = 0x40, - LLVMDwarfTagTypeUnit = 0x41, - LLVMDwarfTagRValueReferenceType = 0x42, - LLVMDwarfTagTemplateAlias = 0x43, - - // New in DWARF 5: - LLVMDwarfTagCoArrayType = 0x44, - LLVMDwarfTagGenericSubrange = 0x45, - LLVMDwarfTagDynamicType = 0x46, - - LLVMDwarfTagMipsLoop = 0x4081, - LLVMDwarfTagFormatLabel = 0x4101, - LLVMDwarfTagFunctionTemplate = 0x4102, - LLVMDwarfTagClassTemplate = 0x4103, - LLVMDwarfTagGnuTemplateTemplateParam = 0x4106, - LLVMDwarfTagGnuTemplateParameterPack = 0x4107, - LLVMDwarfTagGnuFormalParameterPack = 0x4108, - LLVMDwarfTagLoUser = 0x4080, - LLVMDwarfTagAppleProperty = 0x4200, - LLVMDwarfTagHiUser = 0xffff - }; - - // values and ordering extracted from LLVM's Attributes.inc - // which is used to construct the Attribute::AttributeKind enumeration - internal enum LLVMAttrKind - { - None, - Alignment, - AllocSize, - AlwaysInline, - ArgMemOnly, - Builtin, - ByVal, - Cold, - Convergent, - Dereferenceable, - DereferenceableOrNull, - InAlloca, - InReg, - InaccessibleMemOnly, - InaccessibleMemOrArgMemOnly, - InlineHint, - JumpTable, - MinSize, - Naked, - Nest, - NoAlias, - NoBuiltin, - NoCapture, - NoDuplicate, - NoImplicitFloat, - NoInline, - NoRecurse, - NoRedZone, - NoReturn, - NoUnwind, - NonLazyBind, - NonNull, - OptimizeForSize, - OptimizeNone, - ReadNone, - ReadOnly, - Returned, - ReturnsTwice, - SExt, - SafeStack, - SanitizeAddress, - SanitizeMemory, - SanitizeThread, - StackAlignment, - StackProtect, - StackProtectReq, - StackProtectStrong, - StructRet, - SwiftError, - SwiftSelf, - UWTable, - ZExt, - }; - - internal enum LLVMMetadataKind - { - LLVMMetadaKindMDTuple, - LLVMMetadaKindDILocation, - LLVMMetadaKindGenericDINode, - LLVMMetadaKindDISubrange, - LLVMMetadaKindDIEnumerator, - LLVMMetadaKindDIBasicType, - LLVMMetadaKindDIDerivedType, - LLVMMetadaKindDICompositeType, - LLVMMetadaKindDISubroutineType, - LLVMMetadaKindDIFile, - LLVMMetadaKindDICompileUnit, - LLVMMetadaKindDISubprogram, - LLVMMetadaKindDILexicalBlock, - LLVMMetadaKindDILexicalBlockFile, - LLVMMetadaKindDINamespace, - LLVMMetadaKindDIModule, - LLVMMetadaKindDITemplateTypeParameter, - LLVMMetadaKindDITemplateValueParameter, - LLVMMetadaKindDIGlobalVariable, - LLVMMetadaKindDILocalVariable, - LLVMMetadaKindDIExpression, - LLVMMetadaKindDIObjCProperty, - LLVMMetadaKindDIImportedEntity, - LLVMMetadaKindConstantAsMetadata, - LLVMMetadaKindLocalAsMetadata, - LLVMMetadaKindMDString - }; - - internal enum LLVMOptVerifierKind - { - LLVMOptVerifierKindNone, - LLVMOptVerifierKindVerifyInAndOut, - LLVMOptVerifierKindVerifyEachPass - }; - - enum LLVMTripleArchType - { - LlvmTripleArchType_UnknownArch, - LlvmTripleArchType_arm, // ARM (little endian): arm, armv.*, xscale - LlvmTripleArchType_armeb, // ARM (big endian): armeb - LlvmTripleArchType_aarch64, // AArch64 (little endian): aarch64 - LlvmTripleArchType_aarch64_be, // AArch64 (big endian): aarch64_be - LlvmTripleArchType_avr, // AVR: Atmel AVR microcontroller - LlvmTripleArchType_bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) - LlvmTripleArchType_bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) - LlvmTripleArchType_hexagon, // Hexagon: hexagon - LlvmTripleArchType_mips, // MIPS: mips, mipsallegrex - LlvmTripleArchType_mipsel, // MIPSEL: mipsel, mipsallegrexel - LlvmTripleArchType_mips64, // MIPS64: mips64 - LlvmTripleArchType_mips64el, // MIPS64EL: mips64el - LlvmTripleArchType_msp430, // MSP430: msp430 - LlvmTripleArchType_ppc, // PPC: powerpc - LlvmTripleArchType_ppc64, // PPC64: powerpc64, ppu - LlvmTripleArchType_ppc64le, // PPC64LE: powerpc64le - LlvmTripleArchType_r600, // R600: AMD GPUs HD2XXX - HD6XXX - LlvmTripleArchType_amdgcn, // AMDGCN: AMD GCN GPUs - LlvmTripleArchType_sparc, // Sparc: sparc - LlvmTripleArchType_sparcv9, // Sparcv9: Sparcv9 - LlvmTripleArchType_sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant - LlvmTripleArchType_systemz, // SystemZ: s390x - LlvmTripleArchType_tce, // TCE (http://tce.cs.tut.fi/): tce - LlvmTripleArchType_thumb, // Thumb (little endian): thumb, thumbv.* - LlvmTripleArchType_thumbeb, // Thumb (big endian): thumbeb - LlvmTripleArchType_x86, // X86: i[3-9]86 - LlvmTripleArchType_x86_64, // X86-64: amd64, x86_64 - LlvmTripleArchType_xcore, // XCore: xcore - LlvmTripleArchType_nvptx, // NVPTX: 32-bit - LlvmTripleArchType_nvptx64, // NVPTX: 64-bit - LlvmTripleArchType_le32, // le32: generic little-endian 32-bit CPU (PNaCl) - LlvmTripleArchType_le64, // le64: generic little-endian 64-bit CPU (PNaCl) - LlvmTripleArchType_amdil, // AMDIL - LlvmTripleArchType_amdil64, // AMDIL with 64-bit pointers - LlvmTripleArchType_hsail, // AMD HSAIL - LlvmTripleArchType_hsail64, // AMD HSAIL with 64-bit pointers - LlvmTripleArchType_spir, // SPIR: standard portable IR for OpenCL 32-bit version - LlvmTripleArchType_spir64, // SPIR: standard portable IR for OpenCL 64-bit version - LlvmTripleArchType_kalimba, // Kalimba: generic kalimba - LlvmTripleArchType_shave, // SHAVE: Movidius vector VLIW processors - LlvmTripleArchType_lanai, // Lanai: Lanai 32-bit - LlvmTripleArchType_wasm32, // WebAssembly with 32-bit pointers - LlvmTripleArchType_wasm64, // WebAssembly with 64-bit pointers - LlvmTripleArchType_renderscript32, // 32-bit RenderScript - LlvmTripleArchType_renderscript64, // 64-bit RenderScript - LlvmTripleArchType_LastArchType = LlvmTripleArchType_renderscript64 - }; - - enum LLVMTripleSubArchType - { - LlvmTripleSubArchType_NoSubArch, - LlvmTripleSubArchType_ARMSubArch_v8_2a, - LlvmTripleSubArchType_ARMSubArch_v8_1a, - LlvmTripleSubArchType_ARMSubArch_v8, - LlvmTripleSubArchType_ARMSubArch_v8m_baseline, - LlvmTripleSubArchType_ARMSubArch_v8m_mainline, - LlvmTripleSubArchType_ARMSubArch_v7, - LlvmTripleSubArchType_ARMSubArch_v7em, - LlvmTripleSubArchType_ARMSubArch_v7m, - LlvmTripleSubArchType_ARMSubArch_v7s, - LlvmTripleSubArchType_ARMSubArch_v7k, - LlvmTripleSubArchType_ARMSubArch_v6, - LlvmTripleSubArchType_ARMSubArch_v6m, - LlvmTripleSubArchType_ARMSubArch_v6k, - LlvmTripleSubArchType_ARMSubArch_v6t2, - LlvmTripleSubArchType_ARMSubArch_v5, - LlvmTripleSubArchType_ARMSubArch_v5te, - LlvmTripleSubArchType_ARMSubArch_v4t, - LlvmTripleSubArchType_KalimbaSubArch_v3, - LlvmTripleSubArchType_KalimbaSubArch_v4, - LlvmTripleSubArchType_KalimbaSubArch_v5 - }; - - enum LLVMTripleVendorType - { - LlvmTripleVendorType_UnknownVendor, - LlvmTripleVendorType_Apple, - LlvmTripleVendorType_PC, - LlvmTripleVendorType_SCEI, - LlvmTripleVendorType_BGP, - LlvmTripleVendorType_BGQ, - LlvmTripleVendorType_Freescale, - LlvmTripleVendorType_IBM, - LlvmTripleVendorType_ImaginationTechnologies, - LlvmTripleVendorType_MipsTechnologies, - LlvmTripleVendorType_NVIDIA, - LlvmTripleVendorType_CSR, - LlvmTripleVendorType_Myriad, - LlvmTripleVendorType_AMD, - LlvmTripleVendorType_Mesa, - LlvmTripleVendorType_LastVendorType = LlvmTripleVendorType_Mesa - }; - - enum LLVMTripleOSType - { - LlvmTripleOSType_UnknownOS, - LlvmTripleOSType_CloudABI, - LlvmTripleOSType_Darwin, - LlvmTripleOSType_DragonFly, - LlvmTripleOSType_FreeBSD, - LlvmTripleOSType_IOS, - LlvmTripleOSType_KFreeBSD, - LlvmTripleOSType_Linux, - LlvmTripleOSType_Lv2, // PS3 - LlvmTripleOSType_MacOSX, - LlvmTripleOSType_NetBSD, - LlvmTripleOSType_OpenBSD, - LlvmTripleOSType_Solaris, - LlvmTripleOSType_Win32, - LlvmTripleOSType_Haiku, - LlvmTripleOSType_Minix, - LlvmTripleOSType_RTEMS, - LlvmTripleOSType_NaCl, // Native Client - LlvmTripleOSType_CNK, // BG/P Compute-Node Kernel - LlvmTripleOSType_Bitrig, - LlvmTripleOSType_AIX, - LlvmTripleOSType_CUDA, // NVIDIA CUDA - LlvmTripleOSType_NVCL, // NVIDIA OpenCL - LlvmTripleOSType_AMDHSA, // AMD HSA Runtime - LlvmTripleOSType_PS4, - LlvmTripleOSType_ELFIAMCU, - LlvmTripleOSType_TvOS, // Apple tvOS - LlvmTripleOSType_WatchOS, // Apple watchOS - LlvmTripleOSType_Mesa3D, - LlvmTripleOSType_LastOSType = LlvmTripleOSType_Mesa3D - }; - - enum LLVMTripleEnvironmentType - { - LlvmTripleEnvironmentType_UnknownEnvironment, - LlvmTripleEnvironmentType_GNU, - LlvmTripleEnvironmentType_GNUABI64, - LlvmTripleEnvironmentType_GNUEABI, - LlvmTripleEnvironmentType_GNUEABIHF, - LlvmTripleEnvironmentType_GNUX32, - LlvmTripleEnvironmentType_CODE16, - LlvmTripleEnvironmentType_EABI, - LlvmTripleEnvironmentType_EABIHF, - LlvmTripleEnvironmentType_Android, - LlvmTripleEnvironmentType_Musl, - LlvmTripleEnvironmentType_MuslEABI, - LlvmTripleEnvironmentType_MuslEABIHF, - LlvmTripleEnvironmentType_MSVC, - LlvmTripleEnvironmentType_Itanium, - LlvmTripleEnvironmentType_Cygnus, - LlvmTripleEnvironmentType_AMDOpenCL, - LlvmTripleEnvironmentType_CoreCLR, - LlvmTripleEnvironmentType_LastEnvironmentType = LlvmTripleEnvironmentType_CoreCLR - }; - - enum LLVMTripleObjectFormatType - { - LlvmTripleObjectFormatType_UnknownObjectFormat, - LlvmTripleObjectFormatType_COFF, - LlvmTripleObjectFormatType_ELF, - LlvmTripleObjectFormatType_MachO, - }; - - enum LLVMComdatSelectionKind - { - COMDAT_ANY, - COMDAT_EXACTMATCH, - COMDAT_LARGEST, - COMDAT_NODUPLICATES, - COMDAT_SAMESIZE - }; - - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling" )] - internal static partial class NativeMethods - { - [DllImport(libraryPath, EntryPoint = "LLVMGetVersionInfo", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern void GetVersionInfo(ref LLVMVersionInfo pVersionInfo); - - [DllImport( libraryPath, EntryPoint = "LLVMGetValueID", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern int GetValueID( LLVMValueRef @val ); - - [ DllImport( libraryPath, EntryPoint = "LLVMBuildIntCast2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern LLVMValueRef BuildIntCast( InstructionBuilderHandle @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, LLVMBool isSigned, [MarshalAs( UnmanagedType.LPStr )] string @Name ); - - [DllImport( libraryPath, EntryPoint = "LLVMSetDebugLoc", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetDebugLoc( LLVMValueRef inst, uint line, uint column, LLVMMetadataRef scope ); - - [DllImport( libraryPath, EntryPoint = "LLVMSetDILocation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void SetDILocation( LLVMValueRef inst, LLVMMetadataRef location ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationScope", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataRef /*DILocalScope*/ GetDILocationScope( LLVMMetadataRef /*DILocation*/ location ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationLine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt32 GetDILocationLine( LLVMMetadataRef /*DILocation*/ location ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationColumn", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt32 GetDILocationColumn( LLVMMetadataRef /*DILocation*/ location ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationInlinedAt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataRef /*DILocation*/ GetDILocationInlinedAt( LLVMMetadataRef /*DILocation*/ location ); - - [DllImport( libraryPath, EntryPoint = "LLVMDILocationGetInlinedAtScope", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataRef /*DILocalScope*/ DILocationGetInlinedAtScope( LLVMMetadataRef /*DILocation*/ location ); - - [DllImport(libraryPath, EntryPoint = "LLVMVerifyFunctionEx", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool VerifyFunctionEx(LLVMValueRef @Fn, LLVMVerifierFailureAction @Action, out IntPtr @OutMessages); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAddressSanitizerFunctionPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddAddressSanitizerFunctionPass( LLVMPassManagerRef @PM ); - - [DllImport(libraryPath, EntryPoint = "LLVMAddAddressSanitizerModulePass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddAddressSanitizerModulePass( LLVMPassManagerRef @PM ); - - [DllImport(libraryPath, EntryPoint = "LLVMAddThreadSanitizerPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddThreadSanitizerPass( LLVMPassManagerRef @PM ); - - [DllImport(libraryPath, EntryPoint = "LLVMAddMemorySanitizerPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddMemorySanitizerPass( LLVMPassManagerRef @PM ); - - [DllImport(libraryPath, EntryPoint = "LLVMAddDataFlowSanitizerPass", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddDataFlowSanitizerPass( LLVMPassManagerRef @PM, [MarshalAs(UnmanagedType.LPStr)] string @ABIListFile); - - [DllImport(libraryPath, EntryPoint = "LLVMAddModuleFlag", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddModuleFlag(LLVMModuleRef @M, LLVMModFlagBehavior behavior, [MarshalAs(UnmanagedType.LPStr)] string @name, uint @value); - - [DllImport( libraryPath, EntryPoint = "LLVMAddModuleFlagMetadata", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AddModuleFlag( LLVMModuleRef @M, LLVMModFlagBehavior behavior, [MarshalAs( UnmanagedType.LPStr )] string @name, LLVMMetadataRef @value ); - - [DllImport(libraryPath, EntryPoint = "LLVMModuleGetModuleFlagsMetadata", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMNamedMDNodeRef ModuleGetModuleFlagsMetadata( LLVMModuleRef module ); - - [DllImport(libraryPath, EntryPoint = "LLVMNamedMDNodeGetNumOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern UInt32 NamedMDNodeGetNumOperands( LLVMNamedMDNodeRef namedMDNode ); - - [DllImport(libraryPath, EntryPoint = "LLVMNamedMDNodeGetOperand", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern /*MDNode*/ LLVMMetadataRef NamedMDNodeGetOperand( LLVMNamedMDNodeRef namedMDNode, UInt32 index ); - - [DllImport(libraryPath, EntryPoint = "LLVMNamedMDNodeGetParentModule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMModuleRef NamedMDNodeGetParentModule( LLVMNamedMDNodeRef namedMDNode ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetOrInsertFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetOrInsertFunction( LLVMModuleRef module, [MarshalAs( UnmanagedType.LPStr )] string @name, LLVMTypeRef functionType ); - - [DllImport(libraryPath, EntryPoint = "LLVMIsConstantZeroValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsConstantZeroValue( LLVMValueRef @Val ); - - [DllImport( libraryPath, EntryPoint = "LLVMRemoveGlobalFromParent", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void RemoveGlobalFromParent( LLVMValueRef @Val ); - - [DllImport(libraryPath, EntryPoint = "LLVMConstantAsMetadata", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef ConstantAsMetadata( LLVMValueRef @Val ); - - [DllImport(libraryPath, EntryPoint = "LLVMMDString2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef MDString2(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Str, uint @SLen); - - [DllImport(libraryPath, EntryPoint = "LLVMMDNode2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef MDNode2( LLVMContextRef @C, out LLVMMetadataRef @MDs, uint @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMTemporaryMDNode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef TemporaryMDNode( LLVMContextRef @C, out LLVMMetadataRef @MDs, uint @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMAddNamedMetadataOperand2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void AddNamedMetadataOperand2( LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name, LLVMMetadataRef @Val); - - [DllImport(libraryPath, EntryPoint = "LLVMSetMetadata2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetMetadata2( LLVMValueRef @Inst, uint @KindID, LLVMMetadataRef @MD); - - [DllImport(libraryPath, EntryPoint = "LLVMMetadataReplaceAllUsesWith", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MetadataReplaceAllUsesWith(LLVMMetadataRef @MD, LLVMMetadataRef @New); - - [DllImport(libraryPath, EntryPoint = "LLVMSetCurrentDebugLocation2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void SetCurrentDebugLocation2( InstructionBuilderHandle @Bref, uint @Line, uint @Col, LLVMMetadataRef @Scope, LLVMMetadataRef @InlinedAt); - - [DllImport(libraryPath, EntryPoint = "LLVMNewDIBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDIBuilderRef NewDIBuilder( LLVMModuleRef @m, LLVMBool allowUnresolved ); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderDestroy", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DIBuilderDestroy(LLVMDIBuilderRef @d); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderFinalize", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void DIBuilderFinalize(LLVMDIBuilderRef @d); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateCompileUnit", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateCompileUnit(LLVMDIBuilderRef @D, uint @Language, [MarshalAs(UnmanagedType.LPStr)] string @File, [MarshalAs(UnmanagedType.LPStr)] string @Dir, [MarshalAs(UnmanagedType.LPStr)] string @Producer, int @Optimized, [MarshalAs(UnmanagedType.LPStr)] string @Flags, uint @RuntimeVersion); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateFile(LLVMDIBuilderRef @D, [MarshalAs(UnmanagedType.LPStr)] string @File, [MarshalAs(UnmanagedType.LPStr)] string @Dir); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateLexicalBlock", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateLexicalBlock(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, LLVMMetadataRef @File, uint @Line, uint @Column); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateLexicalBlockFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, LLVMMetadataRef @File, uint @Discriminator); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateFunction(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, [MarshalAs(UnmanagedType.LPStr)] string @LinkageName, LLVMMetadataRef @File, uint @Line, LLVMMetadataRef @CompositeType, int @IsLocalToUnit, int @IsDefinition, uint @ScopeLine, uint @Flags, int @IsOptimized, LLVMMetadataRef TParam, LLVMMetadataRef Decl ); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateTempFunctionFwdDecl", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateTempFunctionFwdDecl(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, [MarshalAs(UnmanagedType.LPStr)] string @LinkageName, LLVMMetadataRef @File, uint @Line, LLVMMetadataRef @CompositeType, int @IsLocalToUnit, int @IsDefinition, uint @ScopeLine, uint @Flags, int @IsOptimized, LLVMMetadataRef TParam, LLVMMetadataRef Decl ); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateAutoVariable", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateAutoVariable(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMMetadataRef @File, uint @Line, LLVMMetadataRef @Ty, int @AlwaysPreserve, uint @Flags); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateParameterVariable", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateParameterVariable(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, uint @ArgNo, LLVMMetadataRef @File, uint @Line, LLVMMetadataRef @Ty, int @AlwaysPreserve, uint @Flags); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateBasicType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateBasicType(LLVMDIBuilderRef @D, [MarshalAs(UnmanagedType.LPStr)] string @Name, ulong @SizeInBits, ulong @AlignInBits, uint @Encoding); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreatePointerType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreatePointerType(LLVMDIBuilderRef @D, LLVMMetadataRef @PointeeType, ulong @SizeInBits, ulong @AlignInBits, [MarshalAs(UnmanagedType.LPStr)] string @Name); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateQualifiedType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateQualifiedType( LLVMDIBuilderRef Dref, uint Tag, LLVMMetadataRef BaseType ); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateSubroutineType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateSubroutineType(LLVMDIBuilderRef @D, LLVMMetadataRef @ParameterTypes, uint @Flags); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateStructType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateStructType(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMMetadataRef @File, uint @Line, ulong @SizeInBits, ulong @AlignInBits, uint @Flags, LLVMMetadataRef @DerivedFrom, LLVMMetadataRef @ElementTypes); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateUnionType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateUnionType(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMMetadataRef @File, uint @Line, ulong @SizeInBits, ulong @AlignInBits, uint @Flags, LLVMMetadataRef @ElementTypes); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateMemberType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateMemberType(LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMMetadataRef @File, uint @Line, ulong @SizeInBits, ulong @AlignInBits, ulong @OffsetInBits, uint @Flags, LLVMMetadataRef @Ty); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateArrayType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateArrayType(LLVMDIBuilderRef @D, ulong @SizeInBits, ulong @AlignInBits, LLVMMetadataRef @ElementType, LLVMMetadataRef @Subscripts); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateVectorType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateVectorType(LLVMDIBuilderRef @D, ulong @SizeInBits, ulong @AlignInBits, LLVMMetadataRef @ElementType, LLVMMetadataRef @Subscripts); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateTypedef", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateTypedef(LLVMDIBuilderRef @D, LLVMMetadataRef @Ty, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMMetadataRef @File, uint @Line, LLVMMetadataRef @Context); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderGetOrCreateSubrange", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderGetOrCreateSubrange(LLVMDIBuilderRef @D, long @Lo, long @Count); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderGetOrCreateArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderGetOrCreateArray(LLVMDIBuilderRef @D, out LLVMMetadataRef @Data, ulong @Length); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderGetOrCreateTypeArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef @D, out LLVMMetadataRef @Data, ulong @Length); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateExpression", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateExpression(LLVMDIBuilderRef @Dref, out long @Addr, ulong @Length); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderInsertDeclareAtEnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef DIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef @D, LLVMValueRef @Storage, LLVMMetadataRef @VarInfo, LLVMMetadataRef @Expr, LLVMMetadataRef Location, LLVMBasicBlockRef @Block); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderInsertValueAtEnd", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef DIBuilderInsertValueAtEnd(LLVMDIBuilderRef @D, LLVMValueRef @Val, ulong @Offset, LLVMMetadataRef @VarInfo, LLVMMetadataRef @Expr, LLVMMetadataRef Location, LLVMBasicBlockRef @Block); - - [DllImport(libraryPath, EntryPoint = "LLVMDIBuilderCreateEnumerationType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateEnumerationType( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs(UnmanagedType.LPStr)] string @Name, LLVMMetadataRef @File, uint @LineNumber, ulong @SizeInBits, ulong @AlignInBits, LLVMMetadataRef @Elements, LLVMMetadataRef @UnderlyingType, [MarshalAs(UnmanagedType.LPStr)]string @UniqueId ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateEnumeratorValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateEnumeratorValue( LLVMDIBuilderRef @D, [MarshalAs(UnmanagedType.LPStr)]string @Name, long @Val ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIDescriptorGetTag", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMDwarfTag DIDescriptorGetTag( LLVMMetadataRef descriptor ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateGlobalVariable", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateGlobalVariable( LLVMDIBuilderRef Dref, LLVMMetadataRef Context, [MarshalAs(UnmanagedType.LPStr)] string Name, [MarshalAs(UnmanagedType.LPStr)] string LinkageName, LLVMMetadataRef File, uint LineNo, LLVMMetadataRef Ty, LLVMBool isLocalToUnit, LLVMValueRef Val, LLVMMetadataRef Decl ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderInsertDeclareBefore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef DIBuilderInsertDeclareBefore( LLVMDIBuilderRef Dref, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef Location, LLVMValueRef InsertBefore ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderInsertValueBefore", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef DIBuilderInsertValueBefore( LLVMDIBuilderRef Dref, /*llvm::Value **/LLVMValueRef Val, UInt64 Offset, /*DILocalVariable **/ LLVMMetadataRef VarInfo, /*DIExpression **/ LLVMMetadataRef Expr, /*const DILocation **/ LLVMMetadataRef DL, /*Instruction **/ LLVMValueRef InsertBefore ); - - [DllImport( libraryPath, EntryPoint = "LLVMMetadataAsString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr MetadataAsString( LLVMMetadataRef descriptor ); - - [DllImport( libraryPath, EntryPoint = "LLVMMDNodeReplaceAllUsesWith", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MDNodeReplaceAllUsesWith( LLVMMetadataRef oldDescriptor, LLVMMetadataRef newDescriptor ); - - [DllImport( libraryPath, EntryPoint = "LLVMMetadataAsValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef MetadataAsValue( LLVMContextRef context, LLVMMetadataRef metadataRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateReplaceableCompositeType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateReplaceableCompositeType( LLVMDIBuilderRef Dref, uint Tag, [MarshalAs(UnmanagedType.LPStr)] string Name, LLVMMetadataRef Scope, LLVMMetadataRef File, uint Line, uint RuntimeLang, ulong SizeInBits, ulong AlignInBits, uint Flags); - - [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateNamespace", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DIBuilderCreateNamespace( LLVMDIBuilderRef Dref, LLVMMetadataRef scope, [MarshalAs( UnmanagedType.LPStr )] string name, LLVMMetadataRef file, uint line ); - - [DllImport( libraryPath, EntryPoint = "LLVMDILocation", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DILocation( LLVMContextRef context, uint Line, uint Column, LLVMMetadataRef scope, LLVMMetadataRef InlinedAt ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetModuleName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetModuleName( LLVMModuleRef module ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsTemporary", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsTemporary( LLVMMetadataRef M ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsResolved", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool IsResolved( LLVMMetadataRef M ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsDistinct", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool IsDistinct( LLVMMetadataRef M ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsUniqued", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool IsUniqued( LLVMMetadataRef M ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetMDStringText", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr GetMDStringText( LLVMMetadataRef M, out uint len ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetGlobalAlias", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetGlobalAlias( LLVMModuleRef module, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetAliasee", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMValueRef GetAliasee( LLVMValueRef Val ); - - [DllImport( libraryPath, EntryPoint = "LLVMMDNodeResolveCycles", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern void MDNodeResolveCycles( LLVMMetadataRef M ); - - [DllImport( libraryPath, EntryPoint = "LLVMSubProgramDescribes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool SubProgramDescribes( LLVMMetadataRef subProgram, LLVMValueRef function ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetLine", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern UInt32 DITypeGetLine( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetSizeInBits", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern UInt64 DITypeGetSizeInBits( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetAlignInBits", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern UInt64 DITypeGetAlignInBits( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetOffsetInBits", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern UInt64 DITypeGetOffsetInBits( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetFlags", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern UInt32 DITypeGetFlags( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetScope", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DITypeGetScope( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern IntPtr DITypeGetName( LLVMMetadataRef typeRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMDIScopeGetFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataRef DIScopeGetFile( LLVMMetadataRef scope ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetArgumentIndex", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt32 GetArgumentIndex( LLVMValueRef Val ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetDIFileName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr GetDIFileName( LLVMMetadataRef /*DIFile*/ file ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetDIFileDirectory", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr GetDIFileDirectory( LLVMMetadataRef /*DIFile*/ file ); - - [DllImport( libraryPath, EntryPoint = "LLVMBuildAtomicCmpXchg", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMValueRef BuildAtomicCmpXchg( InstructionBuilderHandle @B, LLVMValueRef @Ptr, LLVMValueRef @Cmp, LLVMValueRef @New, LLVMAtomicOrdering @successOrdering, LLVMAtomicOrdering @failureOrdering, LLVMBool @singleThread ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetNodeContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMContextRef GetNodeContext( LLVMMetadataRef /*MDNode*/ node ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetMetadataID", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataKind GetMetadataID( LLVMMetadataRef /*Metadata*/ md ); - - [DllImport( libraryPath, EntryPoint = "LLVMMDNodeGetNumOperands", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt32 MDNodeGetNumOperands( LLVMMetadataRef /*MDNode*/ node ); - - [DllImport( libraryPath, EntryPoint = "LLVMMDNodeGetOperand", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMDOperandRef MDNodeGetOperand( LLVMMetadataRef /*MDNode*/ node, UInt32 index ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetOperandNode", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataRef GetOperandNode( LLVMMDOperandRef operand ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateEmptyAttributeSet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr CreateEmptyAttributeSet( ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttributeSetFromKindArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr CreateAttributeSetFromKindArray( LLVMContextRef context, UInt32 index, out LLVMAttrKind pKinds, UInt64 len ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttributeSetFromAttributeSetArray", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr CreateAttributeSetFromAttributeSetArray( LLVMContextRef context, out UIntPtr pAttributes, UInt64 len ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttributeSetFromBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr CreateAttributeSetFromBuilder( LLVMContextRef context, UInt32 index, AttributeBuilderHandle bldr ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetAddKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetAddKind( UIntPtr attributeSet, LLVMContextRef context, UInt32 index, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetAddString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetAddString( UIntPtr attributeSet, LLVMContextRef context, UInt32 index, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetAddStringValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetAddStringValue( UIntPtr attributeSet, LLVMContextRef context, UInt32 index, [MarshalAs(UnmanagedType.LPStr)] string name, [MarshalAs(UnmanagedType.LPStr)] string value ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetAddAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetAddAttributes( UIntPtr attributeSet, LLVMContextRef context, UInt32 index, UIntPtr otherAttributeSet ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetRemoveAttributeKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetRemoveAttributeKind( UIntPtr attributeSet, UInt32 index, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetRemoveAttributeSet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetRemoveAttributeSet( UIntPtr attributeSet, UInt32 index, UIntPtr attributes ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetRemoveAttributeBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetRemoveAttributeBuilder( UIntPtr attributeSet, LLVMContextRef context, UInt32 index, AttributeBuilderHandle bldr ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetContext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMContextRef AttributeSetGetContext( UIntPtr attributeSet ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeGetAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeGetAttributes( UIntPtr attributeSet, UInt32 index ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetHasAttributeKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeSetHasAttributeKind( UIntPtr attributeSet, UInt32 index, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetHasStringAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeSetHasStringAttribute( UIntPtr attributeSet, UInt32 index, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetHasAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeSetHasAttributes( UIntPtr attributeSet, UInt32 index ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetHasAttributeSomewhere", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeSetHasAttributeSomewhere( UIntPtr attributeSet, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetAttributeByKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetGetAttributeByKind( UIntPtr attributeSet, UInt32 index, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetAttributeByName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetGetAttributeByName( UIntPtr attributeSet, UInt32 index, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetToString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr AttributeSetToString( UIntPtr attributeSet, UInt32 index, LLVMBool inGroup ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetNumSlots", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt32 AttributeSetGetNumSlots( UIntPtr attributeSet ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetSlotAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetGetSlotAttributes( UIntPtr attributeSet, UInt32 slot ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetSlotIndex", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt32 AttributeSetGetSlotIndex( UIntPtr attributeSet, UInt32 slot ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetFunctionAttributeSet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr GetFunctionAttributeSet( LLVMValueRef /*Function*/ function ); - - [DllImport( libraryPath, EntryPoint = "LLVMSetFunctionAttributeSet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void SetFunctionAttributeSet( LLVMValueRef /*Function*/ function, UIntPtr attributeSet ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetCallSiteAttributeSet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr GetCallSiteAttributeSet( LLVMValueRef /*Instruction*/ instruction ); - - [DllImport( libraryPath, EntryPoint = "LLVMSetCallSiteAttributeSet", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void SetCallSiteAttributeSet( LLVMValueRef /*Instruction*/ instruction, UIntPtr attributeSet ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetGetIteratorStartToken", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetGetIteratorStartToken( UIntPtr attributeSet, UInt32 slot ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeSetIteratorGetNext", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr AttributeSetIteratorGetNext( UIntPtr attributeSet, UInt32 slot, ref UIntPtr pToken ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsEnumAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool IsEnumAttribute( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsIntAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool IsIntAttribute( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMIsStringAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool IsStringAttribute( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMHasAttributeKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool HasAttributeKind( UIntPtr attribute, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMHasAttributeString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool HasAttributeString( UIntPtr attribute, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetAttributeKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMAttrKind GetAttributeKind( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetAttributeValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UInt64 GetAttributeValue( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetAttributeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr GetAttributeName( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMGetAttributeStringValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr GetAttributeStringValue( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeToString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr AttributeToString( UIntPtr attribute ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr CreateAttribute( LLVMContextRef ctx, LLVMAttrKind kind, UInt64 value ); - - [DllImport( libraryPath, EntryPoint = "LVMCreateTargetDependentAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern UIntPtr CreateTargetDependentAttribute( LLVMContextRef ctx, [MarshalAs(UnmanagedType.LPStr)] string name, [MarshalAs(UnmanagedType.LPStr)] string value ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttributeBuilder", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern AttributeBuilderHandle CreateAttributeBuilder( ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttributeBuilder2", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern AttributeBuilderHandle CreateAttributeBuilder2( UIntPtr value ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreateAttributeBuilder3", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern AttributeBuilderHandle CreateAttributeBuilder3( UIntPtr attributeSet, UInt32 index ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderDispose", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderDispose( IntPtr bldr ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderClear", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderClear( AttributeBuilderHandle bldr ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderAddEnum", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderAddEnum( AttributeBuilderHandle bldr, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderAddAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderAddAttribute( AttributeBuilderHandle bldr, UIntPtr value ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderAddStringAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderAddStringAttribute( AttributeBuilderHandle bldr, [MarshalAs(UnmanagedType.LPStr)] string name, [MarshalAs(UnmanagedType.LPStr)] string value ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderRemoveEnum", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderRemoveEnum( AttributeBuilderHandle bldr, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderRemoveAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderRemoveAttributes( AttributeBuilderHandle bldr, UIntPtr attributeSet, UInt32 index ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderRemoveAttribute", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderRemoveAttribute( AttributeBuilderHandle bldr, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderRemoveBldr", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderRemoveBldr( AttributeBuilderHandle bldr, AttributeBuilderHandle ohter ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderMerge", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void AttributeBuilderMerge( AttributeBuilderHandle bldr, AttributeBuilderHandle ohter ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderOverlaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderOverlaps( AttributeBuilderHandle bldr, AttributeBuilderHandle other ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderContainsEnum", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderContainsEnum( AttributeBuilderHandle bldr, LLVMAttrKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderContainsName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderContainsName( AttributeBuilderHandle bldr, [MarshalAs(UnmanagedType.LPStr)] string name ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderHasAnyAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderHasAnyAttributes( AttributeBuilderHandle bldr ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderHasAttributes", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderHasAttributes( AttributeBuilderHandle bldr, UIntPtr attributeset, UInt32 index ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderHasTargetIndependentAttrs", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderHasTargetIndependentAttrs( AttributeBuilderHandle bldr ); - - [DllImport( libraryPath, EntryPoint = "LLVMAttributeBuilderHasTargetDependentAttrs", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool AttributeBuilderHasTargetDependentAttrs( AttributeBuilderHandle bldr ); - - [DllImport(libraryPath, EntryPoint = "LLVMDILocalScopeGetSubProgram", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMMetadataRef DILocalScopeGetSubProgram(LLVMMetadataRef /*DILocalScope*/ localScope); - - [DllImport( libraryPath, EntryPoint = "LLVMFunctionGetSubprogram", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMMetadataRef FunctionGetSubprogram( LLVMValueRef function ); - - [DllImport( libraryPath, EntryPoint = "LLVMFunctionSetSubprogram", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void FunctionSetSubprogram( LLVMValueRef function, LLVMMetadataRef subprogram ); - - [DllImport(libraryPath, EntryPoint = "LLVMFunctionHasPersonalityFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern LLVMBool FunctionHasPersonalityFunction( LLVMValueRef function ); - - [DllImport( libraryPath, EntryPoint = "LLVMCreatePassRegistry", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern PassRegistryHandle CreatePassRegistry( ); - - [DllImport( libraryPath, EntryPoint = "LLVMPassRegistryDispose", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void PassRegistryDispose( IntPtr hPassRegistry ); - - [DllImport( libraryPath, EntryPoint = "LLVMRunPassPipeline", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool RunPassPipeline( LLVMContextRef context, LLVMModuleRef M, LLVMTargetMachineRef TM, [MarshalAs( UnmanagedType.LPStr )] string passPipeline, LLVMOptVerifierKind VK, [MarshalAs(UnmanagedType.Bool)] bool ShouldPreserveAssemblyUseListOrder, [MarshalAs( UnmanagedType.Bool )] bool ShouldPreserveBitcodeUseListOrder ); - - [DllImport( libraryPath, EntryPoint = "LLVMInitializeCodeGenForOpt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void InitializeCodeGenForOpt( PassRegistryHandle R ); - - [DllImport( libraryPath, EntryPoint = "LLVMInitializePassesForLegacyOpt", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void InitializePassesForLegacyOpt( ); - - [DllImport( libraryPath, EntryPoint = "LLVMRunLegacyOptimizer", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void RunLegacyOptimizer( LLVMModuleRef Mref, LLVMTargetMachineRef TMref ); - - [DllImport( libraryPath, EntryPoint = "LLVMParseTriple", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern TripleHandle ParseTriple( [MarshalAs( UnmanagedType.LPStr )] string triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMDisposeTriple", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void DisposeTriple( IntPtr triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleOpEqual", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool TripleOpEqual( TripleHandle lhs, TripleHandle rhs ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetArchType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTripleArchType TripleGetArchType( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetSubArchType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTripleSubArchType TripleGetSubArchType( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetVendorType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTripleVendorType TripleGetVendorType( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetOsType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTripleOSType TripleGetOsType( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleHasEnvironment", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMBool TripleHasEnvironment( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetEnvironmentType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTripleEnvironmentType TripleGetEnvironmentType( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetEnvironmentVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void TripleGetEnvironmentVersion( TripleHandle triple, out UInt32 major, out UInt32 minor, out UInt32 micro ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetObjectFormatType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMTripleObjectFormatType TripleGetObjectFormatType( TripleHandle triple ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleAsString", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleAsString( TripleHandle triple, [MarshalAs(UnmanagedType.U1)]bool normalize ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetArchTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleGetArchTypeName( LLVMTripleArchType type ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetSubArchTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleGetSubArchTypeName( LLVMTripleSubArchType type ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetVendorTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleGetVendorTypeName( LLVMTripleVendorType vendor ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetOsTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleGetOsTypeName( LLVMTripleOSType osType ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetEnvironmentTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleGetEnvironmentTypeName( LLVMTripleEnvironmentType environmentType ); - - [DllImport( libraryPath, EntryPoint = "LLVMTripleGetObjectFormatTypeName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr TripleGetObjectFormatTypeName( LLVMTripleObjectFormatType environmentType ); - - [DllImport( libraryPath, EntryPoint = "LLVMNormalizeTriple", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr NormalizeTriple( [MarshalAs( UnmanagedType.LPStr )] string triple ); - - [UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - [return: MarshalAs(UnmanagedType.Bool)] - internal delegate bool ComdatIteratorCallback( LLVMComdatRef comdatRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMModuleEnumerateComdats", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void ModuleEnumerateComdats( LLVMModuleRef module, ComdatIteratorCallback callback ); - - [DllImport( libraryPath, EntryPoint = "LLVMModuleInsertOrUpdateComdat", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMComdatRef ModuleInsertOrUpdateComdat( LLVMModuleRef module, [MarshalAs( UnmanagedType.LPStr )] string name, LLVMComdatSelectionKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMModuleComdatRemove", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void ModuleComdatRemove( LLVMModuleRef module, LLVMComdatRef comdatRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMModuleComdatClear", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void ModuleComdatClear( LLVMModuleRef module ); - - [DllImport( libraryPath, EntryPoint = "LLVMGlobalObjectGetComdat", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMComdatRef GlobalObjectGetComdat( LLVMValueRef Val ); - - [DllImport( libraryPath, EntryPoint = "LLVMGlobalObjectSetComdat", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void GlobalObjectSetComdat( LLVMValueRef Val, LLVMComdatRef comdatRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMComdatGetKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern LLVMComdatSelectionKind ComdatGetKind( LLVMComdatRef comdatRef ); - - [DllImport( libraryPath, EntryPoint = "LLVMComdatSetKind", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern void ComdatSetKind( LLVMComdatRef comdatRef, LLVMComdatSelectionKind kind ); - - [DllImport( libraryPath, EntryPoint = "LLVMComdatGetName", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] - internal static extern IntPtr ComdatGetName( LLVMComdatRef comdatRef ); - } -} diff --git a/src/Llvm.NET/LLVM/LLVMNative.cs b/src/Llvm.NET/LLVM/LLVMNative.cs deleted file mode 100644 index 4a251c340..000000000 --- a/src/Llvm.NET/LLVM/LLVMNative.cs +++ /dev/null @@ -1,291 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; -using System.Threading; - -namespace Llvm.NET.Native -{ - internal enum ValueKind : uint - { - Argument = LLVMValueKind.LLVMArgumentValueKind, // This is an instance of Argument - BasicBlock = LLVMValueKind.LLVMBasicBlockValueKind, // This is an instance of BasicBlock - MemoryUse = LLVMValueKind.LLVMMemoryUseValueKind, // ??? - MemoryDef = LLVMValueKind.LLVMMemoryDefValueKind, // ??? - MemoryPhi = LLVMValueKind.LLVMMemoryPhiValueKind, // ??? - - Function = LLVMValueKind.LLVMFunctionValueKind, // This is an instance of Function - GlobalAlias = LLVMValueKind.LLVMGlobalAliasValueKind, // This is an instance of GlobalAlias - GlobalIFunc = LLVMValueKind.LLVMGlobalIFuncValueKind, // ??? - GlobalVariable = LLVMValueKind.LLVMGlobalVariableValueKind, // This is an instance of GlobalVariable - BlockAddress = LLVMValueKind.LLVMBlockAddressValueKind, // This is an instance of BlockAddress - ConstantExpr = LLVMValueKind.LLVMConstantExprValueKind, // This is an instance of ConstantExpr - ConstantArray = LLVMValueKind.LLVMConstantArrayValueKind, // This is an instance of ConstantArray - ConstantStruct = LLVMValueKind.LLVMConstantStructValueKind, // This is an instance of ConstantStruct - ConstantVector = LLVMValueKind.LLVMConstantVectorValueKind, // This is an instance of ConstantVector - - UndefValue = LLVMValueKind.LLVMUndefValueValueKind, // This is an instance of UndefValue - ConstantAggregateZero = LLVMValueKind.LLVMConstantAggregateZeroValueKind, // This is an instance of ConstantAggregateZero - ConstantDataArray = LLVMValueKind.LLVMConstantDataArrayValueKind, // This is an instance of ConstantDataArray - ConstantDataVector = LLVMValueKind.LLVMConstantDataVectorValueKind, // This is an instance of ConstantDataVector - ConstantInt = LLVMValueKind.LLVMConstantIntValueKind, // This is an instance of ConstantInt - ConstantFP = LLVMValueKind.LLVMConstantFPValueKind, // This is an instance of ConstantFP - ConstantPointerNull = LLVMValueKind.LLVMConstantPointerNullValueKind, // This is an instance of ConstantPointerNull - ConstantTokenNone = LLVMValueKind.LLVMConstantTokenNoneValueKind, // This is an instance of ConstantTokenNone - - MetadataAsValue = LLVMValueKind.LLVMMetadataAsValueValueKind, // This is an instance of MetadataAsValue - InlineAsm = LLVMValueKind.LLVMInlineAsmValueKind, // This is an instance of InlineAsm - - Instruction = LLVMValueKind.LLVMInstructionValueKind, // This is an instance of Instruction - // Enum values starting at InstructionVal are used for Instructions; - - // instruction values come directly from LLVM Instruction.def which is different from the "stable" - // LLVM-C API, therefore they are less "stable" and bound to the C++ implementation version and - // subject to change from version to version. - Return = 1 + Instruction, // Terminators - Branch = 2 + Instruction, - Switch = 3 + Instruction, - IndirectBranch = 4 + Instruction, - Invoke = 5 + Instruction, - Resume = 6 + Instruction, - Unreachable = 7 + Instruction, - CleanUpReturn = 8 + Instruction, - CatchReturn = 9 + Instruction, - CatchSwitch = 10 + Instruction, - - Add = 11 + Instruction, // binary operators - FAdd = 12 + Instruction, - Sub = 13 + Instruction, - FSub = 14 + Instruction, - Mul = 15 + Instruction, - FMul = 16 + Instruction, - UDiv = 17 + Instruction, - SDiv = 18 + Instruction, - FDiv = 19 + Instruction, - URem = 20 + Instruction, - SRem = 21 + Instruction, - FRem = 22 + Instruction, - - Shl = 23 + Instruction, // Logical Operators - LShr = 24 + Instruction, - AShr = 25 + Instruction, - And = 26 + Instruction, - Or = 27 + Instruction, - Xor = 28 + Instruction, - - Alloca = 29 + Instruction, // Memory Operators - Load = 30 + Instruction, - Store = 31 + Instruction, - GetElementPtr = 32 + Instruction, - Fence = 33 + Instruction, - AtomicCmpXchg = 34 + Instruction, - AtomicRMW = 35 + Instruction, - - Trunc = 36 + Instruction, // cast/conversion operators - ZeroExtend = 37 + Instruction, - SignExtend = 38 + Instruction, - FPToUI = 39 + Instruction, - FPToSI = 40 + Instruction, - UIToFP = 41 + Instruction, - SIToFP = 42 + Instruction, - FPTrunc = 43 + Instruction, - FPExt = 44 + Instruction, - PtrToInt = 45 + Instruction, - IntToPtr = 46 + Instruction, - BitCast = 47 + Instruction, - AddrSpaceCast = 48 + Instruction, - - CleanupPad = 49 + Instruction, // New Exception pads - CatchPad = 50 + Instruction, - - ICmp = 51 + Instruction, - FCmp = 52 + Instruction, - Phi = 53 + Instruction, - Call = 54 + Instruction, - Select = 55 + Instruction, - UserOp1 = 56 + Instruction, - UserOp2 = 57 + Instruction, - VaArg = 58 + Instruction, - ExtractElement = 59 + Instruction, - InsertElement = 60 + Instruction, - ShuffleVector = 61 + Instruction, - ExtractValue = 62 + Instruction, - InsertValue = 63 + Instruction, - LandingPad = 64 + Instruction, - - // Markers: - ConstantFirstVal = Function, - ConstantLastVal = ConstantTokenNone, - - ConstantDataFirstVal = UndefValue, - ConstantDataLastVal = ConstantTokenNone, - ConstantAggregateFirstVal = ConstantArray, - ConstantAggregateLastVal = ConstantVector, - } - - internal partial struct LLVMVersionInfo - { - public override string ToString() - { - if( VersionString == IntPtr.Zero ) - return null; - - return Marshal.PtrToStringAnsi( VersionString ); - } - - public static implicit operator Version( LLVMVersionInfo versionInfo ) - => new Version( versionInfo.Major, versionInfo.Minor, versionInfo.Patch ); - } - - // add implicit conversions to/from C# bool for convenience - internal partial struct LLVMBool - { - // sometimes LLVMBool values are actually success/failure codes - // and thus a zero value actually means success and not false or failure. - public bool Succeeded => Value == 0; - - public bool Failed => !Succeeded; - - public static implicit operator LLVMBool( bool value ) => new LLVMBool( value ? 1 : 0 ); - public static implicit operator bool( LLVMBool value ) => value.Value != 0; - } - - internal partial struct LLVMMetadataRef - : IEquatable - { - internal static LLVMMetadataRef Zero = new LLVMMetadataRef( IntPtr.Zero ); - - public override int GetHashCode( ) => Pointer.GetHashCode( ); - - public override bool Equals( object obj ) - { - if( obj is LLVMMetadataRef ) - return Equals( ( LLVMMetadataRef )obj ); - - if( obj is IntPtr ) - return Pointer.Equals( obj ); - - return base.Equals( obj ); - } - - public bool Equals( LLVMMetadataRef other ) => Pointer == other.Pointer; - - public static bool operator ==( LLVMMetadataRef lhs, LLVMMetadataRef rhs ) => lhs.Equals( rhs ); - public static bool operator !=( LLVMMetadataRef lhs, LLVMMetadataRef rhs ) => !lhs.Equals( rhs ); - } - - internal static partial class NativeMethods - { - internal static ValueKind GetValueKind( LLVMValueRef valueRef ) => ( ValueKind )GetValueID( valueRef ); - - static void FatalErrorHandler( string Reason ) - { - Trace.TraceError( "LLVM Fatal Error: '{0}'; Application exiting.", Reason ); - // LLVM will call exit() upon return from this function and there's no way to stop it - } - - /// This method is used to marshal a string when NativeMethods.DisposeMessage() is required on the string allocated from native code - /// Pointer to the native code allocated string - /// Managed code string marshaled from the native content - /// - /// This method will, construct a new managed string containing the text of the string from native code, normalizing - /// the line endings to the current execution environments line endings (See: ). - /// - internal static string MarshalMsg( IntPtr msg ) - { - var retVal = string.Empty; - if( msg != IntPtr.Zero ) - { - try - { - retVal = NormalizeLineEndings( msg ); - } - finally - { - DisposeMessage( msg ); - } - } - return retVal; - } - - /// Static constructor for NativeMethods - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations" )] - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline" )] - static NativeMethods() - { - // force loading the appropriate architecture specific - // DLL before any use of the wrapped inter-op APIs to - // allow building this library as ANYCPU - var path = Path.GetDirectoryName( Assembly.GetExecutingAssembly( ).Location ); - if( Directory.Exists( Path.Combine( path, "LibLLVM") ) ) - { - LoadWin32Library( libraryPath, "LibLLVM" ); - } - else - { - // fall-back to standard library search paths to allow building - // CPU specific variants with only one native DLL without needing - // conditional compilation on this library, which is useful for - // unit testing or whenever the Nuget packaging isn't desired. - LoadWin32Library( libraryPath, null ); - } - - // Verify the version of LLVM in LibLLVM - LLVMVersionInfo versionInfo = new LLVMVersionInfo( ); - GetVersionInfo( ref versionInfo ); - if( versionInfo.Major != VersionMajor - || versionInfo.Minor != VersionMinor - || versionInfo.Patch < VersionPatch - ) - { - throw new BadImageFormatException( "Mismatched LibLLVM version" ); - } - - // initialize the static fields - LineEndingNormalizingRegEx = new Regex( "(\r\n|\n\r|\r|\n)" ); - FatalErrorHandlerDelegate = new Lazy( ( ) => FatalErrorHandler, LazyThreadSafetyMode.PublicationOnly ); - InstallFatalErrorHandler( FatalErrorHandlerDelegate.Value ); - } - - // LLVM doesn't use environment/OS specific line endings, so this will - // normalize the line endings from strings provided by LLVM into the current - // environment's normal format. - internal static string NormalizeLineEndings( IntPtr llvmString ) - { - if( llvmString == IntPtr.Zero ) - return string.Empty; - - var str = Marshal.PtrToStringAnsi( llvmString ); - return NormalizeLineEndings( str ); - } - - internal static string NormalizeLineEndings( IntPtr llvmString, int len ) - { - if( llvmString == IntPtr.Zero || len == 0 ) - return string.Empty; - - var str = Marshal.PtrToStringAnsi( llvmString, len ); - return NormalizeLineEndings( str ); - } - - private static string NormalizeLineEndings( string txt ) - { - // shortcut optimization for environments that match the LLVM assumption - if( Environment.NewLine.Length == 1 && Environment.NewLine[ 0 ] == '\n' ) - return txt; - - return LineEndingNormalizingRegEx.Replace( txt, Environment.NewLine ); - } - - // lazy initialized singleton unmanaged delegate so it is never collected - private static Lazy FatalErrorHandlerDelegate; - private static readonly Regex LineEndingNormalizingRegEx; - - // version info for verification of matched LibLLVM - private const int VersionMajor = 3; - private const int VersionMinor = 9; - private const int VersionPatch = 1; - } -} diff --git a/src/Llvm.NET/LLVM/LlvmHandles.cs b/src/Llvm.NET/LLVM/LlvmHandles.cs deleted file mode 100644 index 68717481a..000000000 --- a/src/Llvm.NET/LLVM/LlvmHandles.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Runtime.ConstrainedExecution; -using System.Runtime.InteropServices; -using System.Security; -using System.Security.Permissions; - -namespace Llvm.NET.Native -{ - internal static class IntPtrExtensions - { - public static bool IsNull( this IntPtr self ) => self == IntPtr.Zero; - public static bool IsNull( this UIntPtr self ) => self == UIntPtr.Zero; - } - - /// Base class for LLVM disposable types that are instantiated outside of an LLVM and therefore won't be disposed by the context - [SecurityCritical] - [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)] - internal abstract class SafeHandleNullIsInvalid - : SafeHandle - { - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - protected SafeHandleNullIsInvalid( bool ownsHandle) - : base( IntPtr.Zero, ownsHandle ) - { - } - - public bool IsNull => handle.IsNull(); - - public override bool IsInvalid - { - [SecurityCritical] - get - { - return IsNull; - } - } - } - - [SecurityCritical] - internal class AttributeBuilderHandle - : SafeHandleNullIsInvalid - { - internal AttributeBuilderHandle() - : base( true ) - { - } - - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] - internal AttributeBuilderHandle( IntPtr handle ) - : base( true ) - { - SetHandle( handle ); - } - - [SecurityCritical] - protected override bool ReleaseHandle( ) - { - NativeMethods.AttributeBuilderDispose( handle ); - return true; - } - } - - [SecurityCritical] - internal class PassRegistryHandle - : SafeHandleNullIsInvalid - { - internal PassRegistryHandle( ) - : base( true ) - { - } - - internal PassRegistryHandle( IntPtr handle, bool owner ) - : base( owner ) - { - SetHandle( handle ); - } - - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] - internal PassRegistryHandle( IntPtr handle ) - : this( handle, false ) - { - } - - [SecurityCritical] - protected override bool ReleaseHandle( ) - { - NativeMethods.PassRegistryDispose( handle ); - return true; - } - } - - // typedef struct LLVMOpaqueTriple* LLVMTripleRef; - [SecurityCritical] - internal class TripleHandle - : SafeHandleNullIsInvalid - { - internal TripleHandle( ) - : base( true ) - { - } - - internal TripleHandle( IntPtr handle, bool owner ) - : base( owner ) - { - SetHandle( handle ); - } - - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] - internal TripleHandle( IntPtr handle ) - : this( handle, false ) - { - } - - [SecurityCritical] - protected override bool ReleaseHandle( ) - { - NativeMethods.DisposeTriple( handle ); - return true; - } - } - - [SecurityCritical] - internal class InstructionBuilderHandle - : SafeHandleNullIsInvalid - { - internal InstructionBuilderHandle( ) - : base( true ) - { - } - - internal InstructionBuilderHandle( IntPtr handle, bool owner ) - : base( owner ) - { - SetHandle( handle ); - } - - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] - internal InstructionBuilderHandle( IntPtr handle ) - : this( handle, false ) - { - } - - [SecurityCritical] - protected override bool ReleaseHandle( ) - { - NativeMethods.DisposeBuilder( handle ); - return true; - } - } -} diff --git a/src/Llvm.NET/Llvm.NET.csproj b/src/Llvm.NET/Llvm.NET.csproj index 22d402e81..eca087af2 100644 --- a/src/Llvm.NET/Llvm.NET.csproj +++ b/src/Llvm.NET/Llvm.NET.csproj @@ -1,280 +1,248 @@ - - - - - - Debug - AnyCPU - {0162C8CE-6641-4922-8664-F8A44356FBF7} - Library - Properties - Llvm.NET - Llvm.NET - v4.6.2 - 512 - - - - true - TRACE;DEBUG - true - $(OutputPath)\Llvm.NET.XML - 1591 - full - AnyCPU - prompt - Llvm.NET.ruleset - true - - - true - $(OutputPath)\Llvm.NET.XML - true - 1591 - pdbonly - AnyCPU - prompt - Llvm.NET.ruleset - true - - - true - TRACE;DEBUG - true - $(OutputPath)\Llvm.NET.XML - 1591 - full - AnyCPU - prompt - Llvm.NET.ruleset - true - - - true - $(OutputPath)\Llvm.NET.XML - true - 1591 - pdbonly - AnyCPU - prompt - Llvm.NET.ruleset - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {6c77a7de-d464-430f-96a9-a64768763b5f} - LibLLVM - false - True - - - - - - - - - CustomDictionary.xml - - - - - - - - - - \ No newline at end of file + + + net47;netstandard2.0 + win-x64;win-x86 + full + True + Llvm.NET.xml + False + 1701;1702;1705;1591 + true + NugetPkg\Llvm.NET.nuspec + configuration=$(Configuration);buildbinoutput=$(BaseOutputPath) + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CustomDictionary.xml + + + + + + + + + + + + + + + + + + + + + + + version=$(PackageVersion);llvmversion=$(LlvmVersion);$(NuspecProperties) + + + diff --git a/src/Llvm.NET/Llvm.NET.nuget.props b/src/Llvm.NET/Llvm.NET.nuget.props deleted file mode 100644 index fbde08527..000000000 --- a/src/Llvm.NET/Llvm.NET.nuget.props +++ /dev/null @@ -1,9 +0,0 @@ - - - - $(UserProfile)\.nuget\packages\ - - - - - \ No newline at end of file diff --git a/src/Llvm.NET/Llvm.NET.nuget.targets b/src/Llvm.NET/Llvm.NET.nuget.targets deleted file mode 100644 index 663be7ec0..000000000 --- a/src/Llvm.NET/Llvm.NET.nuget.targets +++ /dev/null @@ -1,9 +0,0 @@ - - - - $(UserProfile)\.nuget\packages\ - - - - - \ No newline at end of file diff --git a/src/Llvm.NET/Llvm.NET.ruleset b/src/Llvm.NET/Llvm.NET.ruleset deleted file mode 100644 index 2db597f99..000000000 --- a/src/Llvm.NET/Llvm.NET.ruleset +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Llvm.NET/Llvm.NET.xml b/src/Llvm.NET/Llvm.NET.xml new file mode 100644 index 000000000..68b247674 --- /dev/null +++ b/src/Llvm.NET/Llvm.NET.xml @@ -0,0 +1,2953 @@ + + + + Llvm.NET + + + + Fluent style method for validating a function argument is not null + Type of the argument + argument value to test for null + name of the argument to appear in the exception + + unless it is null, in which case an + is thrown. + + + This is useful for validating cases where a parameter must be used to compute + an additional parameter to a base class constructor. + + + + Comdat entry for a module + + A COMDAT is a named kind pair to ensure that, within + a given module there are no two named COMDATs with a + different kinds. Ultimately, Comdat is 'owned' by the + module, if the module is disposed the Comdats it owns + are invalidated. Using a Comdat instance after the + module is disposed results in an effective NOP. + + + + Provides validation extensions to the class + + These are done as extensions deliberately to allow for the possibility that the provided + context may actually be , which wouldn't be possible as member methods. + + + + Throw an if the is or is disposed + to test + Argument name + Error message for the exception + + + Throw an if the is or is disposed + to test + Argument name + + + Throw an if the is or is disposed + to test + Error message for the exception + + + Throw an if the is or is disposed + to test + + + Execute a given action if the is or is disposed + to test + Argument name or if name is not needed by the supplied + Error message for the + Action to perform if the verification fails + + + Provides debug information binding between an and a + + + Creates a new + Underlying LLVM array type to bind debug info to + Array element type with debug information + module to use for creating debug information + Number of elements in the array + Lower bound of the array [default = 0] + Alignment for the type + + + Constructs a new + Type of elements in the array + to use for the context of the debug information + Number of elements in the array + value for the array indices [Default: 0] + + + Constructs a new + Native LLVM type for the elements + to use for the context of the debug information + Debug type of the array elements + Number of elements in the array + value for the array indices [Default: 0] + + + Full type for the elements + + + + + + + + + Lower bound of the array, usually but not always zero + + + Resolves a temporary metadata node for the array if full size information wasn't available at creation time + Type layout information + Debug information builder for creating the new debug information + + + Describes a member/field of a type for creating debug information + + This class is used with to provide debug information for a type. + In order to support explicit layout structures the members relating to layout are all . + When they are null then modules target specific layout information is used to determine + layout details. Setting the layout members of this class to non-null will override that behavior to define explicit + layout details. + + + + LLVM structure element index this descriptor describes + + + Name of the field + + + File the field is declared in + + + Line the field is declared on + + + flags for the field declaration + + + Debug type information for this field + + + Provides explicit layout information for this member + If this is null then + will default to using to determine the size using the module's target specific layout. + + If this property is provided (e.g. is not ) for any member of a type, then + it must be set for all members. In other words explicit layout must be defined for all members + or none. Furthermore, for types using explicit layout, the type containing this member must + include the "packed" modifier. + + + + + DebugMemberLayout is used to define custom layout information for structure members + + Ordinarily layout information is handle automatically in + + however in cases where explicitly controlled (or "packed") layout is required, instances of DebugMemberLayout are + used to provide the information necessary to generate a proper type and debug information. + + + + Constructs a new + Size of the member in bits + Alignment of the member in bits + Offset of the member in bits + + + Bit size for the field + + + Bit alignment for the field + + + Bit offset for the field in it's containing type + + + Binding between a and an + + + Constructs a new + Debug type of the pointee + used for creating the pointer type and debug information + Target address space for the pointer [Default: 0] + Name of the type [Default: null] + Alignment on pointer + + + Constructs a new + Native type of the pointee + used for creating the pointer type and debug information + Debug type of the pointee + Target address space for the pointer [Default: 0] + Name of the type [Default: null] + Alignment of pointer + + + Constructs a new + Native type of the pointer + used for creating the pointer type and debug information + Debug type of the pointee + Name of the type [Default: null] + Alignment for pointer type + + + Constructs a new + Native type of the pointer + Debug type for the pointer + + This constructor is typically used when building typedefs to a basic type + to provide namespace scoping for the typedef for languages that support + such a concept. This is needed because basic types don't have any namespace + information in the LLVM Debug information (they are implicitly in the global + namespace) + + + + + + + + + + Debug representation of a union type + The underlying native LLVM type is a structure with a single member + + + Array of debug information nodes for use with methods + + + + Debug information for a basic type + + + + see + + + see + + + see + + + see + + + see + + + see + + + see + + + see + + + see + + + see + + + Legal scope for lexical blocks, local variables, and debug info locations + + + see + + + see + + + Root of the object hierarchy for Debug information metadata nodes + + + Dwarf tag for the descriptor + + + Base class for all Debug info scopes + + + see + + + see + + + see + + + Base class for Debug info types + + + Array of see nodes for use with see methods + + + Provides pairing of a with a for function signatures + + Primitive types and function signature types are all interned in LLVM, thus there won't be a + strict one to one relationship between an LLVM type and corresponding language specific debug + type. (e.g. unsigned char, char, byte and signed byte might all be 8 bit integer values as far + as LLVM is concerned. Also, when using the pointer+alloca+memcpy pattern to pass by value the + actual source debug info type is different than the LLVM function signature. This class is used + to construct native type and debug info pairing to allow applications to maintain a link from + their AST or IR types into the LLVM native type and debug information. + + + It is important to note that the relationship between the to it's + properties is strictly one way. That is, there is no way to take an arbitrary and re-associate + it with the DIType or an implementation of this interface as there may be many such mappings to choose from. + + + + + LLVM NativeType this interface is associating with debug info in + + + Debug information type this interface is associating with + + + Creates a new instance inferring the generic arguments from the parameters + Type of the Native LLVM type for the association + Type of the debug information type for the association + type instance for this association + type instance for this association + implementation for the specified association + + + Convenience extensions for determining if the property is valid + + In LLVM Debug information a is + used to represent the void type. Thus, looking only at the property is + insufficient to distinguish between a type with no debug information and one representing the void + type. This property is used to disambiguate the two possibilities. + + + + Generic wrapper to treat an MDTuple as an array of elements of specific type + Type of elements + + This treats the operands of a tuple as the elements of the array + + + + Debug information binding between an LLVM native and a + + This class provides a binding between an LLVM type and a corresponding . + In LLVM all primitive types are unnamed and interned. That is, any use of an i8 is always the same + type. However, at the source language level it is common to have named primitive types that map + to the same underlying LLVM. For example, in C and C++ char maps to i8 but so does unsigned char + (LLVM integral types don't have signed vs unsigned). This class is designed to handle this sort + of one to many mapping of the lower level LLVM types to source level debugging types. Each + instance of this class represents a source level basic type and the corresponding representation + for LLVM. + + + + Create a debug type for a basic type + Type to wrap debug information for + Module to use when constructing the debug information + Source language name of the type + Encoding for the type + + + This class provides debug information binding for an + and a + + + Function signatures are unnamed interned types in LLVM. While there is usually a one + to one mapping between an LLVM function signature type and the source language debug + signature type that isn't always true. In particular, when passing data by value. In + cases where the address of a by value structure is needed a common pattern is to use + a pointer to the structure in the signature, then perform an Alloca + memcpy. The + actual approach taken depends on the calling conventions of the target. In these cases + you get an LLVM signature that doesn't match the source and could actually match another + source function where a pointer to the structure is actually used in the source. + For example, the following two C language functions might use the same LLVM signature: + void foo(struct bar) + void foo2(struct bar*) + Implementing both of those might be done in LLVM with a single signature: + void (%struct.bar*) + This class is designed to provide mapping between the debug signature type + and the underlying LLVM type + It is important to keep in mind that signatures are only concerned + with types. That is, they do not include names of parameters. Parameter information is + provided by + and + + + + Constructs a new + Native LLVM function signature + to use when construction debug information + for this signature + Return type for the function + Potentially empty set of argument types for the signature + + + + + + + + + + + + DebugInfoBuilder is a factory class for creating DebugInformation for an LLVM + + + Many Debug information metadata nodes are created with unresolved references to additional + metadata. To ensure such metadata is resolved applications should call the + method to resolve and finalize the metadata. After this point only fully resolved nodes may + be added to ensure that the data remains valid. + + + + Module that owns this builder + + + Creates a new + for the compilation unit + Full path to the source file of this compilation unit + Name of the application processing the compilation unit + Flag to indicate if the code in this compilation unit is optimized + Additional tool specific flags + Runtime version + + + + Creates a new + for the compilation unit + Name of the source file of this compilation unit (without any path) + Path of the directory containing the file + Name of the application processing the compilation unit + Flag to indicate if the code in this compilation unit is optimized + Additional tool specific flags + Runtime version + + + + Creates a + Containing scope for the namespace or null if the namespace is a global one + Name of the namespace + export symbols + + + + Creates a + Path of the file (may be or empty) + + or if + is empty, or all whitespace + + + + Creates a + Name of the file (may be or empty) + Path of the directory containing the file (may be or empty) + + or if + is empty, or all whitespace + + + + Creates a new + for the block + containing the block + Starting line number for the block + Starting column for the block + + created from the parameters + + + + Creates a + for the block + + Discriminator to disambiguate lexical blocks with the same file info + + constructed from the parameters + + + + Create a with debug information + for the function + Name of the function as it appears in the source language + Linkage (mangled) name of the function + containing the function + starting line of the function definition + for the function's signature type + Flag to indicate if this function is local to the compilation unit or available externally + Flag to indicate if this is a definition or a declaration only + starting line of the first scope of the function's body + for this function + Flag to indicate if this function is optimized + Underlying LLVM to attach debug info to + Template parameter [default = null] + Template declarations [default = null] + + + Creates a new forward declaration to a function + for the declaration + Name of the function as it appears in source + mangled name of the function (for linker) + Source file location for the function + starting line of the declaration + Signature for the function + Flag to indicate if this declaration is local to the compilation unit + Flag to indicate if this is a definition + Line of the first scope block + for the function + Flag to indicate if the function is optimized + + + + Creates an argument for a function as a + Scope for the argument + Name of the argument + containing the function this argument is declared in + Line number fort his argument + Debug type for this argument + Flag to indicate if this argument is always preserved for debug view even if optimization would remove it + for this argument + One based argument index on the method (e.g the first argument is 1 not 0 ) + representing the function argument + + + Construct debug information for a basic type (a.k.a. primitive type) + Name of the type + Bit size for the type + encoding for the type + + + + Accessibility flags + + The three accessibility flags are mutually exclusive and rolled together + in the first two bits. + + + + Common implementation of + + This class implements through an + internal + + + + + + + + + + Provides consistent accessors for an extended property + Type of values stored in the property + + This class is used to describe a property stored in a class implementing + . Using a single, typically + , instance of this class to describe and access + an extended property helps to encapsulate the type casting and property + ID into a single place. Making calling code easier to comprehend and + less prone to typographical errors that a compiler can't catch ahead of + time. + + + + Creates a new instance of a property descriptor + Name of the extended property + + + Gets a value for the property from the container + container + Value retrieved from the property or the default value of type + + + Gets a value for the property from the container + container + default value if the value is not yet present as an extended property + Value retrieved from the property or if it wasn't found + If the value didn't exist a new value with is added to the container + + + Gets a value for the property from the container + container + default value factory delegate to create the default value if the value is not yet present as an extended property + Value retrieved from the property or default value created by if it wasn't found + If the value didn't exist a new value created by calling with is added to the container + + + Sets the value of an extended property in a container + Container to set the value in + value of the property + + + Name of the property + + + Provides extension methods to that cannot be achieved as members of the class + + Using generic static extension methods allows for fluent coding while retaining the type of the "this" parameter. + If these were members of the class then the only return type could be + thus losing the original type and requiring a cast to get back to it, thereby defeating the purpose of the fluent style. + + + + Fluent style extension method to set the for an instruction + Type of the instruction (usually implicitly inferred from usage) + Instruction to set the for + New alignment for the instruction + To allow fluent style coding this returns the parameter + + + Fluent style extension method to set the Volatile property of a or instruction + Type of the instruction (usually implicitly inferred from usage) + Instruction to set the Volatile property for + Flag to indicate if the instruction's operation is volatile + To allow fluent style coding this returns the parameter + + + LLVM Instruction builder allowing managed code to generate IR instructions + + + Initializes a new instance of the class for a given + Context used for creating instructions + + + Initializes a new instance of the class for a + Block this builder is initially attached to + + + Gets the context this builder is creating instructions for + + + Gets the this builder is building instructions for + + + Positions the builder at the end of a given + Block to set the poition of + + + Positions the builder before the given instruction + Instruction to position the builder before + This method will position the builder to add new instructions + immediately before the specified instruction. + It is important to keep in mind that this can change the + block this builder is targeting. That is, + is not required to come from the same block the instruction builder is + currently referencing. + + + + Builds an LLVM Store instruction + Value to store in destination + value for the destination + instruction + + Since store targets memory the type of + must be an . Furthermore, the element type of + the pointer must match the type of . Otherwise, + an is thrown. + + + + Creates a that accesses an element (field) of a structure + pointer to the structure to get an element from + element index + + for the member access. This is a + as LLVM may optimize the expression to a if it + can so the actual type of the result may be + or . + Note that must be a pointer to a structure + or an exception is thrown. + + + + Creates a that accesses an element of a type referenced by a pointer + pointer to get an element from + additional indices for computing the resulting pointer + + for the member access. This is a + as LLVM may optimize the expression to a if it + can so the actual type of the result may be + or . + Note that must be a pointer to a structure + or an exception is thrown. + + + For details on GetElementPointer (GEP) see http://llvm.org/docs/GetElementPtr.html. The + basic gist is that the GEP instruction does not access memory, it only computes a pointer + offset from a base. A common confusion is around the first index and what it means. For C + and C++ programmers an expression like pFoo->bar seems to only have a single offset or + index. However, that is only syntactic sugar where the compiler implicitly hides the first + index. That is, there is no difference between pFoo[0].bar and pFoo->bar except that the + former makes the first index explicit. In order to properly compute the offset for a given + element in an aggregate type LLVM requires an explicit first index even if it is zero. + + + + Creates a that accesses an element of a type referenced by a pointer + pointer to get an element from + additional indices for computing the resulting pointer + + for the member access. This is a + as LLVM may optimize the expression to a if it + can so the actual type of the result may be + or . + Note that must be a pointer to a structure + or an exception is thrown. + + + For details on GetElementPointer (GEP) see http://llvm.org/docs/GetElementPtr.html. The + basic gist is that the GEP instruction does not access memory, it only computes a pointer + offset from a base. A common confusion is around the first index and what it means. For C + and C++ programmers an expression like pFoo->bar seems to only have a single offset or + index. However that is only syntactic sugar where the compiler implicitly hides the first + index. That is, there is no difference between pFoo[0].bar and pFoo->bar except that the + former makes the first index explicit. In order to properly compute the offset for a given + element in an aggregate type LLVM requires an explicit first index even if it is zero. + + + + Creates a that accesses an element of a type referenced by a pointer + pointer to get an element from + additional indices for computing the resulting pointer + + for the member access. This is a + as LLVM may optimize the expression to a if it + can so the actual type of the result may be + or . + Note that must be a pointer to a structure + or an exception is thrown. + + + For details on GetElementPointer (GEP) see http://llvm.org/docs/GetElementPtr.html. The + basic gist is that the GEP instruction does not access memory, it only computes a pointer + offset from a base. A common confusion is around the first index and what it means. For C + and C++ programmers an expression like pFoo->bar seems to only have a single offset or + index. However, that is only syntactic sugar where the compiler implicitly hides the first + index. That is, there is no difference between pFoo[0].bar and pFoo->bar except that the + former makes the first index explicit. In order to properly compute the offset for a given + element in an aggregate type LLVM requires an explicit first index even if it is zero. + + + + Creates a that accesses an element of a type referenced by a pointer + pointer to get an element from + additional indices for computing the resulting pointer + + for the member access. This is a User as LLVM may + optimize the expression to a if it + can so the actual type of the result may be + or . + Note that must be a pointer to a structure + or an exception is thrown. + + + For details on GetElementPointer (GEP) see http://llvm.org/docs/GetElementPtr.html. The + basic gist is that the GEP instruction does not access memory, it only computes a pointer + offset from a base. A common confusion is around the first index and what it means. For C + and C++ programmers an expression like pFoo->bar seems to only have a single offset or + index. However that is only syntactic sugar where the compiler implicitly hides the first + index. That is, there is no difference between pFoo[0].bar and pFoo->bar except that the + former makes the first index explicit. LLVM requires an explicit first index even if it is + zero, in order to properly compute the offset for a given element in an aggregate type. + + + + Builds a cast from an integer to a pointer + Integer value to cast + pointer type to return + Resulting value from the cast + + The actual type of value returned depends on + and is either a or an + instruction. Conversion to a constant expression is performed whenever possible. + + + + Builds a cast from a pointer to an integer type + Pointer value to cast + Integer type to return + Resulting value from the cast + + The actual type of value returned depends on + and is either a or a + instruction. Conversion to a constant expression is performed whenever possible. + + + + Builds an Integer compare instruction + Integer predicate for the comparison + Left hand side of the comparison + Right hand side of the comparison + Comparison instruction + + + Builds a Floating point compare instruction + predicate for the comparison + Left hand side of the comparison + Right hand side of the comparison + Comparison instruction + + + Builds a compare instruction + predicate for the comparison + Left hand side of the comparison + Right hand side of the comparison + Comparison instruction + + + Builds a instruction + Value for the condition to select between the values + Result value if evaluates to 1 + Result value if evaluates to 0 + Selected value + + If is a vector then both values must be a vector of the same + size and the selection is performed element by element. The values must be the same type. + + + + Builds a memcpy intrinsic call + Destination pointer of the memcpy + Source pointer of the memcpy + length of the data to copy + Alignment of the data for the copy + Flag to indicate if the copy involves volatile data such as physical registers + call for the memcpy + + LLVM has many overloaded variants of the memcpy intrinsic, this implementation will deduce the types from + the provided values and generate a more specific call without the need to provide overloaded forms of this + method and otherwise complicating the calling code. + + + + Builds a memcpy intrinsic call + Module to add the declaration of the intrinsic to if it doesn't already exist + Destination pointer of the memcpy + Source pointer of the memcpy + length of the data to copy + Alignment of the data for the copy + Flag to indicate if the copy involves volatile data such as physical registers + call for the memcpy + + LLVM has many overloaded variants of the memcpy intrinsic, this implementation will deduce the types from + the provided values and generate a more specific call without the need to provide overloaded forms of this + method and otherwise complicating the calling code. + + + + Builds a memmov intrinsic call + Destination pointer of the memmov + Source pointer of the memmov + length of the data to copy + Alignment of the data for the copy + Flag to indicate if the copy involves volatile data such as physical registers + call for the memmov + + LLVM has many overloaded variants of the memmov intrinsic, this implementation currently assumes the + single form defined by , which matches the classic "C" style memmov + function. However future implementations should be able to deduce the types from the provided values + and generate a more specific call without changing any caller code (as is done with + .) + + + + Builds a memmov intrinsic call + Module to add the declaration of the intrinsic to if it doesn't already exist + Destination pointer of the memmov + Source pointer of the memmov + length of the data to copy + Alignment of the data for the copy + Flag to indicate if the copy involves volatile data such as physical registers + call for the memmov + + LLVM has many overloaded variants of the memmov intrinsic, this implementation currently assumes the + single form defined by , which matches the classic "C" style memmov + function. However future implementations should be able to deduce the types from the provided values + and generate a more specific call without changing any caller code (as is done with + .) + + + + Builds a memset intrinsic call + Destination pointer of the memset + fill value for the memset + length of the data to fill + ALignment of the data for the fill + Flag to indicate if the fill involves volatile data such as physical registers + call for the memset + + LLVM has many overloaded variants of the memset intrinsic, this implementation currently assumes the + single form defined by , which matches the classic "C" style memset + function. However future implementations should be able to deduce the types from the provided values + and generate a more specific call without changing any caller code (as is done with + .) + + + + Builds a memset intrinsic call + Module to add the declaration of the intrinsic to if it doesn't already exist + Destination pointer of the memset + fill value for the memset + length of the data to fill + ALignment of the data for the fill + Flag to indicate if the fill involves volatile data such as physical registers + call for the memset + + LLVM has many overloaded variants of the memset intrinsic, this implementation currently assumes the + single form defined by , which matches the classic "C" style memset + function. However future implementations should be able to deduce the types from the provided values + and generate a more specific call without changing any caller code (as is done with + .) + + + + Default for the switch + + + Adds a new case to the instruction + Value for the case to match + Destination if the case matches + + + Exposes an LLVM Instruction + + + Block that contains this instruction + + + Gets the LLVM opcode for the instruction + + + Flag to indicate if the opcode is for a memory access , , + + + Alignment for the instruction + + The alignment is always 0 for instructions other than Alloca, Load, and Store + that deal with memory accesses. Setting the alignment for other instructions + results in an InvalidOperationException() + + + + Support class to provide readonly list semantics to the operands of an MDNode + + + This is an internal duplicate of Extensions added to CoreFx. + + This is duped here to enable use in down-level runtimes. Furthermore, it uses a different + name and is marked internal to prevent conflicts with the official implementation when + built for runtimes supporting that. (See: https://github.com/dotnet/corefx/pull/5947) + + + + Base class for LLVM disposable types that are instantiated outside of an LLVM and therefore won't be disposed by the context + + + Static constructor for NativeMethods + + + Dynamically loads a DLL from a directory dependent on the current architecture + name of the DLL + Root path to find the DLL from + Handle for the DLL + + This method will detect the architecture the code is executing on (i.e. x86 or x64) + and will load the DLL from an architecture specific sub folder of . + This allows use of AnyCPU builds and interop to simplify build processes from needing to + deal with "mixed" configurations or other accidental combinations that are a pain to + sort out and keep straight when the tools insist on creating AnyCPU projects and "mixed" configurations + by default. + If the Is , empty or all whitespace then + the standard DLL search paths are used. This assumes the correct variant of the DLL is available + (e.g. for a 32 bit system a 32 bit native DLL is found). This allows for either building as AnyCPU + plus shipping multiple native DLLs, or building for a specific CPU type while shipping only one native + DLL. Different products or projects may have different needs so this covers those cases. + + + + + Root of the LLVM Metadata hierarchy + In LLVM this is just "Metadata" however that name has the potential + to conflict with the .NET runtime namespace of the same name, so the name + is changed in the .NET bindings to avoid the conflict. + + + Replace all uses of this descriptor with another + New descriptor to replace this one with + + + + + + Enumeration to define debug information metadata nodes + + + Wraps an LLVM NamedMDNode + Despite its name a NamedMDNode is not itself an MDNode. + + + Triple to describe a target + + The term 'Triple' is a bit of a misnomer. At some point in the past it + actually consisted of only three parts, but that has changed over the years + without the name itself changing. The triple is normally represented as a + string of 4 components delimited by '-'. Some of the components have + sub components as part of the content. The canonical form of a triple is: + {Architecture}{SubArchitecture}-{Vendor}-{OS}-{Environment}{ObjectFormat} + + A few shorthand variations are allowed and converted to their full normalized form. + In particular "cygwin" is a shorthand for the OS-Environment tuple "windows-cygnus" + and "mingw" is a shorthand form of "windows-gnu". + + In addition to shorthand allowances, the OS component may optionally include + a trailing version of the form Maj.Min.Micro. If any of the version number parts are + not present, then they default to 0. + + For the environment "androideabi" is allowed and normalized to android (including + an optional version number). + + + + + Constructs a new instance from a triple string + Triple string to parse + + The string is normalized before parsing to allow for + common non-canonical forms of triples. + + + + Retrieves the final string form of the triple + Normalized Triple string + + + Architecture of the triple + + + Sub Architecture type + + + Vendor component of the triple + + + OS Type for the triple + + + Environment type for the triple + + + Object format type for the triple + + + Retrieves the canonical name for an architecture type + Architecture type + String name for the architecture + + Many parts of a triple can take a variety of literal string + forms to allow for common real world triples when parsing. + The GetCanonicalName methods provide the canonical form of + such triple components used in a normalized triple. + + + + Retrieves the canonical name for an architecture sub type + Architecture sub type + String name for the architecture sub type + + + Retrieves the canonical name for the vendor component of a triple + Vendor type + String name for the vendor + + + Retrieves the canonical name for the OS component of a triple + OS type + String name for the OS + + + Retrieves the canonical name for the environment component of a triple + Environment type + String name for the environment component + + + Retrieves the canonical name for the object component of a triple + Object type + String name for the object component + + + Equality test for a triple + triple to compare this triple to + if the two triples are equivalent + + + Equality test for a triple + object to compare this triple to + if the two triples are equivalent + + + + + + Normalizes a triple string + triple to normalize + Normalized string + + + Gets the default for a given and + Architecture type + Operating system type + Default object format + + + Provides the canonical Architecture form for a given architecture sub architecture pair + Architecture type + Sub Architecture type + Canonical + + Some architectures, particularly ARM variants, have multiple sub-architecture types that + have a canonical form (i.e. Arch=; SubArch=; + has the Canonical Arch of ). This method retrieves the canonical Arch + for a given architecture,SubArchitecture pair. + + + + Interface for a Type in LLVM + + + LibLLVM handle for the type + + + Flag to indicate if the type is sized + + + LLVM Type kind for this type + + + Flag to indicate if this type is an integer + + + Flag to indicate if this type represents the void type + + + Flag to indicate if this type is a structure type + + + Flag to indicate if this type is a pointer + + + Flag to indicate if this type is a sequence type + + + Flag to indicate if this type is a floating point type + + + FLag to indicate if this type is a pointer to a pointer + + + Context that owns this type + + + Integer bit width of this type or 0 for non integer types + + + Gets a null value (e.g. all bits == 0 ) for the type + + This is a getter function instead of a property as it can throw exceptions + for types that don't support such a thing (i.e. void ) + + + + Array type factory for an array with elements of this type + Number of elements in the array + for the array + + + Get a for a type that points to elements of this type in the default (0) address space + corresponding to the type of a pointer that refers to elements of this type + + + Get a for a type that points to elements of this type in the specified address space + Address space for the pointer + corresponding to the type of a pointer that refers to elements of this type + + + Interface for an LLVM array type + + + Length of the array + + + Array type definition + + Array's in LLVM are fixed length sequences of elements + + + + Length of the array + + + Interface to represent the LLVM type of a function (e.g. a signature) + + + Flag to indicate if this signature is for a variadic function + + + Return type of the function + + + Collection of types of the parameters for the function + + + Class to represent the LLVM type of a function (e.g. a signature) + + + + + + + + + + + + Interface for an LLVM sequence type + + Sequence types represent a sequence of elements of the same type + that are contiguous in memory. These include Vectors, Arrays, and + pointers. + + + + Type of elements in the sequence + + + Interface for a named type with members + This is a common interface for structures and unions + + + Name of the structure + + + Indicates if the structure is opaque (e.g. has no body defined yet) + + + List of types for all member elements of the structure + + + Interface for an LLVM structure type + + + Indicates if the structure is packed (e.g. no automatic alignment padding between elements) + + + Sets the body of the structure + Flag to indicate if the body elements are packed (e.g. no padding) + Optional types of each element + + To set the body , at least one element type is required. If none are provided this is a NOP. + + + + LLVM Type + + + Flag to indicate if the type is sized + + + LLVM Type kind for this type + + + Flag to indicate if the type is a sequence type + + + Context that owns this type + + + Integer bid width of this type or 0 for non integer types + + + Gets a null value (e.g. all bits = 0 ) for the type + This is a getter function instead of a property as it can throw exceptions + + + Array type factory for an array with elements of this type + Number of elements in the array + for the array + + + Get a for a type that points to elements of this type in the default (0) address space + corresponding to the type of a pointer that referns to elements of this type + + + Get a for a type that points to elements of this type in the specified address space + Address space for the pointer + corresponding to the type of a pointer that referns to elements of this type + + + Builds a string representation for this type in LLVM assembly language form + Formatted string for this type + + + Interface for a pointer type in LLVM + + + Address space the pointer refers to + + + LLVM pointer type + + + Address space the pointer refers to + + + An LLVM Value representing an Argument to a function + + + Function this argument belongs to + + + Zero based index of the argument + + + Sets the alignment for the argument + Alignment value for this argument + + + Enumeration for the known LLVM attributes + + It is important to note that the integer values of this enum + do NOT necessarily correlate to the attribute IDs. LLVM has + moved away from using an enum Flags model as the number of + attributes reached the limit of available bits. Thus, the + enum was dropped as of V5.0. Instead, strings are used to + identify attributes. However, for maximum compatibility and + ease of use for this library the enum is retained and the + provided attribute manipulation classes will map the enum + to the associated string. + Also note that as a reult of the changes in LLVM this + set of attributes is fluid and subject to change from version + to version. Thus, code using any attributes that have changed + or were removed will produce compile time errors. That is useful + and by design so that any changes in LLVM naming will break at + compile time instead of at runtime. + + + + Enumeration flags to indicate which attribute set index an attribute may apply to + + + Invalid attributes don't apply to any index + + + The attribute is applicable to a function + + + The attribute is applicable to a function's return + + + The attribute is applicable to a function's parameter + + + Utility class to provide extension methods for validating usage of attribute kinds + + + Single attribute for functions, function returns and function parameters + + This is the equivalent to the underlying llvm::AttributeImpl class. The name was changed to + AttributeValue in .NET to prevent confusion with the standard class + that is used throughout .NET libraries. + + + + Kind of the attribute, for target specific named attributes + + + Name of a named attribute or null for other kinds of attributes + + + StringValue for named attributes with values + + + Integer value of the attribute or null if the attribute doesn't have a value + + + Flag to indicate if this attribute is a target specific string value + + + Flag to indicate if this attribute has an integer attribute + + + Flag to indicate if this attribute is a simple enumeration value + + + Implicitly cast an to an + Kind of attribute to create + Context that should own the attribute value + + + Implicitly cast a string to an named + Attribute name + Context that should own the attribute value + + + Provides access to an LLVM Basic block + + A basic block is a sequence of instructions with a single entry + and a single exit. The exit point must be a + instruction or the block is not (yet) well-formed. + + + + Gets the function containing the block + + + First instruction in the block + + + Last instruction in the block + + + Terminator instruction for the block + May be null if the block is not yet well-formed + as is commonly the case while generating code for a new block + + + + Enumerable collection of all instructions in the block + + + Gets the instruction that follows a given instruction in a block + instruction in the block to get the next instruction from + Next instruction or null if none + Thrown when is from a different block + + + Contains an LLVM Constant value + + + Indicates if the constant is a Zero value for the its type + + + Create a NULL pointer for a given type + Type of pointer to create a null vale for + Constant NULL pointer of the specified type + + + Creates a constant instance of with all bits in the instance set to 1 + Type of value to create + Constant for the type with all instance bits set to 1 + + + Creates an representing an undefined value for + Type to create the undefined value for + + representing an undefined value of + + + + Create a constant NULL pointer for a given type + Type of pointer to create a null value for + Constant NULL pointer of the specified type + + + LLVM Constant Array + + Due to how LLVM treats constant arrays internally creating a constant array + with the From method overloads may not actually produce a ConstantArray + instance. At the least it will produce a Constant. LLVM will determine the + appropriate internal representation based on the input types and values + + + + Create a constant array of values of a given type + Type of elements in the array + Values to initialize the array + Constant representing the array + + + Create a constant array of values of a given type with a fixed size, zero filling any un-specified values + Type of elements in the array + Length of the array + Values to initialize the array + Constant representing the array + + If the number of arguments provided for the values is less than + then the remaining elements of the array are set with the null value for the + + + + Create a constant array of values of a given type + Type of elements in the array + Values to initialize the array + Constant representing the array + + + + A vector or array constant whose element type is a simple 1/2/4/8-byte integer + or float/double, and whose elements are just simple data values + (i.e. ConstantInt/ConstantFP). + + + This Constant node has no operands because + it stores all of the elements of the constant as densely packed data, instead + of as s + + + + While technically a type in LLVM, ConstantExpression is primarily a static factory for Constants + + + Floating point constant value in LLVM + + + Represents an arbitrary bit width integer constant in LLVM + + Note - for integers, in LLVM, signed or unsigned is not part of the type of + the integer. The distinction between them is determined entirely by the + instructions used on the integer values. + + + + Retrieves the value of the constant zero extended to 64 bits + + + Sign extends the value to a 64 bit value + + + Creates a constant null pointer to a given type + + + + + LLVM Function definition + + + Signature type of the function + + + Entry block for this function + + + Basic Blocks for the function + + + Parameters for the function including any method definition specific attributes (i.e. ByVal) + + + Calling convention for the method + + + LLVM instrinsicID for the method + + + Flag to indicate if the method signature accepts variable arguments + + + Return type of the function + + + Debug information for this function + + + Garbage collection engine name that this function is generated to work with + For details on GC support in LLVM see: http://llvm.org/docs/GarbageCollection.html + + + Verifies the function is valid and all blocks properly terminated + + + Add a new basic block to the beginning of a function + Name (label) for the block + created and inserted at the beginning of the function + + + Appends a new basic block to a function + Name (label) of the block + created and inserted onto the end of the function + + + Retrieves or creates block by name + Block name (label) to look for or create + If the block was created it is appended to the end of function + + This method tries to find a block by it's name and returns it if found, if not found a new block is + created and appended to the current function. + + + + LLVM Global Alias for a function or global value + + + Alignment requirements for this object + + + Linker section this object belongs to + + + Gets or sets the comdat attached to this object, if any + + Setting this property to or an + empty string will remove any comdat setting for the + global object. + + + + Fluent style extensions for properties of + + + LLVM Global value + + + Visibility of this global value + + + Linkage specification for this symbol + + + Flag to indicate if this is an Unnamed address + + + Flag to indicate if this is a declaration + + + Module containing this global value + + + Fluent style extensions for modifying properties of a + + + Visibility of this global value + + + Linkage specification for this symbol + + + An LLVM Global Variable + + + Flag to indicate if this variable is initialized in an external module + + + Gets or sets if this global is a Constant + + + Flag to indicate if this global is stored per thread + + + Initial value for the variable + + + Removes the value from its parent module, but does not delete it + + + Support class to provide read only list semantics to the parameters of a method + + + Interface to an Attribute Dictionary + + This interface provides a full collection of all the + attributes keyed by the + + This connceptually corresponds to the functionality of the + LLVM AttributeSet class for Versions prior to 5. (at this + time v5 is not yet released). In 5 the equivalent type is + currently AttributeList. In v5 AttributeSet has no index and + is therefore more properly a set than in the past. To help + remove confusion and satisfy naming rules this is called + a Dictionary as that reflects the use here and fits the + direction of LLVM + + + + LLVM Use, which is essentially a tuple of the and the used + + A Use in LLVM forms a link in a directed graph of dependencies for values. + + + + Contains an LLVM User value + + A user is one role in the user->uses relationship + conveyed by the LLVM value model. A User can contain + references (e.g. uses) of other values. + + + + Collection of operands + + + Enumerable collection of s + + + Support class to provide read-only list semantics to the operands of a of a method + + + LLVM Value + + Value is the root of a hierarchy of types representing values + in LLVM. Values (and derived classes) are never constructed + directly with the new operator. Instead, they are produced by + other classes in this library internally. This is because they + are just wrappers around the LLVM-C API handles and must + maintain the "uniqueing" semantics. (e.g. allowing reference + equality for values that are fundamentally the same value) + This is generally hidden in the internals of the Llvm.NET + library so callers need not be concerned with the details + but can rely on the expected behavior that two Value instances + referring to the same actual value (i.e. a function) are actually + the same .NET object as well within the same + + + + Gets or sets name of the value (if any) + + + Gets a value indicating whether this value is Undefined + + + Gets a value indicating whether the Value represents the NULL value for the values type + + + Gets the type of the value + + + Generates a string representing the LLVM syntax of the value + string version of the value formatted by LLVM + + + Replace all uses of a with another one + New value + + + + + + + + + Gets an Llvm.NET managed wrapper for a LibLLVM value handle + Value handle to wrap + LLVM.NET managed instance for the handle + + This method uses a cached mapping to ensure that two calls given the same + input handle returns the same managed instance so that reference equality + works as expected. + + + + Gets an Llvm.NET managed wrapper for a LibLLVM value handle + Required type for the handle + Value handle to wrap + LLVM.NET managed instance for the handle + + This method uses a cached mapping to ensure that two calls given the same + input handle returns the same managed instance so that reference equality + works as expected. + + When the handle is for a different type of handle than specified by + + + Central factory for creating instances of and all derived types + LibLLVM handle for the value + New Value or derived type instance that wraps the underlying LibLLVM handle + + This method will determine the correct type for the handle and construct an instance of that + type wrapping the handle. + + + + Provides extension methods to that cannot be achieved as members of the class + + Using generic static extension methods allows for fluent coding while retaining the type of the "this" parameter. + If these were members of the class then the only return type could be , + thus losing the original type and requiring a cast to get back to it. + + + + Sets the debugging location for a value + Type of the value to tag + Value to set debug location for + Debug location information + + Technically speaking only an can have debug location + information. However, since LLVM will perform constant folding in the + most of the methods in return a rather than a + more specific . Thus, without this extension method here, + code would need to know ahead of time that an actual instruction would be produced then cast the result + to an and then set the debug location. This makes the code rather + ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches + the original and no additional casting is needed, which would defeat the purpose of doing this. For + types that are not instructions this does nothing. This allows for a simpler fluent + style of programming where the actual type is retained even in cases where an + method will always return an actual instruction. + In order to help simplify code generation for cases where not all of the source information is + available this is a NOP if is null. Thus, it is safe to call even when debugging + information isn't actually available. This helps to avoid cluttering calling code with test for debug info + before trying to add it. + + + + Sets the debugging location for a value + Type of the value to tag + Value to set debug location for + Line number + Column number + Scope for the value + + Technically speaking only an can have debug location + information. However, since LLVM will perform constant folding in the + most of the methods in return a rather than a + more specific . Thus, without this extension method here, + code would need to know ahead of time that an actual instruction would be produced then cast the result + to an and then set the debug location. This makes the code rather + ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches + the original and no additional casting is needed, which would defeat the purpose of doing this. For + types that are not instructions this does nothing. This allows for a simpler fluent + style of programming where the actual type is retained even in cases where an + method will always return an actual instruction. + In order to help simplify code generation for cases where not all of the source information is + available this is a NOP if is null. Thus, it is safe to call even when debugging + information isn't actually available. This helps to avoid cluttering calling code with test for debug info + before trying to add it. + + + + Sets the virtual register name for a value + Type of the value to set the name for + Value to set register name for + Name for the virtual register the value represents + + Technically speaking only an can have register name + information. However, since LLVM will perform constant folding in the + it almost all of the methods in return a rather + than an more specific . Thus, without this extension method here, + code would need to know ahead of time that an actual instruction would be produced then cast the result + to an and then set the debug location. This makes the code rather + ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches + the original and no additional casting is needed, which would defeat the purpose of doing this. For + types that are not instructions this does nothing. This allows for a simpler fluent + style of programming where the actual type is retained even in cases where an + method will always return an actual instruction. + Since the property is available on all s this is slightly + redundant. It is useful for maintaining the fluent style of coding along with expressing intent more clearly. + (e.g. using this makes it expressly clear that the intent is to set the virtual register name and not the + name of a local variable etc...) Using the fluent style allows a significant reduction in the number of + overloaded methods in to account for all variations with or without a name. + + + + + Encapsulates an LLVM context + + A context in LLVM is a container for interning (LLVM refers + to this as "uniqueing") various types and values in the system. This + allows running multiple LLVM tool transforms etc.. on different threads + without causing them to collide namespaces and types even if they use + the same name (e.g. module one may have a type Foo, and so does module + two but they are completely distinct from each other) + + LLVM Debug information is ultimately all parented to a top level + as the scope, and a compilation + unit is bound to a , even though, technically + the types are owned by a Context. Thus to keep things simpler and help + make working with debug information easier. Lllvm.NET encapsulates the + native type and the debug type in separate classes that are instances + of the interface + It is important to be aware of the fact that a Context + is not thread safe. The context itself and the object instances it owns + are intended for use by a single thread only. Accessing and manipulating + LLVM objects from multiple threads may lead to race conditions corrupted + state and any number of other undefined issues. + + + + Creates a new context + + + Flag to indicate if this instance is still valid + + + Get's the LLVM void type for this context + + + Get's the LLVM boolean type for this context + + + Get's the LLVM 8 bit integer type for this context + + + Get's the LLVM 16 bit integer type for this context + + + Get's the LLVM 32 bit integer type for this context + + + Get's the LLVM 64 bit integer type for this context + + + Get's the LLVM half precision floating point type for this context + + + Get's the LLVM single precision floating point type for this context + + + Get's the LLVM double precision floating point type for this context + + + Gets an enumerable collection of all the metadata created in this context + + + Get a type that is a pointer to a value of a given type + Type of value the pointer points to + for a pointer that references a value of type + + + Get's an LLVM integer type of arbitrary bit width + + For standard integer bit widths (e.g. 1,8,16,32,64) this will return + the same type as the corresponding specialized property. + (e.g. GetIntType(1) is the same as , + GetIntType(16) is the same as , etc... ) + + + + Get an LLVM Function type (e.g. signature) + Return type of the function + Optional set of function argument types + Signature type for the specified signature + + + Get an LLVM Function type (e.g. signature) + Return type of the function + Potentially empty set of function argument types + Signature type for the specified signature + + + Get an LLVM Function type (e.g. signature) + Return type of the function + Potentially empty set of function argument types + Flag to indicate if the method supports C/C++ style VarArgs + Signature type for the specified signature + + + Creates a FunctionType with Debug information + to use to create the debug information + Return type of the function + Argument types of the function + Function signature + + + Creates a FunctionType with Debug information + to use to create the debug information + Return type of the function + Argument types of the function + Function signature + + + Creates a FunctionType with Debug information + to use to create the debug information + Flag to indicate if this function is variadic + Return type of the function + Argument types of the function + Function signature + + + Creates a FunctionType with Debug information + to use to create the debug information + Flag to indicate if this function is variadic + Return type of the function + Argument types of the function + Function signature + + + Creates a constant structure from a set of values + Flag to indicate if the structure is packed and no alignment should be applied to the members + Set of values to use in forming the structure + Newly created + + The actual concrete return type depends on the parameters provided and will be one of the following: + + + derived typeDescription + + ConstantAggregateZeroIf all the member values are zero constants + UndefValueIf all the member values are UndefValue + ConstantStructAll other cases + + + + + + Creates a constant structure from a set of values + Set of values to use in forming the structure + Flag to indicate if the structure is packed and no alignment should be applied to the members + Newly created + + The actual concrete return type depends on the parameters provided and will be one of the following: + + + derived typeDescription + + ConstantAggregateZeroIf all the member values are zero constants + UndefValueIf all the member values are UndefValue + ConstantStructAll other cases + + + + + + Creates a constant instance of a specified structure type from a set of values + Type of the structure to create + Set of values to use in forming the structure + Newly created + + The actual concrete return type depends on the parameters provided and will be one of the following: + + + derived typeDescription + + ConstantAggregateZeroIf all the member values are zero constants + UndefValueIf all the member values are UndefValue + ConstantStructAll other cases + + + + + + Creates a constant instance of a specified structure type from a set of values + Type of the structure to create + Set of values to use in forming the structure + Newly created + + The actual concrete return type depends on the parameters provided and will be one of the following: + + + derived typeDescription + + ConstantAggregateZeroIf all the member values are zero constants + UndefValueIf all the member values are UndefValue + ConstantStructAll other cases + + + + + + Create an empty structure type + Name of the type + New type + + + Create an anonymous structure type (e.g. Tuple) + Flag to indicate if the structure is "packed" + Type of the first field of the structure + Types of any additional fields of the structure + + with the specified body defined. + + + + Creates a new structure type in this + Name of the structure + Flag indicating if the structure is packed + Types for the structures elements in layout order + + with the specified body defined. + + + If the elements argument list is empty then an opaque type is created (e.g. a forward reference) + The method provides a means to add a body to + an opaque type at a later time if the details of the body are required. (If only pointers to + to the type are required the body isn't required) + + + + Creates a metadata string from the given string + string to create as metadata + new metadata string + + + Create a constant data string value + string to convert into an LLVM constant value + new + + This converts th string to ANSI form and creates an LLVM constant array of i8 + characters for the data without any terminating null character. + + + + Create a constant data string value + string to convert into an LLVM constant value + flag to indicate if the string should include a null terminator + new + + This converts the string to ANSI form and creates an LLVM constant array of i8 + characters for the data without any terminating null character. + + + + Creates a new with a bit length of 1 + Value for the constant + representing the value + + + Creates a new with a bit length of 8 + Value for the constant + representing the value + + + Creates a new with a bit length of 8 + Value for the constant + representing the value + + + Creates a new with a bit length of 16 + Value for the constant + representing the value + + + Creates a new with a bit length of 16 + Value for the constant + representing the value + + + Creates a new with a bit length of 32 + Value for the constant + representing the value + + + Creates a new with a bit length of 32 + Value for the constant + representing the value + + + Creates a new with a bit length of 64 + Value for the constant + representing the value + + + Creates a new with a bit length of 64 + Value for the constant + representing the value + + + Creates a new with a bit length of 64 + Bit width of the integer + Value for the constant + flag to indicate if the const value should be sign extended + representing the value + + + Create a constant value of the specified integer type + Integer type + value + flag to indicate if is sign extended + Constant for the specified value + + + Creates a constant floating point value for a given value + Value to make into a + Constant value + + + Creates a constant floating point value for a given value + Value to make into a + Constant value + + + Creates a simple boolean attribute + Kind of attribute + + + Creates an attribute with an integer value parameter + The kind of attribute + Value for the attribute + + Not all attributes support a value and those that do don't all support + a full 64bit value. The following table provides the kinds of attributes + accepting a value and the allowed size of the values. + + Bit Length + 32 + 32 + 64 + 64 + + + + + Adds a valueless named attribute + Attribute name + + + Adds a Target specific named attribute with value + Name of the attribute + Value of the attribute + + + Enumeration to indicate the behavior of module level flags metadata sharing the same name in a + + + Invalid value (default value for this enumeration) + + + Emits an error if two values disagree, otherwise the resulting value is that of the operands + + + Emits a warning if two values disagree. The result will be the operand for the flag from the first module being linked + + + Adds a requirement that another module flag be present and have a specified value after linking is performed + + The value must be a metadata pair, where the first element of the pair is the ID of the module flag to be restricted, and the + second element of the pair is the value the module flag should be restricted to. This behavior can be used to restrict the + allowable results (via triggering of an error) of linking IDs with the behavior + + + + Uses the specified value, regardless of the behavior or value of the other module + If both modules specify Override, but the values differ, and error will be emitted + + + Appends the two values, which are required to be metadata nodes + + + Appends the two values, which are required to be metadata nodes dropping duplicate entries in the second list + + + Takes the max of the two values, which are required to be integers + + + LLVM Instruction opcodes + + These are based on the "C" API and therefore more stable as changes in the underlying instruction ids are remapped in the C API layer + + + + Basic kind of a type + + + Type with no size + + + 16 bit floating point type + + + 32 bit floating point type + + + 64 bit floating point type + + + 80 bit floating point type (X87) + + + 128 bit floating point type (112-bit mantissa) + + + 128 bit floating point type (two 64-bits) + + + instruction label + + + Arbitrary bit width integers + + + + + + + + + + + + + + + SIMD 'packed' format, or other implementation + + + + + + x86 MMX data type + + + Exception handler token + + + Calling Convention for functions + + + Linkage specification for functions and globals + + + Enumeration for the visibility of a global value + + + Unified predicate enumeration + + Underneath the C API this is what LLVM uses. For some reason the C API + split it into the integer and float predicate enumerations. + + + + Any value Greater than or equal to this is not valid for Fcmp operations + + + Any value Greater than or equal to this is not valid for Icmp operations + + + Predicate enumeration for integer comparison + + + Predicate enumeration for integer comparison + + + Optimization level for target code generation + + + Relocation type for target code generation + + + Code model to use for target code generation + + + Output file type for target code generation + + + Byte ordering for target code generation and data type layout + + + Function index for attributes + + Attributes on functions apply to the function itself, the return type + or one of the function's parameters. This enumeration is used to + identify where the attribute applies. + + + + The attribute applies to the function itself + + + The attribute applies to the return type of the function + + + The attribute applies to the first parameter of the function + + Additional parameters can identified by simply adding an integer value to + this value. (i.e. FunctionAttributeIndex.Parameter0 + 1 ) + + + + Interface to allow adding arbitrary named data items to an object + + It is sometimes useful for code generation applications to attach some tool specific + data to the LLVM objects created but that don't need representation as LLVM Metadata + nodes. This interface provides such a facility. + + + + Try to get a value from the container + Type of value to retrieve + id of the value to retrieve + value retrieved if present (or default value of type otherwise) + + true if the item was found and it's type matches false otherwise. + + + + Adds a value to the container + Id of the value + value to add + + Adds the value with the specified id. If a value with the same id + already exists and its type is the same as + it is replaced. If the existing value is of a different type, then + an ArgumentException is thrown. + + + + Exception generated when the internal state of the code generation cannot proceed due to an internal error + + + LLVM MemoryBuffer + + + Load a file as an LLVM Memory Buffer + Path of the file to load into a + + + Size of the buffer + + + LLVM Bitcode module + + A module is the basic unit for containing code in LLVM. Modules are an in memory + representation of the LLVM bit-code. + + + + Creates an unnamed module without debug information + + + Creates a new module with the specified id in a new context + Module's ID + + + Creates an named module in a given context + Module's ID + Context for the module + + + Creates a named module with a root to contain debugging information + Module name + Language to store in the debugging information + path of source file to set for the compilation unit + Name of the application producing this module + Flag to indicate if the module is optimized + Additional flags + Runtime version if any (use 0 if the runtime version has no meaning) + + + Creates a named module with a root to contain debugging information + Module name + Context for the module + Language to store in the debugging information + path of source file to set for the compilation unit + Name of the application producing this module + Flag to indicate if the module is optimized + Additional flags + Runtime version if any (use 0 if the runtime version has no meaning) + + + Name of the Debug Version information module flag + + + Name of the Dwarf Version module flag + + + Version of the Debug information Metadata + + + Comdats for this module + + + this module belongs to + + + to create debug information for this module + + + Debug Compile unit for this module + + + Data layout string + + Note the data layout string doesn't do what seems obvious. + That is, it doesn't force the target back-end to generate code + or types with a particular layout. Rather, the layout string has + to match the implicit layout of the target. Thus it should only + come from the actual the code is + targeting. + + + + Target data layout for this module + The layout is produced by parsing the + therefore this property changes anytime the is + set. Furthermore, setting this property will change the value of . + In other words, Layout and are two different views + of the same information. + + + + Target Triple describing the target, ABI and OS + + + Globals contained by this module + + + Enumerable collection of functions contained in this module + + + Name of the module + + + Run optimization passes on the module + for use during optimizations + + Options configuring optimization are provided by calling . + The current implementation uses the legacy pass manager architecture, thus the options for controlling passes + are the same as used for the LLVM 'opt' tool. Once LLVM stabilizes on the new pass manager support this + will be obsoleted in favor of a new method that takes a string representation of the optimizations in a manner + consistent with the support in the 'opt' tool. + + + + Verifies a bit-code module + Error messages describing any issues found in the bit-code + true if the verification succeeded and false if not. + + + Gets a function by name from this module + Name of the function to get + The function or null if not found + + + Add a function with the specified signature to the module + Name of the function to add + Signature of the function + matching the specified signature and name + + If a matching function already exists it is returned, and therefore the returned + may have a body and additional attributes. If a function of + the same name exists with a different signature an exception is thrown as LLVM does + not perform any function overloading. + + + + Writes a bit-code module to a file + Path to write the bit-code into + + This is a blind write. (e.g. no verification is performed) + So if an invalid module is saved it might not work with any + later stage processing tools. + + + + Writes this module as LLVM IR source to a file + File to write the LLVM IR source to + Error messages encountered, if any + if successful or if not + + + Creates a string representation of the module + LLVM textual representation of the module + + This is intentionally NOT an override of ToString() as that is + used by debuggers to show the value of a type and this can take + an extremely long time (up to many seconds depending on complexity + of the module) which is bad for the debugger. + + + + Add an alias to the module + Value being aliased + Name of the alias + for the alias + + + Get an alias by name + name of the alias to get + Alias matching or null if no such alias exists + + + Adds a global to this module with a specific address space + + Type of the global's value + Name of the global + The new + + - What does LLVM do if creating a second Global with the same name (return null, throw, crash??,...) + + + + Adds a global to this module + + Type of the global's value + Flag to indicate if this global is a constant + Linkage type for this global + Initial value for the global + New global variable + + + Adds a global to this module + + Type of the global's value + Flag to indicate if this global is a constant + Linkage type for this global + Initial value for the global + Name of the variable + New global variable + + + Adds a global to this module + Type of the global's value + Name of the global + The new + + - What does LLVM do if creating a second Global with the same name (return null, throw, crash??,...) + + + + Adds a global to this module + Type of the global's value + Flag to indicate if this global is a constant + Linkage type for this global + Initial value for the global + New global variable + + + Adds a global to this module + Type of the global's value + Flag to indicate if this global is a constant + Linkage type for this global + Initial value for the global + Name of the variable + New global variable + + + Retrieves a by name from the module + Name of the type + The type or null if no type with the specified name exists in the module + + + Retrieves a named global from the module + + + + + Adds a module flag to the module + Module flag behavior for this flag + Name of the flag + Value of the flag + + + Adds a module flag to the module + Module flag behavior for this flag + Name of the flag + Value of the flag + + + Adds operand value to named metadata + Name of the metadata + operand value + + + Adds an llvm.ident metadata string to the module + version information to place in the llvm.ident metadata + + + Create an from a string + String value + New node with the string as [0] (as an MDString) + + + Creates a Function definition with Debug information + Containing scope for the function + Name of the function in source language form + Mangled linker visible name of the function (may be same as if mangling not required by source language + File containing the function definition + Line number of the function definition + LLVM Function type for the signature of the function + Flag to indicate if this function is local to the compilation unit + Flag to indicate if this is a definition + First line of the function's outermost scope, this may not be the same as the first line of the function definition due to source formatting + Additional flags describing this function + Flag to indicate if this function is optimized + + + Function described by the arguments + + + Clones the current module + Cloned module + + + + + + + + + Load a bit-code module from a given file + path of the file to load + Context to use for creating the module + Loaded + + + Load bit code from a memory buffer + Buffer to load from + Context to load the module into + Loaded + + This along with are useful for "cloning" + a module from one context to another. This allows creation of multiple + modules on different threads and contexts and later moving them to a + single context in order to link them into a single final module for + optimization. + + + + Provides a wrapper around the LLVM PassManagerBuilder + This class is still in the experimental stage as there is a lack of full support from the C API + + + Target tools to register/enable + + + Register nothing + + + Register the Target class + + + Register the Target info for the target + + + Register the target machine(s) for a target + + + Registers the assembly source code generator for a target + + + Registers the Disassembler for a target + + + Registers the assembly source parser for a target + + + Registers all the code generation components + + + Registers all components + + + Provides support for various LLVM static state initialization and manipulation + + + Registers components for all available targets + Flags indicating which components to register/enable + + + Registers components for the target representing the system the calling process is running on + Flags indicating which components to register/enable + + + Registers components for ARM AArch64 target(s) + Flags indicating which components to register/enable + + + Registers components for ARM 32bit and 16bit thumb targets + Flags indicating which components to register/enable + + + Registers components for the Hexagon CPU + Flags indicating which components to register/enable + + + Registers components for MIPS targets + Flags indicating which components to register/enable + + + Registers components for MSP430 targets + Flags indicating which components to register/enable + + + Registers components for the NVPTX targets + Flags indicating which components to register/enable + + + Registers components for the PowerPC targets + Flags indicating which components to register/enable + + + Registers components for AMDGPU targets + Flags indicating which components to register/enable + + + Registers components for SPARC targets + Flags indicating which components to register/enable + + + Registers components for SystemZ targets + Flags indicating which components to register/enable + + + Registers components for X86 targets + Flags indicating which components to register/enable + + + Registers components for XCore targets + Flags indicating which components to register/enable + + + LLVM Target Instruction Set Architecture + + + Name of this target + + + Description of this target + + + Flag indicating if this target has JIT support + + + Flag indicating if this target has a TargetMachine initialized + + + Flag indicating if this target has an Assembly code generating back end initialized + + + Creates a for the target and specified parameters + Context to use for LLVM objects created by this machine + Target triple for this machine (e.g. -mtriple) + CPU for this machine (e.g. -mcpu) + Features for this machine (e.g. -mattr...) + Optimization level + Relocation mode for generated code + to use for generated code + based on the specified parameters + + + Retrieves an enumerable collection of the available targets built into this library + + + Gets the target for a given target "triple" value + Target triple string describing the target + Target for the given triple + + + Target specific code generation information + + + Retrieves the Target that owns this + + + Target triple describing this machine + + + CPU Type for this machine + + + CPU specific features for this machine + + + Gets Layout information for this machine + + + Generate code for the target machine from a module + to generate the code from + Path to the output file + Type of file to emit + + + This machine is associated with + + + Provides access to LLVM target data layout information + + There is a distinction between various sizes and alignment for a given type + that are target dependent. + The following table illustrates the differences in sizes and their meaning + for a sample set of types. + + + Type + SizeInBits + StoreSizeInBits + AllocSizeInBits + + i1 1 8 8 + i8 8 8 8 + i19 19 24 32 + i32 32 32 32 + i100 100 104 128 + i128 128 128 128 + Float 32 32 32 + Double 64 64 64 + X86_FP80 80 80 96 + + + The alloc size depends on the alignment, and thus on the target. + The values in the example table are for x86-32-linux. + + + + + Context used for this data (in particular, for retrieving pointer types) + + + Retrieves the byte ordering for this target + + + Retrieves the size of a pointer for the default address space of the target + Size of a pointer to the default address space + + + Retrieves the size of a pointer for a given address space of the target + Address space for the pointer + Size of a pointer + + + Retrieves an LLVM integer type with the same bit width as + a pointer for the default address space of the target + Integer type matching the bit width of a native pointer in the target's default address space + + + Retrieves an LLVM integer type with the same bit width as + a pointer for the given address space of the target + Integer type matching the bit width of a native pointer in the target's address space + + + Returns the number of bits necessary to hold the specified type. + Type to retrieve the size of + + This method determines the bit size of a type (e.g. the minimum number of + bits required to represent any value of the given type.) This is distinct from the storage + and stack size due to various target alignment requirements. + + + + Retrieves the number of bits required to store a value of the given type + Type to retrieve the storage size of + Number of bits required to store a value of the given type in the target + This method retrieves the storage size in bits of a given type. The storage size + includes any trailing padding bits that may be needed if the target requires reading a wider + word size. (e.g. most systems can't write a single bit value for an LLVM i1, thus the + storage size is whatever the minimum number of bits that the target requires to store a value + of the given type) + + + + Retrieves the ABI specified size of the given type + Type to get the size from + Size of the type + + + Retrieves the ABI specified alignment, in bytes, for a specified type + Type to get the alignment for + ABI specified alignment + + + Retrieves the call frame alignment for a given type + type to get the alignment of + Alignment for the type + + + Parses an LLVM target layout string + for types created by the new + string to parse + Parsed target data + For full details on the syntax of the string see http://llvm.org/releases/3.9.1/docs/LangRef.html#data-layout + + + diff --git a/src/Llvm.NET/MemoryBuffer.cs b/src/Llvm.NET/MemoryBuffer.cs index bf91e4ac4..92ad69841 100644 --- a/src/Llvm.NET/MemoryBuffer.cs +++ b/src/Llvm.NET/MemoryBuffer.cs @@ -1,6 +1,7 @@ using System; -using Llvm.NET.Native; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; +using Llvm.NET.Native; namespace Llvm.NET { @@ -12,11 +13,12 @@ public sealed class MemoryBuffer /// Path of the file to load into a public MemoryBuffer( string path ) { - IntPtr msg; - if( NativeMethods.CreateMemoryBufferWithContentsOfFile( path, out BufferHandle_, out msg ).Succeeded ) + if( NativeMethods.CreateMemoryBufferWithContentsOfFile( path, out BufferHandle_, out string msg ).Succeeded ) + { return; + } - throw new InternalCodeGeneratorException( NativeMethods.MarshalMsg( msg ) ); + throw new InternalCodeGeneratorException( msg ); } /// Size of the buffer @@ -25,9 +27,11 @@ public int Size get { if( BufferHandle.Pointer == IntPtr.Zero ) + { return 0; + } - return NativeMethods.GetBufferSize( BufferHandle ); + return NativeMethods.GetBufferSize( BufferHandle ).Pointer.ToInt32(); } } @@ -54,8 +58,14 @@ internal MemoryBuffer( LLVMMemoryBufferRef bufferHandle ) } internal LLVMMemoryBufferRef BufferHandle => BufferHandle_; - + // keep as a private field so this is usable as an out parameter in constructor + // do not write to it directly, treat it as readonly. + [SuppressMessage( "StyleCop.CSharp.NamingRules" + , "SA1310:Field names must not contain underscore" + , Justification = "Trailing _ indicates should not be written to directly even internally" + ) + ] private LLVMMemoryBufferRef BufferHandle_; } } diff --git a/src/Llvm.NET/Metadata/MDNode.cs b/src/Llvm.NET/Metadata/MDNode.cs index 8b70ce9f3..b1d1be5e1 100644 --- a/src/Llvm.NET/Metadata/MDNode.cs +++ b/src/Llvm.NET/Metadata/MDNode.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; -using Llvm.NET.Values; namespace Llvm.NET { @@ -14,28 +14,41 @@ internal MDNode( LLVMMetadataRef handle ) } public Context Context => Context.GetContextFor( MetadataHandle ); + public bool IsDeleted => MetadataHandle == LLVMMetadataRef.Zero; + public bool IsTemporary => NativeMethods.IsTemporary( MetadataHandle ); + public bool IsResolved => NativeMethods.IsResolved( MetadataHandle ); + public bool IsUniqued => NativeMethods.IsUniqued( MetadataHandle ); + public bool IsDistinct => NativeMethods.IsDistinct( MetadataHandle ); + public IReadOnlyList Operands { get; } public void ResolveCycles( ) => NativeMethods.MDNodeResolveCycles( MetadataHandle ); - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "MDNode" )] + [SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "MDNode", Justification = "It is spelled correctly" )] public override void ReplaceAllUsesWith( LlvmMetadata other ) { if( other == null ) + { throw new ArgumentNullException( nameof( other ) ); + } if( !IsTemporary || IsResolved ) + { throw new InvalidOperationException( "Cannot replace non temporary or resolved MDNode" ); + } if( MetadataHandle.Pointer == IntPtr.Zero ) + { throw new InvalidOperationException( "Cannot Replace all uses of a null descriptor" ); + } NativeMethods.MDNodeReplaceAllUsesWith( MetadataHandle, other.MetadataHandle ); + // remove current node mapping from the context. // It won't be valid for use after clearing the handle Context.RemoveDeletedNode( this ); @@ -46,7 +59,9 @@ internal static T FromHandle( LLVMMetadataRef handle ) where T : MDNode { if( handle.Pointer.IsNull( ) ) + { return null; + } var context = Context.GetContextFor( handle ); return FromHandle( context, handle ); diff --git a/src/Llvm.NET/DebugInfo/MDNodeOperandList.cs b/src/Llvm.NET/Metadata/MDNodeOperandList.cs similarity index 92% rename from src/Llvm.NET/DebugInfo/MDNodeOperandList.cs rename to src/Llvm.NET/Metadata/MDNodeOperandList.cs index 451512e57..6e46df53a 100644 --- a/src/Llvm.NET/DebugInfo/MDNodeOperandList.cs +++ b/src/Llvm.NET/Metadata/MDNodeOperandList.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Llvm.NET.Native; -namespace Llvm.NET.Values +namespace Llvm.NET { /// Support class to provide readonly list semantics to the operands of an MDNode internal class MDNodeOperandList @@ -18,7 +18,9 @@ public MDOperand this[ int index ] get { if( index >= Count || index < 0 ) + { throw new ArgumentOutOfRangeException( nameof( index ) ); + } var handle = NativeMethods.MDNodeGetOperand( OwningNode.MetadataHandle, ( uint )index ); return MDOperand.FromHandle( OwningNode, handle ); @@ -38,9 +40,11 @@ public IEnumerator GetEnumerator( ) { for( uint i = 0; i < Count; ++i ) { - LLVMMDOperandRef handle = NativeMethods.MDNodeGetOperand( OwningNode.MetadataHandle, i ) ; + LLVMMDOperandRef handle = NativeMethods.MDNodeGetOperand( OwningNode.MetadataHandle, i ); if( handle.Pointer == IntPtr.Zero ) + { yield break; + } yield return MDOperand.FromHandle( OwningNode, handle ); } diff --git a/src/Llvm.NET/Metadata/MDOperand.cs b/src/Llvm.NET/Metadata/MDOperand.cs index eb7f957d7..186d7b1c6 100644 --- a/src/Llvm.NET/Metadata/MDOperand.cs +++ b/src/Llvm.NET/Metadata/MDOperand.cs @@ -6,12 +6,15 @@ namespace Llvm.NET public class MDOperand { public MDNode OwningNode { get; } + public LlvmMetadata Metadata => LlvmMetadata.FromHandle( OwningNode.Context, NativeMethods.GetOperandNode( OperandHandle ) ); internal MDOperand( MDNode owningNode, LLVMMDOperandRef handle ) { if( handle.Pointer == IntPtr.Zero ) + { throw new ArgumentNullException( nameof( handle ) ); + } OperandHandle = handle; OwningNode = owningNode; diff --git a/src/Llvm.NET/Metadata/MDString.cs b/src/Llvm.NET/Metadata/MDString.cs index dfb188bba..61f9a3941 100644 --- a/src/Llvm.NET/Metadata/MDString.cs +++ b/src/Llvm.NET/Metadata/MDString.cs @@ -12,9 +12,7 @@ internal MDString( LLVMMetadataRef handle ) public override string ToString( ) { - uint len; - var ptr = NativeMethods.GetMDStringText( MetadataHandle, out len ); - return NativeMethods.NormalizeLineEndings( ptr, ( int )len ); + return NativeMethods.GetMDStringText( MetadataHandle, out uint len ); } } } \ No newline at end of file diff --git a/src/Llvm.NET/Metadata/Metadata.cs b/src/Llvm.NET/Metadata/Metadata.cs index b46115bbf..4b549a10d 100644 --- a/src/Llvm.NET/Metadata/Metadata.cs +++ b/src/Llvm.NET/Metadata/Metadata.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.DebugInfo; using Llvm.NET.Native; @@ -12,12 +13,14 @@ public abstract class LlvmMetadata { // ideally this would be protected + internal but C# // doesn't have any syntax to allow such a thing so it - // is internal and internal code should ensure it is + // is internal and internal code should ensure it is // only ever used by derived type constructors internal /*protected*/ LlvmMetadata( LLVMMetadataRef handle ) { if( handle == LLVMMetadataRef.Zero ) + { throw new ArgumentNullException( nameof( handle ) ); + } MetadataHandle = handle; } @@ -27,10 +30,14 @@ public abstract class LlvmMetadata public virtual void ReplaceAllUsesWith( LlvmMetadata other ) { if( other == null ) + { throw new ArgumentNullException( nameof( other ) ); + } if( MetadataHandle.Pointer == IntPtr.Zero ) + { throw new InvalidOperationException( "Cannot Replace all uses of a null descriptor" ); + } NativeMethods.MetadataReplaceAllUsesWith( MetadataHandle, other.MetadataHandle ); MetadataHandle = LLVMMetadataRef.Zero; @@ -40,9 +47,11 @@ public virtual void ReplaceAllUsesWith( LlvmMetadata other ) public override string ToString( ) { if( MetadataHandle.Pointer == IntPtr.Zero ) + { return string.Empty; + } - return NativeMethods.MarshalMsg( NativeMethods.MetadataAsString( MetadataHandle ) ); + return NativeMethods.MetadataAsString( MetadataHandle ); } internal LLVMMetadataRef MetadataHandle { get; /*protected*/ set; } @@ -51,7 +60,9 @@ internal static T FromHandle( Context context, LLVMMetadataRef handle ) where T : LlvmMetadata { if( handle == LLVMMetadataRef.Zero ) + { return null; + } return ( T )context.GetNodeFor( handle, StaticFactory ); } @@ -60,48 +71,49 @@ internal static T FromHandle( Context context, LLVMMetadataRef handle ) private enum MetadataKind : uint { MDString, // HANDLE_METADATA_LEAF(MDString) - //ValueAsMetadata, // HANDLE_METADATA_BRANCH(ValueAsMetadata) + // ValueAsMetadata, // HANDLE_METADATA_BRANCH(ValueAsMetadata) ConstantAsMetadata, // HANDLE_METADATA_LEAF(ConstantAsMetadata) LocalAsMetadata, // HANDLE_METADATA_LEAF(LocalAsMetadata) DistinctMDOperandPlaceholder, // HANDLE_METADATA_LEAF(DistinctMDOperandPlaceholder) - //MDNode, // HANDLE_MDNODE_BRANCH(MDNode) + // MDNode, // HANDLE_MDNODE_BRANCH(MDNode) MDTuple, // HANDLE_MDNODE_LEAF_UNIQUABLE(MDTuple) DILocation, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DILocation) DIExpression, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIExpression) - //DINode, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DINode) + DIGlobalVariableExpression, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIGlobalVariableExpression) + // DINode, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DINode) GenericDINode, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(GenericDINode) DISubrange, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DISubrange) DIEnumerator, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIEnumerator) - //DIScope, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIScope) - //DIType, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIType) + // DIScope, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIScope) + // DIType, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIType) DIBasicType, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIBasicType) DIDerivedType, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIDerivedType) DICompositeType, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DICompositeType) DISubroutineType, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DISubroutineType) DIFile, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIFile) DICompileUnit, // HANDLE_SPECIALIZED_MDNODE_LEAF(DICompileUnit) - //DILocalScope, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DILocalScope) + // DILocalScope, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DILocalScope) DISubprogram, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DISubprogram) - //DILexicalBlockBase, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DILexicalBlockBase) + // DILexicalBlockBase, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DILexicalBlockBase) DILexicalBlock, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DILexicalBlock) DILexicalBlockFile, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DILexicalBlockFile) DINamespace, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DINamespace) DIModule, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIModule) - //DITemplateParameter, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DITemplateParameter) + // DITemplateParameter, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DITemplateParameter) DITemplateTypeParameter, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DITemplateTypeParameter) DITemplateValueParameter, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DITemplateValueParameter) - //DIVariable, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIVariable) + // DIVariable, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIVariable) DIGlobalVariable, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIGlobalVariable) DILocalVariable, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DILocalVariable) DIObjCProperty, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIObjCProperty) DIImportedEntity, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIImportedEntity) - //DIMacroNode, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIMacroNode) + // DIMacroNode, // HANDLE_SPECIALIZED_MDNODE_BRANCH(DIMacroNode) DIMacro, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIMacro) DIMacroFile, // HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DIMacroFile) } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Static factory method" )] - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Static factory method" )] + [SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Static factory method" )] + [SuppressMessage( "Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Static factory method" )] private static LlvmMetadata StaticFactory( LLVMMetadataRef handle ) { // use the native kind value to determine the managed type // that should wrap this particular handle @@ -114,6 +126,12 @@ private static LlvmMetadata StaticFactory( LLVMMetadataRef handle ) case MetadataKind.DILocation: return new DILocation( handle ); + case MetadataKind.DIExpression: + return new DIExpression( handle ); + + case MetadataKind.DIGlobalVariableExpression: + return new DIGlobalVariableExpression( handle ); + case MetadataKind.GenericDINode: return new GenericDINode( handle ); @@ -168,9 +186,6 @@ private static LlvmMetadata StaticFactory( LLVMMetadataRef handle ) case MetadataKind.DILocalVariable: return new DILocalVariable( handle ); - case MetadataKind.DIExpression: - return new DIExpression( handle ); - case MetadataKind.DIObjCProperty: return new DIObjCProperty( handle ); @@ -187,9 +202,10 @@ private static LlvmMetadata StaticFactory( LLVMMetadataRef handle ) return new MDString( handle ); default: +#pragma warning disable RECS0083 // Intentional trigger to catch changes in underlying LLVM libs throw new NotImplementedException( ); +#pragma warning restore RECS0083 } } } - } diff --git a/src/Llvm.NET/Metadata/MetadataAsValue.cs b/src/Llvm.NET/Metadata/MetadataAsValue.cs index 38c20f1db..63e0dee89 100644 --- a/src/Llvm.NET/Metadata/MetadataAsValue.cs +++ b/src/Llvm.NET/Metadata/MetadataAsValue.cs @@ -14,16 +14,20 @@ internal MetadataAsValue( LLVMValueRef valueRef ) internal static LLVMValueRef IsAMetadataAsValue( LLVMValueRef value ) { if( value.Pointer == IntPtr.Zero ) + { return value; + } - return NativeMethods.GetValueKind( value ) == ValueKind.MetadataAsValue ? value : default( LLVMValueRef ); + return NativeMethods.GetValueIdAsKind( value ) == ValueKind.MetadataAsValue ? value : default( LLVMValueRef ); } + /* //public static implicit operator Metadata( MetadataAsValue self ) //{ // // TODO: Add support to get the metadata ref from the value... // // e.g. call C++ MetadataAsValue.getMetadata() // throw new NotImplementedException(); //} + */ } } \ No newline at end of file diff --git a/src/Llvm.NET/Metadata/NamedMDNode.cs b/src/Llvm.NET/Metadata/NamedMDNode.cs index 86309a8ce..09b8d08ba 100644 --- a/src/Llvm.NET/Metadata/NamedMDNode.cs +++ b/src/Llvm.NET/Metadata/NamedMDNode.cs @@ -14,10 +14,12 @@ internal NamedMDNode( LLVMNamedMDNodeRef nativeNode ) Operands = new OperandIterator( this ); } - // TODO: Enable retrieving the name from LibLLVM - //public string Name { get; } + /* TODO: Enable retrieving the name from LibLLVM + // public string Name { get; } + */ public IReadOnlyList Operands { get; } + public NativeModule ParentModule => NativeModule.FromHandle( NativeMethods.NamedMDNodeGetParentModule( NativeHandle ) ); private LLVMNamedMDNodeRef NativeHandle; @@ -45,13 +47,12 @@ public MDNode this[ int index ] public IEnumerator GetEnumerator( ) { for( int i = 0; i < Count; ++i ) + { yield return this[ i ]; + } } - IEnumerator IEnumerable.GetEnumerator( ) - { - return GetEnumerator( ); - } + IEnumerator IEnumerable.GetEnumerator( ) => GetEnumerator( ); private NamedMDNode OwningNode; } diff --git a/src/Llvm.NET/Module.cs b/src/Llvm.NET/Module.cs index c51784470..edebc3e0c 100644 --- a/src/Llvm.NET/Module.cs +++ b/src/Llvm.NET/Module.cs @@ -1,32 +1,24 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using Llvm.NET.DebugInfo; using Llvm.NET.Native; using Llvm.NET.Types; using Llvm.NET.Values; -using System.Diagnostics.CodeAnalysis; namespace Llvm.NET { /// LLVM Bitcode module /// /// A module is the basic unit for containing code in LLVM. Modules are an in memory - /// representation of the LLVM bit-code. + /// representation of the LLVM bit-code. /// public sealed class NativeModule : IDisposable , IExtensiblePropertyContainer { - internal NativeModule( LLVMModuleRef handle ) - { - ModuleHandle = handle; - DIBuilder_ = new Lazy( ( ) => new DebugInfoBuilder( this ) ); - Context.AddModule( this ); - Comdats = new ComdatCollection( this ); - } - /// Creates an unnamed module without debug information public NativeModule( ) : this( string.Empty, null ) @@ -43,11 +35,12 @@ public NativeModule( string moduleId ) /// Creates an named module in a given context /// Module's ID /// Context for the module - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Reliability", "CA2000:Dispose objects before losing scope" )] public NativeModule( string moduleId, Context context ) { if( moduleId == null ) + { moduleId = string.Empty; + } if( context == null ) { @@ -55,13 +48,32 @@ public NativeModule( string moduleId, Context context ) OwnsContext = true; } - ModuleHandle = NativeMethods.ModuleCreateWithNameInContext( moduleId, context.ContextHandle ); - if( ModuleHandle.Pointer == IntPtr.Zero ) - throw new InternalCodeGeneratorException( "Could not create module in context" ); + Func onException = ( ) => + { + if( OwnsContext && context != null ) + { + context.Dispose( ); + } - DIBuilder_ = new Lazy( ( ) => new DebugInfoBuilder( this ) ); - Context.AddModule( this ); - Comdats = new ComdatCollection( this ); + return false; + }; + + try + { + ModuleHandle = NativeMethods.ModuleCreateWithNameInContext( moduleId, context.ContextHandle ); + if( ModuleHandle.Pointer == IntPtr.Zero ) + { + throw new InternalCodeGeneratorException( "Could not create module in context" ); + } + + LazyDiBuilder = new Lazy( ( ) => new DebugInfoBuilder( this ) ); + Context.AddModule( this ); + Comdats = new ComdatCollection( this ); + } + catch when ( onException() ) + { + // NOP + } } /// Creates a named module with a root to contain debugging information @@ -121,7 +133,6 @@ public NativeModule( string moduleId ); } - #region IDisposable Pattern public bool IsDisposed => ModuleHandle.Pointer.IsNull(); public void Dispose( ) @@ -135,33 +146,6 @@ public void Dispose( ) Dispose( false ); } - void Dispose( bool disposing ) - { - // if not already disposed, dispose the module - // Do this only on dispose. The containing context - // will clean up the module when it is disposed or - // finalized. Since finalization order isn't - // deterministic it is possible that the module is - // finalized after the context has already run its - // finalizer, which would cause an access violation - // in the native LLVM layer. - if( disposing && ModuleHandle.Pointer != IntPtr.Zero ) - { - // remove the module handle from the module cache. - Context.RemoveModule( this ); - - // if this module created the context then just dispose - // the context as that will clean up the module as well. - if( OwnsContext ) - Context.Dispose( ); - else - NativeMethods.DisposeModule( ModuleHandle ); - - ModuleHandle = default( LLVMModuleRef ); - } - } - #endregion - /// Name of the Debug Version information module flag public const string DebugVersionValue = "Debug Info Version"; @@ -180,7 +164,9 @@ public Context Context get { if( ModuleHandle.Pointer == IntPtr.Zero ) + { return null; + } return Context.GetContextFor( ModuleHandle ); } @@ -196,7 +182,7 @@ public NamedMDNode ModuleFlags } /// to create debug information for this module - public DebugInfoBuilder DIBuilder => DIBuilder_.Value; + public DebugInfoBuilder DIBuilder => LazyDiBuilder.Value; /// Debug Compile unit for this module public DICompileUnit DICompileUnit { get; internal set; } @@ -210,47 +196,43 @@ public NamedMDNode ModuleFlags /// come from the actual the code is /// targeting. /// - public string DataLayoutString - { - get - { - return Layout?.ToString( ) ?? string.Empty; - } - } + public string DataLayoutString => Layout?.ToString( ) ?? string.Empty; /// Target data layout for this module /// The layout is produced by parsing the - /// therefore this property changes anytime the is + /// therefore this property changes anytime the is /// set. Furthermore, setting this property will change the value of . /// In other words, Layout and are two different views /// of the same information. /// public DataLayout Layout { - get { return Layout_; } + get => Layout_; + set { if( Layout_ != null ) + { Layout_.Dispose( ); + } Layout_ = value; NativeMethods.SetDataLayout( ModuleHandle, value?.ToString( ) ?? string.Empty ); } } + + [SuppressMessage( "StyleCop.CSharp.NamingRules" + , "SA1310:Field names must not contain underscore" + , Justification = "Trailing _ indicates it must not be written to directly even directly" + ) + ] private DataLayout Layout_; /// Target Triple describing the target, ABI and OS public string TargetTriple { - get - { - var ptr = NativeMethods.GetTarget( ModuleHandle ); - return NativeMethods.NormalizeLineEndings( ptr ); - } - set - { - NativeMethods.SetTarget( ModuleHandle, value ); - } + get => NativeMethods.GetTarget( ModuleHandle ); + set => NativeMethods.SetTarget( ModuleHandle, value ); } /// Globals contained by this module @@ -285,29 +267,27 @@ public IEnumerable Functions // TODO: Add enumerator for NamedMDNode(s) /// Name of the module - public string Name - { - get - { - var ptr = NativeMethods.GetModuleName( ModuleHandle ); - return NativeMethods.NormalizeLineEndings( ptr ); - } - } + public string Name => NativeMethods.GetModuleName( ModuleHandle ); public void Link( NativeModule otherModule ) { if( otherModule == null ) + { throw new ArgumentNullException( nameof( otherModule ) ); + } if( otherModule.Context != Context ) + { throw new ArgumentException( "Linking modules with different contexts is not allowed", nameof( otherModule ) ); + } - if( !NativeMethods.LinkModules( ModuleHandle, otherModule.ModuleHandle ).Succeeded ) + if( !NativeMethods.LinkModules2( ModuleHandle, otherModule.ModuleHandle ).Succeeded ) { throw new InternalCodeGeneratorException( "Module link error" ); } + Context.RemoveModule( otherModule ); - otherModule.ModuleHandle = LLVMModuleRef.Zero; + otherModule.ModuleHandle = new LLVMModuleRef( IntPtr.Zero ); } /// Run optimization passes on the module @@ -322,7 +302,9 @@ public void Link( NativeModule otherModule ) public void Optimize( TargetMachine targetMachine ) { if( targetMachine == null ) + { throw new ArgumentNullException( nameof( targetMachine ) ); + } NativeMethods.RunLegacyOptimizer( ModuleHandle, targetMachine.TargetMachineHandle ); } @@ -332,14 +314,7 @@ public void Optimize( TargetMachine targetMachine ) /// true if the verification succeeded and false if not. public bool Verify( out string errmsg ) { - errmsg = null; - IntPtr msgPtr; - LLVMBool result = NativeMethods.VerifyModule( ModuleHandle, LLVMVerifierFailureAction.LLVMReturnStatusAction, out msgPtr ); - if( result.Succeeded ) - return true; - - errmsg = NativeMethods.MarshalMsg( msgPtr ); - return false; + return NativeMethods.VerifyModule( ModuleHandle, LLVMVerifierFailureAction.LLVMReturnStatusAction, out errmsg ); } /// Gets a function by name from this module @@ -349,7 +324,9 @@ public Function GetFunction( string name ) { var funcRef = NativeMethods.GetNamedFunction( ModuleHandle, name ); if( funcRef.Pointer == IntPtr.Zero ) + { return null; + } return Value.FromHandle( funcRef ); } @@ -380,9 +357,11 @@ public Function AddFunction( string name, IFunctionType signature ) /// public void WriteToFile( string path ) { - var err = NativeMethods.WriteBitcodeToFile( ModuleHandle, path ); - if( err < 0 ) - throw new IOException( ); + LLVMStatus status = NativeMethods.WriteBitcodeToFile( ModuleHandle, path ); + if( status.Failed ) + { + throw new IOException( $"Error reading bitcode file '{path}'", status.ErrorCode ); + } } /// Writes this module as LLVM IR source to a file @@ -391,13 +370,7 @@ public void WriteToFile( string path ) /// if successful or if not public bool WriteToTextFile( string path, out string errMsg ) { - errMsg = string.Empty; - IntPtr msg; - if( NativeMethods.PrintModuleToFile( ModuleHandle, path, out msg ).Succeeded ) - return true; - - errMsg = NativeMethods.MarshalMsg( msg ); - return false; + return NativeMethods.PrintModuleToFile( ModuleHandle, path, out errMsg ); } /// Creates a string representation of the module @@ -408,7 +381,7 @@ public bool WriteToTextFile( string path, out string errMsg ) /// an extremely long time (up to many seconds depending on complexity /// of the module) which is bad for the debugger. /// - public string WriteToString( ) => NativeMethods.MarshalMsg( NativeMethods.PrintModuleToString( ModuleHandle ) ); + public string WriteToString( ) => NativeMethods.PrintModuleToString( ModuleHandle ); public MemoryBuffer WriteToBuffer() { @@ -422,7 +395,9 @@ public MemoryBuffer WriteToBuffer() public GlobalAlias AddAlias( Value aliasee, string aliasName ) { if( aliasee == null ) + { throw new ArgumentNullException( nameof( aliasee ) ); + } var handle = NativeMethods.AddAlias( ModuleHandle, aliasee.NativeType.GetTypeRef( ), aliasee.ValueHandle, aliasName ); return Value.FromHandle( handle ); @@ -437,7 +412,6 @@ public GlobalAlias GetAlias( string name ) return Value.FromHandle( handle ); } - /// Adds a global to this module with a specific address space /// /// Type of the global's value @@ -539,7 +513,9 @@ public GlobalVariable GetNamedGlobal( string name ) { var hGlobal = NativeMethods.GetNamedGlobal( ModuleHandle, name ); if( hGlobal.Pointer == IntPtr.Zero ) + { return null; + } return Value.FromHandle( hGlobal ); } @@ -561,7 +537,9 @@ public void AddModuleFlag( ModuleFlagBehavior behavior, string name, UInt32 valu public void AddModuleFlag( ModuleFlagBehavior behavior, string name, LlvmMetadata value ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } // AddModuleFlag comes from custom LLVMDebug-C API NativeMethods.AddModuleFlag( ModuleHandle, ( LLVMModFlagBehavior )behavior, name, value.MetadataHandle ); @@ -588,7 +566,7 @@ public void AddVersionIdentMetadata( string version ) /// New node with the string as [0] (as an MDString) public MDNode CreateMDNode( string value ) { - var elements = new LLVMMetadataRef[ ] { NativeMethods.MDString2( Context.ContextHandle, value, ( uint )(value?.Length ?? 0 ) ) }; + var elements = new LLVMMetadataRef[ ] { NativeMethods.MDString2( Context.ContextHandle, value, ( uint )( value?.Length ?? 0 ) ) }; var hNode = NativeMethods.MDNode2( Context.ContextHandle, out elements[ 0 ], ( uint )elements.Length ); return MDNode.FromHandle( hNode ); } @@ -624,13 +602,19 @@ public Function CreateFunction( DIScope scope ) { if( scope == null ) + { throw new ArgumentNullException( nameof( scope ) ); + } if( string.IsNullOrWhiteSpace( name ) ) + { throw new ArgumentException( "Name cannot be null, empty or whitespace", nameof( name ) ); + } if( signature == null ) + { throw new ArgumentNullException( nameof( signature ) ); + } var func = AddFunction( linkageName ?? name, signature ); var diSignature = signature.DIType; @@ -677,7 +661,9 @@ public NativeModule Clone( Context targetContext ) } if( targetContext == Context ) + { return Clone( ); + } using( var buffer = WriteToBuffer( ) ) { @@ -700,12 +686,6 @@ void IExtensiblePropertyContainer.AddExtendedPropertyValue( string id, object va PropertyBag.AddExtendedPropertyValue( id, value ); } - internal static NativeModule FromHandle( LLVMModuleRef nativeHandle ) - { - var context = Context.GetContextFor( nativeHandle ); - return context.GetModuleFor( nativeHandle ); - } - /// Load a bit-code module from a given file /// path of the file to load /// Context to use for creating the module @@ -713,13 +693,19 @@ internal static NativeModule FromHandle( LLVMModuleRef nativeHandle ) public static NativeModule LoadFrom( string path, Context context ) { if( string.IsNullOrWhiteSpace( path ) ) + { throw new ArgumentException( "path cannot be null or an empty string", nameof( path ) ); + } if( context == null ) + { throw new ArgumentNullException( nameof( context ) ); + } if( !File.Exists( path ) ) + { throw new FileNotFoundException( "Specified bit-code file does not exist", path ); + } using( var buffer = new MemoryBuffer( path ) ) { @@ -741,25 +727,71 @@ public static NativeModule LoadFrom( string path, Context context ) public static NativeModule LoadFrom( MemoryBuffer buffer, Context context ) { if( buffer == null ) + { throw new ArgumentNullException( nameof( buffer ) ); + } if( context == null ) + { throw new ArgumentNullException( nameof( buffer ) ); + } - LLVMModuleRef modRef; - IntPtr errMsgPtr; - if( NativeMethods.ParseBitcodeInContext( context.ContextHandle, buffer.BufferHandle, out modRef, out errMsgPtr ).Failed ) + if( NativeMethods.ParseBitcodeInContext( context.ContextHandle, buffer.BufferHandle, out LLVMModuleRef modRef, out string errMsg ).Failed ) { - var errMsg = NativeMethods.MarshalMsg( errMsgPtr ); throw new InternalCodeGeneratorException( errMsg ); } + return context.GetModuleFor( modRef ); } + internal NativeModule( LLVMModuleRef handle ) + { + ModuleHandle = handle; + LazyDiBuilder = new Lazy( ( ) => new DebugInfoBuilder( this ) ); + Context.AddModule( this ); + Comdats = new ComdatCollection( this ); + } + + internal static NativeModule FromHandle( LLVMModuleRef nativeHandle ) + { + var context = Context.GetContextFor( nativeHandle ); + return context.GetModuleFor( nativeHandle ); + } + + private void Dispose( bool disposing ) + { + // if not already disposed, dispose the module + // Do this only on dispose. The containing context + // will clean up the module when it is disposed or + // finalized. Since finalization order isn't + // deterministic it is possible that the module is + // finalized after the context has already run its + // finalizer, which would cause an access violation + // in the native LLVM layer. + if( disposing && ModuleHandle.Pointer != IntPtr.Zero ) + { + // remove the module handle from the module cache. + Context.RemoveModule( this ); + + // if this module created the context then just dispose + // the context as that will clean up the module as well. + if( OwnsContext ) + { + Context.Dispose( ); + } + else + { + NativeMethods.DisposeModule( ModuleHandle ); + } + + ModuleHandle = default( LLVMModuleRef ); + } + } + internal LLVMModuleRef ModuleHandle { get; private set; } private readonly ExtensiblePropertyContainer PropertyBag = new ExtensiblePropertyContainer( ); - private readonly Lazy DIBuilder_; + private readonly Lazy LazyDiBuilder; private readonly bool OwnsContext; } } diff --git a/src/Llvm.NET/Native/CustomGenerated.cs b/src/Llvm.NET/Native/CustomGenerated.cs new file mode 100644 index 000000000..3533f6140 --- /dev/null +++ b/src/Llvm.NET/Native/CustomGenerated.cs @@ -0,0 +1,833 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +#pragma warning disable SA1300 // "StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Generated Interop" + +/* Enums types and P/Invoke calls here are extensions to standard LLVM-C APIs +// many are cmoon bindings borrowed from the go bindings (or further extended from them) +// others are uinique to Llvm.NET to enable max use of the LLVM libraries in .NET based +// code. +*/ + +namespace Llvm.NET.Native +{ + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Generated code relies on this to match C++" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Reviewed." )] + internal partial struct size_t + { + internal size_t( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + + public static explicit operator size_t(int size) + { + return new size_t( ( IntPtr )size ); + } + + public static implicit operator int(size_t size) + { + return size.Pointer.ToInt32( ); + } + + public static implicit operator long( size_t size ) + { + return size.Pointer.ToInt64( ); + } + } + + internal partial struct LLVMMDOperandRef + { + internal LLVMMDOperandRef(IntPtr pointer) + { + Pointer = pointer; + } + + internal readonly IntPtr Pointer; + } + + internal partial struct LLVMNamedMDNodeRef + { + internal LLVMNamedMDNodeRef(IntPtr pointer) + { + Pointer = pointer; + } + + internal readonly IntPtr Pointer; + } + + internal partial struct LLVMComdatRef + { + internal LLVMComdatRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal readonly IntPtr Pointer; + } + +#pragma warning disable CA1008 // Enums should have zero value. + internal enum LLVMModFlagBehavior + { + @Error = 1, + @Warning = 2, + @Require = 3, + @Override = 4, + @Append = 5, + @AppendUnique = 6, + @ModFlagBehaviorFirstVal = Error, + @ModFlagBehaviorLastVal = AppendUnique + } + + internal enum LLVMDwarfTag : ushort + { + ArrayType = 0x01, + ClassType = 0x02, + EntryPoint = 0x03, + EnumerationType = 0x04, + FormalParameter = 0x05, + ImportedDeclaration = 0x08, + Label = 0x0a, + LexicalBlock = 0x0b, + Member = 0x0d, + PointerType = 0x0f, + ReferenceType = 0x10, + CompileUnit = 0x11, + StringType = 0x12, + StructureType = 0x13, + SubroutineType = 0x15, + TypeDef = 0x16, + UnionType = 0x17, + UnspecifiedParameters = 0x18, + Variant = 0x19, + CommonBlock = 0x1a, + CommonInclusion = 0x1b, + Inheritance = 0x1c, + InlinedSubroutine = 0x1d, + Module = 0x1e, + PtrToMemberType = 0x1f, + SetType = 0x20, + SubrangeType = 0x21, + WithStatement = 0x22, + AccessDeclaration = 0x23, + BaseType = 0x24, + CatchBlock = 0x25, + ConstType = 0x26, + Constant = 0x27, + Enumerator = 0x28, + FileType = 0x29, + Friend = 0x2a, + NameList = 0x2b, + NameListItem = 0x2c, + PackedType = 0x2d, + SubProgram = 0x2e, + TemplateTypeParameter = 0x2f, + TemplateValueParameter = 0x30, + ThrownType = 0x31, + TryBlock = 0x32, + VariantPart = 0x33, + Variable = 0x34, + VolatileType = 0x35, + DwarfProcedure = 0x36, + RestrictType = 0x37, + InterfaceType = 0x38, + Namespace = 0x39, + ImportedModule = 0x3a, + UnspecifiedType = 0x3b, + PartialUnit = 0x3c, + ImportedUnit = 0x3d, + Condition = 0x3f, + SharedType = 0x40, + TypeUnit = 0x41, + RValueReferenceType = 0x42, + TemplateAlias = 0x43, + + // New in DWARF 5: + CoArrayType = 0x44, + GenericSubrange = 0x45, + DynamicType = 0x46, + + MipsLoop = 0x4081, + FormatLabel = 0x4101, + FunctionTemplate = 0x4102, + ClassTemplate = 0x4103, + GnuTemplateTemplateParam = 0x4106, + GnuTemplateParameterPack = 0x4107, + GnuFormalParameterPack = 0x4108, + LoUser = 0x4080, + AppleProperty = 0x4200, + HiUser = 0xffff + } +#pragma warning restore CA1008 // Enums should have zero value. + + internal enum LLVMMetadataKind + { + MDTuple, + DILocation, + GenericDINode, + DISubrange, + DIEnumerator, + DIBasicType, + DIDerivedType, + DICompositeType, + DISubroutineType, + DIFile, + DICompileUnit, + DISubprogram, + DILexicalBlock, + DILexicalBlockFile, + DINamespace, + DIModule, + DITemplateTypeParameter, + DITemplateValueParameter, + DIGlobalVariable, + DILocalVariable, + DIExpression, + DIObjCProperty, + DIImportedEntity, + ConstantAsMetadata, + LocalAsMetadata, + MDString + } + + internal enum LLVMOptVerifierKind + { + None, + VerifyInAndOut, + VerifyEachPass + } + + internal enum LLVMTripleArchType + { + UnknownArch, + arm, // ARM (little endian): arm, armv.*, xscale + armeb, // ARM (big endian): armeb + aarch64, // AArch64 (little endian): aarch64 + aarch64_be, // AArch64 (big endian): aarch64_be + avr, // AVR: Atmel AVR microcontroller + bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) + bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) + hexagon, // Hexagon: hexagon + mips, // MIPS: mips, mipsallegrex + mipsel, // MIPSEL: mipsel, mipsallegrexel + mips64, // MIPS64: mips64 + mips64el, // MIPS64EL: mips64el + msp430, // MSP430: msp430 + ppc, // PPC: powerpc + ppc64, // PPC64: powerpc64, ppu + ppc64le, // PPC64LE: powerpc64le + r600, // R600: AMD GPUs HD2XXX - HD6XXX + amdgcn, // AMDGCN: AMD GCN GPUs + riscV32, // RISC-V (32-bit): riscv32 + riscV64, // RISC-V (64-bit): riscv64 + sparc, // Sparc: sparc + sparcv9, // Sparcv9: Sparcv9 + sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant + systemz, // SystemZ: s390x + tce, // TCE (http://tce.cs.tut.fi/): tce + tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele + thumb, // Thumb (little endian): thumb, thumbv.* + thumbeb, // Thumb (big endian): thumbeb + x86, // X86: i[3-9]86 + x86_64, // X86-64: amd64, x86_64 + xcore, // XCore: xcore + nvptx, // NVPTX: 32-bit + nvptx64, // NVPTX: 64-bit + le32, // le32: generic little-endian 32-bit CPU (PNaCl) + le64, // le64: generic little-endian 64-bit CPU (PNaCl) + amdil, // AMDIL + amdil64, // AMDIL with 64-bit pointers + hsail, // AMD HSAIL + hsail64, // AMD HSAIL with 64-bit pointers + spir, // SPIR: standard portable IR for OpenCL 32-bit version + spir64, // SPIR: standard portable IR for OpenCL 64-bit version + kalimba, // Kalimba: generic kalimba + shave, // SHAVE: Movidius vector VLIW processors + lanai, // Lanai: Lanai 32-bit + wasm32, // WebAssembly with 32-bit pointers + wasm64, // WebAssembly with 64-bit pointers + renderscript32, // 32-bit RenderScript + renderscript64, // 64-bit RenderScript + LastArchType = renderscript64 + } + + internal enum LLVMTripleSubArchType + { + NoSubArch, + ARMSubArch_v8_2a, + ARMSubArch_v8_1a, + ARMSubArch_v8, + ARMSubArch_v8r, + ARMSubArch_v8m_baseline, + ARMSubArch_v8m_mainline, + ARMSubArch_v7, + ARMSubArch_v7em, + ARMSubArch_v7m, + ARMSubArch_v7s, + ARMSubArch_v7k, + ARMSubArch_v6, + ARMSubArch_v6m, + ARMSubArch_v6k, + ARMSubArch_v6t2, + ARMSubArch_v5, + ARMSubArch_v5te, + ARMSubArch_v4t, + KalimbaSubArch_v3, + KalimbaSubArch_v4, + KalimbaSubArch_v5 + } + + internal enum LLVMTripleVendorType + { + UnknownVendor, + Apple, + PC, + SCEI, + BGP, + BGQ, + Freescale, + IBM, + ImaginationTechnologies, + MipsTechnologies, + NVIDIA, + CSR, + Myriad, + AMD, + Mesa, + LastVendorType = Mesa + } + + internal enum LLVMTripleOSType + { + UnknownOS, + + CloudABI, + Darwin, + DragonFly, + FreeBSD, + Fuchsia, + IOS, + KFreeBSD, + Linux, + Lv2, // PS3 + MacOSX, + NetBSD, + OpenBSD, + Solaris, + Win32, + Haiku, + Minix, + RTEMS, + NaCl, // Native Client + CNK, // BG/P Compute-Node Kernel + Bitrig, + AIX, + CUDA, // NVIDIA CUDA + NVCL, // NVIDIA OpenCL + AMDHSA, // AMD HSA Runtime + PS4, + ELFIAMCU, + TvOS, // Apple tvOS + WatchOS, // Apple watchOS + Mesa3D, + Contiki, + LastOSType = Contiki + } + + internal enum LLVMTripleEnvironmentType + { + UnknownEnvironment, + GNU, + GNUABI64, + GNUEABI, + GNUEABIHF, + GNUX32, + CODE16, + EABI, + EABIHF, + Android, + Musl, + MuslEABI, + MuslEABIHF, + MSVC, + Itanium, + Cygnus, + AMDOpenCL, + CoreCLR, + OpenCL, + LastEnvironmentType = OpenCL + } + + internal enum LLVMTripleObjectFormatType + { + UnknownObjectFormat, + COFF, + ELF, + MachO, + } + + internal enum LLVMComdatSelectionKind + { + ANY, + EXACTMATCH, + LARGEST, + NODUPLICATES, + SAMESIZE + } + + [SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Mapping to interop C based API" )] + internal static partial class NativeMethods + { + [DllImport( libraryPath, EntryPoint = "LLVMGetVersionInfo", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void GetVersionInfo( out LLVMVersionInfo pVersionInfo ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetValueID", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern int GetValueID( LLVMValueRef @val ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildIntCast2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef BuildIntCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.Bool )]bool isSigned, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetDebugLoc", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void SetDebugLoc( LLVMValueRef inst, UInt32 line, UInt32 column, LLVMMetadataRef scope ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetDILocation", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void SetDILocation( LLVMValueRef inst, LLVMMetadataRef location ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationScope", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef /*DILocalScope*/ GetDILocationScope( LLVMMetadataRef /*DILocation*/ location ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationLine", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 GetDILocationLine( LLVMMetadataRef /*DILocation*/ location ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationColumn", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 GetDILocationColumn( LLVMMetadataRef /*DILocation*/ location ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDILocationInlinedAt", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef /*DILocation*/ GetDILocationInlinedAt( LLVMMetadataRef /*DILocation*/ location ); + + [DllImport( libraryPath, EntryPoint = "LLVMDILocationGetInlinedAtScope", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef /*DILocalScope*/ DILocationGetInlinedAtScope( LLVMMetadataRef /*DILocation*/ location ); + + [DllImport( libraryPath, EntryPoint = "LLVMVerifyFunctionEx", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMStatus VerifyFunctionEx( LLVMValueRef @Fn, LLVMVerifierFailureAction @Action, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] out string @OutMessages ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAddressSanitizerFunctionPass", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddAddressSanitizerFunctionPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAddressSanitizerModulePass", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddAddressSanitizerModulePass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddThreadSanitizerPass", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddThreadSanitizerPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddMemorySanitizerPass", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddMemorySanitizerPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddDataFlowSanitizerPass", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddDataFlowSanitizerPass( LLVMPassManagerRef @PM, [MarshalAs( UnmanagedType.LPStr )] string @ABIListFile ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddModuleFlag", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddModuleFlag( LLVMModuleRef @M, LLVMModFlagBehavior behavior, [MarshalAs( UnmanagedType.LPStr )] string @name, UInt32 @value ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddModuleFlagMetadata", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddModuleFlag( LLVMModuleRef @M, LLVMModFlagBehavior behavior, [MarshalAs( UnmanagedType.LPStr )] string @name, LLVMMetadataRef @value ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleGetModuleFlagsMetadata", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMNamedMDNodeRef ModuleGetModuleFlagsMetadata( LLVMModuleRef module ); + + [DllImport( libraryPath, EntryPoint = "LLVMNamedMDNodeGetNumOperands", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 NamedMDNodeGetNumOperands( LLVMNamedMDNodeRef namedMDNode ); + + [DllImport( libraryPath, EntryPoint = "LLVMNamedMDNodeGetOperand", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern /*MDNode*/ LLVMMetadataRef NamedMDNodeGetOperand( LLVMNamedMDNodeRef namedMDNode, UInt32 index ); + + [DllImport( libraryPath, EntryPoint = "LLVMNamedMDNodeGetParentModule", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMModuleRef NamedMDNodeGetParentModule( LLVMNamedMDNodeRef namedMDNode ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetOrInsertFunction", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef GetOrInsertFunction( LLVMModuleRef module, [MarshalAs( UnmanagedType.LPStr )] string @name, LLVMTypeRef functionType ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsConstantZeroValue", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool IsConstantZeroValue( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveGlobalFromParent", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void RemoveGlobalFromParent( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstantAsMetadata", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef ConstantAsMetadata( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDString2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef MDString2( LLVMContextRef @C, [MarshalAs( UnmanagedType.LPStr )] string @Str, UInt32 @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNode2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef MDNode2( LLVMContextRef @C, out LLVMMetadataRef @MDs, UInt32 @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMTemporaryMDNode", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef TemporaryMDNode( LLVMContextRef @C, out LLVMMetadataRef @MDs, UInt32 @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddNamedMetadataOperand2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void AddNamedMetadataOperand2( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @name, LLVMMetadataRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetMetadata2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void SetMetadata2( LLVMValueRef @Inst, UInt32 @KindID, LLVMMetadataRef @MD ); + + [DllImport( libraryPath, EntryPoint = "LLVMMetadataReplaceAllUsesWith", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void MetadataReplaceAllUsesWith( LLVMMetadataRef @MD, LLVMMetadataRef @New ); + + // Added to LLVM-C API in LLVM 5.0.0 + [DllImport( libraryPath, EntryPoint = "LLVMMetadataAsValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef MetadataAsValue( LLVMContextRef context, LLVMMetadataRef metadataRef ); + + /* Added to LLVM-C API in LLVM 5.0.0 + // [DllImport( libraryPath, EntryPoint = "LLVMValueAsMetadata", CallingConvention = CallingConvention.Cdecl )] + // internal static extern LLVMMetadataRef LLVMValueAsMetadata( LLVMValueRef Val ); + */ + + [DllImport( libraryPath, EntryPoint = "LLVMSetCurrentDebugLocation2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void SetCurrentDebugLocation2( LLVMBuilderRef @Bref, UInt32 @Line, UInt32 @Col, LLVMMetadataRef @Scope, LLVMMetadataRef @InlinedAt ); + + [DllImport( libraryPath, EntryPoint = "LLVMNewDIBuilder", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMDIBuilderRef NewDIBuilder( LLVMModuleRef @m, [MarshalAs(UnmanagedType.Bool)]bool allowUnresolved ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderDestroy", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void DIBuilderDestroy( LLVMDIBuilderRef @d ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderFinalize", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void DIBuilderFinalize( LLVMDIBuilderRef @d ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateCompileUnit", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateCompileUnit( LLVMDIBuilderRef @D, UInt32 @Language, [MarshalAs( UnmanagedType.LPStr )] string @File, [MarshalAs( UnmanagedType.LPStr )] string @Dir, [MarshalAs( UnmanagedType.LPStr )] string @Producer, int @Optimized, [MarshalAs( UnmanagedType.LPStr )] string @Flags, UInt32 @RuntimeVersion ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateFile", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateFile( LLVMDIBuilderRef @D, [MarshalAs( UnmanagedType.LPStr )] string @File, [MarshalAs( UnmanagedType.LPStr )] string @Dir ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateLexicalBlock", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateLexicalBlock( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, LLVMMetadataRef @File, UInt32 @Line, UInt32 @Column ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateLexicalBlockFile", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateLexicalBlockFile( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, LLVMMetadataRef @File, UInt32 @Discriminator ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateFunction", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateFunction( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, [MarshalAs( UnmanagedType.LPStr )] string @LinkageName, LLVMMetadataRef @File, UInt32 @Line, LLVMMetadataRef @CompositeType, int @IsLocalToUnit, int @IsDefinition, UInt32 @ScopeLine, UInt32 @Flags, int @IsOptimized, LLVMMetadataRef TParam, LLVMMetadataRef Decl ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateTempFunctionFwdDecl", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateTempFunctionFwdDecl( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, [MarshalAs( UnmanagedType.LPStr )] string @LinkageName, LLVMMetadataRef @File, UInt32 @Line, LLVMMetadataRef @CompositeType, int @IsLocalToUnit, int @IsDefinition, UInt32 @ScopeLine, UInt32 @Flags, int @IsOptimized, LLVMMetadataRef TParam, LLVMMetadataRef Decl ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateAutoVariable", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateAutoVariable( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMMetadataRef @File, UInt32 @Line, LLVMMetadataRef @Ty, int @AlwaysPreserve, UInt32 @Flags ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateParameterVariable", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateParameterVariable( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, UInt32 @ArgNo, LLVMMetadataRef @File, UInt32 @Line, LLVMMetadataRef @Ty, int @AlwaysPreserve, UInt32 @Flags ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateBasicType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateBasicType( LLVMDIBuilderRef @D, [MarshalAs( UnmanagedType.LPStr )] string @Name, UInt64 @SizeInBits, UInt32 @Encoding ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreatePointerType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreatePointerType( LLVMDIBuilderRef @D, LLVMMetadataRef @PointeeType, UInt64 @SizeInBits, UInt32 @AlignInBits, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateQualifiedType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateQualifiedType( LLVMDIBuilderRef Dref, UInt32 Tag, LLVMMetadataRef BaseType ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateSubroutineType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateSubroutineType( LLVMDIBuilderRef @D, LLVMMetadataRef @ParameterTypes, UInt32 @Flags ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateStructType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateStructType( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMMetadataRef @File, UInt32 @Line, UInt64 @SizeInBits, UInt32 @AlignInBits, UInt32 @Flags, LLVMMetadataRef @DerivedFrom, LLVMMetadataRef @ElementTypes ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateUnionType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateUnionType( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMMetadataRef @File, UInt32 @Line, UInt64 @SizeInBits, UInt32 @AlignInBits, UInt32 @Flags, LLVMMetadataRef @ElementTypes ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateMemberType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateMemberType( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMMetadataRef @File, UInt32 @Line, UInt64 @SizeInBits, UInt32 @AlignInBits, UInt64 @OffsetInBits, UInt32 @Flags, LLVMMetadataRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateArrayType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateArrayType( LLVMDIBuilderRef @D, UInt64 @SizeInBits, UInt32 @AlignInBits, LLVMMetadataRef @ElementType, LLVMMetadataRef @Subscripts ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateVectorType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateVectorType( LLVMDIBuilderRef @D, UInt64 @SizeInBits, UInt32 @AlignInBits, LLVMMetadataRef @ElementType, LLVMMetadataRef @Subscripts ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateTypedef", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateTypedef( LLVMDIBuilderRef @D, LLVMMetadataRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMMetadataRef @File, UInt32 @Line, LLVMMetadataRef @Context ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderGetOrCreateSubrange", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderGetOrCreateSubrange( LLVMDIBuilderRef @D, Int64 @Lo, Int64 @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderGetOrCreateArray", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderGetOrCreateArray( LLVMDIBuilderRef @D, out LLVMMetadataRef @Data, UInt64 @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderGetOrCreateTypeArray", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderGetOrCreateTypeArray( LLVMDIBuilderRef @D, out LLVMMetadataRef @Data, UInt64 @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateExpression", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateExpression( LLVMDIBuilderRef @Dref, out Int64 @Addr, UInt64 @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderInsertDeclareAtEnd", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef DIBuilderInsertDeclareAtEnd( LLVMDIBuilderRef @D, LLVMValueRef @Storage, LLVMMetadataRef @VarInfo, LLVMMetadataRef @Expr, LLVMMetadataRef Location, LLVMBasicBlockRef @Block ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderInsertValueAtEnd", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef DIBuilderInsertValueAtEnd( LLVMDIBuilderRef @D, LLVMValueRef @Val, UInt64 @Offset, LLVMMetadataRef @VarInfo, LLVMMetadataRef @Expr, LLVMMetadataRef Location, LLVMBasicBlockRef @Block ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateEnumerationType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateEnumerationType( LLVMDIBuilderRef @D, LLVMMetadataRef @Scope, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMMetadataRef @File, UInt32 @LineNumber, UInt64 @SizeInBits, UInt32 @AlignInBits, LLVMMetadataRef @Elements, LLVMMetadataRef @UnderlyingType, [MarshalAs( UnmanagedType.LPStr )]string @UniqueId ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateEnumeratorValue", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateEnumeratorValue( LLVMDIBuilderRef @D, [MarshalAs( UnmanagedType.LPStr )]string @Name, Int64 @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIDescriptorGetTag", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMDwarfTag DIDescriptorGetTag( LLVMMetadataRef descriptor ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateGlobalVariableExpression", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateGlobalVariableExpression( LLVMDIBuilderRef Dref, LLVMMetadataRef Context, [MarshalAs( UnmanagedType.LPStr )] string Name, [MarshalAs( UnmanagedType.LPStr )] string LinkageName, LLVMMetadataRef File, UInt32 LineNo, LLVMMetadataRef Ty, [MarshalAs( UnmanagedType.Bool )]bool isLocalToUnit, LLVMMetadataRef expression, LLVMMetadataRef Decl, UInt32 AlignInBits ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderInsertDeclareBefore", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef DIBuilderInsertDeclareBefore( LLVMDIBuilderRef Dref, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef Location, LLVMValueRef InsertBefore ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderInsertValueBefore", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef DIBuilderInsertValueBefore( LLVMDIBuilderRef Dref, /*llvm::Value **/LLVMValueRef Val, UInt64 Offset, /*DILocalVariable **/ LLVMMetadataRef VarInfo, /*DIExpression **/ LLVMMetadataRef Expr, /*const DILocation **/ LLVMMetadataRef DL, /*Instruction **/ LLVMValueRef InsertBefore ); + + [DllImport( libraryPath, EntryPoint = "LLVMMetadataAsString", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string MetadataAsString( LLVMMetadataRef descriptor ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNodeReplaceAllUsesWith", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void MDNodeReplaceAllUsesWith( LLVMMetadataRef oldDescriptor, LLVMMetadataRef newDescriptor ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateReplaceableCompositeType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateReplaceableCompositeType( LLVMDIBuilderRef Dref, UInt32 Tag, [MarshalAs( UnmanagedType.LPStr )] string Name, LLVMMetadataRef Scope, LLVMMetadataRef File, UInt32 Line, UInt32 RuntimeLang, UInt64 SizeInBits, UInt64 AlignInBits, UInt32 Flags ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIBuilderCreateNamespace", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIBuilderCreateNamespace( LLVMDIBuilderRef Dref, LLVMMetadataRef scope, [MarshalAs( UnmanagedType.LPStr )] string name, [MarshalAs( UnmanagedType.Bool )]bool exportSymbols ); + + [DllImport( libraryPath, EntryPoint = "LLVMDILocation", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DILocation( LLVMContextRef context, UInt32 Line, UInt32 Column, LLVMMetadataRef scope, LLVMMetadataRef InlinedAt ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetModuleName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ))] + internal static extern string GetModuleName( LLVMModuleRef module ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsTemporary", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsTemporary( LLVMMetadataRef M ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsResolved", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsResolved( LLVMMetadataRef M ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsDistinct", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsDistinct( LLVMMetadataRef M ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsUniqued", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsUniqued( LLVMMetadataRef M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMDStringText", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetMDStringText( LLVMMetadataRef M, out UInt32 len ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetGlobalAlias", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef GetGlobalAlias( LLVMModuleRef module, [MarshalAs( UnmanagedType.LPStr )] string name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetAliasee", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMValueRef GetAliasee( LLVMValueRef Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNodeResolveCycles", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void MDNodeResolveCycles( LLVMMetadataRef M ); + + [DllImport( libraryPath, EntryPoint = "LLVMSubProgramDescribes", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool SubProgramDescribes( LLVMMetadataRef subProgram, LLVMValueRef function ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetLine", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 DITypeGetLine( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetSizeInBits", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt64 DITypeGetSizeInBits( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetAlignInBits", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt64 DITypeGetAlignInBits( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetOffsetInBits", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt64 DITypeGetOffsetInBits( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetFlags", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 DITypeGetFlags( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetScope", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DITypeGetScope( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDITypeGetName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string DITypeGetName( LLVMMetadataRef typeRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIScopeGetFile", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DIScopeGetFile( LLVMMetadataRef scope ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetArgumentIndex", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 GetArgumentIndex( LLVMValueRef Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDIFileName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetDIFileName( LLVMMetadataRef /*DIFile*/ file ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDIFileDirectory", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetDIFileDirectory( LLVMMetadataRef /*DIFile*/ file ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNodeContext", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMContextRef GetNodeContext( LLVMMetadataRef /*MDNode*/ node ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMetadataID", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataKind GetMetadataID( LLVMMetadataRef /*Metadata*/ md ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNodeGetNumOperands", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern UInt32 MDNodeGetNumOperands( LLVMMetadataRef /*MDNode*/ node ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNodeGetOperand", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMDOperandRef MDNodeGetOperand( LLVMMetadataRef /*MDNode*/ node, UInt32 index ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetOperandNode", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef GetOperandNode( LLVMMDOperandRef operand ); + + [DllImport( libraryPath, EntryPoint = "LLVMDILocalScopeGetSubProgram", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef DILocalScopeGetSubProgram( LLVMMetadataRef /*DILocalScope*/ localScope ); + + [DllImport( libraryPath, EntryPoint = "LLVMFunctionGetSubprogram", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMMetadataRef FunctionGetSubprogram( LLVMValueRef function ); + + [DllImport( libraryPath, EntryPoint = "LLVMFunctionSetSubprogram", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void FunctionSetSubprogram( LLVMValueRef function, LLVMMetadataRef subprogram ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreatePassRegistry", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMPassRegistryRef CreatePassRegistry( ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassRegistryDispose", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void PassRegistryDispose( IntPtr hPassRegistry ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunPassPipeline", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool RunPassPipeline( LLVMContextRef context, LLVMModuleRef M, LLVMTargetMachineRef TM, [MarshalAs( UnmanagedType.LPStr )] string passPipeline, LLVMOptVerifierKind VK, [MarshalAs( UnmanagedType.Bool )] bool ShouldPreserveAssemblyUseListOrder, [MarshalAs( UnmanagedType.Bool )] bool ShouldPreserveBitcodeUseListOrder ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeCodeGenForOpt", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void InitializeCodeGenForOpt( LLVMPassRegistryRef R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePassesForLegacyOpt", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void InitializePassesForLegacyOpt( ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunLegacyOptimizer", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void RunLegacyOptimizer( LLVMModuleRef Mref, LLVMTargetMachineRef TMref ); + + [DllImport( libraryPath, EntryPoint = "LLVMParseTriple", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleRef ParseTriple( [MarshalAs( UnmanagedType.LPStr )] string triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeTriple", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void DisposeTriple( IntPtr triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleOpEqual", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool TripleOpEqual( LLVMTripleRef lhs, LLVMTripleRef rhs ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetArchType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleArchType TripleGetArchType( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetSubArchType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleSubArchType TripleGetSubArchType( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetVendorType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleVendorType TripleGetVendorType( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetOsType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleOSType TripleGetOsType( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleHasEnvironment", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool TripleHasEnvironment( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetEnvironmentType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleEnvironmentType TripleGetEnvironmentType( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetEnvironmentVersion", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void TripleGetEnvironmentVersion( LLVMTripleRef triple, out UInt32 major, out UInt32 minor, out UInt32 micro ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetObjectFormatType", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMTripleObjectFormatType TripleGetObjectFormatType( LLVMTripleRef triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleAsString", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleAsString( LLVMTripleRef triple, [MarshalAs( UnmanagedType.U1 )]bool normalize ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetArchTypeName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleGetArchTypeName( LLVMTripleArchType type ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetSubArchTypeName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleGetSubArchTypeName( LLVMTripleSubArchType type ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetVendorTypeName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleGetVendorTypeName( LLVMTripleVendorType vendor ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetOsTypeName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleGetOsTypeName( LLVMTripleOSType osType ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetEnvironmentTypeName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleGetEnvironmentTypeName( LLVMTripleEnvironmentType environmentType ); + + [DllImport( libraryPath, EntryPoint = "LLVMTripleGetObjectFormatTypeName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string TripleGetObjectFormatTypeName( LLVMTripleObjectFormatType environmentType ); + + [DllImport( libraryPath, EntryPoint = "LLVMNormalizeTriple", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string NormalizeTriple( [MarshalAs( UnmanagedType.LPStr )] string triple ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs( UnmanagedType.Bool )] + internal delegate bool ComdatIteratorCallback( LLVMComdatRef comdatRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleEnumerateComdats", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void ModuleEnumerateComdats( LLVMModuleRef module, ComdatIteratorCallback callback ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleInsertOrUpdateComdat", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMComdatRef ModuleInsertOrUpdateComdat( LLVMModuleRef module, [MarshalAs( UnmanagedType.LPStr )] string name, LLVMComdatSelectionKind kind ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleComdatRemove", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void ModuleComdatRemove( LLVMModuleRef module, LLVMComdatRef comdatRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleComdatClear", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void ModuleComdatClear( LLVMModuleRef module ); + + [DllImport( libraryPath, EntryPoint = "LLVMGlobalObjectGetComdat", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMComdatRef GlobalObjectGetComdat( LLVMValueRef Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGlobalObjectSetComdat", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void GlobalObjectSetComdat( LLVMValueRef Val, LLVMComdatRef comdatRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMComdatGetKind", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern LLVMComdatSelectionKind ComdatGetKind( LLVMComdatRef comdatRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMComdatSetKind", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + internal static extern void ComdatSetKind( LLVMComdatRef comdatRef, LLVMComdatSelectionKind kind ); + + [DllImport( libraryPath, EntryPoint = "LLVMComdatGetName", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string ComdatGetName( LLVMComdatRef comdatRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMAttributeToString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + internal static extern string AttributeToString( LLVMAttributeRef attribute ); + + [DllImport( libraryPath, EntryPoint = "LLVMDIGlobalVarExpGetVariable", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMMetadataRef DIGlobalVarExpGetVariable( LLVMMetadataRef metadataHandle ); + + [DllImport( libraryPath, EntryPoint = "LLVMGlobalVariableAddDebugExpression", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GlobalVariableAddDebugExpression( LLVMValueRef variable, LLVMMetadataRef metadataHandle ); + } +} diff --git a/src/Llvm.NET/Native/Generated.cs b/src/Llvm.NET/Native/Generated.cs new file mode 100644 index 000000000..32800c6cd --- /dev/null +++ b/src/Llvm.NET/Native/Generated.cs @@ -0,0 +1,3699 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +// warning CS0649: Field 'xxx' is never assigned to, and will always have its default value 0 +#pragma warning disable 649 + +namespace Llvm.NET.Native +{ + internal partial struct LLVMOpaqueMemoryBuffer + { + } + + internal partial struct LLVMOpaqueContext + { + } + + internal partial struct LLVMOpaqueModule + { + } + + internal partial struct LLVMOpaqueType + { + } + + internal partial struct LLVMOpaqueValue + { + } + + internal partial struct LLVMOpaqueBasicBlock + { + } + + internal partial struct LLVMOpaqueBuilder + { + } + + internal partial struct LLVMOpaqueModuleProvider + { + } + + internal partial struct LLVMOpaquePassManager + { + } + + internal partial struct LLVMOpaquePassRegistry + { + } + + internal partial struct LLVMOpaqueUse + { + } + + internal partial struct LLVMOpaqueDiagnosticInfo + { + } + + internal partial struct LLVMOpInfoSymbol1 + { + internal int @Present; + [MarshalAs( UnmanagedType.LPStr )] + internal string @Name; + internal int @Value; + } + + internal partial struct LLVMOpInfo1 + { + internal LLVMOpInfoSymbol1 @AddSymbol; + internal LLVMOpInfoSymbol1 @SubtractSymbol; + internal int @Value; + internal int @VariantKind; + } + + internal partial struct LLVMOpaqueTargetData + { + } + + internal partial struct LLVMOpaqueTargetLibraryInfotData + { + } + + internal partial struct LLVMOpaqueTargetMachine + { + } + + internal partial struct LLVMTarget + { + } + + internal partial struct LLVMOpaqueGenericValue + { + } + + internal partial struct LLVMOpaqueExecutionEngine + { + } + + internal partial struct LLVMOpaqueMCJITMemoryManager + { + } + + internal partial struct LLVMMCJITCompilerOptions + { + internal uint @OptLevel; + internal LLVMCodeModel @CodeModel; + internal int @NoFramePointerElim; + internal int @EnableFastISel; + internal LLVMMCJITMemoryManagerRef @MCJMM; + } + + internal partial struct LLVMOpaqueLTOModule + { + } + + internal partial struct LLVMOpaqueLTOCodeGenerator + { + } + + internal partial struct LLVMOpaqueObjectFile + { + } + + internal partial struct LLVMOpaqueSectionIterator + { + } + + internal partial struct LLVMOpaqueSymbolIterator + { + } + + internal partial struct LLVMOpaqueRelocationIterator + { + } + + internal partial struct LLVMOrcOpaqueJITStack + { + } + + internal partial struct LLVMOpaquePassManagerBuilder + { + } + + // hand added to help clarify use when the value + // is not really a bool but a status where (0==SUCCESS) + internal partial struct LLVMStatus + { + public LLVMStatus( int value ) + { + ErrorCode = value; + } + + public bool Succeeded => ErrorCode == 0; + + public bool Failed => !Succeeded; + + public static implicit operator bool( LLVMStatus value ) => value.Succeeded; + + public int ErrorCode { get; } + } + + internal partial struct LLVMMemoryBufferRef + { + internal LLVMMemoryBufferRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMContextRef + { + internal LLVMContextRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMModuleRef + { + internal LLVMModuleRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMTypeRef + { + internal LLVMTypeRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMValueRef + { + internal LLVMValueRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMBasicBlockRef + { + internal LLVMBasicBlockRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMMetadataRef + { + internal LLVMMetadataRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal readonly IntPtr Pointer; + } + + internal partial struct LLVMDIBuilderRef + { + internal LLVMDIBuilderRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal readonly IntPtr Pointer; + } + + /* replaced with SafeHandle Variant to ensure release + internal partial struct LLVMBuilderRef + { + internal LLVMBuilderRef(IntPtr pointer) + { + this.Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + */ + + internal partial struct LLVMModuleProviderRef + { + internal LLVMModuleProviderRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMPassManagerRef + { + internal LLVMPassManagerRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + /* replaced with SafeHandle Variant to ensure release + internal partial struct LLVMPassRegistryRef + { + internal LLVMPassRegistryRef(IntPtr pointer) + { + this.Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + */ + + internal partial struct LLVMUseRef + { + internal LLVMUseRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMAttributeRef + { + internal LLVMAttributeRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMDiagnosticInfoRef + { + internal LLVMDiagnosticInfoRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate void LLVMFatalErrorHandler( [MarshalAs( UnmanagedType.LPStr )] string reason ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate void LLVMDiagnosticHandler( LLVMDiagnosticInfoRef @param0, IntPtr @param1 ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate void LLVMYieldCallback( LLVMContextRef @param0, IntPtr @param1 ); + + internal partial struct LLVMDisasmContextRef + { + internal LLVMDisasmContextRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate int LLVMOpInfoCallback( IntPtr disInfo, int pC, int offset, int size, int tagType, IntPtr tagBuf ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate string LLVMSymbolLookupCallback( IntPtr disInfo, int referenceValue, out int referenceType, int referencePC, out IntPtr referenceName ); + + internal partial struct LLVMTargetDataRef + { + internal LLVMTargetDataRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMTargetLibraryInfoRef + { + internal LLVMTargetLibraryInfoRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMTargetMachineRef + { + internal LLVMTargetMachineRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMTargetRef + { + internal LLVMTargetRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMGenericValueRef + { + internal LLVMGenericValueRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMExecutionEngineRef + { + internal LLVMExecutionEngineRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMMCJITMemoryManagerRef + { + internal LLVMMCJITMemoryManagerRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate IntPtr LLVMMemoryManagerAllocateCodeSectionCallback( IntPtr opaque, int size, uint alignment, uint sectionID, [MarshalAs( UnmanagedType.LPStr )] string sectionName ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate IntPtr LLVMMemoryManagerAllocateDataSectionCallback( IntPtr opaque, int size, uint alignment, uint sectionID, [MarshalAs( UnmanagedType.LPStr )] string sectionName, int isReadOnly ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate int LLVMMemoryManagerFinalizeMemoryCallback( IntPtr opaque, out IntPtr errMsg ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate void LLVMMemoryManagerDestroyCallback( IntPtr opaque ); + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type")] + internal partial struct llvm_lto_t + { + internal llvm_lto_t( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal partial struct lto_bool_t + { + internal lto_bool_t( bool value ) + { + Value = value; + } + + internal bool Value; + } + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal partial struct lto_module_t + { + internal lto_module_t( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal partial struct lto_code_gen_t + { + internal lto_code_gen_t( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal delegate void lto_diagnostic_handler_t( lto_codegen_diagnostic_severity_t @severity, [MarshalAs( UnmanagedType.LPStr )] string @diag, IntPtr @ctxt ); + + internal partial struct LLVMObjectFileRef + { + internal LLVMObjectFileRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMSectionIteratorRef + { + internal LLVMSectionIteratorRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMSymbolIteratorRef + { + internal LLVMSymbolIteratorRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMRelocationIteratorRef + { + internal LLVMRelocationIteratorRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMSharedModuleRef + { + internal LLVMSharedModuleRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMSharedObjectBufferRef + { + internal LLVMSharedObjectBufferRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMOrcJITStackRef + { + internal LLVMOrcJITStackRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal partial struct LLVMOrcModuleHandle + { + internal LLVMOrcModuleHandle( int value ) + { + Value = value; + } + + internal int Value { get; } + } + + internal partial struct LLVMOrcTargetAddress + { + internal LLVMOrcTargetAddress( ulong value ) + { + Value = value; + } + + internal ulong Value { get; } + } + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate ulong LLVMOrcSymbolResolverFn( [MarshalAs( UnmanagedType.LPStr )] string name, IntPtr lookupCtx ); + + [UnmanagedFunctionPointer( CallingConvention.Cdecl )] + internal delegate ulong LLVMOrcLazyCompileCallbackFn( LLVMOrcJITStackRef jITStack, IntPtr callbackCtx ); + + internal partial struct LLVMPassManagerBuilderRef + { + internal LLVMPassManagerBuilderRef( IntPtr pointer ) + { + Pointer = pointer; + } + + internal IntPtr Pointer { get; } + } + + internal enum LLVMVerifierFailureAction + { + @LLVMAbortProcessAction = 0, + @LLVMPrintMessageAction = 1, + @LLVMReturnStatusAction = 2, + } + +#pragma warning disable CA1008 // Enums should have zero value. + internal enum LLVMAttribute + { + @LLVMZExtAttribute = 1, + @LLVMSExtAttribute = 2, + @LLVMNoReturnAttribute = 4, + @LLVMInRegAttribute = 8, + @LLVMStructRetAttribute = 16, + @LLVMNoUnwindAttribute = 32, + @LLVMNoAliasAttribute = 64, + @LLVMByValAttribute = 128, + @LLVMNestAttribute = 256, + @LLVMReadNoneAttribute = 512, + @LLVMReadOnlyAttribute = 1024, + @LLVMNoInlineAttribute = 2048, + @LLVMAlwaysInlineAttribute = 4096, + @LLVMOptimizeForSizeAttribute = 8192, + @LLVMStackProtectAttribute = 16384, + @LLVMStackProtectReqAttribute = 32768, + @LLVMAlignment = 2031616, + @LLVMNoCaptureAttribute = 2097152, + @LLVMNoRedZoneAttribute = 4194304, + @LLVMNoImplicitFloatAttribute = 8388608, + @LLVMNakedAttribute = 16777216, + @LLVMInlineHintAttribute = 33554432, + @LLVMStackAlignment = 469762048, + @LLVMReturnsTwice = 536870912, + @LLVMUWTable = 1073741824, + @LLVMNonLazyBind = -2147483648, + } + + internal enum LLVMOpcode + { + @LLVMRet = 1, + @LLVMBr = 2, + @LLVMSwitch = 3, + @LLVMIndirectBr = 4, + @LLVMInvoke = 5, + @LLVMUnreachable = 7, + @LLVMAdd = 8, + @LLVMFAdd = 9, + @LLVMSub = 10, + @LLVMFSub = 11, + @LLVMMul = 12, + @LLVMFMul = 13, + @LLVMUDiv = 14, + @LLVMSDiv = 15, + @LLVMFDiv = 16, + @LLVMURem = 17, + @LLVMSRem = 18, + @LLVMFRem = 19, + @LLVMShl = 20, + @LLVMLShr = 21, + @LLVMAShr = 22, + @LLVMAnd = 23, + @LLVMOr = 24, + @LLVMXor = 25, + @LLVMAlloca = 26, + @LLVMLoad = 27, + @LLVMStore = 28, + @LLVMGetElementPtr = 29, + @LLVMTrunc = 30, + @LLVMZExt = 31, + @LLVMSExt = 32, + @LLVMFPToUI = 33, + @LLVMFPToSI = 34, + @LLVMUIToFP = 35, + @LLVMSIToFP = 36, + @LLVMFPTrunc = 37, + @LLVMFPExt = 38, + @LLVMPtrToInt = 39, + @LLVMIntToPtr = 40, + @LLVMBitCast = 41, + @LLVMAddrSpaceCast = 60, + @LLVMICmp = 42, + @LLVMFCmp = 43, + @LLVMPHI = 44, + @LLVMCall = 45, + @LLVMSelect = 46, + @LLVMUserOp1 = 47, + @LLVMUserOp2 = 48, + @LLVMVAArg = 49, + @LLVMExtractElement = 50, + @LLVMInsertElement = 51, + @LLVMShuffleVector = 52, + @LLVMExtractValue = 53, + @LLVMInsertValue = 54, + @LLVMFence = 55, + @LLVMAtomicCmpXchg = 56, + @LLVMAtomicRMW = 57, + @LLVMResume = 58, + @LLVMLandingPad = 59, + @LLVMCleanupRet = 61, + @LLVMCatchRet = 62, + @LLVMCatchPad = 63, + @LLVMCleanupPad = 64, + @LLVMCatchSwitch = 65, + } +#pragma warning restore CA1008 // Enums should have zero value. + + internal enum LLVMTypeKind + { + @LLVMVoidTypeKind = 0, + @LLVMHalfTypeKind = 1, + @LLVMFloatTypeKind = 2, + @LLVMDoubleTypeKind = 3, + @LLVMX86_FP80TypeKind = 4, + @LLVMFP128TypeKind = 5, + @LLVMPPC_FP128TypeKind = 6, + @LLVMLabelTypeKind = 7, + @LLVMIntegerTypeKind = 8, + @LLVMFunctionTypeKind = 9, + @LLVMStructTypeKind = 10, + @LLVMArrayTypeKind = 11, + @LLVMPointerTypeKind = 12, + @LLVMVectorTypeKind = 13, + @LLVMMetadataTypeKind = 14, + @LLVMX86_MMXTypeKind = 15, + @LLVMTokenTypeKind = 16, + } + + internal enum LLVMLinkage + { + @LLVMExternalLinkage = 0, + @LLVMAvailableExternallyLinkage = 1, + @LLVMLinkOnceAnyLinkage = 2, + @LLVMLinkOnceODRLinkage = 3, + @LLVMLinkOnceODRAutoHideLinkage = 4, + @LLVMWeakAnyLinkage = 5, + @LLVMWeakODRLinkage = 6, + @LLVMAppendingLinkage = 7, + @LLVMInternalLinkage = 8, + @LLVMPrivateLinkage = 9, + @LLVMDLLImportLinkage = 10, + @LLVMDLLExportLinkage = 11, + @LLVMExternalWeakLinkage = 12, + @LLVMGhostLinkage = 13, + @LLVMCommonLinkage = 14, + @LLVMLinkerPrivateLinkage = 15, + @LLVMLinkerPrivateWeakLinkage = 16, + } + + internal enum LLVMVisibility + { + @LLVMDefaultVisibility = 0, + @LLVMHiddenVisibility = 1, + @LLVMProtectedVisibility = 2, + } + + internal enum LLVMDLLStorageClass + { + @LLVMDefaultStorageClass = 0, + @LLVMDLLImportStorageClass = 1, + @LLVMDLLExportStorageClass = 2, + } + + internal enum LLVMCallConv + { + @LLVMCCallConv = 0, + @LLVMFastCallConv = 8, + @LLVMColdCallConv = 9, + @LLVMWebKitJSCallConv = 12, + @LLVMAnyRegCallConv = 13, + @LLVMX86StdcallCallConv = 64, + @LLVMX86FastcallCallConv = 65, + } + + internal enum LLVMValueKind + { + @LLVMArgumentValueKind = 0, + @LLVMBasicBlockValueKind = 1, + @LLVMMemoryUseValueKind = 2, + @LLVMMemoryDefValueKind = 3, + @LLVMMemoryPhiValueKind = 4, + @LLVMFunctionValueKind = 5, + @LLVMGlobalAliasValueKind = 6, + @LLVMGlobalIFuncValueKind = 7, + @LLVMGlobalVariableValueKind = 8, + @LLVMBlockAddressValueKind = 9, + @LLVMConstantExprValueKind = 10, + @LLVMConstantArrayValueKind = 11, + @LLVMConstantStructValueKind = 12, + @LLVMConstantVectorValueKind = 13, + @LLVMUndefValueValueKind = 14, + @LLVMConstantAggregateZeroValueKind = 15, + @LLVMConstantDataArrayValueKind = 16, + @LLVMConstantDataVectorValueKind = 17, + @LLVMConstantIntValueKind = 18, + @LLVMConstantFPValueKind = 19, + @LLVMConstantPointerNullValueKind = 20, + @LLVMConstantTokenNoneValueKind = 21, + @LLVMMetadataAsValueValueKind = 22, + @LLVMInlineAsmValueKind = 23, + @LLVMInstructionValueKind = 24, + } + +#pragma warning disable CA1008 // Enums should have zero value. + internal enum LLVMIntPredicate + { + @LLVMIntEQ = 32, + @LLVMIntNE = 33, + @LLVMIntUGT = 34, + @LLVMIntUGE = 35, + @LLVMIntULT = 36, + @LLVMIntULE = 37, + @LLVMIntSGT = 38, + @LLVMIntSGE = 39, + @LLVMIntSLT = 40, + @LLVMIntSLE = 41, + } +#pragma warning restore CA1008 // Enums should have zero value. + + internal enum LLVMRealPredicate + { + @LLVMRealPredicateFalse = 0, + @LLVMRealOEQ = 1, + @LLVMRealOGT = 2, + @LLVMRealOGE = 3, + @LLVMRealOLT = 4, + @LLVMRealOLE = 5, + @LLVMRealONE = 6, + @LLVMRealORD = 7, + @LLVMRealUNO = 8, + @LLVMRealUEQ = 9, + @LLVMRealUGT = 10, + @LLVMRealUGE = 11, + @LLVMRealULT = 12, + @LLVMRealULE = 13, + @LLVMRealUNE = 14, + @LLVMRealPredicateTrue = 15, + } + + internal enum LLVMLandingPadClauseTy + { + @LLVMLandingPadCatch = 0, + @LLVMLandingPadFilter = 1, + } + + internal enum LLVMThreadLocalMode + { + @LLVMNotThreadLocal = 0, + @LLVMGeneralDynamicTLSModel = 1, + @LLVMLocalDynamicTLSModel = 2, + @LLVMInitialExecTLSModel = 3, + @LLVMLocalExecTLSModel = 4, + } + + internal enum LLVMAtomicOrdering + { + @LLVMAtomicOrderingNotAtomic = 0, + @LLVMAtomicOrderingUnordered = 1, + @LLVMAtomicOrderingMonotonic = 2, + @LLVMAtomicOrderingAcquire = 4, + @LLVMAtomicOrderingRelease = 5, + @LLVMAtomicOrderingAcquireRelease = 6, + @LLVMAtomicOrderingSequentiallyConsistent = 7, + } + + internal enum LLVMAtomicRMWBinOp + { + @LLVMAtomicRMWBinOpXchg = 0, + @LLVMAtomicRMWBinOpAdd = 1, + @LLVMAtomicRMWBinOpSub = 2, + @LLVMAtomicRMWBinOpAnd = 3, + @LLVMAtomicRMWBinOpNand = 4, + @LLVMAtomicRMWBinOpOr = 5, + @LLVMAtomicRMWBinOpXor = 6, + @LLVMAtomicRMWBinOpMax = 7, + @LLVMAtomicRMWBinOpMin = 8, + @LLVMAtomicRMWBinOpUMax = 9, + @LLVMAtomicRMWBinOpUMin = 10, + } + + internal enum LLVMDiagnosticSeverity + { + @LLVMDSError = 0, + @LLVMDSWarning = 1, + @LLVMDSRemark = 2, + @LLVMDSNote = 3, + } + + internal enum LLVMAttributeIndex + { + @LLVMAttributeReturnIndex = 0, + @LLVMAttributeFunctionIndex = -1, + } + + internal enum LLVMByteOrdering + { + @LLVMBigEndian = 0, + @LLVMLittleEndian = 1, + } + + internal enum LLVMCodeGenOptLevel + { + @LLVMCodeGenLevelNone = 0, + @LLVMCodeGenLevelLess = 1, + @LLVMCodeGenLevelDefault = 2, + @LLVMCodeGenLevelAggressive = 3, + } + + internal enum LLVMRelocMode + { + @LLVMRelocDefault = 0, + @LLVMRelocStatic = 1, + @LLVMRelocPIC = 2, + @LLVMRelocDynamicNoPic = 3, + } + + internal enum LLVMCodeModel + { + @LLVMCodeModelDefault = 0, + @LLVMCodeModelJITDefault = 1, + @LLVMCodeModelSmall = 2, + @LLVMCodeModelKernel = 3, + @LLVMCodeModelMedium = 4, + @LLVMCodeModelLarge = 5, + } + + internal enum LLVMCodeGenFileType + { + @LLVMAssemblyFile = 0, + @LLVMObjectFile = 1, + } + + internal enum LLVMLinkerMode + { + @LLVMLinkerDestroySource = 0, + @LLVMLinkerPreserveSource_Removed = 1, + } + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal enum llvm_lto_status + { + @LLVM_LTO_UNKNOWN = 0, + @LLVM_LTO_OPT_SUCCESS = 1, + @LLVM_LTO_READ_SUCCESS = 2, + @LLVM_LTO_READ_FAILURE = 3, + @LLVM_LTO_WRITE_FAILURE = 4, + @LLVM_LTO_NO_TARGET = 5, + @LLVM_LTO_NO_WORK = 6, + @LLVM_LTO_MODULE_MERGE_FAILURE = 7, + @LLVM_LTO_ASM_FAILURE = 8, + @LLVM_LTO_NULL_OBJECT = 9, + } + +#pragma warning disable CA1008 // Enums should have zero value. + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal enum lto_symbol_attributes + { + @LTO_SYMBOL_ALIGNMENT_MASK = 31, + @LTO_SYMBOL_PERMISSIONS_MASK = 224, + @LTO_SYMBOL_PERMISSIONS_CODE = 160, + @LTO_SYMBOL_PERMISSIONS_DATA = 192, + @LTO_SYMBOL_PERMISSIONS_RODATA = 128, + @LTO_SYMBOL_DEFINITION_MASK = 1792, + @LTO_SYMBOL_DEFINITION_REGULAR = 256, + @LTO_SYMBOL_DEFINITION_TENTATIVE = 512, + @LTO_SYMBOL_DEFINITION_WEAK = 768, + @LTO_SYMBOL_DEFINITION_UNDEFINED = 1024, + @LTO_SYMBOL_DEFINITION_WEAKUNDEF = 1280, + @LTO_SYMBOL_SCOPE_MASK = 14336, + @LTO_SYMBOL_SCOPE_INTERNAL = 2048, + @LTO_SYMBOL_SCOPE_HIDDEN = 4096, + @LTO_SYMBOL_SCOPE_PROTECTED = 8192, + @LTO_SYMBOL_SCOPE_DEFAULT = 6144, + @LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 10240, + @LTO_SYMBOL_COMDAT = 16384, + @LTO_SYMBOL_ALIAS = 32768, + } +#pragma warning restore CA1008 // Enums should have zero value. + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal enum lto_debug_model + { + @LTO_DEBUG_MODEL_NONE = 0, + @LTO_DEBUG_MODEL_DWARF = 1, + } + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal enum lto_codegen_model + { + @LTO_CODEGEN_PIC_MODEL_STATIC = 0, + @LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, + @LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, + @LTO_CODEGEN_PIC_MODEL_DEFAULT = 3, + } + + [SuppressMessage( "Style", "IDE1006:Naming Styles", Justification = "Low level Interop API matching" )] + [SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1300:Element must begin with upper-case letter", Justification = "Matches interop type" )] + internal enum lto_codegen_diagnostic_severity_t + { + @LTO_DS_ERROR = 0, + @LTO_DS_WARNING = 1, + @LTO_DS_REMARK = 3, + @LTO_DS_NOTE = 2, + } + + internal enum LLVMOrcErrorCode + { + @LLVMOrcErrSuccess = 0, + @LLVMOrcErrGeneric = 1, + } + + internal static partial class NativeMethods + { + private const string libraryPath = "libLLVM"; + + [DllImport( libraryPath, EntryPoint = "LLVMVerifyModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus VerifyModule( LLVMModuleRef @M, LLVMVerifierFailureAction @Action, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] out string @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMVerifyFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus VerifyFunction( LLVMValueRef @Fn, LLVMVerifierFailureAction @Action ); + + [DllImport( libraryPath, EntryPoint = "LLVMViewFunctionCFG", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ViewFunctionCFG( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMViewFunctionCFGOnly", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ViewFunctionCFGOnly( LLVMValueRef @Fn ); + + [Obsolete( "Use LLVMParseBitcode2 instead" )] + [DllImport( libraryPath, EntryPoint = "LLVMParseBitcode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus ParseBitcode( LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule, out IntPtr @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMParseBitcode2", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus ParseBitcode2( LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule ); + + [DllImport( libraryPath, EntryPoint = "LLVMParseBitcodeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus ParseBitcodeInContext( LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] out string @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMParseBitcodeInContext2", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus ParseBitcodeInContext2( LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBitcodeModuleInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus GetBitcodeModuleInContext( LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBitcodeModuleInContext2", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus GetBitcodeModuleInContext2( LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBitcodeModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus GetBitcodeModule( LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBitcodeModule2", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus GetBitcodeModule2( LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM ); + + [DllImport( libraryPath, EntryPoint = "LLVMWriteBitcodeToFile", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMStatus WriteBitcodeToFile( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Path ); + + [DllImport( libraryPath, EntryPoint = "LLVMWriteBitcodeToFD", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus WriteBitcodeToFD( LLVMModuleRef @M, int @FD, int @ShouldClose, int @Unbuffered ); + + [DllImport( libraryPath, EntryPoint = "LLVMWriteBitcodeToFileHandle", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus WriteBitcodeToFileHandle( LLVMModuleRef @M, int @Handle ); + + [DllImport( libraryPath, EntryPoint = "LLVMWriteBitcodeToMemoryBuffer", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMMemoryBufferRef WriteBitcodeToMemoryBuffer( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMInstallFatalErrorHandler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InstallFatalErrorHandler( LLVMFatalErrorHandler @Handler ); + + [DllImport( libraryPath, EntryPoint = "LLVMResetFatalErrorHandler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ResetFatalErrorHandler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMEnablePrettyStackTrace", CallingConvention = CallingConvention.Cdecl )] + internal static extern void EnablePrettyStackTrace( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeCore", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeCore( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMShutdown", CallingConvention = CallingConvention.Cdecl )] + internal static extern void Shutdown( ); + + /* CreateMessage should never be called by managed code + //[DllImport( libraryPath, EntryPoint = "LLVMCreateMessage", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + //internal static extern IntPtr CreateMessage( [MarshalAs( UnmanagedType.LPStr )] string @Message ); + */ + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeMessage", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeMessage( IntPtr @Message ); + + [DllImport( libraryPath, EntryPoint = "LLVMContextCreate", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMContextRef ContextCreate( ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetGlobalContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMContextRef GetGlobalContext( ); + + [DllImport( libraryPath, EntryPoint = "LLVMContextSetDiagnosticHandler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ContextSetDiagnosticHandler( LLVMContextRef @C, IntPtr @Handler, IntPtr @DiagnosticContext ); + + [DllImport( libraryPath, EntryPoint = "LLVMContextGetDiagnosticHandler", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMDiagnosticHandler ContextGetDiagnosticHandler( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMContextGetDiagnosticContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr ContextGetDiagnosticContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMContextSetYieldCallback", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ContextSetYieldCallback( LLVMContextRef @C, LLVMYieldCallback @Callback, IntPtr @OpaqueHandle ); + + [DllImport( libraryPath, EntryPoint = "LLVMContextDispose", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ContextDispose( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDiagInfoDescription", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string GetDiagInfoDescription( LLVMDiagnosticInfoRef @DI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDiagInfoSeverity", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMDiagnosticSeverity GetDiagInfoSeverity( LLVMDiagnosticInfoRef @DI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMDKindIDInContext", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern uint GetMDKindIDInContext( LLVMContextRef @C, [MarshalAs( UnmanagedType.LPStr )] string @Name, uint @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMDKindID", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern uint GetMDKindID( [MarshalAs( UnmanagedType.LPStr )] string @Name, uint @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetEnumAttributeKindForName", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern uint GetEnumAttributeKindForName( [MarshalAs( UnmanagedType.LPStr )] string @Name, size_t @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLastEnumAttributeKind", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetLastEnumAttributeKind( ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateEnumAttribute", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMAttributeRef CreateEnumAttribute( LLVMContextRef @C, uint @KindID, ulong @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetEnumAttributeKind", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetEnumAttributeKind( LLVMAttributeRef @A ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetEnumAttributeValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong GetEnumAttributeValue( LLVMAttributeRef @A ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateStringAttribute", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMAttributeRef CreateStringAttribute( LLVMContextRef @C, [MarshalAs( UnmanagedType.LPStr )] string @K, uint @KLength, [MarshalAs( UnmanagedType.LPStr )] string @V, uint @VLength ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetStringAttributeKind", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetStringAttributeKind( LLVMAttributeRef @A, out uint @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetStringAttributeValue", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetStringAttributeValue( LLVMAttributeRef @A, out uint @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsEnumAttribute", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsEnumAttribute( LLVMAttributeRef @A ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsStringAttribute", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsStringAttribute( LLVMAttributeRef @A ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleCreateWithName", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMModuleRef ModuleCreateWithName( [MarshalAs( UnmanagedType.LPStr )] string @ModuleID ); + + [DllImport( libraryPath, EntryPoint = "LLVMModuleCreateWithNameInContext", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMModuleRef ModuleCreateWithNameInContext( [MarshalAs( UnmanagedType.LPStr )] string @ModuleID, LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMCloneModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMModuleRef CloneModule( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeModule( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetModuleIdentifier", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetModuleIdentifier( LLVMModuleRef @M, out size_t @Len ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetModuleIdentifier", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetModuleIdentifier( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Ident, size_t @Len ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDataLayoutStr", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetDataLayoutStr( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDataLayout", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetDataLayout( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetDataLayout", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetDataLayout( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @DataLayoutStr ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTarget", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetTarget( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetTarget", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetTarget( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Triple ); + + [DllImport( libraryPath, EntryPoint = "LLVMDumpModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DumpModule( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMPrintModuleToFile", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMStatus PrintModuleToFile( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Filename, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] out string @ErrorMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMPrintModuleToString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string PrintModuleToString( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetModuleInlineAsm", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetModuleInlineAsm( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Asm ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetModuleContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMContextRef GetModuleContext( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTypeByName", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMTypeRef GetTypeByName( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNamedMetadataNumOperands", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern uint GetNamedMetadataNumOperands( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNamedMetadataOperands", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void GetNamedMetadataOperands( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name, out LLVMValueRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddNamedMetadataOperand", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void AddNamedMetadataOperand( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddFunction", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef AddFunction( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name, LLVMTypeRef @FunctionTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNamedFunction", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef GetNamedFunction( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetFirstFunction( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLastFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetLastFunction( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetNextFunction( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPreviousFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetPreviousFunction( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTypeKind", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeKind GetTypeKind( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMTypeIsSized", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool TypeIsSized( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTypeContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMContextRef GetTypeContext( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMDumpType", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DumpType( LLVMTypeRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMPrintTypeToString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string PrintTypeToString( LLVMTypeRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt1TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int1TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt8TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int8TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt16TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int16TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt32TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int32TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt64TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int64TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt128TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int128TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMIntTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef IntTypeInContext( LLVMContextRef @C, uint @NumBits ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt1Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int1Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt8Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int8Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt16Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int16Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt32Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int32Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt64Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int64Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInt128Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef Int128Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMIntType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef IntType( uint @NumBits ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetIntTypeWidth", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetIntTypeWidth( LLVMTypeRef @IntegerTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMHalfTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef HalfTypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMFloatTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef FloatTypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMDoubleTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef DoubleTypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMX86FP80TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef X86FP80TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMFP128TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef FP128TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMPPCFP128TypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef PPCFP128TypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMHalfType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef HalfType( ); + + [DllImport( libraryPath, EntryPoint = "LLVMFloatType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef FloatType( ); + + [DllImport( libraryPath, EntryPoint = "LLVMDoubleType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef DoubleType( ); + + [DllImport( libraryPath, EntryPoint = "LLVMX86FP80Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef X86FP80Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMFP128Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef FP128Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMPPCFP128Type", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef PPCFP128Type( ); + + [DllImport( libraryPath, EntryPoint = "LLVMFunctionType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef FunctionType( LLVMTypeRef @ReturnType, out LLVMTypeRef @ParamTypes, uint @ParamCount, [MarshalAs( UnmanagedType.Bool )]bool @IsVarArg ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsFunctionVarArg", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsFunctionVarArg( LLVMTypeRef @FunctionTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetReturnType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef GetReturnType( LLVMTypeRef @FunctionTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMCountParamTypes", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint CountParamTypes( LLVMTypeRef @FunctionTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetParamTypes", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetParamTypes( LLVMTypeRef @FunctionTy, out LLVMTypeRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMStructTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef StructTypeInContext( LLVMContextRef @C, out LLVMTypeRef @ElementTypes, uint @ElementCount, [MarshalAs( UnmanagedType.Bool )]bool @Packed ); + + [DllImport( libraryPath, EntryPoint = "LLVMStructType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef StructType( out LLVMTypeRef @ElementTypes, uint @ElementCount, [MarshalAs( UnmanagedType.Bool )]bool @Packed ); + + [DllImport( libraryPath, EntryPoint = "LLVMStructCreateNamed", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMTypeRef StructCreateNamed( LLVMContextRef @C, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetStructName", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetStructName( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMStructSetBody", CallingConvention = CallingConvention.Cdecl )] + internal static extern void StructSetBody( LLVMTypeRef @StructTy, out LLVMTypeRef @ElementTypes, uint @ElementCount, [MarshalAs( UnmanagedType.Bool )]bool @Packed ); + + [DllImport( libraryPath, EntryPoint = "LLVMCountStructElementTypes", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint CountStructElementTypes( LLVMTypeRef @StructTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetStructElementTypes", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetStructElementTypes( LLVMTypeRef @StructTy, out LLVMTypeRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMStructGetTypeAtIndex", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef StructGetTypeAtIndex( LLVMTypeRef @StructTy, uint @i ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsPackedStruct", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsPackedStruct( LLVMTypeRef @StructTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsOpaqueStruct", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsOpaqueStruct( LLVMTypeRef @StructTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetElementType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef GetElementType( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMArrayType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef ArrayType( LLVMTypeRef @ElementType, uint @ElementCount ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetArrayLength", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetArrayLength( LLVMTypeRef @ArrayTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMPointerType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef PointerType( LLVMTypeRef @ElementType, uint @AddressSpace ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPointerAddressSpace", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetPointerAddressSpace( LLVMTypeRef @PointerTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMVectorType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef VectorType( LLVMTypeRef @ElementType, uint @ElementCount ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetVectorSize", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetVectorSize( LLVMTypeRef @VectorTy ); + + [DllImport( libraryPath, EntryPoint = "LLVMVoidTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef VoidTypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMLabelTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef LabelTypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMX86MMXTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef X86MMXTypeInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMVoidType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef VoidType( ); + + [DllImport( libraryPath, EntryPoint = "LLVMLabelType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef LabelType( ); + + [DllImport( libraryPath, EntryPoint = "LLVMX86MMXType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef X86MMXType( ); + + [DllImport( libraryPath, EntryPoint = "LLVMTypeOf", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef TypeOf( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetValueKind", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueKind GetValueKind( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetValueName", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetValueName( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetValueName", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetValueName( LLVMValueRef @Val, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMDumpValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DumpValue( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMPrintValueToString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string PrintValueToString( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMReplaceAllUsesWith", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ReplaceAllUsesWith( LLVMValueRef @OldVal, LLVMValueRef @NewVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsConstant", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsConstant( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsUndef", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsUndef( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAArgument", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAArgument( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsABasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsABasicBlock( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAInlineAsm", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAInlineAsm( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAUser", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAUser( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstant", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstant( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsABlockAddress", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsABlockAddress( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantAggregateZero", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantAggregateZero( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantArray", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantArray( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantDataSequential", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantDataSequential( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantDataArray", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantDataArray( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantDataVector", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantDataVector( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantExpr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantExpr( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantFP", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantFP( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantInt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantInt( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantPointerNull", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantPointerNull( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantStruct", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantStruct( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantTokenNone", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantTokenNone( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAConstantVector", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAConstantVector( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAGlobalValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAGlobalValue( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAGlobalAlias", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAGlobalAlias( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAGlobalObject", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAGlobalObject( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFunction( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAGlobalVariable", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAGlobalVariable( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAUndefValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAUndefValue( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAInstruction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAInstruction( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsABinaryOperator", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsABinaryOperator( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACallInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACallInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAIntrinsicInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAIntrinsicInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsADbgInfoIntrinsic", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsADbgInfoIntrinsic( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsADbgDeclareInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsADbgDeclareInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAMemIntrinsic", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAMemIntrinsic( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAMemCpyInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAMemCpyInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAMemMoveInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAMemMoveInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAMemSetInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAMemSetInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACmpInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACmpInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFCmpInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFCmpInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAICmpInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAICmpInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAExtractElementInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAExtractElementInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAGetElementPtrInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAGetElementPtrInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAInsertElementInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAInsertElementInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAInsertValueInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAInsertValueInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsALandingPadInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsALandingPadInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAPHINode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAPHINode( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsASelectInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsASelectInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAShuffleVectorInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAShuffleVectorInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAStoreInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAStoreInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsATerminatorInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsATerminatorInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsABranchInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsABranchInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAIndirectBrInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAIndirectBrInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAInvokeInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAInvokeInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAReturnInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAReturnInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsASwitchInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsASwitchInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAUnreachableInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAUnreachableInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAResumeInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAResumeInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACleanupReturnInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACleanupReturnInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACatchReturnInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACatchReturnInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFuncletPadInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFuncletPadInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACatchPadInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACatchPadInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACleanupPadInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACleanupPadInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAUnaryInstruction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAUnaryInstruction( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAAllocaInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAAllocaInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsACastInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsACastInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAAddrSpaceCastInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAAddrSpaceCastInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsABitCastInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsABitCastInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFPExtInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFPExtInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFPToSIInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFPToSIInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFPToUIInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFPToUIInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAFPTruncInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAFPTruncInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAIntToPtrInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAIntToPtrInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAPtrToIntInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAPtrToIntInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsASExtInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsASExtInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsASIToFPInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsASIToFPInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsATruncInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsATruncInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAUIToFPInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAUIToFPInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAZExtInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAZExtInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAExtractValueInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAExtractValueInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsALoadInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsALoadInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAVAArgInst", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAVAArgInst( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAMDNode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAMDNode( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAMDString", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef IsAMDString( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstUse", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMUseRef GetFirstUse( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextUse", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMUseRef GetNextUse( LLVMUseRef @U ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetUser", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetUser( LLVMUseRef @U ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetUsedValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetUsedValue( LLVMUseRef @U ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetOperand", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetOperand( LLVMValueRef @Val, uint @Index ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetOperandUse", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMUseRef GetOperandUse( LLVMValueRef @Val, uint @Index ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetOperand", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetOperand( LLVMValueRef @User, uint @Index, LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNumOperands", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetNumOperands( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNull", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNull( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstAllOnes", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstAllOnes( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetUndef", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetUndef( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsNull", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsNull( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstPointerNull", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstPointerNull( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstInt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstInt( LLVMTypeRef @IntTy, ulong @N, [MarshalAs( UnmanagedType.Bool )]bool @SignExtend ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntOfArbitraryPrecision", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstIntOfArbitraryPrecision( LLVMTypeRef @IntTy, uint @NumWords, int[ ] @Words ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntOfString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstIntOfString( LLVMTypeRef @IntTy, [MarshalAs( UnmanagedType.LPStr )] string @Text, byte @Radix ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntOfStringAndSize", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstIntOfStringAndSize( LLVMTypeRef @IntTy, [MarshalAs( UnmanagedType.LPStr )] string @Text, uint @SLen, byte @Radix ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstReal", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstReal( LLVMTypeRef @RealTy, double @N ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstRealOfString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstRealOfString( LLVMTypeRef @RealTy, [MarshalAs( UnmanagedType.LPStr )] string @Text ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstRealOfStringAndSize", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstRealOfStringAndSize( LLVMTypeRef @RealTy, [MarshalAs( UnmanagedType.LPStr )] string @Text, uint @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntGetZExtValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong ConstIntGetZExtValue( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntGetSExtValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern long ConstIntGetSExtValue( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstRealGetDouble", CallingConvention = CallingConvention.Cdecl )] + internal static extern double ConstRealGetDouble( LLVMValueRef @ConstantVal, [MarshalAs( UnmanagedType.Bool )]out bool @losesInfo ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstStringInContext", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstStringInContext( LLVMContextRef @C, [MarshalAs( UnmanagedType.LPStr )] string @Str, uint @Length, [MarshalAs( UnmanagedType.Bool )]bool @DontNullTerminate ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstString( [MarshalAs( UnmanagedType.LPStr )] string @Str, uint @Length, [MarshalAs( UnmanagedType.Bool )]bool @DontNullTerminate ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsConstantString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsConstantString( LLVMValueRef @c ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetAsString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetAsString( LLVMValueRef @c, out size_t @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstStructInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstStructInContext( LLVMContextRef @C, out LLVMValueRef @ConstantVals, uint @Count, [MarshalAs( UnmanagedType.Bool )]bool @Packed ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstStruct", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstStruct( out LLVMValueRef @ConstantVals, uint @Count, [MarshalAs( UnmanagedType.Bool )]bool @Packed ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstArray", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstArray( LLVMTypeRef @ElementTy, out LLVMValueRef @ConstantVals, uint @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNamedStruct", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNamedStruct( LLVMTypeRef @StructTy, out LLVMValueRef @ConstantVals, uint @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetElementAsConstant", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetElementAsConstant( LLVMValueRef @C, uint @idx ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstVector", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstVector( out LLVMValueRef @ScalarConstantVals, uint @Size ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetConstOpcode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMOpcode GetConstOpcode( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMAlignOf", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef AlignOf( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMSizeOf", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef SizeOf( LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNeg", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNeg( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNSWNeg", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNSWNeg( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNUWNeg", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNUWNeg( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFNeg", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFNeg( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNot", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNot( LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstAdd", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstAdd( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNSWAdd", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNSWAdd( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNUWAdd", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNUWAdd( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFAdd", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFAdd( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSub", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSub( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNSWSub", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNSWSub( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNUWSub", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNUWSub( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFSub", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFSub( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstMul", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstMul( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNSWMul", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNSWMul( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstNUWMul", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstNUWMul( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFMul", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFMul( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstUDiv", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstUDiv( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + // Added to LLVM-C APIs in LLVM 4.0.0 + [DllImport( libraryPath, EntryPoint = "LLVMConstExactUDiv", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstExactUDiv( LLVMValueRef LHSConstant, LLVMValueRef RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSDiv", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSDiv( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstExactSDiv", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstExactSDiv( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFDiv", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFDiv( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstURem", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstURem( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSRem", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSRem( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFRem", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFRem( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstAnd", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstAnd( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstOr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstOr( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstXor", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstXor( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstICmp", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstICmp( LLVMIntPredicate @Predicate, LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFCmp", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFCmp( LLVMRealPredicate @Predicate, LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstShl", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstShl( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstLShr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstLShr( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstAShr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstAShr( LLVMValueRef @LHSConstant, LLVMValueRef @RHSConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstGEP", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstGEP( LLVMValueRef @ConstantVal, out LLVMValueRef @ConstantIndices, uint @NumIndices ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstInBoundsGEP", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstInBoundsGEP( LLVMValueRef @ConstantVal, out LLVMValueRef @ConstantIndices, uint @NumIndices ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstTrunc", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstTrunc( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSExt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSExt( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstZExt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstZExt( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFPTrunc", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFPTrunc( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFPExt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFPExt( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstUIToFP", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstUIToFP( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSIToFP", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSIToFP( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFPToUI", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFPToUI( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFPToSI", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFPToSI( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstPtrToInt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstPtrToInt( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntToPtr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstIntToPtr( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstBitCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstBitCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstAddrSpaceCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstAddrSpaceCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstZExtOrBitCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstZExtOrBitCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSExtOrBitCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSExtOrBitCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstTruncOrBitCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstTruncOrBitCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstPointerCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstPointerCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstIntCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstIntCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType, [MarshalAs( UnmanagedType.Bool )]bool @isSigned ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstFPCast", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstFPCast( LLVMValueRef @ConstantVal, LLVMTypeRef @ToType ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstSelect", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstSelect( LLVMValueRef @ConstantCondition, LLVMValueRef @ConstantIfTrue, LLVMValueRef @ConstantIfFalse ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstExtractElement", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstExtractElement( LLVMValueRef @VectorConstant, LLVMValueRef @IndexConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstInsertElement", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstInsertElement( LLVMValueRef @VectorConstant, LLVMValueRef @ElementValueConstant, LLVMValueRef @IndexConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstShuffleVector", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstShuffleVector( LLVMValueRef @VectorAConstant, LLVMValueRef @VectorBConstant, LLVMValueRef @MaskConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstExtractValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstExtractValue( LLVMValueRef @AggConstant, out uint @IdxList, uint @NumIdx ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstInsertValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef ConstInsertValue( LLVMValueRef @AggConstant, LLVMValueRef @ElementValueConstant, out uint @IdxList, uint @NumIdx ); + + [DllImport( libraryPath, EntryPoint = "LLVMConstInlineAsm", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef ConstInlineAsm( LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @AsmString, [MarshalAs( UnmanagedType.LPStr )] string @Constraints, [MarshalAs( UnmanagedType.Bool )]bool @HasSideEffects, [MarshalAs( UnmanagedType.Bool )]bool @IsAlignStack ); + + [DllImport( libraryPath, EntryPoint = "LLVMBlockAddress", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BlockAddress( LLVMValueRef @F, LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetGlobalParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMModuleRef GetGlobalParent( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsDeclaration", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsDeclaration( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLinkage", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMLinkage GetLinkage( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetLinkage", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetLinkage( LLVMValueRef @Global, LLVMLinkage @Linkage ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSection", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetSection( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetSection", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetSection( LLVMValueRef @Global, [MarshalAs( UnmanagedType.LPStr )] string @Section ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetVisibility", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMVisibility GetVisibility( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetVisibility", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetVisibility( LLVMValueRef @Global, LLVMVisibility @Viz ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDLLStorageClass", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMDLLStorageClass GetDLLStorageClass( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetDLLStorageClass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetDLLStorageClass( LLVMValueRef @Global, LLVMDLLStorageClass @Class ); + + [DllImport( libraryPath, EntryPoint = "LLVMHasUnnamedAddr", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool HasUnnamedAddr( LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetUnnamedAddr", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetUnnamedAddr( LLVMValueRef @Global, [MarshalAs( UnmanagedType.Bool )]bool hasUnnamedAddr ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetAlignment", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetAlignment( LLVMValueRef @V ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetAlignment", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetAlignment( LLVMValueRef @V, uint @Bytes ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddGlobal", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef AddGlobal( LLVMModuleRef @M, LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddGlobalInAddressSpace", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef AddGlobalInAddressSpace( LLVMModuleRef @M, LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name, uint @AddressSpace ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNamedGlobal", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef GetNamedGlobal( LLVMModuleRef @M, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetFirstGlobal( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLastGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetLastGlobal( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetNextGlobal( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPreviousGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetPreviousGlobal( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMDeleteGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DeleteGlobal( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetInitializer", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetInitializer( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetInitializer", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetInitializer( LLVMValueRef @GlobalVar, LLVMValueRef @ConstantVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsThreadLocal", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsThreadLocal( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetThreadLocal", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetThreadLocal( LLVMValueRef @GlobalVar, [MarshalAs( UnmanagedType.Bool )]bool isThreadLocal ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsGlobalConstant", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsGlobalConstant( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetGlobalConstant", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetGlobalConstant( LLVMValueRef @GlobalVar, [MarshalAs( UnmanagedType.Bool )]bool isConstant ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetThreadLocalMode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMThreadLocalMode GetThreadLocalMode( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetThreadLocalMode", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetThreadLocalMode( LLVMValueRef @GlobalVar, LLVMThreadLocalMode @Mode ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsExternallyInitialized", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsExternallyInitialized( LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetExternallyInitialized", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetExternallyInitialized( LLVMValueRef @GlobalVar, [MarshalAs( UnmanagedType.Bool )]bool @IsExtInit ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAlias", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef AddAlias( LLVMModuleRef @M, LLVMTypeRef @Ty, LLVMValueRef @Aliasee, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMDeleteFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DeleteFunction( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMHasPersonalityFn", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool HasPersonalityFn( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPersonalityFn", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetPersonalityFn( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetPersonalityFn", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetPersonalityFn( LLVMValueRef @Fn, LLVMValueRef @PersonalityFn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetIntrinsicID", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetIntrinsicID( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFunctionCallConv", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetFunctionCallConv( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetFunctionCallConv", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetFunctionCallConv( LLVMValueRef @Fn, uint @CC ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetGC", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetGC( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetGC", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void SetGC( LLVMValueRef @Fn, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAttributeAtIndex", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddAttributeAtIndex( LLVMValueRef @F, LLVMAttributeIndex @Idx, LLVMAttributeRef @A ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetAttributeCountAtIndex", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetAttributeCountAtIndex( LLVMValueRef F, LLVMAttributeIndex Idx ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetAttributesAtIndex", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetAttributesAtIndex( LLVMValueRef F, LLVMAttributeIndex Idx, out LLVMAttributeRef Attrs ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetEnumAttributeAtIndex", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMAttributeRef GetEnumAttributeAtIndex( LLVMValueRef @F, LLVMAttributeIndex @Idx, uint @KindID ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetStringAttributeAtIndex", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMAttributeRef GetStringAttributeAtIndex( LLVMValueRef @F, LLVMAttributeIndex @Idx, [MarshalAs( UnmanagedType.LPStr )] string @K, uint @KLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveEnumAttributeAtIndex", CallingConvention = CallingConvention.Cdecl )] + internal static extern void RemoveEnumAttributeAtIndex( LLVMValueRef @F, LLVMAttributeIndex @Idx, uint @KindID ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveStringAttributeAtIndex", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void RemoveStringAttributeAtIndex( LLVMValueRef @F, LLVMAttributeIndex @Idx, [MarshalAs( UnmanagedType.LPStr )] string @K, uint @KLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddTargetDependentFunctionAttr", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void AddTargetDependentFunctionAttr( LLVMValueRef @Fn, [MarshalAs( UnmanagedType.LPStr )] string @A, [MarshalAs( UnmanagedType.LPStr )] string @V ); + + [DllImport( libraryPath, EntryPoint = "LLVMCountParams", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint CountParams( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetParams", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetParams( LLVMValueRef @Fn, out LLVMValueRef @Params ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetParam", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetParam( LLVMValueRef @Fn, uint @Index ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetParamParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetParamParent( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstParam", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetFirstParam( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLastParam", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetLastParam( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextParam", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetNextParam( LLVMValueRef @Arg ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPreviousParam", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetPreviousParam( LLVMValueRef @Arg ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetParamAlignment", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetParamAlignment( LLVMValueRef @Arg, uint @Align ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDStringInContext", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef MDStringInContext( LLVMContextRef @C, [MarshalAs( UnmanagedType.LPStr )] string @Str, uint @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef MDString( [MarshalAs( UnmanagedType.LPStr )] string @Str, uint @SLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNodeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef MDNodeInContext( LLVMContextRef @C, out LLVMValueRef @Vals, uint @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMMDNode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef MDNode( out LLVMValueRef @Vals, uint @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMDString", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetMDString( LLVMValueRef @V, out uint @Length ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMDNodeNumOperands", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetMDNodeNumOperands( LLVMValueRef @V ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMDNodeOperands", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetMDNodeOperands( LLVMValueRef @V, out LLVMValueRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMBasicBlockAsValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BasicBlockAsValue( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMValueIsBasicBlock", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool ValueIsBasicBlock( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMValueAsBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef ValueAsBasicBlock( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBasicBlockName", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetBasicBlockName( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBasicBlockParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetBasicBlockParent( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBasicBlockTerminator", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetBasicBlockTerminator( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMCountBasicBlocks", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint CountBasicBlocks( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBasicBlocks", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetBasicBlocks( LLVMValueRef @Fn, out LLVMBasicBlockRef @BasicBlocks ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetFirstBasicBlock( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLastBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetLastBasicBlock( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetNextBasicBlock( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPreviousBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetPreviousBasicBlock( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetEntryBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetEntryBasicBlock( LLVMValueRef @Fn ); + + [DllImport( libraryPath, EntryPoint = "LLVMAppendBasicBlockInContext", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMBasicBlockRef AppendBasicBlockInContext( LLVMContextRef @C, LLVMValueRef @Fn, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMAppendBasicBlock", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMBasicBlockRef AppendBasicBlock( LLVMValueRef @Fn, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMInsertBasicBlockInContext", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMBasicBlockRef InsertBasicBlockInContext( LLVMContextRef @C, LLVMBasicBlockRef @BB, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMInsertBasicBlock", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMBasicBlockRef InsertBasicBlock( LLVMBasicBlockRef @InsertBeforeBB, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMDeleteBasicBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DeleteBasicBlock( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveBasicBlockFromParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern void RemoveBasicBlockFromParent( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMMoveBasicBlockBefore", CallingConvention = CallingConvention.Cdecl )] + internal static extern void MoveBasicBlockBefore( LLVMBasicBlockRef @BB, LLVMBasicBlockRef @MovePos ); + + [DllImport( libraryPath, EntryPoint = "LLVMMoveBasicBlockAfter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void MoveBasicBlockAfter( LLVMBasicBlockRef @BB, LLVMBasicBlockRef @MovePos ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstInstruction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetFirstInstruction( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetLastInstruction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetLastInstruction( LLVMBasicBlockRef @BB ); + + [DllImport( libraryPath, EntryPoint = "LLVMHasMetadata", CallingConvention = CallingConvention.Cdecl )] + internal static extern int HasMetadata( LLVMValueRef @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetMetadata", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetMetadata( LLVMValueRef @Val, uint @KindID ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetMetadata", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetMetadata( LLVMValueRef @Val, uint @KindID, LLVMValueRef @Node ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetInstructionParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetInstructionParent( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextInstruction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetNextInstruction( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPreviousInstruction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetPreviousInstruction( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMInstructionRemoveFromParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InstructionRemoveFromParent( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMInstructionEraseFromParent", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InstructionEraseFromParent( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetInstructionOpcode", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMOpcode GetInstructionOpcode( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetICmpPredicate", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMIntPredicate GetICmpPredicate( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFCmpPredicate", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMRealPredicate GetFCmpPredicate( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMInstructionClone", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef InstructionClone( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNumArgOperands", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetNumArgOperands( LLVMValueRef @Instr ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetInstructionCallConv", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetInstructionCallConv( LLVMValueRef @Instr, uint @CC ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetInstructionCallConv", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetInstructionCallConv( LLVMValueRef @Instr ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetInstrParamAlignment", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetInstrParamAlignment( LLVMValueRef @Instr, uint @index, uint @Align ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddCallSiteAttribute", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddCallSiteAttribute( LLVMValueRef @C, LLVMAttributeIndex @Idx, LLVMAttributeRef @A ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCallSiteAttributeCount", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetCallSiteAttributeCount( LLVMValueRef C, LLVMAttributeIndex Idx ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCallSiteAttributes", CallingConvention = CallingConvention.Cdecl )] + internal static extern void GetCallSiteAttributes( LLVMValueRef C, LLVMAttributeIndex Idx, out LLVMAttributeRef attributes ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCallSiteEnumAttribute", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMAttributeRef GetCallSiteEnumAttribute( LLVMValueRef @C, LLVMAttributeIndex @Idx, uint @KindID ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCallSiteStringAttribute", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMAttributeRef GetCallSiteStringAttribute( LLVMValueRef @C, LLVMAttributeIndex @Idx, [MarshalAs( UnmanagedType.LPStr )] string @K, uint @KLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveCallSiteEnumAttribute", CallingConvention = CallingConvention.Cdecl )] + internal static extern void RemoveCallSiteEnumAttribute( LLVMValueRef @C, LLVMAttributeIndex @Idx, uint @KindID ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveCallSiteStringAttribute", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void RemoveCallSiteStringAttribute( LLVMValueRef @C, LLVMAttributeIndex @Idx, [MarshalAs( UnmanagedType.LPStr )] string @K, uint @KLen ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCalledValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetCalledValue( LLVMValueRef @Instr ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsTailCall", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsTailCall( LLVMValueRef @CallInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetTailCall", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetTailCall( LLVMValueRef @CallInst, [MarshalAs( UnmanagedType.Bool )]bool isTailCall ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNormalDest", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetNormalDest( LLVMValueRef @InvokeInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetUnwindDest", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetUnwindDest( LLVMValueRef @InvokeInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetNormalDest", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetNormalDest( LLVMValueRef @InvokeInst, LLVMBasicBlockRef @B ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetUnwindDest", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetUnwindDest( LLVMValueRef @InvokeInst, LLVMBasicBlockRef @B ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNumSuccessors", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetNumSuccessors( LLVMValueRef @Term ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSuccessor", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetSuccessor( LLVMValueRef @Term, uint @i ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetSuccessor", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetSuccessor( LLVMValueRef @Term, uint @i, LLVMBasicBlockRef @block ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsConditional", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsConditional( LLVMValueRef @Branch ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCondition", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetCondition( LLVMValueRef @Branch ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetCondition", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetCondition( LLVMValueRef @Branch, LLVMValueRef @Cond ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSwitchDefaultDest", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetSwitchDefaultDest( LLVMValueRef @SwitchInstr ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetAllocatedType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef GetAllocatedType( LLVMValueRef @Alloca ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsInBounds", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsInBounds( LLVMValueRef @GEP ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetIsInBounds", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetIsInBounds( LLVMValueRef @GEP, [MarshalAs( UnmanagedType.Bool )]bool @InBounds ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddIncoming", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddIncoming( LLVMValueRef @PhiNode, out LLVMValueRef @IncomingValues, out LLVMBasicBlockRef @IncomingBlocks, uint @Count ); + + [DllImport( libraryPath, EntryPoint = "LLVMCountIncoming", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint CountIncoming( LLVMValueRef @PhiNode ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetIncomingValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetIncomingValue( LLVMValueRef @PhiNode, uint @Index ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetIncomingBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetIncomingBlock( LLVMValueRef @PhiNode, uint @Index ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNumIndices", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetNumIndices( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetIndices", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetIndices( LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateBuilderInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBuilderRef CreateBuilderInContext( LLVMContextRef @C ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateBuilder", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBuilderRef CreateBuilder( ); + + [DllImport( libraryPath, EntryPoint = "LLVMPositionBuilder", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PositionBuilder( LLVMBuilderRef @Builder, LLVMBasicBlockRef @Block, LLVMValueRef @Instr ); + + [DllImport( libraryPath, EntryPoint = "LLVMPositionBuilderBefore", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PositionBuilderBefore( LLVMBuilderRef @Builder, LLVMValueRef @Instr ); + + [DllImport( libraryPath, EntryPoint = "LLVMPositionBuilderAtEnd", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PositionBuilderAtEnd( LLVMBuilderRef @Builder, LLVMBasicBlockRef @Block ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetInsertBlock", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMBasicBlockRef GetInsertBlock( LLVMBuilderRef @Builder ); + + [DllImport( libraryPath, EntryPoint = "LLVMClearInsertionPosition", CallingConvention = CallingConvention.Cdecl )] + internal static extern void ClearInsertionPosition( LLVMBuilderRef @Builder ); + + [DllImport( libraryPath, EntryPoint = "LLVMInsertIntoBuilder", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InsertIntoBuilder( LLVMBuilderRef @Builder, LLVMValueRef @Instr ); + + [DllImport( libraryPath, EntryPoint = "LLVMInsertIntoBuilderWithName", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void InsertIntoBuilderWithName( LLVMBuilderRef @Builder, LLVMValueRef @Instr, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeBuilder", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeBuilder( IntPtr @Builder ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetCurrentDebugLocation", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetCurrentDebugLocation( LLVMBuilderRef @Builder, LLVMValueRef @L ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCurrentDebugLocation", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetCurrentDebugLocation( LLVMBuilderRef @Builder ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetInstDebugLocation", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetInstDebugLocation( LLVMBuilderRef @Builder, LLVMValueRef @Inst ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildRetVoid", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildRetVoid( LLVMBuilderRef @param0 ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildRet", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildRet( LLVMBuilderRef @param0, LLVMValueRef @V ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAggregateRet", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildAggregateRet( LLVMBuilderRef @param0, out LLVMValueRef @RetVals, uint @N ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildBr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildBr( LLVMBuilderRef @param0, LLVMBasicBlockRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildCondBr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildCondBr( LLVMBuilderRef @param0, LLVMValueRef @If, LLVMBasicBlockRef @Then, LLVMBasicBlockRef @Else ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSwitch", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildSwitch( LLVMBuilderRef @param0, LLVMValueRef @V, LLVMBasicBlockRef @Else, uint @NumCases ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildIndirectBr", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildIndirectBr( LLVMBuilderRef @B, LLVMValueRef @Addr, uint @NumDests ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildInvoke", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildInvoke( LLVMBuilderRef @param0, LLVMValueRef @Fn, out LLVMValueRef @Args, uint @NumArgs, LLVMBasicBlockRef @Then, LLVMBasicBlockRef @Catch, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildLandingPad", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildLandingPad( LLVMBuilderRef @B, LLVMTypeRef @Ty, LLVMValueRef @PersFn, uint @NumClauses, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildResume", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildResume( LLVMBuilderRef @B, LLVMValueRef @Exn ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildUnreachable", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildUnreachable( LLVMBuilderRef @param0 ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddCase", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddCase( LLVMValueRef @Switch, LLVMValueRef @OnVal, LLVMBasicBlockRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddDestination", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddDestination( LLVMValueRef @IndirectBr, LLVMBasicBlockRef @Dest ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNumClauses", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GetNumClauses( LLVMValueRef @LandingPad ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetClause", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef GetClause( LLVMValueRef @LandingPad, uint @Idx ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddClause", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddClause( LLVMValueRef @LandingPad, LLVMValueRef @ClauseVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsCleanup", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsCleanup( LLVMValueRef @LandingPad ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetCleanup", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetCleanup( LLVMValueRef @LandingPad, [MarshalAs( UnmanagedType.Bool )]bool @Val ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAdd", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildAdd( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNSWAdd", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNSWAdd( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNUWAdd", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNUWAdd( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFAdd", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFAdd( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSub", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSub( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNSWSub", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNSWSub( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNUWSub", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNUWSub( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFSub", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFSub( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildMul", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildMul( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNSWMul", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNSWMul( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNUWMul", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNUWMul( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFMul", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFMul( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildUDiv", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildUDiv( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + // Added to LLVM-C API in LLVM 4.0.0 + [DllImport( libraryPath, EntryPoint = "LLVMBuildExactUDiv", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildExactUDiv( LLVMBuilderRef @param0, LLVMValueRef LHS, LLVMValueRef RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSDiv", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSDiv( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildExactSDiv", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildExactSDiv( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFDiv", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFDiv( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildURem", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildURem( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSRem", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSRem( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFRem", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFRem( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildShl", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildShl( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildLShr", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildLShr( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAShr", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildAShr( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAnd", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildAnd( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildOr", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildOr( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildXor", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildXor( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildBinOp", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildBinOp( LLVMBuilderRef @B, LLVMOpcode @Op, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNeg", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNeg( LLVMBuilderRef @param0, LLVMValueRef @V, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNSWNeg", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNSWNeg( LLVMBuilderRef @B, LLVMValueRef @V, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNUWNeg", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNUWNeg( LLVMBuilderRef @B, LLVMValueRef @V, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFNeg", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFNeg( LLVMBuilderRef @param0, LLVMValueRef @V, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildNot", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildNot( LLVMBuilderRef @param0, LLVMValueRef @V, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildMalloc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildMalloc( LLVMBuilderRef @param0, LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildArrayMalloc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildArrayMalloc( LLVMBuilderRef @param0, LLVMTypeRef @Ty, LLVMValueRef @Val, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAlloca", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildAlloca( LLVMBuilderRef @param0, LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildArrayAlloca", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildArrayAlloca( LLVMBuilderRef @param0, LLVMTypeRef @Ty, LLVMValueRef @Val, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFree", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildFree( LLVMBuilderRef @param0, LLVMValueRef @PointerVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildLoad", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildLoad( LLVMBuilderRef @param0, LLVMValueRef @PointerVal, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildStore", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildStore( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMValueRef @Ptr ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildGEP", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildGEP( LLVMBuilderRef @B, LLVMValueRef @Pointer, out LLVMValueRef @Indices, uint @NumIndices, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildInBoundsGEP", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildInBoundsGEP( LLVMBuilderRef @B, LLVMValueRef @Pointer, out LLVMValueRef @Indices, uint @NumIndices, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildStructGEP", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildStructGEP( LLVMBuilderRef @B, LLVMValueRef @Pointer, uint @Idx, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildGlobalString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildGlobalString( LLVMBuilderRef @B, [MarshalAs( UnmanagedType.LPStr )] string @Str, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildGlobalStringPtr", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildGlobalStringPtr( LLVMBuilderRef @B, [MarshalAs( UnmanagedType.LPStr )] string @Str, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetVolatile", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool GetVolatile( LLVMValueRef @MemoryAccessInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetVolatile", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetVolatile( LLVMValueRef @MemoryAccessInst, [MarshalAs( UnmanagedType.Bool )]bool @IsVolatile ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetOrdering", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMAtomicOrdering GetOrdering( LLVMValueRef @MemoryAccessInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetOrdering", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetOrdering( LLVMValueRef @MemoryAccessInst, LLVMAtomicOrdering @Ordering ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildTrunc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildTrunc( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildZExt", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildZExt( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSExt", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSExt( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFPToUI", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFPToUI( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFPToSI", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFPToSI( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildUIToFP", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildUIToFP( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSIToFP", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSIToFP( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFPTrunc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFPTrunc( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFPExt", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFPExt( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildPtrToInt", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildPtrToInt( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildIntToPtr", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildIntToPtr( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildBitCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildBitCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAddrSpaceCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildAddrSpaceCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildZExtOrBitCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildZExtOrBitCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSExtOrBitCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSExtOrBitCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildTruncOrBitCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildTruncOrBitCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildCast( LLVMBuilderRef @B, LLVMOpcode @Op, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildPointerCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildPointerCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildIntCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildIntCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFPCast", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFPCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildICmp", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildICmp( LLVMBuilderRef @param0, LLVMIntPredicate @Op, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFCmp", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFCmp( LLVMBuilderRef @param0, LLVMRealPredicate @Op, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildPhi", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildPhi( LLVMBuilderRef @param0, LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildCall", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildCall( LLVMBuilderRef @param0, LLVMValueRef @Fn, out LLVMValueRef @Args, uint @NumArgs, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildSelect", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildSelect( LLVMBuilderRef @param0, LLVMValueRef @If, LLVMValueRef @Then, LLVMValueRef @Else, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildVAArg", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildVAArg( LLVMBuilderRef @param0, LLVMValueRef @List, LLVMTypeRef @Ty, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildExtractElement", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildExtractElement( LLVMBuilderRef @param0, LLVMValueRef @VecVal, LLVMValueRef @Index, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildInsertElement", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildInsertElement( LLVMBuilderRef @param0, LLVMValueRef @VecVal, LLVMValueRef @EltVal, LLVMValueRef @Index, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildShuffleVector", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildShuffleVector( LLVMBuilderRef @param0, LLVMValueRef @V1, LLVMValueRef @V2, LLVMValueRef @Mask, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildExtractValue", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildExtractValue( LLVMBuilderRef @param0, LLVMValueRef @AggVal, uint @Index, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildInsertValue", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildInsertValue( LLVMBuilderRef @param0, LLVMValueRef @AggVal, LLVMValueRef @EltVal, uint @Index, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildIsNull", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildIsNull( LLVMBuilderRef @param0, LLVMValueRef @Val, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildIsNotNull", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildIsNotNull( LLVMBuilderRef @param0, LLVMValueRef @Val, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildPtrDiff", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildPtrDiff( LLVMBuilderRef @param0, LLVMValueRef @LHS, LLVMValueRef @RHS, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildFence", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMValueRef BuildFence( LLVMBuilderRef @B, LLVMAtomicOrdering @ordering, [MarshalAs( UnmanagedType.Bool )]bool @singleThread, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAtomicRMW", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildAtomicRMW( LLVMBuilderRef @B, LLVMAtomicRMWBinOp @op, LLVMValueRef @PTR, LLVMValueRef @Val, LLVMAtomicOrdering @ordering, [MarshalAs( UnmanagedType.Bool )]bool @singleThread ); + + [DllImport( libraryPath, EntryPoint = "LLVMBuildAtomicCmpXchg", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMValueRef BuildAtomicCmpXchg( LLVMBuilderRef @B, LLVMValueRef @Ptr, LLVMValueRef @Cmp, LLVMValueRef @New, LLVMAtomicOrdering @SuccessOrdering, LLVMAtomicOrdering @FailureOrdering, [MarshalAs( UnmanagedType.Bool )]bool @SingleThread ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsAtomicSingleThread", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsAtomicSingleThread( LLVMValueRef @AtomicInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetAtomicSingleThread", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetAtomicSingleThread( LLVMValueRef @AtomicInst, [MarshalAs( UnmanagedType.Bool )]bool @SingleThread ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCmpXchgSuccessOrdering", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMAtomicOrdering GetCmpXchgSuccessOrdering( LLVMValueRef @CmpXchgInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetCmpXchgSuccessOrdering", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetCmpXchgSuccessOrdering( LLVMValueRef @CmpXchgInst, LLVMAtomicOrdering @Ordering ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetCmpXchgFailureOrdering", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMAtomicOrdering GetCmpXchgFailureOrdering( LLVMValueRef @CmpXchgInst ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetCmpXchgFailureOrdering", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetCmpXchgFailureOrdering( LLVMValueRef @CmpXchgInst, LLVMAtomicOrdering @Ordering ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateModuleProviderForExistingModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMModuleProviderRef CreateModuleProviderForExistingModule( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeModuleProvider", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeModuleProvider( LLVMModuleProviderRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithContentsOfFile", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMStatus CreateMemoryBufferWithContentsOfFile( [MarshalAs( UnmanagedType.LPStr )] string @Path, out LLVMMemoryBufferRef @OutMemBuf, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )]out string @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithSTDIN", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus CreateMemoryBufferWithSTDIN( out LLVMMemoryBufferRef @OutMemBuf, out IntPtr @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithMemoryRange", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMMemoryBufferRef CreateMemoryBufferWithMemoryRange( [MarshalAs( UnmanagedType.LPStr )] string @InputData, size_t @InputDataLength, [MarshalAs( UnmanagedType.LPStr )] string @BufferName, [MarshalAs( UnmanagedType.Bool )]bool @RequiresNullTerminator ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateMemoryBufferWithMemoryRangeCopy", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMMemoryBufferRef CreateMemoryBufferWithMemoryRangeCopy( [MarshalAs( UnmanagedType.LPStr )] string @InputData, size_t @InputDataLength, [MarshalAs( UnmanagedType.LPStr )] string @BufferName ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBufferStart", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetBufferStart( LLVMMemoryBufferRef @MemBuf ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetBufferSize", CallingConvention = CallingConvention.Cdecl )] + internal static extern size_t GetBufferSize( LLVMMemoryBufferRef @MemBuf ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeMemoryBuffer", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeMemoryBuffer( LLVMMemoryBufferRef @MemBuf ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetGlobalPassRegistry", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMPassRegistryRef GetGlobalPassRegistry( ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreatePassManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMPassManagerRef CreatePassManager( ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateFunctionPassManagerForModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMPassManagerRef CreateFunctionPassManagerForModule( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateFunctionPassManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMPassManagerRef CreateFunctionPassManager( LLVMModuleProviderRef @MP ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunPassManager", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool RunPassManager( LLVMPassManagerRef @PM, LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeFunctionPassManager", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool InitializeFunctionPassManager( LLVMPassManagerRef @FPM ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunFunctionPassManager", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool RunFunctionPassManager( LLVMPassManagerRef @FPM, LLVMValueRef @F ); + + [DllImport( libraryPath, EntryPoint = "LLVMFinalizeFunctionPassManager", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool FinalizeFunctionPassManager( LLVMPassManagerRef @FPM ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposePassManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposePassManager( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsMultithreaded", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsMultithreaded( ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateDisasm", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMDisasmContextRef CreateDisasm( [MarshalAs( UnmanagedType.LPStr )] string @TripleName, IntPtr @DisInfo, int @TagType, LLVMOpInfoCallback @GetOpInfo, LLVMSymbolLookupCallback @SymbolLookUp ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateDisasmCPU", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMDisasmContextRef CreateDisasmCPU( [MarshalAs( UnmanagedType.LPStr )] string @Triple, [MarshalAs( UnmanagedType.LPStr )] string @CPU, IntPtr @DisInfo, int @TagType, LLVMOpInfoCallback @GetOpInfo, LLVMSymbolLookupCallback @SymbolLookUp ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateDisasmCPUFeatures", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMDisasmContextRef CreateDisasmCPUFeatures( [MarshalAs( UnmanagedType.LPStr )] string @Triple, [MarshalAs( UnmanagedType.LPStr )] string @CPU, [MarshalAs( UnmanagedType.LPStr )] string @Features, IntPtr @DisInfo, int @TagType, LLVMOpInfoCallback @GetOpInfo, LLVMSymbolLookupCallback @SymbolLookUp ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetDisasmOptions", CallingConvention = CallingConvention.Cdecl )] + internal static extern int SetDisasmOptions( LLVMDisasmContextRef @DC, int @Options ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisasmDispose", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisasmDispose( LLVMDisasmContextRef @DC ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisasmInstruction", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern ulong DisasmInstruction( LLVMDisasmContextRef @DC, IntPtr @Bytes, long @BytesSize, long @PC, IntPtr @OutString, size_t @OutStringSize ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAMDGPUTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAMDGPUTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSystemZTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSystemZTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeHexagonTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeHexagonTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNVPTXTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeNVPTXTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMSP430TargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMSP430TargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeXCoreTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeXCoreTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMipsTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMipsTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAArch64TargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAArch64TargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeARMTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeARMTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePowerPCTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializePowerPCTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSparcTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSparcTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeX86TargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeX86TargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeBPFTargetInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeBPFTargetInfo( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAMDGPUTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAMDGPUTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSystemZTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSystemZTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeHexagonTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeHexagonTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNVPTXTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeNVPTXTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMSP430Target", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMSP430Target( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeXCoreTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeXCoreTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMipsTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMipsTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAArch64Target", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAArch64Target( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeARMTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeARMTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePowerPCTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializePowerPCTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSparcTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSparcTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeX86Target", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeX86Target( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeBPFTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeBPFTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAMDGPUTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAMDGPUTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSystemZTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSystemZTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeHexagonTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeHexagonTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNVPTXTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeNVPTXTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMSP430TargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMSP430TargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeXCoreTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeXCoreTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMipsTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMipsTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAArch64TargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAArch64TargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeARMTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeARMTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePowerPCTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializePowerPCTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSparcTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSparcTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeX86TargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeX86TargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeBPFTargetMC", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeBPFTargetMC( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAMDGPUAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAMDGPUAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSystemZAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSystemZAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeHexagonAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeHexagonAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNVPTXAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeNVPTXAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMSP430AsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMSP430AsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeXCoreAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeXCoreAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMipsAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMipsAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAArch64AsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAArch64AsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeARMAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeARMAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePowerPCAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializePowerPCAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSparcAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSparcAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeX86AsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeX86AsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeBPFAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeBPFAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAMDGPUAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAMDGPUAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSystemZAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSystemZAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMipsAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMipsAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAArch64AsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAArch64AsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeARMAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeARMAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePowerPCAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializePowerPCAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSparcAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSparcAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeX86AsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeX86AsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSystemZDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSystemZDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeHexagonDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeHexagonDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeXCoreDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeXCoreDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMipsDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMipsDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAArch64Disassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAArch64Disassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeARMDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeARMDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializePowerPCDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializePowerPCDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeSparcDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeSparcDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeX86Disassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeX86Disassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAllTargetInfos", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAllTargetInfos( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAllTargets", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAllTargets( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAllTargetMCs", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAllTargetMCs( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAllAsmPrinters", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAllAsmPrinters( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAllAsmParsers", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAllAsmParsers( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAllDisassemblers", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAllDisassemblers( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNativeTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus InitializeNativeTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNativeAsmParser", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus InitializeNativeAsmParser( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNativeAsmPrinter", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus InitializeNativeAsmPrinter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeNativeDisassembler", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus InitializeNativeDisassembler( ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetModuleDataLayout", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetDataRef GetModuleDataLayout( LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetModuleDataLayout", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetModuleDataLayout( LLVMModuleRef @M, LLVMTargetDataRef @DL ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateTargetData", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMTargetDataRef CreateTargetData( [MarshalAs( UnmanagedType.LPStr )] string @StringRep ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeTargetData", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeTargetData( LLVMTargetDataRef @TD ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddTargetLibraryInfo", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddTargetLibraryInfo( LLVMTargetLibraryInfoRef @TLI, LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMCopyStringRepOfTargetData", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string CopyStringRepOfTargetData( LLVMTargetDataRef @TD ); + + [DllImport( libraryPath, EntryPoint = "LLVMByteOrder", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMByteOrdering ByteOrder( LLVMTargetDataRef @TD ); + + [DllImport( libraryPath, EntryPoint = "LLVMPointerSize", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint PointerSize( LLVMTargetDataRef @TD ); + + [DllImport( libraryPath, EntryPoint = "LLVMPointerSizeForAS", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint PointerSizeForAS( LLVMTargetDataRef @TD, uint @AS ); + + [DllImport( libraryPath, EntryPoint = "LLVMIntPtrType", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef IntPtrType( LLVMTargetDataRef @TD ); + + [DllImport( libraryPath, EntryPoint = "LLVMIntPtrTypeForAS", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef IntPtrTypeForAS( LLVMTargetDataRef @TD, uint @AS ); + + [DllImport( libraryPath, EntryPoint = "LLVMIntPtrTypeInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef IntPtrTypeInContext( LLVMContextRef @C, LLVMTargetDataRef @TD ); + + [DllImport( libraryPath, EntryPoint = "LLVMIntPtrTypeForASInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTypeRef IntPtrTypeForASInContext( LLVMContextRef @C, LLVMTargetDataRef @TD, uint @AS ); + + [DllImport( libraryPath, EntryPoint = "LLVMSizeOfTypeInBits", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong SizeOfTypeInBits( LLVMTargetDataRef @TD, LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMStoreSizeOfType", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong StoreSizeOfType( LLVMTargetDataRef @TD, LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMABISizeOfType", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong ABISizeOfType( LLVMTargetDataRef @TD, LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMABIAlignmentOfType", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint ABIAlignmentOfType( LLVMTargetDataRef @TD, LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMCallFrameAlignmentOfType", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint CallFrameAlignmentOfType( LLVMTargetDataRef @TD, LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMPreferredAlignmentOfType", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint PreferredAlignmentOfType( LLVMTargetDataRef @TD, LLVMTypeRef @Ty ); + + [DllImport( libraryPath, EntryPoint = "LLVMPreferredAlignmentOfGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint PreferredAlignmentOfGlobal( LLVMTargetDataRef @TD, LLVMValueRef @GlobalVar ); + + [DllImport( libraryPath, EntryPoint = "LLVMElementAtOffset", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint ElementAtOffset( LLVMTargetDataRef @TD, LLVMTypeRef @StructTy, ulong @Offset ); + + [DllImport( libraryPath, EntryPoint = "LLVMOffsetOfElement", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong OffsetOfElement( LLVMTargetDataRef @TD, LLVMTypeRef @StructTy, uint @Element ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFirstTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetRef GetFirstTarget( ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetNextTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetRef GetNextTarget( LLVMTargetRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetFromName", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMTargetRef GetTargetFromName( [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetFromTriple", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMStatus GetTargetFromTriple( [MarshalAs( UnmanagedType.LPStr )] string @Triple, out LLVMTargetRef @T, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] out string @ErrorMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetName", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetTargetName( LLVMTargetRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetDescription", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ) )] + internal static extern string GetTargetDescription( LLVMTargetRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMTargetHasJIT", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool TargetHasJIT( LLVMTargetRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMTargetHasTargetMachine", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool TargetHasTargetMachine( LLVMTargetRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMTargetHasAsmBackend", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool TargetHasAsmBackend( LLVMTargetRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateTargetMachine", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMTargetMachineRef CreateTargetMachine( LLVMTargetRef @T, [MarshalAs( UnmanagedType.LPStr )] string @Triple, [MarshalAs( UnmanagedType.LPStr )] string @CPU, [MarshalAs( UnmanagedType.LPStr )] string @Features, LLVMCodeGenOptLevel @Level, LLVMRelocMode @Reloc, LLVMCodeModel @CodeModel ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeTargetMachine", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeTargetMachine( LLVMTargetMachineRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetMachineTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetRef GetTargetMachineTarget( LLVMTargetMachineRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetMachineTriple", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string GetTargetMachineTriple( LLVMTargetMachineRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetMachineCPU", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string GetTargetMachineCPU( LLVMTargetMachineRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetTargetMachineFeatureString", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] + internal static extern string GetTargetMachineFeatureString( LLVMTargetMachineRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateTargetDataLayout", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetDataRef CreateTargetDataLayout( LLVMTargetMachineRef @T ); + + [DllImport( libraryPath, EntryPoint = "LLVMSetTargetMachineAsmVerbosity", CallingConvention = CallingConvention.Cdecl )] + internal static extern void SetTargetMachineAsmVerbosity( LLVMTargetMachineRef @T, [MarshalAs( UnmanagedType.Bool )]bool @VerboseAsm ); + + [DllImport( libraryPath, EntryPoint = "LLVMTargetMachineEmitToFile", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMStatus TargetMachineEmitToFile( LLVMTargetMachineRef @T, LLVMModuleRef @M, string @Filename, LLVMCodeGenFileType @codegen, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] out string @ErrorMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMTargetMachineEmitToMemoryBuffer", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus TargetMachineEmitToMemoryBuffer( LLVMTargetMachineRef @T, LLVMModuleRef @M, LLVMCodeGenFileType @codegen, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( StringMarshaler ), MarshalCookie = "DisposeMessage" )] out string @ErrorMessage, out LLVMMemoryBufferRef @OutMemBuf ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetDefaultTargetTriple", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetDefaultTargetTriple( ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAnalysisPasses", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddAnalysisPasses( LLVMTargetMachineRef @T, LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMLinkInMCJIT", CallingConvention = CallingConvention.Cdecl )] + internal static extern void LinkInMCJIT( ); + + [DllImport( libraryPath, EntryPoint = "LLVMLinkInInterpreter", CallingConvention = CallingConvention.Cdecl )] + internal static extern void LinkInInterpreter( ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateGenericValueOfInt", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMGenericValueRef CreateGenericValueOfInt( LLVMTypeRef @Ty, ulong @N, [MarshalAs( UnmanagedType.Bool )]bool @IsSigned ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateGenericValueOfPointer", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMGenericValueRef CreateGenericValueOfPointer( IntPtr @P ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateGenericValueOfFloat", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMGenericValueRef CreateGenericValueOfFloat( LLVMTypeRef @Ty, double @N ); + + [DllImport( libraryPath, EntryPoint = "LLVMGenericValueIntWidth", CallingConvention = CallingConvention.Cdecl )] + internal static extern uint GenericValueIntWidth( LLVMGenericValueRef @GenValRef ); + + [DllImport( libraryPath, EntryPoint = "LLVMGenericValueToInt", CallingConvention = CallingConvention.Cdecl )] + internal static extern ulong GenericValueToInt( LLVMGenericValueRef @GenVal, [MarshalAs( UnmanagedType.Bool )]bool @IsSigned ); + + [DllImport( libraryPath, EntryPoint = "LLVMGenericValueToPointer", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GenericValueToPointer( LLVMGenericValueRef @GenVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMGenericValueToFloat", CallingConvention = CallingConvention.Cdecl )] + internal static extern double GenericValueToFloat( LLVMTypeRef @TyRef, LLVMGenericValueRef @GenVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeGenericValue", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeGenericValue( LLVMGenericValueRef @GenVal ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateExecutionEngineForModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus CreateExecutionEngineForModule( out LLVMExecutionEngineRef @OutEE, LLVMModuleRef @M, out IntPtr @OutError ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateInterpreterForModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus CreateInterpreterForModule( out LLVMExecutionEngineRef @OutInterp, LLVMModuleRef @M, out IntPtr @OutError ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateJITCompilerForModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus CreateJITCompilerForModule( out LLVMExecutionEngineRef @OutJIT, LLVMModuleRef @M, uint @OptLevel, out IntPtr @OutError ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeMCJITCompilerOptions", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeMCJITCompilerOptions( out LLVMMCJITCompilerOptions @Options, size_t @SizeOfOptions ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateMCJITCompilerForModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus CreateMCJITCompilerForModule( out LLVMExecutionEngineRef @OutJIT, LLVMModuleRef @M, out LLVMMCJITCompilerOptions @Options, size_t @SizeOfOptions, out IntPtr @OutError ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeExecutionEngine", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeExecutionEngine( LLVMExecutionEngineRef @EE ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunStaticConstructors", CallingConvention = CallingConvention.Cdecl )] + internal static extern void RunStaticConstructors( LLVMExecutionEngineRef @EE ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunStaticDestructors", CallingConvention = CallingConvention.Cdecl )] + internal static extern void RunStaticDestructors( LLVMExecutionEngineRef @EE ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunFunctionAsMain", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern int RunFunctionAsMain( LLVMExecutionEngineRef @EE, LLVMValueRef @F, uint @ArgC, string[ ] @ArgV, string[ ] @EnvP ); + + [DllImport( libraryPath, EntryPoint = "LLVMRunFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMGenericValueRef RunFunction( LLVMExecutionEngineRef @EE, LLVMValueRef @F, uint @NumArgs, out LLVMGenericValueRef @Args ); + + [DllImport( libraryPath, EntryPoint = "LLVMFreeMachineCodeForFunction", CallingConvention = CallingConvention.Cdecl )] + internal static extern void FreeMachineCodeForFunction( LLVMExecutionEngineRef @EE, LLVMValueRef @F ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddModule( LLVMExecutionEngineRef @EE, LLVMModuleRef @M ); + + [DllImport( libraryPath, EntryPoint = "LLVMRemoveModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus RemoveModule( LLVMExecutionEngineRef @EE, LLVMModuleRef @M, out LLVMModuleRef @OutMod, out IntPtr @OutError ); + + [DllImport( libraryPath, EntryPoint = "LLVMFindFunction", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMStatus FindFunction( LLVMExecutionEngineRef @EE, [MarshalAs( UnmanagedType.LPStr )] string @Name, out LLVMValueRef @OutFn ); + + /* As of at least LLVM 4.0.1 this just returns null + //[DllImport( libraryPath, EntryPoint = "LLVMRecompileAndRelinkFunction", CallingConvention = CallingConvention.Cdecl )] + //internal static extern IntPtr RecompileAndRelinkFunction( LLVMExecutionEngineRef @EE, LLVMValueRef @Fn ); + */ + + [DllImport( libraryPath, EntryPoint = "LLVMGetExecutionEngineTargetData", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetDataRef GetExecutionEngineTargetData( LLVMExecutionEngineRef @EE ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetExecutionEngineTargetMachine", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMTargetMachineRef GetExecutionEngineTargetMachine( LLVMExecutionEngineRef @EE ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddGlobalMapping", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddGlobalMapping( LLVMExecutionEngineRef @EE, LLVMValueRef @Global, IntPtr @Addr ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetPointerToGlobal", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetPointerToGlobal( LLVMExecutionEngineRef @EE, LLVMValueRef @Global ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetGlobalValueAddress", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern int GetGlobalValueAddress( LLVMExecutionEngineRef @EE, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetFunctionAddress", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern int GetFunctionAddress( LLVMExecutionEngineRef @EE, [MarshalAs( UnmanagedType.LPStr )] string @Name ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateSimpleMCJITMemoryManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMMCJITMemoryManagerRef CreateSimpleMCJITMemoryManager( IntPtr @Opaque, LLVMMemoryManagerAllocateCodeSectionCallback @AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback @AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback @FinalizeMemory, LLVMMemoryManagerDestroyCallback @Destroy ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeMCJITMemoryManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeMCJITMemoryManager( LLVMMCJITMemoryManagerRef @MM ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeTransformUtils", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeTransformUtils( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeScalarOpts", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeScalarOpts( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeObjCARCOpts", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeObjCARCOpts( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeVectorization", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeVectorization( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeInstCombine", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeInstCombine( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeIPO", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeIPO( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeInstrumentation", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeInstrumentation( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeAnalysis", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeAnalysis( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeIPA", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeIPA( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeCodeGen", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeCodeGen( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMInitializeTarget", CallingConvention = CallingConvention.Cdecl )] + internal static extern void InitializeTarget( LLVMPassRegistryRef @R ); + + [DllImport( libraryPath, EntryPoint = "LLVMParseIRInContext", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus ParseIRInContext( LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage ); + + [DllImport( libraryPath, EntryPoint = "LLVMLinkModules2", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMStatus LinkModules2( LLVMModuleRef @Dest, LLVMModuleRef @Src ); + + [DllImport( libraryPath, EntryPoint = "LLVMCreateObjectFile", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMObjectFileRef CreateObjectFile( LLVMMemoryBufferRef @MemBuf ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeObjectFile", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeObjectFile( LLVMObjectFileRef @ObjectFile ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSections", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMSectionIteratorRef GetSections( LLVMObjectFileRef @ObjectFile ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeSectionIterator", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeSectionIterator( LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsSectionIteratorAtEnd", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsSectionIteratorAtEnd( LLVMObjectFileRef @ObjectFile, LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMMoveToNextSection", CallingConvention = CallingConvention.Cdecl )] + internal static extern void MoveToNextSection( LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMMoveToContainingSection", CallingConvention = CallingConvention.Cdecl )] + internal static extern void MoveToContainingSection( LLVMSectionIteratorRef @Sect, LLVMSymbolIteratorRef @Sym ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSymbols", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMSymbolIteratorRef GetSymbols( LLVMObjectFileRef @ObjectFile ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeSymbolIterator", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeSymbolIterator( LLVMSymbolIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsSymbolIteratorAtEnd", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsSymbolIteratorAtEnd( LLVMObjectFileRef @ObjectFile, LLVMSymbolIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMMoveToNextSymbol", CallingConvention = CallingConvention.Cdecl )] + internal static extern void MoveToNextSymbol( LLVMSymbolIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSectionName", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetSectionName( LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSectionSize", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetSectionSize( LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSectionContents", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetSectionContents( LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSectionAddress", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetSectionAddress( LLVMSectionIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSectionContainsSymbol", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool GetSectionContainsSymbol( LLVMSectionIteratorRef @SI, LLVMSymbolIteratorRef @Sym ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetRelocations", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMRelocationIteratorRef GetRelocations( LLVMSectionIteratorRef @Section ); + + [DllImport( libraryPath, EntryPoint = "LLVMDisposeRelocationIterator", CallingConvention = CallingConvention.Cdecl )] + internal static extern void DisposeRelocationIterator( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMIsRelocationIteratorAtEnd", CallingConvention = CallingConvention.Cdecl )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool IsRelocationIteratorAtEnd( LLVMSectionIteratorRef @Section, LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMMoveToNextRelocation", CallingConvention = CallingConvention.Cdecl )] + internal static extern void MoveToNextRelocation( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSymbolName", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetSymbolName( LLVMSymbolIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSymbolAddress", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetSymbolAddress( LLVMSymbolIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetSymbolSize", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetSymbolSize( LLVMSymbolIteratorRef @SI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetRelocationOffset", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetRelocationOffset( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetRelocationSymbol", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMSymbolIteratorRef GetRelocationSymbol( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetRelocationType", CallingConvention = CallingConvention.Cdecl )] + internal static extern int GetRelocationType( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetRelocationTypeName", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetRelocationTypeName( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMGetRelocationValueString", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr GetRelocationValueString( LLVMRelocationIteratorRef @RI ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcCreateInstance", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMOrcJITStackRef OrcCreateInstance( LLVMTargetMachineRef @TM ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcGetErrorMsg", CallingConvention = CallingConvention.Cdecl )] + internal static extern IntPtr OrcGetErrorMsg( LLVMOrcJITStackRef @JITStack ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcGetMangledSymbol", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void OrcGetMangledSymbol( LLVMOrcJITStackRef @JITStack, out IntPtr @MangledSymbol, [MarshalAs( UnmanagedType.LPStr )] string @Symbol ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcDisposeMangledSymbol", CallingConvention = CallingConvention.Cdecl )] + internal static extern void OrcDisposeMangledSymbol( IntPtr @MangledSymbol ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcCreateLazyCompileCallback", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMOrcTargetAddress OrcCreateLazyCompileCallback( LLVMOrcJITStackRef @JITStack, LLVMOrcLazyCompileCallbackFn @Callback, IntPtr @CallbackCtx ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcCreateIndirectStub", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMOrcErrorCode OrcCreateIndirectStub( LLVMOrcJITStackRef @JITStack, [MarshalAs( UnmanagedType.LPStr )] string @StubName, LLVMOrcTargetAddress @InitAddr ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcSetIndirectStubPointer", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMOrcErrorCode OrcSetIndirectStubPointer( LLVMOrcJITStackRef @JITStack, [MarshalAs( UnmanagedType.LPStr )] string @StubName, LLVMOrcTargetAddress @NewAddr ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcAddEagerlyCompiledIR", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMOrcModuleHandle OrcAddEagerlyCompiledIR( LLVMOrcJITStackRef @JITStack, LLVMSharedModuleRef @Mod, LLVMOrcSymbolResolverFn @SymbolResolver, IntPtr @SymbolResolverCtx ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcAddLazilyCompiledIR", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMOrcModuleHandle OrcAddLazilyCompiledIR( LLVMOrcJITStackRef @JITStack, LLVMSharedModuleRef @Mod, LLVMOrcSymbolResolverFn @SymbolResolver, IntPtr @SymbolResolverCtx ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcRemoveModule", CallingConvention = CallingConvention.Cdecl )] + internal static extern void OrcRemoveModule( LLVMOrcJITStackRef @JITStack, LLVMOrcModuleHandle @H ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcGetSymbolAddress", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern LLVMOrcTargetAddress OrcGetSymbolAddress( LLVMOrcJITStackRef @JITStack, [MarshalAs( UnmanagedType.LPStr )] string @SymbolName ); + + [DllImport( libraryPath, EntryPoint = "LLVMOrcDisposeInstance", CallingConvention = CallingConvention.Cdecl )] + internal static extern void OrcDisposeInstance( LLVMOrcJITStackRef @JITStack ); + + [DllImport( libraryPath, EntryPoint = "LLVMLoadLibraryPermanently", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + [return: MarshalAs( UnmanagedType.Bool )] + internal static extern bool LoadLibraryPermanently( [MarshalAs( UnmanagedType.LPStr )] string @Filename ); + + [DllImport( libraryPath, EntryPoint = "LLVMParseCommandLineOptions", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void ParseCommandLineOptions( int @argc, string[ ] @argv, [MarshalAs( UnmanagedType.LPStr )] string @Overview ); + + [DllImport( libraryPath, EntryPoint = "LLVMSearchForAddressOfSymbol", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern IntPtr SearchForAddressOfSymbol( [MarshalAs( UnmanagedType.LPStr )] string @symbolName ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddSymbol", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = true, BestFitMapping = false )] + internal static extern void AddSymbol( [MarshalAs( UnmanagedType.LPStr )] string @symbolName, IntPtr @symbolValue ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddArgumentPromotionPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddArgumentPromotionPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddConstantMergePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddConstantMergePass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddDeadArgEliminationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddDeadArgEliminationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddFunctionAttrsPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddFunctionAttrsPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddFunctionInliningPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddFunctionInliningPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAlwaysInlinerPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddAlwaysInlinerPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddGlobalDCEPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddGlobalDCEPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddGlobalOptimizerPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddGlobalOptimizerPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddIPConstantPropagationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddIPConstantPropagationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddPruneEHPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddPruneEHPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddIPSCCPPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddIPSCCPPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddInternalizePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddInternalizePass( LLVMPassManagerRef @param0, uint @AllButMain ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddStripDeadPrototypesPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddStripDeadPrototypesPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddStripSymbolsPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddStripSymbolsPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderCreate", CallingConvention = CallingConvention.Cdecl )] + internal static extern LLVMPassManagerBuilderRef PassManagerBuilderCreate( ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderDispose", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderDispose( LLVMPassManagerBuilderRef @PMB ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderSetOptLevel", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderSetOptLevel( LLVMPassManagerBuilderRef @PMB, uint @OptLevel ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderSetSizeLevel", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderSetSizeLevel( LLVMPassManagerBuilderRef @PMB, uint @SizeLevel ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderSetDisableUnitAtATime", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderSetDisableUnitAtATime( LLVMPassManagerBuilderRef @PMB, [MarshalAs( UnmanagedType.Bool )]bool @Value ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderSetDisableUnrollLoops", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderSetDisableUnrollLoops( LLVMPassManagerBuilderRef @PMB, [MarshalAs( UnmanagedType.Bool )]bool @Value ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderSetDisableSimplifyLibCalls", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderSetDisableSimplifyLibCalls( LLVMPassManagerBuilderRef @PMB, [MarshalAs( UnmanagedType.Bool )]bool @Value ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderUseInlinerWithThreshold", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderUseInlinerWithThreshold( LLVMPassManagerBuilderRef @PMB, uint @Threshold ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderPopulateFunctionPassManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderPopulateFunctionPassManager( LLVMPassManagerBuilderRef @PMB, LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderPopulateModulePassManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderPopulateModulePassManager( LLVMPassManagerBuilderRef @PMB, LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMPassManagerBuilderPopulateLTOPassManager", CallingConvention = CallingConvention.Cdecl )] + internal static extern void PassManagerBuilderPopulateLTOPassManager( LLVMPassManagerBuilderRef @PMB, LLVMPassManagerRef @PM, [MarshalAs( UnmanagedType.Bool )]bool @Internalize, [MarshalAs( UnmanagedType.Bool )]bool @RunInliner ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAggressiveDCEPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddAggressiveDCEPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddBitTrackingDCEPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddBitTrackingDCEPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddAlignmentFromAssumptionsPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddAlignmentFromAssumptionsPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddCFGSimplificationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddCFGSimplificationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddDeadStoreEliminationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddDeadStoreEliminationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddScalarizerPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddScalarizerPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddMergedLoadStoreMotionPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddMergedLoadStoreMotionPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddGVNPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddGVNPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddNewGVNPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddNewGVNPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddIndVarSimplifyPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddIndVarSimplifyPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddInstructionCombiningPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddInstructionCombiningPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddJumpThreadingPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddJumpThreadingPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLICMPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLICMPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopDeletionPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopDeletionPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopIdiomPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopIdiomPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopRotatePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopRotatePass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopRerollPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopRerollPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopUnrollPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopUnrollPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopUnswitchPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopUnswitchPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddMemCpyOptPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddMemCpyOptPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddPartiallyInlineLibCallsPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddPartiallyInlineLibCallsPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLowerSwitchPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLowerSwitchPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddPromoteMemoryToRegisterPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddPromoteMemoryToRegisterPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddReassociatePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddReassociatePass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddSCCPPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddSCCPPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddScalarReplAggregatesPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddScalarReplAggregatesPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddScalarReplAggregatesPassSSA", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddScalarReplAggregatesPassSSA( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddScalarReplAggregatesPassWithThreshold", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddScalarReplAggregatesPassWithThreshold( LLVMPassManagerRef @PM, int @Threshold ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddSimplifyLibCallsPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddSimplifyLibCallsPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddTailCallEliminationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddTailCallEliminationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddConstantPropagationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddConstantPropagationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddDemoteMemoryToRegisterPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddDemoteMemoryToRegisterPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddVerifierPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddVerifierPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddCorrelatedValuePropagationPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddCorrelatedValuePropagationPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddEarlyCSEPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddEarlyCSEPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddEarlyCSEMemSSAPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddEarlyCSEMemSSAPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLowerExpectIntrinsicPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLowerExpectIntrinsicPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddTypeBasedAliasAnalysisPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddTypeBasedAliasAnalysisPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddScopedNoAliasAAPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddScopedNoAliasAAPass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddBasicAliasAnalysisPass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddBasicAliasAnalysisPass( LLVMPassManagerRef @PM ); + + [Obsolete( "Use AddSLPVectorizePass instead" )] + [DllImport( libraryPath, EntryPoint = "LLVMAddBBVectorizePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddBBVectorizePass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddLoopVectorizePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddLoopVectorizePass( LLVMPassManagerRef @PM ); + + [DllImport( libraryPath, EntryPoint = "LLVMAddSLPVectorizePass", CallingConvention = CallingConvention.Cdecl )] + internal static extern void AddSLPVectorizePass( LLVMPassManagerRef @PM ); + } +} \ No newline at end of file diff --git a/src/Llvm.NET/Native/GeneratedCodeExtensions.cs b/src/Llvm.NET/Native/GeneratedCodeExtensions.cs new file mode 100644 index 000000000..acdc4e220 --- /dev/null +++ b/src/Llvm.NET/Native/GeneratedCodeExtensions.cs @@ -0,0 +1,124 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Llvm.NET.Native +{ + internal static partial class NativeMethods + { + // version info for verification of matched LibLLVM + private const int VersionMajor = 4; + private const int VersionMinor = 0; + private const int VersionPatch = 1; + + private static void FatalErrorHandler( string Reason ) + { + // NOTE: LLVM will call exit() upon return from this function and there's no way to stop it + Trace.TraceError( "LLVM Fatal Error: '{0}'; Application exiting.", Reason ); + } + + /* TODO: Remove static constructor in favor of a static state init utility that returns IDisposable + so that all the analyzer issue here go away and proper LLVMShutdown can be performed. + */ + + /// Static constructor for NativeMethods + [SuppressMessage( "Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations", Justification = "Exception needed as code can't function if LibLLVM isn't loaded" )] + [SuppressMessage( "Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Constructor needed to run init code" )] + static NativeMethods( ) + { + // force loading the appropriate architecture specific + // DLL before any use of the wrapped inter-op APIs to + // allow building this library as ANYCPU + string path = Path.GetDirectoryName( Assembly.GetExecutingAssembly( ).Location ); + if( Directory.Exists( Path.Combine( path, "LibLLVM" ) ) ) + { + LoadWin32Library( libraryPath, "LibLLVM" ); + } + else + { + // fall-back to standard library search paths to allow building + // CPU specific variants with only one native DLL without needing + // conditional compilation on this library, which is useful for + // unit testing or whenever the Nuget packaging isn't desired. + LoadWin32Library( libraryPath, null ); + } + + // Verify the version of LLVM in LibLLVM + GetVersionInfo( out LLVMVersionInfo versionInfo ); + if( versionInfo.Major != VersionMajor + || versionInfo.Minor != VersionMinor + || versionInfo.Patch < VersionPatch + ) + { + throw new BadImageFormatException( "Mismatched LibLLVM version" ); + } + + // initialize the static fields + FatalErrorHandlerDelegate = new Lazy( ( ) => FatalErrorHandler, LazyThreadSafetyMode.PublicationOnly ); + InstallFatalErrorHandler( FatalErrorHandlerDelegate.Value ); + } + + /// Dynamically loads a DLL from a directory dependent on the current architecture + /// name of the DLL + /// Root path to find the DLL from + /// Handle for the DLL + /// + /// This method will detect the architecture the code is executing on (i.e. x86 or x64) + /// and will load the DLL from an architecture specific sub folder of . + /// This allows use of AnyCPU builds and interop to simplify build processes from needing to + /// deal with "mixed" configurations or other accidental combinations that are a pain to + /// sort out and keep straight when the tools insist on creating AnyCPU projects and "mixed" configurations + /// by default. + /// If the Is , empty or all whitespace then + /// the standard DLL search paths are used. This assumes the correct variant of the DLL is available + /// (e.g. for a 32 bit system a 32 bit native DLL is found). This allows for either building as AnyCPU + /// plus shipping multiple native DLLs, or building for a specific CPU type while shipping only one native + /// DLL. Different products or projects may have different needs so this covers those cases. + /// + /// + internal static IntPtr LoadWin32Library( string moduleName, string rootPath ) + { + if( string.IsNullOrWhiteSpace( moduleName ) ) + { + throw new ArgumentNullException( nameof( moduleName ) ); + } + + string libPath; + if( string.IsNullOrWhiteSpace( rootPath ) ) + { + libPath = moduleName; + } + else + { + if( Environment.Is64BitProcess ) + { + libPath = Path.Combine( rootPath, "x64", moduleName ); + } + else + { + libPath = Path.Combine( rootPath, "x86", moduleName ); + } + } + + IntPtr moduleHandle = LoadLibrary( libPath ); + if( moduleHandle == IntPtr.Zero ) + { + int lasterror = Marshal.GetLastWin32Error( ); + throw new Win32Exception( lasterror, $"System error occurred trying to load DLL {libPath} from module '{Path.GetDirectoryName( Assembly.GetExecutingAssembly( ).Location )}' " ); + } + + return moduleHandle; + } + + [DllImport( "kernel32", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true )] + private static extern IntPtr LoadLibrary( [MarshalAs( UnmanagedType.LPStr )]string lpFileName ); + + // lazy initialized singleton unmanaged delegate so it is never collected + private static Lazy FatalErrorHandlerDelegate; + } +} diff --git a/src/Llvm.NET/Native/IntPtrExtensions.cs b/src/Llvm.NET/Native/IntPtrExtensions.cs new file mode 100644 index 000000000..d94073484 --- /dev/null +++ b/src/Llvm.NET/Native/IntPtrExtensions.cs @@ -0,0 +1,11 @@ +using System; + +namespace Llvm.NET.Native +{ + internal static class IntPtrExtensions + { + public static bool IsNull( this IntPtr self ) => self == IntPtr.Zero; + + public static bool IsNull( this UIntPtr self ) => self == UIntPtr.Zero; + } +} diff --git a/src/Llvm.NET/Native/LLVMBuilderRef.cs b/src/Llvm.NET/Native/LLVMBuilderRef.cs new file mode 100644 index 000000000..b8f85ae32 --- /dev/null +++ b/src/Llvm.NET/Native/LLVMBuilderRef.cs @@ -0,0 +1,34 @@ +using System; +using System.Security; + +namespace Llvm.NET.Native +{ + [SecurityCritical] + internal class LLVMBuilderRef + : SafeHandleNullIsInvalid + { + internal LLVMBuilderRef( ) + : base( true ) + { + } + + internal LLVMBuilderRef( IntPtr handle, bool owner ) + : base( owner ) + { + SetHandle( handle ); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] + internal LLVMBuilderRef( IntPtr handle ) + : this( handle, false ) + { + } + + [SecurityCritical] + protected override bool ReleaseHandle( ) + { + NativeMethods.DisposeBuilder( handle ); + return true; + } + } +} diff --git a/src/Llvm.NET/Native/LLVMMetadataRef.cs b/src/Llvm.NET/Native/LLVMMetadataRef.cs new file mode 100644 index 000000000..2a371c144 --- /dev/null +++ b/src/Llvm.NET/Native/LLVMMetadataRef.cs @@ -0,0 +1,33 @@ +using System; + +namespace Llvm.NET.Native +{ + internal partial struct LLVMMetadataRef + : IEquatable + { + public static LLVMMetadataRef Zero = new LLVMMetadataRef( IntPtr.Zero ); + + public override int GetHashCode( ) => Pointer.GetHashCode( ); + + public override bool Equals( object obj ) + { + if( obj is LLVMMetadataRef ) + { + return Equals( ( LLVMMetadataRef )obj ); + } + + if( obj is IntPtr ) + { + return Pointer.Equals( obj ); + } + + return base.Equals( obj ); + } + + public bool Equals( LLVMMetadataRef other ) => Pointer == other.Pointer; + + public static bool operator ==( LLVMMetadataRef lhs, LLVMMetadataRef rhs ) => lhs.Equals( rhs ); + + public static bool operator !=( LLVMMetadataRef lhs, LLVMMetadataRef rhs ) => !lhs.Equals( rhs ); + } +} diff --git a/src/Llvm.NET/Native/LLVMPassRegistryRef.cs b/src/Llvm.NET/Native/LLVMPassRegistryRef.cs new file mode 100644 index 000000000..7c2e42453 --- /dev/null +++ b/src/Llvm.NET/Native/LLVMPassRegistryRef.cs @@ -0,0 +1,34 @@ +using System; +using System.Security; + +namespace Llvm.NET.Native +{ + [SecurityCritical] + internal class LLVMPassRegistryRef + : SafeHandleNullIsInvalid + { + internal LLVMPassRegistryRef( ) + : base( true ) + { + } + + internal LLVMPassRegistryRef( IntPtr handle, bool owner ) + : base( owner ) + { + SetHandle( handle ); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] + internal LLVMPassRegistryRef( IntPtr handle ) + : this( handle, false ) + { + } + + [SecurityCritical] + protected override bool ReleaseHandle( ) + { + NativeMethods.PassRegistryDispose( handle ); + return true; + } + } +} diff --git a/src/Llvm.NET/Native/LLVMTripleRef.cs b/src/Llvm.NET/Native/LLVMTripleRef.cs new file mode 100644 index 000000000..a2d963f44 --- /dev/null +++ b/src/Llvm.NET/Native/LLVMTripleRef.cs @@ -0,0 +1,35 @@ +using System; +using System.Security; + +namespace Llvm.NET.Native +{ + // typedef struct LLVMOpaqueTriple* LLVMTripleRef; + [SecurityCritical] + internal class LLVMTripleRef + : SafeHandleNullIsInvalid + { + internal LLVMTripleRef( ) + : base( true ) + { + } + + internal LLVMTripleRef( IntPtr handle, bool owner ) + : base( owner ) + { + SetHandle( handle ); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Required for marshaling support (used via reflection)" )] + internal LLVMTripleRef( IntPtr handle ) + : this( handle, false ) + { + } + + [SecurityCritical] + protected override bool ReleaseHandle( ) + { + NativeMethods.DisposeTriple( handle ); + return true; + } + } +} diff --git a/src/Llvm.NET/Native/LLVMVersionInfo.cs b/src/Llvm.NET/Native/LLVMVersionInfo.cs new file mode 100644 index 000000000..9d99e8551 --- /dev/null +++ b/src/Llvm.NET/Native/LLVMVersionInfo.cs @@ -0,0 +1,21 @@ +using System; +using System.Runtime.InteropServices; + +namespace Llvm.NET.Native +{ + internal struct LLVMVersionInfo + { + public readonly int Major; + public readonly int Minor; + public readonly int Patch; + private readonly IntPtr VersionStringPtr; + + public override string ToString( ) + { + return Marshal.PtrToStringAnsi( VersionStringPtr ); + } + + public static implicit operator Version( LLVMVersionInfo versionInfo ) + => new Version( versionInfo.Major, versionInfo.Minor, versionInfo.Patch ); + } +} diff --git a/src/Llvm.NET/Native/SafeHandleNullIsInvalid.cs b/src/Llvm.NET/Native/SafeHandleNullIsInvalid.cs new file mode 100644 index 000000000..5717bc2d2 --- /dev/null +++ b/src/Llvm.NET/Native/SafeHandleNullIsInvalid.cs @@ -0,0 +1,29 @@ +using System; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices; +using System.Security; +using System.Security.Permissions; + +namespace Llvm.NET.Native +{ + /// Base class for LLVM disposable types that are instantiated outside of an LLVM and therefore won't be disposed by the context + [SecurityCritical] + [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)] + internal abstract class SafeHandleNullIsInvalid + : SafeHandle + { + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected SafeHandleNullIsInvalid( bool ownsHandle) + : base( IntPtr.Zero, ownsHandle ) + { + } + + public bool IsNull => handle.IsNull(); + + public override bool IsInvalid + { + [SecurityCritical] + get => IsNull; + } + } +} diff --git a/src/Llvm.NET/Native/StringMarshaler.cs b/src/Llvm.NET/Native/StringMarshaler.cs new file mode 100644 index 000000000..0e072e46b --- /dev/null +++ b/src/Llvm.NET/Native/StringMarshaler.cs @@ -0,0 +1,87 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; + +namespace Llvm.NET.Native +{ + internal enum NativeStringCleanup + { + None, + DisposeMessage, + } + + // use with: + // [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler))] + // or + // [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(StringMarshaler), MarshalCookie="DisposeMessage")] + [SuppressMessage( "Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated via CustomMarshaling" )] + internal class StringMarshaler + : ICustomMarshaler + { + internal StringMarshaler( Action nativeDisposer ) + { + NativeDisposer = nativeDisposer; + } + + public void CleanUpManagedData( object ManagedObj ) + { + } + + public void CleanUpNativeData( IntPtr pNativeData ) + => NativeDisposer?.Invoke( pNativeData ); + + [SuppressMessage( "Design", "CA1024:Use properties where appropriate.", Justification = "Name and signature defined by interface")] + public int GetNativeDataSize( ) => -1; + + public IntPtr MarshalManagedToNative( object ManagedObj ) + => throw new NotImplementedException( ); + + public object MarshalNativeToManaged( IntPtr pNativeData ) + => NormalizeLineEndings( pNativeData ); + + private Action NativeDisposer; + + // LLVM doesn't use environment/OS specific line endings, so this will + // normalize the line endings from strings provided by LLVM into the current + // environment's normal format. + private static string NormalizeLineEndings( IntPtr llvmString ) + { + if( llvmString == IntPtr.Zero ) + { + return string.Empty; + } + + string str = Marshal.PtrToStringAnsi( llvmString ); + return NormalizeLineEndings( str ); + } + + private static string NormalizeLineEndings( string txt ) + { + // shortcut optimization for environments that match the LLVM assumption + if( Environment.NewLine.Length == 1 && Environment.NewLine[ 0 ] == '\n' ) + { + return txt; + } + + return LineEndingNormalizingRegEx.Replace( txt, Environment.NewLine ); + } + + private static readonly Regex LineEndingNormalizingRegEx = new Regex( "(\r\n|\n\r|\r|\n)" ); + + public static ICustomMarshaler GetInstance( string cookie ) + { + switch(cookie.ToUpperInvariant()) + { + case null: + case "": + case "NONE": + return new StringMarshaler( null ); + case "DISPOSEMESSAGE": + return new StringMarshaler( NativeMethods.DisposeMessage ); + default: + throw new ArgumentException( $"'{cookie}' is not a valid option", nameof( cookie ) ); + } + } + } +} diff --git a/src/Llvm.NET/Native/ValueKind.cs b/src/Llvm.NET/Native/ValueKind.cs new file mode 100644 index 000000000..019080e42 --- /dev/null +++ b/src/Llvm.NET/Native/ValueKind.cs @@ -0,0 +1,130 @@ +namespace Llvm.NET.Native +{ + internal enum ValueKind : uint + { + Argument = LLVMValueKind.LLVMArgumentValueKind, // This is an instance of Argument + BasicBlock = LLVMValueKind.LLVMBasicBlockValueKind, // This is an instance of BasicBlock + MemoryUse = LLVMValueKind.LLVMMemoryUseValueKind, // ??? + MemoryDef = LLVMValueKind.LLVMMemoryDefValueKind, // ??? + MemoryPhi = LLVMValueKind.LLVMMemoryPhiValueKind, // ??? + + Function = LLVMValueKind.LLVMFunctionValueKind, // This is an instance of Function + GlobalAlias = LLVMValueKind.LLVMGlobalAliasValueKind, // This is an instance of GlobalAlias + GlobalIFunc = LLVMValueKind.LLVMGlobalIFuncValueKind, // ??? + GlobalVariable = LLVMValueKind.LLVMGlobalVariableValueKind, // This is an instance of GlobalVariable + BlockAddress = LLVMValueKind.LLVMBlockAddressValueKind, // This is an instance of BlockAddress + ConstantExpr = LLVMValueKind.LLVMConstantExprValueKind, // This is an instance of ConstantExpr + ConstantArray = LLVMValueKind.LLVMConstantArrayValueKind, // This is an instance of ConstantArray + ConstantStruct = LLVMValueKind.LLVMConstantStructValueKind, // This is an instance of ConstantStruct + ConstantVector = LLVMValueKind.LLVMConstantVectorValueKind, // This is an instance of ConstantVector + + UndefValue = LLVMValueKind.LLVMUndefValueValueKind, // This is an instance of UndefValue + ConstantAggregateZero = LLVMValueKind.LLVMConstantAggregateZeroValueKind, // This is an instance of ConstantAggregateZero + ConstantDataArray = LLVMValueKind.LLVMConstantDataArrayValueKind, // This is an instance of ConstantDataArray + ConstantDataVector = LLVMValueKind.LLVMConstantDataVectorValueKind, // This is an instance of ConstantDataVector + ConstantInt = LLVMValueKind.LLVMConstantIntValueKind, // This is an instance of ConstantInt + ConstantFP = LLVMValueKind.LLVMConstantFPValueKind, // This is an instance of ConstantFP + ConstantPointerNull = LLVMValueKind.LLVMConstantPointerNullValueKind, // This is an instance of ConstantPointerNull + ConstantTokenNone = LLVMValueKind.LLVMConstantTokenNoneValueKind, // This is an instance of ConstantTokenNone + + MetadataAsValue = LLVMValueKind.LLVMMetadataAsValueValueKind, // This is an instance of MetadataAsValue + InlineAsm = LLVMValueKind.LLVMInlineAsmValueKind, // This is an instance of InlineAsm + + Instruction = LLVMValueKind.LLVMInstructionValueKind, // This is an instance of Instruction + // Enum values starting at InstructionVal are used for Instructions; + + // instruction values come directly from LLVM Instruction.def which is different from the "stable" + // LLVM-C API, therefore they are less "stable" and bound to the C++ implementation version and + // subject to change from version to version. + Return = 1 + Instruction, // Terminators + Branch = 2 + Instruction, + Switch = 3 + Instruction, + IndirectBranch = 4 + Instruction, + Invoke = 5 + Instruction, + Resume = 6 + Instruction, + Unreachable = 7 + Instruction, + CleanUpReturn = 8 + Instruction, + CatchReturn = 9 + Instruction, + CatchSwitch = 10 + Instruction, + + Add = 11 + Instruction, // binary operators + FAdd = 12 + Instruction, + Sub = 13 + Instruction, + FSub = 14 + Instruction, + Mul = 15 + Instruction, + FMul = 16 + Instruction, + UDiv = 17 + Instruction, + SDiv = 18 + Instruction, + FDiv = 19 + Instruction, + URem = 20 + Instruction, + SRem = 21 + Instruction, + FRem = 22 + Instruction, + + Shl = 23 + Instruction, // Logical Operators + LShr = 24 + Instruction, + AShr = 25 + Instruction, + And = 26 + Instruction, + Or = 27 + Instruction, + Xor = 28 + Instruction, + + Alloca = 29 + Instruction, // Memory Operators + Load = 30 + Instruction, + Store = 31 + Instruction, + GetElementPtr = 32 + Instruction, + Fence = 33 + Instruction, + AtomicCmpXchg = 34 + Instruction, + AtomicRMW = 35 + Instruction, + + Trunc = 36 + Instruction, // cast/conversion operators + ZeroExtend = 37 + Instruction, + SignExtend = 38 + Instruction, + FPToUI = 39 + Instruction, + FPToSI = 40 + Instruction, + UIToFP = 41 + Instruction, + SIToFP = 42 + Instruction, + FPTrunc = 43 + Instruction, + FPExt = 44 + Instruction, + PtrToInt = 45 + Instruction, + IntToPtr = 46 + Instruction, + BitCast = 47 + Instruction, + AddrSpaceCast = 48 + Instruction, + + CleanupPad = 49 + Instruction, // New Exception pads + CatchPad = 50 + Instruction, + + ICmp = 51 + Instruction, + FCmp = 52 + Instruction, + Phi = 53 + Instruction, + Call = 54 + Instruction, + Select = 55 + Instruction, + UserOp1 = 56 + Instruction, + UserOp2 = 57 + Instruction, + VaArg = 58 + Instruction, + ExtractElement = 59 + Instruction, + InsertElement = 60 + Instruction, + ShuffleVector = 61 + Instruction, + ExtractValue = 62 + Instruction, + InsertValue = 63 + Instruction, + LandingPad = 64 + Instruction, + + // Markers: + ConstantFirstVal = Function, + ConstantLastVal = ConstantTokenNone, + + ConstantDataFirstVal = UndefValue, + ConstantDataLastVal = ConstantTokenNone, + ConstantAggregateFirstVal = ConstantArray, + ConstantAggregateLastVal = ConstantVector, + } + + internal static partial class NativeMethods + { + // retrieves the raw underlying native C++ ValueKind enumeration for a value + // This is generally only used in the mapping of an LLVMValueRef to a the + // Llvm.NET instance wrapping it. Since the Stable C API uses a distinct enum for + // the instruction codes, they don't actually match the underlying C++ kind and + // actually overlap it in incompatible ways. So, this uses the underlying enum to + // build up the correct .NET types for a given LLVMValueRef. + internal static ValueKind GetValueIdAsKind( LLVMValueRef valueRef ) => ( ValueKind )GetValueID( valueRef ); + } +} diff --git a/src/Llvm.NET/LLVM/WrappedNativeCallback.cs b/src/Llvm.NET/Native/WrappedNativeCallback.cs similarity index 100% rename from src/Llvm.NET/LLVM/WrappedNativeCallback.cs rename to src/Llvm.NET/Native/WrappedNativeCallback.cs diff --git a/src/Llvm.NET/NativeMethods.cs b/src/Llvm.NET/NativeMethods.cs deleted file mode 100644 index 90eeca384..000000000 --- a/src/Llvm.NET/NativeMethods.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.ComponentModel; -using System.IO; -using System.Runtime.InteropServices; - -namespace Llvm.NET.Native -{ - internal static partial class NativeMethods - { - /// Dynamically loads a DLL from a directory dependent on the current architecture - /// name of the DLL - /// Root path to find the DLL from - /// Handle for the DLL - /// - /// This method will detect the architecture the code is executing on (i.e. x86 or x64) - /// and will load the DLL from an architecture specific sub folder of . - /// This allows use of AnyCPU builds and interop to simplify build processes from needing to - /// deal with "mixed" configurations or other accidental combinations that are a pain to - /// sort out and keep straight when the tools insist on creating AnyCPU projects and "mixed" configurations - /// by default. - /// If the Is , empty or all whitespace then - /// the standard DLL search paths are used. This assumes the correct variant of the DLL is available - /// (e.g. for a 32 bit system a 32 bit native DLL is found). This allows for either building as AnyCPU - /// plus shipping multiple native DLLs, or building for a specific CPU type while shipping only one native - /// DLL. Different products or projects may have different needs so this covers those cases. - /// - /// - internal static IntPtr LoadWin32Library( string moduleName, string rootPath ) - { - if( string.IsNullOrWhiteSpace( moduleName ) ) - throw new ArgumentNullException( nameof( moduleName ) ); - - string libPath; - if( string.IsNullOrWhiteSpace( rootPath ) ) - libPath = moduleName; - else - { - if( Environment.Is64BitProcess ) - libPath = Path.Combine( rootPath, "x64", moduleName ); - else - libPath = Path.Combine( rootPath, "x86", moduleName ); - } - - IntPtr moduleHandle = LoadLibrary( libPath ); - if( moduleHandle == IntPtr.Zero ) - { - var lasterror = Marshal.GetLastWin32Error( ); - throw new Win32Exception( lasterror ); - } - return moduleHandle; - } - - [DllImport("kernel32", SetLastError=true, BestFitMapping = false, ThrowOnUnmappableChar = true)] - static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName); - } -} diff --git a/src/Llvm.NET/NugetPkg/Llvm.NET.nuspec b/src/Llvm.NET/NugetPkg/Llvm.NET.nuspec new file mode 100644 index 000000000..c918eba02 --- /dev/null +++ b/src/Llvm.NET/NugetPkg/Llvm.NET.nuspec @@ -0,0 +1,20 @@ + + + + Llvm.NET + $version$ + .NET Foundation,LLVM.org + false + .NET Bindings for LLVM v$llvmversion$ + LLVM,Compiler,JIT + + + + + + + + + + + diff --git a/src/Llvm.NET/NugetPkg/build/Llvm.NET.props b/src/Llvm.NET/NugetPkg/build/Llvm.NET.props new file mode 100644 index 000000000..e2963fff0 --- /dev/null +++ b/src/Llvm.NET/NugetPkg/build/Llvm.NET.props @@ -0,0 +1,5 @@ + + + $([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', '..') + + diff --git a/src/Llvm.NET/PassManagerBuilder.cs b/src/Llvm.NET/PassManagerBuilder.cs index bf2bd6814..f0706abca 100644 --- a/src/Llvm.NET/PassManagerBuilder.cs +++ b/src/Llvm.NET/PassManagerBuilder.cs @@ -3,9 +3,8 @@ namespace Llvm.NET { - /// Provides a wrapper around an LLVM Pass Manager + /// Provides a wrapper around the LLVM PassManagerBuilder /// This class is still in the experimental stage as there is a lack of full support from the C API - [Obsolete("Direct use of legacy pass manager support will not carry forward")] public sealed class PassManagerBuilder : IDisposable { @@ -39,25 +38,26 @@ public void SetDisableSimplifyLibCalls( bool value ) NativeMethods.PassManagerBuilderSetDisableSimplifyLibCalls( PassManagerBuilderHandle, value ); } - //public void PopulateFunctionPassManager( PassManager passManager ) - //{ - // LLVMNative.PassManagerBuilderPopulateFunctionPassManager( PassManagerBuilderHandle, passManager.PassManagerHandle ); - //} - - //public void PopulateModulePassManager( PassManager passManager ) - //{ - // LLVMNative.PassManagerBuilderPopulateModulePassManager( PassManagerBuilderHandle, passManager.PassManagerHandle ); - //} + /* + public void PopulateFunctionPassManager( PassManager passManager ) + { + NativeMethods.PassManagerBuilderPopulateFunctionPassManager( PassManagerBuilderHandle, passManager.PassManagerHandle ); + } - //public void PopulateLTOPassManager( PassManager passManager, bool internalize, bool runInliner ) - //{ - // LLVMNative.PassManagerBuilderPopulateLTOPassManager( PassManagerBuilderHandle - // , passManager.PassManagerHandle - // , internalize - // , runInliner - // ); - //} + public void PopulateModulePassManager( PassManager passManager ) + { + NativeMethods.PassManagerBuilderPopulateModulePassManager( PassManagerBuilderHandle, passManager.PassManagerHandle ); + } + public void PopulateLTOPassManager( PassManager passManager, bool internalize, bool runInliner ) + { + NativeMethods.PassManagerBuilderPopulateLTOPassManager( PassManagerBuilderHandle + , passManager.PassManagerHandle + , internalize + , runInliner + ); + } + */ public void Dispose( ) { if( PassManagerBuilderHandle.Pointer != IntPtr.Zero ) @@ -67,6 +67,6 @@ public void Dispose( ) } } - LLVMPassManagerBuilderRef PassManagerBuilderHandle; + private LLVMPassManagerBuilderRef PassManagerBuilderHandle; } } diff --git a/src/Llvm.NET/PassRegistry.cs b/src/Llvm.NET/PassRegistry.cs index aedeccc79..af6253257 100644 --- a/src/Llvm.NET/PassRegistry.cs +++ b/src/Llvm.NET/PassRegistry.cs @@ -1,6 +1,6 @@ -using Llvm.NET.Native; -using System; +using System; using System.Threading; +using Llvm.NET.Native; namespace Llvm.NET { @@ -13,11 +13,25 @@ public PassRegistry( ) PassRegistryHandle = NativeMethods.CreatePassRegistry( ); } - private PassRegistry( PassRegistryHandle hRegistry ) + private PassRegistry( LLVMPassRegistryRef hRegistry ) { PassRegistryHandle = hRegistry; } + ~PassRegistry( ) + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose( false ); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose( ) + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose( true ); + GC.SuppressFinalize( this ); + } + public void InitializeAll( ) { InitializeCore( ); @@ -33,8 +47,8 @@ public void InitializeAll( ) InitializeIPA( ); InitializeTarget( ); InitializeCodeGenForOpt( ); - } + public void InitializeCodeGenForOpt() { NativeMethods.InitializeCodeGenForOpt( PassRegistryHandle ); @@ -100,8 +114,7 @@ public void InitializeTarget( ) NativeMethods.InitializeTarget( PassRegistryHandle ); } - #region IDisposable Support - void Dispose( bool disposing ) + private void Dispose( bool disposing ) { if( !PassRegistryHandle.IsClosed ) { @@ -114,27 +127,12 @@ void Dispose( bool disposing ) } } - ~PassRegistry( ) - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose( false ); - } - - // This code added to correctly implement the disposable pattern. - public void Dispose( ) - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose( true ); - GC.SuppressFinalize( this ); - } - #endregion - - PassRegistryHandle PassRegistryHandle; + private LLVMPassRegistryRef PassRegistryHandle; public static PassRegistry GlobalRegistry => LazyGlobalPassRegistry.Value; - private static Lazy LazyGlobalPassRegistry - = new Lazy( ( ) => new PassRegistry( NativeMethods.GetGlobalPassRegistry( ) ) + private static readonly Lazy LazyGlobalPassRegistry + = new Lazy( () => new PassRegistry( NativeMethods.GetGlobalPassRegistry() ) , LazyThreadSafetyMode.ExecutionAndPublication ); } diff --git a/src/Llvm.NET/Properties/AssemblyInfo.cs b/src/Llvm.NET/Properties/AssemblyInfo.cs index 820b5f742..d6f068e92 100644 --- a/src/Llvm.NET/Properties/AssemblyInfo.cs +++ b/src/Llvm.NET/Properties/AssemblyInfo.cs @@ -1,23 +1,10 @@ using System; -using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle( "Llvm.NET" )] -[assembly: AssemblyDescription( ".NET bindings for LLVM-C API libraries in LibLLVM dll" )] -[assembly: AssemblyConfiguration( "" )] -[assembly: AssemblyCompany( "Microsoft .NET Foundation" )] -[assembly: AssemblyProduct( "Llvm.NET" )] -[assembly: AssemblyCopyright( "Copyright © 2015" )] -[assembly: AssemblyTrademark( "" )] -[assembly: AssemblyCulture( "" )] - [assembly: CLSCompliant( false )] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible( false )] @@ -27,11 +14,11 @@ // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] // Assembly version info is generated into $(IntermediateOutputPath)\AssemblyVersionInfo.cs by the build system diff --git a/src/Llvm.NET/StaticState.cs b/src/Llvm.NET/StaticState.cs index cb624857d..726877466 100644 --- a/src/Llvm.NET/StaticState.cs +++ b/src/Llvm.NET/StaticState.cs @@ -9,20 +9,28 @@ public enum TargetRegistrations { /// Register nothing None = 0x00, + /// Register the Target class Target = 0x01, + /// Register the Target info for the target TargetInfo = 0x02, + /// Register the target machine(s) for a target TargetMachine = 0x04, + /// Registers the assembly source code generator for a target AsmPrinter = 0x08, + /// Registers the Disassembler for a target Disassembler = 0x10, + /// Registers the assembly source parser for a target AsmParser = 0x20, + /// Registers all the code generation components CodeGen = Target | TargetInfo | TargetMachine, + /// Registers all components All = CodeGen | AsmPrinter | Disassembler | AsmParser } @@ -33,7 +41,9 @@ public static class StaticState public static void ParseCommandLineOptions( string[ ] args, string overview ) { if( args == null ) + { throw new ArgumentNullException( nameof( args ) ); + } NativeMethods.ParseCommandLineOptions( args.Length, args, overview ); } @@ -44,48 +54,62 @@ public static void InitializeOptimization() } // basic pattern to follow for any new targets in the future - //public static void RegisterXXX( TargetRegistrations registrations = TargetRegistration.All ) - //{ - // if( registrations.HasFlag( TargetRegistrations.Target ) ) - // LLVMNative.InitializeXXXTarget( ); + /* + public static void RegisterXXX( TargetRegistrations registrations = TargetRegistration.All ) + { + if( registrations.HasFlag( TargetRegistrations.Target ) ) + LLVMNative.InitializeXXXTarget( ); - // if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) - // LLVMNative.InitializeXXXTargetInfo( ); + if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + LLVMNative.InitializeXXXTargetInfo( ); - // if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) - // LLVMNative.InitializeXXXTargetMC( ); + if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + LLVMNative.InitializeXXXTargetMC( ); - // if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) - // LLVMNative.InitializeXXXAsmPrinter( ); + if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + LLVMNative.InitializeXXXAsmPrinter( ); - // if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) - // LLVMNative.InitializeXXXDisassembler( ); + if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + LLVMNative.InitializeXXXDisassembler( ); - // if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) - // LLVMNative.InitializeXXXAsmParser( ); - //} + if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + LLVMNative.InitializeXXXAsmParser( ); + } + */ /// Registers components for all available targets /// Flags indicating which components to register/enable public static void RegisterAll( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeAllTargets( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeAllTargetInfos( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeAllTargetMCs( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeAllAsmPrinters( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeAllDisassemblers( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeAllAsmParsers( ); + } } /// Registers components for the target representing the system the calling process is running on @@ -93,22 +117,32 @@ public static void RegisterAll( TargetRegistrations registrations = TargetRegist public static void RegisterNative( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeNativeTarget( ); + } + /* Not supported on this platform //if( registrations.HasFlag( TargetRegistration.TargetInfo ) ) // LLVMNative.InitializeNativeTargetInfo( ); //if( registrations.HasFlag( TargetRegistration.TargetMachine ) ) // LLVMNative.InitializeNativeTargetMC( ); + */ if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeNativeAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeNativeDisassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeNativeAsmParser( ); + } } /// Registers components for ARM AArch64 target(s) @@ -116,22 +150,34 @@ public static void RegisterNative( TargetRegistrations registrations = TargetReg public static void RegisterAArch64( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeAArch64Target( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeAArch64TargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeAArch64TargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeAArch64AsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeAArch64Disassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeAArch64AsmParser( ); + } } /// Registers components for ARM 32bit and 16bit thumb targets @@ -139,22 +185,34 @@ public static void RegisterAArch64( TargetRegistrations registrations = TargetRe public static void RegisterARM( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeARMTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeARMTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeARMTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeARMAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeARMDisassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeARMAsmParser( ); + } } /// Registers components for the Hexagon CPU @@ -162,22 +220,34 @@ public static void RegisterARM( TargetRegistrations registrations = TargetRegist public static void RegisterHexagon( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeHexagonTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeHexagonTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeHexagonTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeHexagonAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeHexagonDisassembler( ); + } + /* //if( registrations.HasFlag( TargetRegistration.AsmParser ) ) // LLVMNative.InitializeHexagonAsmParser( ); + */ } /// Registers components for MIPS targets @@ -185,22 +255,34 @@ public static void RegisterHexagon( TargetRegistrations registrations = TargetRe public static void RegisterMips( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeMipsTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeMipsTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeMipsTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeMipsAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeMipsDisassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeMipsAsmParser( ); + } } /// Registers components for MSP430 targets @@ -208,22 +290,32 @@ public static void RegisterMips( TargetRegistrations registrations = TargetRegis public static void RegisterMSP430( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeMSP430Target( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeMSP430TargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeMSP430TargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeMSP430AsmPrinter( ); + } + /* //if( registrations.HasFlag( TargetRegistration.Disassembler ) ) // LLVMNative.InitializeMSP430Disassembler( ); //if( registrations.HasFlag( TargetRegistration.AsmParser ) ) // LLVMNative.InitializeMSP430AsmParser( ); + */ } /// Registers components for the NVPTX targets @@ -231,22 +323,32 @@ public static void RegisterMSP430( TargetRegistrations registrations = TargetReg public static void RegisterNVPTX( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeNVPTXTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeNVPTXTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeNVPTXTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeNVPTXAsmPrinter( ); + } + /* //if( registrations.HasFlag( TargetRegistration.Disassembler ) ) // LLVMNative.InitializeNVPTXDisassembler( ); //if( registrations.HasFlag( TargetRegistration.AsmParser ) ) // LLVMNative.InitializeNVPTXAsmParser( ); + */ } /// Registers components for the PowerPC targets @@ -254,22 +356,34 @@ public static void RegisterNVPTX( TargetRegistrations registrations = TargetRegi public static void RegisterPowerPC( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializePowerPCTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializePowerPCTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializePowerPCTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializePowerPCAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializePowerPCDisassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializePowerPCAsmParser( ); + } } /// Registers components for AMDGPU targets @@ -277,22 +391,34 @@ public static void RegisterPowerPC( TargetRegistrations registrations = TargetRe public static void RegisterAMDGPU( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeAMDGPUTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeAMDGPUTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeAMDGPUTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeAMDGPUAsmPrinter( ); + } + /* //if( registrations.HasFlag( TargetRegistration.Disassembler ) ) // LLVMNative.InitializeAMDGPUDisassembler( ); + */ if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeAMDGPUAsmParser( ); + } } /// Registers components for SPARC targets @@ -300,22 +426,34 @@ public static void RegisterAMDGPU( TargetRegistrations registrations = TargetReg public static void RegisterSparc( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeSparcTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeSparcTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeSparcTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeSparcAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeSparcDisassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeSparcAsmParser( ); + } } /// Registers components for SystemZ targets @@ -323,22 +461,34 @@ public static void RegisterSparc( TargetRegistrations registrations = TargetRegi public static void RegisterSystemZ( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeSystemZTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeSystemZTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeSystemZTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeSystemZAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeSystemZDisassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeSystemZAsmParser( ); + } } /// Registers components for X86 targets @@ -346,22 +496,34 @@ public static void RegisterSystemZ( TargetRegistrations registrations = TargetRe public static void RegisterX86( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeX86Target( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeX86TargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeX86TargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeX86AsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeX86Disassembler( ); + } if( registrations.HasFlag( TargetRegistrations.AsmParser ) ) + { NativeMethods.InitializeX86AsmParser( ); + } } /// Registers components for XCore targets @@ -369,22 +531,34 @@ public static void RegisterX86( TargetRegistrations registrations = TargetRegist public static void RegisterXCore( TargetRegistrations registrations = TargetRegistrations.All ) { if( registrations.HasFlag( TargetRegistrations.Target ) ) + { NativeMethods.InitializeXCoreTarget( ); + } if( registrations.HasFlag( TargetRegistrations.TargetInfo ) ) + { NativeMethods.InitializeXCoreTargetInfo( ); + } if( registrations.HasFlag( TargetRegistrations.TargetMachine ) ) + { NativeMethods.InitializeXCoreTargetMC( ); + } if( registrations.HasFlag( TargetRegistrations.AsmPrinter ) ) + { NativeMethods.InitializeXCoreAsmPrinter( ); + } if( registrations.HasFlag( TargetRegistrations.Disassembler ) ) + { NativeMethods.InitializeXCoreDisassembler( ); + } + /* //if( registrations.HasFlag( TargetRegistration.AsmParser ) ) // LLVMNative.InitializeXCoreAsmParser( ); + */ } } } diff --git a/src/Llvm.NET/Target.cs b/src/Llvm.NET/Target.cs index 7e0958390..57aaec65d 100644 --- a/src/Llvm.NET/Target.cs +++ b/src/Llvm.NET/Target.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using Llvm.NET.Native; namespace Llvm.NET @@ -9,19 +8,19 @@ namespace Llvm.NET public class Target { /// Name of this target - public string Name => Marshal.PtrToStringAnsi( NativeMethods.GetTargetName( TargetHandle ) ); + public string Name => NativeMethods.GetTargetName( TargetHandle ); /// Description of this target - public string Description => NativeMethods.NormalizeLineEndings( NativeMethods.GetTargetDescription( TargetHandle ) ); + public string Description => NativeMethods.GetTargetDescription( TargetHandle ); /// Flag indicating if this target has JIT support - public bool HasJIT => 0 != NativeMethods.TargetHasJIT( TargetHandle ).Value; + public bool HasJIT => NativeMethods.TargetHasJIT( TargetHandle ); /// Flag indicating if this target has a TargetMachine initialized - public bool HasTargetMachine => 0 != NativeMethods.TargetHasTargetMachine( TargetHandle ).Value; + public bool HasTargetMachine => NativeMethods.TargetHasTargetMachine( TargetHandle ); /// Flag indicating if this target has an Assembly code generating back end initialized - public bool HasAsmBackEnd => 0 != NativeMethods.TargetHasAsmBackend( TargetHandle ).Value; + public bool HasAsmBackEnd => NativeMethods.TargetHasAsmBackend( TargetHandle ); /// Creates a for the target and specified parameters /// Context to use for LLVM objects created by this machine @@ -71,12 +70,9 @@ public static IEnumerable AvailableTargets /// Target for the given triple public static Target FromTriple( string targetTriple ) { - LLVMTargetRef targetHandle; - IntPtr msgPtr; - if( 0 != NativeMethods.GetTargetFromTriple( targetTriple, out targetHandle, out msgPtr ).Value ) + if( !NativeMethods.GetTargetFromTriple( targetTriple, out LLVMTargetRef targetHandle, out string errorMessag ) ) { - var msg = NativeMethods.MarshalMsg( msgPtr ); - throw new InternalCodeGeneratorException( msg ); + throw new InternalCodeGeneratorException( errorMessag ); } return FromHandle( targetHandle ); @@ -93,9 +89,10 @@ internal static Target FromHandle( LLVMTargetRef targetHandle ) { lock( TargetMap ) { - Target retVal; - if( TargetMap.TryGetValue( targetHandle.Pointer, out retVal ) ) + if( TargetMap.TryGetValue( targetHandle.Pointer, out Target retVal ) ) + { return retVal; + } retVal = new Target( targetHandle ); TargetMap.Add( targetHandle.Pointer, retVal ); @@ -103,6 +100,6 @@ internal static Target FromHandle( LLVMTargetRef targetHandle ) } } - static Dictionary TargetMap = new Dictionary( ); + private static readonly Dictionary TargetMap = new Dictionary(); } } diff --git a/src/Llvm.NET/TargetMachine.cs b/src/Llvm.NET/TargetMachine.cs index 820464843..5331832da 100644 --- a/src/Llvm.NET/TargetMachine.cs +++ b/src/Llvm.NET/TargetMachine.cs @@ -4,19 +4,34 @@ namespace Llvm.NET { /// Target specific code generation information - public class TargetMachine : IDisposable + public sealed class TargetMachine + : IDisposable { + ~TargetMachine( ) + { + // Do not change this code. Put cleanup code in Dispose(bool disposing). + DisposeTargetMachine( false ); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose( ) + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) + DisposeTargetMachine( true ); + GC.SuppressFinalize( this ); + } + /// Retrieves the Target that owns this public Target Target => Target.FromHandle( NativeMethods.GetTargetMachineTarget( TargetMachineHandle ) ); /// Target triple describing this machine - public string Triple => NativeMethods.MarshalMsg( NativeMethods.GetTargetMachineTriple( TargetMachineHandle ) ); + public string Triple => NativeMethods.GetTargetMachineTriple( TargetMachineHandle ); /// CPU Type for this machine - public string Cpu => NativeMethods.MarshalMsg( NativeMethods.GetTargetMachineCPU( TargetMachineHandle ) ); + public string Cpu => NativeMethods.GetTargetMachineCPU( TargetMachineHandle ); /// CPU specific features for this machine - public string Features => NativeMethods.MarshalMsg( NativeMethods.GetTargetMachineFeatureString( TargetMachineHandle ) ); + public string Features => NativeMethods.GetTargetMachineFeatureString( TargetMachineHandle ); /// Gets Layout information for this machine public DataLayout TargetData @@ -25,7 +40,9 @@ public DataLayout TargetData { var handle = NativeMethods.CreateTargetDataLayout( TargetMachineHandle ); if( handle.Pointer == IntPtr.Zero ) + { return null; + } return DataLayout.FromHandle( Context, handle, isDisposable: false ); } @@ -38,24 +55,28 @@ public DataLayout TargetData public void EmitToFile( NativeModule module, string path, CodeGenFileType fileType ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( string.IsNullOrWhiteSpace( path ) ) + { throw new ArgumentException( "Null or empty paths are not valid", nameof( path ) ); + } if( module.TargetTriple != null && Triple != module.TargetTriple ) + { throw new ArgumentException( "Triple specified for the module doesn't match target machine", nameof( module ) ); + } - IntPtr errMsg; var status = NativeMethods.TargetMachineEmitToFile( TargetMachineHandle - , module.ModuleHandle - , path - , ( LLVMCodeGenFileType )fileType - , out errMsg - ); + , module.ModuleHandle + , path + , ( LLVMCodeGenFileType )fileType + , out string errTxt + ); if( status.Failed ) { - var errTxt = NativeMethods.MarshalMsg( errMsg ); throw new InternalCodeGeneratorException( errTxt ); } } @@ -63,23 +84,24 @@ public void EmitToFile( NativeModule module, string path, CodeGenFileType fileTy public MemoryBuffer EmitToBuffer( NativeModule module, CodeGenFileType fileType ) { if( module == null ) + { throw new ArgumentNullException( nameof( module ) ); + } if( module.TargetTriple != null && Triple != module.TargetTriple ) + { throw new ArgumentException( "Triple specified for the module doesn't match target machine", nameof( module ) ); + } - IntPtr errMsg; - LLVMMemoryBufferRef bufferHandle; var status = NativeMethods.TargetMachineEmitToMemoryBuffer( TargetMachineHandle , module.ModuleHandle , ( LLVMCodeGenFileType )fileType - , out errMsg - , out bufferHandle + , out string errTxt + , out LLVMMemoryBufferRef bufferHandle ); if( status.Failed ) { - var errTxt = NativeMethods.MarshalMsg( errMsg ); throw new InternalCodeGeneratorException( errTxt ); } @@ -94,39 +116,23 @@ internal TargetMachine( Context context, LLVMTargetMachineRef targetMachineHandl TargetMachineHandle = targetMachineHandle; Context = context; } - - #region IDisposable Support + private bool IsDisposed => TargetMachineHandle.Pointer == IntPtr.Zero; - protected virtual void Dispose( bool disposing ) + private void DisposeTargetMachine( bool disposing ) { if( !IsDisposed ) { - // no managed state to dispose here - //if( disposing ) - //{ - // // dispose managed state (managed objects). - //} + if( disposing ) + { + // dispose any managed resources + } + NativeMethods.DisposeTargetMachine( TargetMachineHandle ); TargetMachineHandle = default( LLVMTargetMachineRef ); } } - ~TargetMachine( ) - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose( false ); - } - - // This code added to correctly implement the disposable pattern. - public void Dispose( ) - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose( true ); - GC.SuppressFinalize(this); - } - #endregion - internal LLVMTargetMachineRef TargetMachineHandle { get; private set; } } } diff --git a/src/Llvm.NET/Triple.cs b/src/Llvm.NET/Triple.cs index 0565090ea..b0d1bc7e1 100644 --- a/src/Llvm.NET/Triple.cs +++ b/src/Llvm.NET/Triple.cs @@ -1,14 +1,14 @@ -using Llvm.NET.Native; -using System; +using System; +using Llvm.NET.Native; namespace Llvm.NET { /// Triple to describe a target /// /// The term 'Triple' is a bit of a misnomer. At some point in the past it - /// actually consisted of only three parts, but that has changed over the - /// years without the name itself changing. The triple is normally represented - /// as a string of 4 components delimited by '-'. Some of the components have + /// actually consisted of only three parts, but that has changed over the years + /// without the name itself changing. The triple is normally represented as a + /// string of 4 components delimited by '-'. Some of the components have /// sub components as part of the content. The canonical form of a triple is: /// {Architecture}{SubArchitecture}-{Vendor}-{OS}-{Environment}{ObjectFormat} /// @@ -38,27 +38,32 @@ public Triple( string tripleTxt ) TripleHandle = NativeMethods.ParseTriple( tripleTxt ); } + ~Triple( ) + { + TripleHandle.Close( ); + } + /// Retrieves the final string form of the triple /// Normalized Triple string - public override string ToString( ) => NativeMethods.MarshalMsg( NativeMethods.TripleAsString( TripleHandle, true ) ); + public override string ToString( ) => NativeMethods.TripleAsString( TripleHandle, true ); /// Architecture of the triple public TripleArchType ArchitectureType => ( TripleArchType )NativeMethods.TripleGetArchType( TripleHandle ); /// Sub Architecture type - public TripleSubArchType SubArchitecture => ( TripleSubArchType)NativeMethods.TripleGetSubArchType( TripleHandle ); + public TripleSubArchType SubArchitecture => ( TripleSubArchType )NativeMethods.TripleGetSubArchType( TripleHandle ); /// Vendor component of the triple - public TripleVendorType VendorType => ( TripleVendorType ) NativeMethods.TripleGetVendorType( TripleHandle ); + public TripleVendorType VendorType => ( TripleVendorType )NativeMethods.TripleGetVendorType( TripleHandle ); /// OS Type for the triple - public TripleOSType OSType => ( TripleOSType ) NativeMethods.TripleGetOsType( TripleHandle ); + public TripleOSType OSType => ( TripleOSType )NativeMethods.TripleGetOsType( TripleHandle ); /// Environment type for the triple - public TripleEnvironmentType EnvironmentType => ( TripleEnvironmentType ) NativeMethods.TripleGetEnvironmentType( TripleHandle ); + public TripleEnvironmentType EnvironmentType => ( TripleEnvironmentType )NativeMethods.TripleGetEnvironmentType( TripleHandle ); /// Object format type for the triple - public TripleObjectFormatType ObjectFormatType => ( TripleObjectFormatType ) NativeMethods.TripleGetObjectFormatType( TripleHandle ); + public TripleObjectFormatType ObjectFormatType => ( TripleObjectFormatType )NativeMethods.TripleGetObjectFormatType( TripleHandle ); /// Retrieves the canonical name for an architecture type /// Architecture type @@ -70,38 +75,37 @@ public Triple( string tripleTxt ) /// such triple components used in a normalized triple. /// public static string GetCanonicalName( TripleArchType archType ) - => NativeMethods.MarshalMsg( NativeMethods.TripleGetArchTypeName( ( LLVMTripleArchType )archType ) ); + => NativeMethods.TripleGetArchTypeName( ( LLVMTripleArchType )archType ) ?? string.Empty; /// Retrieves the canonical name for an architecture sub type /// Architecture sub type /// String name for the architecture sub type public static string GetCanonicalName( TripleSubArchType subArchType ) - => NativeMethods.MarshalMsg( NativeMethods.TripleGetSubArchTypeName( ( LLVMTripleSubArchType )subArchType ) ); + => NativeMethods.TripleGetSubArchTypeName( ( LLVMTripleSubArchType )subArchType ) ?? string.Empty; /// Retrieves the canonical name for the vendor component of a triple /// Vendor type /// String name for the vendor public static string GetCanonicalName( TripleVendorType vendorType ) - => NativeMethods.MarshalMsg( NativeMethods.TripleGetVendorTypeName( ( LLVMTripleVendorType )vendorType ) ); + => NativeMethods.TripleGetVendorTypeName( ( LLVMTripleVendorType )vendorType ) ?? string.Empty; /// Retrieves the canonical name for the OS component of a triple /// OS type /// String name for the OS public static string GetCanonicalName( TripleOSType osType ) - => NativeMethods.MarshalMsg( NativeMethods.TripleGetOsTypeName( ( LLVMTripleOSType )osType ) ); - + => NativeMethods.TripleGetOsTypeName( ( LLVMTripleOSType )osType ) ?? string.Empty; /// Retrieves the canonical name for the environment component of a triple /// Environment type /// String name for the environment component public static string GetCanonicalName( TripleEnvironmentType envType ) - => NativeMethods.MarshalMsg( NativeMethods.TripleGetEnvironmentTypeName( (LLVMTripleEnvironmentType)envType ) ); + => NativeMethods.TripleGetEnvironmentTypeName( ( LLVMTripleEnvironmentType )envType ) ?? string.Empty; /// Retrieves the canonical name for the object component of a triple /// Object type /// String name for the object component public static string GetCanonicalName( TripleObjectFormatType objFormatType ) - => NativeMethods.MarshalMsg( NativeMethods.TripleGetObjectFormatTypeName( ( LLVMTripleObjectFormatType )objFormatType ) ); + => NativeMethods.TripleGetObjectFormatTypeName( ( LLVMTripleObjectFormatType )objFormatType ) ?? string.Empty; /// Equality test for a triple /// triple to compare this triple to @@ -109,10 +113,14 @@ public static string GetCanonicalName( TripleObjectFormatType objFormatType ) public bool Equals( Triple other ) { if( other == null ) + { return false; + } if( ReferenceEquals( this, other ) ) + { return true; + } return NativeMethods.TripleOpEqual( TripleHandle, other.TripleHandle ); } @@ -136,7 +144,7 @@ public override int GetHashCode( ) /// Normalized string public static string Normalize( string unNormalizedTriple ) { - return NativeMethods.MarshalMsg( NativeMethods.NormalizeTriple( unNormalizedTriple ) ); + return NativeMethods.NormalizeTriple( unNormalizedTriple ); } /// Gets the default for a given and @@ -148,61 +156,69 @@ public static TripleObjectFormatType GetDefaultObjectFormat( TripleArchType arch switch( arch ) { case TripleArchType.UnknownArch: - case TripleArchType.aarch64: - case TripleArchType.arm: - case TripleArchType.thumb: - case TripleArchType.x86: - case TripleArchType.x86_64: + case TripleArchType.Aarch64: + case TripleArchType.Arm: + case TripleArchType.Thumb: + case TripleArchType.X86: + case TripleArchType.X86_64: if( IsOsDarwin( os ) ) + { return TripleObjectFormatType.MachO; - else if( os == TripleOSType.Win32 ) + } + + if( os == TripleOSType.Win32 ) + { return TripleObjectFormatType.COFF; + } + return TripleObjectFormatType.ELF; - case TripleArchType.aarch64_be: - case TripleArchType.amdgcn: - case TripleArchType.amdil: - case TripleArchType.amdil64: - case TripleArchType.armeb: - case TripleArchType.avr: - case TripleArchType.bpfeb: - case TripleArchType.bpfel: - case TripleArchType.hexagon: - case TripleArchType.lanai: - case TripleArchType.hsail: - case TripleArchType.hsail64: - case TripleArchType.kalimba: - case TripleArchType.le32: - case TripleArchType.le64: - case TripleArchType.mips: - case TripleArchType.mips64: - case TripleArchType.mips64el: - case TripleArchType.mipsel: - case TripleArchType.msp430: - case TripleArchType.nvptx: - case TripleArchType.nvptx64: - case TripleArchType.ppc64le: - case TripleArchType.r600: - case TripleArchType.renderscript32: - case TripleArchType.renderscript64: - case TripleArchType.shave: - case TripleArchType.sparc: - case TripleArchType.sparcel: - case TripleArchType.sparcv9: - case TripleArchType.spir: - case TripleArchType.spir64: - case TripleArchType.systemz: - case TripleArchType.tce: - case TripleArchType.thumbeb: - case TripleArchType.wasm32: - case TripleArchType.wasm64: - case TripleArchType.xcore: + case TripleArchType.Aarch64_be: + case TripleArchType.AMDGCN: + case TripleArchType.Amdil: + case TripleArchType.Amdil64: + case TripleArchType.Armeb: + case TripleArchType.Avr: + case TripleArchType.BPFeb: + case TripleArchType.BPFel: + case TripleArchType.Hexagon: + case TripleArchType.Lanai: + case TripleArchType.Hsail: + case TripleArchType.Hsail64: + case TripleArchType.Kalimba: + case TripleArchType.Le32: + case TripleArchType.Le64: + case TripleArchType.MIPS: + case TripleArchType.MIPS64: + case TripleArchType.MIPS64el: + case TripleArchType.MIPSel: + case TripleArchType.MSP430: + case TripleArchType.Nvptx: + case TripleArchType.Nvptx64: + case TripleArchType.PPC64le: + case TripleArchType.R600: + case TripleArchType.Renderscript32: + case TripleArchType.Renderscript64: + case TripleArchType.Shave: + case TripleArchType.Sparc: + case TripleArchType.Sparcel: + case TripleArchType.Sparcv9: + case TripleArchType.Spir: + case TripleArchType.Spir64: + case TripleArchType.SystemZ: + case TripleArchType.TCE: + case TripleArchType.Thumbeb: + case TripleArchType.Wasm32: + case TripleArchType.Wasm64: + case TripleArchType.Xcore: return TripleObjectFormatType.ELF; - case TripleArchType.ppc: - case TripleArchType.ppc64: + case TripleArchType.PPC: + case TripleArchType.PPC64: if( IsOsDarwin( os ) ) + { return TripleObjectFormatType.MachO; + } return TripleObjectFormatType.ELF; @@ -217,32 +233,33 @@ public static TripleObjectFormatType GetDefaultObjectFormat( TripleArchType arch /// Canonical /// /// Some architectures, particularly ARM variants, have multiple sub-architecture types that - /// have a canonical form (i.e. Arch=; SubArch=; - /// has the Canonical Arch of ). This method retrieves the canonical Arch + /// have a canonical form (i.e. Arch=; SubArch=; + /// has the Canonical Arch of ). This method retrieves the canonical Arch /// for a given architecture,SubArchitecture pair. /// public static TripleArchType GetCanonicalArchForSubArch( TripleArchType archType, TripleSubArchType subArch ) { switch( archType ) { - case TripleArchType.kalimba: + case TripleArchType.Kalimba: switch( subArch ) { case TripleSubArchType.NoSubArch: case TripleSubArchType.KalimbaSubArch_v3: case TripleSubArchType.KalimbaSubArch_v4: case TripleSubArchType.KalimbaSubArch_v5: - return TripleArchType.kalimba; + return TripleArchType.Kalimba; default: return TripleArchType.UnknownArch; } - case TripleArchType.arm: - case TripleArchType.armeb: + + case TripleArchType.Arm: + case TripleArchType.Armeb: switch( subArch ) { case TripleSubArchType.ARMSubArch_v6m: - return archType == TripleArchType.armeb ? TripleArchType.thumbeb : TripleArchType.thumb; + return archType == TripleArchType.Armeb ? TripleArchType.Thumbeb : TripleArchType.Thumb; case TripleSubArchType.KalimbaSubArch_v3: case TripleSubArchType.KalimbaSubArch_v4: case TripleSubArchType.KalimbaSubArch_v5: @@ -251,6 +268,7 @@ public static TripleArchType GetCanonicalArchForSubArch( TripleArchType archType default: return archType; } + default: return archType; } @@ -272,11 +290,6 @@ private static bool IsOsDarwin( TripleOSType osType ) } } - ~Triple() - { - TripleHandle.Close( ); - } - - Llvm.NET.Native.TripleHandle TripleHandle; + private LLVMTripleRef TripleHandle; } } diff --git a/src/Llvm.NET/Types/ArrayType.cs b/src/Llvm.NET/Types/ArrayType.cs index 7c52f54d6..f8f4d02d0 100644 --- a/src/Llvm.NET/Types/ArrayType.cs +++ b/src/Llvm.NET/Types/ArrayType.cs @@ -26,7 +26,9 @@ internal ArrayType( LLVMTypeRef typeRef ) : base( typeRef ) { if( NativeMethods.GetTypeKind( typeRef ) != LLVMTypeKind.LLVMArrayTypeKind ) + { throw new ArgumentException( "Array type reference expected", nameof( typeRef ) ); + } } } } diff --git a/src/Llvm.NET/Types/FunctionType.cs b/src/Llvm.NET/Types/FunctionType.cs index 296f99772..e36f4d221 100644 --- a/src/Llvm.NET/Types/FunctionType.cs +++ b/src/Llvm.NET/Types/FunctionType.cs @@ -10,7 +10,7 @@ public interface IFunctionType { /// Flag to indicate if this signature is for a variadic function bool IsVarArg { get; } - + /// Return type of the function ITypeRef ReturnType { get; } @@ -39,9 +39,11 @@ public IReadOnlyList ParameterTypes { get { - var paramCount = NativeMethods.CountParamTypes( TypeHandle_ ); + uint paramCount = NativeMethods.CountParamTypes( TypeHandle_ ); if( paramCount == 0 ) + { return new List().AsReadOnly(); + } var paramTypes = new LLVMTypeRef[ paramCount ]; NativeMethods.GetParamTypes( TypeHandle_, out paramTypes[ 0 ] ); diff --git a/src/Llvm.NET/Types/ITypeRef.cs b/src/Llvm.NET/Types/ITypeRef.cs index 3a7fa1fee..2e9d52785 100644 --- a/src/Llvm.NET/Types/ITypeRef.cs +++ b/src/Llvm.NET/Types/ITypeRef.cs @@ -1,19 +1,20 @@ -using Llvm.NET.Values; -using System; +using System; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; +using Llvm.NET.Values; namespace Llvm.NET.Types { /// Interface for a Type in LLVM - public interface ITypeRef + public interface ITypeRef : IExtensiblePropertyContainer { /// LibLLVM handle for the type - IntPtr TypeHandle { get; } + IntPtr TypeHandle { get; } // TODO: move this to an internal interface so that low level internals not exposed in public API /// Flag to indicate if the type is sized bool IsSized { get; } - + /// LLVM Type kind for this type TypeKind Kind { get; } @@ -48,7 +49,7 @@ public interface ITypeRef Context Context { get; } /// Integer bit width of this type or 0 for non integer types - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "integer" )] + [SuppressMessage( "Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", Justification = "Value is the bitwidth of an integer, name is appropriate" )] uint IntegerBitWidth { get; } /// Gets a null value (e.g. all bits == 0 ) for the type @@ -56,7 +57,7 @@ public interface ITypeRef /// This is a getter function instead of a property as it can throw exceptions /// for types that don't support such a thing (i.e. void ) /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate" )] + [SuppressMessage( "Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "See comment remarks" )] Constant GetNullValue( ); /// Array type factory for an array with elements of this type diff --git a/src/Llvm.NET/Types/PointerType.cs b/src/Llvm.NET/Types/PointerType.cs index 6ddc10ff9..363e9e393 100644 --- a/src/Llvm.NET/Types/PointerType.cs +++ b/src/Llvm.NET/Types/PointerType.cs @@ -23,7 +23,9 @@ internal PointerType( LLVMTypeRef typeRef ) : base( typeRef ) { if( NativeMethods.GetTypeKind( typeRef ) != LLVMTypeKind.LLVMPointerTypeKind ) + { throw new ArgumentException( "Pointer type reference expected", nameof( typeRef ) ); + } } } } diff --git a/src/Llvm.NET/Types/SequenceType.cs b/src/Llvm.NET/Types/SequenceType.cs index 4010c41cd..f0b22c057 100644 --- a/src/Llvm.NET/Types/SequenceType.cs +++ b/src/Llvm.NET/Types/SequenceType.cs @@ -26,7 +26,9 @@ public ITypeRef ElementType { var typeRef = NativeMethods.GetElementType( this.GetTypeRef() ); if( typeRef.Pointer == IntPtr.Zero ) + { return null; + } return FromHandle( typeRef ); } @@ -36,7 +38,9 @@ internal SequenceType( LLVMTypeRef typeRef ) : base( typeRef ) { if( !IsSequenceTypeRef( typeRef ) ) + { throw new ArgumentException( "Expected a sequence type", nameof( typeRef ) ); + } } internal static bool IsSequenceTypeRef( LLVMTypeRef typeRef ) diff --git a/src/Llvm.NET/Types/StructType.cs b/src/Llvm.NET/Types/StructType.cs index e513c6fb6..e5cb30d44 100644 --- a/src/Llvm.NET/Types/StructType.cs +++ b/src/Llvm.NET/Types/StructType.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using Llvm.NET.Native; namespace Llvm.NET.Types @@ -47,22 +46,19 @@ public void SetBody( bool packed, params ITypeRef[ ] elements ) // To interop correctly, we need to have an array of at least size one. if ( argsLength == 0 ) + { llvmArgs = new LLVMTypeRef[ 1 ]; + } NativeMethods.StructSetBody( TypeHandle_, out llvmArgs[ 0 ], argsLength, packed ); } - public string Name - { - get - { - var ptr = NativeMethods.GetStructName( TypeHandle_ ); - return Marshal.PtrToStringAnsi( ptr ); - } - } + public string Name => NativeMethods.GetStructName( TypeHandle_ ); public bool IsOpaque => NativeMethods.IsOpaqueStruct( TypeHandle_ ); + public bool IsPacked => NativeMethods.IsPackedStruct( TypeHandle_ ); + public IReadOnlyList Members { get diff --git a/src/Llvm.NET/Types/TypeRef.cs b/src/Llvm.NET/Types/TypeRef.cs index a7e438391..e9e4e8c91 100644 --- a/src/Llvm.NET/Types/TypeRef.cs +++ b/src/Llvm.NET/Types/TypeRef.cs @@ -1,11 +1,12 @@ using System; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; using Llvm.NET.Values; namespace Llvm.NET.Types { /// LLVM Type - internal class TypeRef + internal class TypeRef : ITypeRef { public IntPtr TypeHandle => TypeHandle_.Pointer; @@ -16,7 +17,9 @@ public bool IsSized get { if( Kind == TypeKind.Function ) + { return false; + } return NativeMethods.TypeIsSized( TypeHandle_ ); } @@ -24,6 +27,7 @@ public bool IsSized /// LLVM Type kind for this type public TypeKind Kind => ( TypeKind )NativeMethods.GetTypeKind( TypeHandle_ ); + public bool IsInteger=> Kind == TypeKind.Integer; // Return true if value is 'float', a 32-bit IEEE fp type. @@ -79,7 +83,9 @@ public uint IntegerBitWidth get { if( Kind != TypeKind.Integer ) + { return 0; + } return NativeMethods.GetIntTypeWidth( TypeHandle_ ); } @@ -89,33 +95,6 @@ public uint IntegerBitWidth /// This is a getter function instead of a property as it can throw exceptions public Constant GetNullValue() => Constant.NullValueFor( this ); - /// Retrieves an expression that results in the size of the type - [Obsolete("Use TargetData layout information to compute size and create a constant from that")] - public Constant GetSizeOfExpression( int pointerSize ) - { - if( !IsSized - || Kind == TypeKind.Void - || Kind == TypeKind.Function - || ( Kind == TypeKind.Struct && ( NativeMethods.IsOpaqueStruct( TypeHandle_ ) ) ) - ) - { - return Context.CreateConstant( 0 ); - } - - var hSize = NativeMethods.SizeOf( TypeHandle_ ); - - // LLVM uses an expression to construct Sizeof, however it is hard coded to - // use an i64 as the type for the size, which isn't valid for 32 bit systems - var sizeOfBitWidth = NativeMethods.GetIntTypeWidth( NativeMethods.TypeOf( hSize ) ); - var hIntPtr = new LLVMTypeRef( Context.GetIntType( ( uint )pointerSize ).TypeHandle ); - if( sizeOfBitWidth > pointerSize ) - hSize = NativeMethods.ConstTrunc( hSize, hIntPtr ); - else if( sizeOfBitWidth < pointerSize ) - hSize = NativeMethods.ConstZExt( hSize, hIntPtr ); - - return Value.FromHandle( hSize ); - } - /// Array type factory for an array with elements of this type /// Number of elements in the array /// for the array @@ -131,30 +110,31 @@ public Constant GetSizeOfExpression( int pointerSize ) public IPointerType CreatePointerType( uint addressSpace ) { if( IsVoid ) + { throw new InvalidOperationException( "Cannot create pointer to void in LLVM, use i8* instead" ); + } return FromHandle( NativeMethods.PointerType( TypeHandle_, addressSpace ) ); } public bool TryGetExtendedPropertyValue( string id, out T value ) => ExtensibleProperties.TryGetExtendedPropertyValue( id, out value ); + public void AddExtendedPropertyValue( string id, object value ) => ExtensibleProperties.AddExtendedPropertyValue( id, value ); /// Builds a string representation for this type in LLVM assembly language form /// Formatted string for this type - public override string ToString( ) - { - var msgString = NativeMethods.PrintTypeToString( TypeHandle_ ); - return NativeMethods.MarshalMsg( msgString ); - } + public override string ToString( ) => NativeMethods.PrintTypeToString( TypeHandle_ ); internal TypeRef( LLVMTypeRef typeRef ) { TypeHandle_ = typeRef; if( typeRef.Pointer == IntPtr.Zero ) + { throw new ArgumentNullException( nameof( typeRef ) ); + } #if DEBUG - var ctx = Llvm.NET.Context.GetContextFor( typeRef ); + var ctx = Context.GetContextFor( typeRef ); ctx.AssertTypeNotInterned( typeRef ); #endif } @@ -163,10 +143,11 @@ internal TypeRef( LLVMTypeRef typeRef ) internal static T FromHandle( LLVMTypeRef typeRef ) where T : class, ITypeRef - { if( typeRef.Pointer == IntPtr.Zero ) + { return null; + } var ctx = Context.GetContextFor( typeRef ); return ( T )ctx.GetTypeFor( typeRef, StaticFactory ); @@ -174,7 +155,7 @@ internal static T FromHandle( LLVMTypeRef typeRef ) private static ITypeRef StaticFactory( LLVMTypeRef typeRef ) { - var kind = (TypeKind)NativeMethods.GetTypeKind( typeRef ); + var kind = ( TypeKind )NativeMethods.GetTypeKind( typeRef ); switch( kind ) { case TypeKind.Struct: @@ -210,7 +191,14 @@ private static ITypeRef StaticFactory( LLVMTypeRef typeRef ) } } - internal readonly LLVMTypeRef TypeHandle_; + // field required to allow use as an out param in constructor + [SuppressMessage( "StyleCop.CSharp.NamingRules" + , "SA1310:Field names must not contain underscore" + , Justification = "Trailing _ indicates code must not write to it directly" + ) + ] + protected LLVMTypeRef TypeHandle_ { get; } + private readonly ExtensiblePropertyContainer ExtensibleProperties = new ExtensiblePropertyContainer( ); } } diff --git a/src/Llvm.NET/Types/VectorType.cs b/src/Llvm.NET/Types/VectorType.cs index 98af71132..bbf58b6b7 100644 --- a/src/Llvm.NET/Types/VectorType.cs +++ b/src/Llvm.NET/Types/VectorType.cs @@ -19,7 +19,9 @@ internal VectorType( LLVMTypeRef typeRef ) : base( typeRef ) { if( NativeMethods.GetTypeKind( typeRef ) != LLVMTypeKind.LLVMVectorTypeKind ) + { throw new ArgumentException( "Vector type reference expected", nameof( typeRef ) ); + } } } } diff --git a/src/Llvm.NET/Values/Argument.cs b/src/Llvm.NET/Values/Argument.cs index 816b8f90e..0639b7f83 100644 --- a/src/Llvm.NET/Values/Argument.cs +++ b/src/Llvm.NET/Values/Argument.cs @@ -5,11 +5,10 @@ namespace Llvm.NET.Values /// An LLVM Value representing an Argument to a function public class Argument : Value - , IAttributeSetContainer { /// Function this argument belongs to public Function ContainingFunction => FromHandle( NativeMethods.GetParamParent( ValueHandle ) ); - + /// Zero based index of the argument public uint Index => NativeMethods.GetArgumentIndex( ValueHandle ); @@ -17,20 +16,15 @@ public class Argument /// Alignment value for this argument public Argument SetAlignment( uint value ) { - ContainingFunction.AddAttribute( FunctionAttributeIndex.Parameter0 + ( int ) Index - , new AttributeValue( Context, AttributeKind.Alignment, value ) - ); + ContainingFunction.AddAttributeAtIndex( FunctionAttributeIndex.Parameter0 + ( int )Index + , Context.CreateAttribute( AttributeKind.Alignment, value ) + ); return this; } - /// Attributes for this parameter - public AttributeSet Attributes + public IAttributeCollection Attributes { - get { return ContainingFunction.Attributes.ParameterAttributes( ( int )Index ); } - set - { - ContainingFunction.AddAttributes( FunctionAttributeIndex.Parameter0 + ( int )Index, value ); - } + get => new ValueAttributeCollection( ContainingFunction, FunctionAttributeIndex.Parameter0 + (int)Index ); } internal Argument( LLVMValueRef valueRef ) diff --git a/src/Llvm.NET/Values/AttributeBuilder.cs b/src/Llvm.NET/Values/AttributeBuilder.cs deleted file mode 100644 index 954819b89..000000000 --- a/src/Llvm.NET/Values/AttributeBuilder.cs +++ /dev/null @@ -1,252 +0,0 @@ -using System; -using Llvm.NET.Native; - -namespace Llvm.NET.Values -{ - /// Factory for building AttributeSets, which are otherwise immutable - /// - /// This class is used to build immutable instances. - /// - /// Manipulator methods of this class return the instance of the class. This allows use - /// in fluent style coding scenarios. (see: https://en.wikipedia.org/wiki/Fluent_interface ) - /// - /// - /// It is important to keep in mind that an AttributeBuilder is dimensionless, that is, - /// AttributeSet does not contain or store a value. - /// The index is applied only when creating the in - /// - /// - /// - public sealed class AttributeBuilder - : IDisposable - { - /// Creates a new empty instance - public AttributeBuilder( ) - { - BuilderHandle = NativeMethods.CreateAttributeBuilder( ); - } - - /// Creates a new with a given - /// to add to the builder after creating it - public AttributeBuilder( AttributeValue value ) - { - BuilderHandle = NativeMethods.CreateAttributeBuilder2( value.NativeAttribute ); - } - - /// Creates a new from a single index of an existing - /// to initialize the builder from - /// to take from - public AttributeBuilder( AttributeSet attributes, FunctionAttributeIndex index ) - { - if( attributes == null ) - throw new ArgumentNullException( nameof( attributes ) ); - - BuilderHandle = NativeMethods.CreateAttributeBuilder3( attributes.NativeAttributeSet, ( uint )index ); - } - - /// Destroys the underlying native builder - public void Dispose( ) - { - BuilderHandle.Dispose( ); - } - - /// Indicates if this Builder contains no attributes - public bool IsEmpty - { - get - { - if( BuilderHandle.IsClosed ) - return true; // don't throw an exception in a property getter method - - return !NativeMethods.AttributeBuilderHasTargetDependentAttrs( BuilderHandle ) - && !NativeMethods.AttributeBuilderHasTargetIndependentAttrs( BuilderHandle ); - } - } - - /// Adds a new boolean attribute to this builder - /// Kind of attribute to add - /// This builder for fluent style programming - public AttributeBuilder Add( AttributeKind kind ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - if( kind.RequiresIntValue( ) ) - throw new ArgumentException( "Attribute requires a value" ); - - NativeMethods.AttributeBuilderAddEnum( BuilderHandle, ( LLVMAttrKind )kind ); - return this; - } - - /// Adds an to a builder - /// Value to add to this builder - /// This builder for fluent style programming - public AttributeBuilder Add( AttributeValue value ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderAddAttribute( BuilderHandle, value.NativeAttribute ); - return this; - } - - /// Adds a target dependent string attribute to a builder - /// Name of the attribute - /// This builder for fluent style programming - public AttributeBuilder Add( string name ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - return Add( name, string.Empty ); - } - - /// Adds a target dependent attribute to the builder - /// Name of the attribute - /// Value of the attribute - /// This builder for fluent style programming - public AttributeBuilder Add( string name, string value ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderAddStringAttribute( BuilderHandle, name, value ); - return this; - } - - /// Removes a boolean attribute from the builder - /// Kind of attribute to remove - /// This builder for fluent style programming - public AttributeBuilder Remove( AttributeKind kind ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderRemoveEnum( BuilderHandle, ( LLVMAttrKind )kind ); - return this; - } - - /// Removes attributes specified in an - /// Attributes to remove - /// Index of attributes in to remove - /// - public AttributeBuilder Remove( AttributeSet attributes, FunctionAttributeIndex index ) - { - if( attributes == null ) - throw new ArgumentNullException( nameof( attributes ) ); - - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderRemoveAttributes( BuilderHandle, attributes.NativeAttributeSet, ( uint )index ); - return this; - } - - /// Removes a target dependent attribute from this builder - /// Name of the attribute to remove - /// This builder for fluent style programming - public AttributeBuilder Remove( string name ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderRemoveAttribute( BuilderHandle, name ); - return this; - } - - /// Merges the contents of another into this one - /// Other to merge into this one - /// This builder for fluent style programming - public AttributeBuilder Merge( AttributeBuilder other ) - { - if( other == null ) - throw new ArgumentNullException( nameof( other ) ); - - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderMerge( BuilderHandle, other.BuilderHandle ); - return this; - } - - /// Removes the attributes of another builder from this one - /// builder containing attributes to remove - /// This builder for fluent style programming - public AttributeBuilder Remove( AttributeBuilder other ) - { - if( other == null ) - throw new ArgumentNullException( nameof( other ) ); - - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - NativeMethods.AttributeBuilderRemoveBldr( BuilderHandle, other.BuilderHandle ); - return this; - } - - /// Checks if this builder overlaps the attributes in another builder - /// Other builder to check for overlap - /// if this builder overlaps - public bool Overlaps( AttributeBuilder other ) - { - if( other == null ) - throw new ArgumentNullException( nameof( other ) ); - - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - return NativeMethods.AttributeBuilderOverlaps( BuilderHandle, other.BuilderHandle ); - } - - /// Checks if this builder contains a given boolean attribute - /// Kind of attribute to test for - /// if this builder contains - public bool Contains( AttributeKind kind ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - return NativeMethods.AttributeBuilderContainsEnum( BuilderHandle, ( LLVMAttrKind )kind ); - } - - /// Checks if this builder contains a given target dependent attribute - /// Kind of attribute to test for - /// if this builder contains - public bool Contains( string name ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - return NativeMethods.AttributeBuilderContainsName( BuilderHandle, name ); - } - - /// Checks if the builder contains any of the attributes in a given - /// Attributes to check for - /// Index of to use - /// if any of the attributes in the specified index of exists in this builder - public bool HasAttributes( AttributeSet attributes, FunctionAttributeIndex index ) - { - if( attributes == null ) - throw new ArgumentNullException( nameof( attributes ) ); - - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - return NativeMethods.AttributeBuilderHasAttributes( BuilderHandle, attributes.NativeAttributeSet, ( uint )index ); - } - - /// Converts the contents of this builder to an immutable - /// Index for the attributes in the new AttributeSet - /// to use when building the resulting AttributeSet - /// New containing the attributes from this builder in the specified index - public AttributeSet ToAttributeSet( FunctionAttributeIndex index, Context context ) - { - if( BuilderHandle.IsClosed ) - throw new ObjectDisposedException( nameof( AttributeBuilder ) ); - - return new AttributeSet( context, index, this ); - } - - internal AttributeBuilderHandle BuilderHandle; - } -} diff --git a/src/Llvm.NET/Values/AttributeContainerMixins.cs b/src/Llvm.NET/Values/AttributeContainerMixins.cs new file mode 100644 index 000000000..6afcc88e5 --- /dev/null +++ b/src/Llvm.NET/Values/AttributeContainerMixins.cs @@ -0,0 +1,181 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Llvm.NET.Values +{ + // Provides a layer of simplicity and backwards compatibility for manipulating attributes on Values + public static class AttributesMixins + { + public static bool Contains( this IAttributeCollection self, AttributeKind kind ) + { + return self.Any( a => a.Kind == kind ); + } + + public static T AddAttributes( this T self, FunctionAttributeIndex index, params AttributeKind[ ] values ) + where T : class, IAttributeContainer + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + if( values != null ) + { + foreach( var kind in values ) + { + AttributeValue attrib = self.Context.CreateAttribute( kind ); + if( self is IAttributeAccessor container ) + { + container.AddAttributeAtIndex( index, attrib ); + } + else + { + self.Attributes[ index ].Add( attrib ); + } + } + } + + return self; + } + + public static T AddAttribute( this T self, FunctionAttributeIndex index, AttributeKind kind ) + where T : class, IAttributeContainer + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + AttributeValue attrib = self.Context.CreateAttribute( kind ); + if( self is IAttributeAccessor container ) + { + container.AddAttributeAtIndex( index, attrib ); + } + else + { + self.Attributes[ index ].Add( self.Context.CreateAttribute( kind ) ); + } + + return self; + } + + public static T AddAttribute( this T self, FunctionAttributeIndex index, AttributeValue attrib ) + where T : class, IAttributeContainer + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + if( self is IAttributeAccessor container ) + { + container.AddAttributeAtIndex( index, attrib ); + } + else + { + self.Attributes[ index ].Add( attrib ); + } + + return self; + } + + public static T AddAttributes( this T self, FunctionAttributeIndex index, params AttributeValue[ ] attributes ) + where T : class, IAttributeContainer + { + return AddAttributes( self, index, ( IEnumerable )attributes ); + } + + public static T AddAttributes( this T self, FunctionAttributeIndex index, IEnumerable attributes ) + where T : class, IAttributeContainer + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + if( attributes != null ) + { + foreach( var attrib in attributes ) + { + if( self is IAttributeAccessor container ) + { + container.AddAttributeAtIndex( index, attrib ); + } + else + { + self.Attributes[ index ].Add( attrib ); + } + } + } + + return self; + } + + public static T AddAttributes( this T self, FunctionAttributeIndex index, IAttributeDictionary attributes ) + where T : class, IAttributeContainer + { + if( attributes == null ) + { + return self; + } + + return AddAttributes( self, index, attributes[ index ] ); + } + + public static T RemoveAttribute( this T self, FunctionAttributeIndex index, AttributeKind kind ) + where T : class, IAttributeContainer + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + if( kind == AttributeKind.None ) + { + return self; + } + + if( self is IAttributeAccessor container ) + { + container.RemoveAttributeAtIndex( index, kind ); + } + else + { + IAttributeCollection attributes = self.Attributes[ index ]; + AttributeValue attrib = attributes.FirstOrDefault( a => a.Kind == kind ); + if( attrib != default( AttributeValue ) ) + { + attributes.Remove( attrib ); + } + } + + return self; + } + + public static T RemoveAttribute( this T self, FunctionAttributeIndex index, string name ) + where T : class, IAttributeContainer + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + if( self is IAttributeAccessor container ) + { + container.RemoveAttributeAtIndex( index, name ); + } + else + { + IAttributeCollection attributes = self.Attributes[ index ]; + AttributeValue attrib = attributes.FirstOrDefault( a => a.Name == name ); + if( attrib != default( AttributeValue ) ) + { + attributes.Remove( attrib ); + } + } + + return self; + } + } +} diff --git a/src/Llvm.NET/Values/AttributeKind.cs b/src/Llvm.NET/Values/AttributeKind.cs new file mode 100644 index 000000000..4c32df080 --- /dev/null +++ b/src/Llvm.NET/Values/AttributeKind.cs @@ -0,0 +1,517 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Llvm.NET.Native; + +namespace Llvm.NET.Values +{ + /// Enumeration for the known LLVM attributes + /// + /// It is important to note that the integer values of this enum + /// do NOT necessarily correlate to the attribute IDs. LLVM has + /// moved away from using an enum Flags model as the number of + /// attributes reached the limit of available bits. Thus, the + /// enum was dropped as of V5.0. Instead, strings are used to + /// identify attributes. However, for maximum compatibility and + /// ease of use for this library the enum is retained and the + /// provided attribute manipulation classes will map the enum + /// to the associated string. + /// Also note that as a reult of the changes in LLVM this + /// set of attributes is fluid and subject to change from version + /// to version. Thus, code using any attributes that have changed + /// or were removed will produce compile time errors. That is useful + /// and by design so that any changes in LLVM naming will break at + /// compile time instead of at runtime. + /// + public enum AttributeKind + { + None, + Alignment, + AllocSize, + AlwaysInline, + ArgMemOnly, + Builtin, + ByVal, + Cold, + Convergent, + Dereferenceable, + DereferenceableOrNull, + InAlloca, + InReg, + InaccessibleMemOnly, + InaccessibleMemOrArgMemOnly, + InlineHint, + JumpTable, + MinSize, + Naked, + Nest, + NoAlias, + NoBuiltin, + NoCapture, + NoDuplicate, + NoImplicitFloat, + NoInline, + NoRecurse, + NoRedZone, + NoReturn, + NoUnwind, + NonLazyBind, + NonNull, + OptimizeForSize, + OptimizeNone, + ReadNone, + ReadOnly, + Returned, + ReturnsTwice, + SExt, + SafeStack, + SanitizeAddress, + SanitizeMemory, + SanitizeThread, + Speculatable, + StackAlignment, + StackProtect, + StackProtectReq, + StackProtectStrong, + StructRet, + SwiftError, + SwiftSelf, + UWTable, + WriteOnly, + ZExt, + EndAttrKinds// always last + } + + /// Enumeration flags to indicate which attribute set index an attribute may apply to + [Flags] + public enum FunctionIndexKinds + { + /// Invalid attributes don't apply to any index + None = 0, + + /// The attribute is applicable to a function + Function = 1, + + /// The attribute is applicable to a function's return + Return = 2, + + /// The attribute is applicable to a function's parameter + Parameter = 4 + } + + /// Utility class to provide extension methods for validating usage of attribute kinds + public static class AttributeKindExtensions + { + public static string GetAttributeName( this AttributeKind kind ) + { + return KnownAttributeNames[ ( int )kind ]; + } + + public static bool RequiresIntValue( this AttributeKind kind ) + { + Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); + switch( kind ) + { + case AttributeKind.Alignment: + case AttributeKind.StackAlignment: + case AttributeKind.Dereferenceable: + case AttributeKind.DereferenceableOrNull: + return true; + + default: + return false; + } + } + + public static AttributeKind LookupId( uint id ) + { + if( AttribIdToKindMap.Value.TryGetValue( id, out AttributeKind retValue ) ) + { + return retValue; + } + + return AttributeKind.None; + } + + internal static uint GetEnumAttributeId( this AttributeKind kind ) + { + if( KindToAttribIdMap.Value.TryGetValue( kind, out uint retVal ) ) + { + return retVal; + } + + return 0; + } + + internal static bool CheckAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index, Value value ) + { + Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); + FunctionIndexKinds allowedindices = kind.GetAllowedIndexes( ); + switch( index ) + { + case FunctionAttributeIndex.Function: + if( !allowedindices.HasFlag( FunctionIndexKinds.Function ) ) + { + return false; + } + + break; + + case FunctionAttributeIndex.ReturnType: + if( !allowedindices.HasFlag( FunctionIndexKinds.Return ) ) + { + return false; + } + + break; + + // case FunctionAttributeIndex.Parameter0: + default: + { + if( value == null ) + { + throw new ArgumentNullException( nameof( value ) ); + } + + if( !allowedindices.HasFlag( FunctionIndexKinds.Parameter ) ) + { + return false; + } + + Function function; + switch( value ) + { + case Function f: + function = f; + break; + + case Instructions.Invoke inv: + function = inv.TargetFunction; + break; + + case Instructions.CallInstruction call: + function = call.TargetFunction; + break; + + case Argument arg: + function = arg.ContainingFunction; + if( index != FunctionAttributeIndex.Parameter0 + ( int )arg.Index ) + { + return false; + } + + break; + + default: + function = null; + break; + } + + int paramIndex = index - FunctionAttributeIndex.Parameter0; + if( paramIndex >= function.Parameters.Count ) + { + return false; + } + } + + break; + } + + return true; + } + + internal static void VerifyAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index, Value value ) + { + Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); + VerifyAttributeUsage( kind, index ); + + if( index >= FunctionAttributeIndex.Parameter0 ) + { + Function function; + switch( value ) + { + case Function f: + function = f; + break; + + case Instructions.Invoke inv: + function = inv.TargetFunction; + break; + + case Instructions.CallInstruction call: + function = call.TargetFunction; + break; + + case Argument arg: + function = arg.ContainingFunction; + if( index != FunctionAttributeIndex.Parameter0 + ( int )arg.Index ) + { + throw new ArgumentException( "Index for paramters must be the actual position of the argument" ); + } + + break; + + default: + function = null; + break; + } + + int paramIndex = index - FunctionAttributeIndex.Parameter0; + if( paramIndex > ( function.Parameters.Count - 1 ) ) + { + throw new ArgumentException( "Specified parameter index exceeds the number of parameters in the function", nameof( index ) ); + } + } + } + + internal static void VerifyAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index ) + { + Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); + FunctionIndexKinds allowedindices = kind.GetAllowedIndexes( ); + switch( index ) + { + case FunctionAttributeIndex.Function: + if( !allowedindices.HasFlag( FunctionIndexKinds.Function ) ) + { + throw new ArgumentException( "Attribute not allowed on functions", nameof( index ) ); + } + + break; + + case FunctionAttributeIndex.ReturnType: + if( !allowedindices.HasFlag( FunctionIndexKinds.Return ) ) + { + throw new ArgumentException( "Attribute not allowed on function Return", nameof( index ) ); + } + + break; + + // case FunctionAttributeIndex.Parameter0: + default: + if( !allowedindices.HasFlag( FunctionIndexKinds.Parameter ) ) + { + throw new ArgumentException( "Attribute not allowed on function parameter", nameof( index ) ); + } + + break; + } + } + + // To prevent native asserts or crashes - validates parameters before passing down to native code + internal static void VerifyAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index, ulong value ) + { + kind.VerifyAttributeUsage( index ); + kind.RangeCheckValue( value ); + } + + internal static void RangeCheckValue( this AttributeKind kind, ulong value ) + { + Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); + + // To prevent native asserts or crashes - validate parameters before passing down to native code + switch( kind ) + { + case AttributeKind.Alignment: + if( value > UInt32.MaxValue ) + { + throw new ArgumentOutOfRangeException( nameof( value ), "Expected a 32 bit value for alignment" ); + } + + break; + + case AttributeKind.StackAlignment: + if( value > UInt32.MaxValue ) + { + throw new ArgumentOutOfRangeException( nameof( value ), "Expected a 32 bit value for stack alignment" ); + } + + if( value != 0 && !IsPowerOfTwo( value ) ) + { + throw new ArgumentException( "Stack alignment value must be a power of 2", nameof( value ) ); + } + + break; + + case AttributeKind.Dereferenceable: + case AttributeKind.DereferenceableOrNull: + break; + + default: + throw new ArgumentException( $"Attribute '{kind}' does not support an argument", nameof( kind ) ); + } + } + + internal static FunctionIndexKinds GetAllowedIndexes( this AttributeKind kind ) + { + Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); + switch( kind ) + { + default: + return FunctionIndexKinds.None; + + case AttributeKind.ReadOnly: + case AttributeKind.WriteOnly: + case AttributeKind.ReadNone: + return FunctionIndexKinds.Function | FunctionIndexKinds.Parameter; + + case AttributeKind.ByVal: + case AttributeKind.InAlloca: + case AttributeKind.StructRet: + case AttributeKind.Nest: + case AttributeKind.NoCapture: + case AttributeKind.Returned: + case AttributeKind.SwiftSelf: + case AttributeKind.SwiftError: + return FunctionIndexKinds.Parameter; + + case AttributeKind.ZExt: + case AttributeKind.SExt: + case AttributeKind.InReg: + case AttributeKind.Alignment: + case AttributeKind.NoAlias: + case AttributeKind.NonNull: + case AttributeKind.Dereferenceable: + case AttributeKind.DereferenceableOrNull: + return FunctionIndexKinds.Parameter | FunctionIndexKinds.Return; + + case AttributeKind.NoReturn: + case AttributeKind.NoUnwind: + case AttributeKind.NoInline: + case AttributeKind.AlwaysInline: + case AttributeKind.OptimizeForSize: + case AttributeKind.StackProtect: + case AttributeKind.StackProtectReq: + case AttributeKind.StackProtectStrong: + case AttributeKind.SafeStack: + case AttributeKind.NoRedZone: + case AttributeKind.NoImplicitFloat: + case AttributeKind.Naked: + case AttributeKind.InlineHint: + case AttributeKind.StackAlignment: + case AttributeKind.UWTable: + case AttributeKind.NonLazyBind: + case AttributeKind.ReturnsTwice: + case AttributeKind.SanitizeAddress: + case AttributeKind.SanitizeThread: + case AttributeKind.SanitizeMemory: + case AttributeKind.MinSize: + case AttributeKind.NoDuplicate: + case AttributeKind.Builtin: + case AttributeKind.NoBuiltin: + case AttributeKind.Cold: + case AttributeKind.OptimizeNone: + case AttributeKind.JumpTable: + case AttributeKind.Convergent: + case AttributeKind.ArgMemOnly: + case AttributeKind.NoRecurse: + case AttributeKind.InaccessibleMemOnly: + case AttributeKind.InaccessibleMemOrArgMemOnly: + case AttributeKind.AllocSize: + case AttributeKind.Speculatable: + return FunctionIndexKinds.Function; + } + } + + private static Function GetFunctionForAttributes( Value value ) + { + switch( value ) + { + case Function f: + return f; + + case Instructions.Invoke inv: + return inv.TargetFunction; + + case Instructions.CallInstruction call: + return call.TargetFunction; + + case Argument arg: + return arg.ContainingFunction; + + default: + return null; + } + } + + // use complement and compare technique for efficiency + private static bool IsPowerOfTwo( ulong x ) => ( x != 0 ) && ( ( x & ( ~x + 1 ) ) == x ); + + // Lazy initialized one time mapping of LLVM attribut Ids to AttributeKind + private static Lazy> AttribIdToKindMap = new Lazy>( BuildAttribIdToKindMap ); + + private static Dictionary BuildAttribIdToKindMap( ) + { + return ( from kind in Enum.GetValues( typeof( AttributeKind ) ).Cast( ).Skip( 1 ) + where kind != AttributeKind.EndAttrKinds + let name = kind.GetAttributeName( ) + select new KeyValuePair( NativeMethods.GetEnumAttributeKindForName( name, ( size_t )name.Length ), kind ) + ).ToDictionary( ( KeyValuePair kvp ) => kvp.Key, ( KeyValuePair kvp ) => kvp.Value ); + } + + private static Lazy> KindToAttribIdMap = new Lazy>( BuildKindToAttribIdMap ); + + private static Dictionary BuildKindToAttribIdMap( ) + { + return AttribIdToKindMap.Value.ToDictionary( kvp => kvp.Value, kvp => kvp.Key ); + } + + private static string[ ] KnownAttributeNames = + { + string.Empty, + "align", + "allocsize", + "alwaysinline", + "argmemonly", + "builtin", + "byval", + "cold", + "convergent", + "dereferenceable", + "dereferenceable_or_null", + "inalloca", + "inreg", + "inaccessiblememonly", + "inaccessiblemem_or_argmemonly", + "inlinehint", + "jumptable", + "minsize", + "naked", + "nest", + "noalias", + "nobuiltin", + "nocapture", + "noduplicate", + "noimplicitfloat", + "noinline", + "norecurse", + "noredzone", + "noreturn", + "nounwind", + "nonlazybind", + "nonnull", + "optsize", + "optnone", + "readnone", + "readonly", + "returned", + "returns_twice", + "signext", + "safestack", + "sanitize_address", + "sanitize_memory", + "sanitize_thread", + "speculatable", + "alignstack", + "ssp", + "sspreq", + "sspstrong", + "sret", + "swifterror", + "swiftself", + "uwtable", + "writeonly", + "zeroext", + }; + } +} diff --git a/src/Llvm.NET/Values/AttributeKindExtensions.cs b/src/Llvm.NET/Values/AttributeKindExtensions.cs deleted file mode 100644 index d5a404a1a..000000000 --- a/src/Llvm.NET/Values/AttributeKindExtensions.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.Diagnostics; - -namespace Llvm.NET.Values -{ - /// Enumeration flags to indicate which attribute set index an attribute may apply to - [Flags] - public enum FunctionIndexKinds - { - /// Invalid attributes don't apply to any index - None = 0, - /// The attribute is applicable to a function - Function = 1, - /// The attribute is applicable to a function's return - Return = 2, - /// The attribute is applicable to a function's parameter - Parameter = 4 - } - - /// Utility class to provide extension methods for validating usage of attribute kinds - public static class AttributeKindExtensions - { - public static bool RequiresIntValue( this AttributeKind kind ) - { - Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); - switch( kind ) - { - case AttributeKind.Alignment: - case AttributeKind.StackAlignment: - case AttributeKind.Dereferenceable: - case AttributeKind.DereferenceableOrNull: - return true; - - default: - return false; - } - } - - public static bool CheckAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index, Function function ) - { - Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); - FunctionIndexKinds allowedindices = kind.GetAllowedIndexes( ); - switch( index ) - { - case FunctionAttributeIndex.Function: - if( !allowedindices.HasFlag( FunctionIndexKinds.Function ) ) - return false; - break; - - case FunctionAttributeIndex.ReturnType: - if( !allowedindices.HasFlag( FunctionIndexKinds.Return ) ) - return false; - break; - - //case FunctionAttributeIndex.Parameter0: - default: - if(function == null) - throw new ArgumentNullException( nameof( function ) ); - - if( !allowedindices.HasFlag( FunctionIndexKinds.Parameter ) ) - return false; - - var paramIndex = index - FunctionAttributeIndex.Parameter0; - if( paramIndex >= function.Parameters.Count ) - return false; - break; - } - return true; - } - - public static void VerifyAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index ) - { - Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); - FunctionIndexKinds allowedindices = kind.GetAllowedIndexes( ); - switch( index ) - { - case FunctionAttributeIndex.Function: - if( !allowedindices.HasFlag( FunctionIndexKinds.Function ) ) - throw new ArgumentException( "Attribute not allowed on functions", nameof( index ) ); - break; - - case FunctionAttributeIndex.ReturnType: - if( !allowedindices.HasFlag( FunctionIndexKinds.Return ) ) - throw new ArgumentException( "Attribute not allowed on function Return", nameof( index ) ); - break; - - //case FunctionAttributeIndex.Parameter0: - default: - if( !allowedindices.HasFlag( FunctionIndexKinds.Parameter ) ) - throw new ArgumentException( "Attribute not allowed on function parameter", nameof( index ) ); - break; - } - } - - // To prevent native asserts or crashes - validates parameters before passing down to native code - public static void VerifyIntAttributeUsage( this AttributeKind kind, FunctionAttributeIndex index, ulong value ) - { - kind.VerifyAttributeUsage( index ); - kind.RangeCheckValue( value ); - } - - public static void RangeCheckValue( this AttributeKind kind, ulong value ) - { - Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); - // To prevent native asserts or crashes - validate parameters before passing down to native code - switch( kind ) - { - case AttributeKind.Alignment: - if( value > UInt32.MaxValue ) - throw new ArgumentOutOfRangeException( nameof( value ), "Expected a 32 bit value for alignment" ); - - break; - - case AttributeKind.StackAlignment: - if( value > UInt32.MaxValue ) - throw new ArgumentOutOfRangeException( nameof( value ), "Expected a 32 bit value for stack alignment" ); - - if( value != 0 && !IsPowerOfTwo( value ) ) - throw new ArgumentException( "Stack alignment value must be a power of 2", nameof( value ) ); - - break; - - case AttributeKind.Dereferenceable: - case AttributeKind.DereferenceableOrNull: - break; - - default: - throw new ArgumentException( $"Attribute '{kind}' does not support an argument", nameof( kind ) ); - } - } - - static bool IsPowerOfTwo( ulong x ) - { - // use complement and compare technique for efficiency - return ( ( x != 0 ) && ( ( x & ( ~x + 1 ) ) == x ) ); - } - - public static FunctionIndexKinds GetAllowedIndexes( this AttributeKind kind ) - { - Debug.Assert( kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds ); - switch( kind ) - { - default: - return FunctionIndexKinds.None; - - case AttributeKind.ZExt: - case AttributeKind.SExt: - case AttributeKind.InReg: - case AttributeKind.ByVal: - case AttributeKind.InAlloca: - case AttributeKind.StructRet: - case AttributeKind.Alignment: - case AttributeKind.NoAlias: - case AttributeKind.NoCapture: - case AttributeKind.Nest: - case AttributeKind.Returned: - case AttributeKind.NonNull: - case AttributeKind.Dereferenceable: - case AttributeKind.DereferenceableOrNull: - return FunctionIndexKinds.Parameter | FunctionIndexKinds.Return; - - case AttributeKind.StackAlignment: - case AttributeKind.AlwaysInline: - case AttributeKind.Builtin: - case AttributeKind.Cold: - case AttributeKind.Convergent: - case AttributeKind.InlineHint: - case AttributeKind.JumpTable: - case AttributeKind.MinSize: - case AttributeKind.Naked: - case AttributeKind.NoBuiltin: - case AttributeKind.NoDuplicate: - case AttributeKind.NoImplicitFloat: - case AttributeKind.NoInline: - case AttributeKind.NonLazyBind: - case AttributeKind.NoRedZone: - case AttributeKind.NoReturn: - //case AttributeKind.NoRecurse: // ver > 3.7.0? - case AttributeKind.NoUnwind: - case AttributeKind.OptimizeForSize: - case AttributeKind.OptimizeNone: - case AttributeKind.ReadNone: - case AttributeKind.ReadOnly: - case AttributeKind.ArgMemOnly: - case AttributeKind.ReturnsTwice: - case AttributeKind.SafeStack: - case AttributeKind.SanitizeAddress: - case AttributeKind.SanitizeMemory: - case AttributeKind.SanitizeThread: - case AttributeKind.StackProtect: - case AttributeKind.StackProtectReq: - case AttributeKind.StackProtectStrong: - case AttributeKind.UWTable: - return FunctionIndexKinds.Function; - } - } - } -} diff --git a/src/Llvm.NET/Values/AttributeSet.cs b/src/Llvm.NET/Values/AttributeSet.cs deleted file mode 100644 index 8e9d54a88..000000000 --- a/src/Llvm.NET/Values/AttributeSet.cs +++ /dev/null @@ -1,324 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using Llvm.NET.Native; - -namespace Llvm.NET.Values -{ - /// AttributeSet for a , , or instruction - /// - /// The underlying LLVM AttributeSet class is an immutable value type, unfortunately it includes a non-default constructor - /// and therefore isn't a POD. However, it is trivially copy constructible and standard layout so this class simply wraps - /// the LLVM AttributeSet class. All data allocated for an AttributeSet is owned by a , which - /// will handle cleaning it up on . - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable", Justification = "LLVM Context owns the attribute set" )] - public struct AttributeSet - : IEquatable - { - public AttributeSet( Context context, FunctionAttributeIndex index, AttributeBuilder builder ) - { - if( context == null ) - throw new ArgumentNullException( nameof( context ) ); - - if( builder == null ) - throw new ArgumentNullException( nameof( builder ) ); - - NativeAttributeSet = NativeMethods.CreateAttributeSetFromBuilder( context.ContextHandle, ( uint )index, builder.BuilderHandle ); - } - - #region IEquatable - public override int GetHashCode( ) => NativeAttributeSet.GetHashCode( ); - - public override bool Equals( object obj ) - { - if( ReferenceEquals( this, obj ) ) - return true; - - if( obj is AttributeSet ) - return Equals( ( LLVMMetadataRef )obj ); - - if( obj is UIntPtr ) - return NativeAttributeSet.Equals( obj ); - - return false; - } - - public bool Equals( AttributeSet other ) => NativeAttributeSet == other.NativeAttributeSet; - - - public static bool operator ==( AttributeSet left, AttributeSet right ) => left.Equals( right ); - public static bool operator !=( AttributeSet left, AttributeSet right ) => !left.Equals( right ); - #endregion - - public bool IsEmpty => NativeAttributeSet.IsNull( ); - - /// Retrieves an attributeSet filtered by the specified function index - /// Index to filter on - /// A new with attributes from this set belonging to the specified index - public AttributeSet this[ FunctionAttributeIndex index ] - { - get - { - // explicitly check Context so that getter method doesn't throw an exception - if( IsEmpty || !HasAny( index ) ) - return new AttributeSet( ); - - return new AttributeSet( NativeMethods.AttributeGetAttributes( NativeAttributeSet, ( uint )index ) ); - } - } - - /// Enumerates the values that have attributes associated in this - public IEnumerable Indexes - { - get - { - // explicitly check Context so that getter method doesn't throw an exception - if( IsEmpty ) - yield break; - - var numIndices = NativeMethods.AttributeSetGetNumSlots( NativeAttributeSet ); - for( uint i = 0; i < numIndices; ++i ) - yield return ( FunctionAttributeIndex )NativeMethods.AttributeSetGetSlotIndex( NativeAttributeSet, i ); - } - } - - /// Gets the attributes for the function return - public AttributeSet ReturnAttributes => this[ FunctionAttributeIndex.ReturnType ]; - - /// Gets the attributes for the function itself - public AttributeSet FunctionAttributes => this[ FunctionAttributeIndex.Function ]; - - /// Gets the attributes for a function parameter - /// Parameter index [ 0 based ] - /// filtered for the specified parameter - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "AttributeSet" )] - public AttributeSet ParameterAttributes( int parameterIndex ) - { - // prevent overflow on offset addition below - if( parameterIndex > int.MaxValue - ( int )FunctionAttributeIndex.Parameter0 ) - throw new ArgumentOutOfRangeException( nameof( parameterIndex ) ); - - var index = FunctionAttributeIndex.Parameter0 + parameterIndex; - return new AttributeSet( NativeMethods.AttributeGetAttributes( NativeAttributeSet, ( uint )index ) ); - } - - /// Get LLVM formatted string representation of this for a given index - /// Index to get the string for - /// Formatted string for the specified attribute index - public string AsString( FunctionAttributeIndex index ) - { - var msgPtr = NativeMethods.AttributeSetToString( NativeAttributeSet, ( uint )index, false ); - return NativeMethods.MarshalMsg( msgPtr ); - } - - public IEnumerable AllAttributes - { - get - { - var numSlots = NativeMethods.AttributeSetGetNumSlots( NativeAttributeSet ); - for( uint slot = 0; slot < numSlots; ++slot ) - { - var index = ( FunctionAttributeIndex )NativeMethods.AttributeSetGetSlotIndex( NativeAttributeSet, slot ); - UIntPtr token = NativeMethods.AttributeSetGetIteratorStartToken( NativeAttributeSet, slot ); - UIntPtr attr = UIntPtr.Zero; - do - { - attr = NativeMethods.AttributeSetIteratorGetNext( NativeAttributeSet, slot, ref token ); - if( attr == UIntPtr.Zero ) - break; - - yield return new IndexedAttributeValue( index, new AttributeValue( attr ) ); - } while( attr != UIntPtr.Zero ); - } - } - } - - /// Creates a formatted string representation of the entire (e.g. all indices) - /// Formatted string representation of the - public override string ToString( ) - { - var bldr = new StringBuilder( ); - var indexGroups = from attribute in AllAttributes - group attribute.Value.ToString( ) by attribute.Index; - - foreach( var group in indexGroups ) - { - var values = string.Join( ", ", group ); - if( group.Key < FunctionAttributeIndex.Parameter0 ) - bldr.AppendFormat( "[{0}: {1}]", group.Key, values ); - else - bldr.AppendFormat( "[Parameter{0}: {1}]", group.Key - FunctionAttributeIndex.Parameter0, values ); - } - - return bldr.ToString( ); - } - - /// Adds a set of attributes - /// Index for the attribute - /// Attributes to add - /// Context for construction of the resulting - public AttributeSet Add(Context ctx, FunctionAttributeIndex index, params AttributeValue[ ] attributes ) - => Add( ctx, index, ( IEnumerable )attributes ); - - /// Adds a set of attributes - /// Index for the attribute - /// Attributes to add - /// Context for construction of the resulting - public AttributeSet Add( Context ctx, FunctionAttributeIndex index, params AttributeKind[ ] attributes ) - => Add( ctx, index, attributes.Select( a => a.ToAttributeValue( ctx ) ) ); - - /// Produces a new that includes the attributes from this set along with additional attributes provided - /// to use for the new attributes - /// Collection of attributes to add - /// Context for construction of the resulting - /// Newly created with the new attributes added - public AttributeSet Add( Context ctx, FunctionAttributeIndex index, IEnumerable attributes ) - { - if( ctx == null ) - throw new ArgumentNullException( nameof( ctx ) ); - - if( attributes == null ) - throw new ArgumentNullException( nameof( attributes ) ); - - using( var bldr = new AttributeBuilder( ) ) - { - foreach( var attribute in attributes ) - bldr.Add( attribute ); - - return Add( ctx, index, bldr.ToAttributeSet( index, ctx ) ); - } - } - - /// Adds a single attribute - /// Index for the attribute - /// kind to add - /// Context for construction of the resulting - public AttributeSet Add( Context ctx, FunctionAttributeIndex index, AttributeValue attribute ) - { - using( var bldr = new AttributeBuilder( ) ) - { - bldr.Add( attribute ); - return Add( ctx, index, bldr.ToAttributeSet( index, ctx ) ); - } - } - - /// Adds Attributes from another attribute set along a given index - /// Index to add attributes to and from - /// to add the attributes from - /// Context for construction of the resulting - /// New Containing all attributes of this set plus any - /// attributes from along the specified - public AttributeSet Add( Context ctx, FunctionAttributeIndex index, AttributeSet attributes ) - { - if( ctx == null ) - throw new ArgumentNullException( nameof( ctx ) ); - - var nativeSet = NativeMethods.AttributeSetAddAttributes( NativeAttributeSet, ctx.ContextHandle, ( uint )index, attributes.NativeAttributeSet ); - return new AttributeSet( nativeSet ); - } - - /// Removes the specified attribute from the attribute set - public AttributeSet Remove( FunctionAttributeIndex index, AttributeKind kind ) - { - if( IsEmpty ) - return this; - - var nativeSet = NativeMethods.AttributeSetRemoveAttributeKind( NativeAttributeSet, ( uint )index, ( LLVMAttrKind )kind ); - return new AttributeSet( nativeSet ); - } - - public AttributeSet Remove( Context ctx, FunctionAttributeIndex index, AttributeBuilder builder ) - { - if( ctx == null ) - throw new ArgumentNullException( nameof( ctx ) ); - - if( builder == null ) - throw new ArgumentNullException( nameof( builder ) ); - - var nativeSet = NativeMethods.AttributeSetRemoveAttributeBuilder( NativeAttributeSet, ctx.ContextHandle, ( uint )index, builder.BuilderHandle ); - return new AttributeSet( nativeSet ); - } - - /// Remove a target specific attribute - /// Index for the attribute - /// Name of the attribute - /// Context for construction of the resulting - public AttributeSet Remove( Context ctx, FunctionAttributeIndex index, string name ) - { - using( var bldr = new AttributeBuilder( ) ) - { - bldr.Add( name ); - return Remove( ctx, index, bldr ); - } - } - - /// Get an integer value for an index - /// Index to get the value from - /// to get the value of (see remarks for supported attributes) - /// Value of the attribute - /// - /// The only attributes supporting an integer value are , - /// , , - /// . - /// - public UInt64 GetAttributeValue( FunctionAttributeIndex index, AttributeKind kind ) - { - kind.VerifyIntAttributeUsage( index, 0 ); - var value = new AttributeValue( NativeMethods.AttributeSetGetAttributeByKind( NativeAttributeSet, ( uint )index, ( LLVMAttrKind )kind ) ); - Debug.Assert( value.IntegerValue.HasValue ); - return value.IntegerValue.Value; - } - - /// Tests if an has any attributes in the specified index - /// Index for the attribute - public bool HasAny( FunctionAttributeIndex index ) - { - if( IsEmpty ) - return false; - - return NativeMethods.AttributeSetHasAttributes( NativeAttributeSet, ( uint )index ); - } - - /// Tests if this attribute set has a given AttributeValue kind - /// Index for the attribute - /// Kind of AttributeValue to test for - /// true if the AttributeValue exists or false if not - public bool Has( FunctionAttributeIndex index, AttributeKind kind ) - { - if( IsEmpty ) - return false; - - return NativeMethods.AttributeSetHasAttributeKind( NativeAttributeSet, ( uint )index, ( LLVMAttrKind )kind ); - } - - /// Tests if this attribute set has a given string attribute - /// Index for the attribute - /// Name of the attribute to test for - /// true if the attribute exists or false if not - public bool Has( FunctionAttributeIndex index, string name ) - { - if( IsEmpty ) - return false; - - return NativeMethods.AttributeSetHasStringAttribute( NativeAttributeSet, ( uint )index, name ); - } - - internal AttributeSet( UIntPtr nativeAttributeSet ) - { - NativeAttributeSet = nativeAttributeSet; - } - - // underlying native llvm::AttributeSet follows the basic Pointer to Implementation (PIMPL) pattern. - // Thus, the total size of the structure is that of a pointer. While it isn't POD it is trivially - // copy constructible and standard layout so it is safe to just use a pointer here and pass that to - // native code as a simple IntPtr. The implementation for the PIMPL pattern is allocated and owned by - // the context. Since AttributeSets are "interned" multiple AttributeSets may refer to the same internal - // implementation instance. There is no dispose for the AttributeSet however as the context will take - // care of cleaning them up when it is disposed. - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources", Justification = "LLVM Context will clean up the allocations for this" )] - internal readonly UIntPtr NativeAttributeSet; - } -} diff --git a/src/Llvm.NET/Values/AttributeSetContainer.cs b/src/Llvm.NET/Values/AttributeSetContainer.cs deleted file mode 100644 index 0eba0ae8a..000000000 --- a/src/Llvm.NET/Values/AttributeSetContainer.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; - -namespace Llvm.NET.Values -{ - /// Static class to provide mutators for otherwise immutable s - /// - /// The methods of this class provide mutators for an contained in a - /// class implementing . (This includes - /// , and . An - /// is immutable, all of the methods that modify an attribute set actually - /// produce a new attribute set. (This follows the underlying LLVM model and semantics). Thus, to - /// change the attributes of a you must get the - /// set, produce a modified version and then set the - /// new value back to the property. The methods in - /// this class will perform the read, modify and write back sequence as a single call for any of the - /// available implementations. - /// - public static class AttributeSetContainer - { - public static T AddAttributes( this T self, FunctionAttributeIndex index, params AttributeKind[ ] values ) - where T : IAttributeSetContainer - { - if( values == null ) - throw new ArgumentNullException( nameof( values ) ); - - using( var bldr = new AttributeBuilder( self.Attributes, index ) ) - { - foreach( var kind in values ) - bldr.Add( kind ); - - self.Attributes = self.Attributes.Add( self.Context, index, bldr.ToAttributeSet( index, self.Context ) ); - return self; - } - } - - public static T AddAttribute( this T self, FunctionAttributeIndex index, AttributeKind value ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Add( self.Context, index, new AttributeValue( self.Context, value ) ); - return self; - } - - public static T AddAttribute( this T self, FunctionAttributeIndex index, AttributeValue value ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Add( self.Context, index, value ); - return self; - } - - /// Compatibility extension method to handle migrating code from older attribute handling - /// Function to add attributes to - /// Attributes to add - /// The function itself - /// - /// Adds attributes to a given function itself (as opposed to the return or one of the function's parameters) - /// This is equivalent to calling - /// with as the first parameter - /// - public static Function AddAttributes( this Function self, params AttributeValue[ ] attributes ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - self.Attributes = self.Attributes.Add( self.Context, FunctionAttributeIndex.Function, attributes ); - return self; - } - - /// Compatibility extension method to handle migrating code from older attribute handling - /// Function to add attributes to - /// Attributes to add - /// The function itself - /// - /// Adds attributes to a given function itself (as opposed to the return or one of the function's parameters) - /// This is equivalent to calling - /// with as the first parameter - /// - public static Function AddAttributes( this Function self, params AttributeKind[ ] attributes ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - var attribValues = attributes.Select( a => a.ToAttributeValue( self.Context ) ).ToArray( ); - self.Attributes = self.Attributes.Add( self.Context, FunctionAttributeIndex.Function, attribValues ); - return self; - } - - /// Compatibility extension method to handle migrating code from older attribute handling - /// Function to add attributes to - /// Attributes to add - /// The function itself - /// - /// Adds attributes to a given function itself (as opposed to the return or one of the function's parameters) - /// This is equivalent to calling - /// with as the first parameter - /// - public static Function AddAttributes( this Function self, IEnumerable attributes ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - var attribValues = attributes.Select( a => a.ToAttributeValue( self.Context ) ); - self.Attributes = self.Attributes.Add( self.Context, FunctionAttributeIndex.Function, attribValues ); - return self; - } - - - /// Compatibility extension method to handle migrating code from older attribute handling - /// Function to add attributes to - /// Attributes to add - /// The function itself - /// - /// Adds attributes to a given function itself (as opposed to the return or one of the function's parameters) - /// This is equivalent to calling - /// with as the first parameter - /// - public static Function AddAttributes( this Function self, IEnumerable attributes ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - self.Attributes = self.Attributes.Add( self.Context, FunctionAttributeIndex.Function, attributes ); - return self; - } - - /// Compatibility extension method to handle migrating code from older attribute handling - /// Function to remove attributes from - /// Attribute to remove - /// The function itself - /// - /// Removes attributes from a given function itself (as opposed to the return or one of the function's parameters) - /// This is equivalent to calling - /// with as the first parameter - /// - public static Function RemoveAttribute( this Function self, AttributeKind kind ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - self.Attributes = self.Attributes.Remove( FunctionAttributeIndex.Function, kind ); - return self; - } - - /// Compatibility extension method to handle migrating code from older attribute handling - /// Function to remove attributes from - /// Attribute to remove - /// The function itself - /// - /// Removes attributes from a given function itself (as opposed to the return or one of the function's parameters) - /// This is equivalent to calling - /// with as the first parameter - /// - public static Function RemoveAttribute( this Function self, string name ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - self.Attributes = self.Attributes.Remove( self.Context, FunctionAttributeIndex.Function, name ); - return self; - } - - public static T AddAttributes( this T self, FunctionAttributeIndex index, params AttributeValue[ ] attributes ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Add( self.Context, index, attributes ); - return self; - } - - public static T AddAttributes( this T self, FunctionAttributeIndex index, AttributeSet attributes ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Add( self.Context, index, attributes[ index ] ); - return self; - } - - public static T AddAttributes( this T self, FunctionAttributeIndex index, IEnumerable attributes ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Add( self.Context, index, attributes ); - return self; - } - - public static T RemoveAttribute( this T self, FunctionAttributeIndex index, AttributeKind kind ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Remove( index, kind ); - return self; - } - - public static T RemoveAttribute( this T self, FunctionAttributeIndex index, string name ) - where T : IAttributeSetContainer - { - self.Attributes = self.Attributes.Remove( self.Context, index, name ); - return self; - } - } -} \ No newline at end of file diff --git a/src/Llvm.NET/Values/AttributeValue.cs b/src/Llvm.NET/Values/AttributeValue.cs index 4acc41930..c9658816b 100644 --- a/src/Llvm.NET/Values/AttributeValue.cs +++ b/src/Llvm.NET/Values/AttributeValue.cs @@ -1,160 +1,74 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; using Llvm.NET.Native; namespace Llvm.NET.Values { - // TODO: Consider removing this in favor of C#7 Tuple support - public struct IndexedAttributeValue - : IEquatable - { - public IndexedAttributeValue( FunctionAttributeIndex index, AttributeValue value ) - { - Index = index; - Value = value; - } - - public FunctionAttributeIndex Index { get; } - public AttributeValue Value { get; } - - public override string ToString( ) - { - if( Index < FunctionAttributeIndex.Parameter0 ) - return $"{Index}: {Value}"; - - return $"Parameter{Index - FunctionAttributeIndex.Parameter0}: {Value}"; - } - #region Equality operators - public bool Equals( IndexedAttributeValue other ) - => other.Index == Index - && other.Value == Value; - - public override bool Equals( object obj ) - { - if( !( obj is IndexedAttributeValue ) ) - return false; - - return Equals( ( IndexedAttributeValue )obj ); - } - - public override int GetHashCode( ) => Value.GetHashCode( ) ^ Index.GetHashCode( ); - - public static bool operator ==( IndexedAttributeValue left, IndexedAttributeValue right ) => left.Equals( right ); - - public static bool operator !=( IndexedAttributeValue left, IndexedAttributeValue right ) => left.Equals( right ); - #endregion - } - /// Single attribute for functions, function returns and function parameters /// - /// This is the equivalent to the underlying llvm::Attribute class. The name was changed to - /// AttributeValue in .NET to prevent confusion with the class - /// that is used throughout .NET libraries. As with the underlying LLVM type, this is an - /// immutable value type. + /// This is the equivalent to the underlying llvm::AttributeImpl class. The name was changed to + /// AttributeValue in .NET to prevent confusion with the standard class + /// that is used throughout .NET libraries. /// - [SuppressMessage( "Microsoft.Design" - , "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable" - , Justification = "The native pointer isn't owned by this structure, it is owned by the LLVM context" - ) - ] public struct AttributeValue + : IEquatable { - /// Creates a simple boolean attribute - /// Context for creating the attribute - /// Kind of attribute - public AttributeValue( Context context, AttributeKind kind ) - : this( context, kind, 0ul ) - { - if( kind.RequiresIntValue() ) - throw new ArgumentException( $"Attribute {kind} requires a value", nameof( kind ) ); - } + public Context Context { get; } - /// Creates an attribute with an integer value parameter - /// Context used for interning attributes - /// The kind of attribute - /// Value for the attribute - /// - /// Not all attributes support a value and those that do don't all support - /// a full 64bit value. The following table provides the kinds of attributes - /// accepting a value and the allowed size of the values. - /// - /// Bit Length - /// 32 - /// 32 - /// 64 - /// 64 - /// - /// - public AttributeValue( Context context, AttributeKind kind, UInt64 value ) - : this( NativeMethods.CreateAttribute( context.VerifyAsArg( nameof( context ) ).ContextHandle - , ( LLVMAttrKind )kind - , value - ) - ) - { - } + public override int GetHashCode( ) => NativeAttribute.GetHashCode( ); - /// Adds a valueless named attribute - /// Context to use for interning attributes - /// Attribute name - public AttributeValue( Context context, string name ) - : this( context, name, string.Empty ) + public override bool Equals( object obj ) { - } + if( obj is AttributeValue attrib ) + { + return Equals( attrib ); + } - /// Adds a Target specific named attribute with value - /// Context to use for interning attributes - /// Name of the attribute - /// Value of the attribute - [SuppressMessage( "Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0" )] - public AttributeValue( Context context, string name, string value ) - { - context.VerifyAsArg( nameof( context ) ); - if( string.IsNullOrWhiteSpace( name ) ) - throw new ArgumentException( "AttributeValue name cannot be null, Empty or all whitespace" ); + if( obj is UIntPtr ) + { + return NativeAttribute.Equals( obj ); + } - NativeAttribute = NativeMethods.CreateTargetDependentAttribute( context.ContextHandle, name, value ); + return false; } - internal AttributeValue( UIntPtr nativeValue ) + public bool Equals( AttributeValue other ) { - NativeAttribute = nativeValue; - } + if( ReferenceEquals( other, null ) ) + { + return false; + } - #region IEquatable - public override int GetHashCode( ) => NativeAttribute.GetHashCode( ); + return NativeAttribute.Pointer == other.NativeAttribute.Pointer; + } - public override bool Equals( object obj ) + /// Kind of the attribute, for target specific named attributes + public AttributeKind Kind { - if( obj is AttributeValue ) - return Equals( ( LLVMMetadataRef )obj ); - - if( obj is UIntPtr ) - return NativeAttribute.Equals( obj ); + get + { + if( !NativeMethods.IsEnumAttribute( NativeAttribute ) ) + { + return AttributeKind.None; + } - return base.Equals( obj ); + return AttributeKindExtensions.LookupId( NativeMethods.GetEnumAttributeKind( NativeAttribute ) ); + } } - public bool Equals( AttributeValue other ) => NativeAttribute == other.NativeAttribute; - - public static bool operator ==( AttributeValue left, AttributeValue right ) => left.Equals( right ); - public static bool operator !=( AttributeValue left, AttributeValue right ) => !left.Equals( right ); - #endregion - - /// Kind of the attribute, or null for target specif named attributes - public AttributeKind? Kind => IsString ? (AttributeKind?)null : ( AttributeKind )NativeMethods.GetAttributeKind( NativeAttribute ); - /// Name of a named attribute or null for other kinds of attributes public string Name { get { - if( !IsString ) - return null; - - var llvmString = NativeMethods.GetAttributeName( NativeAttribute ); - return Marshal.PtrToStringAnsi( llvmString ); + if( IsString ) + { + return NativeMethods.GetStringAttributeKind( NativeAttribute, out uint length ); + } + else + { + return AttributeKindExtensions.LookupId( NativeMethods.GetEnumAttributeKind( NativeAttribute ) ).GetAttributeName( ); + } } } @@ -164,67 +78,105 @@ public string StringValue get { if( !IsString ) + { return null; + } - var llvmString = NativeMethods.GetAttributeStringValue( NativeAttribute ); - return Marshal.PtrToStringAnsi( llvmString ); + return NativeMethods.GetStringAttributeValue( NativeAttribute, out uint len ); } } /// Integer value of the attribute or null if the attribute doesn't have a value - public UInt64? IntegerValue => IsInt ? NativeMethods.GetAttributeValue( NativeAttribute ) : (UInt64?)null; + public UInt64? IntegerValue => IsInt ? NativeMethods.GetEnumAttributeValue( NativeAttribute ) : ( UInt64? )null; /// Flag to indicate if this attribute is a target specific string value public bool IsString => NativeMethods.IsStringAttribute( NativeAttribute ); /// Flag to indicate if this attribute has an integer attribute - public bool IsInt => NativeMethods.IsIntAttribute( NativeAttribute ); + public bool IsInt => Kind.RequiresIntValue( ); /// Flag to indicate if this attribute is a simple enumeration value public bool IsEnum => NativeMethods.IsEnumAttribute( NativeAttribute ); - public bool IsValidOn( FunctionAttributeIndex index, Function function ) + public bool IsValidOn( FunctionAttributeIndex index, Value value ) { + if( value == null ) + { + throw new ArgumentNullException( nameof( value ) ); + } + // for now all string attributes are valid everywhere as they are target dependent // (e.g. no way to verify the validity of an arbitrary without knowing the target) if( IsString ) - return true; + { + return value.IsCallSite || value.IsFunction; // TODO: Attributes on globals?? + } - return Kind.Value.CheckAttributeUsage( index, function ); + return Kind.CheckAttributeUsage( index, value ); } - public override string ToString( ) + public void VerifyValidOn( FunctionAttributeIndex index, Value value) { - if( IsString ) + if( value == null ) { - if( !string.IsNullOrWhiteSpace( StringValue ) ) - return $"\"{ Name }\" = \"{ StringValue }\""; + throw new ArgumentNullException( nameof( value ) ); + } - return Name; + // TODO: Attributes on globals?? + if( !( value.IsCallSite || value.IsFunction ) ) + { + throw new ArgumentException( "Attributes only allowed on functions and callsites" ); } - if( IsInt ) + // for now all string attributes are valid everywhere as they are target dependent + // (e.g. no way to verify the validity of an arbitrary without knowing the target) + if( IsString ) { - return $"{ Kind } = { IntegerValue }"; + return; } - return Kind.ToString( ); + Kind.VerifyAttributeUsage( index, value ); + } + + public override string ToString( ) + { + return NativeMethods.AttributeToString( NativeAttribute ); + } + + public static bool operator ==( AttributeValue left, AttributeValue right ) => Equals( left, right ); + + public static bool operator !=( AttributeValue left, AttributeValue right ) => !Equals( left, right ); + + internal static AttributeValue FromHandle( Context context, LLVMAttributeRef handle) + { + return context.GetAttributeFor( handle, (c,h)=>new AttributeValue(c, h) ); + } + + private AttributeValue( Context context, LLVMAttributeRef nativeValue ) + { + context.VerifyAsArg( nameof( context ) ); + Context = context; + NativeAttribute = nativeValue; } - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources" )] - internal readonly UIntPtr NativeAttribute; + internal LLVMAttributeRef NativeAttribute { get; } } + [SuppressMessage( "StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Legacy support to be removed but doesn't warrant it's own file" )] public static class AttributeValueMixins { /// Implicitly cast an to an /// Kind of attribute to create /// Context that should own the attribute value - public static AttributeValue ToAttributeValue( this AttributeKind kind, Context ctx ) => new AttributeValue( ctx, kind ); + [Obsolete("Use Context.CreateAttribute() instead")] + public static AttributeValue ToAttributeValue( this AttributeKind kind, Context ctx ) + => ctx?.CreateAttribute( kind ) ?? throw new ArgumentNullException(nameof(ctx)); /// Implicitly cast a string to an named /// Attribute name /// Context that should own the attribute value - public static AttributeValue ToAttributeValue( this string kind, Context ctx ) => new AttributeValue( ctx, kind ); + [Obsolete( "Use Context.CreateAttribute() instead" )] + public static AttributeValue ToAttributeValue( this string kind, Context ctx ) + => ctx?.CreateAttribute( kind ) ?? throw new ArgumentNullException( nameof( ctx ) ); } } diff --git a/src/Llvm.NET/Values/BasicBlock.cs b/src/Llvm.NET/Values/BasicBlock.cs index f6705fa13..e20292000 100644 --- a/src/Llvm.NET/Values/BasicBlock.cs +++ b/src/Llvm.NET/Values/BasicBlock.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Instructions; using Llvm.NET.Native; -using System.Diagnostics.CodeAnalysis; namespace Llvm.NET.Values { @@ -12,17 +12,19 @@ namespace Llvm.NET.Values /// and a single exit. The exit point must be a /// instruction or the block is not (yet) well-formed. /// - public class BasicBlock + public class BasicBlock : Value { - /// Function containing the block + /// Gets the function containing the block public Function ContainingFunction { get { var parent = NativeMethods.GetBasicBlockParent( BlockHandle ); if( parent.Pointer == IntPtr.Zero ) + { return null; + } // cache functions and use lookups to ensure // identity/interning remains consistent with actual @@ -38,7 +40,9 @@ public Instruction FirstInstruction { var firstInst = NativeMethods.GetFirstInstruction( BlockHandle ); if( firstInst.Pointer == IntPtr.Zero ) + { return null; + } return FromHandle( firstInst ); } @@ -51,7 +55,9 @@ public Instruction LastInstruction { var lastInst = NativeMethods.GetLastInstruction( BlockHandle ); if( lastInst.Pointer == IntPtr.Zero) + { return null; + } return FromHandle( lastInst ); } @@ -67,7 +73,9 @@ public Instruction Terminator { var terminator = NativeMethods.GetBasicBlockTerminator( BlockHandle ); if( terminator.Pointer == IntPtr.Zero) + { return null; + } return FromHandle( terminator ); } @@ -94,10 +102,14 @@ public IEnumerable Instructions public Instruction GetNextInstruction( Instruction instruction ) { if( instruction == null ) + { throw new ArgumentNullException( nameof( instruction ) ); + } if( instruction.ContainingBlock != this ) + { throw new ArgumentException( "Instruction is from a different block", nameof( instruction ) ); + } var hInst = NativeMethods.GetNextInstruction( instruction.ValueHandle ); return hInst.Pointer == IntPtr.Zero ? null : FromHandle( hInst ); diff --git a/src/Llvm.NET/Values/Constant.cs b/src/Llvm.NET/Values/Constant.cs index 0eaea1d19..081ec5dd0 100644 --- a/src/Llvm.NET/Values/Constant.cs +++ b/src/Llvm.NET/Values/Constant.cs @@ -17,12 +17,16 @@ public class Constant public static Constant NullValueFor( ITypeRef typeRef ) { if( typeRef == null ) + { throw new ArgumentNullException( nameof( typeRef ) ); + } var kind = typeRef.Kind; var structType = typeRef as StructType; if( kind == TypeKind.Label || kind == TypeKind.Function || ( structType != null && structType.IsOpaque ) ) + { throw new ArgumentException( "Cannot get a Null value for labels, functions and opaque types" ); + } return FromHandle( NativeMethods.ConstNull( typeRef.GetTypeRef( ) ) ); } diff --git a/src/Llvm.NET/Values/ConstantArray.cs b/src/Llvm.NET/Values/ConstantArray.cs index 192bb8d9a..fbd2aeaaa 100644 --- a/src/Llvm.NET/Values/ConstantArray.cs +++ b/src/Llvm.NET/Values/ConstantArray.cs @@ -1,8 +1,8 @@ -using System.Linq; +using System; using System.Collections.Generic; -using System; -using Llvm.NET.Types; +using System.Linq; using Llvm.NET.Native; +using Llvm.NET.Types; namespace Llvm.NET.Values { @@ -13,7 +13,7 @@ namespace Llvm.NET.Values /// instance. At the least it will produce a Constant. LLVM will determine the /// appropriate internal representation based on the input types and values /// - public class ConstantArray + public class ConstantArray : Constant { /// Create a constant array of values of a given type @@ -47,12 +47,16 @@ public static Constant From( ITypeRef elementType, int len, params Constant[] va public static Constant From( ITypeRef elementType, IList values ) { if( values.Any( v => v.NativeType.TypeHandle != elementType.TypeHandle ) ) + { throw new ArgumentException( "One or more value(s) type does not match specified array element type" ); + } var valueHandles = values.Select( v => v.ValueHandle ).ToArray( ); - var argCount = valueHandles.Length; + int argCount = valueHandles.Length; if( argCount == 0 ) + { valueHandles = new LLVMValueRef[ 1 ]; + } var handle = NativeMethods.ConstArray( elementType.GetTypeRef(), out valueHandles[ 0 ], (uint)argCount ); return FromHandle( handle ); @@ -66,11 +70,15 @@ internal ConstantArray( LLVMValueRef valueRef ) private static IEnumerable ZeroFill( ITypeRef elementType, int len, IList values) { foreach( var value in values ) + { yield return value; + } var zeroVal = elementType.GetNullValue( ); for( int i = values.Count; i < len; ++i ) + { yield return zeroVal; + } } } } diff --git a/src/Llvm.NET/Values/ConstantDataSequential.cs b/src/Llvm.NET/Values/ConstantDataSequential.cs index 670c99fec..c8f47a5ab 100644 --- a/src/Llvm.NET/Values/ConstantDataSequential.cs +++ b/src/Llvm.NET/Values/ConstantDataSequential.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; namespace Llvm.NET.Values @@ -17,15 +18,14 @@ public class ConstantDataSequential : Constant { public bool IsString => NativeMethods.IsConstantString( ValueHandle ); - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ConstantDataSequential" )] public string ExtractAsString() { if( !IsString ) - throw new InvalidOperationException( "ConstantDataSequential is not a string" ); + { + throw new InvalidOperationException( "Value is not a string" ); + } - int len; - var strPtr = NativeMethods.GetAsString( ValueHandle, out len ); - return NativeMethods.NormalizeLineEndings( strPtr, len ); + return NativeMethods.GetAsString( ValueHandle, out size_t len ); } internal ConstantDataSequential( LLVMValueRef valueRef ) diff --git a/src/Llvm.NET/Values/ConstantExpression.cs b/src/Llvm.NET/Values/ConstantExpression.cs index 3d963e930..d539a2177 100644 --- a/src/Llvm.NET/Values/ConstantExpression.cs +++ b/src/Llvm.NET/Values/ConstantExpression.cs @@ -1,8 +1,9 @@ using System; -using Llvm.NET.Types; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Instructions; using Llvm.NET.Native; +using Llvm.NET.Types; namespace Llvm.NET.Values { @@ -16,13 +17,19 @@ public class ConstantExpression public static Constant IntToPtrExpression( Constant value, ITypeRef type ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } if( value.NativeType.Kind != TypeKind.Integer ) + { throw new ArgumentException( "Integer Type expected", nameof( value ) ); + } if( !( type is IPointerType ) ) + { throw new ArgumentException( "pointer type expected", nameof( type ) ); + } return FromHandle( NativeMethods.ConstIntToPtr( value.ValueHandle, type.GetTypeRef( ) ) ); } @@ -31,20 +38,22 @@ public static Constant IntToPtrExpression( Constant value, ITypeRef type ) public static Constant BitCast( Constant value, ITypeRef toType ) { if( value == null ) + { throw new ArgumentNullException( nameof( value ) ); + } var handle = NativeMethods.ConstBitCast( value.ValueHandle, toType.GetTypeRef( ) ); return FromHandle( handle ); } - public static Constant GetElementPtr( Constant value, params Constant[ ] args ) + public static Constant GetElementPtr( Constant value, params Constant[ ] args ) => GetElementPtr( value, ( IEnumerable )args ); - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call")] + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call")] public static Constant GetElementPtr(Constant value, IEnumerable args) { var llvmArgs = InstructionBuilder.GetValidatedGEPArgs(value, args); - var handle = NativeMethods.ConstGEP(value.ValueHandle, out llvmArgs[0], (uint)llvmArgs.Length); + var handle = NativeMethods.ConstGEP( value.ValueHandle, out llvmArgs[0], (uint)llvmArgs.Length); return FromHandle(handle); } diff --git a/src/Llvm.NET/Values/ConstantFP.cs b/src/Llvm.NET/Values/ConstantFP.cs index 757629c4c..99e5a8f41 100644 --- a/src/Llvm.NET/Values/ConstantFP.cs +++ b/src/Llvm.NET/Values/ConstantFP.cs @@ -5,22 +5,11 @@ namespace Llvm.NET.Values /// Floating point constant value in LLVM public class ConstantFP : Constant { - public double Value - { - get - { - bool loosesInfo; - return GetValueWithLoss( out loosesInfo ); - } - } + public double Value => GetValueWithLoss( out bool loosesInfo ); public double GetValueWithLoss( out bool loosesInfo ) { - loosesInfo = false; - LLVMBool nativeLoosesInfo; - var retVal = NativeMethods.ConstRealGetDouble( ValueHandle, out nativeLoosesInfo ); - loosesInfo = nativeLoosesInfo; - return retVal; + return NativeMethods.ConstRealGetDouble( ValueHandle, out loosesInfo ); } internal ConstantFP( LLVMValueRef valueRef ) diff --git a/src/Llvm.NET/Values/Function.cs b/src/Llvm.NET/Values/Function.cs index 132183814..1ca5ffce9 100644 --- a/src/Llvm.NET/Values/Function.cs +++ b/src/Llvm.NET/Values/Function.cs @@ -1,18 +1,18 @@ using System; -using System.Linq; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Runtime.InteropServices; -using Llvm.NET.Types; using Llvm.NET.DebugInfo; using Llvm.NET.Native; +using Llvm.NET.Types; namespace Llvm.NET.Values { /// LLVM Function definition public class Function : GlobalObject - , IAttributeSetContainer + , IAttributeAccessor { /// Signature type of the function public IFunctionType Signature => TypeRef.FromHandle( NativeMethods.GetElementType( NativeMethods.TypeOf( ValueHandle ) ) ); @@ -23,7 +23,9 @@ public BasicBlock EntryBlock get { if( NativeMethods.CountBasicBlocks( ValueHandle ) == 0 ) + { return null; + } return BasicBlock.FromHandle( NativeMethods.GetEntryBasicBlock( ValueHandle ) ); } @@ -37,7 +39,9 @@ public IReadOnlyList BasicBlocks uint count = NativeMethods.CountBasicBlocks( ValueHandle ); var buf = new LLVMBasicBlockRef[ count ]; if( count > 0 ) + { NativeMethods.GetBasicBlocks( ValueHandle, out buf[ 0 ] ); + } return buf.Select( BasicBlock.FromHandle ) .ToList( ) @@ -51,14 +55,8 @@ public IReadOnlyList BasicBlocks /// Calling convention for the method public CallingConvention CallingConvention { - get - { - return ( CallingConvention )NativeMethods.GetFunctionCallConv( ValueHandle ); - } - set - { - NativeMethods.SetFunctionCallConv( ValueHandle, ( uint )value ); - } + get => ( CallingConvention )NativeMethods.GetFunctionCallConv( ValueHandle ); + set => NativeMethods.SetFunctionCallConv( ValueHandle, ( uint )value ); } /// LLVM instrinsicID for the method @@ -74,29 +72,28 @@ public Function PersonalityFunction { get { - if( !NativeMethods.FunctionHasPersonalityFunction( ValueHandle ) ) + if( !NativeMethods.HasPersonalityFn( ValueHandle ) ) + { return null; + } - return FromHandle( NativeMethods.GetPersonalityFunction( ValueHandle ) ); + return FromHandle( NativeMethods.GetPersonalityFn( ValueHandle ) ); } - set - { - NativeMethods.SetPersonalityFunction( ValueHandle, value?.ValueHandle ?? LLVMValueRef.Zero ); - } + set => NativeMethods.SetPersonalityFn( ValueHandle, value?.ValueHandle ?? new LLVMValueRef( IntPtr.Zero ) ); } /// Debug information for this function public DISubProgram DISubProgram { - get - { - return MDNode.FromHandle( NativeMethods.FunctionGetSubprogram( ValueHandle ) ); - } + get => MDNode.FromHandle( NativeMethods.FunctionGetSubprogram( ValueHandle ) ); + set { if( ( value != null ) && !value.Describes( this ) ) + { throw new ArgumentException( "Subprogram does not describe this Function" ); + } NativeMethods.FunctionSetSubprogram( ValueHandle, value?.MetadataHandle ?? LLVMMetadataRef.Zero ); } @@ -106,37 +103,19 @@ public DISubProgram DISubProgram /// For details on GC support in LLVM see: http://llvm.org/docs/GarbageCollection.html public string GcName { - get - { - var nativePtr = NativeMethods.GetGC( ValueHandle ); - return Marshal.PtrToStringAnsi( nativePtr ); - } - set - { - NativeMethods.SetGC( ValueHandle, value ); - } + get => NativeMethods.GetGC( ValueHandle ); + set => NativeMethods.SetGC( ValueHandle, value ); } + public IAttributeDictionary Attributes { get; } + /// Verifies the function is valid and all blocks properly terminated public void Verify( ) { - IntPtr errMsgPtr; - var status = NativeMethods.VerifyFunctionEx( ValueHandle, LLVMVerifierFailureAction.LLVMReturnStatusAction, out errMsgPtr ); + var status = NativeMethods.VerifyFunctionEx( ValueHandle, LLVMVerifierFailureAction.LLVMReturnStatusAction, out string errMsg ); if( status ) - throw new InternalCodeGeneratorException( NativeMethods.MarshalMsg( errMsgPtr ) ); - } - - public AttributeSet Attributes - { - get - { - return new AttributeSet( NativeMethods.GetFunctionAttributeSet( ValueHandle ) ); - } - - set { - // TODO: verify that the attribute set doesn't contain any attributes for parameter indices not available in this function. - NativeMethods.SetFunctionAttributeSet( ValueHandle, value.NativeAttributeSet ); + throw new InternalCodeGeneratorException( errMsg ); } } @@ -156,6 +135,7 @@ public BasicBlock PrependBasicBlock( string name ) var blockRef = NativeMethods.InsertBasicBlockInContext( NativeType.Context.ContextHandle, firstBlock, name ); retVal = BasicBlock.FromHandle( blockRef ); } + return retVal; } @@ -172,22 +152,83 @@ public BasicBlock AppendBasicBlock( string name ) /// Block name (label) to look for or create /// If the block was created it is appended to the end of function /// - /// This method tries to find a block by it's name and returns it if found, if not found a new block is + /// This method tries to find a block by it's name and returns it if found, if not found a new block is /// created and appended to the current function. /// public BasicBlock FindOrCreateNamedBlock( string name ) { var retVal = BasicBlocks.FirstOrDefault( b => b.Name == name ); if( ReferenceEquals( retVal, null ) ) + { retVal = AppendBasicBlock( name ); + } Debug.Assert( retVal.ContainingFunction.ValueHandle.Pointer == ValueHandle.Pointer ); return retVal; } + public void AddAttributeAtIndex( FunctionAttributeIndex index, AttributeValue attrib ) + { + attrib.VerifyValidOn( index, this ); + + NativeMethods.AddAttributeAtIndex( ValueHandle, ( LLVMAttributeIndex )index, attrib.NativeAttribute ); + } + + public uint GetAttributeCountAtIndex( FunctionAttributeIndex index ) + { + return NativeMethods.GetAttributeCountAtIndex( ValueHandle, ( LLVMAttributeIndex )index ); + } + + public IEnumerable GetAttributesAtIndex( FunctionAttributeIndex index ) + { + uint count = GetAttributeCountAtIndex( index ); + if( count == 0 ) + { + return Enumerable.Empty( ); + } + + var buffer = new LLVMAttributeRef[ count ]; + NativeMethods.GetAttributesAtIndex( ValueHandle, ( LLVMAttributeIndex )index, out buffer[0] ); + return from attribRef in buffer + select AttributeValue.FromHandle( Context, attribRef ); + } + + public AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ) + { + var handle = NativeMethods.GetEnumAttributeAtIndex( ValueHandle, ( LLVMAttributeIndex )index, kind.GetEnumAttributeId( ) ); + return AttributeValue.FromHandle( Context, handle ); + } + + public AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, string name ) + { + if( string.IsNullOrWhiteSpace( name ) ) + { + throw new ArgumentException( "name cannot be null or empty", nameof( name ) ); + } + + var handle = NativeMethods.GetStringAttributeAtIndex( ValueHandle, ( LLVMAttributeIndex )index, name, (uint)name.Length ); + return AttributeValue.FromHandle( Context, handle ); + } + + public void RemoveAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ) + { + NativeMethods.RemoveEnumAttributeAtIndex( ValueHandle, ( LLVMAttributeIndex )index, kind.GetEnumAttributeId( ) ); + } + + public void RemoveAttributeAtIndex( FunctionAttributeIndex index, string name ) + { + if( string.IsNullOrWhiteSpace( name ) ) + { + throw new ArgumentException( "Name cannot be null or empty", nameof( name ) ); + } + + NativeMethods.RemoveStringAttributeAtIndex( ValueHandle, ( LLVMAttributeIndex )index, name, ( uint )name.Length ); + } + internal Function( LLVMValueRef valueRef ) : base( valueRef ) { + Attributes = new ValueAttributeDictionary( this, ()=>this ); } } } diff --git a/src/Llvm.NET/Values/FunctionParameterList.cs b/src/Llvm.NET/Values/FunctionParameterList.cs index c58a29159..f811ee7e4 100644 --- a/src/Llvm.NET/Values/FunctionParameterList.cs +++ b/src/Llvm.NET/Values/FunctionParameterList.cs @@ -18,7 +18,9 @@ public Argument this[ int index ] get { if( index >= Count || index < 0 ) + { throw new ArgumentOutOfRangeException( nameof( index ) ); + } return Value.FromHandle( NativeMethods.GetParam( OwningFunction.ValueHandle, ( uint )index ) ); } @@ -39,7 +41,9 @@ public IEnumerator GetEnumerator( ) { LLVMValueRef val = NativeMethods.GetParam( OwningFunction.ValueHandle, i ); if( val.Pointer == IntPtr.Zero ) + { yield break; + } yield return Value.FromHandle( val ); } diff --git a/src/Llvm.NET/Values/GlobalAlias.cs b/src/Llvm.NET/Values/GlobalAlias.cs index 60d4681a2..db9ede8c2 100644 --- a/src/Llvm.NET/Values/GlobalAlias.cs +++ b/src/Llvm.NET/Values/GlobalAlias.cs @@ -12,11 +12,15 @@ public Constant Aliasee get { if( ValueHandle.Pointer == IntPtr.Zero ) + { return null; + } var handle = NativeMethods.GetAliasee( ValueHandle ); if( handle.Pointer == IntPtr.Zero ) + { return null; + } return FromHandle( handle ); } diff --git a/src/Llvm.NET/Values/GlobalObject.cs b/src/Llvm.NET/Values/GlobalObject.cs index 737f50149..74910cefb 100644 --- a/src/Llvm.NET/Values/GlobalObject.cs +++ b/src/Llvm.NET/Values/GlobalObject.cs @@ -1,10 +1,9 @@ -using System.Runtime.InteropServices; +using System; using Llvm.NET.Native; -using System; namespace Llvm.NET.Values { - public class GlobalObject + public class GlobalObject : GlobalValue { internal GlobalObject( LLVMValueRef valueRef ) @@ -15,28 +14,15 @@ internal GlobalObject( LLVMValueRef valueRef ) /// Alignment requirements for this object public uint Alignment { - get - { - return NativeMethods.GetAlignment( ValueHandle ); - } - set - { - NativeMethods.SetAlignment( ValueHandle, value ); - } + get => NativeMethods.GetAlignment( ValueHandle ); + set => NativeMethods.SetAlignment( ValueHandle, value ); } /// Linker section this object belongs to public string Section { - get - { - var ptr = NativeMethods.GetSection( ValueHandle ); - return Marshal.PtrToStringAnsi( ptr ); - } - set - { - NativeMethods.SetSection( ValueHandle, value ); - } + get => NativeMethods.GetSection( ValueHandle ); + set => NativeMethods.SetSection( ValueHandle, value ); } /// Gets or sets the comdat attached to this object, if any @@ -51,58 +37,22 @@ public Comdat Comdat { LLVMComdatRef comdatRef = NativeMethods.GlobalObjectGetComdat( ValueHandle ); if( comdatRef.Pointer.IsNull( ) ) + { return null; + } return new Comdat( ParentModule, comdatRef ); } set { - if( value != null && value.Module != ParentModule ) + { throw new ArgumentException( "Mismatched modules for Comdat", nameof( value ) ); + } NativeMethods.GlobalObjectSetComdat( ValueHandle, value?.ComdatHandle?? new LLVMComdatRef( IntPtr.Zero ) ); } } } - - /// Fluent style extensions for properties of - public static class GlobalObjectExtensions - { - public static GlobalObject Comdat( this GlobalObject self, string name ) => Comdat( self, name, ComdatKind.Any ); - - public static GlobalObject Comdat( this GlobalObject self, string name, ComdatKind kind ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - Comdat comdat; - if( !self.ParentModule.Comdats.TryGetValue( name, out comdat ) ) - { - comdat = self.ParentModule.Comdats.Add( name, kind ); - } - else - comdat.Kind = kind; - - self.Comdat = comdat; - return self; - } - - public static void SectionName( this GlobalObject self, string name ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - self.Section = name; - } - - public static void Alignment( this GlobalObject self, uint value ) - { - if( self == null ) - throw new ArgumentNullException( nameof( self ) ); - - self.Alignment = value; - } - } } diff --git a/src/Llvm.NET/Values/GlobalObjectExtensions.cs b/src/Llvm.NET/Values/GlobalObjectExtensions.cs new file mode 100644 index 000000000..bd3173ac3 --- /dev/null +++ b/src/Llvm.NET/Values/GlobalObjectExtensions.cs @@ -0,0 +1,50 @@ +using System; + +namespace Llvm.NET.Values +{ + /// Fluent style extensions for properties of + public static class GlobalObjectExtensions + { + public static GlobalObject Comdat( this GlobalObject self, string name ) => Comdat( self, name, ComdatKind.Any ); + + public static GlobalObject Comdat( this GlobalObject self, string name, ComdatKind kind ) + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + if(!self.ParentModule.Comdats.TryGetValue( name, out Comdat comdat )) + { + comdat = self.ParentModule.Comdats.Add( name, kind ); + } + else + { + comdat.Kind = kind; + } + + self.Comdat = comdat; + return self; + } + + public static void SectionName( this GlobalObject self, string name ) + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + self.Section = name; + } + + public static void Alignment( this GlobalObject self, uint value ) + { + if( self == null ) + { + throw new ArgumentNullException( nameof( self ) ); + } + + self.Alignment = value; + } + } +} diff --git a/src/Llvm.NET/Values/GlobalValue.cs b/src/Llvm.NET/Values/GlobalValue.cs index 49bd68db4..c2599cb3c 100644 --- a/src/Llvm.NET/Values/GlobalValue.cs +++ b/src/Llvm.NET/Values/GlobalValue.cs @@ -9,40 +9,22 @@ public class GlobalValue /// Visibility of this global value public Visibility Visibility { - get - { - return ( Visibility )NativeMethods.GetVisibility( ValueHandle ); - } - set - { - NativeMethods.SetVisibility( ValueHandle, ( LLVMVisibility )value ); - } + get => ( Visibility )NativeMethods.GetVisibility( ValueHandle ); + set => NativeMethods.SetVisibility( ValueHandle, ( LLVMVisibility )value ); } /// Linkage specification for this symbol public Linkage Linkage { - get - { - return ( Linkage )NativeMethods.GetLinkage( ValueHandle ); - } - set - { - NativeMethods.SetLinkage( ValueHandle, ( LLVMLinkage )value ); - } + get => ( Linkage )NativeMethods.GetLinkage( ValueHandle ); + set => NativeMethods.SetLinkage( ValueHandle, ( LLVMLinkage )value ); } /// Flag to indicate if this is an Unnamed address public bool UnnamedAddress { - get - { - return NativeMethods.HasUnnamedAddr( ValueHandle ); - } - set - { - NativeMethods.SetUnnamedAddr( ValueHandle, value ); - } + get => NativeMethods.HasUnnamedAddr( ValueHandle ); + set => NativeMethods.SetUnnamedAddr( ValueHandle, value ); } /// Flag to indicate if this is a declaration @@ -56,31 +38,4 @@ internal GlobalValue( LLVMValueRef valueRef ) { } } - - /// Fluent style extensions for modifying properties of a - public static class GlobalValueExtensions - { - /// Visibility of this global value - public static T Visibility( this T self, Visibility value ) - where T : GlobalValue - { - self.Visibility = value; - return self; - } - - /// Linkage specification for this symbol - public static T Linkage( this T self, Linkage value ) - where T : GlobalValue - { - self.Linkage = value; - return self; - } - - public static T UnnamedAddress( this T self, bool value ) - where T : GlobalValue - { - self.UnnamedAddress = value; - return self; - } - } } diff --git a/src/Llvm.NET/Values/GlobalValueExtensions.cs b/src/Llvm.NET/Values/GlobalValueExtensions.cs new file mode 100644 index 000000000..f314d5fe1 --- /dev/null +++ b/src/Llvm.NET/Values/GlobalValueExtensions.cs @@ -0,0 +1,29 @@ +namespace Llvm.NET.Values +{ + /// Fluent style extensions for modifying properties of a + public static class GlobalValueExtensions + { + /// Visibility of this global value + public static T Visibility( this T self, Visibility value ) + where T : GlobalValue + { + self.Visibility = value; + return self; + } + + /// Linkage specification for this symbol + public static T Linkage( this T self, Linkage value ) + where T : GlobalValue + { + self.Linkage = value; + return self; + } + + public static T UnnamedAddress( this T self, bool value ) + where T : GlobalValue + { + self.UnnamedAddress = value; + return self; + } + } +} diff --git a/src/Llvm.NET/Values/GlobalVariable.cs b/src/Llvm.NET/Values/GlobalVariable.cs index b74ca9cc3..2ff666699 100644 --- a/src/Llvm.NET/Values/GlobalVariable.cs +++ b/src/Llvm.NET/Values/GlobalVariable.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics.CodeAnalysis; +using Llvm.NET.DebugInfo; using Llvm.NET.Native; namespace Llvm.NET.Values @@ -10,43 +12,22 @@ public class GlobalVariable /// Flag to indicate if this variable is initialized in an external module public bool IsExternallyInitialized { - get - { - return NativeMethods.IsExternallyInitialized( ValueHandle ); - } - - set - { - NativeMethods.SetExternallyInitialized( ValueHandle, value ); - } + get => NativeMethods.IsExternallyInitialized( ValueHandle ); + set => NativeMethods.SetExternallyInitialized( ValueHandle, value ); } /// Gets or sets if this global is a Constant public bool IsConstant { - get - { - return NativeMethods.IsGlobalConstant( ValueHandle ); - } - - set - { - NativeMethods.SetGlobalConstant( ValueHandle, value ); - } + get => NativeMethods.IsGlobalConstant( ValueHandle ); + set => NativeMethods.SetGlobalConstant( ValueHandle, value ); } /// Flag to indicate if this global is stored per thread public bool IsThreadLocal { - get - { - return NativeMethods.IsThreadLocal( ValueHandle ); - } - - set - { - NativeMethods.SetThreadLocal( ValueHandle, value ); - } + get => NativeMethods.IsThreadLocal( ValueHandle ); + set => NativeMethods.SetThreadLocal( ValueHandle, value ); } /// Initial value for the variable @@ -56,23 +37,28 @@ public Constant Initializer { var handle = NativeMethods.GetInitializer( ValueHandle ); if( handle.Pointer == IntPtr.Zero ) + { return null; + } return FromHandle( handle ); } - set - { - NativeMethods.SetInitializer( ValueHandle, value?.ValueHandle ?? LLVMValueRef.Zero ); - } + set => NativeMethods.SetInitializer( ValueHandle, value?.ValueHandle ?? new LLVMValueRef( IntPtr.Zero ) ); } - /// Removes the value from its parent module, but does not delete it - public void RemoveFromParent() + [SuppressMessage( "Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "VerifyArgNotNull" )] + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop" )] + public void AddDebugInfo(DIGlobalVariableExpression expression) { - NativeMethods.RemoveGlobalFromParent( ValueHandle ); + expression.VerifyArgNotNull( nameof( expression ) ); + + NativeMethods.GlobalVariableAddDebugExpression( ValueHandle, expression.MetadataHandle ); } + /// Removes the value from its parent module, but does not delete it + public void RemoveFromParent() => NativeMethods.RemoveGlobalFromParent( ValueHandle ); + internal GlobalVariable( LLVMValueRef valueRef ) : base( valueRef ) { diff --git a/src/Llvm.NET/Values/IAttributeAccessor.cs b/src/Llvm.NET/Values/IAttributeAccessor.cs new file mode 100644 index 000000000..4333c0d3c --- /dev/null +++ b/src/Llvm.NET/Values/IAttributeAccessor.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace Llvm.NET.Values +{ + // As of v3.9x and later Functions and call sites use distinct LLVM-C API sets for + // manipulating attributes. Fortunately they have consistent signatures so these + // are used to abstract the difference via derived types specialized for each case. + // going forward this is the simplest and most direct way to manipulate attributes + // on a value as everything ultimately comes down to this interface. + internal interface IAttributeAccessor + : IAttributeContainer + { + uint GetAttributeCountAtIndex( FunctionAttributeIndex index ); + + IEnumerable GetAttributesAtIndex( FunctionAttributeIndex index ); + + AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ); + + AttributeValue GetAttributeAtIndex( FunctionAttributeIndex index, string name ); + + void AddAttributeAtIndex( FunctionAttributeIndex index, AttributeValue attrib ); + + void RemoveAttributeAtIndex( FunctionAttributeIndex index, AttributeKind kind ); + + void RemoveAttributeAtIndex( FunctionAttributeIndex index, string name ); + } +} diff --git a/src/Llvm.NET/Values/IAttributeDictionary.cs b/src/Llvm.NET/Values/IAttributeDictionary.cs new file mode 100644 index 000000000..f0c34a9d3 --- /dev/null +++ b/src/Llvm.NET/Values/IAttributeDictionary.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace Llvm.NET.Values +{ + public interface IAttributeCollection + : ICollection + { + } + + /// Interface to an Attribute Dictionary + /// + /// This interface provides a full collection of all the + /// attributes keyed by the + /// + /// This connceptually corresponds to the functionality of the + /// LLVM AttributeSet class for Versions prior to 5. (at this + /// time v5 is not yet released). In 5 the equivalent type is + /// currently AttributeList. In v5 AttributeSet has no index and + /// is therefore more properly a set than in the past. To help + /// remove confusion and satisfy naming rules this is called + /// a Dictionary as that reflects the use here and fits the + /// direction of LLVM + /// + [SuppressMessage( "Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "Name is correct" )] + [SuppressMessage( "Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Name is correct" )] + public interface IAttributeDictionary + : IReadOnlyDictionary + { + } + + public interface IAttributeContainer + { + Context Context { get; } + + IAttributeDictionary Attributes { get; } + } +} diff --git a/src/Llvm.NET/Values/IAttributeSetContainer.cs b/src/Llvm.NET/Values/IAttributeSetContainer.cs deleted file mode 100644 index ed24a88be..000000000 --- a/src/Llvm.NET/Values/IAttributeSetContainer.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Llvm.NET.Values -{ - /// Interface for values containing an AttributeSet - /// - /// This is used to allow the extension - /// to act as mutators for the otherwise immutable . - /// Each method of the extension class will read the attribute set from the container - /// and create a new set based on the parameters (adding or removing attributes from the set) - /// producing a new attributeSet that is then re-assigned back to the container. - /// - public interface IAttributeSetContainer - { - /// Attributes for this container - AttributeSet Attributes { get; set; } - - /// Context for the Attributes - Context Context { get; } - } -} diff --git a/src/Llvm.NET/Values/InlineAsm.cs b/src/Llvm.NET/Values/InlineAsm.cs index 1fa3e984d..e80d49c74 100644 --- a/src/Llvm.NET/Values/InlineAsm.cs +++ b/src/Llvm.NET/Values/InlineAsm.cs @@ -15,8 +15,8 @@ internal InlineAsm( LLVMValueRef valueRef ) { } - //bool HasSideEffects => LLVMNative.HasSideEffects( ValueHandle ); - //bool IsAlignStack => LLVMNative.IsAlignStack( ValueHandle ); - //AsmDialect Dialect => LLVMNative.GetAsmDialect( ValueHandle ); + // bool HasSideEffects => NativeMethods.HasSideEffects( ValueHandle ); + // bool IsAlignStack => LLVMNative.IsAlignStack( ValueHandle ); + // AsmDialect Dialect => LLVMNative.GetAsmDialect( ValueHandle ); } } diff --git a/src/Llvm.NET/Values/Use.cs b/src/Llvm.NET/Values/Use.cs index 88022f3f0..11afd11a4 100644 --- a/src/Llvm.NET/Values/Use.cs +++ b/src/Llvm.NET/Values/Use.cs @@ -14,7 +14,9 @@ internal Use( LLVMUseRef useRef ) } public User User => Value.FromHandle( NativeMethods.GetUser( OpaqueHandle ) ); + public Value Value => Value.FromHandle( NativeMethods.GetUsedValue( OpaqueHandle ) ); + private LLVMUseRef OpaqueHandle; } } \ No newline at end of file diff --git a/src/Llvm.NET/Values/User.cs b/src/Llvm.NET/Values/User.cs index 28abd6532..f06ba9530 100644 --- a/src/Llvm.NET/Values/User.cs +++ b/src/Llvm.NET/Values/User.cs @@ -36,7 +36,6 @@ public IEnumerable Uses } } - private UserOperandList OperandList; } } diff --git a/src/Llvm.NET/Values/UserOperandList.cs b/src/Llvm.NET/Values/UserOperandList.cs index 21293ed28..29f3bf6df 100644 --- a/src/Llvm.NET/Values/UserOperandList.cs +++ b/src/Llvm.NET/Values/UserOperandList.cs @@ -18,7 +18,9 @@ public Value this[ int index ] get { if( index >= Count || index < 0 ) + { throw new ArgumentOutOfRangeException( nameof( index ) ); + } return Value.FromHandle( NativeMethods.GetOperand( Owner.ValueHandle, ( uint )index ) ); } @@ -39,7 +41,9 @@ public IEnumerator GetEnumerator( ) { LLVMValueRef val = NativeMethods.GetOperand( Owner.ValueHandle, i ); if( val.Pointer == IntPtr.Zero ) + { yield break; + } yield return Value.FromHandle( val ); } diff --git a/src/Llvm.NET/Values/ValuAttributeCollection.cs b/src/Llvm.NET/Values/ValuAttributeCollection.cs new file mode 100644 index 000000000..806af31a2 --- /dev/null +++ b/src/Llvm.NET/Values/ValuAttributeCollection.cs @@ -0,0 +1,77 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Llvm.NET.Values +{ + internal class ValueAttributeCollection + : IAttributeCollection + { + public ValueAttributeCollection(IAttributeAccessor container, FunctionAttributeIndex index ) + { + Container = container; + Index = index; + } + + public int Count => (int)Container.GetAttributeCountAtIndex( Index ); + + public bool IsReadOnly => false; + + public void Add( AttributeValue item ) + { + Container.AddAttributeAtIndex( Index, item ); + } + + public void Clear( ) + { + foreach( AttributeValue attrib in this ) + { + Remove( attrib ); + } + } + + public bool Contains( AttributeValue item ) + { + return this.Any( a => a == item ); + } + + public void CopyTo( AttributeValue[ ] array, int arrayIndex ) + { + if( array == null ) + { + return; + } + + foreach( AttributeValue attrib in this ) + { + array[ arrayIndex ] = attrib; + ++arrayIndex; + } + } + + public IEnumerator GetEnumerator( ) + { + return Container.GetAttributesAtIndex( Index ).GetEnumerator(); + } + + public bool Remove( AttributeValue item ) + { + bool retVal = Contains( item ); + if( item.IsEnum ) + { + Container.RemoveAttributeAtIndex( Index, item.Kind ); + } + else + { + Container.RemoveAttributeAtIndex( Index, item.Name ); + } + + return retVal; + } + + IEnumerator IEnumerable.GetEnumerator( ) => GetEnumerator( ); + + private readonly IAttributeAccessor Container; + private readonly FunctionAttributeIndex Index; + } +} diff --git a/src/Llvm.NET/Values/Value.cs b/src/Llvm.NET/Values/Value.cs index 496245ece..8905955d9 100644 --- a/src/Llvm.NET/Values/Value.cs +++ b/src/Llvm.NET/Values/Value.cs @@ -1,8 +1,6 @@ using System; using System.Diagnostics; -using System.Runtime.InteropServices; -using Llvm.NET.DebugInfo; -using Llvm.NET.Instructions; +using System.Diagnostics.CodeAnalysis; using Llvm.NET.Native; using Llvm.NET.Types; @@ -23,55 +21,68 @@ namespace Llvm.NET.Values /// referring to the same actual value (i.e. a function) are actually /// the same .NET object as well within the same /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling" )] + [SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Mapping factory creates child types from interop handles" )] public class Value : IExtensiblePropertyContainer { - /// Name of the value (if any) + /// Gets or sets name of the value (if any) public string Name { get { if( Context.IsDisposed ) + { return string.Empty; + } - var ptr = NativeMethods.GetValueName( ValueHandle ); - return Marshal.PtrToStringAnsi( ptr ); + return NativeMethods.GetValueName( ValueHandle ); } set { NativeMethods.SetValueName( ValueHandle, value ); + // LLVM auto adds a numeric suffix if a register with the same name already exists Debug.Assert( Name.StartsWith( value, StringComparison.Ordinal ) ); } } - /// Indicates if this value is Undefined + /// Gets a value indicating whether this value is Undefined public bool IsUndefined => NativeMethods.IsUndef( ValueHandle ); - /// Determines if the Value represents the NULL value for the values type + /// Gets a value indicating whether the Value represents the NULL value for the values type public bool IsNull => NativeMethods.IsNull( ValueHandle ); - /// Type of the value + /// Gets the type of the value public ITypeRef NativeType => TypeRef.FromHandle( NativeMethods.TypeOf( ValueHandle ) ); public Context Context => NativeType.Context; - /// Generates a string representing the LLVM syntax of the value - /// string version of the value formatted by LLVM - public override string ToString( ) + public bool IsInstruction => NativeMethods.GetValueIdAsKind( ValueHandle ) > ValueKind.Instruction; + + public bool IsFunction => NativeMethods.GetValueIdAsKind( ValueHandle ) == ValueKind.Function; + + public bool IsCallSite { - var ptr = NativeMethods.PrintValueToString( ValueHandle ); - return NativeMethods.MarshalMsg( ptr ); + get + { + var kind = NativeMethods.GetValueIdAsKind( ValueHandle ); + return (kind == ValueKind.Call) || (kind == ValueKind.Invoke); + } } + /// Generates a string representing the LLVM syntax of the value + /// string version of the value formatted by LLVM + public override string ToString( ) => NativeMethods.PrintValueToString( ValueHandle ); + /// Replace all uses of a with another one /// New value public void ReplaceAllUsesWith( Value other ) { if( other == null ) + { throw new ArgumentNullException( nameof( other ) ); + } NativeMethods.ReplaceAllUsesWith( ValueHandle, other.ValueHandle ); } @@ -85,7 +96,9 @@ public void ReplaceAllUsesWith( Value other ) internal Value( LLVMValueRef valueRef ) { if( valueRef.Pointer == IntPtr.Zero ) + { throw new ArgumentNullException( nameof( valueRef ) ); + } #if DEBUG var context = Context.GetContextFor( valueRef ); @@ -130,11 +143,11 @@ internal static T FromHandle( LLVMValueRef valueRef ) /// This method will determine the correct type for the handle and construct an instance of that /// type wrapping the handle. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling" )] - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity" )] + [SuppressMessage( "Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Factory that maps wrappers with underlying types" )] + [SuppressMessage( "Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Factory that maps wrappers with underlying types" )] private static Value StaticFactory( LLVMValueRef h ) { - var kind = NativeMethods.GetValueKind( h ); + var kind = NativeMethods.GetValueIdAsKind( h ); switch( kind ) { case ValueKind.Argument: @@ -357,7 +370,9 @@ private static Value StaticFactory( LLVMValueRef h ) default: if( kind >= ValueKind.ConstantFirstVal && kind <= ValueKind.ConstantLastVal ) + { return new Constant( h ); + } return kind > ValueKind.Instruction ? new Instructions.Instruction( h ) : new Value( h ); } @@ -365,131 +380,4 @@ private static Value StaticFactory( LLVMValueRef h ) private readonly ExtensiblePropertyContainer ExtensibleProperties = new ExtensiblePropertyContainer( ); } - - /// Provides extension methods to that cannot be achieved as members of the class - /// - /// Using generic static extension methods allows for fluent coding while retaining the type of the "this" parameter. - /// If these were members of the class then the only return type could be , - /// thus losing the original type and requiring a cast to get back to it. - /// - public static class ValueExtensions - { - /// Sets the debugging location for a value - /// Type of the value to tag - /// Value to set debug location for - /// Debug location information - /// - /// Technically speaking only an can have debug location - /// information. However, since LLVM will perform constant folding in the - /// most of the methods in return a rather than a - /// more specific . Thus, without this extension method here, - /// code would need to know ahead of time that an actual instruction would be produced then cast the result - /// to an and then set the debug location. This makes the code rather - /// ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches - /// the original and no additional casting is needed, which would defeat the purpose of doing this. For - /// types that are not instructions this does nothing. This allows for a simpler fluent - /// style of programming where the actual type is retained even in cases where an - /// method will always return an actual instruction. - /// In order to help simplify code generation for cases where not all of the source information is - /// available this is a NOP if is null. Thus, it is safe to call even when debugging - /// information isn't actually available. This helps to avoid cluttering calling code with test for debug info - /// before trying to add it. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public static T SetDebugLocation( this T value, DILocation location ) - where T : Value - { - if( value == null ) - throw new ArgumentNullException( nameof( value ) ); - - if( location == null ) - return value; - - var instruction = value as Instructions.Instruction; - if( instruction != null ) - { - if( !location.Scope.SubProgram.Describes( instruction.ContainingBlock.ContainingFunction ) ) - throw new ArgumentException( "Location does not describe the function containing the provided instruction", nameof( location ) ); - - NativeMethods.SetDILocation( value.ValueHandle, location.MetadataHandle ); - } - - return value; - } - - /// Sets the debugging location for a value - /// Type of the value to tag - /// Value to set debug location for - /// Line number - /// Column number - /// Scope for the value - /// - /// Technically speaking only an can have debug location - /// information. However, since LLVM will perform constant folding in the - /// most of the methods in return a rather than a - /// more specific . Thus, without this extension method here, - /// code would need to know ahead of time that an actual instruction would be produced then cast the result - /// to an and then set the debug location. This makes the code rather - /// ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches - /// the original and no additional casting is needed, which would defeat the purpose of doing this. For - /// types that are not instructions this does nothing. This allows for a simpler fluent - /// style of programming where the actual type is retained even in cases where an - /// method will always return an actual instruction. - /// In order to help simplify code generation for cases where not all of the source information is - /// available this is a NOP if is null. Thus, it is safe to call even when debugging - /// information isn't actually available. This helps to avoid cluttering calling code with test for debug info - /// before trying to add it. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] - public static T SetDebugLocation( this T value, uint line, uint column, DebugInfo.DILocalScope scope ) - where T : Value - { - if( scope == null ) - return value; - - var instruction = value as Instructions.Instruction; - if( instruction != null ) - { - if( !scope.SubProgram.Describes( instruction.ContainingBlock.ContainingFunction ) ) - throw new ArgumentException( "scope does not describe the function containing the provided instruction", nameof( scope ) ); - - NativeMethods.SetDebugLoc( value.ValueHandle, line, column, scope.MetadataHandle ); - } - - return value; - } - - /// Sets the virtual register name for a value - /// Type of the value to set the name for - /// Value to set register name for - /// Name for the virtual register the value represents - /// - /// Technically speaking only an can have register name - /// information. However, since LLVM will perform constant folding in the - /// it almost all of the methods in return a rather - /// than an more specific . Thus, without this extension method here, - /// code would need to know ahead of time that an actual instruction would be produced then cast the result - /// to an and then set the debug location. This makes the code rather - /// ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches - /// the original and no additional casting is needed, which would defeat the purpose of doing this. For - /// types that are not instructions this does nothing. This allows for a simpler fluent - /// style of programming where the actual type is retained even in cases where an - /// method will always return an actual instruction. - /// Since the property is available on all s this is slightly - /// redundant. It is useful for maintaining the fluent style of coding along with expressing intent more clearly. - /// (e.g. using this makes it expressly clear that the intent is to set the virtual register name and not the - /// name of a local variable etc...) Using the fluent style allows a significant reduction in the number of - /// overloaded methods in to account for all variations with or without a name. - /// - /// - public static T RegisterName( this T value, string name ) - where T : Value - { - var inst = value as Instructions.Instruction; - if( inst != null ) - value.Name = name; - - return value; - } - } } diff --git a/src/Llvm.NET/Values/ValueAttributeDictionary.cs b/src/Llvm.NET/Values/ValueAttributeDictionary.cs new file mode 100644 index 000000000..521cd15ac --- /dev/null +++ b/src/Llvm.NET/Values/ValueAttributeDictionary.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace Llvm.NET.Values +{ + // re-usable implementation of IAttributeDictionary for containers that implement IAttributeAccessor + // This uses the lowlevel methods of IAttributeAccessor to abastract out the differences in the + // LLVM-C API for attributes on CallSites vs. Functions + internal class ValueAttributeDictionary + : IAttributeDictionary + { + internal ValueAttributeDictionary( IAttributeAccessor container, Func functionFetcher ) + { + Container = container; + FunctionFetcher = functionFetcher; + } + + public Context Context => Container.Context; + + public IAttributeCollection this[ FunctionAttributeIndex key ] + { + get + { + if( !ContainsKey( key ) ) + { + throw new KeyNotFoundException( ); + } + + return new ValueAttributeCollection( Container, key ); + } + } + + public IEnumerable Keys + => new ReadOnlyCollection( GetValidKeys( ).ToList( ) ); + + public IEnumerable Values + => new ReadOnlyCollection( this.Select( kvp => kvp.Value ).ToList( ) ); + + public int Count => GetValidKeys( ).Count( ); + + public bool ContainsKey( FunctionAttributeIndex key ) => GetValidKeys( ).Any( k => k == key ); + + public IEnumerator> GetEnumerator( ) + { + return ( from key in GetValidKeys( ) + select new KeyValuePair( key, this[ key ] ) + ).GetEnumerator( ); + } + + public bool TryGetValue( FunctionAttributeIndex key, out IAttributeCollection value ) + { + value = null; + if( ContainsKey( key ) ) + { + return false; + } + + value = new ValueAttributeCollection( Container, key ); + return true; + } + + IEnumerator IEnumerable.GetEnumerator( ) => GetEnumerator( ); + + private IEnumerable GetValidKeys() + { + var endIndex = FunctionAttributeIndex.Parameter0 + FunctionFetcher().Parameters.Count; + for( var index = FunctionAttributeIndex.Function; index < endIndex; ++index ) + { + if( Container.GetAttributeCountAtIndex( index ) > 0 ) + { + yield return index; + } + } + } + + private readonly Func FunctionFetcher; + private readonly IAttributeAccessor Container; + } +} diff --git a/src/Llvm.NET/Values/ValueExtensions.cs b/src/Llvm.NET/Values/ValueExtensions.cs new file mode 100644 index 000000000..fd29062d2 --- /dev/null +++ b/src/Llvm.NET/Values/ValueExtensions.cs @@ -0,0 +1,149 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Llvm.NET.DebugInfo; +using Llvm.NET.Instructions; +using Llvm.NET.Native; + +namespace Llvm.NET.Values +{ + /// Provides extension methods to that cannot be achieved as members of the class + /// + /// Using generic static extension methods allows for fluent coding while retaining the type of the "this" parameter. + /// If these were members of the class then the only return type could be , + /// thus losing the original type and requiring a cast to get back to it. + /// + public static class ValueExtensions + { +#pragma warning disable IDE0019 // Use Pattern matching - doesn't work for generics (Expected in C#7.X) + /// Sets the debugging location for a value + /// Type of the value to tag + /// Value to set debug location for + /// Debug location information + /// + /// Technically speaking only an can have debug location + /// information. However, since LLVM will perform constant folding in the + /// most of the methods in return a rather than a + /// more specific . Thus, without this extension method here, + /// code would need to know ahead of time that an actual instruction would be produced then cast the result + /// to an and then set the debug location. This makes the code rather + /// ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches + /// the original and no additional casting is needed, which would defeat the purpose of doing this. For + /// types that are not instructions this does nothing. This allows for a simpler fluent + /// style of programming where the actual type is retained even in cases where an + /// method will always return an actual instruction. + /// In order to help simplify code generation for cases where not all of the source information is + /// available this is a NOP if is null. Thus, it is safe to call even when debugging + /// information isn't actually available. This helps to avoid cluttering calling code with test for debug info + /// before trying to add it. + /// + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + public static T SetDebugLocation( this T value, DILocation location ) + where T : Value + { + if( value == null ) + { + throw new ArgumentNullException( nameof( value ) ); + } + + if( location == null ) + { + return value; + } + + var instruction = value as Instructions.Instruction; + if( instruction != null ) + { + if( !location.Scope.SubProgram.Describes( instruction.ContainingBlock.ContainingFunction ) ) + { + throw new ArgumentException( "Location does not describe the function containing the provided instruction", nameof( location ) ); + } + + NativeMethods.SetDILocation( value.ValueHandle, location.MetadataHandle ); + } + + return value; + } + + /// Sets the debugging location for a value + /// Type of the value to tag + /// Value to set debug location for + /// Line number + /// Column number + /// Scope for the value + /// + /// Technically speaking only an can have debug location + /// information. However, since LLVM will perform constant folding in the + /// most of the methods in return a rather than a + /// more specific . Thus, without this extension method here, + /// code would need to know ahead of time that an actual instruction would be produced then cast the result + /// to an and then set the debug location. This makes the code rather + /// ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches + /// the original and no additional casting is needed, which would defeat the purpose of doing this. For + /// types that are not instructions this does nothing. This allows for a simpler fluent + /// style of programming where the actual type is retained even in cases where an + /// method will always return an actual instruction. + /// In order to help simplify code generation for cases where not all of the source information is + /// available this is a NOP if is null. Thus, it is safe to call even when debugging + /// information isn't actually available. This helps to avoid cluttering calling code with test for debug info + /// before trying to add it. + /// + [SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )] + public static T SetDebugLocation( this T value, uint line, uint column, DebugInfo.DILocalScope scope ) + where T : Value + { + if( scope == null ) + { + return value; + } + + var instruction = value as Instructions.Instruction; + if( instruction != null ) + { + if( !scope.SubProgram.Describes( instruction.ContainingBlock.ContainingFunction ) ) + { + throw new ArgumentException( "scope does not describe the function containing the provided instruction", nameof( scope ) ); + } + + NativeMethods.SetDebugLoc( value.ValueHandle, line, column, scope.MetadataHandle ); + } + + return value; + } + + /// Sets the virtual register name for a value + /// Type of the value to set the name for + /// Value to set register name for + /// Name for the virtual register the value represents + /// + /// Technically speaking only an can have register name + /// information. However, since LLVM will perform constant folding in the + /// it almost all of the methods in return a rather + /// than an more specific . Thus, without this extension method here, + /// code would need to know ahead of time that an actual instruction would be produced then cast the result + /// to an and then set the debug location. This makes the code rather + /// ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches + /// the original and no additional casting is needed, which would defeat the purpose of doing this. For + /// types that are not instructions this does nothing. This allows for a simpler fluent + /// style of programming where the actual type is retained even in cases where an + /// method will always return an actual instruction. + /// Since the property is available on all s this is slightly + /// redundant. It is useful for maintaining the fluent style of coding along with expressing intent more clearly. + /// (e.g. using this makes it expressly clear that the intent is to set the virtual register name and not the + /// name of a local variable etc...) Using the fluent style allows a significant reduction in the number of + /// overloaded methods in to account for all variations with or without a name. + /// + /// + public static T RegisterName( this T value, string name ) + where T : Value + { + var inst = value as Instructions.Instruction; + if( inst != null ) + { + value.Name = name; + } + + return value; + } + } +#pragma warning restore IDE0019 // Use Pattern matching - doesn't work for generics (Expected in C#7.X) +} diff --git a/src/Llvm.NET/project.json b/src/Llvm.NET/project.json deleted file mode 100644 index 8ae493711..000000000 --- a/src/Llvm.NET/project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - "PdbGit": "3.0.38" - }, - "frameworks": { - "net462": {} - }, - "runtimes": { - "win": {} - } -} \ No newline at end of file diff --git a/src/Llvm.NET/project.lock.json b/src/Llvm.NET/project.lock.json deleted file mode 100644 index 834e302b3..000000000 --- a/src/Llvm.NET/project.lock.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "locked": false, - "version": 2, - "targets": { - ".NETFramework,Version=v4.6.2": { - "PdbGit/3.0.38": { - "type": "package" - } - }, - ".NETFramework,Version=v4.6.2/win": { - "PdbGit/3.0.38": { - "type": "package" - } - } - }, - "libraries": { - "PdbGit/3.0.38": { - "sha512": "yZBv+nOAUK6UWi0jTl2j/UPXEx4+9VMPRgtJh8Ewt+TPVEMB5X9r/8/GcBldiW5jzwMKJKaOwa3hCULMQetsrQ==", - "type": "package", - "files": [ - "PdbGit.3.0.38.nupkg.sha512", - "PdbGit.nuspec", - "build/PdbGit.props", - "build/PdbGit.targets", - "tools/Catel.Core.dll", - "tools/GitTools.Core.dll", - "tools/ImpromptuInterface.dll", - "tools/LICENSE.txt", - "tools/LibGit2Sharp.dll", - "tools/NativeBinaries/amd64/git2-e0902fb.dll", - "tools/NativeBinaries/x86/git2-e0902fb.dll", - "tools/PdbGit.Tasks.dll", - "tools/PdbGit.exe", - "tools/PdbGit.props", - "tools/PdbGit.targets", - "tools/System.CommandLine.dll", - "tools/System.Runtime.InteropServices.RuntimeInformation.dll", - "tools/pdbstr.exe", - "tools/winsdk.redist.txt" - ] - } - }, - "projectFileDependencyGroups": { - "": [ - "PdbGit >= 3.0.38" - ], - ".NETFramework,Version=v4.6.2": [] - } -} \ No newline at end of file diff --git a/src/Llvm.NETTests/LLVM.NETTests/AssemblyInitialize.cs b/src/Llvm.NETTests/AssemblyInitialize.cs similarity index 57% rename from src/Llvm.NETTests/LLVM.NETTests/AssemblyInitialize.cs rename to src/Llvm.NETTests/AssemblyInitialize.cs index b06f44629..39e500d2f 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/AssemblyInitialize.cs +++ b/src/Llvm.NETTests/AssemblyInitialize.cs @@ -1,15 +1,17 @@ -using Llvm.NET; +using System.Diagnostics.CodeAnalysis; +using Llvm.NET; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Llvm.NETTests { - /// Provides common location for one time initalization for all tests in this assembly + /// Provides common location for one time initialization for all tests in this assembly [TestClass] public static class AssemblyInitialize { /// Initializes Llvm.NET state for use with all available targets /// Context for the test run [AssemblyInitialize] + [SuppressMessage( "Redundancies in Symbol Declarations", "RECS0154:Parameter is never used", Justification = "Not needed and signature is defined by test framework" )] public static void InitializeAssembly(TestContext ctx) { StaticState.RegisterAll( ); diff --git a/src/Llvm.NETTests/LLVM.NETTests/ContextTests.cs b/src/Llvm.NETTests/ContextTests.cs similarity index 98% rename from src/Llvm.NETTests/LLVM.NETTests/ContextTests.cs rename to src/Llvm.NETTests/ContextTests.cs index e7a503515..c7c0a281e 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/ContextTests.cs +++ b/src/Llvm.NETTests/ContextTests.cs @@ -5,10 +5,11 @@ using Llvm.NET.Values; using Microsoft.VisualStudio.TestTools.UnitTesting; +// warning SA1500: Braces for multi-line statements must not share line +#pragma warning disable SA1500 namespace Llvm.NET.Tests { [TestClass] - [DeploymentItem("LibLLVM.dll")] public class ContextTests { [TestMethod] @@ -20,6 +21,7 @@ public void SimpleConstructorDisposeTest( ) Assert.IsNotNull( context ); Assert.IsFalse( context.IsDisposed ); } + Assert.IsTrue( context.IsDisposed ); } @@ -100,7 +102,7 @@ public void GetIntTypeTest( ) var int128Type = context.GetIntType( 128 ); Assert.AreSame( context, int128Type.Context ); - Assert.AreEqual( 128U, int128Type.IntegerBitWidth ); + Assert.AreEqual( 128U, int128Type.IntegerBitWidth ); } } @@ -117,7 +119,7 @@ public void GetFunctionTypeTest( ) Assert.AreEqual( TypeKind.Function, funcSig.Kind ); Assert.AreSame( context.Int16Type, funcSig.ReturnType ); Assert.AreEqual( 2, funcSig.ParameterTypes.Count ); - + // verify additional properties created properly Assert.AreEqual( 0U, funcSig.IntegerBitWidth ); Assert.IsFalse( funcSig.IsDouble ); @@ -177,7 +179,7 @@ public void CreateFunctionTypeTest( ) Assert.IsNotNull( subroutineType ); Assert.AreSame( context, subroutineType.Context ); Assert.AreEqual( DebugInfoFlags.None, subroutineType.DebugInfoFlags ); - + // signatures, have no scope or file Assert.IsNull( subroutineType.Scope ); Assert.IsNull( subroutineType.File ); @@ -239,7 +241,7 @@ public void GetFunctionTypeTest1( ) Assert.AreEqual( TypeKind.Function, funcSig.Kind ); Assert.AreSame( context.Int16Type, funcSig.ReturnType ); Assert.AreEqual( 2, funcSig.ParameterTypes.Count ); - + // verify additional properties created properly Assert.AreEqual( 0U, funcSig.IntegerBitWidth ); Assert.IsFalse( funcSig.IsDouble ); @@ -271,7 +273,7 @@ public void GetFunctionTypeTest2( ) Assert.AreSame( context.Int16Type, funcSig.ReturnType ); Assert.AreEqual( 2, funcSig.ParameterTypes.Count ); Assert.IsTrue( funcSig.IsVarArg ); - + // verify additional properties created properly Assert.AreEqual( 0U, funcSig.IntegerBitWidth ); Assert.IsFalse( funcSig.IsDouble ); @@ -293,7 +295,7 @@ public void CreateStructTypeTest( ) { using( var context = new Context() ) { - var typeName = "struct.test"; + string typeName = "struct.test"; var type = context.CreateStructType( typeName ); Assert.IsNotNull( type ); Assert.AreSame( context, type.Context ); @@ -303,7 +305,7 @@ public void CreateStructTypeTest( ) Assert.IsTrue( type.IsStruct ); Assert.AreEqual( typeName , type.Name ); Assert.AreEqual( 0, type.Members.Count ); - + // with no elements the type should not be considered sized Assert.IsFalse( type.IsSized ); Assert.IsTrue( type.IsOpaque ); @@ -338,7 +340,7 @@ public void CreateAnonymousStructTypeTestWithOneMemberUnpacked( ) Assert.AreEqual( 1, type.Members.Count ); Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.IsFalse( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -373,7 +375,7 @@ public void CreateAnonymousStructTypeTestWithOneMemberPacked( ) Assert.AreEqual( 1, type.Members.Count ); Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.IsTrue( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -409,7 +411,7 @@ public void CreateAnonymousStructTypeTestWithMultipleMembersUnpacked( ) Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.AreSame( context.Int32Type, type.Members[ 1 ] ); Assert.IsFalse( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -445,7 +447,7 @@ public void CreateAnonymousStructTypeTestWithMultipleMembersPacked( ) Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.AreSame( context.Int32Type, type.Members[ 1 ] ); Assert.IsTrue( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -469,7 +471,7 @@ public void CreateNamedStructTypeTestWithOneMemberUnpacked( ) { using( var context = new Context() ) { - var typeName = "struct.test"; + string typeName = "struct.test"; var type = context.CreateStructType( typeName, false, context.Int16Type ); Assert.IsNotNull( type ); Assert.AreSame( context, type.Context ); @@ -481,7 +483,7 @@ public void CreateNamedStructTypeTestWithOneMemberUnpacked( ) Assert.AreEqual( 1, type.Members.Count ); Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.IsFalse( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -505,7 +507,7 @@ public void CreateNamedStructTypeTestWithOneMemberPacked( ) { using( var context = new Context() ) { - var typeName = "struct.test"; + string typeName = "struct.test"; var type = context.CreateStructType( typeName, true, context.Int16Type ); Assert.IsNotNull( type ); Assert.AreSame( context, type.Context ); @@ -517,7 +519,7 @@ public void CreateNamedStructTypeTestWithOneMemberPacked( ) Assert.AreEqual( 1, type.Members.Count ); Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.IsTrue( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -541,7 +543,7 @@ public void CreateNamedStructTypeTestWithMultipleMembersUnpacked( ) { using( var context = new Context() ) { - var typeName = "struct.test"; + string typeName = "struct.test"; var type = context.CreateStructType( typeName, false, context.Int16Type, context.Int32Type ); Assert.IsNotNull( type ); Assert.AreSame( context, type.Context ); @@ -554,7 +556,7 @@ public void CreateNamedStructTypeTestWithMultipleMembersUnpacked( ) Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.AreSame( context.Int32Type, type.Members[ 1 ] ); Assert.IsFalse( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -578,7 +580,7 @@ public void CreateNamedStructTypeTestWithMultipleMembersPacked( ) { using( var context = new Context() ) { - var typeName = "struct.test"; + string typeName = "struct.test"; var type = context.CreateStructType( typeName, true, context.Int16Type, context.Int32Type ); Assert.IsNotNull( type ); Assert.AreSame( context, type.Context ); @@ -591,7 +593,7 @@ public void CreateNamedStructTypeTestWithMultipleMembersPacked( ) Assert.AreSame( context.Int16Type, type.Members[ 0 ] ); Assert.AreSame( context.Int32Type, type.Members[ 1 ] ); Assert.IsTrue( type.IsPacked ); - + // with at least one element the type should be considered sized Assert.IsTrue( type.IsSized ); Assert.IsFalse( type.IsOpaque ); @@ -794,7 +796,7 @@ public void CreateAnonymousUnpackedConstantStructUsingEnumerableTest( ) [TestMethod] public void CreateNamedConstantPackedStructTestUsingEnumerable( ) - { + { using( var context = new Context() ) { var structType = context.CreateStructType( "struct.test", true, context.Int8Type, context.FloatType, context.Int16Type ); @@ -827,7 +829,7 @@ public void CreateNamedConstantPackedStructTestUsingEnumerable( ) [TestMethod] public void CreateNamedConstantUnpackedStructTestUsingEnumerable( ) - { + { using( var context = new Context() ) { var structType = context.CreateStructType( "struct.test" @@ -865,7 +867,7 @@ public void CreateNamedConstantUnpackedStructTestUsingEnumerable( ) [TestMethod] public void CreateNamedConstantPackedStructTestUsingParams( ) - { + { using( var context = new Context() ) { var structType = context.CreateStructType( "struct.test" @@ -903,7 +905,7 @@ public void CreateNamedConstantPackedStructTestUsingParams( ) [TestMethod] public void CreateNamedConstantUnpackedStructTestUsingParams( ) - { + { using( var context = new Context() ) { var structType = context.CreateStructType( "struct.test" @@ -944,7 +946,7 @@ public void CreateMetadataStringTest( ) { using( var context = new Context() ) { - var content = "Test MDString"; + string content = "Test MDString"; var mdstring = context.CreateMetadataString( content ); Assert.IsNotNull( mdstring ); Assert.AreEqual( content, mdstring.ToString( ) ); @@ -978,7 +980,7 @@ public void CreateConstantStringTest( ) { using( var context = new Context() ) { - var str = "hello world"; + string str = "hello world"; ConstantDataArray value = context.CreateConstantString( str ); Assert.IsNotNull( value ); Assert.IsTrue( value.IsString ); @@ -992,7 +994,7 @@ public void CreateConstantStringTest( ) Assert.AreSame( context, arrayType.Context ); Assert.AreSame( context.Int8Type, arrayType.ElementType ); Assert.AreEqual( ( uint )str.Length, arrayType.Length ); - var valueStr = value.ExtractAsString( ); + string valueStr = value.ExtractAsString( ); Assert.IsFalse( string.IsNullOrWhiteSpace( valueStr ) ); Assert.AreEqual( str, valueStr ); } @@ -1015,4 +1017,4 @@ private static void VerifyIntegerType( ITypeRef integerType, uint bitWidth ) Assert.AreEqual( bitWidth, integerType.IntegerBitWidth ); } } -} \ No newline at end of file +} diff --git a/src/Llvm.NETTests/LLVM.NETTests/DebugInfo/DebugUnionTypeTests.cs b/src/Llvm.NETTests/DebugInfo/DebugUnionTypeTests.cs similarity index 97% rename from src/Llvm.NETTests/LLVM.NETTests/DebugInfo/DebugUnionTypeTests.cs rename to src/Llvm.NETTests/DebugInfo/DebugUnionTypeTests.cs index cd4254304..df894550a 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/DebugInfo/DebugUnionTypeTests.cs +++ b/src/Llvm.NETTests/DebugInfo/DebugUnionTypeTests.cs @@ -1,11 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Llvm.NET.DebugInfo; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +#pragma warning disable SA1500 namespace Llvm.NET.DebugInfo.Tests { // TODO: Standard arg checks and error handling in general @@ -26,12 +21,11 @@ public void DebugUnionTypeTest( ) var union = new DebugUnionType( module, nativeUnionName, null, unionSymbolName, module.DIBuilder.CreateFile("test") ); Assert.IsNotNull( union ); - string errMsg; - Assert.IsTrue( module.Verify( out errMsg ), errMsg ); + Assert.IsTrue( module.Verify( out string errMsg ), errMsg ); Assert.IsNotNull( union.DIType ); Assert.IsNotNull( union.NativeType ); - + Assert.AreEqual( Tag.UnionType, union.DIType.Tag ); Assert.AreEqual( nativeUnionName, union.Name ); Assert.AreEqual( nativeUnionName, union.NativeType.Name ); diff --git a/src/Llvm.NETTests/LLVM.NETTests/ExpectedArgumentException.cs b/src/Llvm.NETTests/ExpectedArgumentException.cs similarity index 99% rename from src/Llvm.NETTests/LLVM.NETTests/ExpectedArgumentException.cs rename to src/Llvm.NETTests/ExpectedArgumentException.cs index 51bbbcead..47e7dc323 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/ExpectedArgumentException.cs +++ b/src/Llvm.NETTests/ExpectedArgumentException.cs @@ -18,8 +18,9 @@ public ExpectedArgumentExceptionAttribute( string expectedName, string noExcepti ExpectedName = expectedName; WrongExceptionMessage = DefautWrongExceptionMessage; } - + public string WrongExceptionMessage { get; set; } + public string ExpectedExceptionMessage { get; set; } protected override void Verify( Exception exception ) diff --git a/src/Llvm.NETTests/LLVM.NETTests/Llvm.NETTests.csproj b/src/Llvm.NETTests/LLVM.NETTests/Llvm.NETTests.csproj deleted file mode 100644 index 11a732e3b..000000000 --- a/src/Llvm.NETTests/LLVM.NETTests/Llvm.NETTests.csproj +++ /dev/null @@ -1,132 +0,0 @@ - - - - - Debug - x64 - {826ADB1C-4BDC-4A89-836B-87088E511D6A} - Library - Properties - Llvm.NETTests - Llvm.NETTests - v4.6.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - - true - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - true - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LibLLVM.dll - Always - - - PreserveNewest - - - - - {0162c8ce-6641-4922-8664-f8a44356fbf7} - Llvm.NET - - - {6c77a7de-d464-430f-96a9-a64768763b5f} - LibLLVM - false - True - - - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file diff --git a/src/Llvm.NETTests/LLVM.NETTests/Properties/AssemblyInfo.cs b/src/Llvm.NETTests/LLVM.NETTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 8f7e284ec..000000000 --- a/src/Llvm.NETTests/LLVM.NETTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle( "Llvm.NETTests" )] -[assembly: AssemblyDescription( "" )] -[assembly: AssemblyConfiguration( "" )] -[assembly: AssemblyCompany( "" )] -[assembly: AssemblyProduct( "Llvm.NETTests" )] -[assembly: AssemblyCopyright( "Copyright © 2015" )] -[assembly: AssemblyTrademark( "" )] -[assembly: AssemblyCulture( "" )] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible( false )] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid( "826adb1c-4bdc-4a89-836b-87088e511d6a" )] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion( "1.0.0.0" )] -[assembly: AssemblyFileVersion( "1.0.0.0" )] diff --git a/src/Llvm.NETTests/LLVM.NETTests/TargetTests.cs b/src/Llvm.NETTests/LLVM.NETTests/TargetTests.cs deleted file mode 100644 index b1ca9367f..000000000 --- a/src/Llvm.NETTests/LLVM.NETTests/TargetTests.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Llvm.NET.Tests -{ - class TargetInfoCollection - : KeyedCollection - { - protected override string GetKeyForItem( TargetInfo item ) => item.Name; - } - - class TargetInfo - { - public TargetInfo( string name, string description, bool hasAsmBackend, bool hasJit, bool hasTargetMachine ) - { - Name = name; - Description = description; - HasAsmBackEnd = hasAsmBackend; - HasJit = hasJit; - HasTargetMachine = hasTargetMachine; - } - - public string Name { get; } - public string Description { get; } - public bool HasAsmBackEnd { get; } - public bool HasJit { get; } - public bool HasTargetMachine { get; } - - public static TargetInfoCollection ExpectedTargets = new TargetInfoCollection { - new TargetInfo( "xcore", "XCore", false, false, true ), - new TargetInfo( "x86-64", "64-bit X86: EM64T and AMD64", true, true, true ), - new TargetInfo( "x86", "32-bit X86: Pentium-Pro and above", true, true, true ), - new TargetInfo( "systemz", "SystemZ", true, true, true ), - new TargetInfo( "sparcel", "Sparc LE", true, true, true ), - new TargetInfo( "sparcv9", "Sparc V9", true, true, true ), - new TargetInfo( "sparc", "Sparc", true, true, true ), - new TargetInfo( "ppc64le", "PowerPC 64 LE", true, true, true ), - new TargetInfo( "ppc64", "PowerPC 64", true, true, true ), - new TargetInfo( "ppc32", "PowerPC 32", true, true, true ), - new TargetInfo( "nvptx64", "NVIDIA PTX 64-bit", false, false, true ), - new TargetInfo( "nvptx", "NVIDIA PTX 32-bit", false, false, true ), - new TargetInfo( "msp430", "MSP430 [experimental]", false, false, true ), - new TargetInfo( "mips64el", "Mips64el [experimental]", true, true, true ), - new TargetInfo( "mips64", "Mips64 [experimental]", true, true, true ), - new TargetInfo( "mipsel", "Mipsel", true, true, true ), - new TargetInfo( "mips", "Mips", true, true, true ), - new TargetInfo( "hexagon", "Hexagon", true, false, true ), - //new TargetInfo( "cpp", "C++ backend", false, false, true ), - new TargetInfo( "bpfeb", "BPF (big endian)", true, true, true ), - new TargetInfo( "bpfel", "BPF (little endian)", true, true, true ), - new TargetInfo( "bpf", "BPF (host endian)", true, true, true ), - new TargetInfo( "thumbeb", "Thumb (big endian)", true, true, true ), - new TargetInfo( "thumb", "Thumb", true, true, true ), - new TargetInfo( "armeb", "ARM (big endian)", true, true, true ), - new TargetInfo( "arm", "ARM", true, true, true ), - new TargetInfo( "amdgcn", "AMD GCN GPUs", true, false, true ), - new TargetInfo( "r600", "AMD GPUs HD2XXX-HD6XXX", true, false, true ), - new TargetInfo( "aarch64_be", "AArch64 (big endian)", true, true, true ), - new TargetInfo( "aarch64", "AArch64 (little endian)", true, true, true ), - new TargetInfo( "arm64", "ARM64 (little endian)", true, true, true ) - }; - } - - [TestClass] - public class TargetTests - { - [TestMethod] - public void CreateTargetMachineTest( ) - { - using( var context = new Context( ) ) - { - var target = Target.FromTriple( DefaultTargetTriple ); - var machine = GetTargetMachine( context, target ); - Assert.IsNotNull( machine ); - Assert.AreSame( context, machine.Context ); - Assert.AreSame( target, machine.Target ); - Assert.AreEqual( DefaultTargetTriple, machine.Triple ); - Assert.AreEqual( DefaultTargetCpu, machine.Cpu ); - Assert.AreEqual( DefaultTargetFeatures, machine.Features ); - Assert.IsNotNull( machine.TargetData ); - } - } - - [TestMethod] - public void FromTripleTest( ) - { - var target = Target.FromTriple( DefaultTargetTriple ); - Assert.IsNotNull( target ); - Assert.AreEqual( "thumb", target.Name ); - Assert.AreEqual( "Thumb", target.Description ); - Assert.IsTrue( target.HasAsmBackEnd ); - Assert.IsTrue( target.HasJIT ); - Assert.IsTrue( target.HasTargetMachine ); - } - - [TestMethod] - public void AvailableTargetsTest() - { - Assert.IsNotNull( Target.AvailableTargets ); - int foundTargets = 0; - foreach( var target in Target.AvailableTargets ) - { - Assert.IsNotNull( target ); - TargetInfo info = TargetInfo.ExpectedTargets[ target.Name ]; - Assert.AreEqual( info.Name, target.Name ); - Assert.AreEqual( info.Description, target.Description ); - Assert.AreEqual( info.HasAsmBackEnd, target.HasAsmBackEnd ); - Assert.AreEqual( info.HasJit, target.HasJIT ); - Assert.AreEqual( info.HasTargetMachine, target.HasTargetMachine ); - ++foundTargets; - } - Assert.AreEqual( TargetInfo.ExpectedTargets.Count, foundTargets ); - } - - internal static TargetMachine GetTargetMachine( Context context ) - { - var target = Target.FromTriple( DefaultTargetTriple ); - return GetTargetMachine( context, target ); - } - - internal static TargetMachine GetTargetMachine( Context context, Target target ) - { - return target.CreateTargetMachine( context - , DefaultTargetTriple - , DefaultTargetCpu - , string.Empty - , CodeGenOpt.Aggressive - , Reloc.Default - , CodeModel.Small - ); - } - - internal const string DefaultTargetTriple = "thumbv7m-none--eabi"; - internal const string DefaultTargetCpu = "cortex-m3"; - internal const string DefaultTargetFeatures = ""; - - //internal string GenerateExpectedTargets() - //{ - // var bldr = new StringBuilder( "public static TargetInfo[ ] ExpectedTargets = {" ); - // bldr.AppendLine( ); - // var targets = Target.AvailableTargets.ToList( ); - // for( int i = 0; i < targets.Count; ++i ) - // { - // var target = targets[ i ]; - // bldr.AppendFormat( " new TargetInfo( \"{0}\", \"{1}\", {2}, {3}, {4} )" - // , target.Name - // , target.Description - // , target.HasAsmBackEnd.ToString().ToLowerInvariant() - // , target.HasJIT.ToString().ToLowerInvariant() - // , target.HasTargetMachine.ToString().ToLowerInvariant() - // ); - // var lastEntry = i == targets.Count - 1; - // bldr.AppendLine( lastEntry ? string.Empty : "," ); - // } - - // bldr.AppendLine( "};" ); - // return bldr.ToString( ); - //} - } -} \ No newline at end of file diff --git a/src/Llvm.NETTests/LLVM.NETTests/Values/AttributeSetTests.cs b/src/Llvm.NETTests/LLVM.NETTests/Values/AttributeSetTests.cs deleted file mode 100644 index bb6a199bd..000000000 --- a/src/Llvm.NETTests/LLVM.NETTests/Values/AttributeSetTests.cs +++ /dev/null @@ -1,535 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Llvm.NET; -using Llvm.NET.Values; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Llvm.NETTests -{ - [TestClass] - public class AttributeSetTests - { - [ClassInitialize] - public static void ClassInitialize( TestContext testContext ) - { - - } - - [TestMethod] - public void ParameterAttributesTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - // add attributes to all indices of the function - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline, AttributeKind.OptimizeNone ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.InReg ); - - var paramAttributes = attributes.ParameterAttributes( 0 ); - Assert.AreNotSame( attributes, paramAttributes ); - // parameterAttributes should only have attributes on the parameter index (e.g. ParameterAttributes(0) should filter them) - Assert.AreEqual( "inreg", paramAttributes.AsString( FunctionAttributeIndex.Parameter0 ) ); - Assert.AreEqual( string.Empty, paramAttributes.AsString( FunctionAttributeIndex.Function ) ); - Assert.AreEqual( string.Empty, paramAttributes.AsString( FunctionAttributeIndex.ReturnType ) ); - } - } - - [TestMethod] - public void GetParameterWhenNoAttributessetForParameterTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type, module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - // add attributes to all indices of the function - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline, AttributeKind.OptimizeNone ) - .Add( ctx, FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) - .Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.InReg ); - - var paramAttributes = attributes.ParameterAttributes( 0 ); - Assert.AreNotSame( attributes, paramAttributes ); - // parameterAttributes should only have attributes on the parameter index (e.g. ParameterAttributes(0) should filter them) - Assert.AreEqual( "inreg", paramAttributes.AsString( FunctionAttributeIndex.Parameter0 ) ); - var shouldBeEmptyAttributes = attributes.ParameterAttributes( 1 ); - Assert.IsFalse( shouldBeEmptyAttributes.AllAttributes.Any( ) ); - } - } - - [TestMethod] - public void AsStringForEmptySetIsEmptyStringTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var sig = module.Context.GetFunctionType( module.Context.Int8Type, module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.Function ) ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.ReturnType ) ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.Parameter0 ) ); - } - } - - [TestMethod] - public void AsStringWithOneFunctionAttributeTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var sig = module.Context.GetFunctionType( module.Context.Int8Type, module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - function.AddAttributes( AttributeKind.AlwaysInline ); - Assert.AreEqual( "alwaysinline", function.Attributes.AsString( FunctionAttributeIndex.Function ) ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.ReturnType ) ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.Parameter0 ) ); - } - } - - [TestMethod] - public void AsStringWithTwoFunctionAttributeTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var sig = module.Context.GetFunctionType( module.Context.Int8Type, module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - function.AddAttributes( AttributeKind.AlwaysInline, AttributeKind.OptimizeNone ); - Assert.AreEqual( "alwaysinline optnone", function.Attributes.AsString( FunctionAttributeIndex.Function ) ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.ReturnType ) ); - Assert.AreEqual( string.Empty, function.Attributes.AsString( FunctionAttributeIndex.Parameter0 ) ); - } - } - - [TestMethod] - [Description("Verifies that mutation produces a new attribute set leaving the original unmodified across all indices")] - public void AttributeSetMutationProducesNewAttributeSet( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - var funcAttributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.NoInline, AttributeKind.OptimizeNone ); - var retAttributes = funcAttributes.Add( ctx, FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ); - var paramAttributes = retAttributes.Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.InReg ); - - // None of the attributeSets returned should be the same instance they started from - Assert.AreNotSame( function.Attributes, funcAttributes ); - Assert.AreNotSame( funcAttributes, retAttributes ); - Assert.AreNotSame( retAttributes, paramAttributes ); - - // starting attribute set should remain un-modified - Assert.IsFalse( function.Attributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoInline ) ); - Assert.IsFalse( function.Attributes.Has( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ) ); - Assert.IsFalse( function.Attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsFalse( function.Attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - - // ditto for each subsequent addition along all indices - Assert.IsTrue( funcAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoInline ) ); - Assert.IsTrue( funcAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ) ); - Assert.IsFalse( funcAttributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsFalse( funcAttributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - - Assert.IsTrue( retAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoInline ) ); - Assert.IsTrue( retAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ) ); - Assert.IsTrue( retAttributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsFalse( retAttributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - - // full set of attributes should be available in final instance - Assert.IsTrue( paramAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoInline ) ); - Assert.IsTrue( paramAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ) ); - Assert.IsTrue( paramAttributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsTrue( paramAttributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - } - } - - [TestMethod] - public void AsStringWithMultipleAttributesTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - function.AddAttributes( AttributeKind.AlwaysInline, AttributeKind.OptimizeNone ); - function.AddAttribute( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ); - function.AddAttribute( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ); - Assert.AreEqual( "alwaysinline optnone", function.Attributes.AsString( FunctionAttributeIndex.Function ) ); - Assert.AreEqual( "nonnull", function.Attributes.AsString( FunctionAttributeIndex.ReturnType ) ); - Assert.AreEqual( "inreg", function.Attributes.AsString( FunctionAttributeIndex.Parameter0 ) ); - } - } - - [TestMethod] - [Description("Verifies that AttributeSet mutation with additional enum attributes into a new set propagates existing values into the new set")] - public void EnumFunctionAttributeMutationPropagationTest( ) - { - using( var ctx = new Context() ) - using( var module = new NativeModule( "test", ctx ) ) - { - var structType = ctx.CreateStructType( "testT", false, ctx.Int32Type, ctx.Int8Type.CreateArrayType( 32 ) ); - var func = module.AddFunction( "test", ctx.GetFunctionType( ctx.VoidType, structType.CreatePointerType() ) ); - - var originalAttributes = func.Attributes; - // shouldn't be created with any attributes - Assert.IsFalse( originalAttributes.HasAny( FunctionAttributeIndex.Function ) ); - - var newAttribs = func.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ); - // creating the new AttributeSet shouldn't modify the original - Assert.IsFalse( originalAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - - Assert.IsTrue( newAttribs.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - - // Add another attribute - var additionalAttributes = newAttribs.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.NoUnwind ); - Assert.IsTrue( additionalAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoUnwind ) ); - - // function should still have the previous attributes, but not the new ones - Assert.IsTrue( newAttribs.Has(FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsFalse( originalAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoUnwind ) ); - Assert.IsFalse( newAttribs.Has( FunctionAttributeIndex.Function, AttributeKind.NoUnwind ) ); - } - } - - [TestMethod] - [Description("Verifies that AttributeSet mutation with additional enum attributes into a new set propagates existing values into the new set")] - public void EnumReturnAttributeMutationPropagationTest( ) - { - using( var ctx = new Context() ) - using( var module = new NativeModule( "test", ctx ) ) - { - var structType = ctx.CreateStructType( "testT", false, ctx.Int32Type, ctx.Int8Type.CreateArrayType( 32 ) ); - var func = module.AddFunction( "test", ctx.GetFunctionType( ctx.VoidType, structType.CreatePointerType() ) ); - - var originalAttributes = func.Attributes; - // shouldn't be created with any attributes - Assert.IsFalse( originalAttributes.HasAny( FunctionAttributeIndex.Function ) ); - - var newAttribs = func.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ); - // creating the new AttributeSet shouldn't modify the original - Assert.IsFalse( originalAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - - Assert.IsTrue( newAttribs.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - - // Add another attribute - var additionalAttributes = newAttribs.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.NoUnwind ); - Assert.IsTrue( additionalAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoUnwind ) ); - - // function should still have the previous attributes, but not the new ones - Assert.IsTrue( newAttribs.Has(FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsFalse( originalAttributes.Has( FunctionAttributeIndex.Function, AttributeKind.NoUnwind ) ); - Assert.IsFalse( newAttribs.Has( FunctionAttributeIndex.Function, AttributeKind.NoUnwind ) ); - } - } - - //[TestMethod] - //[ExpectedArgumentException( "index", ExpectedExceptionMessage = "Specified parameter index exceeds the number of parameters in the function")] - //public void OutofRangeParameterIndexTest() - //{ - // using( var module = new NativeModule( "test" ) ) - // { - // var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - // var function = module.AddFunction( "test", sig ); - // function.Attributes.Add(FunctionAttributeIndex.Parameter0 + 1, new AttributeValue( AttributeKind.Alignment, 64 ) ); - // } - //} - - //[TestMethod] - //[ExpectedArgumentException( "index", ExpectedExceptionMessage = "Attribute not allowed on functions")] - //public void AlignmentNotSupportedOnFunctionTest() - //{ - // using( var module = new NativeModule( "test" ) ) - // { - // var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - // var function = module.AddFunction( "test", sig ); - // function.Attributes.Add( FunctionAttributeIndex.Function, new AttributeValue(AttributeKind.Alignment, 64) ); - // } - //} - - //[TestMethod] - //[ExpectedArgumentException( "index", ExpectedExceptionMessage = "Attribute not allowed on function Return")] - //public void StackAlignmentNotSupportedOnReturnTest() - //{ - // using( var module = new NativeModule( "test" ) ) - // { - // var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - // var function = module.AddFunction( "test", sig ); - // function.Attributes.Add( FunctionAttributeIndex.ReturnType, new AttributeValue(AttributeKind.StackAlignment, 64) ); - // } - //} - - //[TestMethod] - //[ExpectedArgumentException( "index", ExpectedExceptionMessage = "Attribute not allowed on function parameter")] - //public void StackAlignmentNotSupportedOnParameterTest() - //{ - // using( var module = new NativeModule( "test" ) ) - // { - // var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - // var function = module.AddFunction( "test", sig ); - // function.Attributes.Add( FunctionAttributeIndex.Parameter0, new AttributeValue(AttributeKind.StackAlignment, 64) ); - // } - //} - - //[TestMethod] - //[ExpectedArgumentException( "index", ExpectedExceptionMessage = "Attribute not allowed on functions")] - //public void DereferenceableNotSupportedOnFunctionTest() - //{ - // using( var module = new NativeModule( "test" ) ) - // { - // var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - // var function = module.AddFunction( "test", sig ); - // function.Attributes.Add( FunctionAttributeIndex.Function, new AttributeValue(AttributeKind.Dereferenceable, 64) ); - // } - //} - - //[TestMethod] - //[ExpectedArgumentException( "index", ExpectedExceptionMessage = "Attribute not allowed on functions")] - //public void DereferenceableOrNullNotSupportedOnFunctionTest() - //{ - // using( var module = new NativeModule( "test" ) ) - // { - // var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - // var function = module.AddFunction( "test", sig ); - // function.Attributes.Add( FunctionAttributeIndex.Function, new AttributeValue(AttributeKind.DereferenceableOrNull, 64) ); - // } - //} - - [TestMethod] - public void AddAndGetParameterAlignmentAttributeTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( ctx.Int8Type.CreatePointerType(), ctx.Int32Type ); - var function = module.AddFunction( "test", sig ); - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Parameter0, new AttributeValue( ctx, AttributeKind.Alignment, 64) ); - var actual = attributes.GetAttributeValue( FunctionAttributeIndex.Parameter0, AttributeKind.Alignment ); - Assert.AreEqual( 64ul, actual ); - } - } - - [TestMethod] - public void AddAndGetParameterDereferenceableAttributeTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( ctx.Int8Type.CreatePointerType(), ctx.Int32Type ); - var function = module.AddFunction( "test", sig ); - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Parameter0, new AttributeValue( ctx, AttributeKind.Dereferenceable, 64) ); - var actual = attributes.GetAttributeValue( FunctionAttributeIndex.Parameter0, AttributeKind.Dereferenceable ); - Assert.AreEqual( 64ul, actual ); - } - } - - [TestMethod] - public void AddAndGetParameterDereferenceableOrNullAttributeTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( ctx.Int8Type.CreatePointerType(), ctx.Int32Type ); - var function = module.AddFunction( "test", sig ); - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Parameter0, new AttributeValue( ctx, AttributeKind.DereferenceableOrNull, 64) ); - var actual = attributes.GetAttributeValue( FunctionAttributeIndex.Parameter0, AttributeKind.DereferenceableOrNull ); - Assert.AreEqual( 64ul, actual ); - } - } - - [TestMethod] - public void AddAndGetFunctionStackAlignmentAttributeTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = module.Context.GetFunctionType( ctx.Int8Type.CreatePointerType(), ctx.Int32Type ); - var function = module.AddFunction( "test", sig ); - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Function, new AttributeValue( ctx, AttributeKind.StackAlignment, 64) ); - var actual = attributes.GetAttributeValue( FunctionAttributeIndex.Function, AttributeKind.StackAlignment ); - Assert.AreEqual( 64ul, actual ); - } - } - - // TODO: verify each applicability check for attributes and indices - // e.g. attempt to apply all attributes in AttributeKind to all indices - // and ensure invalid ones are flagged with an argument exception... - - // TODO: String attributes and values on each index... - - [TestMethod] - public void RemoveTest( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = module.Context.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline, AttributeKind.OptimizeNone ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.InReg ); - - // verify all the expected attributes are present before trying to remove one - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ) ); - - attributes = attributes.Remove( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.OptimizeNone ) ); - } - } - - [TestMethod] - public void RemoveNamedAttributeTest1( ) - { - using( var module = new NativeModule( "test" ) ) - { - var ctx = module.Context; - var sig = ctx.GetFunctionType( module.Context.Int8Type.CreatePointerType(), module.Context.Int32Type ); - var function = module.AddFunction( "test", sig ); - var attributes = function.Attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.Function, new AttributeValue( module.Context, "testattr" ) ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ); - attributes = attributes.Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.InReg ); - - // verify all the expected attributes are present before trying to remove one - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, "testattr" ) ); - - attributes = attributes.Remove( ctx, FunctionAttributeIndex.Function, "testattr" ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.NonNull ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.InReg ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.Function, "testattr" ) ); - } - } - - [TestMethod] - public void HasAnyTest( ) - { - using( var ctx = new Context( ) ) - { - var attributes = new AttributeSet( ); - Assert.IsFalse( attributes.HasAny( FunctionAttributeIndex.Function ) ); - Assert.IsFalse( attributes.HasAny( FunctionAttributeIndex.ReturnType ) ); - Assert.IsFalse( attributes.HasAny( FunctionAttributeIndex.Parameter0 ) ); - Assert.IsFalse( attributes.HasAny( FunctionAttributeIndex.Parameter0 + 1 ) ); - - attributes = attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline, AttributeKind.Builtin ) - .Add( ctx, FunctionAttributeIndex.ReturnType, new AttributeValue( ctx, AttributeKind.DereferenceableOrNull, 1 ) ) - .Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ) - .Add( ctx, FunctionAttributeIndex.Parameter0 + 1, new AttributeValue( ctx, "TestCustom" ) ); - - Assert.IsTrue( attributes.HasAny( FunctionAttributeIndex.Function ) ); - Assert.IsTrue( attributes.HasAny( FunctionAttributeIndex.ReturnType ) ); - Assert.IsTrue( attributes.HasAny( FunctionAttributeIndex.Parameter0 ) ); - Assert.IsTrue( attributes.HasAny( FunctionAttributeIndex.Parameter0 + 1 ) ); - } - } - - [TestMethod] - public void HasTest( ) - { - using( var ctx = new Context( ) ) - { - var attributes = new AttributeSet( ); - - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.Builtin ) ); - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.DereferenceableOrNull ) ); - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ) ); - Assert.IsFalse( attributes.Has( FunctionAttributeIndex.Parameter0 + 1, "TestCustom" ) ); - - attributes = attributes.Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline, AttributeKind.Builtin ) - .Add( ctx, FunctionAttributeIndex.ReturnType, new AttributeValue( ctx, AttributeKind.DereferenceableOrNull, 1 ) ) - .Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ) - .Add( ctx, FunctionAttributeIndex.Parameter0 + 1, new AttributeValue( ctx, "TestCustom" ) ); - - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Function, AttributeKind.Builtin ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.ReturnType, AttributeKind.DereferenceableOrNull ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ) ); - Assert.IsTrue( attributes.Has( FunctionAttributeIndex.Parameter0 + 1, "TestCustom" ) ); - } - } - - [TestMethod] - public void GetAllowedindicesForAttributeTest( ) - { - var parmOrReturn = FunctionIndexKinds.Parameter | FunctionIndexKinds.Return; - Assert.AreEqual( parmOrReturn, AttributeKind.ZExt.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.SExt.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.InReg.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.ByVal.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.InAlloca.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.StructRet.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.Alignment.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.NoAlias.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.NoCapture.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.Nest.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.Returned.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.NonNull.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.Dereferenceable.GetAllowedIndexes( ) ); - Assert.AreEqual( parmOrReturn, AttributeKind.DereferenceableOrNull.GetAllowedIndexes( ) ); - - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.AlwaysInline.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.Builtin.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.Cold.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.Convergent.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.InlineHint.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.JumpTable.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.MinSize.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.Naked.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoBuiltin.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoDuplicate.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoImplicitFloat.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoInline.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NonLazyBind.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoRedZone.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoReturn.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.NoUnwind.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.OptimizeForSize.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.OptimizeNone.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.ReadNone.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.ReadOnly.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.ArgMemOnly.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.ReturnsTwice.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.StackAlignment.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.StackProtect.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.StackProtectReq.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.StackProtectStrong.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.SafeStack.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.SanitizeAddress.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.SanitizeThread.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.SanitizeMemory.GetAllowedIndexes( ) ); - Assert.AreEqual( FunctionIndexKinds.Function, AttributeKind.UWTable.GetAllowedIndexes( ) ); - } - - [TestMethod] - [Description("Verifies that the AllAttributesProperty contains the attributes specified for an attribute set")] - public void AttributeSetAllAttributesTest( ) - { - using( var ctx = new Context( ) ) - { - var attributes = new AttributeSet( ).Add( ctx, FunctionAttributeIndex.Function, AttributeKind.AlwaysInline, AttributeKind.Builtin ) - .Add( ctx, FunctionAttributeIndex.ReturnType, new AttributeValue( ctx, AttributeKind.DereferenceableOrNull, 1 ) ) - .Add( ctx, FunctionAttributeIndex.Parameter0, AttributeKind.ByVal ) - .Add( ctx, FunctionAttributeIndex.Parameter0 + 1, "TestCustom".ToAttributeValue( ctx ) ); - - var expectedSet = new HashSet - { new IndexedAttributeValue( FunctionAttributeIndex.Function, AttributeKind.AlwaysInline.ToAttributeValue( ctx ) ) - , new IndexedAttributeValue( FunctionAttributeIndex.Function, AttributeKind.Builtin.ToAttributeValue( ctx ) ) - , new IndexedAttributeValue( FunctionAttributeIndex.ReturnType, new AttributeValue( ctx, AttributeKind.DereferenceableOrNull, 1 ) ) - , new IndexedAttributeValue( FunctionAttributeIndex.Parameter0, AttributeKind.ByVal.ToAttributeValue( ctx ) ) - , new IndexedAttributeValue( FunctionAttributeIndex.Parameter0 + 1, new AttributeValue( ctx, "TestCustom" ) ) - }; - - Assert.IsTrue( expectedSet.SetEquals( attributes.AllAttributes ) ); - } - } - } -} \ No newline at end of file diff --git a/src/Llvm.NETTests/Llvm.NETTests.csproj b/src/Llvm.NETTests/Llvm.NETTests.csproj new file mode 100644 index 000000000..bc52a8655 --- /dev/null +++ b/src/Llvm.NETTests/Llvm.NETTests.csproj @@ -0,0 +1,51 @@ + + + net47 + + + + + + + + + + + + + + + + PreserveNewest + + + + + + + + + + + Llvm.NET + false + false + + + + + + + + + + + + + + + + diff --git a/src/Llvm.NETTests/LLVM.NETTests/MDNodeTests.cs b/src/Llvm.NETTests/MDNodeTests.cs similarity index 100% rename from src/Llvm.NETTests/LLVM.NETTests/MDNodeTests.cs rename to src/Llvm.NETTests/MDNodeTests.cs diff --git a/src/Llvm.NETTests/LLVM.NETTests/ModuleTests.cs b/src/Llvm.NETTests/ModuleTests.cs similarity index 94% rename from src/Llvm.NETTests/LLVM.NETTests/ModuleTests.cs rename to src/Llvm.NETTests/ModuleTests.cs index ddb5aee7d..b027bba7a 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/ModuleTests.cs +++ b/src/Llvm.NETTests/ModuleTests.cs @@ -1,15 +1,14 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using Llvm.NET.Instructions; using Llvm.NET.Values; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Llvm.NETTests; -using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Llvm.NET.Tests { [TestClass] - [DeploymentItem( "LibLLVM.dll" )] public class ModuleTests { private const string StructTestName = "struct.Test"; @@ -153,8 +152,7 @@ public void MultiContextCloneLinkTest( ) GC.Collect( GC.MaxGeneration, GCCollectionMode.Forced, true ); mergedMod.Link( clone1 ); GC.Collect( GC.MaxGeneration, GCCollectionMode.Forced, true ); - string errMsg; - Assert.IsTrue( mergedMod.Verify( out errMsg), errMsg ); + Assert.IsTrue( mergedMod.Verify( out string errMsg ), errMsg ); Assert.AreEqual( 1, mergedMod.Functions.Count( ) ); mergedMod.Link( clone2 ); GC.Collect( GC.MaxGeneration, GCCollectionMode.Forced, true ); @@ -169,12 +167,12 @@ public void VerifyValidModuleTest( ) using( var module = new NativeModule( TestModuleName ) ) { Function testFunc = CreateSimpleVoidNopTestFunction( module, "foo" ); + // verify basics Assert.IsNotNull( testFunc ); - string msg; - var isValid = module.Verify( out msg ); + bool isValid = module.Verify( out string msg ); Assert.IsTrue( isValid ); - Assert.IsNull( msg ); + Assert.AreEqual( string.Empty, msg ); } } @@ -184,15 +182,16 @@ public void VerifyInvalidModuleTest( ) using( var module = new NativeModule( TestModuleName ) ) { Function testFunc = CreateInvalidFunction( module, "badfunc" ); + // verify basics Assert.IsNotNull( testFunc ); - string msg; - var isValid = module.Verify( out msg ); + bool isValid = module.Verify( out string msg ); Assert.IsFalse( isValid ); Assert.IsNotNull( msg ); - // while verifying the contents of the message might be a normal test - // it comes from the underlying wrapped LLVM and is subject to change - // by the LLVM team and is therefore outside the control of LLVM.NET + /* while verifying the contents of the message might be a normal test + it comes from the underlying wrapped LLVM and is subject to change + by the LLVM team and is therefore outside the control of LLVM.NET + */ } } @@ -202,6 +201,7 @@ public void AddFunctionGetFunctionTest( ) using( var module = new NativeModule( TestModuleName ) ) { Function testFunc = CreateSimpleVoidNopTestFunction( module, "foo" ); + // verify basics Assert.IsNotNull( testFunc ); Assert.AreSame( module, testFunc.ParentModule ); @@ -214,10 +214,9 @@ public void AddFunctionGetFunctionTest( ) } [TestMethod] - [DeploymentItem( "TestModuleAsString.ll" )] public void WriteToFileTest( ) { - var path = Path.GetTempFileName( ); + string path = Path.GetTempFileName( ); try { using( var module = new NativeModule( TestModuleName ) ) @@ -230,12 +229,14 @@ public void WriteToFileTest( ) using( var module2 = NativeModule.LoadFrom( path, ctx ) ) { Function testFunc = module2.GetFunction( "foo" ); + // verify basics Assert.IsNotNull( testFunc ); - var txt = module2.WriteToString( ); + string txt = module2.WriteToString( ); Assert.IsFalse( string.IsNullOrWhiteSpace( txt ) ); - //var expectedText = File.ReadAllText( "TestModuleAsString.ll" ); - //Assert.AreEqual( expectedText, txt ); + string expectedText = File.ReadAllText( "TestModuleAsString.ll" ) + .Replace( "; ModuleID = 'test'", $"; ModuleID = '{path}'" ); + Assert.AreEqual( expectedText, txt ); } } finally @@ -245,17 +246,17 @@ public void WriteToFileTest( ) } [TestMethod] - [DeploymentItem( "TestModuleAsString.ll" )] public void AsStringTest( ) { using( var module = new NativeModule( TestModuleName ) ) { Function testFunc = CreateSimpleVoidNopTestFunction( module, "foo" ); + // verify basics Assert.IsNotNull( testFunc ); - var txt = module.WriteToString( ); + string txt = module.WriteToString( ); Assert.IsFalse( string.IsNullOrWhiteSpace( txt ) ); - var expectedText = File.ReadAllText( "TestModuleAsString.ll" ); + string expectedText = File.ReadAllText( "TestModuleAsString.ll" ); Assert.AreEqual( expectedText, txt ); } } @@ -313,7 +314,7 @@ public void AddGlobalTest1( ) Assert.IsTrue( globalVar.IsConstant ); Assert.IsInstanceOfType( globalVar.Initializer, typeof( ConstantInt ) ); var constInt = ( ConstantInt )globalVar.Initializer; - Assert.AreEqual( ( long )0x12345678, constInt.SignExtendedValue ); + Assert.AreEqual( 0x12345678, constInt.SignExtendedValue ); } } @@ -331,7 +332,7 @@ public void AddGlobalTest2( ) Assert.IsTrue( globalVar.IsConstant ); Assert.IsInstanceOfType( globalVar.Initializer, typeof( ConstantInt ) ); var constInt = ( ConstantInt )globalVar.Initializer; - Assert.AreEqual( ( long )0x12345678, constInt.SignExtendedValue ); + Assert.AreEqual( 0x12345678, constInt.SignExtendedValue ); } } @@ -361,6 +362,7 @@ public void AddModuleFlagTest( ) module.AddModuleFlag( ModuleFlagBehavior.Error, "wchar_size", 4 ); module.AddModuleFlag( ModuleFlagBehavior.Error, "min_enum_size", 4 ); module.AddVersionIdentMetadata( "unit-tests 1.0" ); + // currently no exposed means to get module level flags... // so at this point as long as adding the flags doesn't throw an exception // assume things are OK. @@ -479,8 +481,9 @@ private static Function CreateInvalidFunction( NativeModule module, string name var testFunc = module.AddFunction( name, ctx.GetFunctionType( ctx.VoidType ) ); testFunc.AppendBasicBlock( "entry" ); + // UNTERMINATED BLOCK INTENTIONAL return testFunc; } } -} \ No newline at end of file +} diff --git a/src/Llvm.NETTests/Properties/AssemblyInfo.cs b/src/Llvm.NETTests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..80aaf2705 --- /dev/null +++ b/src/Llvm.NETTests/Properties/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible( false )] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid( "826adb1c-4bdc-4a89-836b-87088e511d6a" )] diff --git a/src/Llvm.NETTests/TargetTests.cs b/src/Llvm.NETTests/TargetTests.cs new file mode 100644 index 000000000..6685d4c34 --- /dev/null +++ b/src/Llvm.NETTests/TargetTests.cs @@ -0,0 +1,169 @@ +using System.Collections.ObjectModel; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Llvm.NET.Tests +{ + [TestClass] + public class TargetTests + { + [TestMethod] + public void CreateTargetMachineTest( ) + { + using( var context = new Context( ) ) + { + var target = Target.FromTriple( DefaultTargetTriple ); + var machine = GetTargetMachine( context, target ); + Assert.IsNotNull( machine ); + Assert.AreSame( context, machine.Context ); + Assert.AreSame( target, machine.Target ); + Assert.AreEqual( DefaultTargetTriple, machine.Triple ); + Assert.AreEqual( DefaultTargetCpu, machine.Cpu ); + Assert.AreEqual( DefaultTargetFeatures, machine.Features ); + Assert.IsNotNull( machine.TargetData ); + } + } + + [TestMethod] + public void FromTripleTest( ) + { + var target = Target.FromTriple( DefaultTargetTriple ); + Assert.IsNotNull( target ); + Assert.AreEqual( "thumb", target.Name ); + Assert.AreEqual( "Thumb", target.Description ); + Assert.IsTrue( target.HasAsmBackEnd ); + Assert.IsTrue( target.HasJIT ); + Assert.IsTrue( target.HasTargetMachine ); + } + + [TestMethod] + public void AvailableTargetsTest() + { + Assert.IsNotNull( Target.AvailableTargets ); + int foundTargets = 0; + foreach( var target in Target.AvailableTargets ) + { + Assert.IsNotNull( target ); + TargetInfo info = TargetInfo.ExpectedTargets[ target.Name ]; + Assert.AreEqual( info.Name, target.Name ); + Assert.AreEqual( info.Description, target.Description ); + Assert.AreEqual( info.HasAsmBackEnd, target.HasAsmBackEnd ); + Assert.AreEqual( info.HasJit, target.HasJIT ); + Assert.AreEqual( info.HasTargetMachine, target.HasTargetMachine ); + ++foundTargets; + } + + Assert.AreEqual( TargetInfo.ExpectedTargets.Count, foundTargets ); + } + + internal static TargetMachine GetTargetMachine( Context context ) + { + var target = Target.FromTriple( DefaultTargetTriple ); + return GetTargetMachine( context, target ); + } + + internal static TargetMachine GetTargetMachine( Context context, Target target ) + { + return target.CreateTargetMachine( context + , DefaultTargetTriple + , DefaultTargetCpu + , string.Empty + , CodeGenOpt.Aggressive + , Reloc.Default + , CodeModel.Small + ); + } + + internal const string DefaultTargetTriple = "thumbv7m-none--eabi"; + internal const string DefaultTargetCpu = "cortex-m3"; + internal const string DefaultTargetFeatures = ""; + + internal class TargetInfoCollection + : KeyedCollection + { + protected override string GetKeyForItem( TargetInfo item ) => item.Name; + } + + internal class TargetInfo + { + public TargetInfo( string name, string description, bool hasAsmBackend, bool hasJit, bool hasTargetMachine ) + { + Name = name; + Description = description; + HasAsmBackEnd = hasAsmBackend; + HasJit = hasJit; + HasTargetMachine = hasTargetMachine; + } + + public string Name { get; } + + public string Description { get; } + + public bool HasAsmBackEnd { get; } + + public bool HasJit { get; } + + public bool HasTargetMachine { get; } + + public static readonly TargetInfoCollection ExpectedTargets = new TargetInfoCollection + { + new TargetInfo( "xcore", "XCore", false, false, true ), + new TargetInfo( "x86-64", "64-bit X86: EM64T and AMD64", true, true, true ), + new TargetInfo( "x86", "32-bit X86: Pentium-Pro and above", true, true, true ), + new TargetInfo( "systemz", "SystemZ", true, true, true ), + new TargetInfo( "sparcel", "Sparc LE", true, true, true ), + new TargetInfo( "sparcv9", "Sparc V9", true, true, true ), + new TargetInfo( "sparc", "Sparc", true, true, true ), + new TargetInfo( "riscv64", "64-bit RISC-V", true, false, true ), + new TargetInfo( "riscv32", "32-bit RISC-V", true, false, true ), + new TargetInfo( "ppc64le", "PowerPC 64 LE", true, true, true ), + new TargetInfo( "ppc64", "PowerPC 64", true, true, true ), + new TargetInfo( "ppc32", "PowerPC 32", true, true, true ), + new TargetInfo( "nvptx64", "NVIDIA PTX 64-bit", false, false, true ), + new TargetInfo( "nvptx", "NVIDIA PTX 32-bit", false, false, true ), + new TargetInfo( "msp430", "MSP430 [experimental]", false, false, true ), + new TargetInfo( "mips64el", "Mips64el [experimental]", true, true, true ), + new TargetInfo( "mips64", "Mips64 [experimental]", true, true, true ), + new TargetInfo( "mipsel", "Mipsel", true, true, true ), + new TargetInfo( "mips", "Mips", true, true, true ), + new TargetInfo( "lanai", "Lanai", true, false, true ), + new TargetInfo( "hexagon", "Hexagon", true, false, true ), + new TargetInfo( "bpfeb", "BPF (big endian)", true, true, true ), + new TargetInfo( "bpfel", "BPF (little endian)", true, true, true ), + new TargetInfo( "bpf", "BPF (host endian)", true, true, true ), + new TargetInfo( "thumbeb", "Thumb (big endian)", true, true, true ), + new TargetInfo( "thumb", "Thumb", true, true, true ), + new TargetInfo( "armeb", "ARM (big endian)", true, true, true ), + new TargetInfo( "arm", "ARM", true, true, true ), + new TargetInfo( "amdgcn", "AMD GCN GPUs", true, false, true ), + new TargetInfo( "r600", "AMD GPUs HD2XXX-HD6XXX", true, false, true ), + new TargetInfo( "aarch64_be", "AArch64 (big endian)", true, true, true ), + new TargetInfo( "aarch64", "AArch64 (little endian)", true, true, true ), + new TargetInfo( "arm64", "ARM64 (little endian)", true, true, true ) + }; + } + + /*internal string GenerateExpectedTargets( ) + { + var bldr = new System.Text.StringBuilder( "public static TargetInfoCollection ExpectedTargets = new TargetInfoCollection {" ); + bldr.AppendLine( ); + var targets = System.Linq.Enumerable.ToList( Target.AvailableTargets ); + for( int i = 0; i < targets.Count; ++i ) + { + var target = targets[ i ]; + bldr.AppendFormat( " new TargetInfo( \"{0}\", \"{1}\", {2}, {3}, {4} )" + , target.Name + , target.Description + , target.HasAsmBackEnd.ToString( ).ToLowerInvariant( ) + , target.HasJIT.ToString( ).ToLowerInvariant( ) + , target.HasTargetMachine.ToString( ).ToLowerInvariant( ) + ); + var lastEntry = i == targets.Count - 1; + bldr.AppendLine( lastEntry ? string.Empty : "," ); + } + + bldr.AppendLine( "};" ); + return bldr.ToString( ); + } + */ + } +} \ No newline at end of file diff --git a/src/Llvm.NETTests/TestDebugInfo/Properties/AssemblyInfo.cs b/src/Llvm.NETTests/TestDebugInfo/Properties/AssemblyInfo.cs deleted file mode 100644 index 1ca68ed7d..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle( "TestDebugInfo" )] -[assembly: AssemblyDescription( "" )] -[assembly: AssemblyConfiguration( "" )] -[assembly: AssemblyCompany( "" )] -[assembly: AssemblyProduct( "TestDebugInfo" )] -[assembly: AssemblyCopyright( "Copyright © 2015" )] -[assembly: AssemblyTrademark( "" )] -[assembly: AssemblyCulture( "" )] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible( false )] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid( "f9914a60-2e4b-472f-b1f3-bd08fd23ca92" )] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion( "1.0.0.0" )] -[assembly: AssemblyFileVersion( "1.0.0.0" )] diff --git a/src/Llvm.NETTests/TestDebugInfo/TestDebugInfo.csproj b/src/Llvm.NETTests/TestDebugInfo/TestDebugInfo.csproj deleted file mode 100644 index 52467f8c4..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/TestDebugInfo.csproj +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - Debug - x64 - {F9914A60-2E4B-472F-B1F3-BD08FD23CA92} - Exe - Properties - TestDebugInfo - TestDebugInfo - v4.6.2 - 512 - - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - false - false - - - bin\x64\Release\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - false - - - - - - true - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - - - - - {0162c8ce-6641-4922-8664-f8a44356fbf7} - Llvm.NET - - - {6c77a7de-d464-430f-96a9-a64768763b5f} - LibLLVM - false - True - - - - - - - - - - \ No newline at end of file diff --git a/src/Llvm.NETTests/TestDebugInfo/TestInline.cmd b/src/Llvm.NETTests/TestDebugInfo/TestInline.cmd deleted file mode 100644 index c8d8392ad..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/TestInline.cmd +++ /dev/null @@ -1,5 +0,0 @@ -llvm-as -verify-debug-info NeverInlined.ll -if %ERRORLEVEL% NEQ 0 goto :EOF -llvm-dis -o=neverInlined-dis.ll NeverInlined.bc -if %ERRORLEVEL% NEQ 0 goto :EOF -llc.exe -filetype=obj NeverInlined.bc \ No newline at end of file diff --git a/src/Llvm.NETTests/TestDebugInfo/TestInline.cpp b/src/Llvm.NETTests/TestDebugInfo/TestInline.cpp deleted file mode 100644 index 46585dd2d..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/TestInline.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "TestInline.h" - -extern "C" -{ - int NotInlined( int NotInlinedArg1, int NotInlinedArg2 ) - { - int NotInlinedLocal = NotInlinedArg1 / Random( ); - return InlineDepth1( NotInlinedLocal, NotInlinedArg2 ); - } -} \ No newline at end of file diff --git a/src/Llvm.NETTests/TestDebugInfo/X64Details.cs b/src/Llvm.NETTests/TestDebugInfo/X64Details.cs deleted file mode 100644 index 782c68bb4..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/X64Details.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using Llvm.NET; -using Llvm.NET.Types; -using Llvm.NET.Values; - -namespace TestDebugInfo -{ - class X64Details - : ITargetDependentDetails - { - public string Cpu => "x86-64"; - public string Features => "+sse,+sse2"; - public string ShortName => "x86"; - public string Triple => "x86_64-pc-windows-msvc18.0.0"; - - public void AddABIAttributesForByValueStructure( Function function, int paramIndex ) - { - var argType = function.Parameters[ paramIndex ].NativeType as IPointerType; - if( argType == null || !argType.ElementType.IsStruct ) - throw new ArgumentException( "Signature for specified parameter must be a pointer to a structure" ); - } - - public void AddModuleFlags( NativeModule module ) - { - module.AddModuleFlag( ModuleFlagBehavior.Error, "PIC Level", 2 ); - } - - public AttributeSet BuildTargetDependentFunctionAttributes( Context ctx ) - { - var bldr = new AttributeBuilder( ); - - bldr.Add( "disable-tail-calls", "false" ); - bldr.Add( "less-precise-fpmad", "false" ); - bldr.Add( "no-frame-pointer-elim", "false" ); - bldr.Add( "no-infs-fp-math", "false" ); - bldr.Add( "no-nans-fp-math", "false" ); - bldr.Add( "stack-protector-buffer-size", "8" ); - bldr.Add( "target-cpu", Cpu ); - bldr.Add( "target-features", Features ); - bldr.Add( "unsafe-fp-math", "false" ); - bldr.Add( "use-soft-float", "false" ); - bldr.Add( AttributeKind.UWTable ); - return bldr.ToAttributeSet( FunctionAttributeIndex.Function, ctx ); - } - } -} \ No newline at end of file diff --git a/src/Llvm.NETTests/TestDebugInfo/test.cpp b/src/Llvm.NETTests/TestDebugInfo/test.cpp deleted file mode 100644 index db7948019..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -namespace Test -{ - struct foo - { - int a; - float b; - int c[32]; - }; - - foo bar = { 1, 2.0, { 0 } }; - foo baz; - - inline static void copy( foo const src // function line here - , foo* pDst - ) - { // function's ScopeLine here - *pDst = src; - } - - void OtherSig( foo& rSrc, foo* pDst ) - { - copy( rSrc, pDst ); - } - - void DoCopy( ) - { - copy( bar, &baz ); - } - - extern "C" int Add( int x, int y ) - { - return x+y; - } -} \ No newline at end of file diff --git a/src/Llvm.NETTests/TestDebugInfo/test2.cpp b/src/Llvm.NETTests/TestDebugInfo/test2.cpp deleted file mode 100644 index 480127be2..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/test2.cpp +++ /dev/null @@ -1,37 +0,0 @@ -namespace outerns -{ - namespace innerns - { - class foo - { - public: - foo( int offset ); - int add( int a, int b ); - - private: - int m_offset; - }; - } -} - -static outerns::innerns::foo adder( 3 ); - -extern "C" int SimpleAdd( int a, int b ) -{ - return a + b; -} - -extern "C" int AdderAdd( int a, int b ) -{ - return adder.add( a, b ); -} - -outerns::innerns::foo::foo( int offset ) -{ - m_offset = offset; -} - -int outerns::innerns::foo::add( int a, int b ) -{ - return SimpleAdd( a, b ) + m_offset; -} diff --git a/src/Llvm.NETTests/TestDebugInfo/testex.cpp b/src/Llvm.NETTests/TestDebugInfo/testex.cpp deleted file mode 100644 index be0f9522c..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/testex.cpp +++ /dev/null @@ -1,47 +0,0 @@ -namespace outerns -{ - namespace innerns - { - class foo - { - public: - foo( int offset ); - int add( int a, int b ); - - private: - int m_offset; - }; - } -} - -static outerns::innerns::foo adder( 3 ); - -extern "C" int SimpleAdd( int a, int b ) -{ - if( a > b ) - throw a; - - return a + b; -} - -extern "C" int AdderAdd( int a, int b ) -{ - try - { - return adder.add( a, b ); - } - catch( int x ) - { - return x; - } -} - -outerns::innerns::foo::foo( int offset ) -{ - m_offset = offset; -} - -int outerns::innerns::foo::add( int a, int b ) -{ - return SimpleAdd( a, b ) + m_offset; -} diff --git a/src/Llvm.NETTests/TestDebugInfo/testinline.h b/src/Llvm.NETTests/TestDebugInfo/testinline.h deleted file mode 100644 index e60c20ffa..000000000 --- a/src/Llvm.NETTests/TestDebugInfo/testinline.h +++ /dev/null @@ -1,13 +0,0 @@ -extern "C" int Random(); - -inline int InlineDepth2( int inlineDepth2Arg1, int inlineDepth2Arg2 ) -{ - int xFactor = Random( ); - return inlineDepth2Arg1 + inlineDepth2Arg2 + xFactor; -} - -inline int InlineDepth1( int inlineDepth1Arg1, int inlineDepth1Arg2 ) -{ - int inlineDepth1Local = inlineDepth1Arg2 + Random( ); - return InlineDepth2( inlineDepth1Arg1, inlineDepth1Local ); -} diff --git a/src/Llvm.NETTests/LLVM.NETTests/TestModuleAsString.ll b/src/Llvm.NETTests/TestModuleAsString.ll similarity index 100% rename from src/Llvm.NETTests/LLVM.NETTests/TestModuleAsString.ll rename to src/Llvm.NETTests/TestModuleAsString.ll diff --git a/src/Llvm.NETTests/LLVM.NETTests/TripleTests.cs b/src/Llvm.NETTests/TripleTests.cs similarity index 60% rename from src/Llvm.NETTests/LLVM.NETTests/TripleTests.cs rename to src/Llvm.NETTests/TripleTests.cs index a8a843138..ad4ba2102 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/TripleTests.cs +++ b/src/Llvm.NETTests/TripleTests.cs @@ -1,7 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Llvm.NET.Tests { @@ -13,7 +11,7 @@ public void TripleTest( ) { // nonsensical, but syntactically valid triple var triple = new Triple( "thumbv7m-pc-cuda-eabicoff" ); - Assert.AreEqual( TripleArchType.thumb, triple.ArchitectureType ); + Assert.AreEqual( TripleArchType.Thumb, triple.ArchitectureType ); Assert.AreEqual( TripleSubArchType.ARMSubArch_v7m, triple.SubArchitecture ); Assert.AreEqual( TripleVendorType.PC, triple.VendorType ); Assert.AreEqual( TripleOSType.CUDA, triple.OSType ); @@ -27,12 +25,12 @@ public void ToStringTest( ) // constructor should parse and normalize the triple // so that ToString() retrieves the normalized form var triple = new Triple( "thumbv7m-none-eabi" ); - var str = triple.ToString( ); + string str = triple.ToString( ); Assert.AreEqual( "thumbv7m-none--eabi", str ); } [TestMethod] - public void OpEqualsTest() + public void OpEqualsTest( ) { // constructor should parse and normalize the triple // so that ToString() retrieves the normalized form @@ -46,61 +44,61 @@ public void OpEqualsTest() [TestMethod] public void GetArchTypeNameTest( ) { - Dictionary values - = new Dictionary + var values = new Dictionary { - { TripleArchType.UnknownArch, "unknown"}, - { TripleArchType.aarch64, "aarch64"}, - { TripleArchType.aarch64_be, "aarch64_be"}, - { TripleArchType.arm, "arm"}, - { TripleArchType.armeb, "armeb"}, - { TripleArchType.avr, "avr"}, - { TripleArchType.bpfel, "bpfel"}, - { TripleArchType.bpfeb, "bpfeb"}, - { TripleArchType.hexagon, "hexagon"}, - { TripleArchType.mips, "mips"}, - { TripleArchType.mipsel, "mipsel"}, - { TripleArchType.mips64, "mips64"}, - { TripleArchType.mips64el, "mips64el"}, - { TripleArchType.msp430, "msp430"}, - { TripleArchType.ppc64, "powerpc64"}, - { TripleArchType.ppc64le, "powerpc64le"}, - { TripleArchType.ppc, "powerpc"}, - { TripleArchType.r600, "r600"}, - { TripleArchType.amdgcn, "amdgcn"}, - { TripleArchType.sparc, "sparc"}, - { TripleArchType.sparcv9, "sparcv9"}, - { TripleArchType.sparcel, "sparcel"}, - { TripleArchType.systemz, "s390x"}, - { TripleArchType.tce, "tce"}, - { TripleArchType.thumb, "thumb"}, - { TripleArchType.thumbeb, "thumbeb"}, - { TripleArchType.x86, "i386"}, - { TripleArchType.x86_64, "x86_64"}, - { TripleArchType.xcore, "xcore"}, - { TripleArchType.nvptx, "nvptx"}, - { TripleArchType.nvptx64, "nvptx64"}, - { TripleArchType.le32, "le32"}, - { TripleArchType.le64, "le64"}, - { TripleArchType.amdil, "amdil"}, - { TripleArchType.amdil64, "amdil64"}, - { TripleArchType.hsail, "hsail"}, - { TripleArchType.hsail64, "hsail64"}, - { TripleArchType.spir, "spir"}, - { TripleArchType.spir64, "spir64"}, - { TripleArchType.kalimba, "kalimba"}, - { TripleArchType.lanai, "lanai"}, - { TripleArchType.shave, "shave"}, - { TripleArchType.wasm32, "wasm32"}, - { TripleArchType.wasm64, "wasm64"}, - { TripleArchType.renderscript32, "renderscript32"}, - { TripleArchType.renderscript64, "renderscript64"}, + { TripleArchType.UnknownArch, "unknown" }, + { TripleArchType.Aarch64, "aarch64" }, + { TripleArchType.Aarch64_be, "aarch64_be" }, + { TripleArchType.Arm, "arm" }, + { TripleArchType.Armeb, "armeb" }, + { TripleArchType.Avr, "avr" }, + { TripleArchType.BPFel, "bpfel" }, + { TripleArchType.BPFeb, "bpfeb" }, + { TripleArchType.Hexagon, "hexagon" }, + { TripleArchType.MIPS, "mips" }, + { TripleArchType.MIPSel, "mipsel" }, + { TripleArchType.MIPS64, "mips64" }, + { TripleArchType.MIPS64el, "mips64el" }, + { TripleArchType.MSP430, "msp430" }, + { TripleArchType.PPC64, "powerpc64" }, + { TripleArchType.PPC64le, "powerpc64le" }, + { TripleArchType.PPC, "powerpc" }, + { TripleArchType.R600, "r600" }, + { TripleArchType.AMDGCN, "amdgcn" }, + { TripleArchType.Sparc, "sparc" }, + { TripleArchType.Sparcv9, "sparcv9" }, + { TripleArchType.Sparcel, "sparcel" }, + { TripleArchType.SystemZ, "s390x" }, + { TripleArchType.TCE, "tce" }, + { TripleArchType.Thumb, "thumb" }, + { TripleArchType.Thumbeb, "thumbeb" }, + { TripleArchType.X86, "i386" }, + { TripleArchType.X86_64, "x86_64" }, + { TripleArchType.Xcore, "xcore" }, + { TripleArchType.Nvptx, "nvptx" }, + { TripleArchType.Nvptx64, "nvptx64" }, + { TripleArchType.Le32, "le32" }, + { TripleArchType.Le64, "le64" }, + { TripleArchType.Amdil, "amdil" }, + { TripleArchType.Amdil64, "amdil64" }, + { TripleArchType.Hsail, "hsail" }, + { TripleArchType.Hsail64, "hsail64" }, + { TripleArchType.Spir, "spir" }, + { TripleArchType.Spir64, "spir64" }, + { TripleArchType.Kalimba, "kalimba" }, + { TripleArchType.Lanai, "lanai" }, + { TripleArchType.Shave, "shave" }, + { TripleArchType.Wasm32, "wasm32" }, + { TripleArchType.Wasm64, "wasm64" }, + { TripleArchType.Renderscript32, "renderscript32" }, + { TripleArchType.Renderscript64, "renderscript64" }, }; foreach( var kvp in values ) { Assert.AreEqual( kvp.Value, Triple.GetCanonicalName( kvp.Key ) ); } + Assert.AreEqual( values[ TripleArchType.UnknownArch ], Triple.GetCanonicalName( ( TripleArchType )0x12345678 ) ); } @@ -113,6 +111,7 @@ public void GetSubArchTypeNameTest( ) { TripleSubArchType.ARMSubArch_v8_2a, "v8.2a" }, { TripleSubArchType.ARMSubArch_v8_1a, "v8.1a" }, { TripleSubArchType.ARMSubArch_v8, "v8" }, + { TripleSubArchType.ARMSubArch_v8r, "v8r" }, { TripleSubArchType.ARMSubArch_v8m_baseline, "v8m.base" }, { TripleSubArchType.ARMSubArch_v8m_mainline, "v8m.main" }, { TripleSubArchType.ARMSubArch_v7, "v7" }, @@ -141,68 +140,69 @@ public void GetSubArchTypeNameTest( ) } [TestMethod] - public void GetVendorTypeNameTest() + public void GetVendorTypeNameTest( ) { var values = new Dictionary { - { TripleVendorType.UnknownVendor, "unknown"}, - { TripleVendorType.Apple, "apple"}, - { TripleVendorType.PC, "pc"}, - { TripleVendorType.SCEI, "scei"}, - { TripleVendorType.BGP, "bgp"}, - { TripleVendorType.BGQ, "bgq"}, - { TripleVendorType.Freescale, "fsl"}, - { TripleVendorType.IBM, "ibm"}, - { TripleVendorType.ImaginationTechnologies, "img"}, - { TripleVendorType.MipsTechnologies, "mti"}, - { TripleVendorType.NVIDIA, "nvidia"}, - { TripleVendorType.CSR, "csr"}, - { TripleVendorType.Myriad, "myriad"}, - { TripleVendorType.AMD, "amd"}, - { TripleVendorType.Mesa, "mesa"}, + { TripleVendorType.UnknownVendor, "unknown" }, + { TripleVendorType.Apple, "apple" }, + { TripleVendorType.PC, "pc" }, + { TripleVendorType.SCEI, "scei" }, + { TripleVendorType.BGP, "bgp" }, + { TripleVendorType.BGQ, "bgq" }, + { TripleVendorType.Freescale, "fsl" }, + { TripleVendorType.IBM, "ibm" }, + { TripleVendorType.ImaginationTechnologies, "img" }, + { TripleVendorType.MipsTechnologies, "mti" }, + { TripleVendorType.NVIDIA, "nvidia" }, + { TripleVendorType.CSR, "csr" }, + { TripleVendorType.Myriad, "myriad" }, + { TripleVendorType.AMD, "amd" }, + { TripleVendorType.Mesa, "mesa" }, }; foreach( var kvp in values ) { Assert.AreEqual( kvp.Value, Triple.GetCanonicalName( kvp.Key ) ); } + Assert.AreEqual( values[ TripleVendorType.UnknownVendor ], Triple.GetCanonicalName( ( TripleVendorType )0x12345678 ) ); } [TestMethod] - public void GetOsTypeNameTest() + public void GetOsTypeNameTest( ) { var values = new Dictionary { - { TripleOSType.UnknownOS, "unknown"}, - { TripleOSType.CloudABI, "cloudabi"}, - { TripleOSType.Darwin, "darwin"}, - { TripleOSType.DragonFly, "dragonfly"}, - { TripleOSType.FreeBSD, "freebsd"}, - { TripleOSType.IOS, "ios"}, - { TripleOSType.KFreeBSD, "kfreebsd"}, - { TripleOSType.Linux, "linux"}, - { TripleOSType.Lv2, "lv2"}, - { TripleOSType.MacOSX, "macosx"}, - { TripleOSType.NetBSD, "netbsd"}, - { TripleOSType.OpenBSD, "openbsd"}, - { TripleOSType.Solaris, "solaris"}, - { TripleOSType.Win32, "windows"}, - { TripleOSType.Haiku, "haiku"}, - { TripleOSType.Minix, "minix"}, - { TripleOSType.RTEMS, "rtems"}, - { TripleOSType.NaCl, "nacl"}, - { TripleOSType.CNK, "cnk"}, - { TripleOSType.Bitrig, "bitrig"}, - { TripleOSType.AIX, "aix"}, - { TripleOSType.CUDA, "cuda"}, - { TripleOSType.NVCL, "nvcl"}, - { TripleOSType.AMDHSA, "amdhsa"}, - { TripleOSType.PS4, "ps4"}, - { TripleOSType.ELFIAMCU, "elfiamcu"}, - { TripleOSType.TvOS, "tvos"}, - { TripleOSType.WatchOS, "watchos"}, - { TripleOSType.Mesa3D, "mesa3d"}, + { TripleOSType.UnknownOS, "unknown" }, + { TripleOSType.CloudABI, "cloudabi" }, + { TripleOSType.Darwin, "darwin" }, + { TripleOSType.DragonFly, "dragonfly" }, + { TripleOSType.FreeBSD, "freebsd" }, + { TripleOSType.IOS, "ios" }, + { TripleOSType.KFreeBSD, "kfreebsd" }, + { TripleOSType.Linux, "linux" }, + { TripleOSType.Lv2, "lv2" }, + { TripleOSType.MacOSX, "macosx" }, + { TripleOSType.NetBSD, "netbsd" }, + { TripleOSType.OpenBSD, "openbsd" }, + { TripleOSType.Solaris, "solaris" }, + { TripleOSType.Win32, "windows" }, + { TripleOSType.Haiku, "haiku" }, + { TripleOSType.Minix, "minix" }, + { TripleOSType.RTEMS, "rtems" }, + { TripleOSType.NaCl, "nacl" }, + { TripleOSType.CNK, "cnk" }, + { TripleOSType.Bitrig, "bitrig" }, + { TripleOSType.AIX, "aix" }, + { TripleOSType.CUDA, "cuda" }, + { TripleOSType.NVCL, "nvcl" }, + { TripleOSType.AMDHSA, "amdhsa" }, + { TripleOSType.PS4, "ps4" }, + { TripleOSType.ELFIAMCU, "elfiamcu" }, + { TripleOSType.TvOS, "tvos" }, + { TripleOSType.WatchOS, "watchos" }, + { TripleOSType.Mesa3D, "mesa3d" }, }; foreach( var kvp in values ) @@ -214,28 +214,28 @@ public void GetOsTypeNameTest() } [TestMethod] - public void GetEnvironmentTypeNameTest() + public void GetEnvironmentTypeNameTest( ) { var values = new Dictionary { - { TripleEnvironmentType.UnknownEnvironment, "unknown"}, - { TripleEnvironmentType.GNU, "gnu"}, - { TripleEnvironmentType.GNUABI64, "gnuabi64"}, - { TripleEnvironmentType.GNUEABIHF, "gnueabihf"}, - { TripleEnvironmentType.GNUEABI, "gnueabi"}, - { TripleEnvironmentType.GNUX32, "gnux32"}, - { TripleEnvironmentType.CODE16, "code16"}, - { TripleEnvironmentType.EABI, "eabi"}, - { TripleEnvironmentType.EABIHF, "eabihf"}, - { TripleEnvironmentType.Android, "android"}, - { TripleEnvironmentType.Musl, "musl"}, - { TripleEnvironmentType.MuslEABI, "musleabi"}, - { TripleEnvironmentType.MuslEABIHF, "musleabihf"}, - { TripleEnvironmentType.MSVC, "msvc"}, - { TripleEnvironmentType.Itanium, "itanium"}, - { TripleEnvironmentType.Cygnus, "cygnus"}, - { TripleEnvironmentType.AMDOpenCL, "amdopencl"}, - { TripleEnvironmentType.CoreCLR, "coreclr"} + { TripleEnvironmentType.UnknownEnvironment, "unknown" }, + { TripleEnvironmentType.GNU, "gnu" }, + { TripleEnvironmentType.GNUABI64, "gnuabi64" }, + { TripleEnvironmentType.GNUEABIHF, "gnueabihf" }, + { TripleEnvironmentType.GNUEABI, "gnueabi" }, + { TripleEnvironmentType.GNUX32, "gnux32" }, + { TripleEnvironmentType.CODE16, "code16" }, + { TripleEnvironmentType.EABI, "eabi" }, + { TripleEnvironmentType.EABIHF, "eabihf" }, + { TripleEnvironmentType.Android, "android" }, + { TripleEnvironmentType.Musl, "musl" }, + { TripleEnvironmentType.MuslEABI, "musleabi" }, + { TripleEnvironmentType.MuslEABIHF, "musleabihf" }, + { TripleEnvironmentType.MSVC, "msvc" }, + { TripleEnvironmentType.Itanium, "itanium" }, + { TripleEnvironmentType.Cygnus, "cygnus" }, + { TripleEnvironmentType.AMDOpenCL, "amdopencl" }, + { TripleEnvironmentType.CoreCLR, "coreclr" } }; foreach( var kvp in values ) @@ -246,7 +246,7 @@ public void GetEnvironmentTypeNameTest() Assert.AreEqual( values[ TripleEnvironmentType.UnknownEnvironment ], Triple.GetCanonicalName( ( TripleEnvironmentType )0x12345678 ) ); } - public void GetObjFormatTypeNameTest() + public void GetObjFormatTypeNameTest( ) { var values = new Dictionary { @@ -262,6 +262,5 @@ public void GetObjFormatTypeNameTest() Assert.AreSame( string.Empty, Triple.GetCanonicalName( ( TripleObjectFormatType )0x12345678 ) ); } - } } \ No newline at end of file diff --git a/src/Llvm.NETTests/LLVM.NETTests/Values/AttributeValueTests.cs b/src/Llvm.NETTests/Values/AttributeValueTests.cs similarity index 62% rename from src/Llvm.NETTests/LLVM.NETTests/Values/AttributeValueTests.cs rename to src/Llvm.NETTests/Values/AttributeValueTests.cs index b60728e96..d4c1c0c00 100644 --- a/src/Llvm.NETTests/LLVM.NETTests/Values/AttributeValueTests.cs +++ b/src/Llvm.NETTests/Values/AttributeValueTests.cs @@ -1,5 +1,4 @@ -using Llvm.NETTests; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Llvm.NET.Values.Tests { @@ -8,40 +7,19 @@ public class AttributeValueTests { private const string TestTargetDependentAttributeName = "TestCustom"; - [TestMethod] - public void AttributeValueTest( ) - { - var value = new AttributeValue( ); - Assert.IsFalse( value.IntegerValue.HasValue ); - Assert.IsFalse( value.IsEnum ); - Assert.IsFalse( value.IsInt ); - Assert.IsFalse( value.IsString ); - Assert.IsNull( value.Name ); - Assert.IsNull( value.StringValue ); - Assert.AreEqual( AttributeKind.None, value.Kind ); - } - - [TestMethod] - [ExpectedArgumentException("context", ExpectedExceptionMessage = "Provided context cannot be null or disposed")] - public void AttributeValueConstructorNoContextTest( ) - { - var value = new AttributeValue( null, AttributeKind.AlwaysInline ); - } - [TestMethod] public void AttributeValueTestEnum( ) { using( var ctx = new Context( ) ) { - var value = new AttributeValue(ctx, AttributeKind.AlwaysInline ); + var value = ctx.CreateAttribute( AttributeKind.AlwaysInline ); Assert.IsFalse( value.IntegerValue.HasValue ); Assert.IsFalse( value.IsInt ); Assert.IsFalse( value.IsString ); - Assert.IsNull( value.Name ); + Assert.AreEqual( "alwaysinline", value.Name ); Assert.IsNull( value.StringValue ); Assert.IsTrue( value.IsEnum ); - Assert.IsTrue( value.Kind.HasValue ); - Assert.AreEqual( AttributeKind.AlwaysInline, value.Kind.Value ); + Assert.AreEqual( AttributeKind.AlwaysInline, value.Kind ); } } @@ -50,15 +28,14 @@ public void AttributeValueEnumInt( ) { using( var ctx = new Context( ) ) { - var value = new AttributeValue(ctx, AttributeKind.DereferenceableOrNull, 1234ul ); + var value = ctx.CreateAttribute( AttributeKind.DereferenceableOrNull, 1234ul ); Assert.IsTrue( value.IntegerValue.HasValue ); Assert.IsTrue( value.IsInt ); Assert.IsFalse( value.IsString ); - Assert.IsNull( value.Name ); + Assert.AreEqual( "dereferenceable_or_null", value.Name ); Assert.IsNull( value.StringValue ); Assert.IsTrue( value.IsEnum ); - Assert.IsTrue( value.Kind.HasValue ); - Assert.AreEqual( AttributeKind.DereferenceableOrNull, value.Kind.Value ); + Assert.AreEqual( AttributeKind.DereferenceableOrNull, value.Kind ); Assert.AreEqual( value.IntegerValue, 1234ul ); } } @@ -68,14 +45,14 @@ public void AttributeValueEnumString( ) { using( var ctx = new Context( ) ) { - var value = new AttributeValue( ctx, TestTargetDependentAttributeName ); + var value = ctx.CreateAttribute( TestTargetDependentAttributeName ); Assert.IsFalse( value.IntegerValue.HasValue ); Assert.IsFalse( value.IsInt ); Assert.IsTrue( value.IsString ); Assert.AreEqual( TestTargetDependentAttributeName, value.Name ); Assert.IsTrue( string.IsNullOrWhiteSpace( value.StringValue ) ); Assert.IsFalse( value.IsEnum ); - Assert.IsFalse( value.Kind.HasValue ); + Assert.AreEqual( AttributeKind.None, value.Kind ); } } @@ -84,15 +61,14 @@ public void ImplicitCastAttributeKindToAttributeValueTest() { using( var ctx = new Context( ) ) { - AttributeValue value = AttributeKind.NoInline.ToAttributeValue( ctx ); + AttributeValue value = ctx.CreateAttribute( AttributeKind.NoInline ); Assert.IsFalse( value.IntegerValue.HasValue ); Assert.IsFalse( value.IsInt ); Assert.IsFalse( value.IsString ); - Assert.IsNull( value.Name ); + Assert.AreEqual( "noinline", value.Name ); Assert.IsNull( value.StringValue ); Assert.IsTrue( value.IsEnum ); - Assert.IsTrue( value.Kind.HasValue ); - Assert.AreEqual( AttributeKind.NoInline, value.Kind.Value ); + Assert.AreEqual( AttributeKind.NoInline, value.Kind ); } } @@ -101,14 +77,14 @@ public void ImplicitCastStringToAttributeValueTest( ) { using( var ctx = new Context( ) ) { - AttributeValue value = TestTargetDependentAttributeName.ToAttributeValue( ctx ); + AttributeValue value = ctx.CreateAttribute( TestTargetDependentAttributeName ); Assert.IsFalse( value.IntegerValue.HasValue ); Assert.IsFalse( value.IsInt ); Assert.IsTrue( value.IsString ); Assert.AreEqual( TestTargetDependentAttributeName, value.Name ); Assert.IsTrue( string.IsNullOrWhiteSpace( value.StringValue ) ); Assert.IsFalse( value.IsEnum ); - Assert.IsFalse( value.Kind.HasValue ); + Assert.AreEqual( AttributeKind.None, value.Kind ); } } diff --git a/src/NugetPkg/Llvm.NET.nuspec b/src/NugetPkg/Llvm.NET.nuspec deleted file mode 100644 index 44d07e5b5..000000000 --- a/src/NugetPkg/Llvm.NET.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - Llvm.NET - $buildversion$ - Microsoft Corporation,LLVM.org - false - .NET Bindings for LLVM - LLVM - - - - - - - - - - \ No newline at end of file diff --git a/src/NugetPkg/build/Llvm.NET.targets b/src/NugetPkg/build/Llvm.NET.targets deleted file mode 100644 index cc284f2ae..000000000 --- a/src/NugetPkg/build/Llvm.NET.targets +++ /dev/null @@ -1,21 +0,0 @@ - - - - - LibLLVM\x64\LibLLVM.dll - Always - - - LibLLVM\x64\LibLLVM.pdb - Always - - - LibLLVM\x86\LibLLVM.dll - Always - - - LibLLVM\x86\LibLLVM.pdb - Always - - -