Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions BuildVersion.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
BuildMajor = "10"
BuildMinor = "0"
BuildPatch = "0"
PreReleaseName = "alpha"
PreReleaseNumber ="3"
PreReleaseName = "rc"
/>
2 changes: 1 addition & 1 deletion Samples/CodeGenWithDebugInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static void Main( string[ ] args )
// The ordering of passes can matter depending on the pass, and passes may be added more than once
// the caller has full control of ordering, this is just a sample of effectively randomly picked
// passes and not necessarily a reflection of any particular use case.
using var pm = new ModulePassManager( );
var pm = new ModulePassManager( );
pm.AddAlwaysInlinerPass( )
.AddAggressiveDCEPass( )
.AddArgumentPromotionPass( )
Expand Down
1 change: 0 additions & 1 deletion Samples/Kaleidoscope/Chapter4/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void Dispose( )
{
JIT.Dispose( );
Module?.Dispose( );
FunctionPassManager?.Dispose( );
Context.Dispose( );
}
#endregion
Expand Down
1 change: 0 additions & 1 deletion Samples/Kaleidoscope/Chapter5/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void Dispose( )
{
JIT.Dispose( );
Module?.Dispose( );
FunctionPassManager?.Dispose( );
Context.Dispose( );
}
#endregion
Expand Down
1 change: 0 additions & 1 deletion Samples/Kaleidoscope/Chapter6/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void Dispose( )
{
JIT.Dispose( );
Module?.Dispose( );
FunctionPassManager?.Dispose( );
Context.Dispose( );
}
#endregion
Expand Down
1 change: 0 additions & 1 deletion Samples/Kaleidoscope/Chapter7.1/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void Dispose( )
{
JIT.Dispose( );
Module?.Dispose( );
FunctionPassManager?.Dispose( );
Context.Dispose( );
}
#endregion
Expand Down
1 change: 0 additions & 1 deletion Samples/Kaleidoscope/Chapter7/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void Dispose( )
{
JIT.Dispose( );
Module?.Dispose( );
FunctionPassManager?.Dispose( );
Context.Dispose( );
}
#endregion
Expand Down
4 changes: 1 addition & 3 deletions Samples/Kaleidoscope/Chapter8/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

