Add options for printing tokens and target code

This commit is contained in:
XOR 2023-02-04 19:37:04 +01:00
parent eea7693a14
commit 244770c125

View file

@ -14,6 +14,8 @@ struct cmd_arguments
{
char *input_file;
char *output_file;
int print_tokens;
int print_target_code;
};
error_t parser_function(int key, char *arg, struct argp_state *state)
@ -25,6 +27,12 @@ error_t parser_function(int key, char *arg, struct argp_state *state)
case 'o':
save_arguments->output_file = arg;
break;
case 't':
save_arguments->print_tokens = 1;
break;
case 'b':
save_arguments->print_target_code = 1;
break;
case ARGP_KEY_ARG:
// If we got more than one non-option argument
if (state->arg_num >= 1)
@ -57,6 +65,22 @@ struct argp_option argp_options[] =
.doc = "Output file",
.group = 0
},
{
.name = "print_tokens",
.key = 't',
.arg = 0,
.flags = 0,
.doc = "Print the tokens generated by the Lexer to stdout",
.group = 0
},
{
.name = "print_target_code",
.key = 'b',
.arg = 0,
.flags = 0,
.doc = "Print the (Binary) target code generated to stdout",
.group = 0
},
{0}
};
@ -73,6 +97,9 @@ int main(int argc, char **argv)
struct cmd_arguments arguments;
arguments.output_file = DEFAULT_OUT_FILE;
arguments.input_file = "";
arguments.print_target_code = 0;
arguments.print_tokens = 0;
argp_parse(&argument_parser, argc, argv, 0, 0, &arguments);
@ -83,12 +110,14 @@ int main(int argc, char **argv)
lexer(assembly_file, tokens);
fclose(assembly_file);
print_tokens(tokens);
__uint32_t *target_code = malloc(MAX_MEMORY * sizeof(target_code));
gen_target_code(tokens, target_code);
print_target_code(target_code);
save_img(arguments.output_file, target_code);
// If the requested, we print the tokens and/or the target code
if (arguments.print_tokens) print_tokens(tokens);
if (arguments.print_target_code) print_target_code(target_code);
return 0;
}