Skip to content

Commit

Permalink
add --output-tree=FILE option
Browse files Browse the repository at this point in the history
Use the extension of FILE to choose the format of output:
* .ml : OCaml code format
* any other: JSON format (output validated by jsonlint-php)
  • Loading branch information
lefessan committed Jul 14, 2023
1 parent 6b44051 commit 48dae44
Show file tree
Hide file tree
Showing 6 changed files with 1,833 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cobc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bin_PROGRAMS = cobc
cobc_SOURCES = cobc.c cobc.h ppparse.y pplex.c parser.y scanner.c config.c \
reserved.c error.c tree.c tree.h field.c typeck.c codegen.c help.c \
config.def flag.def warning.def codeoptim.def ppparse.def \
codeoptim.c replace.c
codeoptim.c replace.c output_tree.c

#cobc_SOURCES = cobc.c cobc.h ppparse.y pplex.l parser.y scanner.l config.c

Expand Down
12 changes: 12 additions & 0 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ static int save_all_src = 0;
static signed int save_c_src = 0;
static signed int verbose_output = 0;
static int cb_coverage_enabled = 0;
static char* output_tree_to_file = NULL;
static int cob_optimize = 0;


Expand Down Expand Up @@ -608,6 +609,7 @@ static const struct option long_options[] = {
{"MT", CB_RQ_ARG, NULL, '!'},
{"MF", CB_RQ_ARG, NULL, '@'},
{"coverage", CB_NO_ARG, &cb_coverage_enabled, 1},
{"output-tree", CB_RQ_ARG, NULL, '>'},
{"P", CB_OP_ARG, NULL, 'P'},
{"Xref", CB_NO_ARG, NULL, 'X'},
{"use-extfh", CB_RQ_ARG, NULL, 9}, /* this is used by COBOL-IT; Same is -fcallfh= */
Expand Down Expand Up @@ -3638,6 +3640,13 @@ process_command_line (const int argc, char **argv)
}
break;

case '>':
if (output_tree_to_file)
cobc_main_free (output_tree_to_file);
fprintf(stderr, "cob_optarg = [%s]\n", cob_optarg);
output_tree_to_file = cobc_main_strdup (cob_optarg);
break;

case '@':
/* -MF <file> */
cb_depend_file = fopen (cob_optarg, "w");
Expand Down Expand Up @@ -8079,6 +8088,9 @@ process_translate (struct filename *fn)
}
}

if (output_tree_to_file)
cb_output_tree_to_file (current_program, output_tree_to_file);

/* Translate to C */
codegen (current_program, fn->translate);

Expand Down
1 change: 1 addition & 0 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -13722,6 +13722,7 @@ codegen_internal (struct cb_program *prog, const int subsequent_call)
}
}

/* output the procedure division code */
output_internal_function (prog, prog->parameter_list);

if (!prog->next_program) {
Expand Down
1 change: 1 addition & 0 deletions cobc/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ cobc_print_usage_common_options (void)
puts (_(" -A <options> add <options> to the C compile phase"));
puts (_(" -Q <options> add <options> to the C link phase"));
puts (_(" --coverage instrument generated binaries for coverage"));
puts (_(" --output-tree=<file> output the AST to <file> for debugging"));
puts (_(" --conf=<file> user-defined dialect configuration; see -std"));
puts (_(" --list-reserved display reserved words"));
puts (_(" --list-intrinsics display intrinsic functions"));
Expand Down
Loading

0 comments on commit 48dae44

Please sign in to comment.