add Symbol type to operand

This commit is contained in:
Michael McLoughlin
2018-12-06 17:26:33 -08:00
parent e42eb1fb8c
commit 676ec39c51
5 changed files with 61 additions and 7 deletions

View File

@@ -10,17 +10,35 @@ type Op interface {
Asm() string
}
type Symbol struct {
Name string
Static bool
}
func (s Symbol) String() string {
n := s.Name
if s.Static {
n += "<>"
}
return n
}
type Mem struct {
Disp int
Base reg.Register
Index reg.Register
Scale uint8
Symbol Symbol
Disp int
Base reg.Register
Index reg.Register
Scale uint8
}
func (m Mem) Asm() string {
a := ""
a := m.Symbol.String()
if m.Disp != 0 {
a += fmt.Sprintf("%d", m.Disp)
if a == "" {
a += fmt.Sprintf("%d", m.Disp)
} else {
a += fmt.Sprintf("%+d", m.Disp)
}
}
if m.Base != nil {
a += fmt.Sprintf("(%s)", m.Base.Asm())