Function creates a new function with the given name, result type and parameters.
(resTy Type, name string, paramTys ...Type)
| 270 | |
| 271 | // Function creates a new function with the given name, result type and parameters. |
| 272 | func (m *Module) Function(resTy Type, name string, paramTys ...Type) *Function { |
| 273 | ty := m.Types.Function(resTy, paramTys...) |
| 274 | f := llvm.AddFunction(m.llvm, name, ty.llvm) |
| 275 | out := &Function{Name: name, Type: ty, llvm: f, m: m} |
| 276 | if name != "" { |
| 277 | if _, existing := m.funcs[name]; existing { |
| 278 | fail("Duplicate function with name: '%s'", name) |
| 279 | } |
| 280 | m.funcs[name] = out |
| 281 | } |
| 282 | return out |
| 283 | } |
| 284 | |
| 285 | // Ctor creates and builds a new module constructor. |
| 286 | func (m *Module) Ctor(priority int32, cb func(*Builder)) { |