Files
llgo/chore/llcppg/design.md

86 lines
1.4 KiB
Markdown
Raw Normal View History

2024-07-25 17:23:34 +08:00
llcppg Design
2024-07-23 09:41:03 +08:00
=====
2024-07-23 09:41:03 +08:00
## Usage
2024-07-23 09:41:03 +08:00
```sh
llcppg [config-file]
```
2024-07-23 09:41:03 +08:00
If `config-file` is not specified, a `llcppg.cfg` file is used in current directory. The configuration file format is as follows:
```json
{
2024-07-25 17:23:34 +08:00
"name": "inih",
2024-07-23 09:41:03 +08:00
"cflags": "$(pkg-config --cflags inireader)",
"include": [
"INIReader.h",
"AnotherHeaderFile.h"
],
2024-07-25 17:23:34 +08:00
"libs": "$(pkg-config --libs inireader)",
2024-09-02 18:51:46 +08:00
"trimPrefixes": ["Ini", "INI"],
"cplusplus":true
2024-07-23 09:41:03 +08:00
}
```
## Steps
1. llcppsymg: Generate symbol table for a C/C++ library
2. Manually modify the desired Go symbols in symbol table
3. llcppsigfetch: Fetch information of C/C++ symbols
4. gogensig: Generate a go package by information of symbols
### llcppsymg
```sh
llcppsymg config-file
2024-07-25 17:23:34 +08:00
llcppsymg - # read config from stdin
2024-07-23 09:41:03 +08:00
```
2024-07-25 17:23:34 +08:00
It generates a symbol table file named `llcppg.symb.json`. Its file format is as follows:
2024-07-23 09:41:03 +08:00
```json
[
{
"mangle": "_ZN9INIReaderC1EPKcm",
"c++": "INIReader::INIReader(char const*, unsigned long)",
"go": "(*Reader).Init__0"
2024-07-25 18:46:40 +08:00
}
2024-07-23 09:41:03 +08:00
]
```
2024-07-25 17:23:34 +08:00
### llcppsigfetch
```sh
llcppsigfetch config-file
llcppsigfetch - # read config from stdin
```
It fetches information of C/C++ symbols and print to stdout. Its format is as follows:
```json
2024-08-08 11:49:55 +08:00
[
{
"path": "/path/to/file.h",
"doc": {
"decls": [],
"macros": [],
"includes": [
{
2024-08-08 11:49:55 +08:00
"path": "incfile.h"
}
2024-08-08 11:49:55 +08:00
]
}
}
]
```
2024-08-08 11:49:55 +08:00
### gogensig
2024-08-08 11:49:55 +08:00
```sh
2024-07-26 16:14:41 +08:00
gogensig ast-file
2024-08-08 11:49:55 +08:00
gogensig - # read AST from stdin
```