Skip to content

Commit

Permalink
rename -fdump-tree to -dump-ast, less misleading
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Oct 24, 2024
1 parent 5fb3c4c commit 47f2f24
Show file tree
Hide file tree
Showing 11 changed files with 1,488 additions and 1,773 deletions.
9 changes: 9 additions & 0 deletions HACKING
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,12 @@ There should be no difference shown as long as the "old version" passed
the same tests as the new version - given the example above: there was
no support for REPORT WRITER in 2.2 so there would be an expected failure
of the RW tests.

For debugging the AST, you may specify --enable-dump-ast at the
configure step. In such a case, new options -fdump-ast=<file> and
-fdump-ast-flags=<flags> will become available to print the AST
generated for a given file in a file. This option is implemented using
an automatically generated printer cobc/dump_ast_gen.c, that is
generated by ctypes-gen (https://github.com/OCamlPro/ctypes-gen). If
you don't have the tool, you may just modify the file and wait for
somebody else to regenerate it at some point.
17 changes: 7 additions & 10 deletions cobc/ChangeLog.branch
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

* cobc.c, dump_tree.c: new options to dump the AST in text format:
--dump-tree=<file>, and --dump-tree-flags=<flags>. Format is
either OCaml (for files with .ml extension) or JSON. If file
ends with '/', then it is expected to be a directory and the
file will be generated with the program id as name. Flags are
'+/-' for enable/disable, 'c' for cb_common, 'l' for locations,
't' for types, 'p' for pointers, 'i' for indentation, 'n' for
newlines, 'A' for all infos, 'O' for OCaml format, 'J' for
JSON format, 'm' for message. Env variables COB_DUMP_TREE and
COB_DUMP_TREE_FLAGS can also be used to set these flags.
* Makefile.am, cobc.c, dump_ast.c: new options to dump the AST in
text format: --dump-ast=<file>, and
--dump-ast-flags=<flags>. Format is not standard for now, because
it is only for debugging the AST. Flags are prefixed with '+/-'
for enable/disable, 'i' for indentation, 'z' for zero/null
fields. Env variables COB_DUMP_AST and COB_DUMP_AST_FLAGS can also
be used to set these flags.
8 changes: 3 additions & 5 deletions 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 dump_tree.c
codeoptim.c replace.c dump_ast.c

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

Expand All @@ -40,7 +40,7 @@ COBC = cobc$(EXEEXT)
# sources that needs to be built *before* any other file
# note: we actually want their header files...
BUILT_SOURCES = ppparse.c parser.c
EXTRA_DIST = pplex.l scanner.l ppparse.h parser.h dump_tree_gen.c
EXTRA_DIST = pplex.l scanner.l ppparse.h parser.h dump_ast_gen.c

MAINTAINERCLEANFILES = pplex.c scanner.c ppparse.h parser.h cobc.1
CLEANFILES = parser.output ppparse.output
Expand Down Expand Up @@ -68,9 +68,7 @@ endif
.l.c:
LC_CTYPE=C $(LEX) -o$@ $<

dump_tree.$(OBJEXT): $(top_srcdir)/cobc/dump_tree_gen.c

.PHONY: update-dump-tree

update-dump-tree:
ctypes2json -I $(top_srcdir)/cobc -I $(top_srcdir)/lib > $(top_srcdir)/cobc/dump_tree_gen.c
ctypes-gen --gnucobol -I $(top_srcdir)/cobc -I $(top_srcdir)/lib > $(top_srcdir)/cobc/dump_ast_gen.c
34 changes: 17 additions & 17 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ enum compile_level {
#define CB_FLAG_GETOPT_DEPEND_ADD_PHONY 24
#define CB_FLAG_GETOPT_DEPEND_KEEP_MISSING 25
#define CB_FLAG_GETOPT_DEPEND_ON_THE_SIDE 26
#define CB_FLAG_DUMP_TREE 27
#define CB_FLAG_DUMP_TREE_FLAGS 28
#define CB_FLAG_DUMP_AST 27
#define CB_FLAG_DUMP_AST_FLAGS 28

/* Info display limits */
#define CB_IMSG_SIZE 24
Expand Down Expand Up @@ -465,8 +465,8 @@ 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* dump_tree_to_file = NULL;
static char* dump_tree_flags = NULL;
static char* dump_ast_to_file = NULL;
static char* dump_ast_flags = NULL;
static int cob_optimize = 0;


Expand Down Expand Up @@ -3777,18 +3777,18 @@ process_command_line (const int argc, char **argv)
break;
case CB_FLAG_GETOPT_DEPEND_OUTPUT_FILE: /* -MF <file> */
cb_depend_filename = cobc_strdup(cob_optarg);
case CB_FLAG_DUMP_TREE:
if (dump_tree_to_file)
cobc_main_free (dump_tree_to_file);
dump_tree_to_file = cobc_main_strdup (cob_optarg);
case CB_FLAG_DUMP_AST:
if (dump_ast_to_file)
cobc_main_free (dump_ast_to_file);
dump_ast_to_file = cobc_main_strdup (cob_optarg);
break;
case CB_FLAG_DUMP_TREE_FLAGS:
if (dump_tree_flags){
char* old = dump_tree_flags;
dump_tree_flags = cobc_main_stradd_dup(dump_tree_flags, cob_optarg);
case CB_FLAG_DUMP_AST_FLAGS:
if (dump_ast_flags){
char* old = dump_ast_flags;
dump_ast_flags = cobc_main_stradd_dup(dump_ast_flags, cob_optarg);
cobc_main_free (old);
} else {
dump_tree_flags = cobc_main_strdup (cob_optarg);
dump_ast_flags = cobc_main_strdup (cob_optarg);
}
break;

Expand Down Expand Up @@ -8320,10 +8320,10 @@ process_translate (struct filename *fn)
}
}

if (!dump_tree_to_file)
dump_tree_to_file = getenv("COB_DUMP_TREE");
if (dump_tree_to_file)
cb_dump_tree_to_file (current_program, dump_tree_to_file, dump_tree_flags);
if (!dump_ast_to_file)
dump_ast_to_file = getenv("COB_DUMP_AST");
if (dump_ast_to_file)
cb_dump_ast_to_file (current_program, dump_ast_to_file, dump_ast_flags);

/* Translate to C */
codegen (current_program, fn->translate);
Expand Down
1 change: 0 additions & 1 deletion cobc/cobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ extern void *cobc_realloc (void *, const size_t);

extern void *cobc_main_malloc (const size_t);
extern void *cobc_main_strdup (const char *);
extern char *cobc_main_stradd_dup (const char *, const char*);
extern void *cobc_main_realloc (void *, const size_t);
extern void cobc_main_free (void *);

Expand Down
1 change: 0 additions & 1 deletion cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -14040,7 +14040,6 @@ 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
Loading

0 comments on commit 47f2f24

Please sign in to comment.