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:
@@ -107,6 +107,10 @@ func (c *Context) StaticGlobal(name string) operand.Mem {
|
||||
return c.global.Base()
|
||||
}
|
||||
|
||||
func (c *Context) DataAttributes(a avo.Attribute) {
|
||||
c.activeglobal().Attributes = a
|
||||
}
|
||||
|
||||
func (c *Context) AddDatum(offset int, v operand.Constant) {
|
||||
if err := c.activeglobal().AddDatum(avo.NewDatum(offset, v)); err != nil {
|
||||
c.AddError(err)
|
||||
|
||||
@@ -24,8 +24,10 @@ func TEXT(name, signature string) {
|
||||
|
||||
func LABEL(name string) { ctx.Label(avo.Label(name)) }
|
||||
|
||||
func GLOBL(name string) operand.Mem {
|
||||
return ctx.StaticGlobal(name)
|
||||
func GLOBL(name string, a avo.Attribute) operand.Mem {
|
||||
g := ctx.StaticGlobal(name)
|
||||
ctx.DataAttributes(a)
|
||||
return g
|
||||
}
|
||||
|
||||
func DATA(offset int, v operand.Constant) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/mmcloughlin/avo"
|
||||
"github.com/mmcloughlin/avo/operand"
|
||||
"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 {
|
||||
g := c.StaticGlobal(name)
|
||||
c.DataAttributes(avo.RODATA | avo.NOPTR)
|
||||
c.AppendDatum(v)
|
||||
return g
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user