llgo/ssa: b.CString
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
source_filename = "main"
|
source_filename = "main"
|
||||||
|
|
||||||
@"main.init$guard" = global ptr null
|
@"main.init$guard" = global ptr null
|
||||||
|
@0 = private unnamed_addr constant [14 x i8] c"Hello, world\0A\00", align 1
|
||||||
|
|
||||||
define void @main.init() {
|
define void @main.init() {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
@@ -19,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
|||||||
define void @main() {
|
define void @main() {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
call void @main.init()
|
call void @main.init()
|
||||||
call void (ptr, ...) @printf([14 x i8] c"Hello, world\0A\00")
|
call void (ptr, ...) @printf(ptr @0)
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
|||||||
if c, ok := args[0].(*ssa.Const); ok {
|
if c, ok := args[0].(*ssa.Const); ok {
|
||||||
if v := c.Value; v.Kind() == constant.String {
|
if v := c.Value; v.Kind() == constant.String {
|
||||||
sv := constant.StringVal(v)
|
sv := constant.StringVal(v)
|
||||||
return b.Prog.CStringVal(sv)
|
return b.CString(sv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
ssa/expr.go
11
ssa/expr.go
@@ -82,12 +82,6 @@ func (p Program) Null(t Type) Expr {
|
|||||||
return Expr{llvm.ConstNull(t.ll), t}
|
return Expr{llvm.ConstNull(t.ll), t}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CStringVal returns a c-style string constant expression.
|
|
||||||
func (p Program) CStringVal(v string) Expr {
|
|
||||||
t := p.CString()
|
|
||||||
return Expr{llvm.ConstString(v, true), t}
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringVal returns string constant expression.
|
// StringVal returns string constant expression.
|
||||||
func (p Program) StringVal(v string) Expr {
|
func (p Program) StringVal(v string) Expr {
|
||||||
t := p.String()
|
t := p.String()
|
||||||
@@ -153,6 +147,11 @@ func (b Builder) Const(v constant.Value, typ Type) Expr {
|
|||||||
panic("todo")
|
panic("todo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CString returns a c-style string constant expression.
|
||||||
|
func (b Builder) CString(v string) Expr {
|
||||||
|
return Expr{llvm.CreateGlobalStringPtr(b.impl, v), b.Prog.CString()}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user