AllocCStr allocates on heap

This commit is contained in:
Li Jie
2025-04-11 15:17:37 +08:00
parent 7284042823
commit 8512395985
4 changed files with 36 additions and 9 deletions

View File

@@ -446,17 +446,18 @@ const (
llgoAlloca = llgoInstrBase + 2
llgoAllocaCStr = llgoInstrBase + 3
llgoAllocaCStrs = llgoInstrBase + 4
llgoAdvance = llgoInstrBase + 5
llgoIndex = llgoInstrBase + 6
llgoStringData = llgoInstrBase + 7
llgoString = llgoInstrBase + 8
llgoDeferData = llgoInstrBase + 9
llgoAllocCStr = llgoInstrBase + 5
llgoAdvance = llgoInstrBase + 6
llgoIndex = llgoInstrBase + 7
llgoStringData = llgoInstrBase + 8
llgoString = llgoInstrBase + 9
llgoDeferData = llgoInstrBase + 0xa
llgoSigjmpbuf = llgoInstrBase + 0xa
llgoSigsetjmp = llgoInstrBase + 0xb
llgoSiglongjmp = llgoInstrBase + 0xc
llgoSigjmpbuf = llgoInstrBase + 0xb
llgoSigsetjmp = llgoInstrBase + 0xc
llgoSiglongjmp = llgoInstrBase + 0xd
llgoFuncAddr = llgoInstrBase + 0xd
llgoFuncAddr = llgoInstrBase + 0xe
llgoPyList = llgoInstrBase + 0x10
llgoPyStr = llgoInstrBase + 0x11

View File

@@ -165,6 +165,15 @@ func (p *context) allocaCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr)
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 (p *context) allocaCStrs(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
if len(args) == 2 {
@@ -281,6 +290,7 @@ var llgoInstrs = map[string]int{
"advance": llgoAdvance,
"index": llgoIndex,
"alloca": llgoAlloca,
"allocCStr": llgoAllocCStr,
"allocaCStr": llgoAllocaCStr,
"allocaCStrs": llgoAllocaCStrs,
"string": llgoString,
@@ -470,6 +480,8 @@ func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon
ret = p.alloca(b, args)
case llgoAllocaCStr:
ret = p.allocaCStr(b, args)
case llgoAllocCStr:
ret = p.allocCStr(b, args)
case llgoAllocaCStrs:
ret = p.allocaCStrs(b, args)
case llgoString: