gotypes,build: pointer dereference (#61)

Provides a method on `gotypes.Component` to allow pointer dereference. This will enable `gotypes` helpers to be used with struct pointer arguments, for example.

Updates #53 
Fixes #54
This commit is contained in:
Michael McLoughlin
2019-01-27 19:22:21 -08:00
committed by GitHub
parent eb225e9d2c
commit 9eb409b935
9 changed files with 137 additions and 29 deletions

View File

@@ -112,6 +112,9 @@ func Load(src gotypes.Component, dst reg.Register) reg.Register { return ctx.Loa
// attempt to select the right MOV instruction based on the types involved.
func Store(src reg.Register, dst gotypes.Component) { ctx.Store(src, dst) }
// Dereference loads a pointer and returns its element type.
func Dereference(ptr gotypes.Component) gotypes.Component { return ctx.Dereference(ptr) }
// Doc sets documentation comment lines for the currently active function.
func Doc(lines ...string) { ctx.Doc(lines...) }

View File

@@ -54,6 +54,13 @@ func (c *Context) Store(src reg.Register, dst gotypes.Component) {
c.mov(src, b.Addr, int(src.Bytes()), int(gotypes.Sizes.Sizeof(b.Type)), b.Type)
}
// Dereference loads a pointer and returns its element type.
func (c *Context) Dereference(ptr gotypes.Component) gotypes.Component {
r := c.GP64()
c.Load(ptr, r)
return ptr.Dereference(r)
}
// ConstData builds a static data section containing just the given constant.
func (c *Context) ConstData(name string, v operand.Constant) operand.Mem {
g := c.StaticGlobal(name)