transformer: add support for instrumenting the V compiler with -d trace_transformer

This commit is contained in:
Delyan Angelov 2024-09-09 22:42:22 +03:00
parent f002fd4493
commit 234fb8e2b0
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 5 additions and 0 deletions

View file

@ -285,6 +285,7 @@ a copy of the compiler rather than replacing it with `v self`.
| `trace_scanner` | Prints details about the recognized tokens. *Very* verbose. Use `./vnew -no-builtin -check-syntax file.v` later. |
| `trace_parser` | Prints details about parsed statements and expressions. Very verbose. Use it for panics in the parser. |
| `trace_checker` | Prints details about the statements being checked. Very verbose. Use it for panics in the checker. |
| `trace_transformer` | Prints details about the statements being transformed. Very verbose. Use it for panics in the transformer stage. |
| | |
| `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. |

View file

@ -174,6 +174,10 @@ pub fn (mut t Transformer) check_safe_array(mut node ast.IndexExpr) {
}
pub fn (mut t Transformer) stmt(mut node ast.Stmt) ast.Stmt {
$if trace_transformer ? {
ntype := typeof(*node).replace('v.ast.', '')
eprintln('transformer: ${t.file.path:-50} | pos: ${node.pos.line_str():-39} | node: ${ntype:12} | ${node}')
}
match mut node {
ast.EmptyStmt {}
ast.NodeError {}