Skip to content

Commit

Permalink
ir: add Parent field to Func and populate this field from Module.NewFunc
Browse files Browse the repository at this point in the history
Updates #86.
  • Loading branch information
mewmew committed Jun 5, 2019
1 parent 03ed109 commit 71caa2f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ir/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Block struct {

// extra.

// Parent function; field set by ir.Function.NewBlock.
// Parent function; field set by ir.Func.NewBlock.
Parent *Func
}

Expand Down
3 changes: 3 additions & 0 deletions ir/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type Func struct {
// (optional) Metadata.
Metadata

// Parent module; field set by ir.Module.NewFunc.
Parent *Module

// mu prevents races on AssignIDs.
mu sync.Mutex
}
Expand Down
2 changes: 2 additions & 0 deletions ir/func_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ir

// NewBlock appends a new basic block to the function based on the given label
// name. An empty label name indicates an unnamed basic block.
//
// The Parent field of the block is set to f.
func (f *Func) NewBlock(name string) *Block {
block := NewBlock(name)
block.Parent = f
Expand Down
3 changes: 3 additions & 0 deletions ir/module_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import "github.com/llir/llvm/ir/types"

// NewFunc appends a new function to the module based on the given function
// name, return type and function parameters.
//
// The Parent field of the function is set to m.
func (m *Module) NewFunc(name string, retType types.Type, params ...*Param) *Func {
f := NewFunc(name, retType, params...)
f.Parent = m
m.Funcs = append(m.Funcs, f)
return f
}

0 comments on commit 71caa2f

Please sign in to comment.