forked from mefistotelis/psx_mnd_sym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.go
106 lines (93 loc) · 2.63 KB
/
parse.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Package csym translates Playstation 1 symbol information to C declarations.
package csym
import (
"github.com/mefistotelis/psx_mnd_sym"
"github.com/mefistotelis/psx_mnd_sym/csym/c"
)
// Parser tracks type information used for parsing.
type Parser struct {
// Type information.
// Struct maps from struct tag to struct types.
StructTags map[string][]*c.StructType
// Unions maps from union tag to union types.
UnionTags map[string][]*c.UnionType
// Enums maps from enum tag to enum types.
EnumTags map[string][]*c.EnumType
// types maps from type name to underlying type definition.
Types map[string]c.Type
// Structs in order of occurrence in SYM file.
Structs []*c.StructType
// Unions in order of occurrence in SYM file.
Unions []*c.UnionType
// Enums in order of occurrence in SYM file.
Enums []*c.EnumType
// Type definitions in order of occurrence in SYM file.
Typedefs []c.Type
// Tracks unique enum member names.
enumMembers map[string]bool
// Declarations.
*Overlay // default binary
// Overlays.
Overlays []*Overlay
// overlayIDs maps from overlay ID to overlay.
overlayIDs map[uint32]*Overlay
// Current overlay.
curOverlay *Overlay
// Option switches.
opts *sym.Options
}
// NewParser returns a new parser.
func NewParser(opts *sym.Options) *Parser {
overlay := &Overlay{
varNames: make(map[string][]*c.VarDecl),
funcNames: make(map[string][]*c.FuncDecl),
}
return &Parser{
StructTags: make(map[string][]*c.StructType),
UnionTags: make(map[string][]*c.UnionType),
EnumTags: make(map[string][]*c.EnumType),
Types: make(map[string]c.Type),
enumMembers: make(map[string]bool),
Overlay: overlay,
overlayIDs: make(map[uint32]*Overlay),
curOverlay: overlay,
opts: opts,
}
}
// An Overlay is an overlay appended to the end of the executable.
type Overlay struct {
// Base address at which the overlay is loaded.
Addr uint32
// Overlay ID.
ID uint32
// Overlay length in bytes.
Length uint32
// Variable delcarations.
Vars []*c.VarDecl
// Function delcarations.
Funcs []*c.FuncDecl
// varNames maps from variable name to variable declaration.
varNames map[string][]*c.VarDecl
// funcNames maps from function name to function declaration.
funcNames map[string][]*c.FuncDecl
// Symbols.
Symbols []*Symbol
// Source file line numbers.
Lines []*Line
}
// A Symbol associates a symbol name with an address.
type Symbol struct {
// Symbol address.
Addr uint32
// Symbol name.
Name string
}
// A Line associates a line number in a source file with an address.
type Line struct {
// Address.
Addr uint32
// Source file name.
Path string
// Line number.
Line uint32
}