first pass at DATA sections

This commit is contained in:
Michael McLoughlin
2018-12-27 11:57:46 -08:00
parent d29c6340d7
commit 9243d299e6
11 changed files with 250 additions and 15 deletions

View File

@@ -15,6 +15,10 @@ type Symbol struct {
Static bool
}
func NewStaticSymbol(name string) Symbol {
return Symbol{Name: name, Static: true}
}
func (s Symbol) String() string {
n := s.Name
if s.Static {
@@ -51,12 +55,27 @@ func NewStackAddr(offset int) Mem {
}
}
func (m Mem) Idx(idx int) Mem {
func NewDataAddr(sym Symbol, offset int) Mem {
return Mem{
Symbol: sym,
Disp: offset,
Base: reg.StaticBase,
}
}
func (m Mem) Offset(idx int) Mem {
a := m
a.Disp += idx
return a
}
func (m Mem) Idx(r reg.Register, s uint8) Mem {
a := m
a.Index = r
a.Scale = s
return a
}
func (m Mem) Asm() string {
a := m.Symbol.String()
if m.Disp != 0 {

View File

@@ -42,6 +42,8 @@ func TestMemAsm(t *testing.T) {
{Mem{Symbol: Symbol{Name: "foo"}, Base: reg.StaticBase, Disp: -7}, "foo-7(SB)"},
{Mem{Symbol: Symbol{Name: "bar", Static: true}, Base: reg.StaticBase, Disp: 4, Index: reg.R11, Scale: 4}, "bar<>+4(SB)(R11*4)"},
{NewParamAddr("param", 16), "param+16(FP)"},
{NewStackAddr(42), "42(SP)"},
{NewDataAddr(Symbol{Name: "data", Static: true}, 13), "data<>+13(SB)"},
}
for _, c := range cases {
got := c.Mem.Asm()