wip: adding instruction inputs and outputs

This commit is contained in:
Michael McLoughlin
2018-12-02 17:57:12 -08:00
parent f18271ada5
commit 82b31fa0da
15 changed files with 18157 additions and 7650 deletions

View File

@@ -1,10 +1,12 @@
package gen
import (
"bytes"
"fmt"
"sort"
"strconv"
"strings"
"text/tabwriter"
"github.com/mmcloughlin/avo/internal/inst"
)
@@ -95,3 +97,29 @@ func params(i inst.Instruction) signature {
return argslist(ops)
}
// doc generates the lines of the function comment.
func doc(i inst.Instruction) []string {
lines := []string{
fmt.Sprintf("%s: %s.", i.Opcode, i.Summary),
"",
"Forms:",
"",
}
// Write a table of instruction forms.
buf := bytes.NewBuffer(nil)
w := tabwriter.NewWriter(buf, 0, 0, 1, ' ', 0)
for _, f := range i.Forms {
row := i.Opcode + "\t" + strings.Join(f.Signature(), "\t") + "\n"
fmt.Fprint(w, row)
}
w.Flush()
tbl := strings.TrimSpace(buf.String())
for _, line := range strings.Split(tbl, "\n") {
lines = append(lines, "\t"+line)
}
return lines
}