llgo/ssa: builder.Str bugfix; runtime: NewString

This commit is contained in:
xushiwei
2024-04-30 18:42:40 +08:00
parent d62bf858dd
commit f7a54e3377
2 changed files with 19 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ source_filename = "github.com/goplus/llgo/internal/runtime"
@"github.com/goplus/llgo/internal/runtime.basicTypes" = global ptr null
@"github.com/goplus/llgo/internal/runtime.init$guard" = global ptr null
@"github.com/goplus/llgo/internal/runtime.sizeBasicTypes" = global ptr null
@0 = private unnamed_addr constant [21 x i8] c"I2Int: type mismatch\00", align 1
define ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 %0) {
_llgo_0:
@@ -104,7 +105,8 @@ _llgo_1: ; preds = %_llgo_0
ret i64 %10
_llgo_2: ; preds = %_llgo_0
%11 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"([21 x i8] c"I2Int: type mismatch\00")
%11 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 20)
%12 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %11)
unreachable
}
@@ -212,6 +214,17 @@ _llgo_0:
ret %"github.com/goplus/llgo/internal/runtime.Slice" %7
}
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr %0, i64 %1) {
_llgo_0:
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
store ptr %0, ptr %3, align 8
store i64 %1, ptr %4, align 4
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %5
}
define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NilSlice"() {
_llgo_0:
%0 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8

View File

@@ -153,9 +153,12 @@ func (b Builder) CStr(v string) Expr {
}
// Str returns a Go string constant expression.
func (b Builder) Str(v string) Expr {
func (b Builder) Str(v string) (ret Expr) {
prog := b.Prog
cstr := b.CStr(v)
return b.InlineCall(b.fn.pkg.rtFunc("NewString"), cstr, b.Prog.Val(len(v)))
ret = b.InlineCall(b.fn.pkg.rtFunc("NewString"), cstr, prog.Val(len(v)))
ret.Type = prog.String()
return
}
// -----------------------------------------------------------------------------