c/clang/symg:move get conf func
This commit is contained in:
60
chore/_xtool/llcppsymg/config/config.go
Normal file
60
chore/_xtool/llcppsymg/config/config.go
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/c"
|
||||||
|
"github.com/goplus/llgo/c/cjson"
|
||||||
|
"github.com/goplus/llgo/chore/llcppg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Conf struct {
|
||||||
|
*cjson.JSON
|
||||||
|
*types.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetConf(data []byte) (Conf, error) {
|
||||||
|
parsedConf := cjson.ParseBytes(data)
|
||||||
|
if parsedConf == nil {
|
||||||
|
return Conf{}, errors.New("failed to parse config")
|
||||||
|
}
|
||||||
|
|
||||||
|
config := &types.Config{
|
||||||
|
Name: GetStringItem(parsedConf, "name", ""),
|
||||||
|
CFlags: GetStringItem(parsedConf, "cflags", ""),
|
||||||
|
Libs: GetStringItem(parsedConf, "libs", ""),
|
||||||
|
Include: GetStringArrayItem(parsedConf, "include"),
|
||||||
|
TrimPrefixes: GetStringArrayItem(parsedConf, "trimPrefixes"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return Conf{
|
||||||
|
JSON: parsedConf,
|
||||||
|
Config: config,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetString(obj *cjson.JSON) (value string) {
|
||||||
|
str := obj.GetStringValue()
|
||||||
|
return unsafe.String((*byte)(unsafe.Pointer(str)), c.Strlen(str))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStringItem(obj *cjson.JSON, key string, defval string) (value string) {
|
||||||
|
item := obj.GetObjectItemCaseSensitive(c.AllocaCStr(key))
|
||||||
|
if item == nil {
|
||||||
|
return defval
|
||||||
|
}
|
||||||
|
return GetString(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStringArrayItem(obj *cjson.JSON, key string) (value []string) {
|
||||||
|
item := obj.GetObjectItemCaseSensitive(c.AllocaCStr(key))
|
||||||
|
if item == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
value = make([]string, item.GetArraySize())
|
||||||
|
for i := range value {
|
||||||
|
value[i] = GetString(item.GetArrayItem(c.Int(i)))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
"github.com/goplus/llgo/c/cjson"
|
"github.com/goplus/llgo/c/cjson"
|
||||||
|
"github.com/goplus/llgo/chore/_xtool/llcppsymg/config"
|
||||||
"github.com/goplus/llgo/chore/_xtool/llcppsymg/parse"
|
"github.com/goplus/llgo/chore/_xtool/llcppsymg/parse"
|
||||||
"github.com/goplus/llgo/chore/llcppg/types"
|
"github.com/goplus/llgo/chore/llcppg/types"
|
||||||
"github.com/goplus/llgo/cpp/llvm"
|
"github.com/goplus/llgo/cpp/llvm"
|
||||||
@@ -49,22 +50,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
config, err := getConf(data)
|
conf, err := config.GetConf(data)
|
||||||
check(err)
|
check(err)
|
||||||
defer config.Delete()
|
defer conf.Delete()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile)
|
fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile)
|
||||||
}
|
}
|
||||||
symbols, err := parseDylibSymbols(config.Libs)
|
symbols, err := parseDylibSymbols(conf.Libs)
|
||||||
|
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
filepaths := generateHeaderFilePath(config.CFlags, config.Include)
|
filepaths := generateHeaderFilePath(conf.CFlags, conf.Include)
|
||||||
astInfos, err := parse.ParseHeaderFile(filepaths)
|
astInfos, err := parse.ParseHeaderFile(filepaths)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
symbolInfo := getCommonSymbols(symbols, astInfos, config.TrimPrefixes)
|
symbolInfo := getCommonSymbols(symbols, astInfos, conf.TrimPrefixes)
|
||||||
|
|
||||||
err = genSymbolTableFile(symbolInfo)
|
err = genSymbolTableFile(symbolInfo)
|
||||||
check(err)
|
check(err)
|
||||||
@@ -76,51 +77,6 @@ func check(err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConf(data []byte) (types.Conf, error) {
|
|
||||||
parsedConf := cjson.ParseBytes(data)
|
|
||||||
if parsedConf == nil {
|
|
||||||
return types.Conf{}, errors.New("failed to parse config")
|
|
||||||
}
|
|
||||||
|
|
||||||
config := &types.Config{
|
|
||||||
Name: getStringItem(parsedConf, "name", ""),
|
|
||||||
CFlags: getStringItem(parsedConf, "cflags", ""),
|
|
||||||
Libs: getStringItem(parsedConf, "libs", ""),
|
|
||||||
Include: getStringArrayItem(parsedConf, "include"),
|
|
||||||
TrimPrefixes: getStringArrayItem(parsedConf, "trimPrefixes"),
|
|
||||||
}
|
|
||||||
|
|
||||||
return types.Conf{
|
|
||||||
JSON: parsedConf,
|
|
||||||
Config: config,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getString(obj *cjson.JSON) (value string) {
|
|
||||||
str := obj.GetStringValue()
|
|
||||||
return unsafe.String((*byte)(unsafe.Pointer(str)), c.Strlen(str))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStringItem(obj *cjson.JSON, key string, defval string) (value string) {
|
|
||||||
item := obj.GetObjectItemCaseSensitive(c.AllocaCStr(key))
|
|
||||||
if item == nil {
|
|
||||||
return defval
|
|
||||||
}
|
|
||||||
return getString(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStringArrayItem(obj *cjson.JSON, key string) (value []string) {
|
|
||||||
item := obj.GetObjectItemCaseSensitive(c.AllocaCStr(key))
|
|
||||||
if item == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
value = make([]string, item.GetArraySize())
|
|
||||||
for i := range value {
|
|
||||||
value[i] = getString(item.GetArrayItem(c.Int(i)))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseDylibSymbols(lib string) ([]types.CPPSymbol, error) {
|
func parseDylibSymbols(lib string) ([]types.CPPSymbol, error) {
|
||||||
dylibPath, err := generateDylibPath(lib)
|
dylibPath, err := generateDylibPath(lib)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goplus/llgo/c/cjson"
|
|
||||||
"github.com/goplus/llgo/xtool/nm"
|
"github.com/goplus/llgo/xtool/nm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,11 +29,6 @@ type Config struct {
|
|||||||
TrimPrefixes []string `json:"trimPrefixes"`
|
TrimPrefixes []string `json:"trimPrefixes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Conf struct {
|
|
||||||
*cjson.JSON
|
|
||||||
*Config
|
|
||||||
}
|
|
||||||
|
|
||||||
type CPPSymbol struct {
|
type CPPSymbol struct {
|
||||||
DemangleName string
|
DemangleName string
|
||||||
*nm.Symbol
|
*nm.Symbol
|
||||||
|
|||||||
Reference in New Issue
Block a user