internal/gen: docstrings for instruction builders
Piggybacks off the docstrings for constructors in x64 package. Closes #36
This commit is contained in:
17436
build/zinstructions.go
17436
build/zinstructions.go
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
|||||||
package gen
|
package gen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/internal/inst"
|
"github.com/mmcloughlin/avo/internal/inst"
|
||||||
"github.com/mmcloughlin/avo/internal/prnt"
|
"github.com/mmcloughlin/avo/internal/prnt"
|
||||||
"github.com/mmcloughlin/avo/printer"
|
"github.com/mmcloughlin/avo/printer"
|
||||||
@@ -37,14 +39,21 @@ func (b *build) Generate(is []inst.Instruction) ([]byte, error) {
|
|||||||
|
|
||||||
func (b *build) instruction(i inst.Instruction) {
|
func (b *build) instruction(i inst.Instruction) {
|
||||||
s := params(i)
|
s := params(i)
|
||||||
|
d := doc(i)
|
||||||
|
|
||||||
// Context method.
|
// Context method.
|
||||||
|
methoddoc := append([]string{}, d...)
|
||||||
|
methoddoc = append(methoddoc, fmt.Sprintf("Construct and append a %s instruction to the active function.", i.Opcode))
|
||||||
|
b.Comment(methoddoc...)
|
||||||
b.Printf("func (c *Context) %s(%s) {\n", i.Opcode, s.ParameterList())
|
b.Printf("func (c *Context) %s(%s) {\n", i.Opcode, s.ParameterList())
|
||||||
b.Printf("if inst, err := x86.%s(%s); err == nil", i.Opcode, s.Arguments())
|
b.Printf("if inst, err := x86.%s(%s); err == nil", i.Opcode, s.Arguments())
|
||||||
b.Printf(" { c.Instruction(inst) }")
|
b.Printf(" { c.Instruction(inst) }")
|
||||||
b.Printf(" else { c.adderror(err) }\n")
|
b.Printf(" else { c.adderror(err) }\n")
|
||||||
b.Printf("}\n")
|
b.Printf("}\n\n")
|
||||||
|
|
||||||
// Global version.
|
// Global version.
|
||||||
|
globaldoc := append([]string{}, methoddoc...)
|
||||||
|
globaldoc = append(globaldoc, "Operates on the global context.")
|
||||||
|
b.Comment(globaldoc...)
|
||||||
b.Printf("func %s(%s) { ctx.%s(%s) }\n\n", i.Opcode, s.ParameterList(), i.Opcode, s.Arguments())
|
b.Printf("func %s(%s) { ctx.%s(%s) }\n\n", i.Opcode, s.ParameterList(), i.Opcode, s.Arguments())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ func (c *ctors) Generate(is []inst.Instruction) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ctors) instruction(i inst.Instruction) {
|
func (c *ctors) instruction(i inst.Instruction) {
|
||||||
for _, line := range doc(i) {
|
c.Comment(doc(i)...)
|
||||||
c.Printf("// %s\n", line)
|
|
||||||
}
|
|
||||||
|
|
||||||
s := params(i)
|
s := params(i)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user