| 1 |
package generator |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" |
| 7 |
"review.coreboot.org/coreboot.git/util/intelp2m/logs" |
| 8 |
"review.coreboot.org/coreboot.git/util/intelp2m/parser" |
| 9 |
) |
| 10 |
|
| 11 |
type collector []string |
| 12 |
|
| 13 |
func (c *collector) Line(str string) { |
| 14 |
*c = append(*c, str) |
| 15 |
} |
| 16 |
|
| 17 |
func (c *collector) Linef(format string, args ...interface{}) { |
| 18 |
*c = append(*c, fmt.Sprintf(format, args...)) |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
func Run(entries []parser.Entry) ([]string, error) { |
| 23 |
if len(entries) == 0 { |
| 24 |
err := fmt.Errorf("entries array is empty") |
| 25 |
logs.Errorf("%v", err) |
| 26 |
return nil, err |
| 27 |
} |
| 28 |
collection := make(collector, 0) |
| 29 |
logs.Infof("run") |
| 30 |
for _, entry := range entries { |
| 31 |
switch entry.EType { |
| 32 |
case parser.EntryGroup: |
| 33 |
collection.Line("\n") |
| 34 |
collection.Linef("\t/* %s */\n", entry.Function) |
| 35 |
|
| 36 |
case parser.EntryReserved: |
| 37 |
if p2m.Config.GenLevel >= 2 { |
| 38 |
collection.Line("\n") |
| 39 |
} |
| 40 |
collection.Linef("\t/* %s - %s */\n", entry.ID, entry.Function) |
| 41 |
|
| 42 |
case parser.EntryPad: |
| 43 |
if p2m.Config.GenLevel >= 2 { |
| 44 |
collection.Line("\n") |
| 45 |
collection.Linef("\t/* %s - %s */\n", entry.ID, entry.Function) |
| 46 |
collection.Linef("\t/* DW0: 0x%0.8x, DW1: 0x%0.8x */\n", entry.DW0, entry.DW1) |
| 47 |
} |
| 48 |
lines := entry.ToMacro() |
| 49 |
if p2m.Config.GenLevel == 1 && len(lines) != 0 { |
| 50 |
collection.Linef("\t%s\t/* %s */\n", lines[0], entry.Function) |
| 51 |
break |
| 52 |
} |
| 53 |
|
| 54 |
for i := range lines { |
| 55 |
collection.Linef("\t%s\n", lines[i]) |
| 56 |
} |
| 57 |
|
| 58 |
default: |
| 59 |
logs.Errorf("unknown entry type: %d", int(entry.EType)) |
| 60 |
} |
| 61 |
} |
| 62 |
logs.Infof("successfully completed: %d rows", len(collection)) |
| 63 |
return collection, nil |
| 64 |
} |