llgo/ssa: rm HasVArg/IsVArg

This commit is contained in:
xushiwei
2024-05-15 13:09:43 +08:00
parent 75ef9ec524
commit 11e74975b3
3 changed files with 9 additions and 15 deletions

View File

@@ -29,25 +29,18 @@ import (
const (
ClosureCtx = "__llgo_ctx"
ClosureStub = "__llgo_stub."
NameValist = "__llgo_va_list"
)
// -----------------------------------------------------------------------------
const (
NameValist = "__llgo_va_list"
)
func VArg() *types.Var {
return types.NewParam(0, nil, NameValist, types.NewSlice(tyAny))
}
func IsVArg(arg *types.Var) bool {
return arg.Name() == NameValist
}
func HasVArg(t *types.Tuple, n int, sig *types.Signature) bool {
has := n > 0 && IsVArg(t.At(n-1))
if has && !sig.Variadic() { // TODO(xsw): remove this check
panic("HasVArg: varg must mark as variadic in signature")
}
return has
}
// -----------------------------------------------------------------------------
type aNamedConst struct {
@@ -200,7 +193,7 @@ func newParams(fn Type, prog Program) (params []Type, hasVArg bool) {
sig := fn.raw.Type.(*types.Signature)
in := sig.Params()
if n := in.Len(); n > 0 {
if hasVArg = HasVArg(in, n, sig); hasVArg {
if hasVArg = sig.Variadic(); hasVArg {
n--
}
params = make([]Type, n)

View File

@@ -313,7 +313,7 @@ func (p Program) toLLVMTypes(t *types.Tuple, n int) (ret []llvm.Type) {
func (p Program) toLLVMFunc(sig *types.Signature) llvm.Type {
tParams := sig.Params()
n := tParams.Len()
hasVArg := HasVArg(tParams, n, sig)
hasVArg := sig.Variadic()
if hasVArg {
n--
}

View File

@@ -173,6 +173,7 @@ func (p goTypes) cvtFunc(sig *types.Signature, recv *types.Var) (raw *types.Sign
params, cvt1 := p.cvtTuple(sig.Params())
results, cvt2 := p.cvtTuple(sig.Results())
if cvt1 || cvt2 {
// variadic always is false in raw type for Go function
return types.NewSignatureType(nil, nil, nil, params, results, false)
}
return sig