runtime: config hasAltPkg and ignoreName
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goplus/llgo/compiler/internal/env"
|
"github.com/goplus/llgo/compiler/internal/env"
|
||||||
llssa "github.com/goplus/llgo/compiler/ssa"
|
llssa "github.com/goplus/llgo/compiler/ssa"
|
||||||
|
llruntime "github.com/goplus/llgo/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -668,4 +669,8 @@ func replaceGoName(v string, pos int) string {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ignoreName(name string) bool {
|
||||||
|
return llruntime.IgnoreName(name)
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import (
|
|||||||
"github.com/goplus/llgo/xtool/env/llvm"
|
"github.com/goplus/llgo/xtool/env/llvm"
|
||||||
|
|
||||||
llssa "github.com/goplus/llgo/compiler/ssa"
|
llssa "github.com/goplus/llgo/compiler/ssa"
|
||||||
|
llruntime "github.com/goplus/llgo/runtime"
|
||||||
clangCheck "github.com/goplus/llgo/xtool/clang/check"
|
clangCheck "github.com/goplus/llgo/xtool/clang/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
sizes := prog.TypeSizes
|
sizes := prog.TypeSizes
|
||||||
dedup := packages.NewDeduper()
|
dedup := packages.NewDeduper()
|
||||||
dedup.SetPreload(func(pkg *types.Package, files []*ast.File) {
|
dedup.SetPreload(func(pkg *types.Package, files []*ast.File) {
|
||||||
if canSkipToBuild(pkg.Path()) {
|
if llruntime.SkipToBuild(pkg.Path()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cl.ParsePkgSyntax(prog, pkg, files)
|
cl.ParsePkgSyntax(prog, pkg, files)
|
||||||
@@ -580,7 +581,7 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) (cgoLdflags []string,
|
|||||||
if debugBuild || verbose {
|
if debugBuild || verbose {
|
||||||
fmt.Fprintln(os.Stderr, pkgPath)
|
fmt.Fprintln(os.Stderr, pkgPath)
|
||||||
}
|
}
|
||||||
if canSkipToBuild(pkgPath) {
|
if llruntime.SkipToBuild(pkgPath) {
|
||||||
pkg.ExportFile = ""
|
pkg.ExportFile = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -642,8 +643,8 @@ const (
|
|||||||
func altPkgs(initial []*packages.Package, alts ...string) []string {
|
func altPkgs(initial []*packages.Package, alts ...string) []string {
|
||||||
packages.Visit(initial, nil, func(p *packages.Package) {
|
packages.Visit(initial, nil, func(p *packages.Package) {
|
||||||
if p.Types != nil && !p.IllTyped {
|
if p.Types != nil && !p.IllTyped {
|
||||||
if _, ok := hasAltPkg[p.ID]; ok {
|
if llruntime.HasAltPkg(p.PkgPath) {
|
||||||
alts = append(alts, altPkgPathPrefix+p.ID)
|
alts = append(alts, altPkgPathPrefix+p.PkgPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -691,7 +692,7 @@ func allPkgs(ctx *context, initial []*packages.Package, verbose bool) (all []*aP
|
|||||||
}
|
}
|
||||||
var altPkg *packages.Cached
|
var altPkg *packages.Cached
|
||||||
var ssaPkg = createSSAPkg(prog, p, verbose)
|
var ssaPkg = createSSAPkg(prog, p, verbose)
|
||||||
if _, ok := hasAltPkg[pkgPath]; ok {
|
if llruntime.HasAltPkg(pkgPath) {
|
||||||
if altPkg = ctx.dedup.Check(altPkgPathPrefix + pkgPath); altPkg == nil {
|
if altPkg = ctx.dedup.Check(altPkgPathPrefix + pkgPath); altPkg == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -864,13 +865,6 @@ func pkgExists(initial []*packages.Package, pkg *packages.Package) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func canSkipToBuild(pkgPath string) bool {
|
|
||||||
if _, ok := hasAltPkg[pkgPath]; ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return pkgPath == "unsafe"
|
|
||||||
}
|
|
||||||
|
|
||||||
// findDylibDep finds the dylib dependency in the executable. It returns empty
|
// findDylibDep finds the dylib dependency in the executable. It returns empty
|
||||||
// string if not found.
|
// string if not found.
|
||||||
func findDylibDep(exe, lib string) string {
|
func findDylibDep(exe, lib string) string {
|
||||||
@@ -889,49 +883,6 @@ func findDylibDep(exe, lib string) string {
|
|||||||
|
|
||||||
type none struct{}
|
type none struct{}
|
||||||
|
|
||||||
var hasAltPkg = map[string]none{
|
|
||||||
"crypto/hmac": {},
|
|
||||||
"crypto/md5": {},
|
|
||||||
"crypto/rand": {},
|
|
||||||
"crypto/sha1": {},
|
|
||||||
"crypto/sha256": {},
|
|
||||||
"crypto/sha512": {},
|
|
||||||
"crypto/subtle": {},
|
|
||||||
"go/parser": {},
|
|
||||||
"hash/crc32": {},
|
|
||||||
"internal/abi": {},
|
|
||||||
"internal/bytealg": {},
|
|
||||||
"internal/cpu": {},
|
|
||||||
"internal/itoa": {},
|
|
||||||
"internal/filepathlite": {},
|
|
||||||
"internal/godebug": {},
|
|
||||||
"internal/oserror": {},
|
|
||||||
"internal/poll": {},
|
|
||||||
"internal/race": {},
|
|
||||||
"internal/reflectlite": {},
|
|
||||||
"internal/stringslite": {},
|
|
||||||
"internal/syscall/execenv": {},
|
|
||||||
"internal/syscall/unix": {},
|
|
||||||
"math": {},
|
|
||||||
"math/big": {},
|
|
||||||
"math/cmplx": {},
|
|
||||||
"math/rand": {},
|
|
||||||
"reflect": {},
|
|
||||||
"sync": {},
|
|
||||||
"sync/atomic": {},
|
|
||||||
"syscall": {},
|
|
||||||
"time": {},
|
|
||||||
"os": {},
|
|
||||||
"os/exec": {},
|
|
||||||
"os/signal": {},
|
|
||||||
"runtime": {},
|
|
||||||
"runtime/debug": {},
|
|
||||||
"runtime/pprof": {},
|
|
||||||
"runtime/trace": {},
|
|
||||||
"runtime/internal/syscall": {},
|
|
||||||
"io": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
package filepathlite
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package fmtsort provides a general stable ordering mechanism
|
|
||||||
// for maps, on behalf of the fmt and text/template packages.
|
|
||||||
// It is not guaranteed to be efficient and works only for types
|
|
||||||
// that are valid map keys.
|
|
||||||
package fmtsort
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// llgo:skipall
|
|
||||||
type _fmtsort struct{}
|
|
||||||
|
|
||||||
// Note: Throughout this package we avoid calling reflect.Value.Interface as
|
|
||||||
// it is not always legal to do so and it's easier to avoid the issue than to face it.
|
|
||||||
|
|
||||||
// SortedMap represents a map's keys and values. The keys and values are
|
|
||||||
// aligned in index order: Value[i] is the value in the map corresponding to Key[i].
|
|
||||||
type SortedMap struct {
|
|
||||||
Key []reflect.Value
|
|
||||||
Value []reflect.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *SortedMap) Len() int { return len(o.Key) }
|
|
||||||
func (o *SortedMap) Less(i, j int) bool { return compare(o.Key[i], o.Key[j]) < 0 }
|
|
||||||
func (o *SortedMap) Swap(i, j int) {
|
|
||||||
o.Key[i], o.Key[j] = o.Key[j], o.Key[i]
|
|
||||||
o.Value[i], o.Value[j] = o.Value[j], o.Value[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort accepts a map and returns a SortedMap that has the same keys and
|
|
||||||
// values but in a stable sorted order according to the keys, modulo issues
|
|
||||||
// raised by unorderable key values such as NaNs.
|
|
||||||
//
|
|
||||||
// The ordering rules are more general than with Go's < operator:
|
|
||||||
//
|
|
||||||
// - when applicable, nil compares low
|
|
||||||
// - ints, floats, and strings order by <
|
|
||||||
// - NaN compares less than non-NaN floats
|
|
||||||
// - bool compares false before true
|
|
||||||
// - complex compares real, then imag
|
|
||||||
// - pointers compare by machine address
|
|
||||||
// - channel values compare by machine address
|
|
||||||
// - structs compare each field in turn
|
|
||||||
// - arrays compare each element in turn.
|
|
||||||
// Otherwise identical arrays compare by length.
|
|
||||||
// - interface values compare first by reflect.Type describing the concrete type
|
|
||||||
// and then by concrete value as described in the previous rules.
|
|
||||||
func Sort(mapValue reflect.Value) *SortedMap {
|
|
||||||
if mapValue.Type().Kind() != reflect.Map {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Note: this code is arranged to not panic even in the presence
|
|
||||||
// of a concurrent map update. The runtime is responsible for
|
|
||||||
// yelling loudly if that happens. See issue 33275.
|
|
||||||
n := mapValue.Len()
|
|
||||||
key := make([]reflect.Value, 0, n)
|
|
||||||
value := make([]reflect.Value, 0, n)
|
|
||||||
iter := mapValue.MapRange()
|
|
||||||
for iter.Next() {
|
|
||||||
key = append(key, iter.Key())
|
|
||||||
value = append(value, iter.Value())
|
|
||||||
}
|
|
||||||
sorted := &SortedMap{
|
|
||||||
Key: key,
|
|
||||||
Value: value,
|
|
||||||
}
|
|
||||||
sort.Stable(sorted)
|
|
||||||
return sorted
|
|
||||||
}
|
|
||||||
|
|
||||||
// compare compares two values of the same type. It returns -1, 0, 1
|
|
||||||
// according to whether a > b (1), a == b (0), or a < b (-1).
|
|
||||||
// If the types differ, it returns -1.
|
|
||||||
// See the comment on Sort for the comparison rules.
|
|
||||||
func compare(aVal, bVal reflect.Value) int {
|
|
||||||
aType, bType := aVal.Type(), bVal.Type()
|
|
||||||
if aType != bType {
|
|
||||||
return -1 // No good answer possible, but don't return 0: they're not equal.
|
|
||||||
}
|
|
||||||
switch aVal.Kind() {
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
||||||
a, b := aVal.Int(), bVal.Int()
|
|
||||||
switch {
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
|
||||||
a, b := aVal.Uint(), bVal.Uint()
|
|
||||||
switch {
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
case reflect.String:
|
|
||||||
a, b := aVal.String(), bVal.String()
|
|
||||||
switch {
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
case reflect.Float32, reflect.Float64:
|
|
||||||
return floatCompare(aVal.Float(), bVal.Float())
|
|
||||||
case reflect.Complex64, reflect.Complex128:
|
|
||||||
a, b := aVal.Complex(), bVal.Complex()
|
|
||||||
if c := floatCompare(real(a), real(b)); c != 0 {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return floatCompare(imag(a), imag(b))
|
|
||||||
case reflect.Bool:
|
|
||||||
a, b := aVal.Bool(), bVal.Bool()
|
|
||||||
switch {
|
|
||||||
case a == b:
|
|
||||||
return 0
|
|
||||||
case a:
|
|
||||||
return 1
|
|
||||||
default:
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
case reflect.Pointer, reflect.UnsafePointer:
|
|
||||||
a, b := aVal.Pointer(), bVal.Pointer()
|
|
||||||
switch {
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
case reflect.Chan:
|
|
||||||
if c, ok := nilCompare(aVal, bVal); ok {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
ap, bp := aVal.Pointer(), bVal.Pointer()
|
|
||||||
switch {
|
|
||||||
case ap < bp:
|
|
||||||
return -1
|
|
||||||
case ap > bp:
|
|
||||||
return 1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
case reflect.Struct:
|
|
||||||
for i := 0; i < aVal.NumField(); i++ {
|
|
||||||
if c := compare(aVal.Field(i), bVal.Field(i)); c != 0 {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
case reflect.Array:
|
|
||||||
for i := 0; i < aVal.Len(); i++ {
|
|
||||||
if c := compare(aVal.Index(i), bVal.Index(i)); c != 0 {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
case reflect.Interface:
|
|
||||||
if c, ok := nilCompare(aVal, bVal); ok {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
c := compare(reflect.ValueOf(aVal.Elem().Type()), reflect.ValueOf(bVal.Elem().Type()))
|
|
||||||
if c != 0 {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return compare(aVal.Elem(), bVal.Elem())
|
|
||||||
default:
|
|
||||||
// Certain types cannot appear as keys (maps, funcs, slices), but be explicit.
|
|
||||||
panic("bad type in compare: " + aType.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// nilCompare checks whether either value is nil. If not, the boolean is false.
|
|
||||||
// If either value is nil, the boolean is true and the integer is the comparison
|
|
||||||
// value. The comparison is defined to be 0 if both are nil, otherwise the one
|
|
||||||
// nil value compares low. Both arguments must represent a chan, func,
|
|
||||||
// interface, map, pointer, or slice.
|
|
||||||
func nilCompare(aVal, bVal reflect.Value) (int, bool) {
|
|
||||||
if aVal.IsNil() {
|
|
||||||
if bVal.IsNil() {
|
|
||||||
return 0, true
|
|
||||||
}
|
|
||||||
return -1, true
|
|
||||||
}
|
|
||||||
if bVal.IsNil() {
|
|
||||||
return 1, true
|
|
||||||
}
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// floatCompare compares two floating-point values. NaNs compare low.
|
|
||||||
func floatCompare(a, b float64) int {
|
|
||||||
switch {
|
|
||||||
case isNaN(a):
|
|
||||||
return -1 // No good answer if b is a NaN so don't bother checking.
|
|
||||||
case isNaN(b):
|
|
||||||
return 1
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func isNaN(a float64) bool {
|
|
||||||
return a != a
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
package race
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
package stringslite
|
|
||||||
90
runtime/runtime.go
Normal file
90
runtime/runtime.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package runtime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SkipToBuild(pkgPath string) bool {
|
||||||
|
if _, ok := hasAltPkg[pkgPath]; ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if _, ok := supportInternal[pkgPath]; ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch pkgPath {
|
||||||
|
case "unsafe":
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return strings.HasPrefix(pkgPath, "internal/") ||
|
||||||
|
strings.HasPrefix(pkgPath, "runtime/internal/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func IgnoreName(name string) bool {
|
||||||
|
/* TODO(xsw): confirm this is not needed more
|
||||||
|
if name == "unsafe.init" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
const internal = "internal/"
|
||||||
|
return (strings.HasPrefix(name, internal) && IsSupportInternal(name)) ||
|
||||||
|
strings.HasPrefix(name, "runtime/") || strings.HasPrefix(name, "arena.") ||
|
||||||
|
strings.HasPrefix(name, "maps.") || strings.HasPrefix(name, "plugin.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsSupportInternal(path string) (b bool) {
|
||||||
|
_, b = supportInternal[path]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasAltPkg(path string) (b bool) {
|
||||||
|
_, b = hasAltPkg[path]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type none struct{}
|
||||||
|
|
||||||
|
var hasAltPkg = map[string]none{
|
||||||
|
"crypto/hmac": {},
|
||||||
|
"crypto/md5": {},
|
||||||
|
"crypto/rand": {},
|
||||||
|
"crypto/sha1": {},
|
||||||
|
"crypto/sha256": {},
|
||||||
|
"crypto/sha512": {},
|
||||||
|
"crypto/subtle": {},
|
||||||
|
"hash/crc32": {},
|
||||||
|
"internal/abi": {},
|
||||||
|
"internal/bytealg": {},
|
||||||
|
"internal/itoa": {},
|
||||||
|
"internal/oserror": {},
|
||||||
|
"internal/reflectlite": {},
|
||||||
|
"internal/syscall/execenv": {},
|
||||||
|
"internal/syscall/unix": {},
|
||||||
|
"math": {},
|
||||||
|
"math/big": {},
|
||||||
|
"math/cmplx": {},
|
||||||
|
"math/rand": {},
|
||||||
|
"reflect": {},
|
||||||
|
"sync": {},
|
||||||
|
"sync/atomic": {},
|
||||||
|
"syscall": {},
|
||||||
|
"time": {},
|
||||||
|
"os": {},
|
||||||
|
"os/exec": {},
|
||||||
|
"runtime": {},
|
||||||
|
"io": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
var supportInternal = map[string]none{
|
||||||
|
"internal/abi": {},
|
||||||
|
"internal/bytealg": {},
|
||||||
|
"internal/itoa": {},
|
||||||
|
"internal/oserror": {},
|
||||||
|
"internal/race": {},
|
||||||
|
"internal/reflectlite": {},
|
||||||
|
"internal/stringslite": {},
|
||||||
|
"internal/filepathlite": {},
|
||||||
|
"internal/syscall/unix": {},
|
||||||
|
"internal/syscall/execenv": {},
|
||||||
|
"internal/fmtsort": {},
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user