2018-03-31 04:58:57 +02:00
|
|
|
package addrs
|
|
|
|
|
2018-04-04 03:03:47 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-03-31 04:58:57 +02:00
|
|
|
// ModuleCall is the address of a call from the current module to a child
|
|
|
|
// module.
|
|
|
|
type ModuleCall struct {
|
|
|
|
referenceable
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
2018-04-04 03:03:47 +02:00
|
|
|
func (c ModuleCall) String() string {
|
|
|
|
return "module." + c.Name
|
|
|
|
}
|
|
|
|
|
2021-07-11 00:18:19 +02:00
|
|
|
func (c ModuleCall) UniqueKey() UniqueKey {
|
|
|
|
return c // A ModuleCall is its own UniqueKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c ModuleCall) uniqueKeySigil() {}
|
|
|
|
|
2018-03-31 04:58:57 +02:00
|
|
|
// Instance returns the address of an instance of the receiver identified by
|
|
|
|
// the given key.
|
|
|
|
func (c ModuleCall) Instance(key InstanceKey) ModuleCallInstance {
|
|
|
|
return ModuleCallInstance{
|
|
|
|
Call: c,
|
|
|
|
Key: key,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 00:25:00 +02:00
|
|
|
func (c ModuleCall) Absolute(moduleAddr ModuleInstance) AbsModuleCall {
|
|
|
|
return AbsModuleCall{
|
|
|
|
Module: moduleAddr,
|
|
|
|
Call: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AbsModuleCall is the address of a "module" block relative to the root
|
|
|
|
// of the configuration.
|
|
|
|
//
|
|
|
|
// This is similar to ModuleInstance alone, but specifically represents
|
|
|
|
// the module block itself rather than any one of the instances that
|
|
|
|
// module block declares.
|
|
|
|
type AbsModuleCall struct {
|
|
|
|
Module ModuleInstance
|
|
|
|
Call ModuleCall
|
|
|
|
}
|
|
|
|
|
2021-06-30 04:03:59 +02:00
|
|
|
func (c AbsModuleCall) absMoveableSigil() {
|
|
|
|
// AbsModuleCall is "moveable".
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c AbsModuleCall) String() string {
|
2021-07-12 21:23:10 +02:00
|
|
|
if len(c.Module) == 0 {
|
|
|
|
return "module." + c.Call.Name
|
|
|
|
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s.module.%s", c.Module, c.Call.Name)
|
2021-06-30 04:03:59 +02:00
|
|
|
}
|
|
|
|
|
2021-06-30 00:25:00 +02:00
|
|
|
func (c AbsModuleCall) Instance(key InstanceKey) ModuleInstance {
|
|
|
|
ret := make(ModuleInstance, len(c.Module), len(c.Module)+1)
|
|
|
|
copy(ret, c.Module)
|
|
|
|
ret = append(ret, ModuleInstanceStep{
|
|
|
|
Name: c.Call.Name,
|
|
|
|
InstanceKey: key,
|
|
|
|
})
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-07-29 03:25:00 +02:00
|
|
|
type absModuleCallInstanceKey string
|
|
|
|
|
|
|
|
func (c AbsModuleCall) UniqueKey() UniqueKey {
|
|
|
|
return absModuleCallInstanceKey(c.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mk absModuleCallInstanceKey) uniqueKeySigil() {}
|
|
|
|
|
2018-03-31 04:58:57 +02:00
|
|
|
// ModuleCallInstance is the address of one instance of a module created from
|
|
|
|
// a module call, which might create multiple instances using "count" or
|
|
|
|
// "for_each" arguments.
|
2021-06-30 00:25:00 +02:00
|
|
|
//
|
|
|
|
// There is no "Abs" version of ModuleCallInstance because an absolute module
|
|
|
|
// path is represented by ModuleInstance.
|
2018-03-31 04:58:57 +02:00
|
|
|
type ModuleCallInstance struct {
|
|
|
|
referenceable
|
|
|
|
Call ModuleCall
|
|
|
|
Key InstanceKey
|
|
|
|
}
|
|
|
|
|
2018-04-04 03:03:47 +02:00
|
|
|
func (c ModuleCallInstance) String() string {
|
|
|
|
if c.Key == NoKey {
|
|
|
|
return c.Call.String()
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("module.%s%s", c.Call.Name, c.Key)
|
|
|
|
}
|
|
|
|
|
2021-07-11 00:18:19 +02:00
|
|
|
func (c ModuleCallInstance) UniqueKey() UniqueKey {
|
|
|
|
return c // A ModuleCallInstance is its own UniqueKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c ModuleCallInstance) uniqueKeySigil() {}
|
|
|
|
|
2021-06-30 00:25:00 +02:00
|
|
|
func (c ModuleCallInstance) Absolute(moduleAddr ModuleInstance) ModuleInstance {
|
|
|
|
ret := make(ModuleInstance, len(moduleAddr), len(moduleAddr)+1)
|
|
|
|
copy(ret, moduleAddr)
|
|
|
|
ret = append(ret, ModuleInstanceStep{
|
|
|
|
Name: c.Call.Name,
|
|
|
|
InstanceKey: c.Key,
|
|
|
|
})
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2018-05-03 20:53:06 +02:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:18:48 +01:00
|
|
|
// Output returns the absolute address of an output of the receiver identified by its
|
2018-03-31 04:58:57 +02:00
|
|
|
// name.
|
2021-06-30 00:25:00 +02:00
|
|
|
func (c ModuleCallInstance) Output(name string) ModuleCallInstanceOutput {
|
|
|
|
return ModuleCallInstanceOutput{
|
2018-03-31 04:58:57 +02:00
|
|
|
Call: c,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:18:48 +01:00
|
|
|
// ModuleCallOutput is the address of a named output and its associated
|
|
|
|
// ModuleCall, which may expand into multiple module instances
|
2018-03-31 04:58:57 +02:00
|
|
|
type ModuleCallOutput struct {
|
2020-03-20 17:18:48 +01:00
|
|
|
referenceable
|
|
|
|
Call ModuleCall
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m ModuleCallOutput) String() string {
|
|
|
|
return fmt.Sprintf("%s.%s", m.Call.String(), m.Name)
|
|
|
|
}
|
|
|
|
|
2021-07-11 00:18:19 +02:00
|
|
|
func (m ModuleCallOutput) UniqueKey() UniqueKey {
|
|
|
|
return m // A ModuleCallOutput is its own UniqueKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m ModuleCallOutput) uniqueKeySigil() {}
|
|
|
|
|
2021-06-30 00:06:00 +02:00
|
|
|
// ModuleCallInstanceOutput is the address of a particular named output produced by
|
2020-03-20 17:18:48 +01:00
|
|
|
// an instance of a module call.
|
2021-06-30 00:06:00 +02:00
|
|
|
type ModuleCallInstanceOutput struct {
|
2018-03-31 04:58:57 +02:00
|
|
|
referenceable
|
|
|
|
Call ModuleCallInstance
|
|
|
|
Name string
|
|
|
|
}
|
2018-04-04 03:03:47 +02:00
|
|
|
|
2020-04-10 20:45:36 +02:00
|
|
|
// ModuleCallOutput returns the referenceable ModuleCallOutput for this
|
2020-04-09 21:40:28 +02:00
|
|
|
// particular instance.
|
2021-06-30 00:06:00 +02:00
|
|
|
func (co ModuleCallInstanceOutput) ModuleCallOutput() ModuleCallOutput {
|
2020-04-09 21:40:28 +02:00
|
|
|
return ModuleCallOutput{
|
|
|
|
Call: co.Call.Call,
|
|
|
|
Name: co.Name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 00:06:00 +02:00
|
|
|
func (co ModuleCallInstanceOutput) String() string {
|
2018-04-04 03:03:47 +02:00
|
|
|
return fmt.Sprintf("%s.%s", co.Call.String(), co.Name)
|
|
|
|
}
|
2018-05-03 20:53:06 +02:00
|
|
|
|
2021-07-11 00:18:19 +02:00
|
|
|
func (co ModuleCallInstanceOutput) UniqueKey() UniqueKey {
|
|
|
|
return co // A ModuleCallInstanceOutput is its own UniqueKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (co ModuleCallInstanceOutput) uniqueKeySigil() {}
|
|
|
|
|
2018-05-03 20:53:06 +02:00
|
|
|
// AbsOutputValue returns the absolute output value address that corresponds
|
|
|
|
// to the receving module call output address, once resolved in the given
|
|
|
|
// calling module.
|
2021-06-30 00:06:00 +02:00
|
|
|
func (co ModuleCallInstanceOutput) AbsOutputValue(caller ModuleInstance) AbsOutputValue {
|
2018-05-03 20:53:06 +02:00
|
|
|
moduleAddr := co.Call.ModuleInstance(caller)
|
|
|
|
return moduleAddr.OutputValue(co.Name)
|
|
|
|
}
|