Merge pull request #590 from xushiwei/q

osexec: llvm bindir
This commit is contained in:
xushiwei
2024-07-29 00:23:43 +08:00
committed by GitHub
8 changed files with 137 additions and 63 deletions

View File

@@ -1,9 +1,12 @@
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"github.com/goplus/llgo/xtool/env/llvm"
)
func main() {
@@ -15,4 +18,7 @@ func main() {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
dir := llvm.New("").BinDir()
fmt.Println(dir)
}

View File

@@ -500,41 +500,6 @@ func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package {
return pkgTypes
}
func pkgKindByPath(pkgPath string) int {
switch pkgPath {
case "runtime/cgo", "unsafe":
return PkgDeclOnly
}
return PkgNormal
}
func replaceGoName(v string, pos int) string {
switch v[:pos] {
case "runtime":
return "github.com/goplus/llgo/internal/runtime" + v[pos:]
}
return v
}
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) && !supportedInternal(name[len(internal):])) ||
strings.HasPrefix(name, "crypto/") || strings.HasPrefix(name, "runtime/") ||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
strings.HasPrefix(name, "plugin.")
}
func supportedInternal(name string) bool {
return strings.HasPrefix(name, "abi.") || strings.HasPrefix(name, "bytealg.") ||
strings.HasPrefix(name, "oserror.") || strings.HasPrefix(name, "reflectlite.") ||
strings.HasPrefix(name, "syscall/unix.") || strings.HasPrefix(name, "syscall/execenv.")
}
// -----------------------------------------------------------------------------
const (
@@ -600,3 +565,40 @@ func toBackground(bg string) llssa.Background {
}
// -----------------------------------------------------------------------------
func pkgKindByPath(pkgPath string) int {
switch pkgPath {
case "runtime/cgo", "unsafe":
return PkgDeclOnly
}
return PkgNormal
}
func replaceGoName(v string, pos int) string {
switch v[:pos] {
case "runtime":
return "github.com/goplus/llgo/internal/runtime" + v[pos:]
}
return v
}
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) && !supportedInternal(name[len(internal):])) ||
strings.HasPrefix(name, "crypto/") || strings.HasPrefix(name, "runtime/") ||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
strings.HasPrefix(name, "plugin.")
}
func supportedInternal(name string) bool {
return strings.HasPrefix(name, "abi.") || strings.HasPrefix(name, "bytealg.") ||
strings.HasPrefix(name, "itoa.") || strings.HasPrefix(name, "oserror.") || strings.HasPrefix(name, "reflectlite.") ||
strings.HasPrefix(name, "syscall/unix.") || strings.HasPrefix(name, "syscall/execenv.")
}
// -----------------------------------------------------------------------------

View File

@@ -750,6 +750,7 @@ var hasAltPkg = map[string]none{
"fmt": {},
"internal/abi": {},
"internal/bytealg": {},
"internal/itoa": {},
"internal/oserror": {},
"internal/reflectlite": {},
"internal/syscall/execenv": {},

View File

@@ -1218,7 +1218,6 @@ formatLoop:
}
func (p *pp) doPrint(a []any) {
/*
prevString := false
for argNum, arg := range a {
isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String
@@ -1229,8 +1228,6 @@ func (p *pp) doPrint(a []any) {
p.printArg(arg, 'v')
prevString = isString
}
*/
panic("todo: fmt.(*pp).doPrint")
}
// doPrintln is like doPrint but always adds a space between arguments

View File

@@ -0,0 +1,34 @@
// Copyright 2021 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.
// Simple conversions to avoid depending on strconv.
// llgo:skipall
package itoa
// Itoa converts val to a decimal string.
func Itoa(val int) string {
if val < 0 {
return "-" + Uitoa(uint(-val))
}
return Uitoa(uint(val))
}
// Uitoa converts val to a decimal string.
func Uitoa(val uint) string {
if val == 0 { // avoid string allocation
return "0"
}
var buf [20]byte // big enough for 64bit value base 10
i := len(buf) - 1
for val >= 10 {
q := val / 10
buf[i] = byte('0' + val - q*10)
i--
val = q
}
// val < 10
buf[i] = byte('0' + val)
return string(buf[i:])
}

View File

@@ -7,8 +7,10 @@
package os
import (
"runtime"
"syscall"
"github.com/goplus/llgo/internal/lib/internal/itoa"
"github.com/goplus/llgo/internal/lib/internal/syscall/execenv"
)
@@ -96,7 +98,6 @@ func (p *ProcessState) sysUsage() any {
}
func (p *ProcessState) String() string {
/* TODO(xsw):
if p == nil {
return "<nil>"
}
@@ -124,8 +125,6 @@ func (p *ProcessState) String() string {
res += " (core dumped)"
}
return res
*/
panic("todo: os.ProcessState.String")
}
// ExitCode returns the exit code of the exited process, or -1

39
internal/lib/os/str.go Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2009 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.
// Simple conversions to avoid depending on strconv.
package os
// itox converts val (an int) to a hexadecimal string.
func itox(val int) string {
if val < 0 {
return "-" + uitox(uint(-val))
}
return uitox(uint(val))
}
const hex = "0123456789abcdef"
// uitox converts val (a uint) to a hexadecimal string.
func uitox(val uint) string {
if val == 0 { // avoid string allocation
return "0x0"
}
var buf [20]byte // big enough for 64bit value base 16 + 0x
i := len(buf) - 1
for val >= 16 {
q := val / 16
buf[i] = hex[val%16]
i--
val = q
}
// val < 16
buf[i] = hex[val%16]
i--
buf[i] = 'x'
i--
buf[i] = '0'
return string(buf[i:])
}

View File

@@ -7,6 +7,8 @@
package syscall
import (
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/os"
"github.com/goplus/llgo/c/syscall"
@@ -261,15 +263,15 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char,
if fd[i] == i {
// dup2(i, i) won't clear close-on-exec flag on Linux,
// probably not elsewhere either.
if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret != 0 {
err1 = Errno(ret)
if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret < 0 {
err1 = Errno(os.Errno)
goto childerror
}
continue
}
// The new fd is created NOT close-on-exec,
if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret != 0 {
err1 = Errno(ret)
if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret < 0 {
err1 = Errno(os.Errno)
goto childerror
}
}
@@ -279,10 +281,7 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char,
// Programs that know they inherit fds >= 3 will need
// to set them close-on-exec.
for i = len(fd); i < 3; i++ {
/* TODO(xsw):
rawSyscall(abi.FuncPCABI0(libc_close_trampoline), uintptr(i), 0, 0)
*/
panic("todo: syscall.forkAndExecInChild - for i")
os.Close(c.Int(i))
}
// Detach fd 0 from tty
@@ -322,12 +321,9 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char,
*/
childerror:
/* TODO(xsw):
// send error code on pipe
rawSyscall(abi.FuncPCABI0(libc_write_trampoline), uintptr(pipe), uintptr(unsafe.Pointer(&err1)), unsafe.Sizeof(err1))
os.Write(c.Int(pipe), unsafe.Pointer(&err1), unsafe.Sizeof(err1))
for {
rawSyscall(abi.FuncPCABI0(libc_exit_trampoline), 253, 0, 0)
os.Exit(253)
}
*/
panic("todo: syscall.forkAndExecInChild - childerror")
}