2018-03-31 04:58:57 +02:00
|
|
|
package addrs
|
|
|
|
|
2018-04-30 19:06:05 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-03-31 04:58:57 +02:00
|
|
|
// LocalValue is the address of a local value.
|
|
|
|
type LocalValue struct {
|
|
|
|
referenceable
|
|
|
|
Name string
|
|
|
|
}
|
2018-04-04 03:03:47 +02:00
|
|
|
|
|
|
|
func (v LocalValue) String() string {
|
|
|
|
return "local." + v.Name
|
|
|
|
}
|
2018-04-30 19:06:05 +02:00
|
|
|
|
|
|
|
// Absolute converts the receiver into an absolute address within the given
|
|
|
|
// module instance.
|
|
|
|
func (v LocalValue) Absolute(m ModuleInstance) AbsLocalValue {
|
|
|
|
return AbsLocalValue{
|
|
|
|
Module: m,
|
|
|
|
LocalValue: v,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AbsLocalValue is the absolute address of a local value within a module instance.
|
|
|
|
type AbsLocalValue struct {
|
|
|
|
Module ModuleInstance
|
|
|
|
LocalValue LocalValue
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocalValue returns the absolute address of a local value of the given
|
|
|
|
// name within the receiving module instance.
|
|
|
|
func (m ModuleInstance) LocalValue(name string) AbsLocalValue {
|
|
|
|
return AbsLocalValue{
|
|
|
|
Module: m,
|
|
|
|
LocalValue: LocalValue{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v AbsLocalValue) String() string {
|
|
|
|
if len(v.Module) == 0 {
|
|
|
|
return v.LocalValue.String()
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s.%s", v.Module.String(), v.LocalValue.String())
|
|
|
|
}
|