cgen: add support for -d trace_cgen_stmt, document it in CONTRIBUTING.md

This commit is contained in:
Delyan Angelov 2023-09-13 15:04:19 +03:00
parent 4d8b2e9995
commit 5d1f87c5aa
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 35 additions and 13 deletions

View file

@ -192,20 +192,25 @@ which tests have failed and then fix them by making more changes. Just use
run with your updated code. Use `hub ci-status --verbose` to monitor run with your updated code. Use `hub ci-status --verbose` to monitor
their status. their status.
## Flags ## Compiler flags, useful while debugging the compiler itself:
V allows you to pass custom flags using `-d my_flag` that can then be checked V allows you to pass custom flags using `-d my_flag` that can then be checked
at compile time (see the documentation about at compile time (see the documentation about
[compile-time if](https://github.com/vlang/v/blob/master/doc/docs.md#compile-time-if)). [compile-time if](https://github.com/vlang/v/blob/master/doc/docs.md#compile-time-if)).
There are numerous flags that can be passed when building the compiler
with `v self` or when creating a copy of the compiler, that will help
you when debugging.
Beware that the flags must be passed when building the compiler, Since the compiler is *also* an ordinary V program, there are numerous flags that can be
not the program, so do for example: `v -d time_parsing cmd/v` or passed when building the compiler itself with `v self`, or when creating a copy of the
`v -d trace_checker self`. compiler, that will help you when debugging the compiler.
Some flags can make the compiler very verbose, so it is recommended
to create a copy of the compiler rather than replacing it with `v self`. Note: beware that the flags below must be passed, when building the compiler, *not the program*,
so do for example:
`./v -o w -d time_parsing cmd/v`
or
`./v -o w -d trace_checker self`
... then use `./w file.v`, instead of `./v file.v`, to compile your program.
Note: some of the flags can make the compiler *very verbose*, so it is recommended to create
a copy of the compiler rather than replacing it with `v self`.
| Flag | Usage | | Flag | Usage |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------| |-----------------------------------|---------------------------------------------------------------------------------------------------------------------|
@ -216,12 +221,21 @@ to create a copy of the compiler rather than replacing it with `v self`.
| `print_vweb_template_expansions` | Prints vweb compiled HTML files | | `print_vweb_template_expansions` | Prints vweb compiled HTML files |
| `time_checking` | Prints the time spent checking files and other related information | | `time_checking` | Prints the time spent checking files and other related information |
| `time_parsing` | Prints the time spent parsing files and other related information | | `time_parsing` | Prints the time spent parsing files and other related information |
| | |
| `trace_parser` | Prints details about parsed statements and expressions. Very verbose. Use it for panics in the parser. |
| `trace_ccoptions` | Prints options passed down to the C compiler |
| | |
| `trace_checker` | Prints details about the statements being checked. Very verbose. Use it for panics in the checker. |
| | |
| `trace_gen` | Prints all the strings written to the generated C file. Very verbose. |
| `trace_cgen_stmt` | Prints details about the statements that are being processed by cgen. |
| | Use it for panics in cgen, to see the closest input V source line, that caused the panic. |
| | Note: you need `v -no-parallel -d trace_cgen_stmt -o w cmd/v` to make sense of the output of that, |
| | otherwise by default cgen uses several threads, and the lines that are printed are out of order. |
| | |
| `trace_autofree` | Prints details about how/when -autofree puts free() calls | | `trace_autofree` | Prints details about how/when -autofree puts free() calls |
| `trace_autostr` | Prints details about `.str()` method auto-generated by the compiler during C generation | | `trace_autostr` | Prints details about `.str()` method auto-generated by the compiler during C generation |
| `trace_ccoptions` | Prints options passed down to the C compiler | | | |
| `trace_checker` | Prints details about the statements being checked |
| `trace_gen` | Prints strings written to the generated C file. Beware, this flag is very verbose |
| `trace_parser` | Prints details about parsed statements and expressions |
| `trace_thirdparty_obj_files` | Prints details about built thirdparty obj files | | `trace_thirdparty_obj_files` | Prints details about built thirdparty obj files |
| `trace_usecache` | Prints details when -usecache is used | | `trace_usecache` | Prints details when -usecache is used |
| `trace_embed_file` | Prints details when $embed_file is used | | `trace_embed_file` | Prints details when $embed_file is used |

View file

@ -2006,6 +2006,14 @@ fn (mut g Gen) write_v_source_line_info(pos token.Pos) {
} }
fn (mut g Gen) stmt(node ast.Stmt) { fn (mut g Gen) stmt(node ast.Stmt) {
$if trace_cgen_stmt ? {
ntype := typeof(node).replace('v.ast.', '')
if g.file == unsafe { nil } {
eprintln('cgen: <nil> | pos: ${node.pos.line_str():-39} | node: ${ntype} | ${node}')
} else {
eprintln('cgen: ${g.file.path:-30} | pos: ${node.pos.line_str():-39} | node: ${ntype} | ${node}')
}
}
g.inside_call = false g.inside_call = false
if !g.skip_stmt_pos { if !g.skip_stmt_pos {
g.set_current_pos_as_last_stmt_pos() g.set_current_pos_as_last_stmt_pos()