Skip to content

Commit

Permalink
Add better support for 'after' in spec file.
Browse files Browse the repository at this point in the history
after max/min are still unsupported.
  • Loading branch information
trhodeos committed Apr 1, 2018
1 parent 5f454b7 commit 51a008d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions spec.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spicy

import (
"container/list"
"errors"
"fmt"
"github.com/alecthomas/participle"
Expand Down Expand Up @@ -279,6 +280,9 @@ func ParseSpec(r io.Reader) (*Spec, error) {
if err == nil {
log.Debugf("Parsed: %v", out)
}
for _, w := range out.Waves {
w.correctOrdering()
}
return out, err
}

Expand Down Expand Up @@ -315,6 +319,41 @@ func (w *Wave) checkValidity() error {
return nil
}

func findElement(l *list.List, name string) *list.Element {
for e := l.Front(); e != nil; e = e.Next() {
original, _ := e.Value.(*Segment)
if original.Name == name {
return e
}
}
return nil
}

func (w *Wave) correctOrdering() {
// TODO(trhodeos): Make this actually correct. This just places any
// explicitly addressed segments before any 'after.*' segments. If
// 'after' segments depend on other 'after' segments, this'll break.
l := list.New()
for _, seg := range w.ObjectSegments {
if seg.Positioning.Address != 0 {
l.PushBack(seg)
}
}
for _, seg := range w.ObjectSegments {
if seg.Positioning.Address == 0 {
e := findElement(l, seg.Positioning.AfterSegment)
l.InsertAfter(seg, e)
}
}

newSegments := make([]*Segment, 0)
for e := l.Front(); e != nil; e = e.Next() {
original, _ := e.Value.(*Segment)
newSegments = append(newSegments, original)
}
w.ObjectSegments = newSegments
}

func (w *Wave) GetBootSegment() *Segment {
for _, seg := range w.ObjectSegments {
if seg.Flags.Boot {
Expand Down

0 comments on commit 51a008d

Please sign in to comment.