AllocCStr allocates on heap
This commit is contained in:
19
cl/import.go
19
cl/import.go
@@ -446,17 +446,18 @@ const (
|
|||||||
llgoAlloca = llgoInstrBase + 2
|
llgoAlloca = llgoInstrBase + 2
|
||||||
llgoAllocaCStr = llgoInstrBase + 3
|
llgoAllocaCStr = llgoInstrBase + 3
|
||||||
llgoAllocaCStrs = llgoInstrBase + 4
|
llgoAllocaCStrs = llgoInstrBase + 4
|
||||||
llgoAdvance = llgoInstrBase + 5
|
llgoAllocCStr = llgoInstrBase + 5
|
||||||
llgoIndex = llgoInstrBase + 6
|
llgoAdvance = llgoInstrBase + 6
|
||||||
llgoStringData = llgoInstrBase + 7
|
llgoIndex = llgoInstrBase + 7
|
||||||
llgoString = llgoInstrBase + 8
|
llgoStringData = llgoInstrBase + 8
|
||||||
llgoDeferData = llgoInstrBase + 9
|
llgoString = llgoInstrBase + 9
|
||||||
|
llgoDeferData = llgoInstrBase + 0xa
|
||||||
|
|
||||||
llgoSigjmpbuf = llgoInstrBase + 0xa
|
llgoSigjmpbuf = llgoInstrBase + 0xb
|
||||||
llgoSigsetjmp = llgoInstrBase + 0xb
|
llgoSigsetjmp = llgoInstrBase + 0xc
|
||||||
llgoSiglongjmp = llgoInstrBase + 0xc
|
llgoSiglongjmp = llgoInstrBase + 0xd
|
||||||
|
|
||||||
llgoFuncAddr = llgoInstrBase + 0xd
|
llgoFuncAddr = llgoInstrBase + 0xe
|
||||||
|
|
||||||
llgoPyList = llgoInstrBase + 0x10
|
llgoPyList = llgoInstrBase + 0x10
|
||||||
llgoPyStr = llgoInstrBase + 0x11
|
llgoPyStr = llgoInstrBase + 0x11
|
||||||
|
|||||||
12
cl/instr.go
12
cl/instr.go
@@ -165,6 +165,15 @@ func (p *context) allocaCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr)
|
|||||||
panic("allocaCStr(s string): invalid arguments")
|
panic("allocaCStr(s string): invalid arguments")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func allocCStr(s string) *int8
|
||||||
|
func (p *context) allocCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||||
|
if len(args) == 1 {
|
||||||
|
s := p.compileValue(b, args[0])
|
||||||
|
return b.AllocCStr(s)
|
||||||
|
}
|
||||||
|
panic("allocCStr(s string): invalid arguments")
|
||||||
|
}
|
||||||
|
|
||||||
// func allocaCStrs(strs []string, endWithNil bool) **int8
|
// func allocaCStrs(strs []string, endWithNil bool) **int8
|
||||||
func (p *context) allocaCStrs(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
func (p *context) allocaCStrs(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||||
if len(args) == 2 {
|
if len(args) == 2 {
|
||||||
@@ -281,6 +290,7 @@ var llgoInstrs = map[string]int{
|
|||||||
"advance": llgoAdvance,
|
"advance": llgoAdvance,
|
||||||
"index": llgoIndex,
|
"index": llgoIndex,
|
||||||
"alloca": llgoAlloca,
|
"alloca": llgoAlloca,
|
||||||
|
"allocCStr": llgoAllocCStr,
|
||||||
"allocaCStr": llgoAllocaCStr,
|
"allocaCStr": llgoAllocaCStr,
|
||||||
"allocaCStrs": llgoAllocaCStrs,
|
"allocaCStrs": llgoAllocaCStrs,
|
||||||
"string": llgoString,
|
"string": llgoString,
|
||||||
@@ -470,6 +480,8 @@ func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon
|
|||||||
ret = p.alloca(b, args)
|
ret = p.alloca(b, args)
|
||||||
case llgoAllocaCStr:
|
case llgoAllocaCStr:
|
||||||
ret = p.allocaCStr(b, args)
|
ret = p.allocaCStr(b, args)
|
||||||
|
case llgoAllocCStr:
|
||||||
|
ret = p.allocCStr(b, args)
|
||||||
case llgoAllocaCStrs:
|
case llgoAllocaCStrs:
|
||||||
ret = p.allocaCStrs(b, args)
|
ret = p.allocaCStrs(b, args)
|
||||||
case llgoString:
|
case llgoString:
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ func Alloca(size uintptr) Pointer
|
|||||||
//go:linkname AllocaCStr llgo.allocaCStr
|
//go:linkname AllocaCStr llgo.allocaCStr
|
||||||
func AllocaCStr(s string) *Char
|
func AllocaCStr(s string) *Char
|
||||||
|
|
||||||
|
//go:linkname AllocCStr llgo.allocCStr
|
||||||
|
func AllocCStr(s string) *Char
|
||||||
|
|
||||||
//go:linkname AllocaCStrs llgo.allocaCStrs
|
//go:linkname AllocaCStrs llgo.allocaCStrs
|
||||||
func AllocaCStrs(strs []string, endWithNil bool) **Char
|
func AllocaCStrs(strs []string, endWithNil bool) **Char
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,17 @@ func (b Builder) AllocaCStr(gostr Expr) (ret Expr) {
|
|||||||
return b.InlineCall(b.Pkg.rtFunc("CStrCopy"), cstr, gostr)
|
return b.InlineCall(b.Pkg.rtFunc("CStrCopy"), cstr, gostr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllocCStr allocates space on the heap for copy it from a Go string.
|
||||||
|
func (b Builder) AllocCStr(gostr Expr) (ret Expr) {
|
||||||
|
if debugInstr {
|
||||||
|
log.Printf("AllocCStr %v\n", gostr.impl)
|
||||||
|
}
|
||||||
|
n := b.StringLen(gostr)
|
||||||
|
n1 := b.BinOp(token.ADD, n, b.Prog.Val(1))
|
||||||
|
cstr := b.allocUninited(n1)
|
||||||
|
return b.InlineCall(b.Pkg.rtFunc("CStrCopy"), cstr, gostr)
|
||||||
|
}
|
||||||
|
|
||||||
// func allocaCStrs(strs []string, endWithNil bool) **int8
|
// func allocaCStrs(strs []string, endWithNil bool) **int8
|
||||||
func (b Builder) AllocaCStrs(strs Expr, endWithNil bool) (cstrs Expr) {
|
func (b Builder) AllocaCStrs(strs Expr, endWithNil bool) (cstrs Expr) {
|
||||||
if debugInstr {
|
if debugInstr {
|
||||||
|
|||||||
Reference in New Issue
Block a user