Skip to content

Commit e457f03

Browse files
authored
More docs and refactorings (#37)
# Breaking changes * The TypeKind enumeration is moved into the Llvm.NET.Types namespace * TripleXXX enumerations all moved into the Triple class as they are exclusive to it and already had "Triple" in the name. # Other Changes * moved enums out of giant gneeric enums.cs * update of docs for enums * more docs for enums * moved enums out of common enumerations.cs file, some of these have moved namespaces but that should have minimal to no impact on consumers as they are moved into namespaces of the classes that use or expose them already. * updated OrcJit to use lazy jit mode. Seems to be at functional parity with MCJit with opion to provide * added full support for USE_ORCJIT conditional compilation flag in chapter 4 to allow evaluating/testing OrcJit * Fix typos * Add docs for Scalar transforms * more doc comments updates * added more use of arg validator helpers to clean up arg checks
1 parent 631a135 commit e457f03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2876
-1374
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
6262
</PropertyGroup>
6363
<ItemGroup Condition="'$(NoCommonAnalyzers)'!='true' and '$(IsTestProject)' != 'true' and '$(SourceLinkEnabled)' != 'false'">
64-
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.5.0" PrivateAssets="All" />
64+
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.6.0" PrivateAssets="All" />
6565
</ItemGroup>
6666
<ItemGroup Condition="'$(NoCommonAnalyzers)'!='true'">
6767
<PackageReference Include="Microsoft.AnalyzerPowerPack" Version="1.1.0" PrivateAssets="All" />

Samples/Kaleidoscope/Chapter4/Chapter4.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<AssemblyName>kls4</AssemblyName>
66
<RootNamespace>Kaleidoscope</RootNamespace>
77
<LangVersion>latest</LangVersion>
8+
<DefineConstants>USE_ORCJIT</DefineConstants>
89
</PropertyGroup>
910

10-
<ItemGroup>
11+
<ItemGroup>
1112
<ProjectReference Include="$(BuildRootDir)src\Llvm.NET\Llvm.NET.csproj">
1213
<Name>Llvm.NET</Name>
1314
</ProjectReference>

Samples/Kaleidoscope/Chapter4/CodeGenerator.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public override Value VisitTopLevelExpression( [NotNull] TopLevelExpressionConte
167167

168168
private void InitializeModuleAndPassManager( )
169169
{
170-
Module = new BitcodeModule( Context, "Kaleidoscope" );
170+
Module = new BitcodeModule( Context );
171171
FunctionPassManager = new FunctionPassManager( Module );
172172
FunctionPassManager.AddInstructionCombiningPass( )
173173
.AddReassociatePass( )
@@ -220,7 +220,13 @@ private Function GetOrDeclareFunction( Prototype prototype, bool isAnonymous = f
220220
return retVal;
221221
}
222222

223+
// Testing experimental OrcJIT support
224+
#if USE_ORCJIT
225+
private (Function Function, Llvm.NET.JIT.OrcJit.OrcJitHandle JitHandle) DefineFunction( Function function, ExpressionContext body )
226+
#else
227+
#pragma warning disable IDE0008
223228
private (Function Function, int JitHandle) DefineFunction( Function function, ExpressionContext body )
229+
#endif
224230
{
225231
if( !function.IsDeclaration )
226232
{
@@ -247,14 +253,14 @@ private Function GetOrDeclareFunction( Prototype prototype, bool isAnonymous = f
247253
Trace.TraceInformation( function.ToString( ) );
248254

249255
FunctionPassManager.Run( function );
250-
int jitHandle = JIT.AddModule( Module );
256+
var jitHandle = JIT.AddModule( Module );
251257
InitializeModuleAndPassManager( );
252258
return (function, jitHandle);
253259
}
254260

255261
/// <summary>Delegate type to allow execution of a JIT'd TopLevelExpression</summary>
256262
/// <returns>Result of evaluating the expression</returns>
257-
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
263+
[UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl )]
258264
private delegate double AnonExpressionFunc( );
259265

260266
private static int AnonNameIndex;

Samples/Kaleidoscope/Chapter4/KaleidoscopeJIT.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// <copyright file="KaleidoscopeJIT.cs" company=".NET Foundation">
22
// Copyright (c) .NET Foundation. All rights reserved.
33
// </copyright>
4-
54
using Llvm.NET;
65
using Llvm.NET.JIT;
76

@@ -10,7 +9,7 @@ namespace Kaleidoscope
109
#if USE_ORCJIT
1110
internal class KaleidoscopeJIT
1211
{
13-
internal KaleidoscopeJIT( )
12+
public KaleidoscopeJIT( )
1413
{
1514
TargetMachine = Target.FromTriple( Triple.HostTriple.ToString( ) )
1615
.CreateTargetMachine(Triple.HostTriple.ToString(), null, null, CodeGenOpt.Default, Reloc.Default, CodeModel.JitDefault );
@@ -20,7 +19,7 @@ internal KaleidoscopeJIT( )
2019

2120
public TargetMachine TargetMachine { get; }
2221

23-
public OrcJit.OrcJitHandle AddModule( BitcodeModule module ) => ExecutionEngine.AddModule( module );
22+
public OrcJit.OrcJitHandle AddModule( BitcodeModule module ) => ExecutionEngine.AddModule( module, ExecutionEngine.DefaultSymbolResolver );
2423

2524
public void RemoveModule( OrcJit.OrcJitHandle moduleHandle ) => ExecutionEngine.RemoveModule( moduleHandle );
2625

@@ -29,7 +28,7 @@ public T GetDelegateForFunction<T>( string name )
2928
return ExecutionEngine.GetFunctionDelegate<T>( name );
3029
}
3130

32-
private OrcJit ExecutionEngine;
31+
private readonly OrcJit ExecutionEngine;
3332
}
3433

3534
#else

Samples/Kaleidoscope/Chapter5/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ private Function GetOrDeclareFunction( Prototype prototype, bool isAnonymous = f
426426

427427
/// <summary>Delegate type to allow execution of a JIT'd TopLevelExpression</summary>
428428
/// <returns>Result of evaluating the expression</returns>
429-
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
429+
[UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl )]
430430
private delegate double AnonExpressionFunc( );
431431

432432
private static int AnonNameIndex;

Samples/Kaleidoscope/Chapter6/CodeGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Diagnostics;
88
using System.Linq;
99
using System.Runtime.InteropServices;
10-
using Antlr4.Runtime;
1110
using Antlr4.Runtime.Misc;
1211
using Kaleidoscope.Grammar;
1312
using Llvm.NET;
@@ -483,7 +482,7 @@ private Function GetOrDeclareFunction( Prototype prototype, bool isAnonymous = f
483482

484483
/// <summary>Delegate type to allow execution of a JIT'd TopLevelExpression</summary>
485484
/// <returns>Result of evaluating the expression</returns>
486-
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
485+
[UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl )]
487486
private delegate double AnonExpressionFunc( );
488487

489488
private static int AnonNameIndex;

Samples/Kaleidoscope/Chapter7/CodeGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Diagnostics;
88
using System.Linq;
99
using System.Runtime.InteropServices;
10-
using Antlr4.Runtime;
1110
using Antlr4.Runtime.Misc;
1211
using Kaleidoscope.Grammar;
1312
using Llvm.NET;
@@ -556,7 +555,7 @@ private static Alloca CreateEntryBlockAlloca( Function theFunction, string varNa
556555

557556
/// <summary>Delegate type to allow execution of a JIT'd TopLevelExpression</summary>
558557
/// <returns>Result of evaluating the expression</returns>
559-
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
558+
[UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl )]
560559
private delegate double AnonExpressionFunc( );
561560

562561
private static int AnonNameIndex;

Samples/Kaleidoscope/Chapter8/CodeGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Diagnostics;
88
using System.Linq;
99
using System.Runtime.InteropServices;
10-
using Antlr4.Runtime;
1110
using Antlr4.Runtime.Misc;
1211
using Kaleidoscope.Grammar;
1312
using Llvm.NET;
@@ -536,7 +535,7 @@ private static Alloca CreateEntryBlockAlloca( Function theFunction, string varNa
536535

537536
/// <summary>Delegate type to allow execution of a JIT'd TopLevelExpression</summary>
538537
/// <returns>Result of evaluating the expression</returns>
539-
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
538+
[UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl )]
540539
private delegate double AnonExpressionFunc( );
541540

542541
private static int AnonNameIndex;

Samples/Kaleidoscope/Chapter9/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ private static Alloca CreateEntryBlockAlloca( Function theFunction, string varNa
618618

619619
/// <summary>Delegate type to allow execution of a JIT'd TopLevelExpression</summary>
620620
/// <returns>Result of evaluating the expression</returns>
621-
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
621+
[UnmanagedFunctionPointer( System.Runtime.InteropServices.CallingConvention.Cdecl )]
622622
private delegate double AnonExpressionFunc( );
623623

624624
private DebugBasicType DoubleType;

Ubiquity.NET.ruleset

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<Rule Id="CA1049" Action="Warning" />
4949
<Rule Id="CA1050" Action="Warning" />
5050
<Rule Id="CA1051" Action="Warning" />
51-
<Rule Id="CA1052" Action="Warning" />
51+
<Rule Id="CA1052" Action="Error" />
5252
<Rule Id="CA1053" Action="Warning" />
5353
<Rule Id="CA1054" Action="Warning" />
5454
<Rule Id="CA1055" Action="Warning" />
@@ -104,7 +104,7 @@
104104
<Rule Id="CA1712" Action="Warning" />
105105
<Rule Id="CA1713" Action="Warning" />
106106
<Rule Id="CA1714" Action="Warning" />
107-
<Rule Id="CA1715" Action="Warning" />
107+
<Rule Id="CA1715" Action="Error" />
108108
<Rule Id="CA1717" Action="Warning" />
109109
<Rule Id="CA1719" Action="Warning" />
110110
<Rule Id="CA1720" Action="Warning" />
@@ -193,7 +193,7 @@
193193
<Rule Id="CA2211" Action="Warning" />
194194
<Rule Id="CA2212" Action="Warning" />
195195
<Rule Id="CA2213" Action="Warning" />
196-
<Rule Id="CA2214" Action="Warning" />
196+
<Rule Id="CA2214" Action="Error" />
197197
<Rule Id="CA2215" Action="Warning" />
198198
<Rule Id="CA2216" Action="Warning" />
199199
<Rule Id="CA2217" Action="Warning" />
@@ -581,6 +581,7 @@
581581
<Rule Id="RECS0083" Action="Error" />
582582
<Rule Id="RECS0129" Action="None" />
583583
<Rule Id="RECS0145" Action="None" />
584+
<Rule Id="RECS0147" Action="Warning" />
584585
</Rules>
585586
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
586587
<Rule Id="SA1000" Action="None" />
@@ -712,16 +713,24 @@
712713
<Rule Id="SA1636" Action="Error" />
713714
<Rule Id="SA1637" Action="Hidden" />
714715
<Rule Id="SA1638" Action="Hidden" />
715-
<Rule Id="SA1640" Action="None" />
716-
<Rule Id="SA1641" Action="None" />
717-
<Rule Id="SA1642" Action="Info" />
718-
<Rule Id="SA1643" Action="Hidden" />
716+
<Rule Id="SA1640" Action="Error" />
717+
<Rule Id="SA1641" Action="Error" />
718+
<Rule Id="SA1642" Action="Error" />
719+
<Rule Id="SA1643" Action="Error" />
719720
<Rule Id="SA1648" Action="Error" />
720721
<Rule Id="SA1649" Action="Error" />
721722
<Rule Id="SA1651" Action="Error" />
722-
<Rule Id="SA1652" Action="Info" />
723+
<Rule Id="SA1652" Action="Warning" />
723724
<Rule Id="SX1101" Action="Error" />
724725
<Rule Id="SX1309" Action="None" />
725726
<Rule Id="SX1309S" Action="None" />
727+
<Rule Id="SA1612" Action="Error" />
728+
</Rules>
729+
<Rules AnalyzerId="Microsoft.AnalyzerPowerPack.CSharp" RuleNamespace="Microsoft.AnalyzerPowerPack.CSharp">
730+
<Rule Id="CA2214" Action="Error" />
731+
</Rules>
732+
<Rules AnalyzerId="Microsoft.AnalyzerPowerPack.Common" RuleNamespace="Microsoft.AnalyzerPowerPack.Common">
733+
<Rule Id="CA1052" Action="Error" />
734+
<Rule Id="CA1715" Action="Error" />
726735
</Rules>
727736
</RuleSet>

0 commit comments

Comments
 (0)