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

@@ -26,6 +26,8 @@ func (p *goasm) Print(f *avo.File) ([]byte, error) {
switch s := s.(type) {
case *avo.Function:
p.function(s)
case *avo.Global:
p.global(s)
default:
panic("unknown section type")
}
@@ -64,6 +66,16 @@ func (p *goasm) function(f *avo.Function) {
}
}
func (p *goasm) global(g *avo.Global) {
p.NL()
for _, d := range g.Data {
a := operand.NewDataAddr(g.Symbol, d.Offset)
p.Printf("DATA %s/%d, %s\n", a.Asm(), d.Value.Bytes(), d.Value.Asm())
}
// TODO(mbm): replace hardcoded RODATA with an attributes list
p.Printf("GLOBL %s%s(SB), RODATA, $%d\n", dot, g.Symbol, g.Size)
}
func joinOperands(operands []operand.Op) string {
asm := make([]string, len(operands))
for i, op := range operands {