@@ -1,9 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/xtool/env/llvm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -15,4 +18,7 @@ func main() {
|
|||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
|
|
||||||
|
dir := llvm.New("").BinDir()
|
||||||
|
fmt.Println(dir)
|
||||||
}
|
}
|
||||||
|
|||||||
72
cl/import.go
72
cl/import.go
@@ -500,41 +500,6 @@ func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package {
|
|||||||
return pkgTypes
|
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 (
|
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.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -750,6 +750,7 @@ var hasAltPkg = map[string]none{
|
|||||||
"fmt": {},
|
"fmt": {},
|
||||||
"internal/abi": {},
|
"internal/abi": {},
|
||||||
"internal/bytealg": {},
|
"internal/bytealg": {},
|
||||||
|
"internal/itoa": {},
|
||||||
"internal/oserror": {},
|
"internal/oserror": {},
|
||||||
"internal/reflectlite": {},
|
"internal/reflectlite": {},
|
||||||
"internal/syscall/execenv": {},
|
"internal/syscall/execenv": {},
|
||||||
|
|||||||
@@ -1218,19 +1218,16 @@ formatLoop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *pp) doPrint(a []any) {
|
func (p *pp) doPrint(a []any) {
|
||||||
/*
|
prevString := false
|
||||||
prevString := false
|
for argNum, arg := range a {
|
||||||
for argNum, arg := range a {
|
isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String
|
||||||
isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String
|
// Add a space between two non-string arguments.
|
||||||
// Add a space between two non-string arguments.
|
if argNum > 0 && !isString && !prevString {
|
||||||
if argNum > 0 && !isString && !prevString {
|
p.buf.writeByte(' ')
|
||||||
p.buf.writeByte(' ')
|
|
||||||
}
|
|
||||||
p.printArg(arg, 'v')
|
|
||||||
prevString = isString
|
|
||||||
}
|
}
|
||||||
*/
|
p.printArg(arg, 'v')
|
||||||
panic("todo: fmt.(*pp).doPrint")
|
prevString = isString
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// doPrintln is like doPrint but always adds a space between arguments
|
// doPrintln is like doPrint but always adds a space between arguments
|
||||||
|
|||||||
34
internal/lib/internal/itoa/itoa.go
Normal file
34
internal/lib/internal/itoa/itoa.go
Normal 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:])
|
||||||
|
}
|
||||||
@@ -7,8 +7,10 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/internal/lib/internal/itoa"
|
||||||
"github.com/goplus/llgo/internal/lib/internal/syscall/execenv"
|
"github.com/goplus/llgo/internal/lib/internal/syscall/execenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,7 +98,6 @@ func (p *ProcessState) sysUsage() any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessState) String() string {
|
func (p *ProcessState) String() string {
|
||||||
/* TODO(xsw):
|
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return "<nil>"
|
return "<nil>"
|
||||||
}
|
}
|
||||||
@@ -124,8 +125,6 @@ func (p *ProcessState) String() string {
|
|||||||
res += " (core dumped)"
|
res += " (core dumped)"
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
*/
|
|
||||||
panic("todo: os.ProcessState.String")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExitCode returns the exit code of the exited process, or -1
|
// ExitCode returns the exit code of the exited process, or -1
|
||||||
|
|||||||
39
internal/lib/os/str.go
Normal file
39
internal/lib/os/str.go
Normal 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:])
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
package syscall
|
package syscall
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
"github.com/goplus/llgo/c/os"
|
"github.com/goplus/llgo/c/os"
|
||||||
"github.com/goplus/llgo/c/syscall"
|
"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 {
|
if fd[i] == i {
|
||||||
// dup2(i, i) won't clear close-on-exec flag on Linux,
|
// dup2(i, i) won't clear close-on-exec flag on Linux,
|
||||||
// probably not elsewhere either.
|
// probably not elsewhere either.
|
||||||
if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret != 0 {
|
if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret < 0 {
|
||||||
err1 = Errno(ret)
|
err1 = Errno(os.Errno)
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// The new fd is created NOT close-on-exec,
|
// The new fd is created NOT close-on-exec,
|
||||||
if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret != 0 {
|
if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret < 0 {
|
||||||
err1 = Errno(ret)
|
err1 = Errno(os.Errno)
|
||||||
goto childerror
|
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
|
// Programs that know they inherit fds >= 3 will need
|
||||||
// to set them close-on-exec.
|
// to set them close-on-exec.
|
||||||
for i = len(fd); i < 3; i++ {
|
for i = len(fd); i < 3; i++ {
|
||||||
/* TODO(xsw):
|
os.Close(c.Int(i))
|
||||||
rawSyscall(abi.FuncPCABI0(libc_close_trampoline), uintptr(i), 0, 0)
|
|
||||||
*/
|
|
||||||
panic("todo: syscall.forkAndExecInChild - for i")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detach fd 0 from tty
|
// Detach fd 0 from tty
|
||||||
@@ -322,12 +321,9 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
childerror:
|
childerror:
|
||||||
/* TODO(xsw):
|
|
||||||
// send error code on pipe
|
// 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 {
|
for {
|
||||||
rawSyscall(abi.FuncPCABI0(libc_exit_trampoline), 253, 0, 0)
|
os.Exit(253)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
panic("todo: syscall.forkAndExecInChild - childerror")
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user