From 71caa2f012f8a697d059daa1b416674717aec032 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 5 Jun 2019 19:56:13 +0900 Subject: [PATCH] ir: add Parent field to Func and populate this field from Module.NewFunc Updates #86. --- ir/block.go | 2 +- ir/func.go | 3 +++ ir/func_block.go | 2 ++ ir/module_func.go | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ir/block.go b/ir/block.go index 2f242aba..c0c02e53 100644 --- a/ir/block.go +++ b/ir/block.go @@ -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 } diff --git a/ir/func.go b/ir/func.go index ba145627..1694b601 100644 --- a/ir/func.go +++ b/ir/func.go @@ -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 } diff --git a/ir/func_block.go b/ir/func_block.go index 2edf7062..5525d4fd 100644 --- a/ir/func_block.go +++ b/ir/func_block.go @@ -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 diff --git a/ir/module_func.go b/ir/module_func.go index 15c742a4..821db02c 100644 --- a/ir/module_func.go +++ b/ir/module_func.go @@ -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 }