Skip to content

Commit 57058d3

Browse files
authored
Completed internal conversion of all handle interning caches to a common base type/interface pattern. (#40)
## Breaking Changes BitcodeModule is no longer a "newable" type. Creating modules now requires calling factory methods on the context. This is a small but necessary change to clean up internal complexity and clarify the actual ownership via a factory method.
1 parent b86df1c commit 57058d3

29 files changed

+762
-674
lines changed

Samples/CodeGenWithDebugInfo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void Main( string[ ] args )
7171

7272
// <CreatingModule>
7373
using( var context = new Context( ) )
74-
using( var module = new BitcodeModule( context, moduleName ) )
74+
using( var module = context.CreateBitcodeModule( moduleName ) )
7575
{
7676
module.SourceFileName = Path.GetFileName( srcPath );
7777
module.TargetTriple = TargetDetails.TargetMachine.Triple;

Samples/Kaleidoscope/Chapter3/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal sealed class CodeGenerator
2323
public CodeGenerator( LanguageLevel level )
2424
{
2525
Context = new Context( );
26-
Module = new BitcodeModule( Context, "Kaleidoscope" );
26+
Module = Context.CreateBitcodeModule( "Kaleidoscope" );
2727
InstructionBuilder = new InstructionBuilder( Context );
2828
NamedValues = new Dictionary<string, Value>( );
2929
ParserStack = new ReplParserStack( level );

Samples/Kaleidoscope/Chapter4/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
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 );
170+
Module = Context.CreateBitcodeModule( );
171171
FunctionPassManager = new FunctionPassManager( Module );
172172
FunctionPassManager.AddInstructionCombiningPass( )
173173
.AddReassociatePass( )

Samples/Kaleidoscope/Chapter5/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public override Value VisitForExpression( [NotNull] ForExpressionContext context
339339

340340
private void InitializeModuleAndPassManager( )
341341
{
342-
Module = new BitcodeModule( Context, "Kaleidoscope" );
342+
Module = Context.CreateBitcodeModule( "Kaleidoscope" );
343343
FunctionPassManager = new FunctionPassManager( Module );
344344
FunctionPassManager.AddInstructionCombiningPass( )
345345
.AddReassociatePass( )

Samples/Kaleidoscope/Chapter6/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public override Value VisitForExpression( [NotNull] ForExpressionContext context
395395

396396
private void InitializeModuleAndPassManager( )
397397
{
398-
Module = new BitcodeModule( Context, "Kaleidoscope" );
398+
Module = Context.CreateBitcodeModule( "Kaleidoscope" );
399399
FunctionPassManager = new FunctionPassManager( Module );
400400
FunctionPassManager.AddInstructionCombiningPass( )
401401
.AddReassociatePass( )

Samples/Kaleidoscope/Chapter7/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public override Value VisitVarInExpression( [NotNull] VarInExpressionContext con
453453

454454
private void InitializeModuleAndPassManager( )
455455
{
456-
Module = new BitcodeModule( Context, "Kaleidoscope" );
456+
Module = Context.CreateBitcodeModule( "Kaleidoscope" );
457457
FunctionPassManager = new FunctionPassManager( Module );
458458
FunctionPassManager.AddPromoteMemoryToRegisterPass()
459459
.AddInstructionCombiningPass( )

Samples/Kaleidoscope/Chapter8/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public override Value VisitVarInExpression( [NotNull] VarInExpressionContext con
443443

444444
private void InitializeModuleAndPassManager( )
445445
{
446-
Module = new BitcodeModule( Context, "Kaleidoscope" );
446+
Module = Context.CreateBitcodeModule( "Kaleidoscope" );
447447
}
448448

449449
private Function GetFunction( string name )

Samples/Kaleidoscope/Chapter9/CodeGenerator.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ public CodeGenerator( LanguageLevel level, TargetMachine machine )
3333
NamedValues = new Dictionary<string, Alloca>( );
3434
FunctionPrototypes = new PrototypeCollection( );
3535
ParserStack = new ReplParserStack( level );
36-
Module = new BitcodeModule( Context, "Kaleidoscope", SourceLanguage.C, "fib.ks", "Kaleidoscope Compiler" )
37-
{
38-
TargetTriple = machine.Triple,
39-
Layout = machine.TargetData
40-
};
36+
Module = Context.CreateBitcodeModule( "Kaleidoscope", SourceLanguage.C, "fib.ks", "Kaleidoscope Compiler" );
37+
Module.TargetTriple = machine.Triple;
38+
Module.Layout = machine.TargetData;
4139
DoubleType = new DebugBasicType( Context.DoubleType, Module, "double", DiTypeKind.Float );
4240
}
4341

src/Llvm.NET.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27128.1
4+
VisualStudioVersion = 15.0.27130.2003
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llvm.NET", "Llvm.NET\Llvm.NET.csproj", "{0162C8CE-6641-4922-8664-F8A44356FBF7}"
77
EndProject

0 commit comments

Comments
 (0)