@@ -64,7 +64,7 @@ The tutorials have been tested to run on Windows and Linux, however the build (u
64
64
``` csharp
65
65
using System ;
66
66
using System .Runtime .InteropServices ;
67
- using LLVMSharp ;
67
+ using LLVMSharp . Interop ;
68
68
69
69
internal sealed class Program
70
70
{
@@ -73,21 +73,20 @@ The tutorials have been tested to run on Windows and Linux, however the build (u
73
73
74
74
private static void Main (string [] args )
75
75
{
76
- LLVMBool Success = new LLVMBool (0 );
77
- LLVMModuleRef mod = LLVM .ModuleCreateWithName (" LLVMSharpIntro" );
76
+ LLVMModuleRef mod = LLVMModuleRef .CreateWithName (" LLVMSharpIntro" );
78
77
79
- LLVMTypeRef [] param_types = { LLVM . Int32Type (), LLVM . Int32Type () };
80
- LLVMTypeRef ret_type = LLVM . FunctionType ( LLVM . Int32Type () , param_types , false );
81
- LLVMValueRef sum = LLVM .AddFunction (mod , " sum" , ret_type );
78
+ LLVMTypeRef [] param_types = new LLVMTypeRef [ 2 ] { LLVMTypeRef . Int32 , LLVMTypeRef . Int32 };
79
+ LLVMTypeRef ret_type = LLVMTypeRef . CreateFunction ( LLVMTypeRef . Int32 , param_types );
80
+ LLVMValueRef sum = mod .AddFunction (" sum" , ret_type );
82
81
83
- LLVMBasicBlockRef entry = LLVM .AppendBasicBlock (sum , " entry" );
82
+ LLVMBasicBlockRef entry = sum .AppendBasicBlock (" entry" );
84
83
85
- LLVMBuilderRef builder = LLVM . CreateBuilder ( );
86
- LLVM . PositionBuilderAtEnd ( builder , entry );
87
- LLVMValueRef tmp = LLVM .BuildAdd (builder , LLVM . GetParam ( sum , 0 ), LLVM . GetParam ( sum , 1 ) , " tmp" );
88
- LLVM .BuildRet (builder , tmp );
84
+ LLVMBuilderRef builder = LLVMBuilderRef . Create ( mod . Context );
85
+ builder . PositionAtEnd ( entry );
86
+ LLVMValueRef tmp = builder .BuildAdd (sum . Params [ 0 ], sum . Params [ 1 ] , " tmp" );
87
+ builder .BuildRet (tmp );
89
88
90
- if (LLVM . VerifyModule ( mod , LLVMVerifierFailureAction .LLVMPrintMessageAction , out var error ) != Success )
89
+ if (! mod . TryVerify ( LLVMVerifierFailureAction .LLVMPrintMessageAction , out var error ))
91
90
{
92
91
Console .WriteLine ($" Error: {error }" );
93
92
}
@@ -101,26 +100,24 @@ The tutorials have been tested to run on Windows and Linux, however the build (u
101
100
LLVM .InitializeX86AsmPrinter ();
102
101
103
102
LLVMMCJITCompilerOptions options = new LLVMMCJITCompilerOptions { NoFramePointerElim = 1 };
104
- LLVM .InitializeMCJITCompilerOptions (options );
105
- if (LLVM .CreateMCJITCompilerForModule (out var engine , mod , options , out error ) != Success )
103
+ if (! mod .TryCreateMCJITCompiler (out var engine , ref options , out error ))
106
104
{
107
105
Console .WriteLine ($" Error: {error }" );
108
106
}
109
107
110
- var addMethod = (Add )Marshal .GetDelegateForFunctionPointer (LLVM .GetPointerToGlobal (engine , sum ), typeof (Add ));
108
+ var addMethod = (Add )Marshal .GetDelegateForFunctionPointer (engine .GetPointerToGlobal (sum ), typeof (Add ));
111
109
int result = addMethod (10 , 10 );
112
110
113
111
Console .WriteLine (" Result of sum is: " + result );
114
112
115
- if (LLVM .WriteBitcodeToFile (mod , " sum.bc" ) != 0 )
113
+ if (mod .WriteBitcodeToFile (" sum.bc" ) != 0 )
116
114
{
117
115
Console .WriteLine (" error writing bitcode to file, skipping" );
118
116
}
119
117
120
- LLVM .DumpModule (mod );
121
-
122
- LLVM .DisposeBuilder (builder );
123
- LLVM .DisposeExecutionEngine (engine );
118
+ mod .Dump ();
119
+ builder .Dispose ();
120
+ engine .Dispose ();
124
121
}
125
122
}
126
123
````
0 commit comments