frontend: compile: replace verbose option with dedicated logging options
This commit is contained in:
@@ -11,15 +11,14 @@
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
ARG_SOURCE_FILE = 200,
|
ARG_SOURCE_FILE = 200,
|
||||||
OPT_LEX_ONLY,
|
OPT_SHOW_LEX_TOKENS,
|
||||||
OPT_VERBOSE,
|
OPT_SHOW_AST_NODES,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int compile_file(const char *path, const b_arglist *args)
|
static int compile_file(const char *path, const b_arglist *args)
|
||||||
{
|
{
|
||||||
bool lex_only
|
bool show_lex = b_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID) > 0;
|
||||||
= b_arglist_get_count(args, OPT_LEX_ONLY, B_COMMAND_INVALID_ID) > 0;
|
bool show_ast = b_arglist_get_count(args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID) > 0;
|
||||||
int verbose = b_arglist_get_count(args, OPT_VERBOSE, B_COMMAND_INVALID_ID);
|
|
||||||
|
|
||||||
FILE *fp = fopen(path, "r");
|
FILE *fp = fopen(path, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
@@ -63,15 +62,10 @@ static int compile_file(const char *path, const b_arglist *args)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose >= 2) {
|
if (show_lex) {
|
||||||
print_lex_token(tok);
|
print_lex_token(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lex_only) {
|
|
||||||
ivy_token_destroy(tok);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = ivy_parser_push_token(parser, tok);
|
status = ivy_parser_push_token(parser, tok);
|
||||||
|
|
||||||
if (status != IVY_OK) {
|
if (status != IVY_OK) {
|
||||||
@@ -86,11 +80,10 @@ static int compile_file(const char *path, const b_arglist *args)
|
|||||||
int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1;
|
int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1;
|
||||||
ivy_file_close(src);
|
ivy_file_close(src);
|
||||||
|
|
||||||
if (!lex_only && r == 0 && verbose >= 1) {
|
if (r == 0 && show_ast) {
|
||||||
struct ivy_ast_node *root = ivy_parser_root_node(parser);
|
struct ivy_ast_node *root = ivy_parser_root_node(parser);
|
||||||
struct ivy_ast_node_iterator it = {0};
|
struct ivy_ast_node_iterator it = {0};
|
||||||
ivy_ast_node_iterate(root, &it, print_ast_node);
|
ivy_ast_node_iterate(root, &it, print_ast_node);
|
||||||
// ivy_ast_node_print(root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lex) {
|
if (lex) {
|
||||||
@@ -133,22 +126,22 @@ B_COMMAND(CMD_COMPILE, CMD_ROOT)
|
|||||||
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||||
B_COMMAND_FUNCTION(compile);
|
B_COMMAND_FUNCTION(compile);
|
||||||
|
|
||||||
B_COMMAND_OPTION(OPT_LEX_ONLY)
|
B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
|
||||||
{
|
{
|
||||||
B_OPTION_LONG_NAME("lex-only");
|
B_OPTION_LONG_NAME("show-lex");
|
||||||
B_OPTION_SHORT_NAME('L');
|
B_OPTION_SHORT_NAME('l');
|
||||||
B_OPTION_DESC(
|
B_OPTION_DESC(
|
||||||
"print the lexical tokens generated from the input "
|
"print the lexical tokens generated from the input "
|
||||||
"files.");
|
"files.");
|
||||||
}
|
}
|
||||||
|
|
||||||
B_COMMAND_OPTION(OPT_VERBOSE)
|
B_COMMAND_OPTION(OPT_SHOW_AST_NODES)
|
||||||
{
|
{
|
||||||
B_OPTION_LONG_NAME("verbose");
|
B_OPTION_LONG_NAME("show-ast");
|
||||||
B_OPTION_SHORT_NAME('v');
|
B_OPTION_SHORT_NAME('a');
|
||||||
B_OPTION_DESC(
|
B_OPTION_DESC(
|
||||||
"print detailed log output. this option can be used "
|
"print the abstract syntax tree generated from the "
|
||||||
"multiple times to increase verbosity.");
|
"input files.");
|
||||||
}
|
}
|
||||||
|
|
||||||
B_COMMAND_ARG(ARG_SOURCE_FILE)
|
B_COMMAND_ARG(ARG_SOURCE_FILE)
|
||||||
|
|||||||
Reference in New Issue
Block a user