mpy-cross: When reading from stdin, write output to stdout.

Unless -o is given, output defaults to stdout unless a source file is
given (in which case the source file name is used to derive an output
file name).

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
This commit is contained in:
Armin Brauns 2023-07-14 10:31:33 +00:00 committed by Damien George
parent 6a61e4ecd1
commit 3164749b3d
1 changed files with 3 additions and 2 deletions

View File

@ -90,7 +90,8 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
cm.context = m_new_obj(mp_module_context_t);
mp_compile_to_raw_code(&parse_tree, source_name, false, &cm);
if (output_file != NULL && strcmp(output_file, "-") == 0) {
if ((output_file != NULL && strcmp(output_file, "-") == 0) ||
(output_file == NULL && strcmp(file, "-") == 0)) {
mp_raw_code_save(&cm, (mp_print_t *)&mp_stdout_print);
} else {
vstr_t vstr;
@ -121,7 +122,7 @@ STATIC int usage(char **argv) {
"usage: %s [<opts>] [-X <implopt>] [--] <input filename>\n"
"Options:\n"
"--version : show version information\n"
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
"-o : output file for compiled bytecode (defaults to input filename with .mpy extension, or stdout if input is stdin)\n"
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
"-v : verbose (trace various operations); can be multiple\n"
"-O[N] : apply bytecode optimizations of level N\n"