first pass at DATA sections
This commit is contained in:
@@ -15,6 +15,7 @@ type Context struct {
|
||||
pkg *packages.Package
|
||||
file *avo.File
|
||||
function *avo.Function
|
||||
global *avo.Global
|
||||
errs []error
|
||||
reg.Collection
|
||||
}
|
||||
@@ -47,7 +48,7 @@ func (c *Context) Package(path string) {
|
||||
|
||||
func (c *Context) Function(name string) {
|
||||
c.function = avo.NewFunction(name)
|
||||
c.file.Sections = append(c.file.Sections, c.function)
|
||||
c.file.AddSection(c.function)
|
||||
}
|
||||
|
||||
func (c *Context) Signature(s *gotypes.Signature) {
|
||||
@@ -92,6 +93,30 @@ func (c *Context) activefunc() *avo.Function {
|
||||
|
||||
//go:generate avogen -output zinstructions.go build
|
||||
|
||||
func (c *Context) StaticGlobal(name string) operand.Mem {
|
||||
c.global = avo.NewStaticGlobal(name)
|
||||
c.file.AddSection(c.global)
|
||||
return c.global.Base()
|
||||
}
|
||||
|
||||
func (c *Context) AddDatum(offset int, v operand.Constant) {
|
||||
if err := c.activeglobal().AddDatum(avo.NewDatum(offset, v)); err != nil {
|
||||
c.AddError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) AppendDatum(v operand.Constant) {
|
||||
c.activeglobal().Append(v)
|
||||
}
|
||||
|
||||
func (c *Context) activeglobal() *avo.Global {
|
||||
if c.global == nil {
|
||||
c.AddErrorMessage("no active global")
|
||||
return avo.NewStaticGlobal("")
|
||||
}
|
||||
return c.global
|
||||
}
|
||||
|
||||
func (c *Context) AddError(err error) {
|
||||
c.errs = append(c.errs, err)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,14 @@ 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 DATA(offset int, v operand.Constant) {
|
||||
ctx.AddDatum(offset, v)
|
||||
}
|
||||
|
||||
var flags = NewFlags(flag.CommandLine)
|
||||
|
||||
func Generate() {
|
||||
|
||||
Reference in New Issue
Block a user