File: generator.go

package info (click to toggle)
coreboot 25.09%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 217,084 kB
  • sloc: ansic: 1,685,313; sh: 15,803; python: 11,200; perl: 10,186; asm: 8,519; makefile: 5,179; cpp: 4,724; pascal: 2,327; ada: 1,985; yacc: 1,264; lex: 731; sed: 75; ruby: 5; lisp: 5; awk: 4
file content (64 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package generator

import (
	"fmt"

	"review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
	"review.coreboot.org/coreboot.git/util/intelp2m/logs"
	"review.coreboot.org/coreboot.git/util/intelp2m/parser"
)

type collector []string

func (c *collector) Line(str string) {
	*c = append(*c, str)
}

func (c *collector) Linef(format string, args ...interface{}) {
	*c = append(*c, fmt.Sprintf(format, args...))
}

// Run() generates strings with macros
func Run(entries []parser.Entry) ([]string, error) {
	if len(entries) == 0 {
		err := fmt.Errorf("entries array is empty")
		logs.Errorf("%v", err)
		return nil, err
	}
	collection := make(collector, 0)
	logs.Infof("run")
	for _, entry := range entries {
		switch entry.EType {
		case parser.EntryGroup:
			collection.Line("\n")
			collection.Linef("\t/* %s */\n", entry.Function)

		case parser.EntryReserved:
			if p2m.Config.GenLevel >= 2 {
				collection.Line("\n")
			}
			collection.Linef("\t/* %s - %s */\n", entry.ID, entry.Function)

		case parser.EntryPad:
			if p2m.Config.GenLevel >= 2 {
				collection.Line("\n")
				collection.Linef("\t/* %s - %s */\n", entry.ID, entry.Function)
				collection.Linef("\t/* DW0: 0x%0.8x, DW1: 0x%0.8x */\n", entry.DW0, entry.DW1)
			}
			lines := entry.ToMacro()
			if p2m.Config.GenLevel == 1 && len(lines) != 0 {
				collection.Linef("\t%s\t/* %s */\n", lines[0], entry.Function)
				break
			}

			for i := range lines {
				collection.Linef("\t%s\n", lines[i])
			}

		default:
			logs.Errorf("unknown entry type: %d", int(entry.EType))
		}
	}
	logs.Infof("successfully completed: %d rows", len(collection))
	return collection, nil
}