| 111 | } |
| 112 | |
| 113 | func (b *Builder) callArgs(sig Signature, name string, args []*Value) []llvm.Value { |
| 114 | if sig.Variadic { |
| 115 | if g, e := len(args), len(sig.Parameters); g < e { |
| 116 | fail("Got %d arguments, but needed %d to call %v", g, e, sig.string(name)) |
| 117 | } |
| 118 | } else if g, e := len(args), len(sig.Parameters); g != e { |
| 119 | fail("Got %d arguments, but needed %d to call %v", g, e, sig.string(name)) |
| 120 | } |
| 121 | l := make([]llvm.Value, len(args)) |
| 122 | for i, a := range args { |
| 123 | if a == nil { |
| 124 | fail("Argument %d is nil when attempting to call %v", i, sig.string(name)) |
| 125 | } |
| 126 | l[i] = a.llvm |
| 127 | if i < len(sig.Parameters) { |
| 128 | if g, e := a.ty, sig.Parameters[i]; g != e { |
| 129 | fail("Incorrect argument type for parameter %d when calling %v: Got %v, expected %v", |
| 130 | i, sig.string(name), g.TypeName(), e.TypeName()) |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return l |
| 135 | } |
| 136 | |
| 137 | // Parameter returns i'th function parameter |
| 138 | func (b *Builder) Parameter(i int) *Value { |