Skip to content

Commit

Permalink
Start formatting ld script with some hardcoded data.
Browse files Browse the repository at this point in the history
  • Loading branch information
trhodeos committed Feb 25, 2018
1 parent 56f04c3 commit 8e328fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bin/spicy.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main
import (
"bufio"
"encoding/json"
// "encoding/json"
"os"
"fmt"
"github.com/alecthomas/kingpin"
"github.com/trhodeos/spicy"
)
Expand Down Expand Up @@ -47,6 +48,8 @@ func main() {

spec, err := spicy.ParseSpec(bufio.NewReader(f))
if err != nil { panic(err) }

json.NewEncoder(os.Stdout).Encode(spec)
str, err := spec.GenerateLdScript()
if err != nil { panic(err) }
fmt.Println(str)
//json.NewEncoder(os.Stdout).Encode(spec)
}
19 changes: 19 additions & 0 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"errors"
"fmt"
"text/template"
"os"
)

type Constant struct {
Expand Down Expand Up @@ -233,3 +235,20 @@ func ParseSpec(r io.Reader) (*Spec, error) {
}
return convertAstToSpec(*specAst)
}

func (s *Spec) GenerateLdScript() (string, error) {
t := `
MEMORY {
{{range .Segments}}
{{.Name}}.RAM (RX) : ORIGIN = 0x80000450, LENGTH = 0x400000
{{.Name}}.bss.RAM (RW) : ORIGIN = 0x80000450, LENGTH = 0x400000
{{end}}
}
`
tmpl, err := template.New("test").Parse(t)
if err != nil {
return "", err
}
err = tmpl.Execute(os.Stdout, s)
return "", err
}

0 comments on commit 8e328fe

Please sign in to comment.