llgo/ssa,runtime: Slice
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := c.String("Hi\n")
|
||||
s := c.Str("Hi\n")
|
||||
s2 := c.Alloca(4)
|
||||
c.Memcpy(s2, unsafe.Pointer(s), 4)
|
||||
c.Printf(c.String("%s"), s2)
|
||||
c.Printf(c.Str("%s"), s2)
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ func incVal(a any) int {
|
||||
}
|
||||
|
||||
func main() {
|
||||
c.Printf(c.String("Hello %d\n"), incVal(100))
|
||||
c.Printf(c.Str("Hello %d\n"), incVal(100))
|
||||
}
|
||||
|
||||
16
cl/_testcgo/sum/in.go
Normal file
16
cl/_testcgo/sum/in.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
func sum(args ...int) (ret int) {
|
||||
for _, v := range args {
|
||||
ret += v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("Hello %d\n"), sum(1, 2, 3, 4))
|
||||
}
|
||||
0
cl/_testcgo/sum/out.ll
Normal file
0
cl/_testcgo/sum/out.ll
Normal file
@@ -10,5 +10,5 @@ func foo() {
|
||||
|
||||
func main() {
|
||||
foo()
|
||||
c.Printf(c.String("Hello\n"))
|
||||
c.Printf(c.Str("Hello\n"))
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if c, ok := args[0].(*ssa.Const); ok {
|
||||
if v := c.Value; v.Kind() == constant.String {
|
||||
sv := constant.StringVal(v)
|
||||
return b.CString(sv)
|
||||
return b.CStr(sv)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,7 +373,18 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
|
||||
if _, ok := p.isVArgs(vx); ok { // varargs: this is a varargs slice
|
||||
return
|
||||
}
|
||||
panic("todo")
|
||||
var low, high, max llssa.Expr
|
||||
x := p.compileValue(b, vx)
|
||||
if v.Low != nil {
|
||||
low = p.compileValue(b, v.Low)
|
||||
}
|
||||
if v.High != nil {
|
||||
high = p.compileValue(b, v.High)
|
||||
}
|
||||
if v.Max != nil {
|
||||
max = p.compileValue(b, v.Max)
|
||||
}
|
||||
ret = b.Slice(x, low, high, max)
|
||||
case *ssa.Alloc:
|
||||
t := v.Type().(*types.Pointer)
|
||||
if p.checkVArgs(v, t) { // varargs: this is a varargs allocation
|
||||
|
||||
@@ -29,7 +29,7 @@ func testCompile(t *testing.T, src, expected string) {
|
||||
}
|
||||
|
||||
func TestFromTestcgo(t *testing.T) {
|
||||
cltest.FromDir(t, "", "./_testcgo", true)
|
||||
cltest.FromDir(t, "sum", "./_testcgo", true)
|
||||
}
|
||||
|
||||
func TestFromTestdata(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user