For showing codegen, have users specify a pager instead of hardcoding

bat
This commit is contained in:
Bruce Hill 2025-02-21 15:27:59 -05:00
parent a94337bc11
commit ebc4686d60
3 changed files with 30 additions and 23 deletions

18
tomo.1
View File

@ -35,27 +35,31 @@ compiler of your choice.
\f[B]\-h\f[R], \f[B]\-\-help\f[R]
Print the usage and exit.
.TP
\f[B]\-t\f[R]
\f[B]\-t\f[R], \f[B]\-\-transpile\f[R]
Transpile the input files to C code without compiling them.
.TP
\f[B]\-c\f[R]
\f[B]\-c\f[R], \f[B]\-\-compile\-obj\f[R]
Compile the input files to static objects, rather than running them.
.TP
\f[B]\-e\f[R]
\f[B]\-e\f[R], \f[B]\-\-compile\-exe\f[R]
Compile the input file to an executable.
.TP
\f[B]\-L\f[R]
\f[B]\-L\f[R], \f[B]\-\-library\f[R]
Compile the input files to a library \f[B].so\f[R] file and header.
.TP
\f[B]\-I\f[R]
\f[B]\-I\f[R], \f[B]\-\-install\f[R]
Install the compiled executable or library.
.TP
\f[B]\-C\f[R]
Print transpiled C code to the console.
\f[B]\-C\f[R] \f[I]\f[R], \f[B]\-\-show\-codegen\f[R] \f[I]\f[R]
Set a program (e.g.\ \f[B]cat\f[R] or \f[B]bat\f[R]) to display the
generated code
.TP
\f[B]\-\-c\-compiler\f[R]
Set which C compiler is used.
.TP
\f[B]\-O\f[R] \f[B]level\f[R], \f[B]\-\-optimization\f[R] \f[B]level\f[R]
Set the optimization level.
.TP
\f[B]\-v\f[R], \f[B]\-\-verbose\f[R]
Print extra verbose output.
.TP

View File

@ -38,27 +38,30 @@ C code, which is then compiled using a C compiler of your choice.
`-h`, `--help`
: Print the usage and exit.
`-t`
`-t`, `--transpile`
: Transpile the input files to C code without compiling them.
`-c`
`-c`, `--compile-obj`
: Compile the input files to static objects, rather than running them.
`-e`
`-e`, `--compile-exe`
: Compile the input file to an executable.
`-L`
`-L`, `--library`
: Compile the input files to a library `.so` file and header.
`-I`
`-I`, `--install`
: Install the compiled executable or library.
`-C`
: Print transpiled C code to the console.
`-C` *<program>*, `--show-codegen` *<program>*
: Set a program (e.g. `cat` or `bat`) to display the generated code
`--c-compiler`
: Set which C compiler is used.
`-O` **level**, `--optimization` **level**
: Set the optimization level.
`-v`, `--verbose`
: Print extra verbose output.

18
tomo.c
View File

@ -34,7 +34,6 @@ static OptionalArray_t files = NONE_ARRAY,
args = NONE_ARRAY;
static OptionalBool_t verbose = false,
quiet = false,
show_codegen = false,
stop_at_transpile = false,
stop_at_obj_compilation = false,
stop_at_exe_compilation = false,
@ -43,6 +42,7 @@ static OptionalBool_t verbose = false,
uninstall = false;
static OptionalText_t
show_codegen = NONE_TEXT,
cflags = Text("-Werror -fdollars-in-identifiers -std=gnu11 -Wno-trigraphs -fsanitize=signed-integer-overflow -fno-sanitize-recover"
" -fno-signed-zeros -fno-finite-math-only -fno-signaling-nans -fno-trapping-math"
" -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE -fPIC -ggdb"
@ -105,8 +105,8 @@ int main(int argc, char *argv[])
{"u", false, &Bool$info, &uninstall},
{"library", false, &Bool$info, &library_mode},
{"L", false, &Bool$info, &library_mode},
{"show-codegen", false, &Bool$info, &show_codegen},
{"C", false, &Bool$info, &show_codegen},
{"show-codegen", false, &Text$info, &show_codegen},
{"C", false, &Text$info, &show_codegen},
{"install", false, &Bool$info, &should_install},
{"I", false, &Bool$info, &should_install},
{"c-compiler", false, &Text$info, &cc},
@ -522,8 +522,8 @@ void transpile_header(env_t *base_env, Text_t filename, bool force_retranspile)
if (!quiet || verbose)
printf("\x1b[2mTranspiled to %k\x1b[m\n", &h_filename);
if (show_codegen)
system(heap_strf("bat -P %k", &h_filename));
if (show_codegen.length > 0)
system(heap_strf("%k %k", &show_codegen, &h_filename));
}
void transpile_code(env_t *base_env, Text_t filename, bool force_retranspile)
@ -565,8 +565,8 @@ void transpile_code(env_t *base_env, Text_t filename, bool force_retranspile)
if (!quiet || verbose)
printf("\x1b[2mTranspiled to %k\x1b[m\n", &c_filename);
if (show_codegen)
system(heap_strf("bat -P %k", &c_filename));
if (show_codegen.length > 0)
system(heap_strf("%k %k", &show_codegen, &c_filename));
}
void compile_object_file(Text_t filename, bool force_recompile)
@ -613,8 +613,8 @@ Text_t compile_executable(env_t *base_env, Text_t filename, Array_t object_files
"}\n"
);
if (show_codegen) {
FILE *out = run_cmd("bat -P --file-name=run.c");
if (show_codegen.length > 0) {
FILE *out = run_cmd("%k", &show_codegen);
CORD_put(program, out);
pclose(out);
}