frontend: compile: add verbose command option

This commit is contained in:
2024-12-05 21:06:03 +00:00
parent 9a4b074381
commit 8ef057360e

View File

@@ -12,12 +12,14 @@
enum {
ARG_SOURCE_FILE = 200,
OPT_LEX_ONLY,
OPT_VERBOSE,
};
static int compile_file(const char *path, const b_arglist *args)
{
bool lex_only
= b_arglist_get_count(args, OPT_LEX_ONLY, B_COMMAND_INVALID_ID) > 0;
int verbose = b_arglist_get_count(args, OPT_VERBOSE, B_COMMAND_INVALID_ID);
FILE *fp = fopen(path, "r");
if (!fp) {
@@ -61,7 +63,9 @@ static int compile_file(const char *path, const b_arglist *args)
break;
}
print_lex_token(tok);
if (verbose >= 2) {
print_lex_token(tok);
}
if (lex_only) {
ivy_token_destroy(tok);
@@ -82,7 +86,7 @@ static int compile_file(const char *path, const b_arglist *args)
int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1;
ivy_file_close(src);
if (!lex_only && r == 0) {
if (!lex_only && r == 0 && verbose >= 1) {
struct ivy_ast_node *root = ivy_parser_root_node(parser);
struct ivy_ast_node_iterator it = {0};
ivy_ast_node_iterate(root, &it, print_ast_node);
@@ -138,6 +142,15 @@ B_COMMAND(CMD_COMPILE, CMD_ROOT)
"files.");
}
B_COMMAND_OPTION(OPT_VERBOSE)
{
B_OPTION_LONG_NAME("verbose");
B_OPTION_SHORT_NAME('v');
B_OPTION_DESC(
"print detailed log output. this option can be used "
"multiple times to increase verbosity.");
}
B_COMMAND_ARG(ARG_SOURCE_FILE)
{
B_ARG_NAME("source file");