generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 23
Cleanup StrataMain python commands #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewmw94
wants to merge
4
commits into
strata-org:main
Choose a base branch
from
andrewmw94:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,63 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import Strata.DDM.Ion | ||
| import Strata.Util.IO | ||
| import Strata.Languages.Python.Python | ||
| import Strata.Languages.Boogie.Verifier | ||
| import StrataTest.Transform.ProcedureInlining | ||
|
|
||
| namespace Strata.Languages.Python | ||
|
|
||
| structure CommandFlags where | ||
| verbose : Bool := false | ||
| noinline : Bool := false | ||
|
|
||
| def exitFailure {α} (message : String) : IO α := do | ||
| IO.eprintln (message ++ "\n\nRun strata --help for additional help.") | ||
| IO.Process.exit 1 | ||
|
|
||
| def readPythonStrata (path : String) : IO Strata.Program := do | ||
| let bytes ← Strata.Util.readBinInputSource path | ||
| if ! bytes.startsWith Ion.binaryVersionMarker then | ||
| exitFailure s!"pyAnalyze expected Ion file" | ||
| match Strata.Program.fromIon Strata.Python.Python_map Strata.Python.Python.name bytes with | ||
| | .ok p => pure p | ||
| | .error msg => exitFailure msg | ||
|
|
||
| def pyTranslate (path : String) : IO Unit := do | ||
| let pgm ← readPythonStrata path | ||
| let preludePgm := Strata.Python.Internal.Boogie.prelude | ||
| let bpgm := Strata.pythonToBoogie pgm | ||
| let newPgm : Boogie.Program := { decls := preludePgm.decls ++ bpgm.decls } | ||
| IO.print newPgm | ||
|
|
||
| def pyAnalyze (path : String) (flags : CommandFlags) : IO Unit := do | ||
| let verbose := flags.verbose | ||
| let inline := !flags.noinline | ||
| let pgm ← readPythonStrata path | ||
| if verbose then | ||
| IO.print pgm | ||
| let preludePgm := Strata.Python.Internal.Boogie.prelude | ||
| let bpgm := Strata.pythonToBoogie pgm | ||
| let newPgm : Boogie.Program := { decls := preludePgm.decls ++ bpgm.decls } | ||
| if verbose then | ||
| IO.print newPgm | ||
| let newPgm := if inline then runInlineCall newPgm else newPgm | ||
| if verbose && inline then | ||
| IO.println "Inlined: " | ||
| IO.print newPgm | ||
| let vcResults ← EIO.toIO (fun f => IO.Error.userError (toString f)) | ||
| (Boogie.verify "z3" newPgm { Options.default with stopOnFirstError := false, | ||
| verbose, | ||
| removeIrrelevantAxioms := true } | ||
| (moreFns := Strata.Python.ReFactory)) | ||
| let mut s := "" | ||
| for vcResult in vcResults do | ||
| s := s ++ s!"\n{vcResult.obligation.label}: {Std.format vcResult.result}\n" | ||
| IO.println s | ||
|
|
||
| end Strata.Languages.Python |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ for test_file in tests/test_*.py; do | |
| if [ -f "$expected_file" ]; then | ||
| (cd ../../../Tools/Python && python -m strata.gen py_to_strata "../../StrataTest/Languages/Python/$test_file" "../../StrataTest/Languages/Python/$ion_file") | ||
|
|
||
| output=$(cd ../../.. && lake exe strata pyAnalyze --include Tools/Python/test_results/dialects "StrataTest/Languages/Python/${ion_file}" 0) | ||
| output=$(cd ../../.. && lake exe strata pyAnalyze --include Tools/Python/test_results/dialects "StrataTest/Languages/Python/${ion_file}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
|
|
||
| if ! echo "$output" | diff -q "$expected_file" - > /dev/null; then | ||
| echo "ERROR: Analysis output for $base_name does not match expected result" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flagsCallbackseems overly specific to me. How about we having a generic callback that takes the remainingargsas a list of strings? and the functionality between lines 214 and 240 are moved into a standalone function that each callback can invoke?