build: support comments in functions (#41)

This commit is contained in:
Michael McLoughlin
2019-01-11 10:33:41 -08:00
parent 27cea3be8b
commit 284ee13ada
10 changed files with 117 additions and 23 deletions

View File

@@ -20,6 +20,20 @@ type Label string
func (l Label) node() {}
// Comment represents a multi-line comment.
type Comment struct {
Lines []string
}
func (c *Comment) node() {}
// NewComment builds a Comment consisting of the provided lines.
func NewComment(lines ...string) *Comment {
return &Comment{
Lines: lines,
}
}
// Instruction is a single instruction in a function.
type Instruction struct {
Opcode string
@@ -176,6 +190,11 @@ func (f *Function) AddLabel(l Label) {
f.AddNode(l)
}
// AddComment adds comment lines to f.
func (f *Function) AddComment(lines ...string) {
f.AddNode(NewComment(lines...))
}
// AddNode appends a Node to f.
func (f *Function) AddNode(n Node) {
f.Nodes = append(f.Nodes, n)