From 11e74975b31f7971306a7034a74f89ce8b1cdabc Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 15 May 2024 13:09:43 +0800 Subject: [PATCH] llgo/ssa: rm HasVArg/IsVArg --- ssa/decl.go | 21 +++++++-------------- ssa/type.go | 2 +- ssa/type_cvt.go | 1 + 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/ssa/decl.go b/ssa/decl.go index 12e67189..181e47e4 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -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) diff --git a/ssa/type.go b/ssa/type.go index 987fe436..9470d326 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -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-- } diff --git a/ssa/type_cvt.go b/ssa/type_cvt.go index 9f6b9aee..18a6576e 100644 --- a/ssa/type_cvt.go +++ b/ssa/type_cvt.go @@ -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