build: build runtime local
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
func concat(args ...string) (ret string) {
|
||||
for _, v := range args {
|
||||
ret += v
|
||||
@@ -17,5 +13,5 @@ func info(s string) string {
|
||||
|
||||
func main() {
|
||||
result := concat("Hello", " ", "World")
|
||||
c.Fprintf(c.Stderr, c.Str("Hi, %s\n"), c.AllocaCStr(result))
|
||||
println(result)
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ source_filename = "main"
|
||||
@3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
|
||||
@4 = private unnamed_addr constant [2 x i8] c" \00", align 1
|
||||
@5 = private unnamed_addr constant [6 x i8] c"World\00", align 1
|
||||
@stderr = external global ptr
|
||||
@6 = private unnamed_addr constant [8 x i8] c"Hi, %s\0A\00", align 1
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
|
||||
_llgo_0:
|
||||
@@ -119,12 +117,8 @@ _llgo_0:
|
||||
store i64 3, ptr %21, align 4
|
||||
%22 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, align 8
|
||||
%23 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %22)
|
||||
%24 = load ptr, ptr @stderr, align 8
|
||||
%25 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %23, 1
|
||||
%26 = add i64 %25, 1
|
||||
%27 = alloca i8, i64 %26, align 1
|
||||
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %27, %"github.com/goplus/llgo/internal/runtime.String" %23)
|
||||
%29 = call i32 (ptr, ptr, ...) @fprintf(ptr %24, ptr @6, ptr %28)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
@@ -136,6 +130,6 @@ declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String")
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare i32 @fprintf(ptr, ptr, ...)
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
@@ -60,10 +60,6 @@ func TestPython(t *testing.T) {
|
||||
cltest.Pkg(t, ssa.PkgPython, "../py/llgo_autogen.ll")
|
||||
}
|
||||
|
||||
func TestRuntime(t *testing.T) {
|
||||
cltest.Pkg(t, ssa.PkgRuntime, "../internal/runtime/llgo_autogen.ll")
|
||||
}
|
||||
|
||||
func TestVar(t *testing.T) {
|
||||
testCompile(t, `package foo
|
||||
|
||||
|
||||
Binary file not shown.
@@ -149,7 +149,13 @@ func Do(args []string, conf *Config) {
|
||||
|
||||
var runtimeFiles []string
|
||||
if needRt {
|
||||
runtimeFiles = allLinkFiles(rt)
|
||||
dpkg := buildAllPkgs(prog, rt[:1], mode, verbose)
|
||||
for _, pkg := range dpkg {
|
||||
if !strings.HasSuffix(pkg.ExportFile, ".ll") {
|
||||
continue
|
||||
}
|
||||
runtimeFiles = append(runtimeFiles, pkg.ExportFile)
|
||||
}
|
||||
}
|
||||
if mode != ModeBuild {
|
||||
nErr := 0
|
||||
@@ -266,7 +272,7 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string,
|
||||
needRuntime := false
|
||||
needPyInit := false
|
||||
packages.Visit([]*packages.Package{pkg}, nil, func(p *packages.Package) {
|
||||
if p.ExportFile != "" && !isRuntimePkg(p.PkgPath) { // skip packages that only contain declarations
|
||||
if p.ExportFile != "" { // skip packages that only contain declarations
|
||||
args = appendLinkFiles(args, p.ExportFile)
|
||||
need1, need2 := isNeedRuntimeOrPyInit(p)
|
||||
if !needRuntime {
|
||||
@@ -445,38 +451,6 @@ func checkFlag(arg string, i *int, verbose *bool, swflags map[string]bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func allLinkFiles(rt []*packages.Package) (outFiles []string) {
|
||||
outFiles = make([]string, 0, len(rt))
|
||||
packages.Visit(rt, nil, func(p *packages.Package) {
|
||||
pkgPath := p.PkgPath
|
||||
kind, param := cl.PkgKindOf(p.Types)
|
||||
if isRuntimePkg(pkgPath) {
|
||||
exptFile := ""
|
||||
if kind == cl.PkgLinkIR || kind == cl.PkgDeclOnly {
|
||||
exptFile = strings.TrimSpace(param)
|
||||
}
|
||||
llgoPkgLinkFiles(pkgPath, exptFile, func(linkFile string) {
|
||||
outFiles = append(outFiles, linkFile)
|
||||
})
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
pkgAbi = llgoModPath + "/internal/abi"
|
||||
pkgRuntime = llgoModPath + "/internal/runtime"
|
||||
pkgRuntimeC = llgoModPath + "/internal/runtime/c"
|
||||
)
|
||||
|
||||
func isRuntimePkg(pkgPath string) bool {
|
||||
switch pkgPath {
|
||||
case pkgRuntime, pkgAbi, pkgRuntimeC:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
rootDir string
|
||||
)
|
||||
|
||||
@@ -19,6 +19,10 @@ package c
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type (
|
||||
Char = int8
|
||||
Int = C.int
|
||||
@@ -26,15 +30,6 @@ type (
|
||||
FilePtr = unsafe.Pointer
|
||||
)
|
||||
|
||||
//go:linkname Stdin stdin
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout stdout
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr stderr
|
||||
var Stderr FilePtr
|
||||
|
||||
//go:linkname Str llgo.cstr
|
||||
func Str(string) *Char
|
||||
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
|
||||
package c
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl: c_default.ll"
|
||||
)
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname Stdin __stdinp
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout __stdoutp
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr __stderrp
|
||||
var Stderr FilePtr
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/internal/runtime/c'
|
||||
source_filename = "github.com/goplus/llgo/internal/runtime/c"
|
||||
|
||||
@__stderrp = external global ptr
|
||||
@__stdinp = external global ptr
|
||||
@__stdoutp = external global ptr
|
||||
@stdin = alias i8*, i8** @__stdinp
|
||||
@stdout = alias i8*, i8** @__stdoutp
|
||||
@stderr = alias i8*, i8** @__stderrp
|
||||
@@ -3,6 +3,13 @@
|
||||
|
||||
package c
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl: c_linux.ll"
|
||||
)
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname Stdin stdin
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout stdout
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr stderr
|
||||
var Stderr FilePtr
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/internal/runtime/c'
|
||||
source_filename = "github.com/goplus/llgo/internal/runtime/c"
|
||||
Binary file not shown.
@@ -41,14 +41,6 @@ func TestFromTestdata(t *testing.T) {
|
||||
cltest.FromDir(t, "", "../cl/_testdata", false)
|
||||
}
|
||||
|
||||
func TestRuntime(t *testing.T) {
|
||||
cltest.Pkg(t, "github.com/goplus/llgo/internal/runtime", "../internal/runtime/llgo_autogen.ll")
|
||||
}
|
||||
|
||||
func TestAbi(t *testing.T) {
|
||||
cltest.Pkg(t, "github.com/goplus/llgo/internal/abi", "../internal/abi/llgo_autogen.ll")
|
||||
}
|
||||
|
||||
func TestMakeInterface(t *testing.T) {
|
||||
prog := ssatest.NewProgram(t, &ssa.Target{GOARCH: "x86"})
|
||||
pkg := prog.NewPackage("foo", "foo")
|
||||
|
||||
Reference in New Issue
Block a user