using Kaleidoscope.Grammar;
using Kaleidoscope.Grammar.AST;
Expand Down Expand Up @@ -69,7 +68,6 @@ public CodeGenerator( DynamicRuntimeState globalState, TargetMachine machine, bo
public void Dispose( )
{
Module.Dispose( );
FunctionPassManager.Dispose( );
Context.Dispose( );
}
#endregion
Expand Down Expand Up @@ -99,7 +97,7 @@ public OptionalValue<BitcodeModule> Generate( IAstNode ast )
// and inlines each of the anonymous functions directly into main, dropping the now
// unused original anonymous functions all while retaining all of the original source
// debug information locations.
using var mpm = new ModulePassManager( );
var mpm = new ModulePassManager( );
mpm.AddAlwaysInlinerPass( )
.AddGlobalDCEPass( )
.Run( Module );
Expand Down
3 changes: 1 addition & 2 deletions Samples/Kaleidoscope/Chapter9/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public CodeGenerator( DynamicRuntimeState globalState, TargetMachine machine, st
#region Dispose
public void Dispose( )
{
FunctionPassManager?.Dispose( );
Module.Dispose( );
Context.Dispose( );
}
Expand Down Expand Up @@ -109,7 +108,7 @@ public OptionalValue<BitcodeModule> Generate( IAstNode ast )
// and inlines each of the anonymous functions directly into main, dropping the now
// unused original anonymous functions all while retaining all of the original source
// debug information locations.
using var mpm = new ModulePassManager( );
var mpm = new ModulePassManager( );
mpm.AddAlwaysInlinerPass( )
.AddGlobalDCEPass( )
.Run( Module );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

using Antlr4.Runtime;

using Kaleidoscope.Grammar.ANTLR;

using Ubiquity.ArgValidators;

using static Kaleidoscope.Grammar.ANTLR.KaleidoscopeLexer;
Expand Down
7 changes: 7 additions & 0 deletions docfx/current/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ Some APIs had inconsistent, misspelled or confusing names and were updated.
|---------------------------|--------------------------------|---------------|
| BitcodeModule.AddFunction | BitcodeModule.CreateFunction() | The Create vs Add between debug info and raw native was always confusing |

### Types no longer disposable
Some types are no longer disposable. The LLVMObjectRef type uses SafeHandle, which eliminates the need
for Dispose for top level global objects. The following types no longer support IDispose:
* Transforms.ModulePassManager
* Transforms.FunctionPassManager
* ObjectFile.TargetBinary

### Altered Behavior
#### Context.CreateStructType()
As part of resolving [bug #184](https://github.com/UbiquityDotNET/Llvm.NET/issues/184) the CreateStructType
Expand Down
6 changes: 3 additions & 3 deletions docfx/current/Ubiquity.NET.Llvm.Docfx.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<ItemGroup>
<PackageReference Include="docfx.console" PrivateAssets="All" />
<PackageReference Include="memberpage" PrivateAssets="All" GeneratePathProperty="true" />
<PackageReference Include="msdn.4.5.2" PrivateAssets="All" GeneratePathProperty="true" />
<!--PackageReference Include="msdn.4.5.2" PrivateAssets="All" GeneratePathProperty="true" /-->
</ItemGroup>

<Target Name="SetDocFxParameters" BeforeTargets="DocGenerateMetadata">
<ItemGroup>
<DocFxCrossRefMap Include="llvm-xref.yml" />
<DocFxCrossRefMap Include="$(Pkgmsdn_4_5_2)\content\msdn.4.5.2.zip" />
<DocFxCrossRefMap Include="$(Pkgmsdn_4_5_2)\content\namespaces.4.5.2.zip" />
<!--DocFxCrossRefMap Include="$(Pkgmsdn_4_5_2)\content\msdn.4.5.2.zip" />
<DocFxCrossRefMap Include="$(Pkgmsdn_4_5_2)\content\namespaces.4.5.2.zip" /-->
</ItemGroup>
<ItemGroup>
<DocFxTemplate Include="statictoc" />
Expand Down
1 change: 1 addition & 0 deletions docfx/current/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
],
"build": {
"xrefService": ["https://xref.docs.microsoft.com/query?uid={uid}"],
"content": [
{
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Ubiquity.NET.Llvm.DebugInfo;
using Ubiquity.NET.Llvm.Instructions;
using Ubiquity.NET.Llvm.Values;
using Ubiquity.NET.LlvmTests;

namespace Ubiquity.NET.Llvm.Tests.DebugInfo
Expand Down
11 changes: 4 additions & 7 deletions src/Ubiquity.NET.Llvm.Tests/TestObjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
using Ubiquity.NET.Llvm.Instructions;
using Ubiquity.NET.Llvm.Types;

// signatures required by test framework
#pragma warning disable IDE0060 // Remove unused parameter

namespace Ubiquity.NET.Llvm.Tests
{
[TestClass]
Expand Down Expand Up @@ -79,15 +76,15 @@ public static void Initialize( TestContext ctx )
public void LoadObjFileTest( )
{
using var llvmContext = new Context( );
using var obj = llvmContext.OpenBinary( TestObjFileName );
var obj = llvmContext.OpenBinary( TestObjFileName );
}

[TestMethod]
[Description( "All the declared section names should exist" )]
public void DeclaredSectionsTest( )
{
using var llvmContext = new Context( );
using var obj = llvmContext.OpenBinary( TestObjFileName );
var obj = llvmContext.OpenBinary( TestObjFileName );

// all the declared section names should be present (There may be additional obj format specific sections as well)
Assert.IsTrue( obj.Sections.SingleOrDefault( s => s.Name == AddSectionName ) != default );
Expand All @@ -101,7 +98,7 @@ public void DeclaredSectionsTest( )
public void DeclaredSymbolsTest( )
{
using var llvmContext = new Context( );
using var obj = llvmContext.OpenBinary( TestObjFileName );
var obj = llvmContext.OpenBinary( TestObjFileName );

// symbols should be present for all the declared functions
Assert.IsTrue( obj.Symbols.SingleOrDefault( s => s.Name == AddFuncName ) != default );
Expand All @@ -115,7 +112,7 @@ public void DeclaredSymbolsTest( )
public void DeclaredFunctionRelocationTest( )
{
using var llvmContext = new Context( );
using var obj = llvmContext.OpenBinary( TestObjFileName );
var obj = llvmContext.OpenBinary( TestObjFileName );

// all the declared section names should be present (There may be additional obj format specific sections as well)
var declaredSections = from sec in obj.Sections
Expand Down
3 changes: 2 additions & 1 deletion src/Ubiquity.NET.Llvm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Repo Items", "Repo Items",
Push-Nuget.ps1 = Push-Nuget.ps1
..\README.md = ..\README.md
..\.github\workflows\release-build.yml = ..\.github\workflows\release-build.yml
..\docfx\current\ReleaseNotes.md = ..\docfx\current\ReleaseNotes.md
..\stylecop.json = ..\stylecop.json
..\Ubiquity.NET.ruleset = ..\Ubiquity.NET.ruleset
x64.runsettings = x64.runsettings
Expand All @@ -67,7 +68,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter7.1", "..\Samples\Ka
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ubiquity.NET.Llvm.Tests", "Ubiquity.NET.Llvm.Tests\Ubiquity.NET.Llvm.Tests.csproj", "{50AB0DAA-77B1-4C02-9A1F-2C8E7E7D9A88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kaleidoscope.Tests", "..\Samples\Kaleidoscope\Kaleidoscope.Tests\Kaleidoscope.Tests.csproj", "{752FFF38-2B50-4341-ABF5-CCAE013388AE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kaleidoscope.Tests", "..\Samples\Kaleidoscope\Kaleidoscope.Tests\Kaleidoscope.Tests.csproj", "{752FFF38-2B50-4341-ABF5-CCAE013388AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
18 changes: 5 additions & 13 deletions src/Ubiquity.NET.Llvm/BitcodeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
namespace Ubiquity.NET.Llvm
{
/// <summary>Enumeration to indicate the behavior of module level flags metadata sharing the same name in a <see cref="BitcodeModule"/></summary>
[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)" )]
[SuppressMessage( "Design", "CA1027:Mark enums with FlagsAttribute", Justification = "It isn't a flags enum" )]
public enum ModuleFlagBehavior
{
Expand Down Expand Up @@ -288,17 +284,13 @@ public void AppendInlineAsm( string asm )
LLVMAppendModuleInlineAsm( ModuleHandle, asm, string.IsNullOrEmpty( asm ) ? 0 : asm.Length );
}

/// <inheritdoc/>
/// <summary>Disposes the <see cref="BitcodeModule"/>, releasing resources associated with the module in native code</summary>
public void Dispose( )
{
// 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 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( !IsDisposed )
{
// remove the module handle from the module cache.
Expand Down
6 changes: 4 additions & 2 deletions src/Ubiquity.NET.Llvm/ComdatCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ public void Clear( )
/// <returns><see langword="true"/> if the entry is present and <see langword="false"/> if not</returns>
public bool Contains( string key ) => InternalComdatMap.ContainsKey( key );

/// <inheritdoc/>
/// <summary>Gets an enumerator for all the <see cref="Comdat"/>s in the collection</summary>
/// <returns>Enumerator</returns>
public IEnumerator<Comdat> GetEnumerator( ) => InternalComdatMap.Values.GetEnumerator( );

/// <inheritdoc/>
/// <summary>Gets an enumerator for all the <see cref="Comdat"/>s in the collection</summary>
/// <returns>Enumerator</returns>
IEnumerator IEnumerable.GetEnumerator( ) => InternalComdatMap.Values.GetEnumerator( );

/// <summary>Removes a <see cref="Comdat"/> entry from the module</summary>
Expand Down
7 changes: 6 additions & 1 deletion src/Ubiquity.NET.Llvm/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,12 @@ internal Context( LLVMContextRef contextRef )
LLVMContextSetDiagnosticHandler( ContextHandle, ActiveHandler, IntPtr.Zero );
}

/// <inheritdoc />
/// <summary>Disposes the context to release unmanaged resources deterministically</summary>
/// <param name="disposing">Indicates whether this is from a call to Dispose (<see langword="true"/>) or if from a finalizer</param>
/// <remarks>
/// If <paramref name="disposing"/> is <see langword="true"/> then this will release managed and unmanaged resources.
/// Otherwise, this will only release the native/unmanaged resources.
/// </remarks>
protected override void Dispose( bool disposing )
{
// disconnect all modules so that any future critical finalization has no impact
Expand Down
1 change: 0 additions & 1 deletion src/Ubiquity.NET.Llvm/ContextCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Threading;

using Ubiquity.ArgValidators;
using Ubiquity.NET.Llvm.Interop;

namespace Ubiquity.NET.Llvm
Expand Down
8 changes: 3 additions & 5 deletions src/Ubiquity.NET.Llvm/DataLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

using Ubiquity.ArgValidators;
using Ubiquity.NET.Llvm.Interop;
Expand Down Expand Up @@ -200,7 +199,6 @@ public uint PreferredAlignmentOf( Value value )
/// <param name="structType">Type of the structure</param>
/// <param name="offset">Offset to determine the index of</param>
/// <returns>Index of the element</returns>
[SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )]
public uint ElementAtOffset( IStructType structType, ulong offset )
{
VerifySized( structType, nameof( structType ) );
Expand All @@ -211,14 +209,15 @@ public uint ElementAtOffset( IStructType structType, ulong offset )
/// <param name="structType">Type of the structure</param>
/// <param name="element">index of the element in the structure</param>
/// <returns>Offset of the element from the beginning of the structure</returns>
[SuppressMessage( "Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Specific type required by interop call" )]
public ulong OffsetOfElement( IStructType structType, uint element )
{
VerifySized( structType, nameof( structType ) );
return LLVMOffsetOfElement( DataLayoutHandle, structType.GetTypeRef( ), element );
}

/// <inheritdoc/>
/// <summary>Converts the layout to a string representation of the layout data</summary>
/// <returns>Data layout as a string</returns>
/// <seealso href="xref:llvm_langref#data-layout">DICompositeType</seealso>
public override string ToString( ) => LLVMCopyStringRepOfTargetData( DataLayoutHandle );

/// <summary>Gets the byte size of a type</summary>
Expand Down Expand Up @@ -265,7 +264,6 @@ internal static DataLayout FromHandle( LLVMTargetDataRef targetDataRef )

internal LLVMTargetDataRef DataLayoutHandle { get; }

// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
private static void VerifySized( [ValidatedNotNull] ITypeRef type, string name )
{
if( type == null )
Expand Down
2 changes: 0 additions & 2 deletions src/Ubiquity.NET.Llvm/DebugInfo/DIScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// </copyright>
// -----------------------------------------------------------------------

using System;

using Ubiquity.NET.Llvm.Interop;

using static Ubiquity.NET.Llvm.Interop.NativeMethods;
Expand Down
Loading