testFrom: use test.Diff

This commit is contained in:
xushiwei
2025-06-23 21:14:26 +08:00
parent 3d53b12dea
commit b7b6e3bc93
5 changed files with 12 additions and 17 deletions

1
.gitignore vendored
View File

@@ -15,6 +15,7 @@ stories*.bin
.DS_Store
err.log
numpy.txt
result.txt
_go/
_runtime/

View File

@@ -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")
}
}
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 {