patch sync/atomic; typepatch fix (don't change types)
This commit is contained in:
@@ -5,6 +5,20 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
var v int64 = 100
|
||||
println(atomic.AddInt64(&v, 1))
|
||||
var v int64
|
||||
|
||||
atomic.StoreInt64(&v, 100)
|
||||
println("store:", atomic.LoadInt64(&v))
|
||||
|
||||
ret := atomic.AddInt64(&v, 1)
|
||||
println("ret:", ret, "v:", v)
|
||||
|
||||
swp := atomic.CompareAndSwapInt64(&v, 100, 102)
|
||||
println("swp:", swp, "v:", v)
|
||||
|
||||
swp = atomic.CompareAndSwapInt64(&v, 101, 102)
|
||||
println("swp:", swp, "v:", v)
|
||||
|
||||
ret = atomic.AddInt64(&v, -1)
|
||||
println("ret:", ret, "v:", v)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
|
||||
func TestCollectSkipNames(t *testing.T) {
|
||||
ctx := &context{skips: make(map[string]none)}
|
||||
ctx.collectSkipNames("//llgo:skip")
|
||||
ctx.collectSkipNames("//llgo:skip abs")
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/goplus/llgo/cl/blocks"
|
||||
"github.com/goplus/llgo/internal/packages"
|
||||
"github.com/goplus/llgo/internal/typepatch"
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
)
|
||||
@@ -143,6 +145,7 @@ type context struct {
|
||||
bvals map[ssa.Value]llssa.Expr // block values
|
||||
vargs map[*ssa.Alloc][]llssa.Expr // varargs
|
||||
|
||||
patches Patches
|
||||
blkInfos []blocks.Info
|
||||
|
||||
inits []func()
|
||||
@@ -1000,33 +1003,42 @@ func (p *context) compileValues(b llssa.Builder, vals []ssa.Value, hasVArg int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Patches is patches of some packages.
|
||||
type Patches = map[string]*ssa.Package
|
||||
|
||||
// NewPackage compiles a Go package to LLVM IR package.
|
||||
func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret llssa.Package, err error) {
|
||||
return NewPackageEx(prog, pkg, nil, files)
|
||||
return NewPackageEx(prog, nil, pkg, files)
|
||||
}
|
||||
|
||||
// NewPackageEx compiles a Go package (pkg) to LLVM IR package.
|
||||
// The Go package may have an alternative package (alt).
|
||||
// The pkg and alt have the same (Pkg *types.Package).
|
||||
func NewPackageEx(prog llssa.Program, pkg, alt *ssa.Package, files []*ast.File) (ret llssa.Package, err error) {
|
||||
// NewPackageEx compiles a Go package to LLVM IR package.
|
||||
func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files []*ast.File) (ret llssa.Package, err error) {
|
||||
pkgProg := pkg.Prog
|
||||
pkgTypes := pkg.Pkg
|
||||
pkgName, pkgPath := pkgTypes.Name(), llssa.PathOf(pkgTypes)
|
||||
alt, hasPatch := patches[pkgPath]
|
||||
if hasPatch {
|
||||
pkgTypes = typepatch.Pkg(pkgTypes, alt.Pkg)
|
||||
}
|
||||
if packages.DebugPackagesLoad {
|
||||
log.Println("==> NewPackageEx", pkgPath, hasPatch)
|
||||
}
|
||||
if pkgPath == llssa.PkgRuntime {
|
||||
prog.SetRuntime(pkgTypes)
|
||||
}
|
||||
ret = prog.NewPackage(pkgName, pkgPath)
|
||||
|
||||
ctx := &context{
|
||||
prog: prog,
|
||||
pkg: ret,
|
||||
fset: pkgProg.Fset,
|
||||
goProg: pkgProg,
|
||||
goTyps: pkgTypes,
|
||||
goPkg: pkg,
|
||||
link: make(map[string]string),
|
||||
skips: make(map[string]none),
|
||||
vargs: make(map[*ssa.Alloc][]llssa.Expr),
|
||||
prog: prog,
|
||||
pkg: ret,
|
||||
fset: pkgProg.Fset,
|
||||
goProg: pkgProg,
|
||||
goTyps: pkgTypes,
|
||||
goPkg: pkg,
|
||||
patches: patches,
|
||||
link: make(map[string]string),
|
||||
skips: make(map[string]none),
|
||||
vargs: make(map[*ssa.Alloc][]llssa.Expr),
|
||||
loaded: map[*types.Package]*pkgInfo{
|
||||
types.Unsafe: {kind: PkgDeclOnly}, // TODO(xsw): PkgNoInit or PkgDeclOnly?
|
||||
},
|
||||
@@ -1034,7 +1046,7 @@ func NewPackageEx(prog llssa.Program, pkg, alt *ssa.Package, files []*ast.File)
|
||||
ctx.initPyModule()
|
||||
ctx.initFiles(pkgPath, files)
|
||||
|
||||
if alt != nil {
|
||||
if hasPatch {
|
||||
skips := ctx.skips
|
||||
ctx.skips = nil
|
||||
processPkg(ctx, ret, alt)
|
||||
|
||||
10
cl/import.go
10
cl/import.go
@@ -127,14 +127,22 @@ func pkgKindByScope(scope *types.Scope) (int, string) {
|
||||
}
|
||||
|
||||
func (p *context) importPkg(pkg *types.Package, i *pkgInfo) {
|
||||
pkgPath := llssa.PathOf(pkg)
|
||||
scope := pkg.Scope()
|
||||
kind, _ := pkgKindByScope(scope)
|
||||
if kind == PkgNormal {
|
||||
if alt, ok := p.patches[pkgPath]; ok {
|
||||
pkg = alt.Pkg
|
||||
scope = pkg.Scope()
|
||||
if kind, _ = pkgKindByScope(scope); kind != PkgNormal {
|
||||
goto start
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
start:
|
||||
i.kind = kind
|
||||
fset := p.fset
|
||||
pkgPath := llssa.PathOf(pkg)
|
||||
names := scope.Names()
|
||||
syms := newPkgSymInfo()
|
||||
for _, name := range names {
|
||||
|
||||
Reference in New Issue
Block a user