cl: qsort example
This commit is contained in:
@@ -59,6 +59,13 @@ declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
|||||||
|
|
||||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64)
|
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64)
|
||||||
|
|
||||||
declare i32 @"main.main$1"(ptr, ptr)
|
define i32 @"main.main$1"(ptr %0, ptr %1) {
|
||||||
|
_llgo_0:
|
||||||
|
%2 = load i64, ptr %0, align 4
|
||||||
|
%3 = load i64, ptr %1, align 4
|
||||||
|
%4 = sub i64 %2, %3
|
||||||
|
%5 = trunc i64 %4 to i32
|
||||||
|
ret i32 %5
|
||||||
|
}
|
||||||
|
|
||||||
declare i32 @printf(ptr, ...)
|
declare i32 @printf(ptr, ...)
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
|
|||||||
for i, n := 0, mthds.Len(); i < n; i++ {
|
for i, n := 0, mthds.Len(); i < n; i++ {
|
||||||
mthd := mthds.At(i)
|
mthd := mthds.At(i)
|
||||||
if ssaMthd := prog.MethodValue(mthd); ssaMthd != nil {
|
if ssaMthd := prog.MethodValue(mthd); ssaMthd != nil {
|
||||||
p.compileFunc(pkg, mthd.Obj().Pkg(), ssaMthd)
|
p.compileFunc(pkg, mthd.Obj().Pkg(), ssaMthd, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,18 +193,24 @@ func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *context) compileFunc(pkg llssa.Package, pkgTypes *types.Package, f *ssa.Function) {
|
func (p *context) compileFunc(pkg llssa.Package, pkgTypes *types.Package, f *ssa.Function, closure bool) llssa.Function {
|
||||||
sig := f.Signature
|
var sig = f.Signature
|
||||||
name, ftype := p.funcName(pkgTypes, f, true)
|
var name string
|
||||||
switch ftype {
|
if closure {
|
||||||
case ignoredFunc, llgoInstr: // llgo extended instructions
|
name = funcName(pkgTypes, f)
|
||||||
return
|
} else {
|
||||||
}
|
var ftype int
|
||||||
if debugInstr {
|
name, ftype = p.funcName(pkgTypes, f, true)
|
||||||
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig)
|
switch ftype {
|
||||||
}
|
case ignoredFunc, llgoInstr: // llgo extended instructions
|
||||||
if ftype == cFunc {
|
return nil
|
||||||
sig = llssa.CFuncDecl(sig)
|
}
|
||||||
|
if debugInstr {
|
||||||
|
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig)
|
||||||
|
}
|
||||||
|
if ftype == cFunc {
|
||||||
|
sig = llssa.CFuncDecl(sig)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn := pkg.NewFunc(name, sig)
|
fn := pkg.NewFunc(name, sig)
|
||||||
p.inits = append(p.inits, func() {
|
p.inits = append(p.inits, func() {
|
||||||
@@ -233,6 +239,7 @@ func (p *context) compileFunc(pkg llssa.Package, pkgTypes *types.Package, f *ssa
|
|||||||
phi()
|
phi()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return fn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, doInit bool) llssa.BasicBlock {
|
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, doInit bool) llssa.BasicBlock {
|
||||||
@@ -587,11 +594,15 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *ssa.Function:
|
case *ssa.Function:
|
||||||
fn, ftype := p.funcOf(v)
|
fn := p.compileFunc(p.pkg, p.goTyps, v, true)
|
||||||
if ftype >= llgoInstrBase {
|
|
||||||
panic("can't use llgo instruction as a value")
|
|
||||||
}
|
|
||||||
return fn.Expr
|
return fn.Expr
|
||||||
|
/*
|
||||||
|
fn, ftype := p.funcOf(v)
|
||||||
|
if ftype >= llgoInstrBase {
|
||||||
|
panic("can't use llgo instruction as a value")
|
||||||
|
}
|
||||||
|
return fn.Expr
|
||||||
|
*/
|
||||||
case *ssa.Global:
|
case *ssa.Global:
|
||||||
g := p.varOf(v)
|
g := p.varOf(v)
|
||||||
return g.Expr
|
return g.Expr
|
||||||
@@ -676,15 +687,19 @@ func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret ll
|
|||||||
// Do not try to build generic (non-instantiated) functions.
|
// Do not try to build generic (non-instantiated) functions.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ctx.compileFunc(ret, member.Pkg.Pkg, member)
|
ctx.compileFunc(ret, member.Pkg.Pkg, member, false)
|
||||||
case *ssa.Type:
|
case *ssa.Type:
|
||||||
ctx.compileType(ret, member)
|
ctx.compileType(ret, member)
|
||||||
case *ssa.Global:
|
case *ssa.Global:
|
||||||
ctx.compileGlobal(ret, member)
|
ctx.compileGlobal(ret, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, ini := range ctx.inits {
|
for len(ctx.inits) > 0 {
|
||||||
ini()
|
inits := ctx.inits
|
||||||
|
ctx.inits = nil
|
||||||
|
for _, ini := range inits {
|
||||||
|
ini()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user