ast,build: allow setting data attributes
Previously GLOBL/DATA attributes are set to RODATA. This diff removes that default and allows them to be set through the DataAttributes context method. Updates #2
This commit is contained in:
1
ast.go
1
ast.go
@@ -224,7 +224,6 @@ type Global struct {
|
|||||||
func NewGlobal(sym operand.Symbol) *Global {
|
func NewGlobal(sym operand.Symbol) *Global {
|
||||||
return &Global{
|
return &Global{
|
||||||
Symbol: sym,
|
Symbol: sym,
|
||||||
Attributes: RODATA,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,10 @@ func (c *Context) StaticGlobal(name string) operand.Mem {
|
|||||||
return c.global.Base()
|
return c.global.Base()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) DataAttributes(a avo.Attribute) {
|
||||||
|
c.activeglobal().Attributes = a
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) AddDatum(offset int, v operand.Constant) {
|
func (c *Context) AddDatum(offset int, v operand.Constant) {
|
||||||
if err := c.activeglobal().AddDatum(avo.NewDatum(offset, v)); err != nil {
|
if err := c.activeglobal().AddDatum(avo.NewDatum(offset, v)); err != nil {
|
||||||
c.AddError(err)
|
c.AddError(err)
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ func TEXT(name, signature string) {
|
|||||||
|
|
||||||
func LABEL(name string) { ctx.Label(avo.Label(name)) }
|
func LABEL(name string) { ctx.Label(avo.Label(name)) }
|
||||||
|
|
||||||
func GLOBL(name string) operand.Mem {
|
func GLOBL(name string, a avo.Attribute) operand.Mem {
|
||||||
return ctx.StaticGlobal(name)
|
g := ctx.StaticGlobal(name)
|
||||||
|
ctx.DataAttributes(a)
|
||||||
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func DATA(offset int, v operand.Constant) {
|
func DATA(offset int, v operand.Constant) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/mmcloughlin/avo"
|
||||||
"github.com/mmcloughlin/avo/operand"
|
"github.com/mmcloughlin/avo/operand"
|
||||||
"github.com/mmcloughlin/avo/reg"
|
"github.com/mmcloughlin/avo/reg"
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ func (c *Context) Store(src reg.Register, dst gotypes.Component) {
|
|||||||
|
|
||||||
func (c *Context) ConstData(name string, v operand.Constant) operand.Mem {
|
func (c *Context) ConstData(name string, v operand.Constant) operand.Mem {
|
||||||
g := c.StaticGlobal(name)
|
g := c.StaticGlobal(name)
|
||||||
|
c.DataAttributes(avo.RODATA | avo.NOPTR)
|
||||||
c.AppendDatum(v)
|
c.AppendDatum(v)
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
|
"github.com/mmcloughlin/avo"
|
||||||
. "github.com/mmcloughlin/avo/build"
|
. "github.com/mmcloughlin/avo/build"
|
||||||
. "github.com/mmcloughlin/avo/operand"
|
. "github.com/mmcloughlin/avo/operand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bytes := GLOBL("bytes")
|
bytes := GLOBL("bytes", avo.RODATA|avo.NOPTR)
|
||||||
DATA(0, U64(0x0011223344556677))
|
DATA(0, U64(0x0011223344556677))
|
||||||
DATA(8, String("strconst"))
|
DATA(8, String("strconst"))
|
||||||
DATA(16, F32(math.Pi))
|
DATA(16, F32(math.Pi))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ DATA bytes<>+32(SB)/4, $0x00112233
|
|||||||
DATA bytes<>+36(SB)/2, $0x4455
|
DATA bytes<>+36(SB)/2, $0x4455
|
||||||
DATA bytes<>+38(SB)/1, $0x66
|
DATA bytes<>+38(SB)/1, $0x66
|
||||||
DATA bytes<>+39(SB)/1, $0x77
|
DATA bytes<>+39(SB)/1, $0x77
|
||||||
GLOBL bytes<>(SB), RODATA, $40
|
GLOBL bytes<>(SB), RODATA|NOPTR, $40
|
||||||
|
|
||||||
// func DataAt(i int) byte
|
// func DataAt(i int) byte
|
||||||
TEXT ·DataAt(SB), $0-9
|
TEXT ·DataAt(SB), $0-9
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ TEXT ·EncodeInt(SB), $0-24
|
|||||||
RET
|
RET
|
||||||
|
|
||||||
DATA reciprocal180<>(SB)/8, $(0.005555555555555556)
|
DATA reciprocal180<>(SB)/8, $(0.005555555555555556)
|
||||||
GLOBL reciprocal180<>(SB), RODATA, $8
|
GLOBL reciprocal180<>(SB), RODATA|NOPTR, $8
|
||||||
|
|
||||||
DATA onepointfive<>(SB)/8, $(1.5)
|
DATA onepointfive<>(SB)/8, $(1.5)
|
||||||
GLOBL onepointfive<>(SB), RODATA, $8
|
GLOBL onepointfive<>(SB), RODATA|NOPTR, $8
|
||||||
|
|
||||||
DATA reciprocal360<>(SB)/8, $(0.002777777777777778)
|
DATA reciprocal360<>(SB)/8, $(0.002777777777777778)
|
||||||
GLOBL reciprocal360<>(SB), RODATA, $8
|
GLOBL reciprocal360<>(SB), RODATA|NOPTR, $8
|
||||||
|
|
||||||
DATA mask<>(SB)/8, $0x5555555555555555
|
DATA mask<>(SB)/8, $0x5555555555555555
|
||||||
GLOBL mask<>(SB), RODATA, $8
|
GLOBL mask<>(SB), RODATA|NOPTR, $8
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ TEXT ·CriticalLine(SB), $0-24
|
|||||||
RET
|
RET
|
||||||
|
|
||||||
DATA half<>(SB)/8, $(0.5)
|
DATA half<>(SB)/8, $(0.5)
|
||||||
GLOBL half<>(SB), RODATA, $8
|
GLOBL half<>(SB), RODATA|NOPTR, $8
|
||||||
|
|
||||||
// func NewStruct(w uint16, p [2]float64, q uint64) Struct
|
// func NewStruct(w uint16, p [2]float64, q uint64) Struct
|
||||||
TEXT ·NewStruct(SB), $0-64
|
TEXT ·NewStruct(SB), $0-64
|
||||||
|
|||||||
Reference in New Issue
Block a user