Skip to content

Commit e6bdd3e

Browse files
committed
Add --dump-context and native/string mapping
Expose a --dump-context CLI flag and implement context JSON dumping to aid template debugging. Added dump_context_json to serialize the mapped template context (files, types, functions, classes, etc.) and updated README to document the option. Enhance TypeMapper and mapped model to better support cstring/string and native/bridge metadata: bridge_kind, native_type, string/struct free symbols, class create/destroy symbols, pre/post call setup/cleanup lines, and call-arg handling for string parameters and struct returns. Generator context now exposes uses_ffi/uses_pkgffi/uses_ui flags to templates. IR/normalization improvements: serializer recognizes "string" type; normalizer detects std::string and maps it to kind="string", and restricts items to source paths under src/ (skipping unknown/non-src cursors). Parser: add macOS system include discovery via xcrun/clang to provide sensible default -I args on Darwin. Overall these changes improve template visibility, string/native interop handling, and robustness for Mac toolchains.
1 parent 24de13c commit e6bdd3e

File tree

7 files changed

+345
-23
lines changed

7 files changed

+345
-23
lines changed

tools/bindgen/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,16 +438,18 @@ cd tools/bindgen/example
438438
PYTHONPATH=../.. python3 -m bindgen \
439439
--config bindgen/config.yaml \
440440
--dump-ir out/ir.json \
441+
--dump-context out/context.json \
441442
--out out
442443
```
443444

444-
示例运行后将使用 `bindgen/template` 中的模板,并把 IR 与生成结果都写到 `out`
445+
示例运行后将使用 `bindgen/template` 中的模板,并把 IR、模板上下文与生成结果都写到 `out`
445446

446447
常用参数:
447448

448449
- `--config` 配置文件
449450
- `--out` 输出目录
450451
- `--dump-ir` 输出 IR JSON 便于调试
452+
- `--dump-context` 输出模板实际消费的映射后上下文 JSON,便于排查类型/符号/桥接配置
451453

452454
### 生成后格式化(Post Formatters)
453455

tools/bindgen/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
from pathlib import Path
33

4+
from .codegen.context import dump_context_json
45
from .codegen.generator import generate_bindings
56
from .config import load_config
67
from .ir.serializer import dump_ir_json, load_ir_json
@@ -14,6 +15,10 @@ def main(argv=None) -> int:
1415
parser.add_argument("--out", required=True, help="Output directory")
1516
parser.add_argument("--ir", help="Load IR from existing JSON file (skips parsing)")
1617
parser.add_argument("--dump-ir", help="Write IR JSON to path")
18+
parser.add_argument(
19+
"--dump-context",
20+
help="Write mapped template context JSON to path",
21+
)
1722

1823
args = parser.parse_args(argv)
1924

@@ -30,6 +35,8 @@ def main(argv=None) -> int:
3035

3136
if args.dump_ir:
3237
dump_ir_json(module, Path(args.dump_ir))
38+
if args.dump_context:
39+
dump_context_json(module, cfg.mapping, Path(args.dump_context))
3340

3441
out_dir = Path(args.out)
3542
out_dir.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)