-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the --extractTarget option into a command (#5799)
Touchup PR for #5621 ### Description - Change the --extractTarget option into a hidden command - Make `--help` work when used on hidden commandds ### How has this been tested? - Ran `make extract` in DafnyCore <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
- Loading branch information
1 parent
38db1b8
commit 0b44740
Showing
6 changed files
with
71 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#nullable enable | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using DafnyDriver.Commands; | ||
using Microsoft.Boogie; | ||
using Microsoft.Dafny.Compilers; | ||
|
||
namespace Microsoft.Dafny; | ||
|
||
public static class ExtractCommand { | ||
public static Command Create() { | ||
|
||
var result = new Command("extract", "Can be used to generate DafnyPrelude.bpl. Uses the ':extract_boogie_name' attribute to rename symbols. Turns lemmas into universally quantified axioms, as opposed to verify which turns them into Boogie procedures. When translating Dafny expressions to Boogie ones, no well-formedness checks are created."); | ||
|
||
result.IsHidden = true; | ||
result.AddArgument(Target); | ||
result.AddArgument(DafnyCommands.FilesArgument); | ||
foreach (var option in ExtractOptions) { | ||
result.AddOption(option); | ||
} | ||
DafnyNewCli.SetHandlerUsingDafnyOptionsContinuation(result, (options, _) => HandleExtraction(options)); | ||
return result; | ||
} | ||
|
||
private static readonly Argument<FileInfo> Target = new("The path of the extracted file."); | ||
|
||
private static IReadOnlyList<Option> ExtractOptions => | ||
new Option[] { }. | ||
Concat(DafnyCommands.ConsoleOutputOptions). | ||
Concat(DafnyCommands.ResolverOptions); | ||
|
||
public static async Task<int> HandleExtraction(DafnyOptions options) { | ||
if (options.Get(CommonOptionBag.VerificationCoverageReport) != null) { | ||
options.TrackVerificationCoverage = true; | ||
} | ||
|
||
var compilation = CliCompilation.Create(options); | ||
compilation.Start(); | ||
|
||
var resolution = await compilation.Resolution; | ||
if (resolution is not { HasErrors: false }) { | ||
return await compilation.GetAndReportExitCode(); | ||
} | ||
|
||
var outputPath = options.Get(Target).FullName; | ||
using var engine = ExecutionEngine.CreateWithoutSharedCache(options); | ||
try { | ||
var extractedProgram = BoogieExtractor.Extract(resolution.ResolvedProgram); | ||
engine.PrintBplFile(outputPath, extractedProgram, true, pretty: true); | ||
} catch (ExtractorError extractorError) { | ||
await options.OutputWriter.WriteLineAsync($"Boogie axiom extraction error: {extractorError.Message}"); | ||
return 1; | ||
} | ||
|
||
return await compilation.GetAndReportExitCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters