llgo:skipall
This commit is contained in:
@@ -100,10 +100,11 @@ func ignoreName(name string) bool {
|
|||||||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
||||||
strings.HasPrefix(name, "time.") || strings.HasPrefix(name, "syscall.") ||
|
strings.HasPrefix(name, "time.") || strings.HasPrefix(name, "syscall.") ||
|
||||||
strings.HasPrefix(name, "os.") || strings.HasPrefix(name, "plugin.") ||
|
strings.HasPrefix(name, "os.") || strings.HasPrefix(name, "plugin.") ||
|
||||||
strings.HasPrefix(name, "reflect.") || strings.HasPrefix(name, "errors.") {
|
strings.HasPrefix(name, "reflect.") || strings.HasPrefix(name, "errors.") ||
|
||||||
|
strings.HasPrefix(name, "sync.") {
|
||||||
return true // TODO(xsw)
|
return true // TODO(xsw)
|
||||||
}
|
}
|
||||||
return inPkg(name, "runtime") || inPkg(name, "sync")
|
return inPkg(name, "runtime")
|
||||||
}
|
}
|
||||||
|
|
||||||
func inPkg(name, pkg string) bool {
|
func inPkg(name, pkg string) bool {
|
||||||
@@ -157,6 +158,8 @@ type context struct {
|
|||||||
|
|
||||||
inits []func()
|
inits []func()
|
||||||
phis []func()
|
phis []func()
|
||||||
|
|
||||||
|
skipall bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *context) inMain(instr ssa.Instruction) bool {
|
func (p *context) inMain(instr ssa.Instruction) bool {
|
||||||
@@ -1048,7 +1051,9 @@ func NewPackageEx(prog llssa.Program, pkg, alt *ssa.Package, files []*ast.File)
|
|||||||
processPkg(ctx, ret, alt)
|
processPkg(ctx, ret, alt)
|
||||||
ctx.skips = skips
|
ctx.skips = skips
|
||||||
}
|
}
|
||||||
|
if !ctx.skipall {
|
||||||
processPkg(ctx, ret, pkg)
|
processPkg(ctx, ret, pkg)
|
||||||
|
}
|
||||||
for len(ctx.inits) > 0 {
|
for len(ctx.inits) > 0 {
|
||||||
inits := ctx.inits
|
inits := ctx.inits
|
||||||
ctx.inits = nil
|
ctx.inits = nil
|
||||||
|
|||||||
12
cl/import.go
12
cl/import.go
@@ -193,6 +193,8 @@ func (p *context) initFiles(pkgPath string, files []*ast.File) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// llgo:skip symbol1 symbol2 ...
|
||||||
|
// llgo:skipall
|
||||||
func (p *context) collectSkipNames(line string) {
|
func (p *context) collectSkipNames(line string) {
|
||||||
const (
|
const (
|
||||||
skip = "//llgo:skip"
|
skip = "//llgo:skip"
|
||||||
@@ -206,7 +208,15 @@ func (p *context) collectSkipNames(line string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *context) collectSkip(line string, prefix int) {
|
func (p *context) collectSkip(line string, prefix int) {
|
||||||
names := strings.Split(line[prefix:], " ")
|
line = line[prefix:]
|
||||||
|
if line == "all" {
|
||||||
|
p.skipall = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(line) == 0 || line[0] != ' ' {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
names := strings.Split(line[1:], " ")
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
if name != "" {
|
if name != "" {
|
||||||
p.skips[name] = none{}
|
p.skips[name] = none{}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -159,6 +160,10 @@ func Do(args []string, conf *Config) {
|
|||||||
|
|
||||||
var runtimeFiles []string
|
var runtimeFiles []string
|
||||||
if needRt {
|
if needRt {
|
||||||
|
// TODO(xsw): maybe we need trace runtime sometimes
|
||||||
|
llssa.SetDebug(0)
|
||||||
|
cl.SetDebug(0)
|
||||||
|
|
||||||
skip := make(map[string]bool)
|
skip := make(map[string]bool)
|
||||||
for _, v := range pkgs {
|
for _, v := range pkgs {
|
||||||
skip[v.PkgPath] = true
|
skip[v.PkgPath] = true
|
||||||
@@ -208,7 +213,7 @@ const (
|
|||||||
|
|
||||||
func buildAllPkgs(prog llssa.Program, imp importer, initial []*packages.Package, skip map[string]bool, mode Mode, verbose bool) (pkgs []*aPackage) {
|
func buildAllPkgs(prog llssa.Program, imp importer, initial []*packages.Package, skip map[string]bool, mode Mode, verbose bool) (pkgs []*aPackage) {
|
||||||
// Create SSA-form program representation.
|
// Create SSA-form program representation.
|
||||||
ssaProg, pkgs, errPkgs := allPkgs(imp, initial, ssaBuildMode)
|
ssaProg, pkgs, errPkgs := allPkgs(imp, initial, ssaBuildMode, verbose)
|
||||||
ssaProg.Build()
|
ssaProg.Build()
|
||||||
for _, errPkg := range errPkgs {
|
for _, errPkg := range errPkgs {
|
||||||
for _, err := range errPkg.Errors {
|
for _, err := range errPkg.Errors {
|
||||||
@@ -394,7 +399,7 @@ func buildPkg(prog llssa.Program, aPkg *aPackage, mode Mode, verbose bool) {
|
|||||||
|
|
||||||
func canSkipToBuild(pkgPath string) bool {
|
func canSkipToBuild(pkgPath string) bool {
|
||||||
switch pkgPath {
|
switch pkgPath {
|
||||||
case "unsafe", "runtime", "errors", "sync", "sync/atomic":
|
case "unsafe", "runtime", "errors", "sync":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return strings.HasPrefix(pkgPath, "internal/") ||
|
return strings.HasPrefix(pkgPath, "internal/") ||
|
||||||
@@ -419,7 +424,7 @@ var hasAltPkg = map[string]none{
|
|||||||
|
|
||||||
type importer = func(pkgPath string) *packages.Package
|
type importer = func(pkgPath string) *packages.Package
|
||||||
|
|
||||||
func allPkgs(imp importer, initial []*packages.Package, mode ssa.BuilderMode) (prog *ssa.Program, all []*aPackage, errs []*packages.Package) {
|
func allPkgs(imp importer, initial []*packages.Package, mode ssa.BuilderMode, verbose bool) (prog *ssa.Program, all []*aPackage, errs []*packages.Package) {
|
||||||
var fset *token.FileSet
|
var fset *token.FileSet
|
||||||
if len(initial) > 0 {
|
if len(initial) > 0 {
|
||||||
fset = initial[0].Fset
|
fset = initial[0].Fset
|
||||||
@@ -433,9 +438,12 @@ func allPkgs(imp importer, initial []*packages.Package, mode ssa.BuilderMode) (p
|
|||||||
var ssaPkg = prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true)
|
var ssaPkg = prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true)
|
||||||
if imp != nil {
|
if imp != nil {
|
||||||
if _, ok := hasAltPkg[p.PkgPath]; ok {
|
if _, ok := hasAltPkg[p.PkgPath]; ok {
|
||||||
|
if verbose {
|
||||||
|
log.Println("==> Patching", p.PkgPath)
|
||||||
|
}
|
||||||
altPkgPath := "github.com/goplus/llgo/internal/lib/" + p.PkgPath
|
altPkgPath := "github.com/goplus/llgo/internal/lib/" + p.PkgPath
|
||||||
if altPkg = imp(altPkgPath); altPkg != nil { // TODO(xsw): how to minimize import times
|
if altPkg = imp(altPkgPath); altPkg != nil { // TODO(xsw): how to minimize import times
|
||||||
altSSA = createAltSSAPkg(prog, altPkg)
|
altSSA = createAltSSAPkg(prog, altPkg, verbose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,14 +455,17 @@ func allPkgs(imp importer, initial []*packages.Package, mode ssa.BuilderMode) (p
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func createAltSSAPkg(prog *ssa.Program, alt *packages.Package) *ssa.Package {
|
func createAltSSAPkg(prog *ssa.Program, alt *packages.Package, verbose bool) *ssa.Package {
|
||||||
altPath := alt.Types.Path()
|
altPath := alt.Types.Path()
|
||||||
altSSA := prog.ImportedPackage(altPath)
|
altSSA := prog.ImportedPackage(altPath)
|
||||||
if altSSA == nil {
|
if altSSA == nil {
|
||||||
packages.Visit([]*packages.Package{alt}, nil, func(p *packages.Package) {
|
packages.Visit([]*packages.Package{alt}, nil, func(p *packages.Package) {
|
||||||
pkgTypes := p.Types
|
pkgTypes := p.Types
|
||||||
if pkgTypes != nil && !p.IllTyped {
|
if pkgTypes != nil && !p.IllTyped {
|
||||||
if prog.ImportedPackage(pkgTypes.Path()) == nil {
|
if pkgPath := pkgTypes.Path(); prog.ImportedPackage(pkgPath) == nil {
|
||||||
|
if verbose {
|
||||||
|
log.Println("==> SSAPackage", pkgPath)
|
||||||
|
}
|
||||||
prog.CreatePackage(pkgTypes, p.Syntax, p.TypesInfo, true)
|
prog.CreatePackage(pkgTypes, p.Syntax, p.TypesInfo, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package atomic
|
package atomic
|
||||||
|
|
||||||
// llgo:skip init
|
// llgo:skipall
|
||||||
import (
|
import (
|
||||||
_ "unsafe"
|
_ "unsafe"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user