runtime: TODO - error var; cl: link goVar

This commit is contained in:
xushiwei
2024-06-13 02:53:54 +08:00
parent 18eecbe9f4
commit 7235357ef5
7 changed files with 68 additions and 8 deletions

View File

@@ -34,6 +34,7 @@ func main() {
llgen.Verbose = false
llgenDir(dir + "/cl/_testlibc")
llgenDir(dir + "/cl/_testlibgo")
llgenDir(dir + "/cl/_testrt")
llgenDir(dir + "/cl/_testgo")
llgenDir(dir+"/cl/_testpy", "")

9
cl/_testlibgo/math/in.go Normal file
View File

@@ -0,0 +1,9 @@
package main
import (
"math/bits"
)
func main() {
println(bits.Len8(20))
}

42
cl/_testlibgo/math/out.ll Normal file
View File

@@ -0,0 +1,42 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"math/bits.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call i64 @"math/bits.Len8"(i8 20)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %2)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
ret i32 0
}
declare void @"math/bits.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare i64 @"math/bits.Len8"(i8)
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)

View File

@@ -192,7 +192,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
// Global variable.
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
typ := gbl.Type()
name, vtype := p.varName(gbl.Pkg.Pkg, gbl)
name, vtype, define := p.varName(gbl.Pkg.Pkg, gbl)
if vtype == pyVar || ignoreName(name) || checkCgo(gbl.Name()) {
return
}
@@ -200,7 +200,7 @@ func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
log.Println("==> NewVar", name, typ)
}
g := pkg.NewVar(name, typ, llssa.Background(vtype))
if vtype == goVar {
if define {
g.Init(p.prog.Nil(g.Type))
}
}

View File

@@ -36,6 +36,10 @@ func TestFromTestpy(t *testing.T) {
cltest.FromDir(t, "", "./_testpy", false)
}
func TestFromTestlibgo(t *testing.T) {
cltest.FromDir(t, "", "./_testlibgo", true)
}
func TestFromTestlibc(t *testing.T) {
cltest.FromDir(t, "", "./_testlibc", true)
}

View File

@@ -356,24 +356,24 @@ const (
pyVar = int(llssa.InPython)
)
func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, vtype int) {
func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, vtype int, define bool) {
name := llssa.FullName(pkg, v.Name())
if v, ok := p.link[name]; ok {
if pos := strings.IndexByte(v, '.'); pos >= 0 {
if pos == 2 && v[0] == 'p' && v[1] == 'y' {
return v[3:], pyVar
return v[3:], pyVar, false
}
return replaceGoName(v, pos), goVar
return replaceGoName(v, pos), goVar, false
}
return v, cVar
return v, cVar, false
}
return name, goVar
return name, goVar, true
}
func (p *context) varOf(b llssa.Builder, v *ssa.Global) llssa.Expr {
pkgTypes := p.ensureLoaded(v.Pkg.Pkg)
pkg := p.pkg
name, vtype := p.varName(pkgTypes, v)
name, vtype, _ := p.varName(pkgTypes, v)
if vtype == pyVar {
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
return b.PyNewVar(pysymPrefix+mod, name).Expr

View File

@@ -218,6 +218,10 @@ func panicSlice3CU(x uint, y int)
func panicSliceConvert(x int, y int)
*/
var divideError error
var overflowError error
/* TODO(xsw):
var shiftError = error(errorString("negative shift amount"))
func Panicshift() {