Skip to content

Commit

Permalink
ast,printer: add Includes field to File
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Dec 31, 2018
1 parent e364d63 commit 4aaf6bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ type Section interface {

// File represents an assembly file.
type File struct {
Includes []string
Sections []Section
}

func NewFile() *File {
return &File{}
return &File{
Includes: []string{"textflag.h"},
}
}

func (f *File) AddSection(s Section) {
Expand Down
13 changes: 9 additions & 4 deletions printer/goasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewGoAsm(cfg Config) Printer {

func (p *goasm) Print(f *avo.File) ([]byte, error) {
p.header()
p.includes(f.Includes)
for _, s := range f.Sections {
switch s := s.(type) {
case *avo.Function:
Expand All @@ -38,12 +39,16 @@ func (p *goasm) Print(f *avo.File) ([]byte, error) {

func (p *goasm) header() {
p.Comment(p.cfg.GeneratedWarning())
p.NL()
p.include("textflag.h")
}

func (p *goasm) include(path string) {
p.Printf("#include \"%s\"\n", path)
func (p *goasm) includes(paths []string) {
if len(paths) == 0 {
return
}
p.NL()
for _, path := range paths {
p.Printf("#include \"%s\"\n", path)
}
}

func (p *goasm) function(f *avo.Function) {
Expand Down

0 comments on commit 4aaf6bc

Please sign in to comment.