llgo/ssa: allocaCStr; runtime: String
This commit is contained in:
@@ -275,6 +275,7 @@ func (p *context) checkVArgs(v *ssa.Alloc, t *types.Pointer) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// func cstr(string) *int8
|
||||
func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
if c, ok := args[0].(*ssa.Const); ok {
|
||||
@@ -287,6 +288,7 @@ func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
panic("cstr(<string-literal>): invalid arguments")
|
||||
}
|
||||
|
||||
// func alloca(size uintptr) unsafe.Pointer
|
||||
func (p *context) alloca(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
n := p.compileValue(b, args[0])
|
||||
@@ -295,6 +297,15 @@ func (p *context) alloca(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
panic("alloca(size uintptr): invalid arguments")
|
||||
}
|
||||
|
||||
// func allocaCStr(s string) *int8
|
||||
func (p *context) allocaCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
s := p.compileValue(b, args[0])
|
||||
return b.AllocaCStr(s)
|
||||
}
|
||||
panic("allocaCStr(s string): invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue bool) (ret llssa.Expr) {
|
||||
if asValue {
|
||||
if v, ok := p.bvals[iv]; ok {
|
||||
@@ -334,7 +345,9 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
|
||||
ret = cstr(b, call.Args)
|
||||
case llgoAlloca:
|
||||
ret = p.alloca(b, call.Args)
|
||||
case llgoUnreachable:
|
||||
case llgoAllocaCStr:
|
||||
ret = p.allocaCStr(b, call.Args)
|
||||
case llgoUnreachable: // func unreachable()
|
||||
b.Unreachable()
|
||||
default:
|
||||
panic("todo")
|
||||
|
||||
Reference in New Issue
Block a user