diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..6e8466aa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: csharp +mono: none +dotnet: 2.0.0 +dist: trusty +solution: LLVMSharp.sln + +cache: + apt: true + +script: + - dotnet restore + - dotnet build diff --git a/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj b/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj index 8d8a8d6c..fa9a0425 100644 --- a/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj +++ b/KaleidoscopeTutorial/Chapter3/Kaleidoscope/Kaleidoscope.csproj @@ -1,67 +1,16 @@  - - - - Debug - AnyCPU - {CD23CB2E-951B-4FAD-A4CD-4048731DBA31} - Library - Properties - Kaleidoscope - Kaleidoscope - v4.0 - 0e4b5d39 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x64 - bin\x64\Debug\ - - - x64 - bin\x64\Release\ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Debug + AnyCPU + {CD23CB2E-951B-4FAD-A4CD-4048731DBA31} + Library + Properties + Kaleidoscope + Kaleidoscope + netcoreapp2.0 + 0e4b5d39 + 512 + + \ No newline at end of file diff --git a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/CodeGenVisitor.cs b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/CodeGenVisitor.cs index d0e150de..f5aa974a 100644 --- a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/CodeGenVisitor.cs +++ b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/CodeGenVisitor.cs @@ -1,10 +1,10 @@ -namespace KaleidoscopeLLVM -{ - using System; - using System.Collections.Generic; - using Kaleidoscope.AST; - using LLVMSharp; +using System; +using System.Collections.Generic; +using Kaleidoscope.AST; +using LLVMSharp; +namespace KaleidoscopeLLVM +{ internal sealed class CodeGenVisitor : ExprVisitor { private static readonly LLVMBool LLVMBoolFalse = new LLVMBool(0); @@ -25,7 +25,7 @@ public CodeGenVisitor(LLVMModuleRef module, LLVMBuilderRef builder) this.builder = builder; } - public Stack ResultStack { get { return this.valueStack; } } + public Stack ResultStack { get { return valueStack; } } public void ClearResultStack() { @@ -109,7 +109,7 @@ protected override ExprAST VisitCallExprAST(CallExprAST node) argsV[i] = this.valueStack.Pop(); } - this.valueStack.Push(LLVM.BuildCall(this.builder, calleeF, out argsV[0], argumentCount, "calltmp")); + valueStack.Push(LLVM.BuildCall(this.builder, calleeF, argsV, "calltmp")); return node; } @@ -145,7 +145,7 @@ protected override ExprAST VisitPrototypeAST(PrototypeAST node) arguments[i] = LLVM.DoubleType(); } - function = LLVM.AddFunction(this.module, node.Name, LLVM.FunctionType(LLVM.DoubleType(), out arguments[0], argumentCount, LLVMBoolFalse)); + function = LLVM.AddFunction(this.module, node.Name, LLVM.FunctionType(LLVM.DoubleType(), arguments, LLVMBoolFalse)); LLVM.SetLinkage(function, LLVMLinkage.LLVMExternalLinkage); } diff --git a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj index 45f0113d..2beb8cb9 100644 --- a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj +++ b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj @@ -1,6 +1,5 @@  - - + Debug AnyCPU @@ -9,76 +8,24 @@ Properties KaleidoscopeLLVM KaleidoscopeLLVM - v4.5 + netcoreapp2.0 512 b8df454a - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x64 - bin\x64\Debug\ - - - x64 - bin\x64\Release\ - - - - ..\ConsoleApplication4\packages\LLVMSharp.3.5.5\lib\net40\LLVMSharp.dll - - - - - - - - - - - - {cd23cb2e-951b-4fad-a4cd-4048731dba31} - Kaleidoscope - + - - + - + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + Other similar extension points exist, see Microsoft.Common.targets. + + + + + --> \ No newline at end of file diff --git a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Program.cs b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Program.cs index 3def7e35..91acc031 100644 --- a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Program.cs +++ b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Program.cs @@ -16,11 +16,14 @@ private static void Main(string[] args) // Install standard binary operators. // 1 is lowest precedence. - var binopPrecedence = new Dictionary(); - binopPrecedence['<'] = 10; - binopPrecedence['+'] = 20; - binopPrecedence['-'] = 20; - binopPrecedence['*'] = 40; // highest. + var binopPrecedence = new Dictionary + { + ['<'] = 10, + ['+'] = 20, + ['-'] = 20, + ['*'] = 40 + }; + // highest. var scanner = new Lexer(Console.In, binopPrecedence); var parser = new Parser(scanner, codeGenlistener); diff --git a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Properties/AssemblyInfo.cs b/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Properties/AssemblyInfo.cs deleted file mode 100644 index 0a12ae4b..00000000 --- a/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -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("KaleidoscopeLLVM")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("KaleidoscopeLLVM")] -[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("930a7cbb-ed7c-46ea-8f2b-00fb94522b8a")] - -// 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/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj b/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj index 8d8a8d6c..00d09ca4 100644 --- a/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj +++ b/KaleidoscopeTutorial/Chapter4/Kaleidoscope/Kaleidoscope.csproj @@ -1,67 +1,14 @@  - - - - Debug - AnyCPU - {CD23CB2E-951B-4FAD-A4CD-4048731DBA31} - Library - Properties - Kaleidoscope - Kaleidoscope - v4.0 - 0e4b5d39 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x64 - bin\x64\Debug\ - - - x64 - bin\x64\Release\ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Debug + AnyCPU + {CD23CB2E-951B-4FAD-A4CD-4048731DBA31} + Library + Properties + Kaleidoscope + Kaleidoscope + netcoreapp2.0 + 0e4b5d39 + \ No newline at end of file diff --git a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/CodeGenVisitor.cs b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/CodeGenVisitor.cs index d0e150de..13eeaa07 100644 --- a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/CodeGenVisitor.cs +++ b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/CodeGenVisitor.cs @@ -25,7 +25,7 @@ public CodeGenVisitor(LLVMModuleRef module, LLVMBuilderRef builder) this.builder = builder; } - public Stack ResultStack { get { return this.valueStack; } } + public Stack ResultStack => valueStack; public void ClearResultStack() { @@ -109,7 +109,7 @@ protected override ExprAST VisitCallExprAST(CallExprAST node) argsV[i] = this.valueStack.Pop(); } - this.valueStack.Push(LLVM.BuildCall(this.builder, calleeF, out argsV[0], argumentCount, "calltmp")); + this.valueStack.Push(LLVM.BuildCall(this.builder, calleeF, argsV, "calltmp")); return node; } @@ -145,13 +145,13 @@ protected override ExprAST VisitPrototypeAST(PrototypeAST node) arguments[i] = LLVM.DoubleType(); } - function = LLVM.AddFunction(this.module, node.Name, LLVM.FunctionType(LLVM.DoubleType(), out arguments[0], argumentCount, LLVMBoolFalse)); + function = LLVM.AddFunction(this.module, node.Name, LLVM.FunctionType(LLVM.DoubleType(), arguments, LLVMBoolFalse)); LLVM.SetLinkage(function, LLVMLinkage.LLVMExternalLinkage); } for (int i = 0; i < argumentCount; ++i) { - string argumentName = node.Arguments[i]; + var argumentName = node.Arguments[i]; LLVMValueRef param = LLVM.GetParam(function, (uint)i); LLVM.SetValueName(param, argumentName); @@ -165,18 +165,18 @@ protected override ExprAST VisitPrototypeAST(PrototypeAST node) protected override ExprAST VisitFunctionAST(FunctionAST node) { - this.namedValues.Clear(); + namedValues.Clear(); - this.Visit(node.Proto); + Visit(node.Proto); - LLVMValueRef function = this.valueStack.Pop(); + LLVMValueRef function = valueStack.Pop(); // Create a new basic block to start insertion into. - LLVM.PositionBuilderAtEnd(this.builder, LLVM.AppendBasicBlock(function, "entry")); + LLVM.PositionBuilderAtEnd(builder, LLVM.AppendBasicBlock(function, "entry")); try { - this.Visit(node.Body); + Visit(node.Body); } catch (Exception) { @@ -185,12 +185,12 @@ protected override ExprAST VisitFunctionAST(FunctionAST node) } // Finish off the function. - LLVM.BuildRet(this.builder, this.valueStack.Pop()); + LLVM.BuildRet(builder, valueStack.Pop()); // Validate the generated code, checking for consistency. LLVM.VerifyFunction(function, LLVMVerifierFailureAction.LLVMPrintMessageAction); - this.valueStack.Push(function); + valueStack.Push(function); return node; } diff --git a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj index 45f0113d..918c0038 100644 --- a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj +++ b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj @@ -1,6 +1,5 @@  - - + Debug AnyCPU @@ -9,76 +8,14 @@ Properties KaleidoscopeLLVM KaleidoscopeLLVM - v4.5 + netcoreapp2.0 512 b8df454a - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x64 - bin\x64\Debug\ - - - x64 - bin\x64\Release\ - - - - ..\ConsoleApplication4\packages\LLVMSharp.3.5.5\lib\net40\LLVMSharp.dll - - - - - - - - - - - - - {cd23cb2e-951b-4fad-a4cd-4048731dba31} - Kaleidoscope - - - - + - + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Program.cs b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Program.cs index aeb76b1a..53ba73b8 100644 --- a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Program.cs +++ b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Program.cs @@ -8,23 +8,23 @@ public sealed class Program { + public delegate double D(); + private static void Main(string[] args) { // Make the module, which holds all the code. LLVMModuleRef module = LLVM.ModuleCreateWithName("my cool jit"); LLVMBuilderRef builder = LLVM.CreateBuilder(); - LLVM.LinkInJIT(); + LLVM.LinkInMCJIT(); LLVM.InitializeX86TargetInfo(); LLVM.InitializeX86Target(); LLVM.InitializeX86TargetMC(); - LLVMExecutionEngineRef engine; - IntPtr errorMessage; - if (LLVM.CreateExecutionEngineForModule(out engine, module, out errorMessage).Value == 1) + if (LLVM.CreateExecutionEngineForModule(out var engine, module, out var errorMessage).Value == 1) { - Console.WriteLine(Marshal.PtrToStringAnsi(errorMessage)); - LLVM.DisposeMessage(errorMessage); + Console.WriteLine(errorMessage); + // LLVM.DisposeMessage(errorMessage); return; } @@ -33,7 +33,7 @@ private static void Main(string[] args) // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - LLVM.AddTargetData(LLVM.GetExecutionEngineTargetData(engine), passManager); + LLVM.DisposeTargetData(LLVM.GetExecutionEngineTargetData(engine)); // Provide basic AliasAnalysis support for GVN. LLVM.AddBasicAliasAnalysisPass(passManager); @@ -59,11 +59,14 @@ private static void Main(string[] args) // Install standard binary operators. // 1 is lowest precedence. - var binopPrecedence = new Dictionary(); - binopPrecedence['<'] = 10; - binopPrecedence['+'] = 20; - binopPrecedence['-'] = 20; - binopPrecedence['*'] = 40; // highest. + var binopPrecedence = new Dictionary + { + ['<'] = 10, + ['+'] = 20, + ['-'] = 20, + ['*'] = 40 + }; + // highest. var scanner = new Lexer(Console.In, binopPrecedence); var parser = new Parser(scanner, codeGenlistener); diff --git a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Properties/AssemblyInfo.cs b/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Properties/AssemblyInfo.cs deleted file mode 100644 index 0a12ae4b..00000000 --- a/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -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("KaleidoscopeLLVM")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("KaleidoscopeLLVM")] -[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("930a7cbb-ed7c-46ea-8f2b-00fb94522b8a")] - -// 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/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj b/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj index 81d03023..b16f1ccb 100644 --- a/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj +++ b/KaleidoscopeTutorial/Chapter5/Kaleidoscope/Kaleidoscope.csproj @@ -1,69 +1,15 @@  - - - - Debug - AnyCPU - {CD23CB2E-951B-4FAD-A4CD-4048731DBA31} - Library - Properties - Kaleidoscope - Kaleidoscope - v4.0 - 0e4b5d39 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x64 - bin\x64\Debug\ - - - x64 - bin\x64\Release\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + {CD23CB2E-951B-4FAD-A4CD-4048731DBA31} + Library + Properties + Kaleidoscope + Kaleidoscope + netcoreapp2.0 + 0e4b5d39 + \ No newline at end of file diff --git a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/CodeGenVisitor.cs b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/CodeGenVisitor.cs index 7eb96727..46dea6e0 100644 --- a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/CodeGenVisitor.cs +++ b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/CodeGenVisitor.cs @@ -25,7 +25,7 @@ public CodeGenVisitor(LLVMModuleRef module, LLVMBuilderRef builder) this.builder = builder; } - public Stack ResultStack { get { return this.valueStack; } } + public Stack ResultStack { get { return valueStack; } } public void ClearResultStack() { @@ -109,7 +109,7 @@ protected override ExprAST VisitCallExprAST(CallExprAST node) argsV[i] = this.valueStack.Pop(); } - this.valueStack.Push(LLVM.BuildCall(this.builder, calleeF, out argsV[0], argumentCount, "calltmp")); + valueStack.Push(LLVM.BuildCall(this.builder, calleeF, argsV, "calltmp")); return node; } @@ -145,7 +145,7 @@ protected override ExprAST VisitPrototypeAST(PrototypeAST node) arguments[i] = LLVM.DoubleType(); } - function = LLVM.AddFunction(this.module, node.Name, LLVM.FunctionType(LLVM.DoubleType(), out arguments[0], argumentCount, LLVMBoolFalse)); + function = LLVM.AddFunction(this.module, node.Name, LLVM.FunctionType(LLVM.DoubleType(), arguments, LLVMBoolFalse)); LLVM.SetLinkage(function, LLVMLinkage.LLVMExternalLinkage); } @@ -237,8 +237,8 @@ protected override ExprAST VisitIfExprAST(IfExpAST node) LLVM.PositionBuilderAtEnd(this.builder, mergeBB); var phi = LLVM.BuildPhi(this.builder, LLVM.DoubleType(), "iftmp"); - LLVM.AddIncoming(phi, out thenV, out thenBB, 1); - LLVM.AddIncoming(phi, out elseV, out elseBB, 1); + LLVM.AddIncoming(phi, new []{thenV}, new []{thenBB}, 1); + LLVM.AddIncoming(phi, new []{elseV}, new []{elseBB}, 1); this.valueStack.Push(phi); @@ -280,8 +280,8 @@ protected override ExprAST VisitForExprAST(ForExprAST node) LLVM.PositionBuilderAtEnd(this.builder, loopBB); // Start the PHI node with an entry for Start. - var variable = LLVM.BuildPhi(this.builder, LLVM.DoubleType(), node.VarName); - LLVM.AddIncoming(variable, out startVal, out preheaderBB, 1); + var variable = LLVM.BuildPhi(builder, LLVM.DoubleType(), node.VarName); + LLVM.AddIncoming(variable, new []{startVal}, new []{preheaderBB}, 1); // Within the loop, the variable is defined equal to the PHI node. If it // shadows an existing variable, we have to restore it, so save it now. @@ -298,14 +298,14 @@ protected override ExprAST VisitForExprAST(ForExprAST node) // Emit the body of the loop. This, like any other expr, can change the // current BB. Note that we ignore the value computed by the body, but don't // allow an error. - this.Visit(node.Body); + Visit(node.Body); // Emit the step value. LLVMValueRef stepVal; if (node.Step != null) { - this.Visit(node.Step); - stepVal = this.valueStack.Pop(); + Visit(node.Step); + stepVal = valueStack.Pop(); } else { @@ -313,36 +313,36 @@ protected override ExprAST VisitForExprAST(ForExprAST node) stepVal = LLVM.ConstReal(LLVM.DoubleType(), 1.0); } - LLVMValueRef nextVar = LLVM.BuildFAdd(this.builder, variable, stepVal, "nextvar"); + LLVMValueRef nextVar = LLVM.BuildFAdd(builder, variable, stepVal, "nextvar"); // Compute the end condition. - this.Visit(node.End); - LLVMValueRef endCond = LLVM.BuildFCmp(this.builder, LLVMRealPredicate.LLVMRealONE, this.valueStack.Pop(), LLVM.ConstReal(LLVM.DoubleType(), 0.0), "loopcond"); + Visit(node.End); + LLVMValueRef endCond = LLVM.BuildFCmp(builder, LLVMRealPredicate.LLVMRealONE, valueStack.Pop(), LLVM.ConstReal(LLVM.DoubleType(), 0.0), "loopcond"); // Create the "after loop" block and insert it. - var loopEndBB = LLVM.GetInsertBlock(this.builder); + var loopEndBB = LLVM.GetInsertBlock(builder); var afterBB = LLVM.AppendBasicBlock(function, "afterloop"); // Insert the conditional branch into the end of LoopEndBB. - LLVM.BuildCondBr(this.builder, endCond, loopBB, afterBB); + LLVM.BuildCondBr(builder, endCond, loopBB, afterBB); // Any new code will be inserted in AfterBB. - LLVM.PositionBuilderAtEnd(this.builder, afterBB); + LLVM.PositionBuilderAtEnd(builder, afterBB); // Add a new entry to the PHI node for the backedge. - LLVM.AddIncoming(variable, out nextVar, out loopEndBB, 1); + LLVM.AddIncoming(variable, new []{nextVar}, new []{loopEndBB}, 1); // Restore the unshadowed variable. if (oldVal.Pointer != IntPtr.Zero) { - this.namedValues[node.VarName] = oldVal; + namedValues[node.VarName] = oldVal; } else { - this.namedValues.Remove(node.VarName); + namedValues.Remove(node.VarName); } - this.valueStack.Push(LLVM.ConstReal(LLVM.DoubleType(), 0.0)); + valueStack.Push(LLVM.ConstReal(LLVM.DoubleType(), 0.0)); return node; } diff --git a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj index 45f0113d..05e2f638 100644 --- a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj +++ b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj @@ -1,6 +1,5 @@  - - + Debug AnyCPU @@ -9,76 +8,17 @@ Properties KaleidoscopeLLVM KaleidoscopeLLVM - v4.5 + netcoreapp2.0 512 b8df454a - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - x64 - bin\x64\Debug\ - - - x64 - bin\x64\Release\ - - - - ..\ConsoleApplication4\packages\LLVMSharp.3.5.5\lib\net40\LLVMSharp.dll - - - - - - - - - - - - {cd23cb2e-951b-4fad-a4cd-4048731dba31} - Kaleidoscope - + - - + - + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Program.cs b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Program.cs index b3fc0214..c8badd87 100644 --- a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Program.cs +++ b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Program.cs @@ -21,12 +21,10 @@ private static void Main(string[] args) LLVM.InitializeX86Target(); LLVM.InitializeX86TargetMC(); - LLVMExecutionEngineRef engine; - IntPtr errorMessage; - if (LLVM.CreateExecutionEngineForModule(out engine, module, out errorMessage).Value == 1) + if (LLVM.CreateExecutionEngineForModule(out var engine, module, out var errorMessage).Value == 1) { - Console.WriteLine(Marshal.PtrToStringAnsi(errorMessage)); - LLVM.DisposeMessage(errorMessage); + Console.WriteLine(errorMessage); + // LLVM.DisposeMessage(errorMessage); return; } @@ -35,7 +33,7 @@ private static void Main(string[] args) // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - LLVM.AddTargetData(LLVM.GetExecutionEngineTargetData(engine), passManager); + LLVM.DisposeTargetData(LLVM.GetExecutionEngineTargetData(engine)); // Provide basic AliasAnalysis support for GVN. LLVM.AddBasicAliasAnalysisPass(passManager); @@ -61,11 +59,14 @@ private static void Main(string[] args) // Install standard binary operators. // 1 is lowest precedence. - var binopPrecedence = new Dictionary(); - binopPrecedence['<'] = 10; - binopPrecedence['+'] = 20; - binopPrecedence['-'] = 20; - binopPrecedence['*'] = 40; // highest. + var binopPrecedence = new Dictionary + { + ['<'] = 10, + ['+'] = 20, + ['-'] = 20, + ['*'] = 40 + }; + // highest. var scanner = new Lexer(Console.In, binopPrecedence); var parser = new Parser(scanner, codeGenlistener); diff --git a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Properties/AssemblyInfo.cs b/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Properties/AssemblyInfo.cs deleted file mode 100644 index 0a12ae4b..00000000 --- a/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -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("KaleidoscopeLLVM")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("KaleidoscopeLLVM")] -[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("930a7cbb-ed7c-46ea-8f2b-00fb94522b8a")] - -// 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")]