From 4f1903aa4582f5cd96a91f168e4e9c5fb42a6136 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Thu, 11 Apr 2024 21:52:38 +0300 Subject: [PATCH] (compiler) Add `-c` flag for "compile and assemble only" This commit is a small step towards #454. By adding this flag, it's possible to "use Perlang as a transpiler" only. Okay, a _little_ more than a transpiler, since it also emits ELF object files. :) But still, it helps us towards a state where we can gradually, incrementally rewrite parts of the Perlang compiler in Perlang. Oh, the joy! Oh, the glory! --- Perlang.sln | 2 +- release-notes/v0.5.0.md | 3 + src/Perlang.ConsoleApp/Program.cs | 69 ++++++++++++++++++- .../Compiler/PerlangCompiler.cs | 62 +++++++++++++++-- 4 files changed, 129 insertions(+), 7 deletions(-) diff --git a/Perlang.sln b/Perlang.sln index d68cb03a..50a2704f 100644 --- a/Perlang.sln +++ b/Perlang.sln @@ -29,7 +29,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perlang.Tests.Architecture" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perlang.Compiler", "src\Perlang.Compiler\Perlang.Compiler.csproj", "{7E7CF7BF-F792-49C9-BB16-67FE856D8D51}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{47B4A37F-6999-4510-9815-418E03D7B39E}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Items", "_Solution Items", "{47B4A37F-6999-4510-9815-418E03D7B39E}" ProjectSection(SolutionItems) = preProject README.md = README.md EndProjectSection diff --git a/release-notes/v0.5.0.md b/release-notes/v0.5.0.md index c069787e..1af3ccd3 100644 --- a/release-notes/v0.5.0.md +++ b/release-notes/v0.5.0.md @@ -7,6 +7,7 @@ - `BigInt::pow`: Detect negative exponents and throw an exception [[#450][450]] - Implement initial native `ASCIIString` class [[#451][451]] - Wrap `ASCIIString` in `std::shared_ptr` [[#453][453]] +- Add `-c` flag for "compile and assemble only" [[#455][455]] ### Changed #### Data types @@ -27,3 +28,5 @@ [449]: https://github.com/perlang-org/perlang/pull/449 [450]: https://github.com/perlang-org/perlang/pull/450 [451]: https://github.com/perlang-org/perlang/pull/451 +[453]: https://github.com/perlang-org/perlang/pull/453 +[455]: https://github.com/perlang-org/perlang/pull/455 diff --git a/src/Perlang.ConsoleApp/Program.cs b/src/Perlang.ConsoleApp/Program.cs index 0409a157..f4d32e4f 100644 --- a/src/Perlang.ConsoleApp/Program.cs +++ b/src/Perlang.ConsoleApp/Program.cs @@ -121,6 +121,7 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console) { var versionOption = new Option(new[] { "--version", "-v" }, "Show version information"); var detailedVersionOption = new Option("-V", "Show detailed version information"); + var compileAndAssembleOnlyOption = new Option("-c", "Compile and assemble to a .o file, but do not produce and execute an executable"); var printOption = new Option("-p", "Parse a single-line script and output a human-readable version of the AST") { ArgumentHelpName = "script" }; var noWarnAsErrorOption = new Option("-Wno-error", "Treats specified warning as a warning instead of an error.") { ArgumentHelpName = "error" }; @@ -143,6 +144,7 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console) { versionOption, detailedVersionOption, + compileAndAssembleOnlyOption, printOption, noWarnAsErrorOption }; @@ -200,9 +202,32 @@ public static int MainWithCustomConsole(string[] args, IPerlangConsole console) // TODO: Tried to fix this using some logic in the rootCommand.AddValidator() lambda, but I // TODO: couldn't get it working. Since this is going to be rewritten in Perlang at some point // TODO: anyway, let's not spend too much time thinking about it. - Console.Error.WriteLine("One of the -p