-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --fdump-tree=FILE option #108
base: gcos4gnucobol-3.x
Are you sure you want to change the base?
Add --fdump-tree=FILE option #108
Conversation
48dae44
to
e668b19
Compare
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## gcos4gnucobol-3.x #108 +/- ##
=====================================================
- Coverage 65.39% 64.02% -1.38%
=====================================================
Files 32 33 +1
Lines 58797 60063 +1266
Branches 15492 16176 +684
=====================================================
+ Hits 38449 38454 +5
- Misses 14362 15621 +1259
- Partials 5986 5988 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
16ea769
to
4f413a2
Compare
Would it be reasonable to use -fdump-something similar to GCC https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html ?
Note: I don't have any idea if there are options that output JSON.
Question: What is the OCAML ml and where can I read more about it?
What would this output be used for?
In any case please provide test cases with sample output (and to be sure that this doesn't break anything execute make checkall at least once passing this option in COBOL_FLAGS.
|
cobc/output_tree.c
Outdated
const char* string_of_cb_usage (enum cb_usage x) | ||
{ | ||
switch (x){ | ||
case CB_USAGE_BINARY: return "CB_USAGE_BINARY"; /* 0 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't those and similar be "stringified" using our existing macros? This would still need a switch-case, but if the source is a macro then it can be just defined as additional macro instead of the full switch-case, otherwise a macro can still be used to only end in CASE_STRING(some-enum)
.
Note: you don't need to include the numeric values (which possibly be changed later on in any case).
4f413a2
to
610905c
Compare
I changed the options to I ran all the testsuite with both formats (using env variables to not modify scripts), and I could validate both OCaml and JSON files. I am not sure that adding a test in the testsuite would be a good idea: (1) the output depends on the internal types in The OCaml format is actually standard syntax for basic types in the OCaml language (https://ocaml.org). Since I mostly always program in OCaml (except for GnuCOBOL :-) ), it is easier for me to have this format than JSON, as I could easily write tools to simplify/filter information in the AST. For examples, JSON format (with flags
whereas OCaml format looks like:
|
610905c
to
d3294aa
Compare
Note that there are still some TODOs in the code. There are many fields in these data structures, and it's not clear what should be printed or not. Also, it might be interesting at some point to have "levels" of importance for fields, so that, for example, only important fields would be printed at level 1, then less important fields at level 2, and so on... However, such levels should probably be decided after experimenting with using these outputs for real debugging. |
00faae3
to
41819d1
Compare
41819d1
to
266808b
Compare
266808b
to
f47a04a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the build_literal changes are part of a broken merge - you'd like to revert them then (at least with an extra cleanup commit)
To ensure that at least something is tested you definitely want to add some testcases, possibly in used_binaries.at
cobc/ChangeLog.branch
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be dropped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just put the ChangeLog of the branch outside of the ChangeLog, because it creates a conflict everytime I rebased it. I will keep it that way until the work is finished.
cobc/ChangeLog
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please one-time merge that file and everything is nice in it
cobc/ChangeLog
Outdated
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this misses the new files and their inclusion in the Makefile.am
cobc/dump_tree_gen.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this file is generated it may should not be included in VCS but added to git/svn-ignore (not sure yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is generated by a "non standard" tool, I am still wondering what to do. Adding a permanent dependency on the tool is probably a bad idea, I am more considering making this feature a configure-time option, disabled by default, and only available on-demand (with a specific workflow in the Github CI to check whether it is still working or not).
cobc/Makefile.am
Outdated
.PHONY: update-dump-tree | ||
|
||
update-dump-tree: | ||
ctypes2json -I $(top_srcdir)/cobc -I $(top_srcdir)/lib > $(top_srcdir)/cobc/dump_tree_gen.c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ctypes2json
should likely get an entry in the HACKING file
That's strange, if you keep it inserted "down where it is" until there are possibly more changes, then there should be no conflict as no other commits as to the changelog down.
|
I see. For me, it has to be inserted at the point where it is merged, i.e. the ChangeLog before should correspond to what is in the code at the point where the work is done, and not when it was started, no ? |
That depends. If most of the old work is unchanged and "old", then I personally would have one "old" and one "new" entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bunch of issues from the last iteration solved and cleaned up correctly - looking forward for the test
cobc/dump_tree.c
Outdated
case '+': sign = 1; break; | ||
case '-': sign = 0; break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these flags duplicate the filename option and should therefore be dropped here and in the flag.def help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is to be able to enable/disable flags in the same definition, for example +z-i
(add zero-value fields and disable indent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, that's reasonable of course, improved docs and tests will help me to understand that
cobc/flag.def
Outdated
_(" -fdump-tree-flags=<flags> set flags used when dumping the parsed AST\n" | ||
" '+/-' to enable/disable, 'l' for locations,\n" | ||
" 't' for types, 'p' for pointers, 'i' for indent.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this misses some of the flags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most flags have disappeared, as it does not print to JSON/OCaml anymore, but to a human readable format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you consider the "no JSON/OCaml" temporary or is the idea to leave that as-is? Just asking....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I thought that the AST of GnuCOBOL was "clean", in the sense that it was an exact representation of the COBOL code. However, it is not the case: the parser starts translating code to C (for example, replacing some nodes by direct calls to C functions), so the AST is actually half COBOL code, half translated code. So, the interest of sending this AST to another program (through OCaml or JSON) is less interesting. So, for now, I have given up on the idea of a correct JSON/OCaml encoding, focusing more on the ability to debug the compiler using a printed AST.
Yet, on the long term, I think it would be nice to move translations done in the parser to the codegen, and get a clean AST. At that point, it could be used by other programs and this output could be improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree that this separation should be clearer; to do so we'd likely move most of the included C code to a new cb_tree like it currently is implemented, but into a new type of node that is only converted to C in codegen.
... but then - nearly all of the C parts should be FUNC_CALLs and most of those should be quite easily be separated and could be converted "on the fly", if wanted.
... but your human-readable AST dump may be ideal to show what is really in and consider adjustments that way.
I'm looking forward to some test cases showing what you consider to be bad in the AST. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an example of the generated output for a small file:
I am not really sure it is interesting to create a test, as we don't really expect the format to be kept backward compatible. We may just want to make a test to verify that a file is generated, but not check the file format itself.
cobc/tree.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all changes to this file but the definition of the new function can be checked in upstream at any time
Last set of errors from the CI:
The MSVC builds all fail because the new dump_ast files need to be added to build_windows. |
<None Include="..\..\cobc\dump_ast_gen.c"> | ||
<Filter>Header Files</Filter> | ||
</None> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused - that is an auto-generated source (like parser.c) and therefore should be moved there and ClCompile
d as well, no [that applies to all of those files under build_windows]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand these files, I just grep for other similar files (warning.def and typeck.c) and modified the files accordinly...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should we handle that as a header file? I guess we call static functions in here directly from dump_ast.gen.c?
If this is the case and there are not too much, then dropping the static
attribute via sed
and adding those "entry prototypes" to tree.h would work better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should just be renamed as .def to be consistent with other included files that are not actually include files.
memset (ptr_table, 0, ptr_table_size * sizeof(void*) ); | ||
memset (num_table, 0, ptr_table_size * sizeof(int) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a manual change after generation? In this case you possibly want to define bzero as macro instead to do that change.
I guess we cannot generate this file using the tool you do for C89 compat (the one failing test in CI)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new file is generated by a new version of the tool (https://github.com/OCamlPro/ctypes-gen), but I guess most devs will edit it by hand, and the tool will only be used from time to time to get a clean version.
Dump the AST/tree to a file, for debugging purpose.
A file dump_ast_gen.c is generated by an external tool directly from tree.h, it can then be edited manually if the types are modified, until the tool is run again later to clean it up.