Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cl/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ func NC(cfg *llcppg.Config, fileMap map[string]*llcppg.FileInfo, convSym func(na
ConvSym: convSym,
TrimPrefixes: cfg.TrimPrefixes,
KeepUnderScore: cfg.KeepUnderScore,
GenThird: cfg.GenThird,
}
}
5 changes: 3 additions & 2 deletions cl/internal/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type Config struct {
Pkg *ast.File
NC nc.NodeConverter

Deps []string // dependent packages
Libs string
Deps []string // dependent packages
Libs string
GenThird bool // trird type not in generation
}

// if modulePath is not empty, init the module by modulePath
Expand Down
3 changes: 2 additions & 1 deletion cl/internal/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func testFrom(t *testing.T, dir string, gen bool, validateFunc func(t *testing.T
NC: cltest.NC(&cfg, convertPkg.FileMap, cltest.GetConvSym(symbPath)),
Deps: cfg.Deps,
Libs: cfg.Libs,
GenThird: true,
})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -417,7 +418,7 @@ func createJSONFile(filepath string, data any) error {
}

func callSigfetch(configFile string, dir string) ([]byte, error) {
cmd := exec.Command("llcppsigfetch", configFile)
cmd := exec.Command("llcppsigfetch", "-v", configFile)
cmd.Dir = dir

var out bytes.Buffer
Expand Down
22 changes: 22 additions & 0 deletions cl/internal/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (p *Package) NewFuncDecl(goName string, funcDecl *ast.FuncDecl) error {
if debugLog {
log.Printf("NewFuncDecl: %v\n", funcDecl.Name)
}
// not need check , symbol not found will not generate

fnSpec, err := p.LookupFunc(goName, funcDecl)
if err != nil {
Expand Down Expand Up @@ -366,6 +367,10 @@ func (p *Package) NewTypeDecl(goName string, typeDecl *ast.TypeDecl, pnc nc.Node
log.Printf("NewTypeDecl: %s\n", typeDecl.Name.Name)
}

if p.lookupOrigin(typeDecl.Name.Name, goName) != nil {
return nil
}

cname := typeDecl.Name.Name
isForward := p.cvt.inComplete(typeDecl.Type)
name, changed, exist, err := p.RegisterNode(Node{name: cname, kind: TypeDecl}, goName, p.lookupOrigin)
Expand Down Expand Up @@ -467,6 +472,18 @@ func (p *Package) NewTypedefDecl(goName string, typedefDecl *ast.TypedefDecl, pn
log.Printf("NewTypedefDecl: %s\n", typedefDecl.Name.Name)
}

if typedefDecl.Name.Name == "__darwin_va_list" || typedefDecl.Name.Name == "__gnuc_va_list" {
typedefDecl.Type = &ast.PointerType{
X: &ast.BuiltinType{
Kind: ast.Void,
},
}
}

if p.lookupOrigin(typedefDecl.Name.Name, goName) != nil {
return nil
}

node := Node{name: typedefDecl.Name.Name, kind: TypedefDecl}
name, changed, exist, err := p.RegisterNode(node, goName, p.lookupOrigin)
if err != nil {
Expand Down Expand Up @@ -558,6 +575,11 @@ func (p *Package) NewEnumTypeDecl(goName string, enumTypeDecl *ast.EnumTypeDecl,
if debugLog {
log.Printf("NewEnumTypeDecl: %v\n", enumTypeDecl.Name)
}

if enumTypeDecl.Name != nil && p.lookupOrigin(enumTypeDecl.Name.Name, goName) != nil {
return nil
}

enumType, exist, err := p.createEnumType(goName, enumTypeDecl.Name, pnc)
if err != nil {
return fmt.Errorf("NewEnumTypeDecl: %v fail: %w", enumTypeDecl.Name, err)
Expand Down
21 changes: 11 additions & 10 deletions cl/nc/ncimpl/ncimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Converter struct {
Pubs map[string]string
TrimPrefixes []string
KeepUnderScore bool
GenThird bool
}

func (p *Converter) convFile(file string, obj *ast.Object) (goFile string, ok bool) {
Expand All @@ -63,11 +64,11 @@ func (p *Converter) convFile(file string, obj *ast.Object) (goFile string, ok bo

func (p *Converter) ConvDecl(file string, decl ast.Decl) (goName, goFile string, err error) {
obj := ast.ObjectOf(decl)
goFile, ok := p.convFile(file, obj)
if !ok {
err = nc.ErrSkip
return
}
goFile, _ = p.convFile(file, obj)
// if !ok {
// err = nc.ErrSkip
// return
// }
switch decl := decl.(type) {
case *ast.FuncDecl:
goName, err = p.ConvSym(obj, decl.MangledName)
Expand All @@ -89,11 +90,11 @@ func (p *Converter) ConvDecl(file string, decl ast.Decl) (goName, goFile string,
}

func (p *Converter) ConvMacro(file string, macro *ast.Macro) (goName, goFile string, err error) {
goFile, ok := p.convFile(file, nil)
if !ok {
err = nc.ErrSkip
return
}
goFile, _ = p.convFile(file, nil)
// if !ok {
// err = nc.ErrSkip
// return
// }
goName = p.constName(macro.Name)
return
}
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Config struct {
TypeMap map[string]string `json:"typeMap,omitempty"`
StaticLib bool `json:"staticLib,omitempty"`
HeaderOnly bool `json:"headerOnly,omitempty"`
GenThird bool `json:"genThird,omitempty"`
}

// json middleware for validating
Expand Down
Loading