llgo/ssa: Builtin
This commit is contained in:
@@ -571,10 +571,9 @@ func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon
|
||||
if fn == "ssa:wrapnilchk" { // TODO(xsw): check nil ptr
|
||||
arg := args[0]
|
||||
ret = p.compileValue(b, arg)
|
||||
// log.Println("wrapnilchk:", ret.TypeOf())
|
||||
} else {
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.BuiltinDo(act, fn, args...)
|
||||
ret = b.Do(act, llssa.Builtin(fn), args...)
|
||||
}
|
||||
case *ssa.Function:
|
||||
aFn, pyFn, ftype := p.compileFunction(cv)
|
||||
|
||||
28
ssa/expr.go
28
ssa/expr.go
@@ -43,6 +43,26 @@ func (v Expr) IsNil() bool {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type builtinTy struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (p builtinTy) Underlying() types.Type {
|
||||
panic("don't call")
|
||||
}
|
||||
|
||||
func (p builtinTy) String() string {
|
||||
return "builtinTy"
|
||||
}
|
||||
|
||||
// Builtin returns a builtin function expression.
|
||||
func Builtin(name string) Expr {
|
||||
tbi := &aType{raw: rawType{&builtinTy{name}}, kind: vkBuiltin}
|
||||
return Expr{Type: tbi}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type pyVarTy struct {
|
||||
mod Expr
|
||||
name string
|
||||
@@ -742,6 +762,9 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
|
||||
case vkFuncDecl:
|
||||
sig = raw.(*types.Signature)
|
||||
ll = fn.ll
|
||||
case vkBuiltin:
|
||||
bi := raw.(*builtinTy)
|
||||
return b.BuiltinCall(bi.name, args...)
|
||||
default:
|
||||
log.Panicf("unreachable: %d(%T)\n", kind, raw)
|
||||
}
|
||||
@@ -791,11 +814,6 @@ func (b Builder) Do(da DoAction, fn Expr, args ...Expr) (ret Expr) {
|
||||
// `fn` indicates the function: one of the built-in functions from the
|
||||
// Go spec (excluding "make" and "new").
|
||||
func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
|
||||
return b.BuiltinDo(Call, fn, args...)
|
||||
}
|
||||
|
||||
// BuiltinDo call a builtin function with an action.
|
||||
func (b Builder) BuiltinDo(da DoAction, fn string, args ...Expr) (ret Expr) {
|
||||
switch fn {
|
||||
case "len":
|
||||
if len(args) == 1 {
|
||||
|
||||
@@ -44,6 +44,7 @@ const (
|
||||
vkFuncDecl
|
||||
vkFuncPtr
|
||||
vkClosure
|
||||
vkBuiltin
|
||||
vkPyFuncRef
|
||||
vkPyVarRef
|
||||
vkTuple
|
||||
|
||||
Reference in New Issue
Block a user