blob: f63bb8ec98c26b4e41c5e4a4b4cee3846856d812 (
plain)
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
|
package main
import (
"bufio"
"os"
"regexp"
"strings"
)
// Map for labels and their addresses
var labels map[string]uint = make(map[string]uint)
func LabelFind(path string) {
file, err := os.Open(path)
if err != nil {
panic(err)
}
defer file.Close()
input := bufio.NewScanner(file)
for i := 0; input.Scan(); i += 4 {
k := input.Text()
if k == "" {
i -= 4
continue
} else if k == ".text" || k == ".data" {
i += 4
continue
}
s, err := Parse(k)
if err != nil {
panic(err)
}
if len(s) == 1 && s[0] == "" {
i -= 4
continue
}
hasLabel, err := regexp.MatchString("^.*:", s[0])
if err != nil {
panic(err)
}
if hasLabel {
labels[strings.ReplaceAll(s[0], ":", "")] = uint(i)
if len(s) == 1 {
i -= 4
}
}
}
}
|