From f18271ada53a648a4bf8ef775c05d5a8667fd943 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 2 Dec 2018 15:15:00 -0800 Subject: [PATCH] add reg.Type --- operand/checks.go | 2 +- pass/cfg.go | 2 +- reg/types.go | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/operand/checks.go b/operand/checks.go index 2d4e98f..a95a9ea 100644 --- a/operand/checks.go +++ b/operand/checks.go @@ -115,7 +115,7 @@ func IsYmm(op Op) bool { // IsRegisterKindSize returns true if op is a register of the given kind and size in bytes. func IsRegisterKindSize(op Op, k reg.Kind, n uint) bool { - r, ok := op.(reg.Register) + r, ok := op.(reg.Type) return ok && r.Kind() == k && r.Bytes() == n } diff --git a/pass/cfg.go b/pass/cfg.go index 501e09e..7c5360f 100644 --- a/pass/cfg.go +++ b/pass/cfg.go @@ -37,7 +37,7 @@ func LabelTarget(fn *avo.Function) error { return nil } -// CFG constructs the call-flow-graph of each function. +// CFG constructs the call-flow-graph for the function. func CFG(fn *avo.Function) error { is := fn.Instructions() n := len(is) diff --git a/reg/types.go b/reg/types.go index bd8f601..472f2ad 100644 --- a/reg/types.go +++ b/reg/types.go @@ -1,5 +1,7 @@ package reg +import "fmt" + type Size uint const ( @@ -44,10 +46,16 @@ type private interface { private() } -type Virtual interface { - VirtualID() uint16 +type Type interface { Kind() Kind Bytes() uint + Asm() string + private +} + +type Virtual interface { + VirtualID() uint16 + Type } type virtual struct { @@ -59,13 +67,17 @@ type virtual struct { func (v virtual) VirtualID() uint16 { return v.id } func (v virtual) Kind() Kind { return v.kind } +func (v virtual) Asm() string { + // TODO(mbm): decide on virtual register syntax + return fmt.Sprintf("", v.id, v.Kind(), v.Bytes()) +} + +func (v virtual) private() {} + type Register interface { PhysicalID() uint16 - Kind() Kind Mask() uint16 - Bytes() uint - Asm() string - private + Type } type register struct {