diff --git a/.gitignore b/.gitignore index 3d29051e..7c0b0d92 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ stories*.bin .DS_Store err.log numpy.txt +result.txt _go/ _runtime/ diff --git a/cl/cltest/cltest.go b/cl/cltest/cltest.go index 1b6a82e4..25cc9bea 100644 --- a/cl/cltest/cltest.go +++ b/cl/cltest/cltest.go @@ -18,6 +18,7 @@ package cltest import ( "archive/zip" + "bytes" "go/ast" "go/parser" "go/token" @@ -35,6 +36,7 @@ import ( "github.com/goplus/llgo/cl" "github.com/goplus/llgo/internal/llgen" "github.com/goplus/llgo/ssa/ssatest" + "github.com/qiniu/x/test" "golang.org/x/tools/go/ssa" "golang.org/x/tools/go/ssa/ssautil" @@ -112,14 +114,13 @@ func testFrom(t *testing.T, pkgDir, sel string) { return } log.Println("Parsing", pkgDir) + v := llgen.GenFrom(pkgDir) out := pkgDir + "/out.ll" - b, err := os.ReadFile(out) - if err != nil { - t.Fatal("ReadFile failed:", err) - } - expected := string(b) - if v := llgen.GenFrom(pkgDir); v != expected && expected != ";" { // expected == ";" means skipping out.ll - t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected) + b, _ := os.ReadFile(out) + if !bytes.Equal(b, []byte{';'}) { // expected == ";" means skipping out.ll + if test.Diff(t, pkgDir+"/result.txt", []byte(v), b) { + t.Fatal("llgen.GenFrom: unexpect result") + } } } diff --git a/cl/compile.go b/cl/compile.go index 8e9434eb..e8c3fdcb 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -213,15 +213,8 @@ func isCgoVar(name string) bool { } func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Function, llssa.PyObjRef, int) { - pkgTypes, name, ftype := p.funcName(f, true) + pkgTypes, name, ftype := p.funcName(f) if ftype != goFunc { - /* - if ftype == pyFunc { - // TODO(xsw): pyMod == "" - fnName := pysymPrefix + p.pyMod + "." + name - return nil, pkg.NewPyFunc(fnName, f.Signature, call), pyFunc - } - */ return nil, nil, ignoredFunc } sig := f.Signature diff --git a/cl/import.go b/cl/import.go index f5e48c0b..be3cc8c3 100644 --- a/cl/import.go +++ b/cl/import.go @@ -497,7 +497,7 @@ const ( llgoAtomicOpLast = llgoAtomicOpBase + int(llssa.OpUMin) ) -func (p *context) funcName(fn *ssa.Function, ignore bool) (*types.Package, string, int) { +func (p *context) funcName(fn *ssa.Function) (*types.Package, string, int) { var pkg *types.Package var orgName string if origin := fn.Origin(); origin != nil { diff --git a/cl/instr.go b/cl/instr.go index aebc8968..47a93df7 100644 --- a/cl/instr.go +++ b/cl/instr.go @@ -334,7 +334,7 @@ var llgoInstrs = map[string]int{ // funcOf returns a function by name and set ftype = goFunc, cFunc, etc. // or returns nil and set ftype = llgoCstr, llgoAlloca, llgoUnreachable, etc. func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObjRef, ftype int) { - pkgTypes, name, ftype := p.funcName(fn, false) + pkgTypes, name, ftype := p.funcName(fn) switch ftype { case pyFunc: if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {