Skip to content

Commit

Permalink
ir: add docs to NewTypeDef to clarify that typ.SetName is invoked
Browse files Browse the repository at this point in the history
Fixes #226.
  • Loading branch information
mewmew committed Dec 27, 2022
1 parent 7003623 commit 5d46090
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ir/module_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import "github.com/llir/llvm/ir/types"

// NewTypeDef appends a new type definition to the module based on the given
// type name and underlying type.
//
// Note, the name of the given type is set by invoking typ.SetName. As such,
// users are advised to refrain from creating type definitions from the
// convenience global variables of the types package (e.g. types.I64), since
// doing so would change the LLVM IR name of all uses of the types.I64 global
// variable. Instead, create a new type (e.g. types.NewInt(64)) for this
// purpose.
func (m *Module) NewTypeDef(name string, typ types.Type) types.Type {
typ.SetName(name)
m.TypeDefs = append(m.TypeDefs, typ)
Expand Down

0 comments on commit 5d46090

Please sign in to comment.