[tools/mprog7] Add ability to read input litmus test from stdin - #1980
[tools/mprog7] Add ability to read input litmus test from stdin#1980fsestini wants to merge 4 commits into
Conversation
| Misc.iter_argv_or_stdin | ||
| (fun fname -> | ||
| try X.zyva fname with | ||
| | Misc.Exit -> () |
There was a problem hiding this comment.
I've removed this line as I did not understand why it was there: no code path downstream of mprog7 seems to be raising Misc.Exit, and even if it does, I'm not sure it's a good idea to silently swallow the exception anyway.
There was a problem hiding this comment.
Well, I do not know if the handler is appropriate, probably not. The usual reaction to Misc.Exit is not doing anything, assuming that the error has been flagged before, or that there is no error to flag, See tools/mnames.ml for an example of the second possibility.
| | e -> | ||
| Printf.eprintf "\nFatal: %a Adios\n" Pos.pp_pos0 fname ; | ||
| raise e) |
There was a problem hiding this comment.
I've removed this as generally I'm not a fan of catch-all branches, and this branch doesn't seem to really add much to the error it catches, in terms of error message. In fact, catching and rethrowing exceptions risks garbling the stack trace of the original exception, which makes debugging more difficult.
There was a problem hiding this comment.
I agree with deleting this handler. Notice that OCaml stack traces shoud remain understandable here: signaling that the exception is "re-raised".
There was a problem hiding this comment.
Yes, I was being overly pedantic here. While stack trace preservation is somewhat heuristic and not guaranteed in all scenarios, the compiler should be smart enough in this particular case, as you correctly point out.
This PR adds the conventional
-operand tomprog7for reading one litmus test from standard input. For example:$ cat ./tools/tests/mprog/stdin.t/A.litmus AArch64 A {} P0; MOV X0,#1; exists (0:X0=1) $ cat ./tools/tests/mprog/stdin.t/A.litmus | mprog7 -mode text - AArch64 A { } P0 ; MOV X0,#1 ; exists (0:X0=1)This functionality can be quite handy when using
mprog7as a litmus test formatter, for example within an editor like vim.-or positional arguments, stdin is interpreted as a list of filenames.-may be used alongside file paths.-can only be specified at most once.-read from a filename list (be it from stdin or from a@listfile) is interpreted as a literal filename.-o DIRis specified, the litmus test read from stdin input is saved asDIR/stdin.litmus.This PR updates the input mechanism of
mprog7to support the new stdin operand and brings its batch error handling in line with conventional CLI behaviour. Previously, errors associated with an individual input were reported but not reflected in the exit code, so a batch could finish with status zero even when one or more inputs had failed. With this PR,mprog7now retains its useful behaviour of continuing batch processing of multiple inputs, while recording whether any input failed and returning status1after the batch if so. Command-line errors and failures encountered while opening an@listcontinue to return status2.