addrs: Helper methods for converting module calls to absolute modules

This commit is contained in:
Martin Atkins 2018-05-03 11:53:06 -07:00
parent c97dd145b9
commit b9c4780f07
1 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,14 @@ func (c ModuleCallInstance) String() string {
return fmt.Sprintf("module.%s%s", c.Call.Name, c.Key)
}
// ModuleInstance returns the address of the module instance that corresponds
// to the receiving call instance when resolved in the given calling module.
// In other words, it returns the child module instance that the receving
// call instance creates.
func (c ModuleCallInstance) ModuleInstance(caller ModuleInstance) ModuleInstance {
return caller.Child(c.Call.Name, c.Key)
}
// Output returns the address of an output of the receiver identified by its
// name.
func (c ModuleCallInstance) Output(name string) ModuleCallOutput {
@ -63,3 +71,11 @@ type ModuleCallOutput struct {
func (co ModuleCallOutput) String() string {
return fmt.Sprintf("%s.%s", co.Call.String(), co.Name)
}
// AbsOutputValue returns the absolute output value address that corresponds
// to the receving module call output address, once resolved in the given
// calling module.
func (co ModuleCallOutput) AbsOutputValue(caller ModuleInstance) AbsOutputValue {
moduleAddr := co.Call.ModuleInstance(caller)
return moduleAddr.OutputValue(co.Name)
}