testFrom: use test.Diff
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,6 +15,7 @@ stories*.bin
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
err.log
|
err.log
|
||||||
numpy.txt
|
numpy.txt
|
||||||
|
result.txt
|
||||||
|
|
||||||
_go/
|
_go/
|
||||||
_runtime/
|
_runtime/
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package cltest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"bytes"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
@@ -35,6 +36,7 @@ import (
|
|||||||
"github.com/goplus/llgo/cl"
|
"github.com/goplus/llgo/cl"
|
||||||
"github.com/goplus/llgo/internal/llgen"
|
"github.com/goplus/llgo/internal/llgen"
|
||||||
"github.com/goplus/llgo/ssa/ssatest"
|
"github.com/goplus/llgo/ssa/ssatest"
|
||||||
|
"github.com/qiniu/x/test"
|
||||||
"golang.org/x/tools/go/ssa"
|
"golang.org/x/tools/go/ssa"
|
||||||
"golang.org/x/tools/go/ssa/ssautil"
|
"golang.org/x/tools/go/ssa/ssautil"
|
||||||
|
|
||||||
@@ -112,14 +114,13 @@ func testFrom(t *testing.T, pkgDir, sel string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("Parsing", pkgDir)
|
log.Println("Parsing", pkgDir)
|
||||||
|
v := llgen.GenFrom(pkgDir)
|
||||||
out := pkgDir + "/out.ll"
|
out := pkgDir + "/out.ll"
|
||||||
b, err := os.ReadFile(out)
|
b, _ := os.ReadFile(out)
|
||||||
if err != nil {
|
if !bytes.Equal(b, []byte{';'}) { // expected == ";" means skipping out.ll
|
||||||
t.Fatal("ReadFile failed:", err)
|
if test.Diff(t, pkgDir+"/result.txt", []byte(v), b) {
|
||||||
}
|
t.Fatal("llgen.GenFrom: unexpect result")
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -213,15 +213,8 @@ func isCgoVar(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Function, llssa.PyObjRef, int) {
|
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 != 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
|
return nil, nil, ignoredFunc
|
||||||
}
|
}
|
||||||
sig := f.Signature
|
sig := f.Signature
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ const (
|
|||||||
llgoAtomicOpLast = llgoAtomicOpBase + int(llssa.OpUMin)
|
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 pkg *types.Package
|
||||||
var orgName string
|
var orgName string
|
||||||
if origin := fn.Origin(); origin != nil {
|
if origin := fn.Origin(); origin != nil {
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ var llgoInstrs = map[string]int{
|
|||||||
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
|
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
|
||||||
// or returns nil and set ftype = llgoCstr, llgoAlloca, llgoUnreachable, 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) {
|
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 {
|
switch ftype {
|
||||||
case pyFunc:
|
case pyFunc:
|
||||||
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
|
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
|
||||||
|
|||||||
Reference in New Issue
Block a user