canSkipToBuild

This commit is contained in:
xushiwei
2024-06-17 05:33:07 +08:00
parent bcf44b8ab2
commit bf0148e047
4 changed files with 42 additions and 41 deletions

View File

@@ -25,7 +25,6 @@ import (
"log"
"os"
"sort"
"strings"
"github.com/goplus/llgo/cl/blocks"
"github.com/goplus/llgo/internal/typepatch"
@@ -91,20 +90,6 @@ func (p *context) pkgNoInit(pkg *types.Package) bool {
return false
}
func ignoreName(name string) bool {
/* TODO(xsw): confirm this is not needed more
if name == "unsafe.init" {
return true
}
*/
return strings.HasPrefix(name, "internal/") || strings.HasPrefix(name, "crypto/") ||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
strings.HasPrefix(name, "time.") || strings.HasPrefix(name, "syscall.") ||
strings.HasPrefix(name, "os.") || strings.HasPrefix(name, "plugin.") ||
strings.HasPrefix(name, "reflect.") || strings.HasPrefix(name, "errors.") ||
strings.HasPrefix(name, "runtime/")
}
// -----------------------------------------------------------------------------
type instrOrValue interface {

View File

@@ -490,6 +490,20 @@ func replaceGoName(v string, pos int) string {
return v
}
func ignoreName(name string) bool {
/* TODO(xsw): confirm this is not needed more
if name == "unsafe.init" {
return true
}
*/
return strings.HasPrefix(name, "internal/") || strings.HasPrefix(name, "crypto/") ||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
strings.HasPrefix(name, "time.") || strings.HasPrefix(name, "syscall.") ||
strings.HasPrefix(name, "os.") || strings.HasPrefix(name, "plugin.") ||
strings.HasPrefix(name, "reflect.") || strings.HasPrefix(name, "errors.") ||
strings.HasPrefix(name, "runtime/")
}
// -----------------------------------------------------------------------------
const (

View File

@@ -52,7 +52,7 @@ type Command struct {
// Llgo command
var Llgo = &Command{
UsageLine: "llgo",
Short: `llgo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem.`,
Short: `llgo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python.`,
// Commands initialized in package main
}

View File

@@ -292,18 +292,18 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string,
if app == "" {
app = filepath.Join(conf.BinPath, name+conf.AppExt)
}
const N = 6
const N = 5
args := make([]string, N, len(pkg.Imports)+len(runtimeFiles)+(N+1))
args[0] = "-o"
args[1] = app
args[2] = "-Wno-override-module"
args[3] = "-fuse-ld=lld"
args[4] = "-Xlinker"
args[3] = "-Xlinker"
if runtime.GOOS == "darwin" { // ld64.lld (macOS)
args[5] = "-dead_strip"
args[4] = "-dead_strip"
} else { // ld.lld (Unix), lld-link (Windows), wasm-ld (WebAssembly)
args[5] = "--gc-sections"
args[4] = "--gc-sections"
}
//args[5] = "-fuse-ld=lld" // TODO(xsw): to check lld exists or not
//args[6] = "-O2"
needRuntime := false
needPyInit := false
@@ -399,25 +399,6 @@ func buildPkg(ctx *context, aPkg *aPackage) {
aPkg.LPkg = ret
}
func canSkipToBuild(pkgPath string) bool {
switch pkgPath {
case "unsafe", "errors", "runtime", "sync": // TODO(xsw): remove it
return true
default:
return strings.HasPrefix(pkgPath, "internal/") ||
strings.HasPrefix(pkgPath, "runtime/internal/")
}
}
type none struct{}
var hasAltPkg = map[string]none{
"math": {},
"sync": {},
"sync/atomic": {},
"runtime": {},
}
const (
altPkgPathPrefix = "github.com/goplus/llgo/internal/lib/"
)
@@ -468,7 +449,9 @@ func allPkgs(ctx *context, initial []*packages.Package) (all []*aPackage, errs [
var altPkg *packages.Cached
var ssaPkg = createSSAPkg(prog, p, verbose)
if _, ok := hasAltPkg[p.PkgPath]; ok {
altPkg = ctx.dedup.Check(altPkgPathPrefix + p.PkgPath)
if altPkg = ctx.dedup.Check(altPkgPathPrefix + p.PkgPath); altPkg == nil {
return
}
}
all = append(all, &aPackage{p, ssaPkg, altPkg, nil})
} else {
@@ -685,6 +668,25 @@ func decodeFile(outFile string, zipf *zip.File) (err error) {
return
}
func canSkipToBuild(pkgPath string) bool {
switch pkgPath {
case "unsafe", "errors": // TODO(xsw): remove it
return true
default:
return strings.HasPrefix(pkgPath, "internal/") ||
strings.HasPrefix(pkgPath, "runtime/internal/")
}
}
type none struct{}
var hasAltPkg = map[string]none{
"math": {},
"sync": {},
"sync/atomic": {},
"runtime": {},
}
func check(err error) {
if err != nil {
panic(err)