From ef546696e825359ccfd865648eb0ca5cf87233f1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 19 Dec 2024 15:02:39 -0500 Subject: [PATCH] Tweak command line args to support -q and update docs --- tomo.1 | 61 +++++++++++++++++++++++++++++++------------------------ tomo.1.md | 22 +++++++++++++------- tomo.c | 22 ++++++++++++++------ 3 files changed, 66 insertions(+), 39 deletions(-) diff --git a/tomo.1 b/tomo.1 index c5515fc..0398a48 100644 --- a/tomo.1 +++ b/tomo.1 @@ -1,69 +1,78 @@ -.\" Automatically generated by Pandoc 3.1.8 +.\" Automatically generated by Pandoc 3.1.11.1 .\" .TH "TOMO" "1" "June 11, 2024" "" "" .SH NAME -tomo - The programming language of tomorrow. +tomo \- The programming language of tomorrow. .SH SYNOPSIS .TP Run the REPL: \f[B]tomo\f[R] .TP Run a program: -\f[B]tomo\f[R] \f[I]program.tm\f[R] [[\f[B]--\f[R]] \f[I]args\&...\f[R]] +\f[B]tomo\f[R] \f[I]program.tm\f[R] [[\f[B]\-\-\f[R]] +\f[I]args\&...\f[R]] .TP Transpile tomo files to C files: -\f[B]tomo\f[R] \f[B]-t\f[R] \f[I]file1.tm\f[R] \f[I]file2.tm\f[R]\&... +\f[B]tomo\f[R] \f[B]\-t\f[R] \f[I]file1.tm\f[R] \f[I]file2.tm\f[R]\&... .TP Compile files to static object files: -\f[B]tomo\f[R] \f[B]-c\f[R] \f[I]file1.tm\f[R] \f[I]file2.tm\f[R]\&... +\f[B]tomo\f[R] \f[B]\-c\f[R] \f[I]file1.tm\f[R] \f[I]file2.tm\f[R]\&... .TP Compile file to an executable: -\f[B]tomo\f[R] \f[B]-e\f[R] \f[I]file1.tm\f[R] +\f[B]tomo\f[R] \f[B]\-e\f[R] \f[I]file1.tm\f[R] .TP Build a shared library: -\f[B]tomo\f[R] \f[B]-s=\f[R]\f[I]mylib.1.2.3\f[R] \f[I]file1.tm\f[R] +\f[B]tomo\f[R] \f[B]\-s=\f[R]\f[I]mylib.1.2.3\f[R] \f[I]file1.tm\f[R] \f[I]file2.tm\f[R]\&... .SH DESCRIPTION Tomo is a programming language that is statically typed, compiled, -small, and garbage-collected, with concise syntax and built-in support -for high-performance, low-overhead datastructures. +small, and garbage\-collected, with concise syntax and built\-in support +for high\-performance, low\-overhead datastructures. It compiles by first outputting C code, which is then compiled using a C compiler of your choice. .SH OPTIONS .TP -\f[B]-h\f[R], \f[B]--help\f[R] +\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] Transpile the input files to C code without compiling them. .TP -\f[B]-c\f[R] +\f[B]\-c\f[R] Compile the input files to static objects, rather than running them. .TP -\f[B]-e\f[R] +\f[B]\-e\f[R] Compile the input file to an executable. .TP -\f[B]-L\f[R] +\f[B]\-L\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] Install the compiled executable or library. +.TP +\f[B]\-C\f[R] +Print transpiled C code to the console. +.TP +\f[B]\-\-c\-compiler\f[R] +Set which C compiler is used. +.TP +\f[B]\-f\f[R], \f[B]\-\-autoformat\f[R] +Set which autoformat program is used. +.TP +\f[B]\-v\f[R], \f[B]\-\-verbose\f[R] +Print extra verbose output. +.TP +\f[B]\-q\f[R], \f[B]\-\-quiet\f[R] +Be extra quiet and do not print what the compiler is doing, only program +output. .SS ENVIRONMENT VARIABLES Some options can be configured by setting environment variables. .TP -\f[B]VERBOSE=0|1|2\f[R] -Set the verbosity level. -.TP -\f[B]CC=\f[R]\f[I]c-compiler\f[R] +\f[B]CC=\f[R]\f[I]c\-compiler\f[R] Set which C compiler is used. .TP -\f[B]O=\f[R]\f[I]optimization-level\f[R] -Set which optimization level is passed to the C compiler. -Valid values are those accepted by your compiler\[cq]s \f[B]-O\f[R] -flag. -.TP \f[B]AUTOFMT=\f[R]\f[I]autoformatter\f[R] The program used to autoformat generated C code. -Default: \f[B]indent -kr -l100 -nbbo -nut -sob\f[R] +Default: \f[B]indent \-kr \-l100 \-nbbo \-nut \-sob\f[R] .SH AUTHORS -Bruce Hill (\f[I]bruce\[at]bruce-hill.com\f[R]). +Bruce Hill (\f[I]bruce\[at]bruce\-hill.com\f[R]). diff --git a/tomo.1.md b/tomo.1.md index 588a61a..74d9f75 100644 --- a/tomo.1.md +++ b/tomo.1.md @@ -53,19 +53,27 @@ C code, which is then compiled using a C compiler of your choice. `-I` : Install the compiled executable or library. +`-C` +: Print transpiled C code to the console. + +`--c-compiler` +: Set which C compiler is used. + +`-f`, `--autoformat` +: Set which autoformat program is used. + +`-v`, `--verbose` +: Print extra verbose output. + +`-q`, `--quiet` +: Be extra quiet and do not print what the compiler is doing, only program output. + ## ENVIRONMENT VARIABLES Some options can be configured by setting environment variables. -`VERBOSE=0|1|2` -: Set the verbosity level. - `CC=`*c-compiler* : Set which C compiler is used. -`O=`*optimization-level* -: Set which optimization level is passed to the C compiler. Valid values are - those accepted by your compiler's `-O` flag. - `AUTOFMT=`*autoformatter* : The program used to autoformat generated C code. Default: `indent -kr -l100 -nbbo -nut -sob` diff --git a/tomo.c b/tomo.c index e550175..a808d7d 100644 --- a/tomo.c +++ b/tomo.c @@ -33,6 +33,7 @@ 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, @@ -83,7 +84,9 @@ int main(int argc, char *argv[]) " --verbose|-v: verbose output\n" " --install|-I: install the executable or library\n" " --c-compiler : the C compiler to use (default: cc)\n" - " --optimization|-O : set optimization level"); + " --optimization|-O : set optimization level\n" + " --quiet|-q: quiet output\n" + ); Text_t help = Texts(Text("\x1b[1mtomo\x1b[m: a compiler for the Tomo programming language"), Text("\n\n"), usage); tomo_parse_args( argc, argv, usage, help, @@ -110,6 +113,8 @@ int main(int argc, char *argv[]) {"c-compiler", false, &Text$info, &cc}, {"optimization", false, &Text$info, &optimization}, {"O", false, &Text$info, &optimization}, + {"quiet", false, &Bool$info, &quiet}, + {"q", false, &Bool$info, &quiet}, ); if (uninstall) { @@ -306,7 +311,8 @@ void build_library(Text_t lib_dir_name) if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) exit(EXIT_FAILURE); - printf("\x1b[2mCompiled to lib%k.so\x1b[m\n", &lib_dir_name); + if (!quiet || verbose) + printf("\x1b[2mCompiled to lib%k.so\x1b[m\n", &lib_dir_name); prog = run_cmd("objcopy --redefine-syms=symbol_renames.txt 'lib%k.so'", &lib_dir_name); status = pclose(prog); @@ -491,7 +497,8 @@ void transpile_header(env_t *base_env, Text_t filename, bool force_retranspile) if (pclose(prog) == -1) errx(1, "Failed to run autoformat program on header file: %k", &autofmt); - printf("\x1b[2mTranspiled to %k\x1b[m\n", &h_filename); + if (!quiet || verbose) + printf("\x1b[2mTranspiled to %k\x1b[m\n", &h_filename); if (show_codegen) system(heap_strf("bat -P %k", &h_filename)); @@ -532,7 +539,8 @@ void transpile_code(env_t *base_env, Text_t filename, bool force_retranspile) if (pclose(out) == -1) errx(1, "Failed to output autoformatted C code to %k: %k", &c_filename, &autofmt); - printf("\x1b[2mTranspiled to %k\x1b[m\n", &c_filename); + if (!quiet || verbose) + printf("\x1b[2mTranspiled to %k\x1b[m\n", &c_filename); if (show_codegen) system(heap_strf("bat -P %k", &c_filename)); @@ -557,7 +565,8 @@ void compile_object_file(Text_t filename, bool force_recompile) if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) exit(EXIT_FAILURE); - printf("\x1b[2mCompiled to %k\x1b[m\n", &obj_file); + if (!quiet || verbose) + printf("\x1b[2mCompiled to %k\x1b[m\n", &obj_file); } Text_t compile_executable(env_t *base_env, Text_t filename, Array_t object_files, Array_t extra_ldlibs) @@ -592,7 +601,8 @@ Text_t compile_executable(env_t *base_env, Text_t filename, Array_t object_files if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) exit(EXIT_FAILURE); - printf("\x1b[2mCompiled executable: %k\x1b[m\n", &bin_name); + if (!quiet || verbose) + printf("\x1b[2mCompiled executable: %k\x1b[m\n", &bin_name); return bin_name; }